@lumen-stack/react 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/styles.css +317 -14
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
'use strict';var
|
|
3
|
-
${o.stack}`:""}`);continue}try{t.push(JSON.stringify(o,mn));}catch{t.push(String(o));}}let n=t.join(" ");return n.length>4096?n.slice(0,4096)+"\u2026[truncated]":n}function mn(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function pn(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let o=e[n]?.bind(e);o&&(e[n]=(...a)=>{try{he(at,{level:n,ts:Date.now(),message:dn(a)});}catch{}o(...a);});}}function st(e){return Le?e.startsWith(Le):false}function fn(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let o=typeof t=="string"?t:t instanceof URL?t.toString():t.url,a=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(st(o))return e.call(window,t,n);let r=performance.now();try{let i=await e.call(window,t,n);return he(ge,{type:"fetch",method:a,url:Ne(o),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-r),ts:Date.now()}),i}catch(i){throw he(ge,{type:"fetch",method:a,url:Ne(o),status:0,ok:false,durationMs:Math.round(performance.now()-r),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function gn(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(o,a,...r){return this.__lumen={method:String(o).toUpperCase(),url:typeof a=="string"?a:a.toString(),t:0},t.call(this,o,a,...r)},e.prototype.send=function(o){let a=this.__lumen;if(a&&!st(a.url)){a.t=performance.now();let r=()=>{try{he(ge,{type:"xhr",method:a.method,url:Ne(a.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-a.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",r);};this.addEventListener("loadend",r);}return n.call(this,o??null)};}function Ne(e){return e.length>512?e.slice(0,512)+"\u2026":e}function lt(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:Qe(e),consoleLog:[],networkLog:[]};let t=cn();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:Qe(e),device:hn(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function hn(){let e={};try{e.screen={width:window.screen?.width??0,height:window.screen?.height??0},e.pixelRatio=window.devicePixelRatio??1,e.language=navigator.language,e.languages=Array.from(navigator.languages??[]),e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.colorScheme=window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light",e.referrer=document.referrer||void 0,e.title=document.title||void 0,e.online=navigator.onLine,performance.getEntriesByType("navigation")[0]&&(e.uptimeMs=Math.round(performance.now()));}catch{}return e}function Qe(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var ve="lumen:shake",bn=8e3,wn=50,vn='[data-lumen-root], [data-lumen-capture-ignore="true"]';function yn(e={}){return async function(){if(typeof window>"u")throw new x("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=Cn(),n=e.send??En,o=e.timeoutMs??bn,a=e.captureSettleMs??wn,r=Ln(),i=kn(e.concealSelector===void 0?vn:e.concealSelector);try{await Mn(a);let l=await new Promise((m,p)=>{let g=window.setTimeout(()=>{t.pending.delete(r),p(new x("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},o);t.pending.set(r,{resolve:E=>{window.clearTimeout(g),m(E);},reject:E=>{window.clearTimeout(g),p(E);}});try{n({type:"lumen:capture-request",id:r,afterScreenUpdates:!0});}catch{t.pending.delete(r),window.clearTimeout(g),p(new x("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new x(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let s=Nn(l.dataUrl),c=e.platform??Tn();return {blob:s,method:c==="android"?"android-native":"ios-native",platform:c,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:l.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{i();}}}function En(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new x("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function Cn(){if(window.__lumenNativeCapture)return window.__lumenNativeCapture;let e={pending:new Map,resolve(n,o,a){let r=e.pending.get(n);r&&(e.pending.delete(n),r.resolve({type:"lumen:capture-response",id:n,dataUrl:o,pixelRatio:a}));},reject(n,o){let a=e.pending.get(n);a&&(e.pending.delete(n),a.resolve({type:"lumen:capture-response",id:n,error:o}));}},t=n=>{let o=xn(n.data);if(!o||o.type!=="lumen:capture-response")return;let a=e.pending.get(o.id);a&&(e.pending.delete(o.id),a.resolve(o));};return window.addEventListener("message",t),document.addEventListener("message",t),window.__lumenNativeCapture=e,e}function xn(e){if(e&&typeof e=="object"&&"type"in e)return e;if(typeof e=="string")try{let t=JSON.parse(e);if(t&&typeof t=="object"&&t.type)return t}catch{}return null}function kn(e){if(!e||typeof document>"u")return ()=>{};let t=[];for(let n of Array.from(document.querySelectorAll(e)))t.push({el:n,prev:n.style.visibility}),n.style.visibility="hidden";return ()=>{for(let{el:n,prev:o}of t)n.style.visibility=o;}}async function Mn(e){await Rn(),e>0&&await new Promise(t=>window.setTimeout(t,e));}function Rn(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function Tn(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function Ln(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Nn(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new x("Native host returned an invalid image data URL.","NATIVE_CAPTURE_FAILED");let n=t[1]||"image/png",o=!!t[2],a=t[3]??"";if(!o)return new Blob([decodeURIComponent(a)],{type:n});let r=atob(a),i=new Uint8Array(r.length);for(let l=0;l<r.length;l++)i[l]=r.charCodeAt(l);return new Blob([i],{type:n})}var An="[data-lumen-root]",Sn="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function Pn(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(Ae(n))return true;return Ae(e.target)}function Ae(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(Sn)?true:!!e.closest(An):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?Ae(e.host):false:false}async function ut(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new x("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new x("Microphone access denied or unavailable.","MIC_DENIED")}let n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(s=>MediaRecorder.isTypeSupported(s))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),a=[],r=performance.now(),i=null;o.addEventListener("dataavailable",s=>{s.data&&s.data.size>0&&a.push(s.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);function l(){i!==null&&window.clearTimeout(i),i=null;for(let s of t.getTracks())s.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}l();},stop(){return new Promise((s,c)=>{if(o.state==="inactive"){l(),c(new x("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let m=performance.now()-r,p=o.mimeType||n||"audio/webm",g=new Blob(a,{type:p});l(),s({blob:g,durationMs:m,mimeType:p});},{once:true}),o.stop();})}}}async function ct(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new x("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new x("Screen capture was denied or cancelled.","SCREEN_DENIED")}let n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(c=>MediaRecorder.isTypeSupported(c))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),a=[],r=performance.now(),i=null;o.addEventListener("dataavailable",c=>{c.data&&c.data.size>0&&a.push(c.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);let l=t.getVideoTracks()[0];l&&l.addEventListener("ended",()=>{o.state!=="inactive"&&o.stop();});function s(){i!==null&&window.clearTimeout(i),i=null;for(let c of t.getTracks())c.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}s();},stop(){return new Promise((c,m)=>{if(o.state==="inactive"){s(),m(new x("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let p=performance.now()-r,g=o.mimeType||n||"video/webm",E=new Blob(a,{type:g});s(),c({blob:E,durationMs:p,mimeType:g});},{once:true}),o.stop();})}}}var Se=pt.createContext(null);function ue(){let e=pt.useContext(Se);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var ft=pt__namespace.forwardRef(function({screenshot:t,tool:n,color:o="rgb(239, 68, 68)",strokeWidth:a=4,onDrawingChange:r},i){let l=pt.useRef(null),s=pt.useRef(null),c=pt.useRef(null),[m,p]=pt.useState(null),[g,E]=pt.useState([]),C=pt.useRef(null),w=pt.useRef(false),k=pt.useRef(0),M=pt.useRef(false);pt.useEffect(()=>{let f=false,b=null;return (async()=>{try{let v=await createImageBitmap(t);if(f){v.close?.();return}b=v,p(v);}catch{}})(),()=>{f=true,b?.close?.();}},[t]),pt.useEffect(()=>{if(!m)return;let f=l.current,b=s.current;if(!f||!b)return;f.width=m.width,f.height=m.height,b.width=m.width,b.height=m.height;let v=f.getContext("2d");v&&(v.imageSmoothingEnabled=false,v.drawImage(m,0,0));},[m]),pt.useEffect(()=>{let f=s.current;f&&ye(f,g,C.current);},[g]),pt.useImperativeHandle(i,()=>({hasAnnotations:()=>g.length>0,reset:()=>E([]),undo:()=>E(f=>f.length===0?f:f.slice(0,-1)),async flatten(){let f=C.current,b=f?[...g,f]:g;if(b.length===0||!m)return t;let v=document.createElement("canvas");v.width=m.width,v.height=m.height;let R=v.getContext("2d");if(!R)return t;R.imageSmoothingEnabled=false,R.drawImage(m,0,0);for(let S of b)De(R,S);return await new Promise(S=>{v.toBlob(D=>{S(D??t);},"image/jpeg",.85);})}}),[g,m,t]);function T(f){let b=s.current;if(!b)return {x:0,y:0};let v=b.getBoundingClientRect(),R=b.width/Math.max(v.width,1),S=b.height/Math.max(v.height,1);return {x:(f.clientX-v.left)*R,y:(f.clientY-v.top)*S}}function N(){M.current||(M.current=true,requestAnimationFrame(()=>{M.current=false;let f=s.current;f&&ye(f,g,C.current);}));}function P(f){if(f.button!==void 0&&f.button!==0)return;try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}w.current=true,r?.(true);let b=T(f);n==="arrow"?C.current={kind:"arrow",from:b,to:b,color:o,width:a}:n==="rect"?C.current={kind:"rect",from:b,to:b,color:o,width:a}:C.current={kind:"freehand",points:[b],color:o,width:a},k.current=performance.now(),N();}function F(f){if(!w.current||!C.current)return;let b=T(f),v=C.current;if(v.kind==="arrow"||v.kind==="rect")v.to=b;else {let R=v.points[v.points.length-1],S=R?(R.x-b.x)**2+(R.y-b.y)**2:1/0,D=performance.now(),U=D-k.current;(S>16||U>16)&&(v.points.push(b),k.current=D);}N();}function A(){if(!w.current)return;w.current=false,r?.(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,v=f.to.y-f.from.y;if(b*b+v*v<16){let R=s.current;R&&ye(R,g,null);return}}else if(f.points.length<2){let b=s.current;b&&ye(b,g,null);return}E(b=>[...b,f].slice(-50));}}return jsxRuntime.jsxs("div",{ref:c,className:"lumen-annotate-frame",children:[jsxRuntime.jsx("canvas",{ref:l}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:P,onPointerMove:F,onPointerUp:A,onPointerCancel:A})]})});function ye(e,t,n){let o=e.getContext("2d");if(o){o.clearRect(0,0,e.width,e.height);for(let a of t)De(o,a);n&&De(o,n);}}function De(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let n=Math.min(t.from.x,t.to.x),o=Math.min(t.from.y,t.to.y),a=Math.abs(t.to.x-t.from.x),r=Math.abs(t.to.y-t.from.y);e.strokeRect(n,o,a,r);}else if(t.kind==="freehand")_n(e,t.points);else {let{from:n,to:o,width:a}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(o.x,o.y),e.stroke();let r=Math.atan2(o.y-n.y,o.x-n.x),i=Math.max(12,a*4);e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x-i*Math.cos(r-Math.PI/7),o.y-i*Math.sin(r-Math.PI/7)),e.lineTo(o.x-i*Math.cos(r+Math.PI/7),o.y-i*Math.sin(r+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function _n(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 a=t[1];e.lineTo(a.x,a.y),e.stroke();return}for(let a=1;a<t.length-1;a++){let r=t[a],i=t[a+1],l=(r.x+i.x)/2,s=(r.y+i.y)/2;e.quadraticCurveTo(r.x,r.y,l,s);}let o=t[t.length-1];e.lineTo(o.x,o.y),e.stroke();}var Ie=60,Un=60,gt=[{label:"Red",value:"rgb(239, 68, 68)"},{label:"Amber",value:"rgb(245, 158, 11)"},{label:"Blue",value:"rgb(59, 130, 246)"},{label:"Green",value:"rgb(34, 197, 94)"},{label:"Neutral",value:"rgb(244, 244, 245)"}],ht=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],bt=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],Vn=[{value:"shot",label:"Screenshot",hint:"This page, instantly"},{value:"screen",label:"Screen",hint:"Pick a window or tab"},{value:"video",label:"Video",hint:"Record up to 60s"}];function He(){let{client:e,isOpen:t,closeCapture:n,user:o,capture:a,initialCapture:r,initialCaptureError:i}=ue(),[l,s]=pt.useState(1),[c,m]=pt.useState(null),[p,g]=pt.useState({kind:"idle"}),[E,C]=pt.useState(false),[w,k]=pt.useState(0),[M,T]=pt.useState(null),[N,P]=pt.useState(false),[F,A]=pt.useState("arrow"),[f,b]=pt.useState(gt[0].value),[v,R]=pt.useState(ht[1].value),[S,D]=pt.useState(""),[U,K]=pt.useState("bug"),[j,ae]=pt.useState(o?.email??""),[I,B]=pt.useState(null),[_,Y]=pt.useState(null),[ce,ne]=pt.useState(0),[z,oe]=pt.useState(null),[$,V]=pt.useState(null),[O,Z]=pt.useState(false),de=pt.useRef(null),Ve=pt.useRef(null),Be=pt.useRef(null),ie=pt.useRef(false);if(pt.useEffect(()=>{if(t)return ie.current=false,s(1),m(null),D(""),Y(null),ne(0),V(null),C(false),k(0),T(null),P(false),oe(u=>(u?.cancel(),null)),r?(m("shot"),g({kind:"ready",capture:r})):a?.mode==="manual"?g({kind:"manual"}):g({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."}),()=>{ie.current=true;}},[t,a,r,i]),pt.useEffect(()=>{if(!t)return;Be.current=document.activeElement??null;let u=document.documentElement,y=u.style.overflow,H=u.style.paddingRight,W=window.innerWidth-u.clientWidth;u.style.overflow="hidden",W>0&&(u.style.paddingRight=`${W}px`);let q=false,G=()=>{if(!q){q=true,u.style.overflow=y,u.style.paddingRight=H;try{Be.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",G),()=>{window.removeEventListener("pagehide",G),G();}},[t]),pt.useEffect(()=>{if(!t)return;function u(y){if(y.key==="Escape"){y.preventDefault(),n();return}if(y.key!=="Tab")return;let H=Ve.current;if(!H)return;let W=Yn(H);if(W.length===0)return;let q=W[0],G=W[W.length-1],Te=document.activeElement;y.shiftKey&&(Te===q||!H.contains(Te))?(y.preventDefault(),G.focus()):!y.shiftKey&&Te===G&&(y.preventDefault(),q.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),pt.useEffect(()=>{if(!t||p.kind!=="manual")return;function u(y){let q=Array.from(y.clipboardData?.items??[]).find(G=>G.type.startsWith("image/"))?.getAsFile();q&&(y.preventDefault(),We(q));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,p.kind]),pt.useEffect(()=>{if(!I)return;let u=Date.now(),y=window.setInterval(()=>{let H=Math.floor((Date.now()-u)/1e3);ne(H),H>=Ie&&Me();},250);return ()=>window.clearInterval(y)},[I]),!t)return null;async function ke(u){ie.current=false,g({kind:"capturing"});try{let y=await be({...a,mode:u,target:a?.target??document.documentElement});return ie.current?!1:(Wt(y),g({kind:"ready",capture:y}),!0)}catch(y){return ie.current||g({kind:"manual",error:y instanceof Error?y.message:"Automatic screenshot capture was unavailable."}),false}}async function ze(u){m(u),T(null),u!=="video"&&Ke(),u==="shot"?await ke(a?.mode??"auto"):u==="screen"?await ke("true-screen"):await ke(a?.mode??"auto")&&await $e();}function We(u){if(!u.type.startsWith("image/")){sonner.toast.error("Choose a PNG, JPEG, or WebP screenshot.");return}let y=tt(u,["Manual screenshot upload used."]);g({kind:"ready",capture:y});}function Wt(u){u.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function qe(){try{let u=await ut(Ie);B(u);}catch(u){sonner.toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Me(){if(I)try{let u=await I.stop();Y({blob:u.blob,durationMs:u.durationMs});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{B(null);}}function qt(){I?.cancel(),B(null),Y(null),ne(0);}async function $e(){try{let u=await ct(Un);oe(u),u.stream.getVideoTracks()[0]?.addEventListener("ended",()=>{me();});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}async function me(){if(!z)return;let u=z;oe(null);try{let y=await u.stop();V({blob:y.blob,durationMs:y.durationMs});}catch(y){sonner.toast.error(y instanceof Error?y.message:"Could not stop recording");}}function Ke(){z?.cancel(),oe(null),V(null);}let $t=p.kind==="ready";async function Kt(){if(I&&await Me(),l===1){if(z&&await me(),p.kind==="ready"){let u=await de.current?.flatten();T(u??p.capture.blob),P(u!=null&&u!==p.capture.blob);}s(2);}else l===2?s(3):await Yt();}function jt(){l>1&&s(u=>u-1);}async function Yt(){if(p.kind!=="ready")return;let u=S.trim(),{capture:y}=p;C(true),k(0);try{let H=M??y.blob,W=await e.submit({rawText:u.length>0?u:void 0,category:U,submitterEmail:j.trim()||void 0,screenshot:H,audio:_?.blob,audioDurationMs:_?.durationMs,video:$?.blob,videoDurationMs:$?.durationMs,context:lt(y)},{onUploadProgress:q=>k(Math.min(.95,q))});k(1),sonner.toast.success("Feedback sent \u2014 thank you."),W.id,n();}catch(H){sonner.toast.error(H instanceof Error?H.message:"Could not submit feedback"),C(false);}}function Gt(u){u.target===u.currentTarget&&!E&&n();}let pe=Math.round(w*100),Re=c==="video",Xt=l===1&&!$t||E,Jt=l<3?"Next":E?pe<95?`Uploading ${pe}%\u2026`:"Almost done\u2026":"Send feedback";return jsxRuntime.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:Gt,children:jsxRuntime.jsxs("div",{ref:Ve,className:"lumen-modal","data-lumen-drawing":O?"true":void 0,children:[jsxRuntime.jsx(zn,{onDismiss:n}),jsxRuntime.jsxs("header",{className:"lumen-modal-header",children:[jsxRuntime.jsxs("h2",{className:"lumen-modal-title",children:[jsxRuntime.jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsxRuntime.jsx(Bn,{step:l}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[l===1?jsxRuntime.jsxs("div",{className:"lumen-pane",children:[jsxRuntime.jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:Vn.map(u=>jsxRuntime.jsxs("button",{type:"button",className:"lumen-method-btn","aria-pressed":c===u.value,onClick:()=>ze(u.value),disabled:p.kind==="capturing",children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]},u.value))}),p.kind==="idle"?jsxRuntime.jsxs("div",{className:"lumen-cap-empty",children:[jsxRuntime.jsx("p",{children:"Pick a capture method above, or upload a screenshot."}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>g({kind:"manual"}),children:"Or upload a screenshot"})]}):null,p.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,p.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:p.error?"Automatic capture was unavailable. Upload or paste a screenshot to continue.":"Upload or paste a screenshot to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:"Choose or paste a screenshot"}),jsxRuntime.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:u=>{let y=u.currentTarget.files?.[0];y&&We(y),u.currentTarget.value="";}})]})]}):null,p.kind==="ready"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Re?null:jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(Oe,{label:"Arrow",active:F==="arrow",onClick:()=>A("arrow")}),jsxRuntime.jsx(Oe,{label:"Box",active:F==="rect",onClick:()=>A("rect")}),jsxRuntime.jsx(Oe,{label:"Draw",active:F==="freehand",onClick:()=>A("freehand")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:gt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":f===u.value,onClick:()=>b(u.value)},u.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:ht.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":v===u.value,onClick:()=>R(u.value),children:jsxRuntime.jsx("span",{className:"lumen-stroke-size-dot",style:{width:u.dot,height:u.dot}})},u.value))}),jsxRuntime.jsx("span",{className:"lumen-toolbar-spacer"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>de.current?.undo(),children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>de.current?.reset(),children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(ft,{ref:de,screenshot:p.capture.blob,tool:F,color:f,strokeWidth:v,onDrawingChange:Z})}),jsxRuntime.jsxs("div",{className:"lumen-cap-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>c&&ze(c),children:Re?"\u21BB Re-record":"\u21BB Recapture"}),Re?z?jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"lumen-rec-time",children:"Recording\u2026"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:me,children:"Stop"})]}):$?jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round($.durationMs/1e3),"s recorded"]}):null:jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:[wt(c)," captured \xB7 switch method above anytime"]})]})]}):null]}):null,l===2?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-form",children:[jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"What happened?"}),jsxRuntime.jsx("textarea",{value:S,onChange:u=>D(u.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Add a voice note (optional)"}),jsxRuntime.jsxs("div",{className:"lumen-audio-row",children:[!I&&!_?jsxRuntime.jsx("button",{type:"button",onClick:qe,className:"lumen-btn-ghost",children:"Record voice note"}):null,I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(Wn,{stream:I.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[ce,"s / ",Ie,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:Me,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:qt,className:"lumen-btn-ghost",children:"Cancel"})]}):null,_&&!I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx($n,{blob:_.blob,durationMs:_.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>Y(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Category"}),jsxRuntime.jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:bt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":U===u.value,onClick:()=>K(u.value),children:u.label},u.value))})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Your email (optional)"}),jsxRuntime.jsx("input",{type:"email",value:j,onChange:u=>ae(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,l===3?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-review",children:[jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[wt(c),N?" \xB7 annotated":"",jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>s(1),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Category"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[jsxRuntime.jsx("span",{className:"lumen-chip",children:bt.find(u=>u.value===U)?.label}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>s(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Description"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[S.trim()?S.trim():jsxRuntime.jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>s(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Material"}),jsxRuntime.jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[_?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(_.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>Y(null),children:"\xD7"})]}):null,$?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round($.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Ke,children:"\xD7"})]}):null,j.trim()?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u2709 ",j.trim()]}):null,!_&&!I?jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{s(2),qe();},children:"+ Voice note"}):null,z?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-attach",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),"Recording\u2026"]}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:me,children:"Stop"})]}):$?null:jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:$e,children:"+ Screen recording"})]})]})]}):null]}),jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[E?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":pe,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${pe}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:l===1?n:jt,className:"lumen-btn-ghost",disabled:E,children:l===1?"Cancel":"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:Kt,className:"lumen-btn-primary",disabled:Xt,children:Jt})]})]})]})})}function wt(e){return e==="video"?"Screen recording":e==="screen"?"Screen capture":"Screenshot"}function Bn({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsxRuntime.jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,o)=>jsxRuntime.jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsxRuntime.jsx("span",{className:"lumen-step-num",children:n.n}),jsxRuntime.jsx("span",{className:"lumen-step-lbl",children:n.label}),o<t.length-1?jsxRuntime.jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function Oe({label:e,active:t,onClick:n}){return jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function zn({onDismiss:e}){let t=pt.useRef(null),n=pt.useRef(0),o=pt.useRef(null);function a(l){l.currentTarget.setPointerCapture(l.pointerId),t.current=l.clientY,n.current=performance.now(),o.current=l.currentTarget.parentElement;}function r(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current);o.current.style.transform=`translateY(${s}px)`;}function i(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current),c=Math.max(1,performance.now()-n.current),m=s/c;o.current.style.transform="",o.current.style.transition="",t.current=null,(s>80||m>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:a,onPointerMove:r,onPointerUp:i,onPointerCancel:i})}function Wn({stream:e}){let t=pt.useRef(null);return pt.useEffect(()=>{let n=t.current;if(!n)return;let o=Math.min(window.devicePixelRatio||1,2),a=n.clientWidth||88,r=n.clientHeight||22;n.width=Math.round(a*o),n.height=Math.round(r*o);let i=n.getContext("2d");if(!i)return;i.scale(o,o);let l=window.AudioContext??window.webkitAudioContext;if(!l)return;let s=new l,c=s.createMediaStreamSource(e),m=s.createAnalyser();m.fftSize=1024,m.smoothingTimeConstant=.6,c.connect(m);let p=new Uint8Array(m.fftSize),g=18,E=3,C=3,w=Math.max(2,(a-E*(g-1))/g),k=Math.min(w/2,3),M=new Array(g).fill(0),T=0,N=false;function P(){if(N)return;m.getByteTimeDomainData(p);let F=Math.floor(p.length/g);i.clearRect(0,0,a,r),i.fillStyle=Kn("--lumen-danger")||"rgb(239,68,68)";for(let A=0;A<g;A++){let f=0;for(let U=0;U<F;U++){let K=Math.abs((p[A*F+U]??128)-128);K>f&&(f=K);}let b=Math.min(1,f/128*1.8),v=M[A]??0;M[A]=b>v?b:v+(b-v)*.35;let R=Math.max(C,M[A]*r),S=A*(w+E),D=(r-R)/2;qn(i,S,D,w,R,k),i.fill();}T=requestAnimationFrame(P);}return T=requestAnimationFrame(P),()=>{N=true,cancelAnimationFrame(T);try{c.disconnect();}catch{}s.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function qn(e,t,n,o,a,r){let i=Math.min(r,o/2,a/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,o,a,i);return}e.moveTo(t+i,n),e.arcTo(t+o,n,t+o,n+a,i),e.arcTo(t+o,n+a,t,n+a,i),e.arcTo(t,n+a,t,n,i),e.arcTo(t,n,t+o,n,i),e.closePath();}function $n({blob:e,durationMs:t}){let[n,o]=pt.useState("");return pt.useEffect(()=>{let a=URL.createObjectURL(e);return o(a),()=>{URL.revokeObjectURL(a);}},[e]),jsxRuntime.jsxs("div",{className:"lumen-audio-preview",children:[jsxRuntime.jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxRuntime.jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function Kn(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var jn='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Yn(e){return Array.from(e.querySelectorAll(jn)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function vt(){if(typeof document>"u"||typeof window>"u")return 0;let e=window.innerWidth,t=window.innerHeight;if(e===0||t===0)return 0;let n=t-4,o=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],a=new Set,r=0;for(let i of o){let l=document.elementsFromPoint(i,n);for(let s of l){if(a.has(s))continue;a.add(s);let c=window.getComputedStyle(s);if(c.position!=="fixed"&&c.position!=="sticky")continue;let m=s.getBoundingClientRect();m.bottom<t-8||m.bottom>t+8||m.width<e*.6||m.height>r&&(r=m.height);}}return r}function _e(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,o=window.innerHeight,a=0;for(let r of e){let i;try{i=document.querySelectorAll(r);}catch{continue}for(let l of Array.from(i)){let s=l.getBoundingClientRect();if(s.height===0||s.width===0)continue;let c=0;switch(t){case "bottom":if(s.bottom<o-8)break;c=Math.max(0,o-s.top);break;case "top":if(s.top>8)break;c=Math.max(0,s.bottom);break;case "left":if(s.left>8)break;c=Math.max(0,s.right);break;case "right":if(s.right<n-8)break;c=Math.max(0,n-s.left);break}c>a&&(a=c);}}return a}function yt(e){let[t,n]=pt.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),o=pt.useRef(t),a=Zn(e.avoid),r=e.placement,i=e.offset.x,l=e.offset.y;return pt.useEffect(()=>{if(typeof window>"u")return;let s=0,c=false,m=()=>{if(s=0,c)return;let w=r[0]==="b"?"bottom":"top",k=r[1]==="r"?"right":"left",M=0,T=0;e.avoid==="auto"&&w==="bottom"?M=vt():Array.isArray(e.avoid)&&(M=_e(e.avoid,w),T=_e(e.avoid,k));let N={bottom:w==="bottom"?l+M:0,top:w==="top"?l+M:0,right:k==="right"?i+T:0,left:k==="left"?i+T:0},P=o.current;(N.bottom!==P.bottom||N.top!==P.top||N.right!==P.right||N.left!==P.left)&&(o.current=N,n(N));},p=()=>{s||(s=window.requestAnimationFrame(m));};p();let g=typeof ResizeObserver<"u"?new ResizeObserver(p):null;g?.observe(document.documentElement);let E=typeof MutationObserver<"u"?new MutationObserver(p):null;E?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",p);let C=window.visualViewport;return C?.addEventListener("resize",p),C?.addEventListener("scroll",p),()=>{c=true,s&&window.cancelAnimationFrame(s),g?.disconnect(),E?.disconnect(),window.removeEventListener("resize",p),C?.removeEventListener("resize",p),C?.removeEventListener("scroll",p);}},[r,i,l,a]),t}function Zn(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function Et(e){let[t,n]=pt.useState(false);return pt.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;let o=window.visualViewport;if(!o||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let a=100,r=0,i=()=>{r=0;let s=window.innerHeight-o.height;n(s>a);},l=()=>{r||(r=window.requestAnimationFrame(i));};return l(),o.addEventListener("resize",l),o.addEventListener("scroll",l),()=>{r&&window.cancelAnimationFrame(r),o.removeEventListener("resize",l),o.removeEventListener("scroll",l);}},[e]),t}function Mt({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:a}){let[r,i]=pt.useState(null),l=pt.useRef(null),s=yt(e),c=Et(e.hideOnKeyboard);if(pt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),oo(l,!n&&!c),!r)return null;let m=e.placement,p=m[0]==="b"?"bottom":"top",g=m[1]==="r"?"right":"left",E=p==="bottom"?s.bottom:s.top,C=g==="right"?s.right:s.left,w={position:"fixed",[p]:e.safeArea?`calc(${E}px + env(safe-area-inset-${p}, 0px))`:`${E}px`,[g]:e.safeArea?`calc(${C}px + env(safe-area-inset-${g}, 0px))`:`${C}px`,zIndex:e.zIndex,opacity:n||c?0:1,pointerEvents:n||c?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:w,"aria-label":e.label,"aria-hidden":n||c?true:void 0,tabIndex:n||c?-1:0,onPointerDown:k=>o?.(k.nativeEvent),onClick:k=>a(k.nativeEvent),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),r)}function oo(e,t){let n=pt.useRef(false);pt.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let o=window.setTimeout(()=>{let a=e.current;if(!a)return;let r=a.getBoundingClientRect();if(r.width===0||r.height===0)return;let i=r.left+r.width/2,l=r.top+r.height/2,s=document.elementsFromPoint(i,l),c=Ct(window.getComputedStyle(a).zIndex);for(let m of s){if(m===a||a.contains(m))continue;if(Ct(window.getComputedStyle(m).zIndex)>c){n.current=true,console.warn("[lumen] trigger is occluded by",m);break}}},250);return ()=>window.clearTimeout(o)},[t,e]);}function Ct(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function Rt({mount:e,label:t,icon:n,onPointerDown:o,onClick:a}){let[r,i]=pt.useState(null);return pt.useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;i(l);},[e]),r?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onPointerDown:l=>o?.(l.nativeEvent),onClick:l=>a(l.nativeEvent),"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsxRuntime.jsx("span",{children:t})]}),r):null}function Nt({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:a}){let[r,i]=pt.useState(null),[l,s]=pt.useState(false),c=pt.useRef(null);if(pt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),!r)return null;let m=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function p(w){o?.(w.nativeEvent),c.current={x:w.clientX,y:w.clientY},s(true),w.currentTarget.setPointerCapture(w.pointerId);}function g(w){let k=c.current;if(!k)return;let M=w.clientX-k.x,T=w.clientY-k.y;(e.edge==="top"&&T>16||e.edge==="bottom"&&T<-16||e.edge==="right"&&M<-16||e.edge==="left"&&M>16)&&(c.current=null,a(w.nativeEvent));}function E(){c.current=null,s(false);}function C(){c.current=null,s(false);}return reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:m,style:{zIndex:e.zIndex,opacity:n?0:1,pointerEvents:n?"none":"auto"},"aria-label":e.label,"aria-hidden":n?true:void 0,tabIndex:n?-1:0,onClick:w=>a(w.nativeEvent),onPointerDown:p,onPointerMove:g,onPointerUp:E,onPointerCancel:C,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),r)}function At(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function St(e){return {kind:"floating",placement:e.placement??"br",offset:{x:e.offset?.x??16,y:e.offset?.y??16},safeArea:e.safeArea??true,avoid:e.avoid===false?false:e.avoid==null?"auto":Array.isArray(e.avoid)?e.avoid:[e.avoid],hideOnKeyboard:e.hideOnKeyboard??true,zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var wo={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function Pt(e){let t=pt.useId();pt.useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,o=`data-lumen-theme-${vo(t)}`,a={};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")a["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else for(let[r,i]of Object.entries(wo)){let l=e[i];typeof l=="string"&&l.length>0&&(a[r]=n.style.getPropertyValue(r)||null,n.style.setProperty(r,l));}return n.setAttribute(o,""),()=>{n.removeAttribute(o);for(let[r,i]of Object.entries(a))r.startsWith("--")?i?n.style.setProperty(r,i):n.style.removeProperty(r):i==null?n.removeAttribute(r):n.setAttribute(r,i);}},[e,t]);}function vo(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var Dt=Symbol.for("lumen.history.patched"),Fe="lumen:locationchange";function Co(){if(typeof window>"u")return;let e=window;if(e[Dt])return;e[Dt]=true;let t=()=>window.dispatchEvent(new Event(Fe)),n=history.pushState;history.pushState=function(...a){let r=n.apply(this,a);return t(),r};let o=history.replaceState;history.replaceState=function(...a){let r=o.apply(this,a);return t(),r},window.addEventListener("popstate",t);}function It(e){let[t,n]=pt.useState(false);return pt.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;Co();let o=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return o(),window.addEventListener(Fe,o),window.addEventListener("popstate",o),()=>{window.removeEventListener(Fe,o),window.removeEventListener("popstate",o);}},[e]),t}var Mo=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function Ot(){let[e,t]=pt.useState(false);return pt.useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let o=n.webkit;if(o&&o.messageHandlers){t(true);return}let a=navigator.userAgent||"";Mo.some(r=>a.includes(r))&&t(true);},[]),e}var _t="lumen.config.v1.",Lo=3600*1e3;function Ft(e,t){let[n,o]=pt.useState(()=>({trigger:null,enabled:true,shakeToOpen:false,loading:true}));return pt.useEffect(()=>{if(typeof window>"u")return;let a=Po(e);a&&o({trigger:a.trigger,enabled:Ht(a.trigger),shakeToOpen:a.shake,loading:false});let r=new AbortController,i=window.setTimeout(()=>r.abort(),5e3),l=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(l,{method:"GET",mode:"cors",credentials:"omit",signal:r.signal}).then(async s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);let c=await s.json(),m=Ut(c.trigger);if(!m)throw new Error("Malformed config response");let p=So(c.trigger);Do(e,m,p),o({trigger:m,enabled:Ht(m),shakeToOpen:p,loading:false});}).catch(()=>{o(s=>s.loading?{trigger:null,enabled:true,shakeToOpen:false,loading:false}:s);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),r.abort();}},[e,t]),n}function Ht(e){return e.kind!=="headless"}var No=["br","bl","tr","tl"],Ao=["top","right","bottom","left"];function Ut(e){if(!e||typeof e!="object")return null;let t=e;if(t.enabled===false)return {kind:"headless"};let n=typeof t.label=="string"?t.label:"Feedback";return t.kind==="floating"?{kind:"floating",placement:No.find(a=>a===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:Ao.find(a=>a===t.edge)??"top",label:n}:null}function So(e){return !e||typeof e!="object"?false:e.shake===true}function Po(e){try{let t=window.localStorage.getItem(_t+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>Lo)return null;let o=Ut(n.trigger);return o?{fetchedAt:n.fetchedAt,trigger:o,shake:n.shake===!0}:null}catch{return null}}function Do(e,t,n){try{window.localStorage.setItem(_t+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n}));}catch{}}function Oo(e){if(e&&typeof e=="object")return e.type===ve;if(typeof e=="string")try{return JSON.parse(e).type===ve}catch{return false}return false}function Ho(e={}){let t=e.threshold??18,n=e.neededHits??3,o=e.windowMs??700,a=e.throttleMs??60,r=null,i=[];return {push(l,s,c,m){if(!r)return r={x:l,y:s,z:c,t:m},false;if(m-r.t<a)return false;let p=Math.abs(l-r.x)+Math.abs(s-r.y)+Math.abs(c-r.z);return r={x:l,y:s,z:c,t:m},p<t?false:(i=i.filter(g=>m-g<o),i.push(m),i.length>=n?(i=[],true):false)}}}function Vt(e,t,n){pt.useEffect(()=>{if(!e||typeof window>"u")return;let o=0,a=1500;function r(){let m=Date.now();n||m-o<a||(o=m,t());}let i=m=>{Oo(m.data)&&r();};window.addEventListener("message",i),document.addEventListener("message",i);let l=Ho(),s=m=>{let p=m.accelerationIncludingGravity??m.acceleration;!p||p.x==null||p.y==null||p.z==null||l.push(p.x,p.y,p.z,Date.now())&&r();},c=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return c&&window.addEventListener("devicemotion",s),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),c&&window.removeEventListener("devicemotion",s);}},[e,t,n]);}var zt="https://shakebugs.vercel.app";function _o({apiKey:e,apiUrl:t,user:n,amplitude:o,floatingButton:a=true,trigger:r,hideOn:i,theme:l,portalTarget:s,capture:c,shakeToOpen:m,onOpenChange:p,beforeOpen:g,onTriggerActivate:E,children:C}){let[w,k]=pt.useState(false),[M,T]=pt.useState(false),[N,P]=pt.useState(null),[F,A]=pt.useState(null),[f]=pt.useState(false),[b]=pt.useState(null),v=pt.useRef(false),R=pt.useRef(false),S=pt.useRef(null),D=pt.useMemo(()=>new et({apiKey:e,apiUrl:t,user:n,amplitude:o}),[e,t,n?.id,n?.email,n?.name,o?.userId,o?.deviceId,o?.sessionId]);pt.useEffect(()=>{it({ignoreUrlPrefix:(t??zt).replace(/\/$/,"")});},[t]);let U=pt.useRef(p);U.current=p,pt.useEffect(()=>{if(!(typeof document>"u"))return w?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[w]);let K=pt.useRef(null);pt.useEffect(()=>{if(K.current===w)return;let O=K.current;K.current=w,O!==null&&U.current?.(w);},[w]);let j=pt.useRef(g);j.current=g;let ae=pt.useRef(E);ae.current=E;let I=pt.useCallback(O=>{R.current=true,S.current=Promise.resolve().then(()=>j.current?.(O)).then(()=>ae.current?.(O)).then(()=>{});},[]),B=pt.useCallback(O=>{v.current||w||(v.current=true,T(true),P(null),A(null),(async()=>{try{if(R.current?await S.current:(await j.current?.(O),await ae.current?.(O)),c?.mode==="manual")P(null),A(null);else {let Z=await be({...c,mode:c?.mode??"auto",target:c?.target??document.documentElement});P(Z);}}catch(Z){A(Z instanceof Error?Z:new Error(String(Z)));}finally{R.current=false,S.current=null,v.current=false,T(false),k(true);}})());},[c,w]),_=pt.useCallback(()=>k(false),[]),Y=pt.useCallback(D.submit.bind(D),[D]),ce=Ot(),ne=It(i);Pt(l);let z=Ft(r?"":e,t??zt),oe=m??z.shakeToOpen;Vt(oe,B,w);let $=pt.useMemo(()=>({client:D,user:n,isOpen:w,isSubmitting:f,error:b,open:B,close:_,openCapture:B,closeCapture:_,submit:Y,isNativeShell:ce,capture:c,initialCapture:N,initialCaptureError:F,isOpening:M}),[D,n,w,f,b,B,_,Y,ce,c,N,F,M]),V=Fo({explicit:r,remote:z.trigger,remoteLoading:z.loading,floatingButton:a});return jsxRuntime.jsxs(Se.Provider,{value:$,children:[C,V?.kind==="floating"?jsxRuntime.jsx(Mt,{config:St(V),portalTarget:s,hidden:ne||M,onPointerDown:I,onClick:O=>B(O)}):null,V?.kind==="notch"?jsxRuntime.jsx(Nt,{config:At(V),portalTarget:s,hidden:ne||M,onPointerDown:I,onClick:O=>B(O)}):null,V?.kind==="inline"?jsxRuntime.jsx(Rt,{mount:V.mount,label:V.label??"Feedback",icon:V.icon,onPointerDown:I,onClick:O=>B(O)}):null,jsxRuntime.jsx(He,{})]})}function Fo(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function Vo({variant:e="default",floating:t=false,className:n,children:o="Feedback",onClick:a,...r}){let{openCapture:i}=ue(),l=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsxRuntime.jsx("button",{type:"button",className:l,"data-lumen-trigger":"",onClick:s=>{a?.(s),s.defaultPrevented||i(s.nativeEvent);},...r,children:o})}
|
|
4
|
-
exports.CaptureModal=
|
|
2
|
+
'use strict';var kt=require('react'),sonner=require('sonner'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var kt__namespace=/*#__PURE__*/_interopNamespace(kt);var R=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},at=class extends R{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},it=class extends R{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},Se=class extends R{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},wn="https://shakebugs.vercel.app",yn="/api/v1/sdk/submit",En=new Set([502,503,504]),mt=class{apiKey;apiUrl;user;amplitude;constructor(e){if(!e.apiKey||!e.apiKey.startsWith("lk_pub_"))throw new R("Invalid Lumen apiKey \u2014 expected a key starting with `lk_pub_`.","INVALID_API_KEY");this.apiKey=e.apiKey,this.apiUrl=(e.apiUrl??wn).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${yn}`,o=this.#e(e),r=null;for(let a=0;a<3;a++){a>0&&await xn(2**a*250);try{return await this.#t(n,o,t)}catch(i){if(r=i,i instanceof at||i instanceof it||i instanceof R&&typeof i.status=="number"&&!En.has(i.status))throw i}}throw r instanceof Error?r:new Se("Submit failed after 3 attempts.")}#e(e){let t=new FormData;e.rawText&&t.append("rawText",e.rawText),e.category&&t.append("category",e.category),e.submitterEmail&&t.append("submitterEmail",e.submitterEmail),e.submitterFingerprint&&t.append("submitterFingerprint",e.submitterFingerprint);let n=e.context.amplitude??this.amplitude,o=n?{...e.context,amplitude:n}:e.context;return t.append("context",JSON.stringify(o)),e.screenshot&&t.append("screenshot",e.screenshot,Cn(e.screenshot)),e.audio&&t.append("audio",e.audio,"audio"),e.audioDurationMs!=null&&t.append("audioDurationMs",String(e.audioDurationMs)),e.video&&t.append("video",e.video,"video"),e.videoDurationMs!=null&&t.append("videoDurationMs",String(e.videoDurationMs)),t}#t(e,t,n){return new Promise((o,r)=>{let a=new XMLHttpRequest;a.open("POST",e,true),a.setRequestHeader("X-Lumen-Api-Key",this.apiKey),a.responseType="text";let{onUploadProgress:i,signal:l}=n;i&&a.upload.addEventListener("progress",c=>{c.lengthComputable&&c.total>0&&i(Math.min(1,c.loaded/c.total));});let s=()=>{a.abort(),r(new Se("Submit aborted."));};if(l){if(l.aborted){r(new Se("Submit aborted."));return}l.addEventListener("abort",s,{once:true});}a.addEventListener("load",()=>{if(l&&l.removeEventListener("abort",s),a.status===403){r(new at);return}if(a.status===429){let c=Number(a.getResponseHeader("Retry-After"))||60;r(new it(c));return}if(a.status<200||a.status>=300){r(new R(kn(a.responseText)??`HTTP ${a.status}`,"HTTP_ERROR",a.status));return}try{let c=JSON.parse(a.responseText);o(c);}catch{r(new R("Malformed response from server.","BAD_RESPONSE"));}}),a.addEventListener("error",()=>{l&&l.removeEventListener("abort",s),r(new Se("Network error during submit."));}),a.send(t);})}};function Cn(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function xn(e){return new Promise(t=>setTimeout(t,e))}function kn(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var Mn=2,we=8*1024*1024;async function Pe(e={}){gt();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return Tn(await e.provider(),e)}catch(n){if(t==="custom")throw n;e.onWarning?.(["Custom capture provider failed; falling back to browser DOM capture."]);}if(t==="manual")throw new R("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return st(e);if(t==="dom")return lt(e);if(t==="custom")throw new R("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await lt(e)}catch(n){if(ft()){let o=await st(e);return o.warnings=Ee(["DOM screenshot failed; used browser screen permission fallback.",...o.warnings]),e.onWarning?.(o.warnings),o}throw n}}function ye(e,t=[]){gt();let n=Ae();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:Ee(t)}}async function lt(e){let t=await Rn(),n=e.target??document.documentElement,o=Ae(),r=Math.max(1,Math.min(window.devicePixelRatio??1,e.maxScale??Mn)),a=Sn(n),i=await t(n,{backgroundColor:null,logging:false,useCORS:true,allowTaint:false,width:o.width,height:o.height,windowWidth:o.width,windowHeight:o.height,scrollX:window.scrollX,scrollY:window.scrollY,x:window.scrollX,y:window.scrollY,scale:r,ignoreElements:s=>s instanceof HTMLElement&&(s.dataset.lumenCaptureIgnore==="true"||!!s.closest("[data-lumen-capture-ignore='true']"))}),l={blob:await pt(i,a),method:"web-dom",platform:"web",viewport:o,pixelRatio:r,warnings:Ee(a)};return l.warnings.length>0&&e.onWarning?.(l.warnings),l}async function Rn(){let{default:e}=await import('html2canvas-pro');return e}async function st(e){if(!ft())throw new R("Browser screen capture is unavailable in this environment.","DISPLAY_MEDIA_UNAVAILABLE");let t=await navigator.mediaDevices.getDisplayMedia({video:true,audio:false});try{let n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.srcObject=t,await Ln(n);let o=document.createElement("canvas");o.width=n.videoWidth,o.height=n.videoHeight;let r=o.getContext("2d");if(!r)throw new R("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");r.drawImage(n,0,0,o.width,o.height);let a=Ae(),i=["Browser screen capture uses the window or tab selected by the user."],l={blob:await pt(o,i),method:"web-display-media",platform:"web",viewport:a,pixelRatio:a.width>0?o.width/a.width:void 0,warnings:Ee(i)};return e.onWarning?.(l.warnings),l}finally{for(let n of t.getTracks())n.stop();}}function Tn(e,t){let n=Ae(),o={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:Ee(e.warnings??[])};return o.warnings.length>0&&t.onWarning?.(o.warnings),o}function Sn(e){let t=new Set;e.querySelector("iframe")&&t.add("Embedded iframes may be blank or incomplete in DOM capture."),e.querySelector("video")&&t.add("Video frames may be blank or stale in DOM capture."),e.querySelector("canvas")&&t.add("Canvas/WebGL content may be blank if it is cross-origin tainted."),document.fonts&&document.fonts.status!=="loaded"&&t.add("Web fonts were still loading when the screenshot was captured.");let n=0;for(let o of Array.from(e.querySelectorAll("img"))){let r=o.currentSrc||o.src;if(r)try{new URL(r,window.location.href).origin!==window.location.origin&&!o.crossOrigin&&(n+=1);}catch{}}return n>0&&t.add(`${n} cross-origin image${n===1?"":"s"} without CORS may be omitted from the screenshot.`),Array.from(t)}async function pt(e,t){let n=await ut(e,"image/png",.92);if(n.size<=we)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let o=e,r=0;for(;n.size>we&&r<6;){let a=Math.max(.35,Math.min(.95,Math.sqrt(we/n.size)*.9)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(o.width*a)),i.height=Math.max(1,Math.round(o.height*a));let l=i.getContext("2d");if(!l)return n;l.drawImage(o,0,0,i.width,i.height),o=i;for(let s of [.86,.74,.62,.5])if(n=await ut(o,"image/jpeg",s),n.size<=we)return n;if(r+=1,i.width<480||i.height<320)break}return n.size>we&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function ut(e,t,n){return new Promise((o,r)=>{e.toBlob(a=>{if(!a){r(new R("Could not encode screenshot.","ENCODE_FAILED"));return}o(a);},t,n);})}function Ae(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function ft(){return !!navigator.mediaDevices?.getDisplayMedia}async function Ln(e){await new Promise((o,r)=>{let a=()=>o(),i=()=>r(new R("Could not read screen capture video.","VIDEO_FAILED"));e.addEventListener("loadedmetadata",a,{once:true}),e.addEventListener("error",i,{once:true}),e.play().catch(i);});let t=performance.now(),n=1500;for(;e.videoWidth===0||e.videoHeight===0;){if(performance.now()-t>n)throw new R("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(o=>requestAnimationFrame(()=>o()));}}function gt(){if(typeof window>"u"||typeof document>"u")throw new R("Screenshot capture can only run in the browser.","INVALID_ENV")}function Ee(e){return Array.from(new Set(e.filter(Boolean)))}var ht=[],Le=[],ct=false,Ue=null;function bt(e={}){ct||typeof window>"u"||(ct=true,Ue=e.ignoreUrlPrefix??null,In(),Dn(),On());}function Nn(){return {consoleLog:ht.slice(),networkLog:Le.slice()}}function Ne(e,t){e.push(t),e.length>200&&e.splice(0,e.length-200);}function Pn(e){let t=[];for(let o of e){if(typeof o=="string"){t.push(o);continue}if(o instanceof Error){t.push(`${o.name}: ${o.message}${o.stack?`
|
|
3
|
+
${o.stack}`:""}`);continue}try{t.push(JSON.stringify(o,An));}catch{t.push(String(o));}}let n=t.join(" ");return n.length>4096?n.slice(0,4096)+"\u2026[truncated]":n}function An(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function In(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let o=e[n]?.bind(e);o&&(e[n]=(...r)=>{try{Ne(ht,{level:n,ts:Date.now(),message:Pn(r)});}catch{}o(...r);});}}function vt(e){return Ue?e.startsWith(Ue):false}function Dn(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let o=typeof t=="string"?t:t instanceof URL?t.toString():t.url,r=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(vt(o))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return Ne(Le,{type:"fetch",method:r,url:We(o),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw Ne(Le,{type:"fetch",method:r,url:We(o),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function On(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(o,r,...a){return this.__lumen={method:String(o).toUpperCase(),url:typeof r=="string"?r:r.toString(),t:0},t.call(this,o,r,...a)},e.prototype.send=function(o){let r=this.__lumen;if(r&&!vt(r.url)){r.t=performance.now();let a=()=>{try{Ne(Le,{type:"xhr",method:r.method,url:We(r.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-r.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",a);};this.addEventListener("loadend",a);}return n.call(this,o??null)};}function We(e){return e.length>512?e.slice(0,512)+"\u2026":e}function wt(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:dt(e),consoleLog:[],networkLog:[]};let t=Nn();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:dt(e),device:Hn(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function Hn(){let e={};try{e.screen={width:window.screen?.width??0,height:window.screen?.height??0},e.pixelRatio=window.devicePixelRatio??1,e.language=navigator.language,e.languages=Array.from(navigator.languages??[]),e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.colorScheme=window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light",e.referrer=document.referrer||void 0,e.title=document.title||void 0,e.online=navigator.onLine,performance.getEntriesByType("navigation")[0]&&(e.uptimeMs=Math.round(performance.now()));}catch{}return e}function dt(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var Ie="lumen:shake",Vn=8e3,Fn=50,Bn='[data-lumen-root], [data-lumen-capture-ignore="true"]';function _n(e={}){return async function(){if(typeof window>"u")throw new R("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=Wn(),n=e.send??Un,o=e.timeoutMs??Vn,r=e.captureSettleMs??Fn,a=Gn(),i=$n(e.concealSelector===void 0?Bn:e.concealSelector);try{await qn(r);let l=await new Promise((d,p)=>{let b=window.setTimeout(()=>{t.pending.delete(a),p(new R("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},o);t.pending.set(a,{resolve:y=>{window.clearTimeout(b),d(y);},reject:y=>{window.clearTimeout(b),p(y);}});try{n({type:"lumen:capture-request",id:a,afterScreenUpdates:!0});}catch{t.pending.delete(a),window.clearTimeout(b),p(new R("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new R(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let s=Yn(l.dataUrl),c=e.platform??Kn();return {blob:s,method:c==="android"?"android-native":"ios-native",platform:c,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:l.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{i();}}}function Un(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new R("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function Wn(){if(window.__lumenNativeCapture)return window.__lumenNativeCapture;let e={pending:new Map,resolve(n,o,r){let a=e.pending.get(n);a&&(e.pending.delete(n),a.resolve({type:"lumen:capture-response",id:n,dataUrl:o,pixelRatio:r}));},reject(n,o){let r=e.pending.get(n);r&&(e.pending.delete(n),r.resolve({type:"lumen:capture-response",id:n,error:o}));}},t=n=>{let o=zn(n.data);if(!o||o.type!=="lumen:capture-response")return;let r=e.pending.get(o.id);r&&(e.pending.delete(o.id),r.resolve(o));};return window.addEventListener("message",t),document.addEventListener("message",t),window.__lumenNativeCapture=e,e}function zn(e){if(e&&typeof e=="object"&&"type"in e)return e;if(typeof e=="string")try{let t=JSON.parse(e);if(t&&typeof t=="object"&&t.type)return t}catch{}return null}function $n(e){if(!e||typeof document>"u")return ()=>{};let t=[];for(let n of Array.from(document.querySelectorAll(e)))t.push({el:n,prev:n.style.visibility}),n.style.visibility="hidden";return ()=>{for(let{el:n,prev:o}of t)n.style.visibility=o;}}async function qn(e){await jn(),e>0&&await new Promise(t=>window.setTimeout(t,e));}function jn(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function Kn(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function Gn(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Yn(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new R("Native host returned an invalid image data URL.","NATIVE_CAPTURE_FAILED");let n=t[1]||"image/png",o=!!t[2],r=t[3]??"";if(!o)return new Blob([decodeURIComponent(r)],{type:n});let a=atob(r),i=new Uint8Array(a.length);for(let l=0;l<a.length;l++)i[l]=a.charCodeAt(l);return new Blob([i],{type:n})}var Xn="[data-lumen-root]",Jn="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function Zn(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(ze(n))return true;return ze(e.target)}function ze(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(Jn)?true:!!e.closest(Xn):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?ze(e.host):false:false}async function yt(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new R("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new R("Microphone access denied or unavailable.","MIC_DENIED")}let n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(s=>MediaRecorder.isTypeSupported(s))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),r=[],a=performance.now(),i=null;o.addEventListener("dataavailable",s=>{s.data&&s.data.size>0&&r.push(s.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);function l(){i!==null&&window.clearTimeout(i),i=null;for(let s of t.getTracks())s.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}l();},stop(){return new Promise((s,c)=>{if(o.state==="inactive"){l(),c(new R("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let d=performance.now()-a,p=o.mimeType||n||"audio/webm",b=new Blob(r,{type:p});l(),s({blob:b,durationMs:d,mimeType:p});},{once:true}),o.stop();})}}}async function Et(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new R("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new R("Screen capture was denied or cancelled.","SCREEN_DENIED")}let n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(g=>MediaRecorder.isTypeSupported(g))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),r=[],a=performance.now(),i=null,l=false,s=false,c,d,p=new Promise((g,v)=>{c=g,d=v;});p.catch(()=>{});function b(){i!==null&&(window.clearTimeout(i),i=null);for(let g of t.getTracks())g.stop();}o.addEventListener("dataavailable",g=>{g.data&&g.data.size>0&&r.push(g.data);}),o.addEventListener("stop",()=>{if(l)return;if(l=true,b(),s){d(new R("Recording cancelled.","RECORDER_STOPPED"));return}let g=o.mimeType||n||"video/webm";c({blob:new Blob(r,{type:g}),durationMs:performance.now()-a,mimeType:g});});function y(){o.state!=="inactive"&&o.stop();}return o.start(),i=window.setTimeout(y,e*1e3),t.getVideoTracks()[0]?.addEventListener("ended",y),{stream:t,result:p,stop:y,cancel(){s=true,o.state!=="inactive"?o.stop():l||(l=true,b(),d(new R("Recording cancelled.","RECORDER_STOPPED")));}}}var $e=kt.createContext(null);function Ce(){let e=kt.useContext($e);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var je='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, sans-serif';function xt(e,t=1){return Math.max(0,Math.min(t,e))}var Mt=kt__namespace.forwardRef(function({screenshot:t,tool:n,color:o="rgb(239, 68, 68)",strokeWidth:r=4,onDrawingChange:a},i){let l=kt.useRef(null),s=kt.useRef(null),c=kt.useRef(null),[d,p]=kt.useState(null),[b,y]=kt.useState([]),g=kt.useRef(null),v=kt.useRef(false),k=kt.useRef(0),N=kt.useRef(false),[T,L]=kt.useState([]),A=kt.useRef(0),H=kt.useRef([]),P=kt.useRef(null),V=kt.useCallback((f,h)=>{L(E=>E.map(x=>x.id===f?{...x,text:h}:x));},[]),_=kt.useCallback(f=>{L(E=>E.filter(x=>x.id!==f));let h=H.current.lastIndexOf("comment");h>=0&&H.current.splice(h,1);},[]);kt.useEffect(()=>{let f=P.current;if(f==null)return;P.current=null,c.current?.querySelector(`[data-bubble-id="${f}"] .lumen-bubble-text`)?.focus();},[T]),kt.useEffect(()=>{let f=false,h=null;return (async()=>{try{let E=await createImageBitmap(t);if(f){E.close?.();return}h=E,p(E);}catch{}})(),()=>{f=true,h?.close?.();}},[t]),kt.useEffect(()=>{if(!d)return;let f=l.current,h=s.current;if(!f||!h)return;f.width=d.width,f.height=d.height,h.width=d.width,h.height=d.height;let E=f.getContext("2d");E&&(E.imageSmoothingEnabled=false,E.drawImage(d,0,0));},[d]),kt.useEffect(()=>{let f=s.current;f&&De(f,b,g.current);},[b]),kt.useImperativeHandle(i,()=>({hasAnnotations:()=>b.length>0||T.some(f=>f.text.trim().length>0),reset:()=>{y([]),L([]),H.current=[];},undo:()=>{(H.current.pop()??"anno")==="comment"?L(h=>h.length===0?h:h.slice(0,-1)):y(h=>h.length===0?h:h.slice(0,-1));},async flatten(){let f=g.current,h=f?[...b,f]:b,E=T.filter(S=>S.text.trim().length>0);if(h.length===0&&E.length===0||!d)return t;let x=document.createElement("canvas");x.width=d.width,x.height=d.height;let D=x.getContext("2d");if(!D)return t;D.imageSmoothingEnabled=false,D.drawImage(d,0,0);for(let S of h)Ke(D,S);let I=l.current?.clientWidth||d.width,W=d.width/Math.max(I,1);for(let S of E)ao(D,S,d.width,d.height,W);return await new Promise(S=>{x.toBlob(G=>{S(G??t);},"image/jpeg",.85);})}}),[b,T,d,t]);function U(f){let h=s.current;if(!h)return {x:0,y:0};let E=h.getBoundingClientRect(),x=h.width/Math.max(E.width,1),D=h.height/Math.max(E.height,1);return {x:(f.clientX-E.left)*x,y:(f.clientY-E.top)*D}}function j(){N.current||(N.current=true,requestAnimationFrame(()=>{N.current=false;let f=s.current;f&&De(f,b,g.current);}));}function J(f){if(f.button!==void 0&&f.button!==0)return;if(n==="comment"){let E=s.current;if(!E)return;let x=E.getBoundingClientRect(),D=xt((f.clientX-x.left)/Math.max(x.width,1),.72),I=xt((f.clientY-x.top)/Math.max(x.height,1),.8),W=++A.current;L(S=>[...S,{id:W,x:D,y:I,text:"",color:o}]),H.current.push("comment"),P.current=W;return}try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}v.current=true,a?.(true);let h=U(f);n==="arrow"?g.current={kind:"arrow",from:h,to:h,color:o,width:r}:n==="rect"?g.current={kind:"rect",from:h,to:h,color:o,width:r}:g.current={kind:"freehand",points:[h],color:o,width:r},k.current=performance.now(),j();}function K(f){if(!v.current||!g.current)return;let h=U(f),E=g.current;if(E.kind==="arrow"||E.kind==="rect")E.to=h;else {let x=E.points[E.points.length-1],D=x?(x.x-h.x)**2+(x.y-h.y)**2:1/0,I=performance.now(),W=I-k.current;(D>16||W>16)&&(E.points.push(h),k.current=I);}j();}function B(){if(!v.current)return;v.current=false,a?.(false);let f=g.current;if(g.current=null,!!f){if(f.kind==="arrow"||f.kind==="rect"){let h=f.to.x-f.from.x,E=f.to.y-f.from.y;if(h*h+E*E<16){let x=s.current;x&&De(x,b,null);return}}else if(f.points.length<2){let h=s.current;h&&De(h,b,null);return}y(h=>[...h,f].slice(-50)),H.current.push("anno");}}return jsxRuntime.jsxs("div",{ref:c,className:"lumen-annotate-frame","data-lumen-tool":n,children:[jsxRuntime.jsx("canvas",{ref:l}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:J,onPointerMove:K,onPointerUp:B,onPointerCancel:B}),jsxRuntime.jsx("div",{className:"lumen-bubble-layer",children:T.map(f=>jsxRuntime.jsx(oo,{comment:f,onChange:V,onRemove:_},f.id))})]})});function oo({comment:e,onChange:t,onRemove:n}){let o=kt.useRef(null);return kt.useEffect(()=>{let r=o.current;r&&r.textContent!==e.text&&(r.textContent=e.text);},[]),jsxRuntime.jsxs("div",{className:"lumen-bubble","data-bubble-id":e.id,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,"--lumen-bubble-accent":e.color},onPointerDown:r=>r.stopPropagation(),children:[jsxRuntime.jsx("span",{className:"lumen-bubble-label",children:"Comment"}),jsxRuntime.jsx("div",{ref:o,className:"lumen-bubble-text",contentEditable:true,suppressContentEditableWarning:true,role:"textbox","aria-label":"Comment text","data-placeholder":"Type a note\u2026",onInput:r=>t(e.id,r.currentTarget.textContent??"")}),jsxRuntime.jsx("button",{type:"button",className:"lumen-bubble-del","aria-label":"Remove comment",onPointerDown:r=>r.stopPropagation(),onClick:()=>n(e.id),children:"\xD7"})]})}function De(e,t,n){let o=e.getContext("2d");if(o){o.clearRect(0,0,e.width,e.height);for(let r of t)Ke(o,r);n&&Ke(o,n);}}function Ke(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let n=Math.min(t.from.x,t.to.x),o=Math.min(t.from.y,t.to.y),r=Math.abs(t.to.x-t.from.x),a=Math.abs(t.to.y-t.from.y);e.strokeRect(n,o,r,a);}else if(t.kind==="freehand")ro(e,t.points);else {let{from:n,to:o,width:r}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(o.x,o.y),e.stroke();let a=Math.atan2(o.y-n.y,o.x-n.x),i=Math.max(12,r*4);e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x-i*Math.cos(a-Math.PI/7),o.y-i*Math.sin(a-Math.PI/7)),e.lineTo(o.x-i*Math.cos(a+Math.PI/7),o.y-i*Math.sin(a+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function ro(e,t){if(t.length===0)return;e.beginPath();let n=t[0];if(!n)return;if(e.moveTo(n.x,n.y),t.length===1){e.arc(n.x,n.y,e.lineWidth/2,0,Math.PI*2),e.fill();return}if(t.length===2){let r=t[1];e.lineTo(r.x,r.y),e.stroke();return}for(let r=1;r<t.length-1;r++){let a=t[r],i=t[r+1],l=(a.x+i.x)/2,s=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,l,s);}let o=t[t.length-1];e.lineTo(o.x,o.y),e.stroke();}function ao(e,t,n,o,r){let a=t.text.trim();if(!a)return;let i=10*r,l=14*r,s=10*r,c=12*r,d=l*1.35,p=s*1.7,b=t.x*n,y=t.y*o,g=Math.min(n*.6,n-b-8*r);e.save(),e.font=`500 ${l}px ${je}`,e.textBaseline="top";let v=io(e,a,g-i*2),k=v.reduce((P,V)=>Math.max(P,e.measureText(V).width),0),N=Math.min(g,Math.max(k,56*r)+i*2),T=i*2+p+v.length*d;lo(e,b,y,N,T,c),e.fillStyle="#ffffff",e.fill(),e.lineWidth=Math.max(1,r),e.strokeStyle="rgba(0,0,0,0.10)",e.stroke();let L=b+18*r,A=y+T;e.beginPath(),e.moveTo(L,A-r),e.lineTo(L+13*r,A-r),e.lineTo(L+4*r,A+9*r),e.closePath(),e.fillStyle="#ffffff",e.fill(),e.fillStyle=t.color||"rgb(239, 68, 68)",e.font=`700 ${s}px ${je}`,e.fillText("COMMENT",b+i,y+i),e.fillStyle="#111318",e.font=`500 ${l}px ${je}`;let H=y+i+p;for(let P of v)e.fillText(P,b+i,H),H+=d;e.restore();}function io(e,t,n){let o=t.split(/\s+/).filter(Boolean),r=[],a="";for(let i of o){let l=a?`${a} ${i}`:i;a&&e.measureText(l).width>n?(r.push(a),a=i):a=l;}return a&&r.push(a),r.length?r:[t]}function lo(e,t,n,o,r,a){let i=Math.min(a,o/2,r/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,o,r,i);return}e.moveTo(t+i,n),e.arcTo(t+o,n,t+o,n+r,i),e.arcTo(t+o,n+r,t,n+r,i),e.arcTo(t,n+r,t,n,i),e.arcTo(t,n,t+o,n,i),e.closePath();}function Ge({children:e,...t}){return jsxRuntime.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...t,children:e})}function so(e){return jsxRuntime.jsxs(Ge,{...e,children:[jsxRuntime.jsx("path",{d:"M3 9a2 2 0 0 1 2-2h1.5l1-1.5h5l1 1.5H19a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"13",r:"3.2"})]})}function uo(e){return jsxRuntime.jsxs(Ge,{...e,children:[jsxRuntime.jsx("rect",{x:"3",y:"6",width:"13",height:"12",rx:"2.5"}),jsxRuntime.jsx("path",{d:"m16 10 5-3v10l-5-3"})]})}function co(e){return jsxRuntime.jsxs(Ge,{...e,children:[jsxRuntime.jsx("path",{d:"M12 16V4m0 0 4 4m-4-4-4 4"}),jsxRuntime.jsx("path",{d:"M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})]})}var Ye={shot:so,video:uo,upload:co};function Tt(e){let t=e.videoWidth||1280,n=e.videoHeight||720,o=document.createElement("canvas");o.width=t,o.height=n;let r=o.getContext("2d");return r?(r.drawImage(e,0,0,t,n),new Promise(a=>o.toBlob(i=>a(i),"image/jpeg",.82))):Promise.resolve(null)}function mo(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();}})}async function St(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="metadata",n.src=t;try{await new Promise((a,i)=>{n.addEventListener("loadeddata",()=>a(),{once:!0}),n.addEventListener("error",()=>i(new Error("video decode failed")),{once:!0});}),await mo(n,Math.min(.1,(n.duration||0)/2));let o=await Tt(n),r=Number.isFinite(n.duration)?n.duration*1e3:0;return {poster:o,durationMs:r}}catch{return {poster:null,durationMs:0}}finally{URL.revokeObjectURL(t);}}async function Lt(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 Tt(t)}catch{return null}finally{t.srcObject=null;}}async function Je(){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(o=>n(o),"image/jpeg",.8))):null}var Ze=60,Nt=[{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)"}],Pt=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],At=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],It=[{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 Qe(){let{client:e,isOpen:t,closeCapture:n,user:o,capture:r,initialCapture:a,initialCaptureError:i,startVideoSession:l,consumePendingVideo:s}=Ce(),[c,d]=kt.useState(1),[p,b]=kt.useState(null),[y,g]=kt.useState({kind:"idle"}),[v,k]=kt.useState(false),[N,T]=kt.useState(0),[L,A]=kt.useState(null),[H,P]=kt.useState(false),[V,_]=kt.useState("arrow"),[U,j]=kt.useState(Nt[0].value),[J,K]=kt.useState(Pt[1].value),[B,f]=kt.useState(""),[h,E]=kt.useState("bug"),[x,D]=kt.useState(o?.email??""),[I,W]=kt.useState(null),[S,G]=kt.useState(null),[ne,Z]=kt.useState(0),[Q,oe]=kt.useState(null),Me=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",[fe,ge]=kt.useState(false),se=kt.useRef(null),he=kt.useRef(null),be=kt.useRef(null),ee=kt.useRef(false),ve=kt.useRef(false);if(kt.useEffect(()=>{t||(ve.current=false);},[t]),kt.useEffect(()=>{if(!t||ve.current)return;ve.current=true,ee.current=false,d(1),b(null),f(""),G(null),Z(0),oe(null),k(false),T(0),A(null),P(false);let u=s();return u?(b("video"),oe({blob:u.blob,durationMs:u.durationMs}),u.poster?g({kind:"ready",capture:ye(u.poster,["Screen recording; preview is the first frame."])}):(g({kind:"capturing"}),Je().then(C=>{ee.current||g(C?{kind:"ready",capture:ye(C,["Screen recording."])}:{kind:"manual"});}))):a?(b("shot"),g({kind:"ready",capture:a})):r?.mode==="manual"?g({kind:"manual"}):r?.provider&&!i?(b("shot"),Re(r.mode??"auto")):g({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."}),()=>{ee.current=true;}},[t,r,a,i]),kt.useEffect(()=>{if(!t)return;be.current=document.activeElement??null;let u=document.documentElement,C=u.style.overflow,F=u.style.paddingRight,z=window.innerWidth-u.clientWidth;u.style.overflow="hidden",z>0&&(u.style.paddingRight=`${z}px`);let q=false,ie=()=>{if(!q){q=true,u.style.overflow=C,u.style.paddingRight=F;try{be.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",ie),()=>{window.removeEventListener("pagehide",ie),ie();}},[t]),kt.useEffect(()=>{if(!t)return;function u(C){if(C.key==="Escape"){C.preventDefault(),n();return}if(C.key!=="Tab")return;let F=he.current;if(!F)return;let z=Eo(F);if(z.length===0)return;let q=z[0],ie=z[z.length-1],_e=document.activeElement;C.shiftKey&&(_e===q||!F.contains(_e))?(C.preventDefault(),ie.focus()):!C.shiftKey&&_e===ie&&(C.preventDefault(),q.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),kt.useEffect(()=>{if(!t||y.kind!=="manual")return;function u(C){let q=Array.from(C.clipboardData?.items??[]).find(ie=>ie.type.startsWith("image/"))?.getAsFile();q&&(C.preventDefault(),M(q));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,y.kind]),kt.useEffect(()=>{if(!I)return;let u=Date.now(),C=window.setInterval(()=>{let F=Math.floor((Date.now()-u)/1e3);Z(F),F>=Ze&&Ve();},250);return ()=>window.clearInterval(C)},[I]),!t)return null;async function Re(u){ee.current=false,g({kind:"capturing"});try{let C=await Pe({...r,mode:u,target:r?.target??document.documentElement});return ee.current?!1:(Y(C),g({kind:"ready",capture:C}),!0)}catch(C){return ee.current||g({kind:"manual",error:C instanceof Error?C.message:"Automatic screenshot capture was unavailable."}),false}}async function $(u){b(u),A(null),u!=="video"&&Fe(),u==="shot"?await Re(r?.mode??"auto"):u==="video"?(oe(null),g({kind:"idle"})):g({kind:"manual"});}async function M(u){if(u.type.startsWith("image/")){Fe();let C=ye(u,["Manual image upload used."]);g({kind:"ready",capture:C});return}if(u.type.startsWith("video/")){g({kind:"capturing"});try{let{poster:C,durationMs:F}=await St(u),z=C??await Je();if(!z){g({kind:"manual",error:"Could not read that video."});return}let q=ye(z,["Uploaded video; preview is the first frame."]);oe({blob:u,durationMs:F}),g({kind:"ready",capture:q});}catch{g({kind:"manual",error:"Could not read that video."});}return}sonner.toast.error("Choose an image (PNG, JPEG, WebP) or a video (MP4, WebM).");}function Y(u){u.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function rt(){try{let u=await yt(Ze);W(u);}catch(u){sonner.toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Ve(){if(I)try{let u=await I.stop();G({blob:u.blob,durationMs:u.durationMs});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{W(null);}}function cn(){I?.cancel(),W(null),G(null),Z(0);}async function dn(){try{await l();}catch(u){sonner.toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}function Fe(){oe(null);}let mn=y.kind==="ready";async function pn(){if(I&&await Ve(),c===1){if(y.kind==="ready"){let u=await se.current?.flatten();A(u??y.capture.blob),P(u!=null&&u!==y.capture.blob);}d(2);}else c===2?d(3):await gn();}function fn(){c>1&&d(u=>u-1);}async function gn(){if(y.kind!=="ready")return;let u=B.trim(),{capture:C}=y;k(true),T(0);try{let F=L??C.blob,z=await e.submit({rawText:u.length>0?u:void 0,category:h,submitterEmail:x.trim()||void 0,screenshot:F,audio:S?.blob,audioDurationMs:S?.durationMs,video:Q?.blob,videoDurationMs:Q?.durationMs,context:wt(C)},{onUploadProgress:q=>T(Math.min(.95,q))});T(1),sonner.toast.success("Feedback sent \u2014 thank you."),z.id,n();}catch(F){sonner.toast.error(F instanceof Error?F.message:"Could not submit feedback"),k(false);}}function hn(u){u.target===u.currentTarget&&!v&&n();}let Te=Math.round(N*100),Be=p==="video",bn=c===1&&!mn||v,vn=c<3?"Next":v?Te<95?`Uploading ${Te}%\u2026`:"Almost done\u2026":"Send feedback";return jsxRuntime.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:hn,children:jsxRuntime.jsxs("div",{ref:he,className:"lumen-modal","data-lumen-drawing":fe?"true":void 0,children:[jsxRuntime.jsx(go,{onDismiss:n}),jsxRuntime.jsxs("header",{className:"lumen-modal-header",children:[jsxRuntime.jsxs("h2",{className:"lumen-modal-title",children:[jsxRuntime.jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsxRuntime.jsx(po,{step:c}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[c===1?jsxRuntime.jsx("div",{className:"lumen-pane",children:p===null?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:It.map(u=>{let C=Ye[u.value];return jsxRuntime.jsxs("button",{type:"button",className:"lumen-method-btn"+(u.primary?" lumen-method-primary":""),onClick:()=>$(u.value),disabled:y.kind==="capturing",children:[jsxRuntime.jsx("span",{className:"lumen-method-ico",children:jsxRuntime.jsx(C,{})}),u.primary?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-method-text",children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]}),jsxRuntime.jsx("span",{className:"lumen-method-badge",children:"Fastest"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]})]},u.value)})}),jsxRuntime.jsx("p",{className:"lumen-status lumen-method-help",children:"Choose how to capture your feedback."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method-switch",role:"group","aria-label":"Switch capture method",children:It.map(u=>{let C=Ye[u.value];return jsxRuntime.jsxs("button",{type:"button","aria-pressed":p===u.value,onClick:()=>$(u.value),disabled:y.kind==="capturing",children:[jsxRuntime.jsx(C,{}),u.label]},u.value)})}),p==="video"&&y.kind==="idle"?jsxRuntime.jsx(fo,{canRecord:Me,onRecord:dn}):null,y.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,y.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:p==="upload"?"Choose an image or video to attach \u2014 or paste an image.":y.error?"Automatic capture was unavailable. Upload or paste an image to continue.":"Upload or paste an image to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:p==="upload"?"Choose a file \u2014 image or video":"Choose or paste an image"}),jsxRuntime.jsx("input",{type:"file",accept:p==="upload"?"image/png,image/jpeg,image/webp,video/mp4,video/webm,video/quicktime":"image/png,image/jpeg,image/webp",onChange:u=>{let C=u.currentTarget.files?.[0];C&&M(C),u.currentTarget.value="";}})]})]}):null,y.kind==="ready"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Be?null:jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(Oe,{label:"Arrow",active:V==="arrow",onClick:()=>_("arrow")}),jsxRuntime.jsx(Oe,{label:"Box",active:V==="rect",onClick:()=>_("rect")}),jsxRuntime.jsx(Oe,{label:"Draw",active:V==="freehand",onClick:()=>_("freehand")}),jsxRuntime.jsx(Oe,{label:"Comment",active:V==="comment",onClick:()=>_("comment")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:Nt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":U===u.value,onClick:()=>j(u.value)},u.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:Pt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":J===u.value,onClick:()=>K(u.value),children:jsxRuntime.jsx("span",{className:"lumen-stroke-size-dot",style:{width:u.dot,height:u.dot}})},u.value))}),jsxRuntime.jsx("span",{className:"lumen-toolbar-spacer"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>se.current?.undo(),children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>se.current?.reset(),children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(Mt,{ref:se,screenshot:y.capture.blob,tool:V,color:U,strokeWidth:J,onDrawingChange:ge})}),jsxRuntime.jsxs("div",{className:"lumen-cap-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>p&&$(p),children:Be?"\u21BB Re-record":"\u21BB Recapture"}),Be?Q?jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round(Q.durationMs/1e3),"s recorded"]}):null:jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:[Dt(p)," captured \xB7 switch method above anytime"]})]})]}):null]})}):null,c===2?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-form",children:[jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"What happened?"}),jsxRuntime.jsx("textarea",{value:B,onChange:u=>f(u.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Add a voice note (optional)"}),jsxRuntime.jsxs("div",{className:"lumen-audio-row",children:[!I&&!S?jsxRuntime.jsx("button",{type:"button",onClick:rt,className:"lumen-btn-ghost",children:"Record voice note"}):null,I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(ho,{stream:I.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[ne,"s / ",Ze,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:Ve,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:cn,className:"lumen-btn-ghost",children:"Cancel"})]}):null,S&&!I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(vo,{blob:S.blob,durationMs:S.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>G(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Category"}),jsxRuntime.jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:At.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":h===u.value,onClick:()=>E(u.value),children:u.label},u.value))})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Your email (optional)"}),jsxRuntime.jsx("input",{type:"email",value:x,onChange:u=>D(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,c===3?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-review",children:[jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[Dt(p),H?" \xB7 annotated":"",jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>d(1),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Category"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[jsxRuntime.jsx("span",{className:"lumen-chip",children:At.find(u=>u.value===h)?.label}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>d(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Description"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[B.trim()?B.trim():jsxRuntime.jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>d(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Material"}),jsxRuntime.jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[S?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(S.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>G(null),children:"\xD7"})]}):null,Q?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round(Q.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Fe,children:"\xD7"})]}):null,x.trim()?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u2709 ",x.trim()]}):null,!S&&!I?jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{d(2),rt();},children:"+ Voice note"}):null]})]})]}):null]}),jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[v?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Te,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${Te}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:c===1?n:fn,className:"lumen-btn-ghost",disabled:v,children:c===1?"Cancel":"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:pn,className:"lumen-btn-primary",disabled:bn,children:vn})]})]})]})})}function Dt(e){return e==="video"?"Screen recording":e==="upload"?"Upload":"Screenshot"}function po({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsxRuntime.jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,o)=>jsxRuntime.jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsxRuntime.jsx("span",{className:"lumen-step-num",children:n.n}),jsxRuntime.jsx("span",{className:"lumen-step-lbl",children:n.label}),o<t.length-1?jsxRuntime.jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function fo({canRecord:e,onRecord:t}){return e?jsxRuntime.jsxs("div",{className:"lumen-record-prompt",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-record-btn","aria-label":"Start screen recording",onClick:t}),jsxRuntime.jsxs("div",{className:"lumen-record-copy",children:[jsxRuntime.jsx("div",{className:"lumen-record-title",children:"Record your screen"}),jsxRuntime.jsx("div",{className:"lumen-record-sub",children:"Tap to start. The sheet closes so you can record freely \u2014 a Stop button stays on screen, then the sheet returns with your clip. Max 60s."})]})]}):jsxRuntime.jsx("div",{className:"lumen-record-prompt",children:jsxRuntime.jsxs("p",{className:"lumen-record-unavailable",children:["Screen recording isn\u2019t available in this browser. Switch to"," ",jsxRuntime.jsx("strong",{children:"Upload"})," to attach a video instead."]})})}function Oe({label:e,active:t,onClick:n}){return jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function go({onDismiss:e}){let t=kt.useRef(null),n=kt.useRef(0),o=kt.useRef(null);function r(l){l.currentTarget.setPointerCapture(l.pointerId),t.current=l.clientY,n.current=performance.now(),o.current=l.currentTarget.parentElement;}function a(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current);o.current.style.transform=`translateY(${s}px)`;}function i(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current),c=Math.max(1,performance.now()-n.current),d=s/c;o.current.style.transform="",o.current.style.transition="",t.current=null,(s>80||d>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:r,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function ho({stream:e}){let t=kt.useRef(null);return kt.useEffect(()=>{let n=t.current;if(!n)return;let o=Math.min(window.devicePixelRatio||1,2),r=n.clientWidth||88,a=n.clientHeight||22;n.width=Math.round(r*o),n.height=Math.round(a*o);let i=n.getContext("2d");if(!i)return;i.scale(o,o);let l=window.AudioContext??window.webkitAudioContext;if(!l)return;let s=new l,c=s.createMediaStreamSource(e),d=s.createAnalyser();d.fftSize=1024,d.smoothingTimeConstant=.6,c.connect(d);let p=new Uint8Array(d.fftSize),b=18,y=3,g=3,v=Math.max(2,(r-y*(b-1))/b),k=Math.min(v/2,3),N=new Array(b).fill(0),T=0,L=false;function A(){if(L)return;d.getByteTimeDomainData(p);let H=Math.floor(p.length/b);i.clearRect(0,0,r,a),i.fillStyle=wo("--lumen-danger")||"rgb(239,68,68)";for(let P=0;P<b;P++){let V=0;for(let B=0;B<H;B++){let f=Math.abs((p[P*H+B]??128)-128);f>V&&(V=f);}let _=Math.min(1,V/128*1.8),U=N[P]??0;N[P]=_>U?_:U+(_-U)*.35;let j=Math.max(g,N[P]*a),J=P*(v+y),K=(a-j)/2;bo(i,J,K,v,j,k),i.fill();}T=requestAnimationFrame(A);}return T=requestAnimationFrame(A),()=>{L=true,cancelAnimationFrame(T);try{c.disconnect();}catch{}s.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function bo(e,t,n,o,r,a){let i=Math.min(a,o/2,r/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,o,r,i);return}e.moveTo(t+i,n),e.arcTo(t+o,n,t+o,n+r,i),e.arcTo(t+o,n+r,t,n+r,i),e.arcTo(t,n+r,t,n,i),e.arcTo(t,n,t+o,n,i),e.closePath();}function vo({blob:e,durationMs:t}){let[n,o]=kt.useState("");return kt.useEffect(()=>{let r=URL.createObjectURL(e);return o(r),()=>{URL.revokeObjectURL(r);}},[e]),jsxRuntime.jsxs("div",{className:"lumen-audio-preview",children:[jsxRuntime.jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxRuntime.jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function wo(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var yo='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Eo(e){return Array.from(e.querySelectorAll(yo)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function Vt({startedAt:e,maxSeconds:t,portalTarget:n,onStop:o,onCancel:r}){let[a,i]=kt.useState(0),[l,s]=kt.useState(false);if(kt.useEffect(()=>s(true),[]),kt.useEffect(()=>{let p=()=>i(Math.min(t,Math.max(0,Math.floor((Date.now()-e)/1e3))));p();let b=window.setInterval(p,250);return ()=>window.clearInterval(b)},[e,t]),!l||typeof document>"u")return null;let c=n??document.body,d=p=>`${Math.floor(p/60)}:${String(p%60).padStart(2,"0")}`;return reactDom.createPortal(jsxRuntime.jsxs("div",{className:"lumen-rec-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-dot","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-rec-hud-time",children:[d(a)," ",jsxRuntime.jsxs("span",{className:"lumen-rec-hud-max",children:["/ ",d(t)]})]}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"}),jsxRuntime.jsxs("button",{type:"button",className:"lumen-rec-hud-stop",onClick:o,"aria-label":"Stop recording and return to feedback",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-square","aria-hidden":"true"}),"Stop"]})]}),c)}function Ft(){if(typeof document>"u"||typeof window>"u")return 0;let e=window.innerWidth,t=window.innerHeight;if(e===0||t===0)return 0;let n=t-4,o=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],r=new Set,a=0;for(let i of o){let l=document.elementsFromPoint(i,n);for(let s of l){if(r.has(s))continue;r.add(s);let c=window.getComputedStyle(s);if(c.position!=="fixed"&&c.position!=="sticky")continue;let d=s.getBoundingClientRect();d.bottom<t-8||d.bottom>t+8||d.width<e*.6||d.height>a&&(a=d.height);}}return a}function tt(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,o=window.innerHeight,r=0;for(let a of e){let i;try{i=document.querySelectorAll(a);}catch{continue}for(let l of Array.from(i)){let s=l.getBoundingClientRect();if(s.height===0||s.width===0)continue;let c=0;switch(t){case "bottom":if(s.bottom<o-8)break;c=Math.max(0,o-s.top);break;case "top":if(s.top>8)break;c=Math.max(0,s.bottom);break;case "left":if(s.left>8)break;c=Math.max(0,s.right);break;case "right":if(s.right<n-8)break;c=Math.max(0,n-s.left);break}c>r&&(r=c);}}return r}function Bt(e){let[t,n]=kt.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),o=kt.useRef(t),r=Ro(e.avoid),a=e.placement,i=e.offset.x,l=e.offset.y;return kt.useEffect(()=>{if(typeof window>"u")return;let s=0,c=false,d=()=>{if(s=0,c)return;let v=a[0]==="b"?"bottom":"top",k=a[1]==="r"?"right":"left",N=0,T=0;e.avoid==="auto"&&v==="bottom"?N=Ft():Array.isArray(e.avoid)&&(N=tt(e.avoid,v),T=tt(e.avoid,k));let L={bottom:v==="bottom"?l+N:0,top:v==="top"?l+N:0,right:k==="right"?i+T:0,left:k==="left"?i+T:0},A=o.current;(L.bottom!==A.bottom||L.top!==A.top||L.right!==A.right||L.left!==A.left)&&(o.current=L,n(L));},p=()=>{s||(s=window.requestAnimationFrame(d));};p();let b=typeof ResizeObserver<"u"?new ResizeObserver(p):null;b?.observe(document.documentElement);let y=typeof MutationObserver<"u"?new MutationObserver(p):null;y?.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),()=>{c=true,s&&window.cancelAnimationFrame(s),b?.disconnect(),y?.disconnect(),window.removeEventListener("resize",p),g?.removeEventListener("resize",p),g?.removeEventListener("scroll",p);}},[a,i,l,r]),t}function Ro(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function _t(e){let[t,n]=kt.useState(false);return kt.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;let o=window.visualViewport;if(!o||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let r=100,a=0,i=()=>{a=0;let s=window.innerHeight-o.height;n(s>r);},l=()=>{a||(a=window.requestAnimationFrame(i));};return l(),o.addEventListener("resize",l),o.addEventListener("scroll",l),()=>{a&&window.cancelAnimationFrame(a),o.removeEventListener("resize",l),o.removeEventListener("scroll",l);}},[e]),t}function $t({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:r}){let[a,i]=kt.useState(null),l=kt.useRef(null),s=Bt(e),c=_t(e.hideOnKeyboard);if(kt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),Po(l,!n&&!c),!a)return null;let d=e.placement,p=d[0]==="b"?"bottom":"top",b=d[1]==="r"?"right":"left",y=p==="bottom"?s.bottom:s.top,g=b==="right"?s.right:s.left,v={position:"fixed",[p]:e.safeArea?`calc(${y}px + env(safe-area-inset-${p}, 0px))`:`${y}px`,[b]:e.safeArea?`calc(${g}px + env(safe-area-inset-${b}, 0px))`:`${g}px`,zIndex:e.zIndex,opacity:n||c?0:1,pointerEvents:n||c?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:v,"aria-label":e.label,"aria-hidden":n||c?true:void 0,tabIndex:n||c?-1:0,onPointerDown:k=>o?.(k.nativeEvent),onClick:k=>r(k.nativeEvent),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),a)}function Po(e,t){let n=kt.useRef(false);kt.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let o=window.setTimeout(()=>{let r=e.current;if(!r)return;let a=r.getBoundingClientRect();if(a.width===0||a.height===0)return;let i=a.left+a.width/2,l=a.top+a.height/2,s=document.elementsFromPoint(i,l),c=Ut(window.getComputedStyle(r).zIndex);for(let d of s){if(d===r||r.contains(d))continue;if(Ut(window.getComputedStyle(d).zIndex)>c){n.current=true,console.warn("[lumen] trigger is occluded by",d);break}}},250);return ()=>window.clearTimeout(o)},[t,e]);}function Ut(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function qt({mount:e,label:t,icon:n,onPointerDown:o,onClick:r}){let[a,i]=kt.useState(null);return kt.useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;i(l);},[e]),a?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onPointerDown:l=>o?.(l.nativeEvent),onClick:l=>r(l.nativeEvent),"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsxRuntime.jsx("span",{children:t})]}),a):null}function Gt({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:r}){let[a,i]=kt.useState(null),[l,s]=kt.useState(false),c=kt.useRef(null);if(kt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),!a)return null;let d=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function p(v){o?.(v.nativeEvent),c.current={x:v.clientX,y:v.clientY},s(true),v.currentTarget.setPointerCapture(v.pointerId);}function b(v){let k=c.current;if(!k)return;let N=v.clientX-k.x,T=v.clientY-k.y;(e.edge==="top"&&T>16||e.edge==="bottom"&&T<-16||e.edge==="right"&&N<-16||e.edge==="left"&&N>16)&&(c.current=null,r(v.nativeEvent));}function y(){c.current=null,s(false);}function g(){c.current=null,s(false);}return reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:d,style:{zIndex:e.zIndex,opacity:n?0:1,pointerEvents:n?"none":"auto"},"aria-label":e.label,"aria-hidden":n?true:void 0,tabIndex:n?-1:0,onClick:v=>r(v.nativeEvent),onPointerDown:p,onPointerMove:b,onPointerUp:y,onPointerCancel:g,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),a)}function Yt(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function Xt(e){return {kind:"floating",placement:e.placement??"br",offset:{x:e.offset?.x??16,y:e.offset?.y??16},safeArea:e.safeArea??true,avoid:e.avoid===false?false:e.avoid==null?"auto":Array.isArray(e.avoid)?e.avoid:[e.avoid],hideOnKeyboard:e.hideOnKeyboard??true,zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var qo={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function Jt(e){let t=kt.useId();kt.useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,o=`data-lumen-theme-${jo(t)}`,r={};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")r["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else for(let[a,i]of Object.entries(qo)){let l=e[i];typeof l=="string"&&l.length>0&&(r[a]=n.style.getPropertyValue(a)||null,n.style.setProperty(a,l));}return n.setAttribute(o,""),()=>{n.removeAttribute(o);for(let[a,i]of Object.entries(r))a.startsWith("--")?i?n.style.setProperty(a,i):n.style.removeProperty(a):i==null?n.removeAttribute(a):n.setAttribute(a,i);}},[e,t]);}function jo(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var Zt=Symbol.for("lumen.history.patched"),nt="lumen:locationchange";function Yo(){if(typeof window>"u")return;let e=window;if(e[Zt])return;e[Zt]=true;let t=()=>window.dispatchEvent(new Event(nt)),n=history.pushState;history.pushState=function(...r){let a=n.apply(this,r);return t(),a};let o=history.replaceState;history.replaceState=function(...r){let a=o.apply(this,r);return t(),a},window.addEventListener("popstate",t);}function Qt(e){let[t,n]=kt.useState(false);return kt.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;Yo();let o=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return o(),window.addEventListener(nt,o),window.addEventListener("popstate",o),()=>{window.removeEventListener(nt,o),window.removeEventListener("popstate",o);}},[e]),t}var Zo=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function en(){let[e,t]=kt.useState(false);return kt.useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let o=n.webkit;if(o&&o.messageHandlers){t(true);return}let r=navigator.userAgent||"";Zo.some(a=>r.includes(a))&&t(true);},[]),e}var nn="lumen.config.v1.",tr=3600*1e3;function on(e,t){let[n,o]=kt.useState(()=>({trigger:null,enabled:true,shakeToOpen:false,loading:true}));return kt.useEffect(()=>{if(typeof window>"u")return;let r=ar(e);r&&o({trigger:r.trigger,enabled:tn(r.trigger),shakeToOpen:r.shake,loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),l=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(l,{method:"GET",mode:"cors",credentials:"omit",signal:a.signal}).then(async s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);let c=await s.json(),d=rn(c.trigger);if(!d)throw new Error("Malformed config response");let p=rr(c.trigger);ir(e,d,p),o({trigger:d,enabled:tn(d),shakeToOpen:p,loading:false});}).catch(()=>{o(s=>s.loading?{trigger:null,enabled:true,shakeToOpen:false,loading:false}:s);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function tn(e){return e.kind!=="headless"}var nr=["br","bl","tr","tl"],or=["top","right","bottom","left"];function rn(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:nr.find(r=>r===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:or.find(r=>r===t.edge)??"top",label:n}:null}function rr(e){return !e||typeof e!="object"?false:e.shake===true}function ar(e){try{let t=window.localStorage.getItem(nn+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>tr)return null;let o=rn(n.trigger);return o?{fetchedAt:n.fetchedAt,trigger:o,shake:n.shake===!0}:null}catch{return null}}function ir(e,t,n){try{window.localStorage.setItem(nn+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n}));}catch{}}function sr(e){if(e&&typeof e=="object")return e.type===Ie;if(typeof e=="string")try{return JSON.parse(e).type===Ie}catch{return false}return false}function ur(e={}){let t=e.threshold??18,n=e.neededHits??3,o=e.windowMs??700,r=e.throttleMs??60,a=null,i=[];return {push(l,s,c,d){if(!a)return a={x:l,y:s,z:c,t:d},false;if(d-a.t<r)return false;let p=Math.abs(l-a.x)+Math.abs(s-a.y)+Math.abs(c-a.z);return a={x:l,y:s,z:c,t:d},p<t?false:(i=i.filter(b=>d-b<o),i.push(d),i.length>=n?(i=[],true):false)}}}function an(e,t,n){kt.useEffect(()=>{if(!e||typeof window>"u")return;let o=0,r=1500;function a(){let d=Date.now();n||d-o<r||(o=d,t());}let i=d=>{sr(d.data)&&a();};window.addEventListener("message",i),document.addEventListener("message",i);let l=ur(),s=d=>{let p=d.accelerationIncludingGravity??d.acceleration;!p||p.x==null||p.y==null||p.z==null||l.push(p.x,p.y,p.z,Date.now())&&a();},c=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return c&&window.addEventListener("devicemotion",s),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),c&&window.removeEventListener("devicemotion",s);}},[e,t,n]);}var sn="https://shakebugs.vercel.app",un=60;function cr({apiKey:e,apiUrl:t,user:n,amplitude:o,floatingButton:r=true,trigger:a,hideOn:i,theme:l,portalTarget:s,capture:c,shakeToOpen:d,onOpenChange:p,beforeOpen:b,onTriggerActivate:y,children:g}){let[v,k]=kt.useState(false),[N,T]=kt.useState(false),[L,A]=kt.useState(null),[H,P]=kt.useState(null),[V]=kt.useState(false),[_]=kt.useState(null),U=kt.useRef(false),j=kt.useRef(false),J=kt.useRef(null),K=kt.useMemo(()=>new mt({apiKey:e,apiUrl:t,user:n,amplitude:o}),[e,t,n?.id,n?.email,n?.name,o?.userId,o?.deviceId,o?.sessionId]);kt.useEffect(()=>{bt({ignoreUrlPrefix:(t??sn).replace(/\/$/,"")});},[t]);let B=kt.useRef(p);B.current=p,kt.useEffect(()=>{if(!(typeof document>"u"))return v?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[v]);let f=kt.useRef(null);kt.useEffect(()=>{if(f.current===v)return;let M=f.current;f.current=v,M!==null&&B.current?.(v);},[v]);let h=kt.useRef(b);h.current=b;let E=kt.useRef(y);E.current=y;let x=kt.useCallback(M=>{j.current=true,J.current=Promise.resolve().then(()=>h.current?.(M)).then(()=>E.current?.(M)).then(()=>{});},[]),D=kt.useCallback(M=>{U.current||v||ne.current||(U.current=true,T(true),A(null),P(null),(async()=>{try{if(j.current?await J.current:(await h.current?.(M),await E.current?.(M)),c?.mode==="manual")A(null),P(null);else if(c?.provider)A(null),P(null);else {let Y=await Pe({...c,mode:c?.mode??"auto",target:c?.target??document.documentElement});A(Y);}}catch(Y){P(Y instanceof Error?Y:new Error(String(Y)));}finally{j.current=false,J.current=null,U.current=false,T(false),k(true);}})());},[c,v]),I=kt.useCallback(()=>k(false),[]),W=kt.useCallback(K.submit.bind(K),[K]),[S,G]=kt.useState(null),ne=kt.useRef(null),Z=kt.useRef(null),Q=kt.useRef(null),oe=kt.useCallback(M=>{if(ne.current=null,G(null),!M){Z.current=null;return}Q.current={blob:M.blob,durationMs:M.durationMs,poster:Z.current},Z.current=null,k(true);},[]),Me=kt.useCallback(async()=>{if(ne.current)return;let M=await Et(un);ne.current=M,Z.current=null,G({stream:M.stream,startedAt:Date.now(),maxSeconds:un}),k(false),Lt(M.stream).then(Y=>{Z.current=Y;}).catch(()=>{}),M.result.then(Y=>oe(Y)).catch(()=>oe(null));},[oe]),fe=kt.useCallback(()=>{ne.current?.stop();},[]),ge=kt.useCallback(()=>{let M=ne.current;ne.current=null,Z.current=null,G(null),M?.cancel(),A(null),P(null),k(true);},[]),se=kt.useCallback(()=>{let M=Q.current;return Q.current=null,M},[]),he=en(),be=Qt(i);Jt(l);let ee=on(a?"":e,t??sn),ve=d??ee.shakeToOpen;an(ve,D,v);let Re=kt.useMemo(()=>({client:K,user:n,isOpen:v,isSubmitting:V,error:_,open:D,close:I,openCapture:D,closeCapture:I,submit:W,isNativeShell:he,capture:c,initialCapture:L,initialCaptureError:H,isOpening:N,startVideoSession:Me,stopVideoSession:fe,cancelVideoSession:ge,recording:S,consumePendingVideo:se}),[K,n,v,V,_,D,I,W,he,c,L,H,Me,fe,ge,S,se,N]),$=dr({explicit:a,remote:ee.trigger,remoteLoading:ee.loading,floatingButton:r});return jsxRuntime.jsxs($e.Provider,{value:Re,children:[g,$?.kind==="floating"?jsxRuntime.jsx($t,{config:Xt($),portalTarget:s,hidden:be||N||S!=null,onPointerDown:x,onClick:M=>D(M)}):null,$?.kind==="notch"?jsxRuntime.jsx(Gt,{config:Yt($),portalTarget:s,hidden:be||N||S!=null,onPointerDown:x,onClick:M=>D(M)}):null,$?.kind==="inline"?jsxRuntime.jsx(qt,{mount:$.mount,label:$.label??"Feedback",icon:$.icon,onPointerDown:x,onClick:M=>D(M)}):null,S?jsxRuntime.jsx(Vt,{startedAt:S.startedAt,maxSeconds:S.maxSeconds,portalTarget:s,onStop:fe,onCancel:ge}):null,jsxRuntime.jsx(Qe,{})]})}function dr(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function pr({variant:e="default",floating:t=false,className:n,children:o="Feedback",onClick:r,...a}){let{openCapture:i}=Ce(),l=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsxRuntime.jsx("button",{type:"button",className:l,"data-lumen-trigger":"",onClick:s=>{r?.(s),s.defaultPrevented||i(s.nativeEvent);},...a,children:o})}
|
|
4
|
+
exports.CaptureModal=Qe;exports.FeedbackButton=pr;exports.LUMEN_SHAKE_MESSAGE=Ie;exports.LumenProvider=cr;exports.createNativeCaptureProvider=_n;exports.isLumenEventTarget=Zn;exports.useLumen=Ce;//# sourceMappingURL=index.cjs.map
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|