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