@lumen-stack/react 0.7.0 → 0.8.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/README.md +89 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -7
- package/dist/index.d.ts +46 -7
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/styles.css +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -171,6 +171,95 @@ The provider returns `{ blob, method, platform, viewport, pixelRatio,
|
|
|
171
171
|
warnings }`. See `docs/screenshot-ingestion.md` for raw API and native
|
|
172
172
|
bridge examples.
|
|
173
173
|
|
|
174
|
+
## Native screen recording (WebView hosts)
|
|
175
|
+
|
|
176
|
+
The Record tab uses the browser `getDisplayMedia` recorder by default — which
|
|
177
|
+
**does not exist on iOS** (Safari, PWAs, or WKWebView), so the tab shows an
|
|
178
|
+
unavailable message there. A native shell (e.g. an Expo/WKWebView host that
|
|
179
|
+
records via ReplayKit) can take over recording through the `record.provider`
|
|
180
|
+
extension point, mirroring `capture.provider` for screenshots.
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
<LumenProvider
|
|
184
|
+
apiKey="lk_pub_..."
|
|
185
|
+
record={
|
|
186
|
+
canUseNativeScreenRecording()
|
|
187
|
+
? { provider: lumenNativeRecordProvider }
|
|
188
|
+
: undefined
|
|
189
|
+
}
|
|
190
|
+
>
|
|
191
|
+
<App />
|
|
192
|
+
</LumenProvider>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### The provider contract
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
type LumenRecordProvider = (options: {
|
|
199
|
+
maxDurationSeconds: number;
|
|
200
|
+
}) => Promise<LumenRecordingSession> | LumenRecordingSession;
|
|
201
|
+
|
|
202
|
+
interface LumenRecordingSession {
|
|
203
|
+
/** Resolves with the finished clip; rejects with LumenError("RECORDER_STOPPED") when cancelled. */
|
|
204
|
+
result: Promise<LumenRecordingResult>;
|
|
205
|
+
/** Ask the recorder to stop; the clip then arrives via `result`. */
|
|
206
|
+
stop(): void;
|
|
207
|
+
/** Abort and discard the recording. */
|
|
208
|
+
cancel(): void;
|
|
209
|
+
/** Only present for browser getDisplayMedia recordings. Custom providers may omit it. */
|
|
210
|
+
stream?: MediaStream;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
interface LumenRecordingResult {
|
|
214
|
+
blob: Blob;
|
|
215
|
+
durationMs: number;
|
|
216
|
+
mimeType: string; // e.g. "video/webm" (browser) or "video/mp4" (native hosts)
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
A minimal native provider that forwards to the host bridge:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
// lumenNativeRecord.ts
|
|
224
|
+
export async function lumenNativeRecordProvider(
|
|
225
|
+
options: { maxDurationSeconds?: number } = {},
|
|
226
|
+
): Promise<LumenRecordingSession> {
|
|
227
|
+
const maxDurationSeconds =
|
|
228
|
+
typeof options.maxDurationSeconds === "number" && options.maxDurationSeconds > 0
|
|
229
|
+
? options.maxDurationSeconds
|
|
230
|
+
: 60;
|
|
231
|
+
return startNativeScreenRecording({
|
|
232
|
+
maxDurationMs: Math.round(maxDurationSeconds * 1000),
|
|
233
|
+
withMicrophone: true,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
How the widget drives it:
|
|
239
|
+
|
|
240
|
+
1. **Availability** — the Record tab is offered when (`record.provider` is set
|
|
241
|
+
and `record.isAvailable?.()` did not return `false`) **or** `getDisplayMedia`
|
|
242
|
+
exists. A set, available provider takes precedence. `isAvailable` is probed
|
|
243
|
+
when the sheet opens and defaults to `true` when omitted.
|
|
244
|
+
2. **Start** — on tap, Lumen **closes the sheet first** (so a native host never
|
|
245
|
+
captures the Lumen UI and the OS consent dialog shows over the app), then
|
|
246
|
+
calls `provider({ maxDurationSeconds: 60 })`. Starting may take **tens of
|
|
247
|
+
seconds** (first-use consent) — there is no widget-side timeout; reject from
|
|
248
|
+
your own timeout if needed. A reject surfaces an inline error on the Record
|
|
249
|
+
step (Upload offered as the fallback).
|
|
250
|
+
3. **Stop / auto-stop** — the floating Stop button calls `session.stop()` and
|
|
251
|
+
awaits `result`; a brief "Processing…" state covers the native encode +
|
|
252
|
+
transfer. If the host auto-stops at the cap, `result` simply resolves and the
|
|
253
|
+
sheet reopens with the clip — `stop()` need not be called.
|
|
254
|
+
4. **Cancel** — Discard calls `session.cancel()`; the `RECORDER_STOPPED`
|
|
255
|
+
rejection is swallowed and the user returns to the sheet without a clip.
|
|
256
|
+
5. **No live preview** — `stream` is optional; when absent the widget skips any
|
|
257
|
+
`MediaStream` preview and derives the clip thumbnail from the blob.
|
|
258
|
+
|
|
259
|
+
`result.mimeType` of `video/mp4` is supported end-to-end (preview + submit).
|
|
260
|
+
Note the server caps uploads at 25 MB — long native recordings can exceed that;
|
|
261
|
+
the widget warns at attach time when a clip is large.
|
|
262
|
+
|
|
174
263
|
---
|
|
175
264
|
|
|
176
265
|
## Inline mount
|
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 In(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let o=e[n]?.bind(e);o&&(e[n]=(...r)=>{try{Le(ht,{level:n,ts:Date.now(),message:Pn(r)});}catch{}o(...r);});}}function vt(e){return Ue?e.startsWith(Ue):false}function Dn(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let o=typeof t=="string"?t:t instanceof URL?t.toString():t.url,r=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(vt(o))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return Le(Se,{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 Le(Se,{type:"fetch",method:r,url:We(o),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function On(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(o,r,...a){return this.__lumen={method:String(o).toUpperCase(),url:typeof r=="string"?r:r.toString(),t:0},t.call(this,o,r,...a)},e.prototype.send=function(o){let r=this.__lumen;if(r&&!vt(r.url)){r.t=performance.now();let a=()=>{try{Le(Se,{type:"xhr",method:r.method,url:We(r.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-r.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",a);};this.addEventListener("loadend",a);}return n.call(this,o??null)};}function We(e){return e.length>512?e.slice(0,512)+"\u2026":e}function wt(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:dt(e),consoleLog:[],networkLog:[]};let t=Nn();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:dt(e),device:Hn(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function Hn(){let e={};try{e.screen={width:window.screen?.width??0,height:window.screen?.height??0},e.pixelRatio=window.devicePixelRatio??1,e.language=navigator.language,e.languages=Array.from(navigator.languages??[]),e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.colorScheme=window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light",e.referrer=document.referrer||void 0,e.title=document.title||void 0,e.online=navigator.onLine,performance.getEntriesByType("navigation")[0]&&(e.uptimeMs=Math.round(performance.now()));}catch{}return e}function dt(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var Ae="lumen:shake",Vn=8e3,Fn=50,Bn='[data-lumen-root], [data-lumen-capture-ignore="true"]';function _n(e={}){return async function(){if(typeof window>"u")throw new R("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=Wn(),n=e.send??Un,o=e.timeoutMs??Vn,r=e.captureSettleMs??Fn,a=Gn(),i=$n(e.concealSelector===void 0?Bn:e.concealSelector);try{await qn(r);let l=await new Promise((c,p)=>{let b=window.setTimeout(()=>{t.pending.delete(a),p(new R("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},o);t.pending.set(a,{resolve:y=>{window.clearTimeout(b),c(y);},reject:y=>{window.clearTimeout(b),p(y);}});try{n({type:"lumen:capture-request",id:a,afterScreenUpdates:!0});}catch{t.pending.delete(a),window.clearTimeout(b),p(new R("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new R(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let s=Yn(l.dataUrl),d=e.platform??Kn();return {blob:s,method:d==="android"?"android-native":"ios-native",platform:d,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:l.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{i();}}}function Un(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new R("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function Wn(){if(window.__lumenNativeCapture)return window.__lumenNativeCapture;let e={pending:new Map,resolve(n,o,r){let a=e.pending.get(n);a&&(e.pending.delete(n),a.resolve({type:"lumen:capture-response",id:n,dataUrl:o,pixelRatio:r}));},reject(n,o){let r=e.pending.get(n);r&&(e.pending.delete(n),r.resolve({type:"lumen:capture-response",id:n,error:o}));}},t=n=>{let o=zn(n.data);if(!o||o.type!=="lumen:capture-response")return;let r=e.pending.get(o.id);r&&(e.pending.delete(o.id),r.resolve(o));};return window.addEventListener("message",t),document.addEventListener("message",t),window.__lumenNativeCapture=e,e}function zn(e){if(e&&typeof e=="object"&&"type"in e)return e;if(typeof e=="string")try{let t=JSON.parse(e);if(t&&typeof t=="object"&&t.type)return t}catch{}return null}function $n(e){if(!e||typeof document>"u")return ()=>{};let t=[];for(let n of Array.from(document.querySelectorAll(e)))t.push({el:n,prev:n.style.visibility}),n.style.visibility="hidden";return ()=>{for(let{el:n,prev:o}of t)n.style.visibility=o;}}async function qn(e){await jn(),e>0&&await new Promise(t=>window.setTimeout(t,e));}function jn(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function Kn(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function Gn(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Yn(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new R("Native host returned an invalid image data URL.","NATIVE_CAPTURE_FAILED");let n=t[1]||"image/png",o=!!t[2],r=t[3]??"";if(!o)return new Blob([decodeURIComponent(r)],{type:n});let a=atob(r),i=new Uint8Array(a.length);for(let l=0;l<a.length;l++)i[l]=a.charCodeAt(l);return new Blob([i],{type:n})}var Xn="[data-lumen-root]",Jn="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function Zn(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(ze(n))return true;return ze(e.target)}function ze(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(Jn)?true:!!e.closest(Xn):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?ze(e.host):false:false}async function yt(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new R("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new R("Microphone access denied or unavailable.","MIC_DENIED")}let n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(s=>MediaRecorder.isTypeSupported(s))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),r=[],a=performance.now(),i=null;o.addEventListener("dataavailable",s=>{s.data&&s.data.size>0&&r.push(s.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);function l(){i!==null&&window.clearTimeout(i),i=null;for(let s of t.getTracks())s.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}l();},stop(){return new Promise((s,d)=>{if(o.state==="inactive"){l(),d(new R("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let c=performance.now()-a,p=o.mimeType||n||"audio/webm",b=new Blob(r,{type:p});l(),s({blob:b,durationMs:c,mimeType:p});},{once:true}),o.stop();})}}}async function Et(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new R("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new R("Screen capture was denied or cancelled.","SCREEN_DENIED")}let n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(g=>MediaRecorder.isTypeSupported(g))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),r=[],a=performance.now(),i=null,l=false,s=false,d,c,p=new Promise((g,v)=>{d=g,c=v;});p.catch(()=>{});function b(){i!==null&&(window.clearTimeout(i),i=null);for(let g of t.getTracks())g.stop();}o.addEventListener("dataavailable",g=>{g.data&&g.data.size>0&&r.push(g.data);}),o.addEventListener("stop",()=>{if(l)return;if(l=true,b(),s){c(new R("Recording cancelled.","RECORDER_STOPPED"));return}let g=o.mimeType||n||"video/webm";d({blob:new Blob(r,{type:g}),durationMs:performance.now()-a,mimeType:g});});function y(){o.state!=="inactive"&&o.stop();}return o.start(),i=window.setTimeout(y,e*1e3),t.getVideoTracks()[0]?.addEventListener("ended",y),{stream:t,result:p,stop:y,cancel(){s=true,o.state!=="inactive"?o.stop():l||(l=true,b(),c(new R("Recording cancelled.","RECORDER_STOPPED")));}}}var $e=kt.createContext(null);function Ce(){let e=kt.useContext($e);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var je='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, sans-serif';function xt(e,t=1){return Math.max(0,Math.min(t,e))}var Mt=kt__namespace.forwardRef(function({screenshot:t,tool:n,color:o="rgb(239, 68, 68)",strokeWidth:r=4,onDrawingChange:a},i){let l=kt.useRef(null),s=kt.useRef(null),d=kt.useRef(null),[c,p]=kt.useState(null),[b,y]=kt.useState([]),g=kt.useRef(null),v=kt.useRef(false),k=kt.useRef(0),N=kt.useRef(false),[T,L]=kt.useState([]),A=kt.useRef(0),H=kt.useRef([]),P=kt.useRef(null),V=kt.useCallback((f,h)=>{L(E=>E.map(x=>x.id===f?{...x,text:h}:x));},[]),_=kt.useCallback(f=>{L(E=>E.filter(x=>x.id!==f));let h=H.current.lastIndexOf("comment");h>=0&&H.current.splice(h,1);},[]);kt.useEffect(()=>{let f=P.current;if(f==null)return;P.current=null,d.current?.querySelector(`[data-bubble-id="${f}"] .lumen-bubble-text`)?.focus();},[T]),kt.useEffect(()=>{let f=false,h=null;return (async()=>{try{let E=await createImageBitmap(t);if(f){E.close?.();return}h=E,p(E);}catch{}})(),()=>{f=true,h?.close?.();}},[t]),kt.useEffect(()=>{if(!c)return;let f=l.current,h=s.current;if(!f||!h)return;f.width=c.width,f.height=c.height,h.width=c.width,h.height=c.height;let E=f.getContext("2d");E&&(E.imageSmoothingEnabled=false,E.drawImage(c,0,0));},[c]),kt.useEffect(()=>{let f=s.current;f&&Ie(f,b,g.current);},[b]),kt.useImperativeHandle(i,()=>({hasAnnotations:()=>b.length>0||T.some(f=>f.text.trim().length>0),reset:()=>{y([]),L([]),H.current=[];},undo:()=>{(H.current.pop()??"anno")==="comment"?L(h=>h.length===0?h:h.slice(0,-1)):y(h=>h.length===0?h:h.slice(0,-1));},async flatten(){let f=g.current,h=f?[...b,f]:b,E=T.filter(S=>S.text.trim().length>0);if(h.length===0&&E.length===0||!c)return t;let x=document.createElement("canvas");x.width=c.width,x.height=c.height;let D=x.getContext("2d");if(!D)return t;D.imageSmoothingEnabled=false,D.drawImage(c,0,0);for(let S of h)Ke(D,S);let I=l.current?.clientWidth||c.width,W=c.width/Math.max(I,1);for(let S of E)ao(D,S,c.width,c.height,W);return await new Promise(S=>{x.toBlob(G=>{S(G??t);},"image/jpeg",.85);})}}),[b,T,c,t]);function U(f){let h=s.current;if(!h)return {x:0,y:0};let E=h.getBoundingClientRect(),x=h.width/Math.max(E.width,1),D=h.height/Math.max(E.height,1);return {x:(f.clientX-E.left)*x,y:(f.clientY-E.top)*D}}function j(){N.current||(N.current=true,requestAnimationFrame(()=>{N.current=false;let f=s.current;f&&Ie(f,b,g.current);}));}function J(f){if(f.button!==void 0&&f.button!==0)return;if(n==="comment"){let E=s.current;if(!E)return;let x=E.getBoundingClientRect(),D=xt((f.clientX-x.left)/Math.max(x.width,1),.72),I=xt((f.clientY-x.top)/Math.max(x.height,1),.8),W=++A.current;L(S=>[...S,{id:W,x:D,y:I,text:"",color:o}]),H.current.push("comment"),P.current=W;return}try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}v.current=true,a?.(true);let h=U(f);n==="arrow"?g.current={kind:"arrow",from:h,to:h,color:o,width:r}:n==="rect"?g.current={kind:"rect",from:h,to:h,color:o,width:r}:g.current={kind:"freehand",points:[h],color:o,width:r},k.current=performance.now(),j();}function K(f){if(!v.current||!g.current)return;let h=U(f),E=g.current;if(E.kind==="arrow"||E.kind==="rect")E.to=h;else {let x=E.points[E.points.length-1],D=x?(x.x-h.x)**2+(x.y-h.y)**2:1/0,I=performance.now(),W=I-k.current;(D>16||W>16)&&(E.points.push(h),k.current=I);}j();}function B(){if(!v.current)return;v.current=false,a?.(false);let f=g.current;if(g.current=null,!!f){if(f.kind==="arrow"||f.kind==="rect"){let h=f.to.x-f.from.x,E=f.to.y-f.from.y;if(h*h+E*E<16){let x=s.current;x&&Ie(x,b,null);return}}else if(f.points.length<2){let h=s.current;h&&Ie(h,b,null);return}y(h=>[...h,f].slice(-50)),H.current.push("anno");}}return jsxRuntime.jsxs("div",{ref:d,className:"lumen-annotate-frame","data-lumen-tool":n,children:[jsxRuntime.jsx("canvas",{ref:l}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:J,onPointerMove:K,onPointerUp:B,onPointerCancel:B}),jsxRuntime.jsx("div",{className:"lumen-bubble-layer",children:T.map(f=>jsxRuntime.jsx(oo,{comment:f,onChange:V,onRemove:_},f.id))})]})});function oo({comment:e,onChange:t,onRemove:n}){let o=kt.useRef(null);return kt.useEffect(()=>{let r=o.current;r&&r.textContent!==e.text&&(r.textContent=e.text);},[]),jsxRuntime.jsxs("div",{className:"lumen-bubble","data-bubble-id":e.id,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,"--lumen-bubble-accent":e.color},onPointerDown:r=>r.stopPropagation(),children:[jsxRuntime.jsx("span",{className:"lumen-bubble-label",children:"Comment"}),jsxRuntime.jsx("div",{ref:o,className:"lumen-bubble-text",contentEditable:true,suppressContentEditableWarning:true,role:"textbox","aria-label":"Comment text","data-placeholder":"Type a note\u2026",onInput:r=>t(e.id,r.currentTarget.textContent??"")}),jsxRuntime.jsx("button",{type:"button",className:"lumen-bubble-del","aria-label":"Remove comment",onPointerDown:r=>r.stopPropagation(),onClick:()=>n(e.id),children:"\xD7"})]})}function Ie(e,t,n){let o=e.getContext("2d");if(o){o.clearRect(0,0,e.width,e.height);for(let r of t)Ke(o,r);n&&Ke(o,n);}}function Ke(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let n=Math.min(t.from.x,t.to.x),o=Math.min(t.from.y,t.to.y),r=Math.abs(t.to.x-t.from.x),a=Math.abs(t.to.y-t.from.y);e.strokeRect(n,o,r,a);}else if(t.kind==="freehand")ro(e,t.points);else {let{from:n,to:o,width:r}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(o.x,o.y),e.stroke();let a=Math.atan2(o.y-n.y,o.x-n.x),i=Math.max(12,r*4);e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x-i*Math.cos(a-Math.PI/7),o.y-i*Math.sin(a-Math.PI/7)),e.lineTo(o.x-i*Math.cos(a+Math.PI/7),o.y-i*Math.sin(a+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function ro(e,t){if(t.length===0)return;e.beginPath();let n=t[0];if(!n)return;if(e.moveTo(n.x,n.y),t.length===1){e.arc(n.x,n.y,e.lineWidth/2,0,Math.PI*2),e.fill();return}if(t.length===2){let r=t[1];e.lineTo(r.x,r.y),e.stroke();return}for(let r=1;r<t.length-1;r++){let a=t[r],i=t[r+1],l=(a.x+i.x)/2,s=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,l,s);}let o=t[t.length-1];e.lineTo(o.x,o.y),e.stroke();}function ao(e,t,n,o,r){let a=t.text.trim();if(!a)return;let i=10*r,l=14*r,s=10*r,d=12*r,c=l*1.35,p=s*1.7,b=t.x*n,y=t.y*o,g=Math.min(n*.6,n-b-8*r);e.save(),e.font=`500 ${l}px ${je}`,e.textBaseline="top";let v=io(e,a,g-i*2),k=v.reduce((P,V)=>Math.max(P,e.measureText(V).width),0),N=Math.min(g,Math.max(k,56*r)+i*2),T=i*2+p+v.length*c;lo(e,b,y,N,T,d),e.fillStyle="#ffffff",e.fill(),e.lineWidth=Math.max(1,r),e.strokeStyle="rgba(0,0,0,0.10)",e.stroke();let L=b+18*r,A=y+T;e.beginPath(),e.moveTo(L,A-r),e.lineTo(L+13*r,A-r),e.lineTo(L+4*r,A+9*r),e.closePath(),e.fillStyle="#ffffff",e.fill(),e.fillStyle=t.color||"rgb(239, 68, 68)",e.font=`700 ${s}px ${je}`,e.fillText("COMMENT",b+i,y+i),e.fillStyle="#111318",e.font=`500 ${l}px ${je}`;let H=y+i+p;for(let P of v)e.fillText(P,b+i,H),H+=c;e.restore();}function io(e,t,n){let o=t.split(/\s+/).filter(Boolean),r=[],a="";for(let i of o){let l=a?`${a} ${i}`:i;a&&e.measureText(l).width>n?(r.push(a),a=i):a=l;}return a&&r.push(a),r.length?r:[t]}function lo(e,t,n,o,r,a){let i=Math.min(a,o/2,r/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,o,r,i);return}e.moveTo(t+i,n),e.arcTo(t+o,n,t+o,n+r,i),e.arcTo(t+o,n+r,t,n+r,i),e.arcTo(t,n+r,t,n,i),e.arcTo(t,n,t+o,n,i),e.closePath();}function Ge({children:e,...t}){return jsxRuntime.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...t,children:e})}function so(e){return jsxRuntime.jsxs(Ge,{...e,children:[jsxRuntime.jsx("path",{d:"M3 9a2 2 0 0 1 2-2h1.5l1-1.5h5l1 1.5H19a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"13",r:"3.2"})]})}function uo(e){return jsxRuntime.jsxs(Ge,{...e,children:[jsxRuntime.jsx("rect",{x:"3",y:"6",width:"13",height:"12",rx:"2.5"}),jsxRuntime.jsx("path",{d:"m16 10 5-3v10l-5-3"})]})}function co(e){return jsxRuntime.jsxs(Ge,{...e,children:[jsxRuntime.jsx("path",{d:"M12 16V4m0 0 4 4m-4-4-4 4"}),jsxRuntime.jsx("path",{d:"M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})]})}var Ye={shot:so,video:uo,upload:co};function Tt(e){let t=e.videoWidth||1280,n=e.videoHeight||720,o=document.createElement("canvas");o.width=t,o.height=n;let r=o.getContext("2d");return r?(r.drawImage(e,0,0,t,n),new Promise(a=>o.toBlob(i=>a(i),"image/jpeg",.82))):Promise.resolve(null)}function mo(e,t){return !Number.isFinite(t)||t<=0?Promise.resolve():new Promise(n=>{e.addEventListener("seeked",()=>n(),{once:true});try{e.currentTime=t;}catch{n();}})}async function St(e){if(typeof document>"u")return {poster:null,durationMs:0};let t=URL.createObjectURL(e),n=document.createElement("video");n.muted=true,n.playsInline=true,n.preload="metadata",n.src=t;try{await new Promise((a,i)=>{n.addEventListener("loadeddata",()=>a(),{once:!0}),n.addEventListener("error",()=>i(new Error("video decode failed")),{once:!0});}),await mo(n,Math.min(.1,(n.duration||0)/2));let o=await Tt(n),r=Number.isFinite(n.duration)?n.duration*1e3:0;return {poster:o,durationMs:r}}catch{return {poster:null,durationMs:0}}finally{URL.revokeObjectURL(t);}}async function Lt(e){if(typeof document>"u")return null;let t=document.createElement("video");t.muted=true,t.playsInline=true,t.srcObject=e;try{return await t.play().catch(()=>{}),await new Promise(n=>{if(t.readyState>=2)return n();t.addEventListener("loadeddata",()=>n(),{once:!0}),window.setTimeout(n,600);}),await Tt(t)}catch{return null}finally{t.srcObject=null;}}async function Je(){if(typeof document>"u")return null;let e=document.createElement("canvas");e.width=1280,e.height=720;let t=e.getContext("2d");return t?(t.fillStyle="#0e0e12",t.fillRect(0,0,e.width,e.height),t.fillStyle="#52525b",t.beginPath(),t.moveTo(590,312),t.lineTo(590,408),t.lineTo(694,360),t.closePath(),t.fill(),new Promise(n=>e.toBlob(o=>n(o),"image/jpeg",.8))):null}var Ze=60,Nt=[{label:"Red",value:"rgb(239, 68, 68)"},{label:"Amber",value:"rgb(245, 158, 11)"},{label:"Blue",value:"rgb(59, 130, 246)"},{label:"Green",value:"rgb(34, 197, 94)"},{label:"Neutral",value:"rgb(244, 244, 245)"}],Pt=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],At=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],It=[{value:"shot",label:"Screenshot",hint:"This page, instantly",primary:true},{value:"video",label:"Video",hint:"Record up to 60s"},{value:"upload",label:"Upload",hint:"Image or video"}];function Qe(){let{client:e,isOpen:t,closeCapture:n,user:o,capture:r,initialCapture:a,initialCaptureError:i,startVideoSession:l,consumePendingVideo:s}=Ce(),[d,c]=kt.useState(1),[p,b]=kt.useState(null),[y,g]=kt.useState({kind:"idle"}),[v,k]=kt.useState(false),[N,T]=kt.useState(0),[L,A]=kt.useState(null),[H,P]=kt.useState(false),[V,_]=kt.useState("arrow"),[U,j]=kt.useState(Nt[0].value),[J,K]=kt.useState(Pt[1].value),[B,f]=kt.useState(""),[h,E]=kt.useState("bug"),[x,D]=kt.useState(o?.email??""),[I,W]=kt.useState(null),[S,G]=kt.useState(null),[ne,Z]=kt.useState(0),[Q,oe]=kt.useState(null),Me=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",[fe,ge]=kt.useState(false),se=kt.useRef(null),he=kt.useRef(null),be=kt.useRef(null),ee=kt.useRef(false),ve=kt.useRef(false);if(kt.useEffect(()=>{t||(ve.current=false);},[t]),kt.useEffect(()=>{if(!t||ve.current)return;ve.current=true,ee.current=false,c(1),b(null),f(""),G(null),Z(0),oe(null),k(false),T(0),A(null),P(false);let u=s();return u?(b("video"),oe({blob:u.blob,durationMs:u.durationMs}),u.poster?g({kind:"ready",capture:ye(u.poster,["Screen recording; preview is the first frame."])}):(g({kind:"capturing"}),Je().then(C=>{ee.current||g(C?{kind:"ready",capture:ye(C,["Screen recording."])}:{kind:"manual"});}))):a?(b("shot"),g({kind:"ready",capture:a})):r?.mode==="manual"?g({kind:"manual"}):g({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."}),()=>{ee.current=true;}},[t,r,a,i]),kt.useEffect(()=>{if(!t)return;be.current=document.activeElement??null;let u=document.documentElement,C=u.style.overflow,F=u.style.paddingRight,z=window.innerWidth-u.clientWidth;u.style.overflow="hidden",z>0&&(u.style.paddingRight=`${z}px`);let q=false,ie=()=>{if(!q){q=true,u.style.overflow=C,u.style.paddingRight=F;try{be.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",ie),()=>{window.removeEventListener("pagehide",ie),ie();}},[t]),kt.useEffect(()=>{if(!t)return;function u(C){if(C.key==="Escape"){C.preventDefault(),n();return}if(C.key!=="Tab")return;let F=he.current;if(!F)return;let z=Eo(F);if(z.length===0)return;let q=z[0],ie=z[z.length-1],_e=document.activeElement;C.shiftKey&&(_e===q||!F.contains(_e))?(C.preventDefault(),ie.focus()):!C.shiftKey&&_e===ie&&(C.preventDefault(),q.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),kt.useEffect(()=>{if(!t||y.kind!=="manual")return;function u(C){let q=Array.from(C.clipboardData?.items??[]).find(ie=>ie.type.startsWith("image/"))?.getAsFile();q&&(C.preventDefault(),M(q));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,y.kind]),kt.useEffect(()=>{if(!I)return;let u=Date.now(),C=window.setInterval(()=>{let F=Math.floor((Date.now()-u)/1e3);Z(F),F>=Ze&&Ve();},250);return ()=>window.clearInterval(C)},[I]),!t)return null;async function He(u){ee.current=false,g({kind:"capturing"});try{let C=await Ne({...r,mode:u,target:r?.target??document.documentElement});return ee.current?!1:(Y(C),g({kind:"ready",capture:C}),!0)}catch(C){return ee.current||g({kind:"manual",error:C instanceof Error?C.message:"Automatic screenshot capture was unavailable."}),false}}async function $(u){b(u),A(null),u!=="video"&&Fe(),u==="shot"?await He(r?.mode??"auto"):u==="video"?(oe(null),g({kind:"idle"})):g({kind:"manual"});}async function M(u){if(u.type.startsWith("image/")){Fe();let C=ye(u,["Manual image upload used."]);g({kind:"ready",capture:C});return}if(u.type.startsWith("video/")){g({kind:"capturing"});try{let{poster:C,durationMs:F}=await St(u),z=C??await Je();if(!z){g({kind:"manual",error:"Could not read that video."});return}let q=ye(z,["Uploaded video; preview is the first frame."]);oe({blob:u,durationMs:F}),g({kind:"ready",capture:q});}catch{g({kind:"manual",error:"Could not read that video."});}return}sonner.toast.error("Choose an image (PNG, JPEG, WebP) or a video (MP4, WebM).");}function Y(u){u.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function rt(){try{let u=await yt(Ze);W(u);}catch(u){sonner.toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Ve(){if(I)try{let u=await I.stop();G({blob:u.blob,durationMs:u.durationMs});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{W(null);}}function cn(){I?.cancel(),W(null),G(null),Z(0);}async function dn(){try{await l();}catch(u){sonner.toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}function Fe(){oe(null);}let mn=y.kind==="ready";async function pn(){if(I&&await Ve(),d===1){if(y.kind==="ready"){let u=await se.current?.flatten();A(u??y.capture.blob),P(u!=null&&u!==y.capture.blob);}c(2);}else d===2?c(3):await gn();}function fn(){d>1&&c(u=>u-1);}async function gn(){if(y.kind!=="ready")return;let u=B.trim(),{capture:C}=y;k(true),T(0);try{let F=L??C.blob,z=await e.submit({rawText:u.length>0?u:void 0,category:h,submitterEmail:x.trim()||void 0,screenshot:F,audio:S?.blob,audioDurationMs:S?.durationMs,video:Q?.blob,videoDurationMs:Q?.durationMs,context:wt(C)},{onUploadProgress:q=>T(Math.min(.95,q))});T(1),sonner.toast.success("Feedback sent \u2014 thank you."),z.id,n();}catch(F){sonner.toast.error(F instanceof Error?F.message:"Could not submit feedback"),k(false);}}function hn(u){u.target===u.currentTarget&&!v&&n();}let Re=Math.round(N*100),Be=p==="video",bn=d===1&&!mn||v,vn=d<3?"Next":v?Re<95?`Uploading ${Re}%\u2026`:"Almost done\u2026":"Send feedback";return jsxRuntime.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:hn,children:jsxRuntime.jsxs("div",{ref:he,className:"lumen-modal","data-lumen-drawing":fe?"true":void 0,children:[jsxRuntime.jsx(go,{onDismiss:n}),jsxRuntime.jsxs("header",{className:"lumen-modal-header",children:[jsxRuntime.jsxs("h2",{className:"lumen-modal-title",children:[jsxRuntime.jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsxRuntime.jsx(po,{step:d}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[d===1?jsxRuntime.jsx("div",{className:"lumen-pane",children:p===null?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:It.map(u=>{let C=Ye[u.value];return jsxRuntime.jsxs("button",{type:"button",className:"lumen-method-btn"+(u.primary?" lumen-method-primary":""),onClick:()=>$(u.value),disabled:y.kind==="capturing",children:[jsxRuntime.jsx("span",{className:"lumen-method-ico",children:jsxRuntime.jsx(C,{})}),u.primary?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-method-text",children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]}),jsxRuntime.jsx("span",{className:"lumen-method-badge",children:"Fastest"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]})]},u.value)})}),jsxRuntime.jsx("p",{className:"lumen-status lumen-method-help",children:"Choose how to capture your feedback."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method-switch",role:"group","aria-label":"Switch capture method",children:It.map(u=>{let C=Ye[u.value];return jsxRuntime.jsxs("button",{type:"button","aria-pressed":p===u.value,onClick:()=>$(u.value),disabled:y.kind==="capturing",children:[jsxRuntime.jsx(C,{}),u.label]},u.value)})}),p==="video"&&y.kind==="idle"?jsxRuntime.jsx(fo,{canRecord:Me,onRecord:dn}):null,y.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,y.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:p==="upload"?"Choose an image or video to attach \u2014 or paste an image.":y.error?"Automatic capture was unavailable. Upload or paste an image to continue.":"Upload or paste an image to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:p==="upload"?"Choose a file \u2014 image or video":"Choose or paste an image"}),jsxRuntime.jsx("input",{type:"file",accept:p==="upload"?"image/png,image/jpeg,image/webp,video/mp4,video/webm,video/quicktime":"image/png,image/jpeg,image/webp",onChange:u=>{let C=u.currentTarget.files?.[0];C&&M(C),u.currentTarget.value="";}})]})]}):null,y.kind==="ready"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Be?null:jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(De,{label:"Arrow",active:V==="arrow",onClick:()=>_("arrow")}),jsxRuntime.jsx(De,{label:"Box",active:V==="rect",onClick:()=>_("rect")}),jsxRuntime.jsx(De,{label:"Draw",active:V==="freehand",onClick:()=>_("freehand")}),jsxRuntime.jsx(De,{label:"Comment",active:V==="comment",onClick:()=>_("comment")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:Nt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":U===u.value,onClick:()=>j(u.value)},u.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:Pt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":J===u.value,onClick:()=>K(u.value),children:jsxRuntime.jsx("span",{className:"lumen-stroke-size-dot",style:{width:u.dot,height:u.dot}})},u.value))}),jsxRuntime.jsx("span",{className:"lumen-toolbar-spacer"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>se.current?.undo(),children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>se.current?.reset(),children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(Mt,{ref:se,screenshot:y.capture.blob,tool:V,color:U,strokeWidth:J,onDrawingChange:ge})}),jsxRuntime.jsxs("div",{className:"lumen-cap-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>p&&$(p),children:Be?"\u21BB Re-record":"\u21BB Recapture"}),Be?Q?jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round(Q.durationMs/1e3),"s recorded"]}):null:jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:[Dt(p)," captured \xB7 switch method above anytime"]})]})]}):null]})}):null,d===2?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-form",children:[jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"What happened?"}),jsxRuntime.jsx("textarea",{value:B,onChange:u=>f(u.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Add a voice note (optional)"}),jsxRuntime.jsxs("div",{className:"lumen-audio-row",children:[!I&&!S?jsxRuntime.jsx("button",{type:"button",onClick:rt,className:"lumen-btn-ghost",children:"Record voice note"}):null,I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(ho,{stream:I.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[ne,"s / ",Ze,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:Ve,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:cn,className:"lumen-btn-ghost",children:"Cancel"})]}):null,S&&!I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(vo,{blob:S.blob,durationMs:S.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>G(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Category"}),jsxRuntime.jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:At.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":h===u.value,onClick:()=>E(u.value),children:u.label},u.value))})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Your email (optional)"}),jsxRuntime.jsx("input",{type:"email",value:x,onChange:u=>D(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,d===3?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-review",children:[jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[Dt(p),H?" \xB7 annotated":"",jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>c(1),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Category"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[jsxRuntime.jsx("span",{className:"lumen-chip",children:At.find(u=>u.value===h)?.label}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>c(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Description"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[B.trim()?B.trim():jsxRuntime.jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>c(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Material"}),jsxRuntime.jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[S?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(S.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>G(null),children:"\xD7"})]}):null,Q?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round(Q.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Fe,children:"\xD7"})]}):null,x.trim()?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u2709 ",x.trim()]}):null,!S&&!I?jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{c(2),rt();},children:"+ Voice note"}):null]})]})]}):null]}),jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[v?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Re,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${Re}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:d===1?n:fn,className:"lumen-btn-ghost",disabled:v,children:d===1?"Cancel":"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:pn,className:"lumen-btn-primary",disabled:bn,children:vn})]})]})]})})}function Dt(e){return e==="video"?"Screen recording":e==="upload"?"Upload":"Screenshot"}function po({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsxRuntime.jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,o)=>jsxRuntime.jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsxRuntime.jsx("span",{className:"lumen-step-num",children:n.n}),jsxRuntime.jsx("span",{className:"lumen-step-lbl",children:n.label}),o<t.length-1?jsxRuntime.jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function fo({canRecord:e,onRecord:t}){return e?jsxRuntime.jsxs("div",{className:"lumen-record-prompt",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-record-btn","aria-label":"Start screen recording",onClick:t}),jsxRuntime.jsxs("div",{className:"lumen-record-copy",children:[jsxRuntime.jsx("div",{className:"lumen-record-title",children:"Record your screen"}),jsxRuntime.jsx("div",{className:"lumen-record-sub",children:"Tap to start. The sheet closes so you can record freely \u2014 a Stop button stays on screen, then the sheet returns with your clip. Max 60s."})]})]}):jsxRuntime.jsx("div",{className:"lumen-record-prompt",children:jsxRuntime.jsxs("p",{className:"lumen-record-unavailable",children:["Screen recording isn\u2019t available in this browser. Switch to"," ",jsxRuntime.jsx("strong",{children:"Upload"})," to attach a video instead."]})})}function De({label:e,active:t,onClick:n}){return jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function go({onDismiss:e}){let t=kt.useRef(null),n=kt.useRef(0),o=kt.useRef(null);function r(l){l.currentTarget.setPointerCapture(l.pointerId),t.current=l.clientY,n.current=performance.now(),o.current=l.currentTarget.parentElement;}function a(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current);o.current.style.transform=`translateY(${s}px)`;}function i(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current),d=Math.max(1,performance.now()-n.current),c=s/d;o.current.style.transform="",o.current.style.transition="",t.current=null,(s>80||c>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:r,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function ho({stream:e}){let t=kt.useRef(null);return kt.useEffect(()=>{let n=t.current;if(!n)return;let o=Math.min(window.devicePixelRatio||1,2),r=n.clientWidth||88,a=n.clientHeight||22;n.width=Math.round(r*o),n.height=Math.round(a*o);let i=n.getContext("2d");if(!i)return;i.scale(o,o);let l=window.AudioContext??window.webkitAudioContext;if(!l)return;let s=new l,d=s.createMediaStreamSource(e),c=s.createAnalyser();c.fftSize=1024,c.smoothingTimeConstant=.6,d.connect(c);let p=new Uint8Array(c.fftSize),b=18,y=3,g=3,v=Math.max(2,(r-y*(b-1))/b),k=Math.min(v/2,3),N=new Array(b).fill(0),T=0,L=false;function A(){if(L)return;c.getByteTimeDomainData(p);let H=Math.floor(p.length/b);i.clearRect(0,0,r,a),i.fillStyle=wo("--lumen-danger")||"rgb(239,68,68)";for(let P=0;P<b;P++){let V=0;for(let B=0;B<H;B++){let f=Math.abs((p[P*H+B]??128)-128);f>V&&(V=f);}let _=Math.min(1,V/128*1.8),U=N[P]??0;N[P]=_>U?_:U+(_-U)*.35;let j=Math.max(g,N[P]*a),J=P*(v+y),K=(a-j)/2;bo(i,J,K,v,j,k),i.fill();}T=requestAnimationFrame(A);}return T=requestAnimationFrame(A),()=>{L=true,cancelAnimationFrame(T);try{d.disconnect();}catch{}s.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function bo(e,t,n,o,r,a){let i=Math.min(a,o/2,r/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,o,r,i);return}e.moveTo(t+i,n),e.arcTo(t+o,n,t+o,n+r,i),e.arcTo(t+o,n+r,t,n+r,i),e.arcTo(t,n+r,t,n,i),e.arcTo(t,n,t+o,n,i),e.closePath();}function vo({blob:e,durationMs:t}){let[n,o]=kt.useState("");return kt.useEffect(()=>{let r=URL.createObjectURL(e);return o(r),()=>{URL.revokeObjectURL(r);}},[e]),jsxRuntime.jsxs("div",{className:"lumen-audio-preview",children:[jsxRuntime.jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxRuntime.jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function wo(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var yo='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Eo(e){return Array.from(e.querySelectorAll(yo)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function Vt({startedAt:e,maxSeconds:t,portalTarget:n,onStop:o,onCancel:r}){let[a,i]=kt.useState(0),[l,s]=kt.useState(false);if(kt.useEffect(()=>s(true),[]),kt.useEffect(()=>{let p=()=>i(Math.min(t,Math.max(0,Math.floor((Date.now()-e)/1e3))));p();let b=window.setInterval(p,250);return ()=>window.clearInterval(b)},[e,t]),!l||typeof document>"u")return null;let d=n??document.body,c=p=>`${Math.floor(p/60)}:${String(p%60).padStart(2,"0")}`;return reactDom.createPortal(jsxRuntime.jsxs("div",{className:"lumen-rec-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-dot","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-rec-hud-time",children:[c(a)," ",jsxRuntime.jsxs("span",{className:"lumen-rec-hud-max",children:["/ ",c(t)]})]}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"}),jsxRuntime.jsxs("button",{type:"button",className:"lumen-rec-hud-stop",onClick:o,"aria-label":"Stop recording and return to feedback",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-square","aria-hidden":"true"}),"Stop"]})]}),d)}function Ft(){if(typeof document>"u"||typeof window>"u")return 0;let e=window.innerWidth,t=window.innerHeight;if(e===0||t===0)return 0;let n=t-4,o=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],r=new Set,a=0;for(let i of o){let l=document.elementsFromPoint(i,n);for(let s of l){if(r.has(s))continue;r.add(s);let d=window.getComputedStyle(s);if(d.position!=="fixed"&&d.position!=="sticky")continue;let c=s.getBoundingClientRect();c.bottom<t-8||c.bottom>t+8||c.width<e*.6||c.height>a&&(a=c.height);}}return a}function tt(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,o=window.innerHeight,r=0;for(let a of e){let i;try{i=document.querySelectorAll(a);}catch{continue}for(let l of Array.from(i)){let s=l.getBoundingClientRect();if(s.height===0||s.width===0)continue;let d=0;switch(t){case "bottom":if(s.bottom<o-8)break;d=Math.max(0,o-s.top);break;case "top":if(s.top>8)break;d=Math.max(0,s.bottom);break;case "left":if(s.left>8)break;d=Math.max(0,s.right);break;case "right":if(s.right<n-8)break;d=Math.max(0,n-s.left);break}d>r&&(r=d);}}return r}function Bt(e){let[t,n]=kt.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),o=kt.useRef(t),r=Ro(e.avoid),a=e.placement,i=e.offset.x,l=e.offset.y;return kt.useEffect(()=>{if(typeof window>"u")return;let s=0,d=false,c=()=>{if(s=0,d)return;let v=a[0]==="b"?"bottom":"top",k=a[1]==="r"?"right":"left",N=0,T=0;e.avoid==="auto"&&v==="bottom"?N=Ft():Array.isArray(e.avoid)&&(N=tt(e.avoid,v),T=tt(e.avoid,k));let L={bottom:v==="bottom"?l+N:0,top:v==="top"?l+N:0,right:k==="right"?i+T:0,left:k==="left"?i+T:0},A=o.current;(L.bottom!==A.bottom||L.top!==A.top||L.right!==A.right||L.left!==A.left)&&(o.current=L,n(L));},p=()=>{s||(s=window.requestAnimationFrame(c));};p();let b=typeof ResizeObserver<"u"?new ResizeObserver(p):null;b?.observe(document.documentElement);let y=typeof MutationObserver<"u"?new MutationObserver(p):null;y?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",p);let g=window.visualViewport;return g?.addEventListener("resize",p),g?.addEventListener("scroll",p),()=>{d=true,s&&window.cancelAnimationFrame(s),b?.disconnect(),y?.disconnect(),window.removeEventListener("resize",p),g?.removeEventListener("resize",p),g?.removeEventListener("scroll",p);}},[a,i,l,r]),t}function Ro(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function _t(e){let[t,n]=kt.useState(false);return kt.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;let o=window.visualViewport;if(!o||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let r=100,a=0,i=()=>{a=0;let s=window.innerHeight-o.height;n(s>r);},l=()=>{a||(a=window.requestAnimationFrame(i));};return l(),o.addEventListener("resize",l),o.addEventListener("scroll",l),()=>{a&&window.cancelAnimationFrame(a),o.removeEventListener("resize",l),o.removeEventListener("scroll",l);}},[e]),t}function $t({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:r}){let[a,i]=kt.useState(null),l=kt.useRef(null),s=Bt(e),d=_t(e.hideOnKeyboard);if(kt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),Po(l,!n&&!d),!a)return null;let c=e.placement,p=c[0]==="b"?"bottom":"top",b=c[1]==="r"?"right":"left",y=p==="bottom"?s.bottom:s.top,g=b==="right"?s.right:s.left,v={position:"fixed",[p]:e.safeArea?`calc(${y}px + env(safe-area-inset-${p}, 0px))`:`${y}px`,[b]:e.safeArea?`calc(${g}px + env(safe-area-inset-${b}, 0px))`:`${g}px`,zIndex:e.zIndex,opacity:n||d?0:1,pointerEvents:n||d?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:v,"aria-label":e.label,"aria-hidden":n||d?true:void 0,tabIndex:n||d?-1:0,onPointerDown:k=>o?.(k.nativeEvent),onClick:k=>r(k.nativeEvent),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),a)}function Po(e,t){let n=kt.useRef(false);kt.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let o=window.setTimeout(()=>{let r=e.current;if(!r)return;let a=r.getBoundingClientRect();if(a.width===0||a.height===0)return;let i=a.left+a.width/2,l=a.top+a.height/2,s=document.elementsFromPoint(i,l),d=Ut(window.getComputedStyle(r).zIndex);for(let c of s){if(c===r||r.contains(c))continue;if(Ut(window.getComputedStyle(c).zIndex)>d){n.current=true,console.warn("[lumen] trigger is occluded by",c);break}}},250);return ()=>window.clearTimeout(o)},[t,e]);}function Ut(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function qt({mount:e,label:t,icon:n,onPointerDown:o,onClick:r}){let[a,i]=kt.useState(null);return kt.useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;i(l);},[e]),a?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onPointerDown:l=>o?.(l.nativeEvent),onClick:l=>r(l.nativeEvent),"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsxRuntime.jsx("span",{children:t})]}),a):null}function Gt({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:r}){let[a,i]=kt.useState(null),[l,s]=kt.useState(false),d=kt.useRef(null);if(kt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),!a)return null;let c=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function p(v){o?.(v.nativeEvent),d.current={x:v.clientX,y:v.clientY},s(true),v.currentTarget.setPointerCapture(v.pointerId);}function b(v){let k=d.current;if(!k)return;let N=v.clientX-k.x,T=v.clientY-k.y;(e.edge==="top"&&T>16||e.edge==="bottom"&&T<-16||e.edge==="right"&&N<-16||e.edge==="left"&&N>16)&&(d.current=null,r(v.nativeEvent));}function y(){d.current=null,s(false);}function g(){d.current=null,s(false);}return reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:c,style:{zIndex:e.zIndex,opacity:n?0:1,pointerEvents:n?"none":"auto"},"aria-label":e.label,"aria-hidden":n?true:void 0,tabIndex:n?-1:0,onClick:v=>r(v.nativeEvent),onPointerDown:p,onPointerMove:b,onPointerUp:y,onPointerCancel:g,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),a)}function Yt(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function Xt(e){return {kind:"floating",placement:e.placement??"br",offset:{x:e.offset?.x??16,y:e.offset?.y??16},safeArea:e.safeArea??true,avoid:e.avoid===false?false:e.avoid==null?"auto":Array.isArray(e.avoid)?e.avoid:[e.avoid],hideOnKeyboard:e.hideOnKeyboard??true,zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var qo={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function Jt(e){let t=kt.useId();kt.useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,o=`data-lumen-theme-${jo(t)}`,r={};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")r["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else for(let[a,i]of Object.entries(qo)){let l=e[i];typeof l=="string"&&l.length>0&&(r[a]=n.style.getPropertyValue(a)||null,n.style.setProperty(a,l));}return n.setAttribute(o,""),()=>{n.removeAttribute(o);for(let[a,i]of Object.entries(r))a.startsWith("--")?i?n.style.setProperty(a,i):n.style.removeProperty(a):i==null?n.removeAttribute(a):n.setAttribute(a,i);}},[e,t]);}function jo(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var Zt=Symbol.for("lumen.history.patched"),nt="lumen:locationchange";function Yo(){if(typeof window>"u")return;let e=window;if(e[Zt])return;e[Zt]=true;let t=()=>window.dispatchEvent(new Event(nt)),n=history.pushState;history.pushState=function(...r){let a=n.apply(this,r);return t(),a};let o=history.replaceState;history.replaceState=function(...r){let a=o.apply(this,r);return t(),a},window.addEventListener("popstate",t);}function Qt(e){let[t,n]=kt.useState(false);return kt.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;Yo();let o=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return o(),window.addEventListener(nt,o),window.addEventListener("popstate",o),()=>{window.removeEventListener(nt,o),window.removeEventListener("popstate",o);}},[e]),t}var Zo=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function en(){let[e,t]=kt.useState(false);return kt.useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let o=n.webkit;if(o&&o.messageHandlers){t(true);return}let r=navigator.userAgent||"";Zo.some(a=>r.includes(a))&&t(true);},[]),e}var nn="lumen.config.v1.",tr=3600*1e3;function on(e,t){let[n,o]=kt.useState(()=>({trigger:null,enabled:true,shakeToOpen:false,loading:true}));return kt.useEffect(()=>{if(typeof window>"u")return;let r=ar(e);r&&o({trigger:r.trigger,enabled:tn(r.trigger),shakeToOpen:r.shake,loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),l=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(l,{method:"GET",mode:"cors",credentials:"omit",signal:a.signal}).then(async s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);let d=await s.json(),c=rn(d.trigger);if(!c)throw new Error("Malformed config response");let p=rr(d.trigger);ir(e,c,p),o({trigger:c,enabled:tn(c),shakeToOpen:p,loading:false});}).catch(()=>{o(s=>s.loading?{trigger:null,enabled:true,shakeToOpen:false,loading:false}:s);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function tn(e){return e.kind!=="headless"}var nr=["br","bl","tr","tl"],or=["top","right","bottom","left"];function rn(e){if(!e||typeof e!="object")return null;let t=e;if(t.enabled===false)return {kind:"headless"};let n=typeof t.label=="string"?t.label:"Feedback";return t.kind==="floating"?{kind:"floating",placement:nr.find(r=>r===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:or.find(r=>r===t.edge)??"top",label:n}:null}function rr(e){return !e||typeof e!="object"?false:e.shake===true}function ar(e){try{let t=window.localStorage.getItem(nn+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>tr)return null;let o=rn(n.trigger);return o?{fetchedAt:n.fetchedAt,trigger:o,shake:n.shake===!0}:null}catch{return null}}function ir(e,t,n){try{window.localStorage.setItem(nn+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n}));}catch{}}function sr(e){if(e&&typeof e=="object")return e.type===Ae;if(typeof e=="string")try{return JSON.parse(e).type===Ae}catch{return false}return false}function ur(e={}){let t=e.threshold??18,n=e.neededHits??3,o=e.windowMs??700,r=e.throttleMs??60,a=null,i=[];return {push(l,s,d,c){if(!a)return a={x:l,y:s,z:d,t:c},false;if(c-a.t<r)return false;let p=Math.abs(l-a.x)+Math.abs(s-a.y)+Math.abs(d-a.z);return a={x:l,y:s,z:d,t:c},p<t?false:(i=i.filter(b=>c-b<o),i.push(c),i.length>=n?(i=[],true):false)}}}function an(e,t,n){kt.useEffect(()=>{if(!e||typeof window>"u")return;let o=0,r=1500;function a(){let c=Date.now();n||c-o<r||(o=c,t());}let i=c=>{sr(c.data)&&a();};window.addEventListener("message",i),document.addEventListener("message",i);let l=ur(),s=c=>{let p=c.accelerationIncludingGravity??c.acceleration;!p||p.x==null||p.y==null||p.z==null||l.push(p.x,p.y,p.z,Date.now())&&a();},d=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return d&&window.addEventListener("devicemotion",s),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),d&&window.removeEventListener("devicemotion",s);}},[e,t,n]);}var sn="https://shakebugs.vercel.app",un=60;function cr({apiKey:e,apiUrl:t,user:n,amplitude:o,floatingButton:r=true,trigger:a,hideOn:i,theme:l,portalTarget:s,capture:d,shakeToOpen:c,onOpenChange:p,beforeOpen:b,onTriggerActivate:y,children:g}){let[v,k]=kt.useState(false),[N,T]=kt.useState(false),[L,A]=kt.useState(null),[H,P]=kt.useState(null),[V]=kt.useState(false),[_]=kt.useState(null),U=kt.useRef(false),j=kt.useRef(false),J=kt.useRef(null),K=kt.useMemo(()=>new mt({apiKey:e,apiUrl:t,user:n,amplitude:o}),[e,t,n?.id,n?.email,n?.name,o?.userId,o?.deviceId,o?.sessionId]);kt.useEffect(()=>{bt({ignoreUrlPrefix:(t??sn).replace(/\/$/,"")});},[t]);let B=kt.useRef(p);B.current=p,kt.useEffect(()=>{if(!(typeof document>"u"))return v?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[v]);let f=kt.useRef(null);kt.useEffect(()=>{if(f.current===v)return;let M=f.current;f.current=v,M!==null&&B.current?.(v);},[v]);let h=kt.useRef(b);h.current=b;let E=kt.useRef(y);E.current=y;let x=kt.useCallback(M=>{j.current=true,J.current=Promise.resolve().then(()=>h.current?.(M)).then(()=>E.current?.(M)).then(()=>{});},[]),D=kt.useCallback(M=>{U.current||v||ne.current||(U.current=true,T(true),A(null),P(null),(async()=>{try{if(j.current?await J.current:(await h.current?.(M),await E.current?.(M)),d?.mode==="manual")A(null),P(null);else {let Y=await Ne({...d,mode:d?.mode??"auto",target:d?.target??document.documentElement});A(Y);}}catch(Y){P(Y instanceof Error?Y:new Error(String(Y)));}finally{j.current=false,J.current=null,U.current=false,T(false),k(true);}})());},[d,v]),I=kt.useCallback(()=>k(false),[]),W=kt.useCallback(K.submit.bind(K),[K]),[S,G]=kt.useState(null),ne=kt.useRef(null),Z=kt.useRef(null),Q=kt.useRef(null),oe=kt.useCallback(M=>{if(ne.current=null,G(null),!M){Z.current=null;return}Q.current={blob:M.blob,durationMs:M.durationMs,poster:Z.current},Z.current=null,k(true);},[]),Me=kt.useCallback(async()=>{if(ne.current)return;let M=await Et(un);ne.current=M,Z.current=null,G({stream:M.stream,startedAt:Date.now(),maxSeconds:un}),k(false),Lt(M.stream).then(Y=>{Z.current=Y;}).catch(()=>{}),M.result.then(Y=>oe(Y)).catch(()=>oe(null));},[oe]),fe=kt.useCallback(()=>{ne.current?.stop();},[]),ge=kt.useCallback(()=>{let M=ne.current;ne.current=null,Z.current=null,G(null),M?.cancel(),A(null),P(null),k(true);},[]),se=kt.useCallback(()=>{let M=Q.current;return Q.current=null,M},[]),he=en(),be=Qt(i);Jt(l);let ee=on(a?"":e,t??sn),ve=c??ee.shakeToOpen;an(ve,D,v);let He=kt.useMemo(()=>({client:K,user:n,isOpen:v,isSubmitting:V,error:_,open:D,close:I,openCapture:D,closeCapture:I,submit:W,isNativeShell:he,capture:d,initialCapture:L,initialCaptureError:H,isOpening:N,startVideoSession:Me,stopVideoSession:fe,cancelVideoSession:ge,recording:S,consumePendingVideo:se}),[K,n,v,V,_,D,I,W,he,d,L,H,Me,fe,ge,S,se,N]),$=dr({explicit:a,remote:ee.trigger,remoteLoading:ee.loading,floatingButton:r});return jsxRuntime.jsxs($e.Provider,{value:He,children:[g,$?.kind==="floating"?jsxRuntime.jsx($t,{config:Xt($),portalTarget:s,hidden:be||N||S!=null,onPointerDown:x,onClick:M=>D(M)}):null,$?.kind==="notch"?jsxRuntime.jsx(Gt,{config:Yt($),portalTarget:s,hidden:be||N||S!=null,onPointerDown:x,onClick:M=>D(M)}):null,$?.kind==="inline"?jsxRuntime.jsx(qt,{mount:$.mount,label:$.label??"Feedback",icon:$.icon,onPointerDown:x,onClick:M=>D(M)}):null,S?jsxRuntime.jsx(Vt,{startedAt:S.startedAt,maxSeconds:S.maxSeconds,portalTarget:s,onStop:fe,onCancel:ge}):null,jsxRuntime.jsx(Qe,{})]})}function dr(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function pr({variant:e="default",floating:t=false,className:n,children:o="Feedback",onClick:r,...a}){let{openCapture:i}=Ce(),l=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsxRuntime.jsx("button",{type:"button",className:l,"data-lumen-trigger":"",onClick:s=>{r?.(s),s.defaultPrevented||i(s.nativeEvent);},...a,children:o})}
|
|
4
|
-
exports.CaptureModal=
|
|
2
|
+
'use strict';var Ot=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 Ot__namespace=/*#__PURE__*/_interopNamespace(Ot);var T=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},ht=class extends T{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},bt=class extends T{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},Fe=class extends T{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},Tn="https://shakebugs.vercel.app",Pn="/api/v1/sdk/submit",Ln=new Set([502,503,504]),Rt=class{apiKey;apiUrl;user;amplitude;constructor(e){if(!e.apiKey||!e.apiKey.startsWith("lk_pub_"))throw new T("Invalid Lumen apiKey \u2014 expected a key starting with `lk_pub_`.","INVALID_API_KEY");this.apiKey=e.apiKey,this.apiUrl=(e.apiUrl??Tn).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${Pn}`,r=this.#e(e),o=null;for(let a=0;a<3;a++){a>0&&await An(2**a*250);try{return await this.#t(n,r,t)}catch(i){if(o=i,i instanceof ht||i instanceof bt||i instanceof T&&typeof i.status=="number"&&!Ln.has(i.status))throw i}}throw o instanceof Error?o:new Fe("Submit failed after 3 attempts.")}#e(e){let t=new FormData;e.rawText&&t.append("rawText",e.rawText),e.category&&t.append("category",e.category),e.submitterEmail&&t.append("submitterEmail",e.submitterEmail),e.submitterFingerprint&&t.append("submitterFingerprint",e.submitterFingerprint);let n=e.context.amplitude??this.amplitude,r=n?{...e.context,amplitude:n}:e.context;return t.append("context",JSON.stringify(r)),e.screenshot&&t.append("screenshot",e.screenshot,Nn(e.screenshot)),e.audio&&t.append("audio",e.audio,"audio"),e.audioDurationMs!=null&&t.append("audioDurationMs",String(e.audioDurationMs)),e.video&&t.append("video",e.video,"video"),e.videoDurationMs!=null&&t.append("videoDurationMs",String(e.videoDurationMs)),t}#t(e,t,n){return new Promise((r,o)=>{let a=new XMLHttpRequest;a.open("POST",e,true),a.setRequestHeader("X-Lumen-Api-Key",this.apiKey),a.responseType="text";let{onUploadProgress:i,signal:l}=n;i&&a.upload.addEventListener("progress",m=>{m.lengthComputable&&m.total>0&&i(Math.min(1,m.loaded/m.total));});let s=()=>{a.abort(),o(new Fe("Submit aborted."));};if(l){if(l.aborted){o(new Fe("Submit aborted."));return}l.addEventListener("abort",s,{once:true});}a.addEventListener("load",()=>{if(l&&l.removeEventListener("abort",s),a.status===403){o(new ht);return}if(a.status===429){let m=Number(a.getResponseHeader("Retry-After"))||60;o(new bt(m));return}if(a.status<200||a.status>=300){o(new T(In(a.responseText)??`HTTP ${a.status}`,"HTTP_ERROR",a.status));return}try{let m=JSON.parse(a.responseText);r(m);}catch{o(new T("Malformed response from server.","BAD_RESPONSE"));}}),a.addEventListener("error",()=>{l&&l.removeEventListener("abort",s),o(new Fe("Network error during submit."));}),a.send(t);})}};function Nn(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function An(e){return new Promise(t=>setTimeout(t,e))}function In(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var Dn=2,Le=8*1024*1024;async function ze(e={}){kt();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return Hn(await e.provider(),e)}catch(n){if(t==="custom")throw n;e.onWarning?.(["Custom capture provider failed; falling back to browser DOM capture."]);}if(t==="manual")throw new T("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return wt(e);if(t==="dom")return vt(e);if(t==="custom")throw new T("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await vt(e)}catch(n){if(St()){let r=await wt(e);return r.warnings=Ae(["DOM screenshot failed; used browser screen permission fallback.",...r.warnings]),e.onWarning?.(r.warnings),r}throw n}}function Ne(e,t=[]){kt();let n=$e();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:Ae(t)}}async function vt(e){let t=await On(),n=e.target??document.documentElement,r=$e(),o=Math.max(1,Math.min(window.devicePixelRatio??1,e.maxScale??Dn)),a=Vn(n),i=await t(n,{backgroundColor:null,logging:false,useCORS:true,allowTaint:false,width:r.width,height:r.height,windowWidth:r.width,windowHeight:r.height,scrollX:window.scrollX,scrollY:window.scrollY,x:window.scrollX,y:window.scrollY,scale:o,ignoreElements:s=>s instanceof HTMLElement&&(s.dataset.lumenCaptureIgnore==="true"||!!s.closest("[data-lumen-capture-ignore='true']"))}),l={blob:await xt(i,a),method:"web-dom",platform:"web",viewport:r,pixelRatio:o,warnings:Ae(a)};return l.warnings.length>0&&e.onWarning?.(l.warnings),l}async function On(){let{default:e}=await import('html2canvas-pro');return e}async function wt(e){if(!St())throw new T("Browser screen capture is unavailable in this environment.","DISPLAY_MEDIA_UNAVAILABLE");let t=await navigator.mediaDevices.getDisplayMedia({video:true,audio:false});try{let n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.srcObject=t,await Bn(n);let r=document.createElement("canvas");r.width=n.videoWidth,r.height=n.videoHeight;let o=r.getContext("2d");if(!o)throw new T("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");o.drawImage(n,0,0,r.width,r.height);let a=$e(),i=["Browser screen capture uses the window or tab selected by the user."],l={blob:await xt(r,i),method:"web-display-media",platform:"web",viewport:a,pixelRatio:a.width>0?r.width/a.width:void 0,warnings:Ae(i)};return e.onWarning?.(l.warnings),l}finally{for(let n of t.getTracks())n.stop();}}function Hn(e,t){let n=$e(),r={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:Ae(e.warnings??[])};return r.warnings.length>0&&t.onWarning?.(r.warnings),r}function Vn(e){let t=new Set;e.querySelector("iframe")&&t.add("Embedded iframes may be blank or incomplete in DOM capture."),e.querySelector("video")&&t.add("Video frames may be blank or stale in DOM capture."),e.querySelector("canvas")&&t.add("Canvas/WebGL content may be blank if it is cross-origin tainted."),document.fonts&&document.fonts.status!=="loaded"&&t.add("Web fonts were still loading when the screenshot was captured.");let n=0;for(let r of Array.from(e.querySelectorAll("img"))){let o=r.currentSrc||r.src;if(o)try{new URL(o,window.location.href).origin!==window.location.origin&&!r.crossOrigin&&(n+=1);}catch{}}return n>0&&t.add(`${n} cross-origin image${n===1?"":"s"} without CORS may be omitted from the screenshot.`),Array.from(t)}async function xt(e,t){let n=await yt(e,"image/png",.92);if(n.size<=Le)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let r=e,o=0;for(;n.size>Le&&o<6;){let a=Math.max(.35,Math.min(.95,Math.sqrt(Le/n.size)*.9)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(r.width*a)),i.height=Math.max(1,Math.round(r.height*a));let l=i.getContext("2d");if(!l)return n;l.drawImage(r,0,0,i.width,i.height),r=i;for(let s of [.86,.74,.62,.5])if(n=await yt(r,"image/jpeg",s),n.size<=Le)return n;if(o+=1,i.width<480||i.height<320)break}return n.size>Le&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function yt(e,t,n){return new Promise((r,o)=>{e.toBlob(a=>{if(!a){o(new T("Could not encode screenshot.","ENCODE_FAILED"));return}r(a);},t,n);})}function $e(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function St(){return !!navigator.mediaDevices?.getDisplayMedia}async function Bn(e){await new Promise((r,o)=>{let a=()=>r(),i=()=>o(new T("Could not read screen capture video.","VIDEO_FAILED"));e.addEventListener("loadedmetadata",a,{once:true}),e.addEventListener("error",i,{once:true}),e.play().catch(i);});let t=performance.now(),n=1500;for(;e.videoWidth===0||e.videoHeight===0;){if(performance.now()-t>n)throw new T("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(r=>requestAnimationFrame(()=>r()));}}function kt(){if(typeof window>"u"||typeof document>"u")throw new T("Screenshot capture can only run in the browser.","INVALID_ENV")}function Ae(e){return Array.from(new Set(e.filter(Boolean)))}var Mt=[],Ue=[],Et=false,Ze=null;function Tt(e={}){Et||typeof window>"u"||(Et=true,Ze=e.ignoreUrlPrefix??null,Wn(),zn(),$n());}function _n(){return {consoleLog:Mt.slice(),networkLog:Ue.slice()}}function We(e,t){e.push(t),e.length>200&&e.splice(0,e.length-200);}function Fn(e){let t=[];for(let r of e){if(typeof r=="string"){t.push(r);continue}if(r instanceof Error){t.push(`${r.name}: ${r.message}${r.stack?`
|
|
3
|
+
${r.stack}`:""}`);continue}try{t.push(JSON.stringify(r,Un));}catch{t.push(String(r));}}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 Wn(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let r=e[n]?.bind(e);r&&(e[n]=(...o)=>{try{We(Mt,{level:n,ts:Date.now(),message:Fn(o)});}catch{}r(...o);});}}function Pt(e){return Ze?e.startsWith(Ze):false}function zn(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let r=typeof t=="string"?t:t instanceof URL?t.toString():t.url,o=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(Pt(r))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return We(Ue,{type:"fetch",method:o,url:Qe(r),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw We(Ue,{type:"fetch",method:o,url:Qe(r),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function $n(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(r,o,...a){return this.__lumen={method:String(r).toUpperCase(),url:typeof o=="string"?o:o.toString(),t:0},t.call(this,r,o,...a)},e.prototype.send=function(r){let o=this.__lumen;if(o&&!Pt(o.url)){o.t=performance.now();let a=()=>{try{We(Ue,{type:"xhr",method:o.method,url:Qe(o.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-o.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",a);};this.addEventListener("loadend",a);}return n.call(this,r??null)};}function Qe(e){return e.length>512?e.slice(0,512)+"\u2026":e}function Lt(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:Ct(e),consoleLog:[],networkLog:[]};let t=_n();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:Ct(e),device:qn(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function qn(){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 Ct(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var qe="lumen:shake",jn=8e3,Kn=50,Gn='[data-lumen-root], [data-lumen-capture-ignore="true"]';function Yn(e={}){return async function(){if(typeof window>"u")throw new T("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=Jn(),n=e.send??Xn,r=e.timeoutMs??jn,o=e.captureSettleMs??Kn,a=rr(),i=Qn(e.concealSelector===void 0?Gn:e.concealSelector);try{await er(o);let l=await new Promise((c,p)=>{let h=window.setTimeout(()=>{t.pending.delete(a),p(new T("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},r);t.pending.set(a,{resolve:C=>{window.clearTimeout(h),c(C);},reject:C=>{window.clearTimeout(h),p(C);}});try{n({type:"lumen:capture-request",id:a,afterScreenUpdates:!0});}catch{t.pending.delete(a),window.clearTimeout(h),p(new T("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new T(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let s=or(l.dataUrl),m=e.platform??nr();return {blob:s,method:m==="android"?"android-native":"ios-native",platform:m,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:l.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{i();}}}function Xn(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new T("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function Jn(){if(window.__lumenNativeCapture)return window.__lumenNativeCapture;let e={pending:new Map,resolve(n,r,o){let a=e.pending.get(n);a&&(e.pending.delete(n),a.resolve({type:"lumen:capture-response",id:n,dataUrl:r,pixelRatio:o}));},reject(n,r){let o=e.pending.get(n);o&&(e.pending.delete(n),o.resolve({type:"lumen:capture-response",id:n,error:r}));}},t=n=>{let r=Zn(n.data);if(!r||r.type!=="lumen:capture-response")return;let o=e.pending.get(r.id);o&&(e.pending.delete(r.id),o.resolve(r));};return window.addEventListener("message",t),document.addEventListener("message",t),window.__lumenNativeCapture=e,e}function Zn(e){if(e&&typeof e=="object"&&"type"in e)return e;if(typeof e=="string")try{let t=JSON.parse(e);if(t&&typeof t=="object"&&t.type)return t}catch{}return null}function Qn(e){if(!e||typeof document>"u")return ()=>{};let t=[];for(let n of Array.from(document.querySelectorAll(e)))t.push({el:n,prev:n.style.visibility}),n.style.visibility="hidden";return ()=>{for(let{el:n,prev:r}of t)n.style.visibility=r;}}async function er(e){await tr(),e>0&&await new Promise(t=>window.setTimeout(t,e));}function tr(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function nr(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function rr(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function or(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new T("Native host returned an invalid image data URL.","NATIVE_CAPTURE_FAILED");let n=t[1]||"image/png",r=!!t[2],o=t[3]??"";if(!r)return new Blob([decodeURIComponent(o)],{type:n});let a=atob(o),i=new Uint8Array(a.length);for(let l=0;l<a.length;l++)i[l]=a.charCodeAt(l);return new Blob([i],{type:n})}var ar="[data-lumen-root]",ir="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function lr(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(et(n))return true;return et(e.target)}function et(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(ir)?true:!!e.closest(ar):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?et(e.host):false:false}async function Nt(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(s=>MediaRecorder.isTypeSupported(s))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null;r.addEventListener("dataavailable",s=>{s.data&&s.data.size>0&&o.push(s.data);}),r.start(),i=window.setTimeout(()=>{r.state!=="inactive"&&r.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{r.state!=="inactive"&&r.stop();}catch{}l();},stop(){return new Promise((s,m)=>{if(r.state==="inactive"){l(),m(new T("Recorder already stopped.","RECORDER_STOPPED"));return}r.addEventListener("stop",()=>{let c=performance.now()-a,p=r.mimeType||n||"audio/webm",h=new Blob(o,{type:p});l(),s({blob:h,durationMs:c,mimeType:p});},{once:true}),r.stop();})}}}async function At(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(y=>MediaRecorder.isTypeSupported(y))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,l=false,s=false,m,c,p=new Promise((y,v)=>{m=y,c=v;});p.catch(()=>{});function h(){i!==null&&(window.clearTimeout(i),i=null);for(let y of t.getTracks())y.stop();}r.addEventListener("dataavailable",y=>{y.data&&y.data.size>0&&o.push(y.data);}),r.addEventListener("stop",()=>{if(l)return;if(l=true,h(),s){c(new T("Recording cancelled.","RECORDER_STOPPED"));return}let y=r.mimeType||n||"video/webm";m({blob:new Blob(o,{type:y}),durationMs:performance.now()-a,mimeType:y});});function C(){r.state!=="inactive"&&r.stop();}return r.start(),i=window.setTimeout(C,e*1e3),t.getVideoTracks()[0]?.addEventListener("ended",C),{stream:t,result:p,stop:C,cancel(){s=true,r.state!=="inactive"?r.stop():l||(l=true,h(),c(new T("Recording cancelled.","RECORDER_STOPPED")));}}}var tt=Ot.createContext(null);function Ie(){let e=Ot.useContext(tt);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var rt='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, sans-serif';function Dt(e,t=1){return Math.max(0,Math.min(t,e))}var Ht=Ot__namespace.forwardRef(function({screenshot:t,tool:n,color:r="rgb(239, 68, 68)",strokeWidth:o=4,onDrawingChange:a},i){let l=Ot.useRef(null),s=Ot.useRef(null),m=Ot.useRef(null),[c,p]=Ot.useState(null),[h,C]=Ot.useState([]),y=Ot.useRef(null),v=Ot.useRef(false),b=Ot.useRef(0),x=Ot.useRef(false),[M,P]=Ot.useState([]),A=Ot.useRef(0),I=Ot.useRef([]),N=Ot.useRef(null),_=Ot.useCallback((f,g)=>{P(R=>R.map(S=>S.id===f?{...S,text:g}:S));},[]),Q=Ot.useCallback(f=>{P(R=>R.filter(S=>S.id!==f));let g=I.current.lastIndexOf("comment");g>=0&&I.current.splice(g,1);},[]);Ot.useEffect(()=>{let f=N.current;if(f==null)return;N.current=null,m.current?.querySelector(`[data-bubble-id="${f}"] .lumen-bubble-text`)?.focus();},[M]),Ot.useEffect(()=>{let f=false,g=null;return (async()=>{try{let R=await createImageBitmap(t);if(f){R.close?.();return}g=R,p(R);}catch{}})(),()=>{f=true,g?.close?.();}},[t]),Ot.useEffect(()=>{if(!c)return;let f=l.current,g=s.current;if(!f||!g)return;f.width=c.width,f.height=c.height,g.width=c.width,g.height=c.height;let R=f.getContext("2d");R&&(R.imageSmoothingEnabled=false,R.drawImage(c,0,0));},[c]),Ot.useEffect(()=>{let f=s.current;f&&je(f,h,y.current);},[h]),Ot.useImperativeHandle(i,()=>({hasAnnotations:()=>h.length>0||M.some(f=>f.text.trim().length>0),reset:()=>{C([]),P([]),I.current=[];},undo:()=>{(I.current.pop()??"anno")==="comment"?P(g=>g.length===0?g:g.slice(0,-1)):C(g=>g.length===0?g:g.slice(0,-1));},async flatten(){let f=y.current,g=f?[...h,f]:h,R=M.filter(L=>L.text.trim().length>0);if(g.length===0&&R.length===0||!c)return t;let S=document.createElement("canvas");S.width=c.width,S.height=c.height;let B=S.getContext("2d");if(!B)return t;B.imageSmoothingEnabled=false,B.drawImage(c,0,0);for(let L of g)ot(B,L);let H=l.current?.clientWidth||c.width,Y=c.width/Math.max(H,1);for(let L of R)fr(B,L,c.width,c.height,Y);return await new Promise(L=>{S.toBlob(X=>{L(X??t);},"image/jpeg",.85);})}}),[h,M,c,t]);function W(f){let g=s.current;if(!g)return {x:0,y:0};let R=g.getBoundingClientRect(),S=g.width/Math.max(R.width,1),B=g.height/Math.max(R.height,1);return {x:(f.clientX-R.left)*S,y:(f.clientY-R.top)*B}}function q(){x.current||(x.current=true,requestAnimationFrame(()=>{x.current=false;let f=s.current;f&&je(f,h,y.current);}));}function te(f){if(f.button!==void 0&&f.button!==0)return;if(n==="comment"){let R=s.current;if(!R)return;let S=R.getBoundingClientRect(),B=Dt((f.clientX-S.left)/Math.max(S.width,1),.72),H=Dt((f.clientY-S.top)/Math.max(S.height,1),.8),Y=++A.current;P(L=>[...L,{id:Y,x:B,y:H,text:"",color:r}]),I.current.push("comment"),N.current=Y;return}try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}v.current=true,a?.(true);let g=W(f);n==="arrow"?y.current={kind:"arrow",from:g,to:g,color:r,width:o}:n==="rect"?y.current={kind:"rect",from:g,to:g,color:r,width:o}:y.current={kind:"freehand",points:[g],color:r,width:o},b.current=performance.now(),q();}function ie(f){if(!v.current||!y.current)return;let g=W(f),R=y.current;if(R.kind==="arrow"||R.kind==="rect")R.to=g;else {let S=R.points[R.points.length-1],B=S?(S.x-g.x)**2+(S.y-g.y)**2:1/0,H=performance.now(),Y=H-b.current;(B>16||Y>16)&&(R.points.push(g),b.current=H);}q();}function z(){if(!v.current)return;v.current=false,a?.(false);let f=y.current;if(y.current=null,!!f){if(f.kind==="arrow"||f.kind==="rect"){let g=f.to.x-f.from.x,R=f.to.y-f.from.y;if(g*g+R*R<16){let S=s.current;S&&je(S,h,null);return}}else if(f.points.length<2){let g=s.current;g&&je(g,h,null);return}C(g=>[...g,f].slice(-50)),I.current.push("anno");}}return jsxRuntime.jsxs("div",{ref:m,className:"lumen-annotate-frame","data-lumen-tool":n,children:[jsxRuntime.jsx("canvas",{ref:l}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:te,onPointerMove:ie,onPointerUp:z,onPointerCancel:z}),jsxRuntime.jsx("div",{className:"lumen-bubble-layer",children:M.map(f=>jsxRuntime.jsx(mr,{comment:f,onChange:_,onRemove:Q},f.id))})]})});function mr({comment:e,onChange:t,onRemove:n}){let r=Ot.useRef(null);return Ot.useEffect(()=>{let o=r.current;o&&o.textContent!==e.text&&(o.textContent=e.text);},[]),jsxRuntime.jsxs("div",{className:"lumen-bubble","data-bubble-id":e.id,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,"--lumen-bubble-accent":e.color},onPointerDown:o=>o.stopPropagation(),children:[jsxRuntime.jsx("span",{className:"lumen-bubble-label",children:"Comment"}),jsxRuntime.jsx("div",{ref:r,className:"lumen-bubble-text",contentEditable:true,suppressContentEditableWarning:true,role:"textbox","aria-label":"Comment text","data-placeholder":"Type a note\u2026",onInput:o=>t(e.id,o.currentTarget.textContent??"")}),jsxRuntime.jsx("button",{type:"button",className:"lumen-bubble-del","aria-label":"Remove comment",onPointerDown:o=>o.stopPropagation(),onClick:()=>n(e.id),children:"\xD7"})]})}function je(e,t,n){let r=e.getContext("2d");if(r){r.clearRect(0,0,e.width,e.height);for(let o of t)ot(r,o);n&&ot(r,n);}}function ot(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let n=Math.min(t.from.x,t.to.x),r=Math.min(t.from.y,t.to.y),o=Math.abs(t.to.x-t.from.x),a=Math.abs(t.to.y-t.from.y);e.strokeRect(n,r,o,a);}else if(t.kind==="freehand")pr(e,t.points);else {let{from:n,to:r,width:o}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(r.x,r.y),e.stroke();let a=Math.atan2(r.y-n.y,r.x-n.x),i=Math.max(12,o*4);e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(r.x-i*Math.cos(a-Math.PI/7),r.y-i*Math.sin(a-Math.PI/7)),e.lineTo(r.x-i*Math.cos(a+Math.PI/7),r.y-i*Math.sin(a+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function pr(e,t){if(t.length===0)return;e.beginPath();let n=t[0];if(!n)return;if(e.moveTo(n.x,n.y),t.length===1){e.arc(n.x,n.y,e.lineWidth/2,0,Math.PI*2),e.fill();return}if(t.length===2){let o=t[1];e.lineTo(o.x,o.y),e.stroke();return}for(let o=1;o<t.length-1;o++){let a=t[o],i=t[o+1],l=(a.x+i.x)/2,s=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,l,s);}let r=t[t.length-1];e.lineTo(r.x,r.y),e.stroke();}function fr(e,t,n,r,o){let a=t.text.trim();if(!a)return;let i=10*o,l=14*o,s=10*o,m=12*o,c=l*1.35,p=s*1.7,h=t.x*n,C=t.y*r,y=Math.min(n*.6,n-h-8*o);e.save(),e.font=`500 ${l}px ${rt}`,e.textBaseline="top";let v=gr(e,a,y-i*2),b=v.reduce((N,_)=>Math.max(N,e.measureText(_).width),0),x=Math.min(y,Math.max(b,56*o)+i*2),M=i*2+p+v.length*c;hr(e,h,C,x,M,m),e.fillStyle="#ffffff",e.fill(),e.lineWidth=Math.max(1,o),e.strokeStyle="rgba(0,0,0,0.10)",e.stroke();let P=h+18*o,A=C+M;e.beginPath(),e.moveTo(P,A-o),e.lineTo(P+13*o,A-o),e.lineTo(P+4*o,A+9*o),e.closePath(),e.fillStyle="#ffffff",e.fill(),e.fillStyle=t.color||"rgb(239, 68, 68)",e.font=`700 ${s}px ${rt}`,e.fillText("COMMENT",h+i,C+i),e.fillStyle="#111318",e.font=`500 ${l}px ${rt}`;let I=C+i+p;for(let N of v)e.fillText(N,h+i,I),I+=c;e.restore();}function gr(e,t,n){let r=t.split(/\s+/).filter(Boolean),o=[],a="";for(let i of r){let l=a?`${a} ${i}`:i;a&&e.measureText(l).width>n?(o.push(a),a=i):a=l;}return a&&o.push(a),o.length?o:[t]}function hr(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,r,o,i);return}e.moveTo(t+i,n),e.arcTo(t+r,n,t+r,n+o,i),e.arcTo(t+r,n+o,t,n+o,i),e.arcTo(t,n+o,t,n,i),e.arcTo(t,n,t+r,n,i),e.closePath();}function at({children:e,...t}){return jsxRuntime.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...t,children:e})}function br(e){return jsxRuntime.jsxs(at,{...e,children:[jsxRuntime.jsx("path",{d:"M3 9a2 2 0 0 1 2-2h1.5l1-1.5h5l1 1.5H19a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"13",r:"3.2"})]})}function vr(e){return jsxRuntime.jsxs(at,{...e,children:[jsxRuntime.jsx("rect",{x:"3",y:"6",width:"13",height:"12",rx:"2.5"}),jsxRuntime.jsx("path",{d:"m16 10 5-3v10l-5-3"})]})}function wr(e){return jsxRuntime.jsxs(at,{...e,children:[jsxRuntime.jsx("path",{d:"M12 16V4m0 0 4 4m-4-4-4 4"}),jsxRuntime.jsx("path",{d:"M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})]})}var it={shot:br,video:vr,upload:wr};function Bt(e){let t=e.videoWidth||1280,n=e.videoHeight||720,r=document.createElement("canvas");r.width=t,r.height=n;let o=r.getContext("2d");return o?(o.drawImage(e,0,0,t,n),new Promise(a=>r.toBlob(i=>a(i),"image/jpeg",.82))):Promise.resolve(null)}function yr(e,t){return !Number.isFinite(t)||t<=0?Promise.resolve():new Promise(n=>{e.addEventListener("seeked",()=>n(),{once:true});try{e.currentTime=t;}catch{n();}})}async function st(e){if(typeof document>"u")return {poster:null,durationMs:0};let t=URL.createObjectURL(e),n=document.createElement("video");n.muted=true,n.playsInline=true,n.preload="metadata",n.src=t;try{await new Promise((a,i)=>{n.addEventListener("loadeddata",()=>a(),{once:!0}),n.addEventListener("error",()=>i(new Error("video decode failed")),{once:!0});}),await yr(n,Math.min(.1,(n.duration||0)/2));let r=await Bt(n),o=Number.isFinite(n.duration)?n.duration*1e3:0;return {poster:r,durationMs:o}}catch{return {poster:null,durationMs:0}}finally{URL.revokeObjectURL(t);}}async function ut(e){if(typeof document>"u")return null;let t=document.createElement("video");t.muted=true,t.playsInline=true,t.srcObject=e;try{return await t.play().catch(()=>{}),await new Promise(n=>{if(t.readyState>=2)return n();t.addEventListener("loadeddata",()=>n(),{once:!0}),window.setTimeout(n,600);}),await Bt(t)}catch{return null}finally{t.srcObject=null;}}async function ct(){if(typeof document>"u")return null;let e=document.createElement("canvas");e.width=1280,e.height=720;let t=e.getContext("2d");return t?(t.fillStyle="#0e0e12",t.fillRect(0,0,e.width,e.height),t.fillStyle="#52525b",t.beginPath(),t.moveTo(590,312),t.lineTo(590,408),t.lineTo(694,360),t.closePath(),t.fill(),new Promise(n=>e.toBlob(r=>n(r),"image/jpeg",.8))):null}var dt=60,Er=25*1024*1024,_t=[{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)"}],Ft=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],Ut=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],Wt=[{value:"shot",label:"Screenshot",hint:"This page, instantly",primary:true},{value:"video",label:"Video",hint:"Record up to 60s"},{value:"upload",label:"Upload",hint:"Image or video"}];function mt(){let{client:e,isOpen:t,closeCapture:n,user:r,capture:o,initialCapture:a,initialCaptureError:i,startVideoSession:l,consumePendingVideo:s,canRecordScreen:m,consumeRecordStartError:c}=Ie(),[p,h]=Ot.useState(1),[C,y]=Ot.useState(null),[v,b]=Ot.useState({kind:"idle"}),[x,M]=Ot.useState(false),[P,A]=Ot.useState(0),[I,N]=Ot.useState(null),[_,Q]=Ot.useState(false),[W,q]=Ot.useState("arrow"),[te,ie]=Ot.useState(_t[0].value),[z,f]=Ot.useState(Ft[1].value),[g,R]=Ot.useState(""),[S,B]=Ot.useState("bug"),[H,Y]=Ot.useState(r?.email??""),[L,X]=Ot.useState(null),[V,le]=Ot.useState(null),[ye,ne]=Ot.useState(0),[$,j]=Ot.useState(null),[J,ce]=Ot.useState(null),[ge,Ee]=Ot.useState(false),he=Ot.useRef(null),Se=Ot.useRef(null),Ce=Ot.useRef(null),re=Ot.useRef(false),Re=Ot.useRef(false);if(Ot.useEffect(()=>{t||(Re.current=false);},[t]),Ot.useEffect(()=>{if(!t||Re.current)return;Re.current=true,re.current=false,h(1),y(null),R(""),le(null),ne(0),j(null),M(false),A(0),N(null),Q(false),ce(null);let u=s();if(u)y("video"),j({blob:u.blob,durationMs:u.durationMs}),u.blob.size>Er&&sonner.toast.warning("This recording is large and may be too big to upload. Try a shorter clip if the upload fails."),u.poster?b({kind:"ready",capture:Ne(u.poster,["Screen recording; preview is the first frame."])}):(b({kind:"capturing"}),(async()=>{let E=null;if(u.deriveBlobPoster)try{E=(await st(u.blob)).poster;}catch{E=null;}E=E??await ct(),!re.current&&b(E?{kind:"ready",capture:Ne(E,["Screen recording; preview is the first frame."])}:{kind:"manual"});})());else {let E=c();E?(y("video"),ce(E),b({kind:"idle"})):a?(y("shot"),b({kind:"ready",capture:a})):o?.mode==="manual"?b({kind:"manual"}):o?.provider&&!i?(y("shot"),ke(o.mode??"auto")):b({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."});}return ()=>{re.current=true;}},[t,o,a,i]),Ot.useEffect(()=>{if(!t)return;Ce.current=document.activeElement??null;let u=document.documentElement,E=u.style.overflow,U=u.style.paddingRight,K=window.innerWidth-u.clientWidth;u.style.overflow="hidden",K>0&&(u.style.paddingRight=`${K}px`);let Z=false,de=()=>{if(!Z){Z=true,u.style.overflow=E,u.style.paddingRight=U;try{Ce.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",de),()=>{window.removeEventListener("pagehide",de),de();}},[t]),Ot.useEffect(()=>{if(!t)return;function u(E){if(E.key==="Escape"){E.preventDefault(),n();return}if(E.key!=="Tab")return;let U=Se.current;if(!U)return;let K=Nr(U);if(K.length===0)return;let Z=K[0],de=K[K.length-1],Je=document.activeElement;E.shiftKey&&(Je===Z||!U.contains(Je))?(E.preventDefault(),de.focus()):!E.shiftKey&&Je===de&&(E.preventDefault(),Z.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),Ot.useEffect(()=>{if(!t||v.kind!=="manual")return;function u(E){let Z=Array.from(E.clipboardData?.items??[]).find(de=>de.type.startsWith("image/"))?.getAsFile();Z&&(E.preventDefault(),Me(Z));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,v.kind]),Ot.useEffect(()=>{if(!L)return;let u=Date.now(),E=window.setInterval(()=>{let U=Math.floor((Date.now()-u)/1e3);ne(U),U>=dt&&Pe();},250);return ()=>window.clearInterval(E)},[L]),!t)return null;async function ke(u){re.current=false,b({kind:"capturing"});try{let E=await ze({...o,mode:u,target:o?.target??document.documentElement});return re.current?!1:(Te(E),b({kind:"ready",capture:E}),!0)}catch(E){return re.current||b({kind:"manual",error:E instanceof Error?E.message:"Automatic screenshot capture was unavailable."}),false}}async function xe(u){y(u),ce(null),N(null),u!=="video"&&D(),u==="shot"?await ke(o?.mode??"auto"):u==="video"?(j(null),b({kind:"idle"})):b({kind:"manual"});}async function Me(u){if(u.type.startsWith("image/")){D();let E=Ne(u,["Manual image upload used."]);b({kind:"ready",capture:E});return}if(u.type.startsWith("video/")){b({kind:"capturing"});try{let{poster:E,durationMs:U}=await st(u),K=E??await ct();if(!K){b({kind:"manual",error:"Could not read that video."});return}let Z=Ne(K,["Uploaded video; preview is the first frame."]);j({blob:u,durationMs:U}),b({kind:"ready",capture:Z});}catch{b({kind:"manual",error:"Could not read that video."});}return}sonner.toast.error("Choose an image (PNG, JPEG, WebP) or a video (MP4, WebM).");}function Te(u){u.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function Be(){try{let u=await Nt(dt);X(u);}catch(u){sonner.toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Pe(){if(L)try{let u=await L.stop();le({blob:u.blob,durationMs:u.durationMs});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{X(null);}}function oe(){L?.cancel(),X(null),le(null),ne(0);}async function k(){ce(null);try{await l();}catch(u){sonner.toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}function D(){j(null);}let F=v.kind==="ready";async function Ye(){if(L&&await Pe(),p===1){if(v.kind==="ready"){let u=await he.current?.flatten();N(u??v.capture.blob),Q(u!=null&&u!==v.capture.blob);}h(2);}else p===2?h(3):await xn();}function Rn(){p>1&&h(u=>u-1);}async function xn(){if(v.kind!=="ready")return;let u=g.trim(),{capture:E}=v;M(true),A(0);try{let U=I??E.blob,K=await e.submit({rawText:u.length>0?u:void 0,category:S,submitterEmail:H.trim()||void 0,screenshot:U,audio:V?.blob,audioDurationMs:V?.durationMs,video:$?.blob,videoDurationMs:$?.durationMs,context:Lt(E)},{onUploadProgress:Z=>A(Math.min(.95,Z))});A(1),sonner.toast.success("Feedback sent \u2014 thank you."),K.id,n();}catch(U){sonner.toast.error(U instanceof Error?U.message:"Could not submit feedback"),M(false);}}function Sn(u){u.target===u.currentTarget&&!x&&n();}let _e=Math.round(P*100),Xe=C==="video",kn=p===1&&!F||x,Mn=p<3?"Next":x?_e<95?`Uploading ${_e}%\u2026`:"Almost done\u2026":"Send feedback";return jsxRuntime.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:Sn,children:jsxRuntime.jsxs("div",{ref:Se,className:"lumen-modal","data-lumen-drawing":ge?"true":void 0,children:[jsxRuntime.jsx(Sr,{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(Cr,{step:p}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[p===1?jsxRuntime.jsx("div",{className:"lumen-pane",children:C===null?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:Wt.map(u=>{let E=it[u.value];return jsxRuntime.jsxs("button",{type:"button",className:"lumen-method-btn"+(u.primary?" lumen-method-primary":""),onClick:()=>xe(u.value),disabled:v.kind==="capturing",children:[jsxRuntime.jsx("span",{className:"lumen-method-ico",children:jsxRuntime.jsx(E,{})}),u.primary?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-method-text",children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]}),jsxRuntime.jsx("span",{className:"lumen-method-badge",children:"Fastest"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]})]},u.value)})}),jsxRuntime.jsx("p",{className:"lumen-status lumen-method-help",children:"Choose how to capture your feedback."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method-switch",role:"group","aria-label":"Switch capture method",children:Wt.map(u=>{let E=it[u.value];return jsxRuntime.jsxs("button",{type:"button","aria-pressed":C===u.value,onClick:()=>xe(u.value),disabled:v.kind==="capturing",children:[jsxRuntime.jsx(E,{}),u.label]},u.value)})}),C==="video"&&v.kind==="idle"?jsxRuntime.jsx(Rr,{canRecord:m,onRecord:k,error:J}):null,v.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,v.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:C==="upload"?"Choose an image or video to attach \u2014 or paste an image.":v.error?"Automatic capture was unavailable. Upload or paste an image to continue.":"Upload or paste an image to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:C==="upload"?"Choose a file \u2014 image or video":"Choose or paste an image"}),jsxRuntime.jsx("input",{type:"file",accept:C==="upload"?"image/png,image/jpeg,image/webp,video/mp4,video/webm,video/quicktime":"image/png,image/jpeg,image/webp",onChange:u=>{let E=u.currentTarget.files?.[0];E&&Me(E),u.currentTarget.value="";}})]})]}):null,v.kind==="ready"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Xe?null:jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(Ke,{label:"Arrow",active:W==="arrow",onClick:()=>q("arrow")}),jsxRuntime.jsx(Ke,{label:"Box",active:W==="rect",onClick:()=>q("rect")}),jsxRuntime.jsx(Ke,{label:"Draw",active:W==="freehand",onClick:()=>q("freehand")}),jsxRuntime.jsx(Ke,{label:"Comment",active:W==="comment",onClick:()=>q("comment")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:_t.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":te===u.value,onClick:()=>ie(u.value)},u.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:Ft.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":z===u.value,onClick:()=>f(u.value),children:jsxRuntime.jsx("span",{className:"lumen-stroke-size-dot",style:{width:u.dot,height:u.dot}})},u.value))}),jsxRuntime.jsx("span",{className:"lumen-toolbar-spacer"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>he.current?.undo(),children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>he.current?.reset(),children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(Ht,{ref:he,screenshot:v.capture.blob,tool:W,color:te,strokeWidth:z,onDrawingChange:Ee})}),jsxRuntime.jsxs("div",{className:"lumen-cap-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>C&&xe(C),children:Xe?"\u21BB Re-record":"\u21BB Recapture"}),Xe?$?jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round($.durationMs/1e3),"s recorded"]}):null:jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:[zt(C)," captured \xB7 switch method above anytime"]})]})]}):null]})}):null,p===2?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-form",children:[jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"What happened?"}),jsxRuntime.jsx("textarea",{value:g,onChange:u=>R(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:[!L&&!V?jsxRuntime.jsx("button",{type:"button",onClick:Be,className:"lumen-btn-ghost",children:"Record voice note"}):null,L?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(kr,{stream:L.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[ye,"s / ",dt,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:Pe,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:oe,className:"lumen-btn-ghost",children:"Cancel"})]}):null,V&&!L?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Tr,{blob:V.blob,durationMs:V.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>le(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:Ut.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":S===u.value,onClick:()=>B(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:H,onChange:u=>Y(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,p===3?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-review",children:[jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[zt(C),_?" \xB7 annotated":"",jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>h(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:Ut.find(u=>u.value===S)?.label}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>h(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:[g.trim()?g.trim():jsxRuntime.jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>h(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:()=>le(null),children:"\xD7"})]}):null,$?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round($.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:D,children:"\xD7"})]}):null,H.trim()?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u2709 ",H.trim()]}):null,!V&&!L?jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{h(2),Be();},children:"+ Voice note"}):null]})]})]}):null]}),jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[x?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":_e,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${_e}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:p===1?n:Rn,className:"lumen-btn-ghost",disabled:x,children:p===1?"Cancel":"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:Ye,className:"lumen-btn-primary",disabled:kn,children:Mn})]})]})]})})}function zt(e){return e==="video"?"Screen recording":e==="upload"?"Upload":"Screenshot"}function Cr({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsxRuntime.jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,r)=>jsxRuntime.jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsxRuntime.jsx("span",{className:"lumen-step-num",children:n.n}),jsxRuntime.jsx("span",{className:"lumen-step-lbl",children:n.label}),r<t.length-1?jsxRuntime.jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function Rr({canRecord:e,onRecord:t,error:n}){return e?jsxRuntime.jsxs("div",{className:"lumen-record-prompt",children:[n?jsxRuntime.jsxs("p",{className:"lumen-record-unavailable",role:"alert",children:[n," Try again, or switch to ",jsxRuntime.jsx("strong",{children:"Upload"})," to attach a video instead."]}):null,jsxRuntime.jsx("button",{type:"button",className:"lumen-record-btn","aria-label":"Start screen recording",onClick:t}),jsxRuntime.jsxs("div",{className:"lumen-record-copy",children:[jsxRuntime.jsx("div",{className:"lumen-record-title",children:"Record your screen"}),jsxRuntime.jsx("div",{className:"lumen-record-sub",children:"Tap to start. The sheet closes so you can record freely \u2014 a Stop button stays on screen, then the sheet returns with your clip. Max 60s."})]})]}):jsxRuntime.jsx("div",{className:"lumen-record-prompt",children:jsxRuntime.jsx("p",{className:"lumen-record-unavailable",children:xr()?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Screen recording isn\u2019t available on iOS browsers. Record with Control Center\u2019s screen recorder, then attach the clip via"," ",jsxRuntime.jsx("strong",{children:"Upload"}),"."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Screen recording isn\u2019t available in this browser. Switch to"," ",jsxRuntime.jsx("strong",{children:"Upload"})," to attach a video instead."]})})})}function xr(){if(typeof navigator>"u")return false;let e=navigator.userAgent||"";return /iPad|iPhone|iPod/.test(e)?true:/Macintosh/.test(e)&&typeof document<"u"&&"ontouchend"in document}function Ke({label:e,active:t,onClick:n}){return jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function Sr({onDismiss:e}){let t=Ot.useRef(null),n=Ot.useRef(0),r=Ot.useRef(null);function o(l){l.currentTarget.setPointerCapture(l.pointerId),t.current=l.clientY,n.current=performance.now(),r.current=l.currentTarget.parentElement;}function a(l){if(t.current==null||!r.current)return;let s=Math.max(0,l.clientY-t.current);r.current.style.transform=`translateY(${s}px)`;}function i(l){if(t.current==null||!r.current)return;let s=Math.max(0,l.clientY-t.current),m=Math.max(1,performance.now()-n.current),c=s/m;r.current.style.transform="",r.current.style.transition="",t.current=null,(s>80||c>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:o,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function kr({stream:e}){let t=Ot.useRef(null);return Ot.useEffect(()=>{let n=t.current;if(!n)return;let r=Math.min(window.devicePixelRatio||1,2),o=n.clientWidth||88,a=n.clientHeight||22;n.width=Math.round(o*r),n.height=Math.round(a*r);let i=n.getContext("2d");if(!i)return;i.scale(r,r);let l=window.AudioContext??window.webkitAudioContext;if(!l)return;let s=new l,m=s.createMediaStreamSource(e),c=s.createAnalyser();c.fftSize=1024,c.smoothingTimeConstant=.6,m.connect(c);let p=new Uint8Array(c.fftSize),h=18,C=3,y=3,v=Math.max(2,(o-C*(h-1))/h),b=Math.min(v/2,3),x=new Array(h).fill(0),M=0,P=false;function A(){if(P)return;c.getByteTimeDomainData(p);let I=Math.floor(p.length/h);i.clearRect(0,0,o,a),i.fillStyle=Pr("--lumen-danger")||"rgb(239,68,68)";for(let N=0;N<h;N++){let _=0;for(let z=0;z<I;z++){let f=Math.abs((p[N*I+z]??128)-128);f>_&&(_=f);}let Q=Math.min(1,_/128*1.8),W=x[N]??0;x[N]=Q>W?Q:W+(Q-W)*.35;let q=Math.max(y,x[N]*a),te=N*(v+C),ie=(a-q)/2;Mr(i,te,ie,v,q,b),i.fill();}M=requestAnimationFrame(A);}return M=requestAnimationFrame(A),()=>{P=true,cancelAnimationFrame(M);try{m.disconnect();}catch{}s.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function Mr(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,r,o,i);return}e.moveTo(t+i,n),e.arcTo(t+r,n,t+r,n+o,i),e.arcTo(t+r,n+o,t,n+o,i),e.arcTo(t,n+o,t,n,i),e.arcTo(t,n,t+r,n,i),e.closePath();}function Tr({blob:e,durationMs:t}){let[n,r]=Ot.useState("");return Ot.useEffect(()=>{let o=URL.createObjectURL(e);return r(o),()=>{URL.revokeObjectURL(o);}},[e]),jsxRuntime.jsxs("div",{className:"lumen-audio-preview",children:[jsxRuntime.jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxRuntime.jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function Pr(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var Lr='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Nr(e){return Array.from(e.querySelectorAll(Lr)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function Kt({state:e,portalTarget:t,onStop:n,onCancel:r}){let[o,a]=Ot.useState(false);if(Ot.useEffect(()=>a(true),[]),!o||typeof document>"u")return null;let i=t??document.body;return e.phase==="recording"?reactDom.createPortal(jsxRuntime.jsx(Ar,{startedAt:e.startedAt,maxSeconds:e.maxSeconds,onStop:n,onCancel:r}),i):reactDom.createPortal(jsxRuntime.jsxs("div",{className:"lumen-rec-hud lumen-rec-hud-pending",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-spinner","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"lumen-rec-hud-time",children:e.phase==="starting"?"Starting\u2026":"Processing\u2026"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"})]}),i)}function Ar({startedAt:e,maxSeconds:t,onStop:n,onCancel:r}){let[o,a]=Ot.useState(0);Ot.useEffect(()=>{let l=()=>a(Math.min(t,Math.max(0,Math.floor((Date.now()-e)/1e3))));l();let s=window.setInterval(l,250);return ()=>window.clearInterval(s)},[e,t]);let i=l=>`${Math.floor(l/60)}:${String(l%60).padStart(2,"0")}`;return jsxRuntime.jsxs("div",{className:"lumen-rec-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-dot","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-rec-hud-time",children:[i(o)," ",jsxRuntime.jsxs("span",{className:"lumen-rec-hud-max",children:["/ ",i(t)]})]}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"}),jsxRuntime.jsxs("button",{type:"button",className:"lumen-rec-hud-stop",onClick:n,"aria-label":"Stop recording and return to feedback",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-square","aria-hidden":"true"}),"Stop"]})]})}function pt(e){let t=e.hasProvider&&e.providerAvailable!==false;return {canRecord:t||e.hasGetDisplayMedia,usingProvider:t}}function Gt(e){return typeof e=="object"&&e!==null&&e.code==="RECORDER_STOPPED"}function Yt(e){return e instanceof Error?e:new Error(String(e))}function Xt(e,t,n){let r=false,o=false,a=false,i=null;function l(){o||(o=true,n.onCancelled());}function s(c){o||(o=true,n.onResult(c));}function m(c){o||(o=true,n.onError(c));}return n.onStarting(),Promise.resolve().then(()=>e(t)).then(c=>{if(i=c,r){try{c.cancel();}catch{}l();return}if(n.onActive(c),a){n.onProcessing();try{c.stop();}catch{}}Promise.resolve(c.result).then(p=>{r?l():s(p);}).catch(p=>{r||Gt(p)?l():m(Yt(p));});}).catch(c=>{r||Gt(c)?l():m(Yt(c));}),{stop(){if(!(o||r||a)&&(a=true,i)){n.onProcessing();try{i.stop();}catch{}}},cancel(){if(!(o&&r)){if(r=true,i)try{i.cancel();}catch{}l();}}}}function Jt(){if(typeof document>"u"||typeof window>"u")return 0;let e=window.innerWidth,t=window.innerHeight;if(e===0||t===0)return 0;let n=t-4,r=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],o=new Set,a=0;for(let i of r){let l=document.elementsFromPoint(i,n);for(let s of l){if(o.has(s))continue;o.add(s);let m=window.getComputedStyle(s);if(m.position!=="fixed"&&m.position!=="sticky")continue;let c=s.getBoundingClientRect();c.bottom<t-8||c.bottom>t+8||c.width<e*.6||c.height>a&&(a=c.height);}}return a}function ft(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,r=window.innerHeight,o=0;for(let a of e){let i;try{i=document.querySelectorAll(a);}catch{continue}for(let l of Array.from(i)){let s=l.getBoundingClientRect();if(s.height===0||s.width===0)continue;let m=0;switch(t){case "bottom":if(s.bottom<r-8)break;m=Math.max(0,r-s.top);break;case "top":if(s.top>8)break;m=Math.max(0,s.bottom);break;case "left":if(s.left>8)break;m=Math.max(0,s.right);break;case "right":if(s.right<n-8)break;m=Math.max(0,n-s.left);break}m>o&&(o=m);}}return o}function Zt(e){let[t,n]=Ot.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),r=Ot.useRef(t),o=Hr(e.avoid),a=e.placement,i=e.offset.x,l=e.offset.y;return Ot.useEffect(()=>{if(typeof window>"u")return;let s=0,m=false,c=()=>{if(s=0,m)return;let v=a[0]==="b"?"bottom":"top",b=a[1]==="r"?"right":"left",x=0,M=0;e.avoid==="auto"&&v==="bottom"?x=Jt():Array.isArray(e.avoid)&&(x=ft(e.avoid,v),M=ft(e.avoid,b));let P={bottom:v==="bottom"?l+x:0,top:v==="top"?l+x:0,right:b==="right"?i+M:0,left:b==="left"?i+M:0},A=r.current;(P.bottom!==A.bottom||P.top!==A.top||P.right!==A.right||P.left!==A.left)&&(r.current=P,n(P));},p=()=>{s||(s=window.requestAnimationFrame(c));};p();let h=typeof ResizeObserver<"u"?new ResizeObserver(p):null;h?.observe(document.documentElement);let C=typeof MutationObserver<"u"?new MutationObserver(p):null;C?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",p);let y=window.visualViewport;return y?.addEventListener("resize",p),y?.addEventListener("scroll",p),()=>{m=true,s&&window.cancelAnimationFrame(s),h?.disconnect(),C?.disconnect(),window.removeEventListener("resize",p),y?.removeEventListener("resize",p),y?.removeEventListener("scroll",p);}},[a,i,l,o]),t}function Hr(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function Qt(e){let[t,n]=Ot.useState(false);return Ot.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;let r=window.visualViewport;if(!r||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let o=100,a=0,i=()=>{a=0;let s=window.innerHeight-r.height;n(s>o);},l=()=>{a||(a=window.requestAnimationFrame(i));};return l(),r.addEventListener("resize",l),r.addEventListener("scroll",l),()=>{a&&window.cancelAnimationFrame(a),r.removeEventListener("resize",l),r.removeEventListener("scroll",l);}},[e]),t}function rn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o}){let[a,i]=Ot.useState(null),l=Ot.useRef(null),s=Zt(e),m=Qt(e.hideOnKeyboard);if(Ot.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),Ur(l,!n&&!m),!a)return null;let c=e.placement,p=c[0]==="b"?"bottom":"top",h=c[1]==="r"?"right":"left",C=p==="bottom"?s.bottom:s.top,y=h==="right"?s.right:s.left,v={position:"fixed",[p]:e.safeArea?`calc(${C}px + env(safe-area-inset-${p}, 0px))`:`${C}px`,[h]:e.safeArea?`calc(${y}px + env(safe-area-inset-${h}, 0px))`:`${y}px`,zIndex:e.zIndex,opacity:n||m?0:1,pointerEvents:n||m?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:v,"aria-label":e.label,"aria-hidden":n||m?true:void 0,tabIndex:n||m?-1:0,onPointerDown:b=>r?.(b.nativeEvent),onClick:b=>o(b.nativeEvent),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),a)}function Ur(e,t){let n=Ot.useRef(false);Ot.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let r=window.setTimeout(()=>{let o=e.current;if(!o)return;let a=o.getBoundingClientRect();if(a.width===0||a.height===0)return;let i=a.left+a.width/2,l=a.top+a.height/2,s=document.elementsFromPoint(i,l),m=en(window.getComputedStyle(o).zIndex);for(let c of s){if(c===o||o.contains(c))continue;if(en(window.getComputedStyle(c).zIndex)>m){n.current=true,console.warn("[lumen] trigger is occluded by",c);break}}},250);return ()=>window.clearTimeout(r)},[t,e]);}function en(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function on({mount:e,label:t,icon:n,onPointerDown:r,onClick:o}){let[a,i]=Ot.useState(null);return Ot.useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;i(l);},[e]),a?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onPointerDown:l=>r?.(l.nativeEvent),onClick:l=>o(l.nativeEvent),"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsxRuntime.jsx("span",{children:t})]}),a):null}function sn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o}){let[a,i]=Ot.useState(null),[l,s]=Ot.useState(false),m=Ot.useRef(null);if(Ot.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),!a)return null;let c=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function p(v){r?.(v.nativeEvent),m.current={x:v.clientX,y:v.clientY},s(true),v.currentTarget.setPointerCapture(v.pointerId);}function h(v){let b=m.current;if(!b)return;let x=v.clientX-b.x,M=v.clientY-b.y;(e.edge==="top"&&M>16||e.edge==="bottom"&&M<-16||e.edge==="right"&&x<-16||e.edge==="left"&&x>16)&&(m.current=null,o(v.nativeEvent));}function C(){m.current=null,s(false);}function y(){m.current=null,s(false);}return reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:c,style:{zIndex:e.zIndex,opacity:n?0:1,pointerEvents:n?"none":"auto"},"aria-label":e.label,"aria-hidden":n?true:void 0,tabIndex:n?-1:0,onClick:v=>o(v.nativeEvent),onPointerDown:p,onPointerMove:h,onPointerUp:C,onPointerCancel:y,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),a)}function un(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function cn(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 to={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function dn(e){let t=Ot.useId();Ot.useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,r=`data-lumen-theme-${no(t)}`,o={};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")o["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else for(let[a,i]of Object.entries(to)){let l=e[i];typeof l=="string"&&l.length>0&&(o[a]=n.style.getPropertyValue(a)||null,n.style.setProperty(a,l));}return n.setAttribute(r,""),()=>{n.removeAttribute(r);for(let[a,i]of Object.entries(o))a.startsWith("--")?i?n.style.setProperty(a,i):n.style.removeProperty(a):i==null?n.removeAttribute(a):n.setAttribute(a,i);}},[e,t]);}function no(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var mn=Symbol.for("lumen.history.patched"),gt="lumen:locationchange";function ao(){if(typeof window>"u")return;let e=window;if(e[mn])return;e[mn]=true;let t=()=>window.dispatchEvent(new Event(gt)),n=history.pushState;history.pushState=function(...o){let a=n.apply(this,o);return t(),a};let r=history.replaceState;history.replaceState=function(...o){let a=r.apply(this,o);return t(),a},window.addEventListener("popstate",t);}function pn(e){let[t,n]=Ot.useState(false);return Ot.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;ao();let r=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return r(),window.addEventListener(gt,r),window.addEventListener("popstate",r),()=>{window.removeEventListener(gt,r),window.removeEventListener("popstate",r);}},[e]),t}var so=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function fn(){let[e,t]=Ot.useState(false);return Ot.useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let r=n.webkit;if(r&&r.messageHandlers){t(true);return}let o=navigator.userAgent||"";so.some(a=>o.includes(a))&&t(true);},[]),e}var hn="lumen.config.v1.",mo=3600*1e3;function bn(e,t){let[n,r]=Ot.useState(()=>({trigger:null,enabled:true,shakeToOpen:false,loading:true}));return Ot.useEffect(()=>{if(typeof window>"u")return;let o=ho(e);o&&r({trigger:o.trigger,enabled:gn(o.trigger),shakeToOpen:o.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 m=await s.json(),c=vn(m.trigger);if(!c)throw new Error("Malformed config response");let p=go(m.trigger);bo(e,c,p),r({trigger:c,enabled:gn(c),shakeToOpen:p,loading:false});}).catch(()=>{r(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 gn(e){return e.kind!=="headless"}var po=["br","bl","tr","tl"],fo=["top","right","bottom","left"];function vn(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:po.find(o=>o===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:fo.find(o=>o===t.edge)??"top",label:n}:null}function go(e){return !e||typeof e!="object"?false:e.shake===true}function ho(e){try{let t=window.localStorage.getItem(hn+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>mo)return null;let r=vn(n.trigger);return r?{fetchedAt:n.fetchedAt,trigger:r,shake:n.shake===!0}:null}catch{return null}}function bo(e,t,n){try{window.localStorage.setItem(hn+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n}));}catch{}}function wo(e){if(e&&typeof e=="object")return e.type===qe;if(typeof e=="string")try{return JSON.parse(e).type===qe}catch{return false}return false}function yo(e={}){let t=e.threshold??18,n=e.neededHits??3,r=e.windowMs??700,o=e.throttleMs??60,a=null,i=[];return {push(l,s,m,c){if(!a)return a={x:l,y:s,z:m,t:c},false;if(c-a.t<o)return false;let p=Math.abs(l-a.x)+Math.abs(s-a.y)+Math.abs(m-a.z);return a={x:l,y:s,z:m,t:c},p<t?false:(i=i.filter(h=>c-h<r),i.push(c),i.length>=n?(i=[],true):false)}}}function wn(e,t,n){Ot.useEffect(()=>{if(!e||typeof window>"u")return;let r=0,o=1500;function a(){let c=Date.now();n||c-r<o||(r=c,t());}let i=c=>{wo(c.data)&&a();};window.addEventListener("message",i),document.addEventListener("message",i);let l=yo(),s=c=>{let p=c.accelerationIncludingGravity??c.acceleration;!p||p.x==null||p.y==null||p.z==null||l.push(p.x,p.y,p.z,Date.now())&&a();},m=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return m&&window.addEventListener("devicemotion",s),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),m&&window.removeEventListener("devicemotion",s);}},[e,t,n]);}var En="https://shakebugs.vercel.app",Ge=60;function Cn(){return typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function"}function Eo({apiKey:e,apiUrl:t,user:n,amplitude:r,floatingButton:o=true,trigger:a,hideOn:i,theme:l,portalTarget:s,capture:m,record:c,shakeToOpen:p,onOpenChange:h,beforeOpen:C,onTriggerActivate:y,children:v}){let[b,x]=Ot.useState(false),[M,P]=Ot.useState(false),[A,I]=Ot.useState(null),[N,_]=Ot.useState(null),[Q]=Ot.useState(false),[W]=Ot.useState(null),q=Ot.useRef(false),te=Ot.useRef(false),ie=Ot.useRef(null),z=Ot.useMemo(()=>new Rt({apiKey:e,apiUrl:t,user:n,amplitude:r}),[e,t,n?.id,n?.email,n?.name,r?.userId,r?.deviceId,r?.sessionId]);Ot.useEffect(()=>{Tt({ignoreUrlPrefix:(t??En).replace(/\/$/,"")});},[t]);let f=Ot.useRef(h);f.current=h,Ot.useEffect(()=>{if(!(typeof document>"u"))return b?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[b]);let g=Ot.useRef(null);Ot.useEffect(()=>{if(g.current===b)return;let k=g.current;g.current=b,k!==null&&f.current?.(b);},[b]);let R=Ot.useRef(C);R.current=C;let S=Ot.useRef(y);S.current=y;let B=Ot.useCallback(k=>{te.current=true,ie.current=Promise.resolve().then(()=>R.current?.(k)).then(()=>S.current?.(k)).then(()=>{});},[]),H=Ot.useCallback(k=>{q.current||b||j.current||(q.current=true,P(true),I(null),_(null),(async()=>{try{if(te.current?await ie.current:(await R.current?.(k),await S.current?.(k)),m?.mode==="manual")I(null),_(null);else if(m?.provider)I(null),_(null);else {let D=await ze({...m,mode:m?.mode??"auto",target:m?.target??document.documentElement});I(D);}}catch(D){_(D instanceof Error?D:new Error(String(D)));}finally{te.current=false,ie.current=null,q.current=false,P(false),x(true);}})());},[m,b]),Y=Ot.useCallback(()=>x(false),[]),L=Ot.useCallback(z.submit.bind(z),[z]),[X,V]=Ot.useState(null),[le,ye]=Ot.useState(null),ne=Ot.useRef(null),$=Ot.useRef(null),j=Ot.useRef(false),J=Ot.useRef(null),ce=Ot.useRef(null),ge=Ot.useRef(null),Ee=Ot.useCallback((k,D=false)=>{if(ne.current=null,$.current=null,j.current=false,V(null),!k){J.current=null;return}ce.current={blob:k.blob,durationMs:k.durationMs,poster:J.current,deriveBlobPoster:D},J.current=null,x(true);},[]);Ot.useEffect(()=>{if(!b)return;if(!c?.provider){ye(null);return}let k=c.isAvailable;if(!k){ye(true);return}let D=false;return Promise.resolve().then(()=>k()).then(F=>{D||ye(F);}).catch(()=>{D||ye(false);}),()=>{D=true;}},[b,c?.provider,c?.isAvailable]);let he=pt({hasProvider:!!c?.provider,providerAvailable:le,hasGetDisplayMedia:Cn()}).canRecord,Se=Ot.useCallback(async()=>{if(j.current)return;if(ge.current=null,pt({hasProvider:!!c?.provider,providerAvailable:le,hasGetDisplayMedia:Cn()}).usingProvider&&c?.provider){j.current=true,J.current=null,x(false),$.current=Xt(c.provider,{maxDurationSeconds:Ge},{onStarting:()=>V({phase:"starting"}),onActive:F=>{V({phase:"recording",stream:F.stream??null,startedAt:Date.now(),maxSeconds:Ge}),F.stream&&ut(F.stream).then(Ye=>{J.current=Ye;}).catch(()=>{});},onProcessing:()=>V({phase:"processing"}),onResult:F=>Ee({blob:F.blob,durationMs:F.durationMs},true),onCancelled:()=>{$.current=null,j.current=false,J.current=null,V(null),I(null),_(null),x(true);},onError:F=>{$.current=null,j.current=false,J.current=null,V(null),ge.current=F.message||"Screen recording could not start.",x(true);}});return}if(ne.current)return;let D=await At(Ge);ne.current=D,j.current=true,J.current=null,V({phase:"recording",stream:D.stream,startedAt:Date.now(),maxSeconds:Ge}),x(false),ut(D.stream).then(F=>{J.current=F;}).catch(()=>{}),D.result.then(F=>Ee(F)).catch(()=>Ee(null));},[Ee,c?.provider,le]),Ce=Ot.useCallback(()=>{$.current?$.current.stop():ne.current?.stop();},[]),re=Ot.useCallback(()=>{if($.current){$.current.cancel();return}let k=ne.current;ne.current=null,j.current=false,J.current=null,V(null),k?.cancel(),I(null),_(null),x(true);},[]),Re=Ot.useCallback(()=>{let k=ce.current;return ce.current=null,k},[]),ke=Ot.useCallback(()=>{let k=ge.current;return ge.current=null,k},[]);Ot.useEffect(()=>{b||(ge.current=null);},[b]);let xe=fn(),Me=pn(i);dn(l);let Te=bn(a?"":e,t??En),Be=p??Te.shakeToOpen;wn(Be,H,b);let Pe=Ot.useMemo(()=>({client:z,user:n,isOpen:b,isSubmitting:Q,error:W,open:H,close:Y,openCapture:H,closeCapture:Y,submit:L,isNativeShell:xe,capture:m,initialCapture:A,initialCaptureError:N,isOpening:M,startVideoSession:Se,stopVideoSession:Ce,cancelVideoSession:re,recording:X,consumePendingVideo:Re,canRecordScreen:he,consumeRecordStartError:ke}),[z,n,b,Q,W,H,Y,L,xe,m,A,N,Se,Ce,re,X,Re,he,ke,M]),oe=Co({explicit:a,remote:Te.trigger,remoteLoading:Te.loading,floatingButton:o});return jsxRuntime.jsxs(tt.Provider,{value:Pe,children:[v,oe?.kind==="floating"?jsxRuntime.jsx(rn,{config:cn(oe),portalTarget:s,hidden:Me||M||X!=null,onPointerDown:B,onClick:k=>H(k)}):null,oe?.kind==="notch"?jsxRuntime.jsx(sn,{config:un(oe),portalTarget:s,hidden:Me||M||X!=null,onPointerDown:B,onClick:k=>H(k)}):null,oe?.kind==="inline"?jsxRuntime.jsx(on,{mount:oe.mount,label:oe.label??"Feedback",icon:oe.icon,onPointerDown:B,onClick:k=>H(k)}):null,X?jsxRuntime.jsx(Kt,{state:X,portalTarget:s,onStop:Ce,onCancel:re}):null,jsxRuntime.jsx(mt,{})]})}function Co(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function xo({variant:e="default",floating:t=false,className:n,children:r="Feedback",onClick:o,...a}){let{openCapture:i}=Ie(),l=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsxRuntime.jsx("button",{type:"button",className:l,"data-lumen-trigger":"",onClick:s=>{o?.(s),s.defaultPrevented||i(s.nativeEvent);},...a,children:r})}
|
|
4
|
+
exports.CaptureModal=mt;exports.FeedbackButton=xo;exports.LUMEN_SHAKE_MESSAGE=qe;exports.LumenProvider=Eo;exports.createNativeCaptureProvider=Yn;exports.isLumenEventTarget=lr;exports.useLumen=Ie;//# sourceMappingURL=index.cjs.map
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|