@lumen-stack/react 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -5
- package/dist/index.d.ts +29 -5
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ReactNode, RefObject } from 'react';
|
|
4
|
-
import { LumenUser, AmplitudeIdentity, ScreenshotCaptureOptions, LumenClient, SubmitPayload, SubmitOptions, SubmitResult } from '@lumen-stack/core';
|
|
5
|
-
export { CaptureMetadata, CaptureMethod, CapturePlatform, CaptureResult, FeedbackCategory, LumenClient, LumenError, LumenUser, ScreenshotCaptureMode, ScreenshotCaptureOptions, ScreenshotCaptureProvider, SubmitPayload, SubmitResult } from '@lumen-stack/core';
|
|
4
|
+
import { LumenUser, AmplitudeIdentity, ScreenshotCaptureOptions, LumenClient, SubmitPayload, SubmitOptions, SubmitResult, CaptureResult } from '@lumen-stack/core';
|
|
5
|
+
export { CaptureMetadata, CaptureMethod, CapturePlatform, CaptureResult, FeedbackCategory, LUMEN_SHAKE_MESSAGE, LumenClient, LumenError, LumenUser, NativeCaptureProviderOptions, NativeCaptureRequest, NativeCaptureResponse, ScreenshotCaptureMode, ScreenshotCaptureOptions, ScreenshotCaptureProvider, ShakeMessage, SubmitPayload, SubmitResult, createNativeCaptureProvider, isLumenEventTarget } from '@lumen-stack/core';
|
|
6
6
|
|
|
7
7
|
type LumenTriggerPlacement = "br" | "bl" | "tr" | "tl";
|
|
8
8
|
interface FloatingTriggerConfig {
|
|
@@ -79,6 +79,14 @@ interface LumenProviderProps {
|
|
|
79
79
|
portalTarget?: HTMLElement;
|
|
80
80
|
/** Screenshot capture behavior and optional native/custom provider. */
|
|
81
81
|
capture?: ScreenshotCaptureOptions;
|
|
82
|
+
/**
|
|
83
|
+
* Open the feedback sheet when the user shakes their device. When omitted
|
|
84
|
+
* the SDK uses the dashboard's shake setting from `/api/v1/sdk/config`;
|
|
85
|
+
* pass a boolean to force it on/off locally. Works via the native bridge
|
|
86
|
+
* (a `lumen:shake` postMessage from an Expo/WebView host) and a best-effort
|
|
87
|
+
* web DeviceMotion fallback.
|
|
88
|
+
*/
|
|
89
|
+
shakeToOpen?: boolean;
|
|
82
90
|
/**
|
|
83
91
|
* Called exactly once whenever the Lumen sheet opens (`true`) or closes
|
|
84
92
|
* (`false`). Never fires on the initial mount. Correct across all trigger
|
|
@@ -121,9 +129,19 @@ interface LumenProviderProps {
|
|
|
121
129
|
* ```
|
|
122
130
|
*/
|
|
123
131
|
onOpenChange?: (open: boolean) => void;
|
|
132
|
+
/**
|
|
133
|
+
* Called before Lumen starts its capture/open flow. Hosts can use this to
|
|
134
|
+
* suppress outside-click dismissal in their own overlay stack.
|
|
135
|
+
*/
|
|
136
|
+
beforeOpen?: (event?: Event) => void | Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Alias for hosts that want trigger-specific coordination.
|
|
139
|
+
* Runs after `beforeOpen` and before the pre-open screenshot.
|
|
140
|
+
*/
|
|
141
|
+
onTriggerActivate?: (event?: Event) => void | Promise<void>;
|
|
124
142
|
children: React.ReactNode;
|
|
125
143
|
}
|
|
126
|
-
declare function LumenProvider({ apiKey, apiUrl, user, amplitude, floatingButton, trigger, hideOn, theme, portalTarget, capture, onOpenChange, children, }: LumenProviderProps): react_jsx_runtime.JSX.Element;
|
|
144
|
+
declare function LumenProvider({ apiKey, apiUrl, user, amplitude, floatingButton, trigger, hideOn, theme, portalTarget, capture, shakeToOpen, onOpenChange, beforeOpen, onTriggerActivate, children, }: LumenProviderProps): react_jsx_runtime.JSX.Element;
|
|
127
145
|
|
|
128
146
|
interface FeedbackButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
129
147
|
variant?: "default" | "ghost" | "outline";
|
|
@@ -137,7 +155,7 @@ declare function CaptureModal(): react_jsx_runtime.JSX.Element | null;
|
|
|
137
155
|
interface LumenContextValue {
|
|
138
156
|
client: LumenClient;
|
|
139
157
|
user: LumenUser | undefined;
|
|
140
|
-
open: () => void;
|
|
158
|
+
open: (event?: Event) => void;
|
|
141
159
|
close: () => void;
|
|
142
160
|
isOpen: boolean;
|
|
143
161
|
/** Pass-through to client.submit — for headless hosts that build their own payload. */
|
|
@@ -146,7 +164,13 @@ interface LumenContextValue {
|
|
|
146
164
|
isNativeShell: boolean;
|
|
147
165
|
/** Capture options from <LumenProvider>. */
|
|
148
166
|
capture: ScreenshotCaptureOptions | undefined;
|
|
149
|
-
|
|
167
|
+
/** Screenshot captured before the wizard mounted, when available. */
|
|
168
|
+
initialCapture: CaptureResult | null;
|
|
169
|
+
/** Error from the pre-open capture; the modal falls back to manual upload. */
|
|
170
|
+
initialCaptureError: Error | null;
|
|
171
|
+
/** True while the trigger has been activated and the pre-open capture is running. */
|
|
172
|
+
isOpening: boolean;
|
|
173
|
+
openCapture: (event?: Event) => void;
|
|
150
174
|
closeCapture: () => void;
|
|
151
175
|
isSubmitting: boolean;
|
|
152
176
|
error: Error | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ReactNode, RefObject } from 'react';
|
|
4
|
-
import { LumenUser, AmplitudeIdentity, ScreenshotCaptureOptions, LumenClient, SubmitPayload, SubmitOptions, SubmitResult } from '@lumen-stack/core';
|
|
5
|
-
export { CaptureMetadata, CaptureMethod, CapturePlatform, CaptureResult, FeedbackCategory, LumenClient, LumenError, LumenUser, ScreenshotCaptureMode, ScreenshotCaptureOptions, ScreenshotCaptureProvider, SubmitPayload, SubmitResult } from '@lumen-stack/core';
|
|
4
|
+
import { LumenUser, AmplitudeIdentity, ScreenshotCaptureOptions, LumenClient, SubmitPayload, SubmitOptions, SubmitResult, CaptureResult } from '@lumen-stack/core';
|
|
5
|
+
export { CaptureMetadata, CaptureMethod, CapturePlatform, CaptureResult, FeedbackCategory, LUMEN_SHAKE_MESSAGE, LumenClient, LumenError, LumenUser, NativeCaptureProviderOptions, NativeCaptureRequest, NativeCaptureResponse, ScreenshotCaptureMode, ScreenshotCaptureOptions, ScreenshotCaptureProvider, ShakeMessage, SubmitPayload, SubmitResult, createNativeCaptureProvider, isLumenEventTarget } from '@lumen-stack/core';
|
|
6
6
|
|
|
7
7
|
type LumenTriggerPlacement = "br" | "bl" | "tr" | "tl";
|
|
8
8
|
interface FloatingTriggerConfig {
|
|
@@ -79,6 +79,14 @@ interface LumenProviderProps {
|
|
|
79
79
|
portalTarget?: HTMLElement;
|
|
80
80
|
/** Screenshot capture behavior and optional native/custom provider. */
|
|
81
81
|
capture?: ScreenshotCaptureOptions;
|
|
82
|
+
/**
|
|
83
|
+
* Open the feedback sheet when the user shakes their device. When omitted
|
|
84
|
+
* the SDK uses the dashboard's shake setting from `/api/v1/sdk/config`;
|
|
85
|
+
* pass a boolean to force it on/off locally. Works via the native bridge
|
|
86
|
+
* (a `lumen:shake` postMessage from an Expo/WebView host) and a best-effort
|
|
87
|
+
* web DeviceMotion fallback.
|
|
88
|
+
*/
|
|
89
|
+
shakeToOpen?: boolean;
|
|
82
90
|
/**
|
|
83
91
|
* Called exactly once whenever the Lumen sheet opens (`true`) or closes
|
|
84
92
|
* (`false`). Never fires on the initial mount. Correct across all trigger
|
|
@@ -121,9 +129,19 @@ interface LumenProviderProps {
|
|
|
121
129
|
* ```
|
|
122
130
|
*/
|
|
123
131
|
onOpenChange?: (open: boolean) => void;
|
|
132
|
+
/**
|
|
133
|
+
* Called before Lumen starts its capture/open flow. Hosts can use this to
|
|
134
|
+
* suppress outside-click dismissal in their own overlay stack.
|
|
135
|
+
*/
|
|
136
|
+
beforeOpen?: (event?: Event) => void | Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Alias for hosts that want trigger-specific coordination.
|
|
139
|
+
* Runs after `beforeOpen` and before the pre-open screenshot.
|
|
140
|
+
*/
|
|
141
|
+
onTriggerActivate?: (event?: Event) => void | Promise<void>;
|
|
124
142
|
children: React.ReactNode;
|
|
125
143
|
}
|
|
126
|
-
declare function LumenProvider({ apiKey, apiUrl, user, amplitude, floatingButton, trigger, hideOn, theme, portalTarget, capture, onOpenChange, children, }: LumenProviderProps): react_jsx_runtime.JSX.Element;
|
|
144
|
+
declare function LumenProvider({ apiKey, apiUrl, user, amplitude, floatingButton, trigger, hideOn, theme, portalTarget, capture, shakeToOpen, onOpenChange, beforeOpen, onTriggerActivate, children, }: LumenProviderProps): react_jsx_runtime.JSX.Element;
|
|
127
145
|
|
|
128
146
|
interface FeedbackButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
129
147
|
variant?: "default" | "ghost" | "outline";
|
|
@@ -137,7 +155,7 @@ declare function CaptureModal(): react_jsx_runtime.JSX.Element | null;
|
|
|
137
155
|
interface LumenContextValue {
|
|
138
156
|
client: LumenClient;
|
|
139
157
|
user: LumenUser | undefined;
|
|
140
|
-
open: () => void;
|
|
158
|
+
open: (event?: Event) => void;
|
|
141
159
|
close: () => void;
|
|
142
160
|
isOpen: boolean;
|
|
143
161
|
/** Pass-through to client.submit — for headless hosts that build their own payload. */
|
|
@@ -146,7 +164,13 @@ interface LumenContextValue {
|
|
|
146
164
|
isNativeShell: boolean;
|
|
147
165
|
/** Capture options from <LumenProvider>. */
|
|
148
166
|
capture: ScreenshotCaptureOptions | undefined;
|
|
149
|
-
|
|
167
|
+
/** Screenshot captured before the wizard mounted, when available. */
|
|
168
|
+
initialCapture: CaptureResult | null;
|
|
169
|
+
/** Error from the pre-open capture; the modal falls back to manual upload. */
|
|
170
|
+
initialCaptureError: Error | null;
|
|
171
|
+
/** True while the trigger has been activated and the pre-open capture is running. */
|
|
172
|
+
isOpening: boolean;
|
|
173
|
+
openCapture: (event?: Event) => void;
|
|
150
174
|
closeCapture: () => void;
|
|
151
175
|
isSubmitting: boolean;
|
|
152
176
|
error: Error | null;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import*as
|
|
3
|
-
${o.stack}`:""}`);continue}try{t.push(JSON.stringify(o,sn));}catch{t.push(String(o));}}let n=t.join(" ");return n.length>4096?n.slice(0,4096)+"\u2026[truncated]":n}function sn(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function ln(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let o=e[n]?.bind(e);o&&(e[n]=(...r)=>{try{ie(Je,{level:n,ts:Date.now(),message:an(r)});}catch{}o(...r);});}}function Qe(e){return he?e.startsWith(he):false}function un(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let o=typeof t=="string"?t:t instanceof URL?t.toString():t.url,r=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(Qe(o))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return ie(ae,{type:"fetch",method:r,url:we(o),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw ie(ae,{type:"fetch",method:r,url:we(o),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function cn(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(o,r,...a){return this.__lumen={method:String(o).toUpperCase(),url:typeof r=="string"?r:r.toString(),t:0},t.call(this,o,r,...a)},e.prototype.send=function(o){let r=this.__lumen;if(r&&!Qe(r.url)){r.t=performance.now();let a=()=>{try{ie(ae,{type:"xhr",method:r.method,url:we(r.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-r.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",a);};this.addEventListener("loadend",a);}return n.call(this,o??null)};}function we(e){return e.length>512?e.slice(0,512)+"\u2026":e}function et(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:$e(e),consoleLog:[],networkLog:[]};let t=rn();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:$e(e),device:dn(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function dn(){let e={};try{e.screen={width:window.screen?.width??0,height:window.screen?.height??0},e.pixelRatio=window.devicePixelRatio??1,e.language=navigator.language,e.languages=Array.from(navigator.languages??[]),e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.colorScheme=window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light",e.referrer=document.referrer||void 0,e.title=document.title||void 0,e.online=navigator.onLine,performance.getEntriesByType("navigation")[0]&&(e.uptimeMs=Math.round(performance.now()));}catch{}return e}function $e(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}async function tt(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new L("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new L("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 u(){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{}u();},stop(){return new Promise((s,d)=>{if(o.state==="inactive"){u(),d(new L("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let m=performance.now()-a,w=o.mimeType||n||"audio/webm",b=new Blob(r,{type:w});u(),s({blob:b,durationMs:m,mimeType:w});},{once:true}),o.stop();})}}}async function nt(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new L("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new L("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(d=>MediaRecorder.isTypeSupported(d))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),r=[],a=performance.now(),i=null;o.addEventListener("dataavailable",d=>{d.data&&d.data.size>0&&r.push(d.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);let u=t.getVideoTracks()[0];u&&u.addEventListener("ended",()=>{o.state!=="inactive"&&o.stop();});function s(){i!==null&&window.clearTimeout(i),i=null;for(let d of t.getTracks())d.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}s();},stop(){return new Promise((d,m)=>{if(o.state==="inactive"){s(),m(new L("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let w=performance.now()-a,b=o.mimeType||n||"video/webm",R=new Blob(r,{type:b});s(),d({blob:R,durationMs:w,mimeType:b});},{once:true}),o.stop();})}}}var ve=createContext(null);function Z(){let e=useContext(ve);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var it=at.forwardRef(function({screenshot:t,tool:n,color:o="rgb(239, 68, 68)",strokeWidth:r=4,onDrawingChange:a},i){let u=useRef(null),s=useRef(null),d=useRef(null),[m,w]=useState(null),[b,R]=useState([]),v=useRef(null),C=useRef(false),k=useRef(0),T=useRef(false);useEffect(()=>{let p=false,g=null;return (async()=>{try{let h=await createImageBitmap(t);if(p){h.close?.();return}g=h,w(h);}catch{}})(),()=>{p=true,g?.close?.();}},[t]),useEffect(()=>{if(!m)return;let p=u.current,g=s.current;if(!p||!g)return;p.width=m.width,p.height=m.height,g.width=m.width,g.height=m.height;let h=p.getContext("2d");h&&(h.imageSmoothingEnabled=false,h.drawImage(m,0,0));},[m]),useEffect(()=>{let p=s.current;p&&le(p,b,v.current);},[b]),useImperativeHandle(i,()=>({hasAnnotations:()=>b.length>0,reset:()=>R([]),undo:()=>R(p=>p.length===0?p:p.slice(0,-1)),async flatten(){let p=v.current,g=p?[...b,p]:b;if(g.length===0||!m)return t;let h=document.createElement("canvas");h.width=m.width,h.height=m.height;let x=h.getContext("2d");if(!x)return t;x.imageSmoothingEnabled=false,x.drawImage(m,0,0);for(let P of g)xe(x,P);return await new Promise(P=>{h.toBlob(V=>{P(V??t);},"image/jpeg",.85);})}}),[b,m,t]);function N(p){let g=s.current;if(!g)return {x:0,y:0};let h=g.getBoundingClientRect(),x=g.width/Math.max(h.width,1),P=g.height/Math.max(h.height,1);return {x:(p.clientX-h.left)*x,y:(p.clientY-h.top)*P}}function E(){T.current||(T.current=true,requestAnimationFrame(()=>{T.current=false;let p=s.current;p&&le(p,b,v.current);}));}function A(p){if(p.button!==void 0&&p.button!==0)return;try{p.currentTarget.setPointerCapture(p.pointerId);}catch{}C.current=true,a?.(true);let g=N(p);n==="arrow"?v.current={kind:"arrow",from:g,to:g,color:o,width:r}:n==="rect"?v.current={kind:"rect",from:g,to:g,color:o,width:r}:v.current={kind:"freehand",points:[g],color:o,width:r},k.current=performance.now(),E();}function D(p){if(!C.current||!v.current)return;let g=N(p),h=v.current;if(h.kind==="arrow"||h.kind==="rect")h.to=g;else {let x=h.points[h.points.length-1],P=x?(x.x-g.x)**2+(x.y-g.y)**2:1/0,V=performance.now(),O=V-k.current;(P>16||O>16)&&(h.points.push(g),k.current=V);}E();}function S(){if(!C.current)return;C.current=false,a?.(false);let p=v.current;if(v.current=null,!!p){if(p.kind==="arrow"||p.kind==="rect"){let g=p.to.x-p.from.x,h=p.to.y-p.from.y;if(g*g+h*h<16){let x=s.current;x&&le(x,b,null);return}}else if(p.points.length<2){let g=s.current;g&&le(g,b,null);return}R(g=>[...g,p].slice(-50));}}return jsxs("div",{ref:d,className:"lumen-annotate-frame",children:[jsx("canvas",{ref:u}),jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:A,onPointerMove:D,onPointerUp:S,onPointerCancel:S})]})});function le(e,t,n){let o=e.getContext("2d");if(o){o.clearRect(0,0,e.width,e.height);for(let r of t)xe(o,r);n&&xe(o,n);}}function xe(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let n=Math.min(t.from.x,t.to.x),o=Math.min(t.from.y,t.to.y),r=Math.abs(t.to.x-t.from.x),a=Math.abs(t.to.y-t.from.y);e.strokeRect(n,o,r,a);}else if(t.kind==="freehand")bn(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 bn(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],u=(a.x+i.x)/2,s=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,u,s);}let o=t[t.length-1];e.lineTo(o.x,o.y),e.stroke();}var Ee=60,wn=60,st=[{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)"}],lt=[{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"}],vn=[{value:"shot",label:"Screenshot",hint:"This page, instantly"},{value:"screen",label:"Screen",hint:"Pick a window or tab"},{value:"video",label:"Video",hint:"Record up to 60s"}];function ke(){let{client:e,isOpen:t,closeCapture:n,user:o,capture:r}=Z(),[a,i]=useState(1),[u,s]=useState(null),[d,m]=useState({kind:"idle"}),[w,b]=useState(false),[R,v]=useState(0),[C,k]=useState(null),[T,N]=useState(false),[E,A]=useState("arrow"),[D,S]=useState(st[0].value),[p,g]=useState(lt[1].value),[h,x]=useState(""),[P,V]=useState("bug"),[O,Q]=useState(o?.email??""),[H,de]=useState(null),[_,Y]=useState(null),[Ot,me]=useState(0),[j,ee]=useState(null),[$,pe]=useState(null),[Ht,Ft]=useState(false),te=useRef(null),Ae=useRef(null),Se=useRef(null),X=useRef(false);if(useEffect(()=>{if(t)return X.current=false,i(1),s(null),x(""),Y(null),me(0),pe(null),b(false),v(0),k(null),N(false),ee(l=>(l?.cancel(),null)),m(r?.mode==="manual"?{kind:"manual"}:{kind:"idle"}),()=>{X.current=true;}},[t,r]),useEffect(()=>{if(!t)return;Se.current=document.activeElement??null;let l=document.documentElement,y=l.style.overflow,I=l.style.paddingRight,F=window.innerWidth-l.clientWidth;l.style.overflow="hidden",F>0&&(l.style.paddingRight=`${F}px`);let B=false,z=()=>{if(!B){B=true,l.style.overflow=y,l.style.paddingRight=I;try{Se.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",z),()=>{window.removeEventListener("pagehide",z),z();}},[t]),useEffect(()=>{if(!t)return;function l(y){if(y.key==="Escape"){y.preventDefault(),n();return}if(y.key!=="Tab")return;let I=Ae.current;if(!I)return;let F=Tn(I);if(F.length===0)return;let B=F[0],z=F[F.length-1],be=document.activeElement;y.shiftKey&&(be===B||!I.contains(be))?(y.preventDefault(),z.focus()):!y.shiftKey&&be===z&&(y.preventDefault(),B.focus());}return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[t,n]),useEffect(()=>{if(!t||d.kind!=="manual")return;function l(y){let B=Array.from(y.clipboardData?.items??[]).find(z=>z.type.startsWith("image/"))?.getAsFile();B&&(y.preventDefault(),Ie(B));}return window.addEventListener("paste",l),()=>window.removeEventListener("paste",l)},[t,d.kind]),useEffect(()=>{if(!H)return;let l=Date.now(),y=window.setInterval(()=>{let I=Math.floor((Date.now()-l)/1e3);me(I),I>=Ee&&Oe();},250);return ()=>window.clearInterval(y)},[H]),!t)return null;async function fe(l){X.current=false,m({kind:"capturing"});try{let y=await Ke({...r,mode:l,target:r?.target??document.documentElement});return X.current?!1:(Bt(y),m({kind:"ready",capture:y}),!0)}catch(y){return X.current||m({kind:"manual",error:y instanceof Error?y.message:"Automatic screenshot capture was unavailable."}),false}}async function Pe(l){s(l),k(null),l!=="video"&&Fe(),l==="shot"?await fe(r?.mode??"auto"):l==="screen"?await fe("true-screen"):await fe(r?.mode??"auto")&&await He();}function Ie(l){if(!l.type.startsWith("image/")){toast.error("Choose a PNG, JPEG, or WebP screenshot.");return}let y=je(l,["Manual screenshot upload used."]);m({kind:"ready",capture:y});}function Bt(l){l.warnings.length!==0&&toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function De(){try{let l=await tt(Ee);de(l);}catch(l){toast.error(l instanceof Error?l.message:"Microphone unavailable");}}async function Oe(){if(H)try{let l=await H.stop();Y({blob:l.blob,durationMs:l.durationMs});}catch(l){toast.error(l instanceof Error?l.message:"Could not stop recording");}finally{de(null);}}function _t(){H?.cancel(),de(null),Y(null),me(0);}async function He(){try{let l=await nt(wn);ee(l),l.stream.getVideoTracks()[0]?.addEventListener("ended",()=>{ne();});}catch(l){toast.error(l instanceof Error?l.message:"Screen capture unavailable");}}async function ne(){if(!j)return;let l=j;ee(null);try{let y=await l.stop();pe({blob:y.blob,durationMs:y.durationMs});}catch(y){toast.error(y instanceof Error?y.message:"Could not stop recording");}}function Fe(){j?.cancel(),ee(null),pe(null);}let Vt=d.kind==="ready";async function zt(){if(a===1){if(j&&await ne(),d.kind==="ready"){let l=await te.current?.flatten();k(l??d.capture.blob),N(l!=null&&l!==d.capture.blob);}i(2);}else a===2?i(3):await Wt();}function Ut(){a>1&&i(l=>l-1);}async function Wt(){if(d.kind!=="ready")return;let l=h.trim(),{capture:y}=d;b(true),v(0);try{let I=C??y.blob,F=await e.submit({rawText:l.length>0?l:void 0,category:P,submitterEmail:O.trim()||void 0,screenshot:I,audio:_?.blob,audioDurationMs:_?.durationMs,video:$?.blob,videoDurationMs:$?.durationMs,context:et(y)},{onUploadProgress:B=>v(Math.min(.95,B))});v(1),toast.success("Feedback sent \u2014 thank you."),F.id,n();}catch(I){toast.error(I instanceof Error?I.message:"Could not submit feedback"),b(false);}}function $t(l){l.target===l.currentTarget&&!w&&n();}let oe=Math.round(R*100),ge=u==="video",qt=a===1&&!Vt||w,Kt=a<3?"Next":w?oe<95?`Uploading ${oe}%\u2026`:"Almost done\u2026":"Send feedback";return jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:$t,children:jsxs("div",{ref:Ae,className:"lumen-modal","data-lumen-drawing":Ht?"true":void 0,children:[jsx(xn,{onDismiss:n}),jsxs("header",{className:"lumen-modal-header",children:[jsxs("h2",{className:"lumen-modal-title",children:[jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsx(yn,{step:a}),jsxs("div",{className:"lumen-modal-body",children:[a===1?jsxs("div",{className:"lumen-pane",children:[jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:vn.map(l=>jsxs("button",{type:"button",className:"lumen-method-btn","aria-pressed":u===l.value,onClick:()=>Pe(l.value),disabled:d.kind==="capturing",children:[jsx("span",{className:"lumen-method-label",children:l.label}),jsx("span",{className:"lumen-method-hint",children:l.hint})]},l.value))}),d.kind==="idle"?jsxs("div",{className:"lumen-cap-empty",children:[jsx("p",{children:"Pick a capture method above \u2014 nothing is captured until you choose, so take your time positioning the screen."}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>m({kind:"manual"}),children:"Or upload a screenshot"})]}):null,d.kind==="capturing"?jsxs("p",{className:"lumen-status",children:[jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,d.kind==="manual"?jsxs("div",{className:"lumen-manual-capture",children:[jsx("p",{className:"lumen-status",children:d.error?"Automatic capture was unavailable. Upload or paste a screenshot to continue.":"Upload or paste a screenshot to continue."}),jsxs("label",{className:"lumen-manual-drop",children:[jsx("span",{children:"Choose or paste a screenshot"}),jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:l=>{let y=l.currentTarget.files?.[0];y&&Ie(y),l.currentTarget.value="";}})]})]}):null,d.kind==="ready"?jsxs(Fragment,{children:[ge?null:jsxs("div",{className:"lumen-toolbar",children:[jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsx(Ce,{label:"Arrow",active:E==="arrow",onClick:()=>A("arrow")}),jsx(Ce,{label:"Box",active:E==="rect",onClick:()=>A("rect")}),jsx(Ce,{label:"Draw",active:E==="freehand",onClick:()=>A("freehand")})]}),jsx("span",{className:"lumen-toolbar-sep"}),jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:st.map(l=>jsx("button",{type:"button",className:"lumen-swatch",style:{background:l.value},"aria-label":l.label,"aria-pressed":D===l.value,onClick:()=>S(l.value)},l.value))}),jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:lt.map(l=>jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":l.label,"aria-pressed":p===l.value,onClick:()=>g(l.value),children:jsx("span",{className:"lumen-stroke-size-dot",style:{width:l.dot,height:l.dot}})},l.value))}),jsx("span",{className:"lumen-toolbar-spacer"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>te.current?.undo(),children:"Undo"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>te.current?.reset(),children:"Clear"})]}),jsx("div",{className:"lumen-annotate",children:jsx(it,{ref:te,screenshot:d.capture.blob,tool:E,color:D,strokeWidth:p,onDrawingChange:Ft})}),jsxs("div",{className:"lumen-cap-actions",children:[jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>u&&Pe(u),children:ge?"\u21BB Re-record":"\u21BB Recapture"}),ge?j?jsxs("span",{className:"lumen-recording",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsx("span",{className:"lumen-rec-time",children:"Recording\u2026"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:ne,children:"Stop"})]}):$?jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round($.durationMs/1e3),"s recorded"]}):null:jsxs("span",{className:"lumen-cap-note",children:[ct(u)," captured \xB7 switch method above anytime"]})]})]}):null]}):null,a===2?jsxs("div",{className:"lumen-pane lumen-form",children:[jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"What happened?"}),jsx("textarea",{value:h,onChange:l=>x(l.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Add a voice note (optional)"}),jsxs("div",{className:"lumen-audio-row",children:[!H&&!_?jsx("button",{type:"button",onClick:De,className:"lumen-btn-ghost",children:"Record voice note"}):null,H?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-recording",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsx(En,{stream:H.stream}),jsxs("span",{className:"lumen-rec-time",children:[Ot,"s / ",Ee,"s"]})]}),jsx("button",{type:"button",onClick:Oe,className:"lumen-btn-ghost",children:"Stop"}),jsx("button",{type:"button",onClick:_t,className:"lumen-btn-ghost",children:"Cancel"})]}):null,_&&!H?jsxs(Fragment,{children:[jsx(kn,{blob:_.blob,durationMs:_.durationMs}),jsx("button",{type:"button",onClick:()=>Y(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]})]}),jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Category"}),jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:ut.map(l=>jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":P===l.value,onClick:()=>V(l.value),children:l.label},l.value))})]}),jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"Your email (optional)"}),jsx("input",{type:"email",value:O,onChange:l=>Q(l.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,a===3?jsxs("div",{className:"lumen-pane lumen-review",children:[jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxs("span",{className:"lumen-review-v",children:[ct(u),T?" \xB7 annotated":"",jsx("button",{type:"button",className:"lumen-edit",onClick:()=>i(1),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Category"}),jsxs("span",{className:"lumen-review-v",children:[jsx("span",{className:"lumen-chip",children:ut.find(l=>l.value===P)?.label}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>i(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Description"}),jsxs("span",{className:"lumen-review-v",children:[h.trim()?h.trim():jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>i(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Material"}),jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[_?jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(_.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>Y(null),children:"\xD7"})]}):null,$?jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round($.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Fe,children:"\xD7"})]}):null,O.trim()?jsxs("span",{className:"lumen-attach",children:["\u2709 ",O.trim()]}):null,!_&&!H?jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{i(2),De();},children:"+ Voice note"}):null,j?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-attach",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),"Recording\u2026"]}),jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:ne,children:"Stop"})]}):$?null:jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:He,children:"+ Screen recording"})]})]})]}):null]}),jsxs("footer",{className:"lumen-modal-footer",children:[w?jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":oe,children:jsx("div",{className:"lumen-progress-fill",style:{width:`${oe}%`}})}):null,jsxs("div",{className:"lumen-modal-actions",children:[jsx("button",{type:"button",onClick:a===1?n:Ut,className:"lumen-btn-ghost",disabled:w,children:a===1?"Cancel":"Back"}),jsx("button",{type:"button",onClick:zt,className:"lumen-btn-primary",disabled:qt,children:Kt})]})]})]})})}function ct(e){return e==="video"?"Screen recording":e==="screen"?"Screen capture":"Screenshot"}function yn({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,o)=>jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsx("span",{className:"lumen-step-num",children:n.n}),jsx("span",{className:"lumen-step-lbl",children:n.label}),o<t.length-1?jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function Ce({label:e,active:t,onClick:n}){return jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function xn({onDismiss:e}){let t=useRef(null),n=useRef(0),o=useRef(null);function r(u){u.currentTarget.setPointerCapture(u.pointerId),t.current=u.clientY,n.current=performance.now(),o.current=u.currentTarget.parentElement;}function a(u){if(t.current==null||!o.current)return;let s=Math.max(0,u.clientY-t.current);o.current.style.transform=`translateY(${s}px)`;}function i(u){if(t.current==null||!o.current)return;let s=Math.max(0,u.clientY-t.current),d=Math.max(1,performance.now()-n.current),m=s/d;o.current.style.transform="",o.current.style.transition="",t.current=null,(s>80||m>.6)&&e();}return jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:r,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function En({stream:e}){let t=useRef(null);return 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 u=window.AudioContext??window.webkitAudioContext;if(!u)return;let s=new u,d=s.createMediaStreamSource(e),m=s.createAnalyser();m.fftSize=1024,m.smoothingTimeConstant=.6,d.connect(m);let w=new Uint8Array(m.fftSize),b=18,R=3,v=3,C=Math.max(2,(r-R*(b-1))/b),k=Math.min(C/2,3),T=new Array(b).fill(0),N=0,E=false;function A(){if(E)return;m.getByteTimeDomainData(w);let D=Math.floor(w.length/b);i.clearRect(0,0,r,a),i.fillStyle=Rn("--lumen-danger")||"rgb(239,68,68)";for(let S=0;S<b;S++){let p=0;for(let O=0;O<D;O++){let Q=Math.abs((w[S*D+O]??128)-128);Q>p&&(p=Q);}let g=Math.min(1,p/128*1.8),h=T[S]??0;T[S]=g>h?g:h+(g-h)*.35;let x=Math.max(v,T[S]*a),P=S*(C+R),V=(a-x)/2;Cn(i,P,V,C,x,k),i.fill();}N=requestAnimationFrame(A);}return N=requestAnimationFrame(A),()=>{E=true,cancelAnimationFrame(N);try{d.disconnect();}catch{}s.close();}},[e]),jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function Cn(e,t,n,o,r,a){let i=Math.min(a,o/2,r/2);e.beginPath();let u=e;if(typeof u.roundRect=="function"){u.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 kn({blob:e,durationMs:t}){let[n,o]=useState("");return useEffect(()=>{let r=URL.createObjectURL(e);return o(r),()=>{URL.revokeObjectURL(r);}},[e]),jsxs("div",{className:"lumen-audio-preview",children:[jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function Rn(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var Ln='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Tn(e){return Array.from(e.querySelectorAll(Ln)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function dt(){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 u=document.elementsFromPoint(i,n);for(let s of u){if(r.has(s))continue;r.add(s);let d=window.getComputedStyle(s);if(d.position!=="fixed"&&d.position!=="sticky")continue;let m=s.getBoundingClientRect();m.bottom<t-8||m.bottom>t+8||m.width<e*.6||m.height>a&&(a=m.height);}}return a}function Re(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,o=window.innerHeight,r=0;for(let a of e){let i;try{i=document.querySelectorAll(a);}catch{continue}for(let u of Array.from(i)){let s=u.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 mt(e){let[t,n]=useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),o=useRef(t),r=Sn(e.avoid),a=e.placement,i=e.offset.x,u=e.offset.y;return useEffect(()=>{if(typeof window>"u")return;let s=0,d=false,m=()=>{if(s=0,d)return;let C=a[0]==="b"?"bottom":"top",k=a[1]==="r"?"right":"left",T=0,N=0;e.avoid==="auto"&&C==="bottom"?T=dt():Array.isArray(e.avoid)&&(T=Re(e.avoid,C),N=Re(e.avoid,k));let E={bottom:C==="bottom"?u+T:0,top:C==="top"?u+T:0,right:k==="right"?i+N:0,left:k==="left"?i+N:0},A=o.current;(E.bottom!==A.bottom||E.top!==A.top||E.right!==A.right||E.left!==A.left)&&(o.current=E,n(E));},w=()=>{s||(s=window.requestAnimationFrame(m));};w();let b=typeof ResizeObserver<"u"?new ResizeObserver(w):null;b?.observe(document.documentElement);let R=typeof MutationObserver<"u"?new MutationObserver(w):null;R?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",w);let v=window.visualViewport;return v?.addEventListener("resize",w),v?.addEventListener("scroll",w),()=>{d=true,s&&window.cancelAnimationFrame(s),b?.disconnect(),R?.disconnect(),window.removeEventListener("resize",w),v?.removeEventListener("resize",w),v?.removeEventListener("scroll",w);}},[a,i,u,r]),t}function Sn(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function pt(e){let[t,n]=useState(false);return 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);},u=()=>{a||(a=window.requestAnimationFrame(i));};return u(),o.addEventListener("resize",u),o.addEventListener("scroll",u),()=>{a&&window.cancelAnimationFrame(a),o.removeEventListener("resize",u),o.removeEventListener("scroll",u);}},[e]),t}function ht({config:e,portalTarget:t,hidden:n,onClick:o}){let[r,a]=useState(null),i=useRef(null),u=mt(e),s=pt(e.hideOnKeyboard);if(useEffect(()=>{typeof document>"u"||a(t??document.body);},[t]),Hn(i,!n&&!s),!r)return null;let d=e.placement,m=d[0]==="b"?"bottom":"top",w=d[1]==="r"?"right":"left",b=m==="bottom"?u.bottom:u.top,R=w==="right"?u.right:u.left,v={position:"fixed",[m]:e.safeArea?`calc(${b}px + env(safe-area-inset-${m}, 0px))`:`${b}px`,[w]:e.safeArea?`calc(${R}px + env(safe-area-inset-${w}, 0px))`:`${R}px`,zIndex:e.zIndex,opacity:n||s?0:1,pointerEvents:n||s?"none":"auto",transition:"opacity 160ms ease"};return createPortal(jsxs("button",{ref:i,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:v,"aria-label":e.label,"aria-hidden":n||s?true:void 0,tabIndex:n||s?-1:0,onClick:o,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsx("span",{children:e.label})]}),r)}function Hn(e,t){let n=useRef(false);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,u=a.top+a.height/2,s=document.elementsFromPoint(i,u),d=ft(window.getComputedStyle(r).zIndex);for(let m of s){if(m===r||r.contains(m))continue;if(ft(window.getComputedStyle(m).zIndex)>d){n.current=true,console.warn("[lumen] trigger is occluded by",m);break}}},250);return ()=>window.clearTimeout(o)},[t,e]);}function ft(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function wt({mount:e,label:t,icon:n,onClick:o}){let[r,a]=useState(null);return useEffect(()=>{if(typeof document>"u")return;let i=e instanceof HTMLElement?e:e.current??null;a(i);},[e]),r?createPortal(jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onClick:o,"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsx("span",{children:t})]}),r):null}function xt({config:e,portalTarget:t,hidden:n,onClick:o}){let[r,a]=useState(null),[i,u]=useState(false),s=useRef(null);if(useEffect(()=>{typeof document>"u"||a(t??document.body);},[t]),!r)return null;let d=`lumen-notch lumen-notch-${e.edge}${i?" lumen-notch-expanded":""}`;function m(v){s.current={x:v.clientX,y:v.clientY},u(true),v.currentTarget.setPointerCapture(v.pointerId);}function w(v){let C=s.current;if(!C)return;let k=v.clientX-C.x,T=v.clientY-C.y;(e.edge==="top"&&T>16||e.edge==="bottom"&&T<-16||e.edge==="right"&&k<-16||e.edge==="left"&&k>16)&&(s.current=null,o());}function b(){s.current=null,u(false);}function R(){s.current=null,u(false);}return createPortal(jsxs("button",{type:"button",className:d,style:{zIndex:e.zIndex,opacity:n?0:1,pointerEvents:n?"none":"auto"},"aria-label":e.label,"aria-hidden":n?true:void 0,tabIndex:n?-1:0,onClick:o,onPointerDown:m,onPointerMove:w,onPointerUp:b,onPointerCancel:R,onMouseEnter:()=>u(true),onMouseLeave:()=>u(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),r)}function Et(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function Ct(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 Gn={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function kt(e){let t=useId();useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,o=`data-lumen-theme-${Jn(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(Gn)){let u=e[i];typeof u=="string"&&u.length>0&&(r[a]=n.style.getPropertyValue(a)||null,n.style.setProperty(a,u));}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 Jn(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var Rt=Symbol.for("lumen.history.patched"),Le="lumen:locationchange";function eo(){if(typeof window>"u")return;let e=window;if(e[Rt])return;e[Rt]=true;let t=()=>window.dispatchEvent(new Event(Le)),n=history.pushState;history.pushState=function(...r){let a=n.apply(this,r);return t(),a};let o=history.replaceState;history.replaceState=function(...r){let a=o.apply(this,r);return t(),a},window.addEventListener("popstate",t);}function Lt(e){let[t,n]=useState(false);return useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;eo();let o=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return o(),window.addEventListener(Le,o),window.addEventListener("popstate",o),()=>{window.removeEventListener(Le,o),window.removeEventListener("popstate",o);}},[e]),t}var oo=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function Tt(){let[e,t]=useState(false);return 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||"";oo.some(a=>r.includes(a))&&t(true);},[]),e}var Nt="lumen.config.v1.",io=3600*1e3;function At(e,t){let[n,o]=useState(()=>({trigger:null,enabled:true,loading:true}));return useEffect(()=>{if(typeof window>"u")return;let r=uo(e);r&&o({trigger:r.trigger,enabled:Mt(r.trigger),loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),u=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(u,{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(),m=St(d.trigger);if(!m)throw new Error("Malformed config response");co(e,m),o({trigger:m,enabled:Mt(m),loading:false});}).catch(()=>{o(s=>s.loading?{trigger:null,enabled:true,loading:false}:s);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function Mt(e){return e.kind!=="headless"}var so=["br","bl","tr","tl"],lo=["top","right","bottom","left"];function St(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:so.find(r=>r===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:lo.find(r=>r===t.edge)??"top",label:n}:null}function uo(e){try{let t=window.localStorage.getItem(Nt+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>io)return null;let o=St(n.trigger);return o?{fetchedAt:n.fetchedAt,trigger:o}:null}catch{return null}}function co(e,t){try{window.localStorage.setItem(Nt+e,JSON.stringify({fetchedAt:Date.now(),trigger:t}));}catch{}}var Dt="https://shakebugs.vercel.app";function mo({apiKey:e,apiUrl:t,user:n,amplitude:o,floatingButton:r=true,trigger:a,hideOn:i,theme:u,portalTarget:s,capture:d,onOpenChange:m,children:w}){let[b,R]=useState(false),[v]=useState(false),[C]=useState(null),k=useMemo(()=>new qe({apiKey:e,apiUrl:t,user:n,amplitude:o}),[e,t,n?.id,n?.email,n?.name,o?.userId,o?.deviceId,o?.sessionId]);useEffect(()=>{Ze({ignoreUrlPrefix:(t??Dt).replace(/\/$/,"")});},[t]);let T=useRef(m);T.current=m,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 N=useRef(null);useEffect(()=>{if(N.current===b)return;let P=N.current;N.current=b,P!==null&&T.current?.(b);},[b]);let E=useCallback(()=>R(true),[]),A=useCallback(()=>R(false),[]),D=useCallback(k.submit.bind(k),[k]),S=Tt(),p=Lt(i);kt(u);let g=At(a?"":e,t??Dt),h=useMemo(()=>({client:k,user:n,isOpen:b,isSubmitting:v,error:C,open:E,close:A,openCapture:E,closeCapture:A,submit:D,isNativeShell:S,capture:d}),[k,n,b,v,C,E,A,D,S,d]),x=po({explicit:a,remote:g.trigger,remoteLoading:g.loading,floatingButton:r});return jsxs(ve.Provider,{value:h,children:[w,x?.kind==="floating"?jsx(ht,{config:Ct(x),portalTarget:s,hidden:p,onClick:E}):null,x?.kind==="notch"?jsx(xt,{config:Et(x),portalTarget:s,hidden:p,onClick:E}):null,x?.kind==="inline"?jsx(wt,{mount:x.mount,label:x.label??"Feedback",icon:x.icon,onClick:E}):null,jsx(ke,{})]})}function po(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function go({variant:e="default",floating:t=false,className:n,children:o="Feedback",onClick:r,...a}){let{openCapture:i}=Z(),u=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsx("button",{type:"button",className:u,onClick:s=>{r?.(s),s.defaultPrevented||i();},...a,children:o})}
|
|
4
|
-
export{
|
|
2
|
+
import*as pt from'react';import {createContext,useRef,useState,useEffect,useImperativeHandle,useContext,useMemo,useCallback,useId}from'react';import {toast}from'sonner';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';var x=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},je=class extends x{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},Ye=class extends x{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},fe=class extends x{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},Zt="https://shakebugs.vercel.app",Qt="/api/v1/sdk/submit",en=new Set([502,503,504]),et=class{apiKey;apiUrl;user;amplitude;constructor(e){if(!e.apiKey||!e.apiKey.startsWith("lk_pub_"))throw new x("Invalid Lumen apiKey \u2014 expected a key starting with `lk_pub_`.","INVALID_API_KEY");this.apiKey=e.apiKey,this.apiUrl=(e.apiUrl??Zt).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${Qt}`,o=this.#e(e),a=null;for(let r=0;r<3;r++){r>0&&await nn(2**r*250);try{return await this.#t(n,o,t)}catch(i){if(a=i,i instanceof je||i instanceof Ye||i instanceof x&&typeof i.status=="number"&&!en.has(i.status))throw i}}throw a instanceof Error?a: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,o=n?{...e.context,amplitude:n}:e.context;return t.append("context",JSON.stringify(o)),e.screenshot&&t.append("screenshot",e.screenshot,tn(e.screenshot)),e.audio&&t.append("audio",e.audio,"audio"),e.audioDurationMs!=null&&t.append("audioDurationMs",String(e.audioDurationMs)),e.video&&t.append("video",e.video,"video"),e.videoDurationMs!=null&&t.append("videoDurationMs",String(e.videoDurationMs)),t}#t(e,t,n){return new Promise((o,a)=>{let r=new XMLHttpRequest;r.open("POST",e,true),r.setRequestHeader("X-Lumen-Api-Key",this.apiKey),r.responseType="text";let{onUploadProgress:i,signal:l}=n;i&&r.upload.addEventListener("progress",c=>{c.lengthComputable&&c.total>0&&i(Math.min(1,c.loaded/c.total));});let s=()=>{r.abort(),a(new fe("Submit aborted."));};if(l){if(l.aborted){a(new fe("Submit aborted."));return}l.addEventListener("abort",s,{once:true});}r.addEventListener("load",()=>{if(l&&l.removeEventListener("abort",s),r.status===403){a(new je);return}if(r.status===429){let c=Number(r.getResponseHeader("Retry-After"))||60;a(new Ye(c));return}if(r.status<200||r.status>=300){a(new x(on(r.responseText)??`HTTP ${r.status}`,"HTTP_ERROR",r.status));return}try{let c=JSON.parse(r.responseText);o(c);}catch{a(new x("Malformed response from server.","BAD_RESPONSE"));}}),r.addEventListener("error",()=>{l&&l.removeEventListener("abort",s),a(new fe("Network error during submit."));}),r.send(t);})}};function tn(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function nn(e){return new Promise(t=>setTimeout(t,e))}function on(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var rn=2,se=8*1024*1024;async function be(e={}){rt();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return sn(await e.provider(),e)}catch(n){if(t==="custom")throw n;e.onWarning?.(["Custom capture provider failed; falling back to browser DOM capture."]);}if(t==="manual")throw new x("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return Xe(e);if(t==="dom")return Ge(e);if(t==="custom")throw new x("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await Ge(e)}catch(n){if(ot()){let o=await Xe(e);return o.warnings=le(["DOM screenshot failed; used browser screen permission fallback.",...o.warnings]),e.onWarning?.(o.warnings),o}throw n}}function tt(e,t=[]){rt();let n=we();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:le(t)}}async function Ge(e){let t=await an(),n=e.target??document.documentElement,o=we(),a=Math.max(1,Math.min(window.devicePixelRatio??1,e.maxScale??rn)),r=ln(n),i=await t(n,{backgroundColor:null,logging:false,useCORS:true,allowTaint:false,width:o.width,height:o.height,windowWidth:o.width,windowHeight:o.height,scrollX:window.scrollX,scrollY:window.scrollY,x:window.scrollX,y:window.scrollY,scale:a,ignoreElements:s=>s instanceof HTMLElement&&(s.dataset.lumenCaptureIgnore==="true"||!!s.closest("[data-lumen-capture-ignore='true']"))}),l={blob:await nt(i,r),method:"web-dom",platform:"web",viewport:o,pixelRatio:a,warnings:le(r)};return l.warnings.length>0&&e.onWarning?.(l.warnings),l}async function an(){let{default:e}=await import('html2canvas-pro');return e}async function Xe(e){if(!ot())throw new x("Browser screen capture is unavailable in this environment.","DISPLAY_MEDIA_UNAVAILABLE");let t=await navigator.mediaDevices.getDisplayMedia({video:true,audio:false});try{let n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.srcObject=t,await un(n);let o=document.createElement("canvas");o.width=n.videoWidth,o.height=n.videoHeight;let a=o.getContext("2d");if(!a)throw new x("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");a.drawImage(n,0,0,o.width,o.height);let r=we(),i=["Browser screen capture uses the window or tab selected by the user."],l={blob:await nt(o,i),method:"web-display-media",platform:"web",viewport:r,pixelRatio:r.width>0?o.width/r.width:void 0,warnings:le(i)};return e.onWarning?.(l.warnings),l}finally{for(let n of t.getTracks())n.stop();}}function sn(e,t){let n=we(),o={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:le(e.warnings??[])};return o.warnings.length>0&&t.onWarning?.(o.warnings),o}function ln(e){let t=new Set;e.querySelector("iframe")&&t.add("Embedded iframes may be blank or incomplete in DOM capture."),e.querySelector("video")&&t.add("Video frames may be blank or stale in DOM capture."),e.querySelector("canvas")&&t.add("Canvas/WebGL content may be blank if it is cross-origin tainted."),document.fonts&&document.fonts.status!=="loaded"&&t.add("Web fonts were still loading when the screenshot was captured.");let n=0;for(let o of Array.from(e.querySelectorAll("img"))){let a=o.currentSrc||o.src;if(a)try{new URL(a,window.location.href).origin!==window.location.origin&&!o.crossOrigin&&(n+=1);}catch{}}return n>0&&t.add(`${n} cross-origin image${n===1?"":"s"} without CORS may be omitted from the screenshot.`),Array.from(t)}async function nt(e,t){let n=await Je(e,"image/png",.92);if(n.size<=se)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let o=e,a=0;for(;n.size>se&&a<6;){let r=Math.max(.35,Math.min(.95,Math.sqrt(se/n.size)*.9)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(o.width*r)),i.height=Math.max(1,Math.round(o.height*r));let l=i.getContext("2d");if(!l)return n;l.drawImage(o,0,0,i.width,i.height),o=i;for(let s of [.86,.74,.62,.5])if(n=await Je(o,"image/jpeg",s),n.size<=se)return n;if(a+=1,i.width<480||i.height<320)break}return n.size>se&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function Je(e,t,n){return new Promise((o,a)=>{e.toBlob(r=>{if(!r){a(new x("Could not encode screenshot.","ENCODE_FAILED"));return}o(r);},t,n);})}function we(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function ot(){return !!navigator.mediaDevices?.getDisplayMedia}async function un(e){await new Promise((o,a)=>{let r=()=>o(),i=()=>a(new x("Could not read screen capture video.","VIDEO_FAILED"));e.addEventListener("loadedmetadata",r,{once:true}),e.addEventListener("error",i,{once:true}),e.play().catch(i);});let t=performance.now(),n=1500;for(;e.videoWidth===0||e.videoHeight===0;){if(performance.now()-t>n)throw new x("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(o=>requestAnimationFrame(()=>o()));}}function rt(){if(typeof window>"u"||typeof document>"u")throw new x("Screenshot capture can only run in the browser.","INVALID_ENV")}function le(e){return Array.from(new Set(e.filter(Boolean)))}var at=[],ge=[],Ze=false,Le=null;function it(e={}){Ze||typeof window>"u"||(Ze=true,Le=e.ignoreUrlPrefix??null,pn(),fn(),gn());}function cn(){return {consoleLog:at.slice(),networkLog:ge.slice()}}function he(e,t){e.push(t),e.length>200&&e.splice(0,e.length-200);}function dn(e){let t=[];for(let o of e){if(typeof o=="string"){t.push(o);continue}if(o instanceof Error){t.push(`${o.name}: ${o.message}${o.stack?`
|
|
3
|
+
${o.stack}`:""}`);continue}try{t.push(JSON.stringify(o,mn));}catch{t.push(String(o));}}let n=t.join(" ");return n.length>4096?n.slice(0,4096)+"\u2026[truncated]":n}function mn(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function pn(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let o=e[n]?.bind(e);o&&(e[n]=(...a)=>{try{he(at,{level:n,ts:Date.now(),message:dn(a)});}catch{}o(...a);});}}function st(e){return Le?e.startsWith(Le):false}function fn(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let o=typeof t=="string"?t:t instanceof URL?t.toString():t.url,a=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(st(o))return e.call(window,t,n);let r=performance.now();try{let i=await e.call(window,t,n);return he(ge,{type:"fetch",method:a,url:Ne(o),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-r),ts:Date.now()}),i}catch(i){throw he(ge,{type:"fetch",method:a,url:Ne(o),status:0,ok:false,durationMs:Math.round(performance.now()-r),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function gn(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(o,a,...r){return this.__lumen={method:String(o).toUpperCase(),url:typeof a=="string"?a:a.toString(),t:0},t.call(this,o,a,...r)},e.prototype.send=function(o){let a=this.__lumen;if(a&&!st(a.url)){a.t=performance.now();let r=()=>{try{he(ge,{type:"xhr",method:a.method,url:Ne(a.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-a.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",r);};this.addEventListener("loadend",r);}return n.call(this,o??null)};}function Ne(e){return e.length>512?e.slice(0,512)+"\u2026":e}function lt(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:Qe(e),consoleLog:[],networkLog:[]};let t=cn();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:Qe(e),device:hn(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function hn(){let e={};try{e.screen={width:window.screen?.width??0,height:window.screen?.height??0},e.pixelRatio=window.devicePixelRatio??1,e.language=navigator.language,e.languages=Array.from(navigator.languages??[]),e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.colorScheme=window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light",e.referrer=document.referrer||void 0,e.title=document.title||void 0,e.online=navigator.onLine,performance.getEntriesByType("navigation")[0]&&(e.uptimeMs=Math.round(performance.now()));}catch{}return e}function Qe(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var ve="lumen:shake",bn=8e3,wn=50,vn='[data-lumen-root], [data-lumen-capture-ignore="true"]';function yn(e={}){return async function(){if(typeof window>"u")throw new x("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=Cn(),n=e.send??En,o=e.timeoutMs??bn,a=e.captureSettleMs??wn,r=Ln(),i=kn(e.concealSelector===void 0?vn:e.concealSelector);try{await Mn(a);let l=await new Promise((m,p)=>{let g=window.setTimeout(()=>{t.pending.delete(r),p(new x("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},o);t.pending.set(r,{resolve:E=>{window.clearTimeout(g),m(E);},reject:E=>{window.clearTimeout(g),p(E);}});try{n({type:"lumen:capture-request",id:r,afterScreenUpdates:!0});}catch{t.pending.delete(r),window.clearTimeout(g),p(new x("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new x(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let s=Nn(l.dataUrl),c=e.platform??Tn();return {blob:s,method:c==="android"?"android-native":"ios-native",platform:c,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:l.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{i();}}}function En(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new x("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function Cn(){if(window.__lumenNativeCapture)return window.__lumenNativeCapture;let e={pending:new Map,resolve(n,o,a){let r=e.pending.get(n);r&&(e.pending.delete(n),r.resolve({type:"lumen:capture-response",id:n,dataUrl:o,pixelRatio:a}));},reject(n,o){let a=e.pending.get(n);a&&(e.pending.delete(n),a.resolve({type:"lumen:capture-response",id:n,error:o}));}},t=n=>{let o=xn(n.data);if(!o||o.type!=="lumen:capture-response")return;let a=e.pending.get(o.id);a&&(e.pending.delete(o.id),a.resolve(o));};return window.addEventListener("message",t),document.addEventListener("message",t),window.__lumenNativeCapture=e,e}function xn(e){if(e&&typeof e=="object"&&"type"in e)return e;if(typeof e=="string")try{let t=JSON.parse(e);if(t&&typeof t=="object"&&t.type)return t}catch{}return null}function kn(e){if(!e||typeof document>"u")return ()=>{};let t=[];for(let n of Array.from(document.querySelectorAll(e)))t.push({el:n,prev:n.style.visibility}),n.style.visibility="hidden";return ()=>{for(let{el:n,prev:o}of t)n.style.visibility=o;}}async function Mn(e){await Rn(),e>0&&await new Promise(t=>window.setTimeout(t,e));}function Rn(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function Tn(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function Ln(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Nn(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new x("Native host returned an invalid image data URL.","NATIVE_CAPTURE_FAILED");let n=t[1]||"image/png",o=!!t[2],a=t[3]??"";if(!o)return new Blob([decodeURIComponent(a)],{type:n});let r=atob(a),i=new Uint8Array(r.length);for(let l=0;l<r.length;l++)i[l]=r.charCodeAt(l);return new Blob([i],{type:n})}var An="[data-lumen-root]",Sn="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function Pn(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(Ae(n))return true;return Ae(e.target)}function Ae(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(Sn)?true:!!e.closest(An):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?Ae(e.host):false:false}async function ut(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new x("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new x("Microphone access denied or unavailable.","MIC_DENIED")}let n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(s=>MediaRecorder.isTypeSupported(s))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),a=[],r=performance.now(),i=null;o.addEventListener("dataavailable",s=>{s.data&&s.data.size>0&&a.push(s.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);function l(){i!==null&&window.clearTimeout(i),i=null;for(let s of t.getTracks())s.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}l();},stop(){return new Promise((s,c)=>{if(o.state==="inactive"){l(),c(new x("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let m=performance.now()-r,p=o.mimeType||n||"audio/webm",g=new Blob(a,{type:p});l(),s({blob:g,durationMs:m,mimeType:p});},{once:true}),o.stop();})}}}async function ct(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new x("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new x("Screen capture was denied or cancelled.","SCREEN_DENIED")}let n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(c=>MediaRecorder.isTypeSupported(c))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),a=[],r=performance.now(),i=null;o.addEventListener("dataavailable",c=>{c.data&&c.data.size>0&&a.push(c.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);let l=t.getVideoTracks()[0];l&&l.addEventListener("ended",()=>{o.state!=="inactive"&&o.stop();});function s(){i!==null&&window.clearTimeout(i),i=null;for(let c of t.getTracks())c.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}s();},stop(){return new Promise((c,m)=>{if(o.state==="inactive"){s(),m(new x("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let p=performance.now()-r,g=o.mimeType||n||"video/webm",E=new Blob(a,{type:g});s(),c({blob:E,durationMs:p,mimeType:g});},{once:true}),o.stop();})}}}var Se=createContext(null);function ue(){let e=useContext(Se);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var ft=pt.forwardRef(function({screenshot:t,tool:n,color:o="rgb(239, 68, 68)",strokeWidth:a=4,onDrawingChange:r},i){let l=useRef(null),s=useRef(null),c=useRef(null),[m,p]=useState(null),[g,E]=useState([]),C=useRef(null),w=useRef(false),k=useRef(0),M=useRef(false);useEffect(()=>{let f=false,b=null;return (async()=>{try{let v=await createImageBitmap(t);if(f){v.close?.();return}b=v,p(v);}catch{}})(),()=>{f=true,b?.close?.();}},[t]),useEffect(()=>{if(!m)return;let f=l.current,b=s.current;if(!f||!b)return;f.width=m.width,f.height=m.height,b.width=m.width,b.height=m.height;let v=f.getContext("2d");v&&(v.imageSmoothingEnabled=false,v.drawImage(m,0,0));},[m]),useEffect(()=>{let f=s.current;f&&ye(f,g,C.current);},[g]),useImperativeHandle(i,()=>({hasAnnotations:()=>g.length>0,reset:()=>E([]),undo:()=>E(f=>f.length===0?f:f.slice(0,-1)),async flatten(){let f=C.current,b=f?[...g,f]:g;if(b.length===0||!m)return t;let v=document.createElement("canvas");v.width=m.width,v.height=m.height;let R=v.getContext("2d");if(!R)return t;R.imageSmoothingEnabled=false,R.drawImage(m,0,0);for(let S of b)De(R,S);return await new Promise(S=>{v.toBlob(D=>{S(D??t);},"image/jpeg",.85);})}}),[g,m,t]);function T(f){let b=s.current;if(!b)return {x:0,y:0};let v=b.getBoundingClientRect(),R=b.width/Math.max(v.width,1),S=b.height/Math.max(v.height,1);return {x:(f.clientX-v.left)*R,y:(f.clientY-v.top)*S}}function N(){M.current||(M.current=true,requestAnimationFrame(()=>{M.current=false;let f=s.current;f&&ye(f,g,C.current);}));}function P(f){if(f.button!==void 0&&f.button!==0)return;try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}w.current=true,r?.(true);let b=T(f);n==="arrow"?C.current={kind:"arrow",from:b,to:b,color:o,width:a}:n==="rect"?C.current={kind:"rect",from:b,to:b,color:o,width:a}:C.current={kind:"freehand",points:[b],color:o,width:a},k.current=performance.now(),N();}function F(f){if(!w.current||!C.current)return;let b=T(f),v=C.current;if(v.kind==="arrow"||v.kind==="rect")v.to=b;else {let R=v.points[v.points.length-1],S=R?(R.x-b.x)**2+(R.y-b.y)**2:1/0,D=performance.now(),U=D-k.current;(S>16||U>16)&&(v.points.push(b),k.current=D);}N();}function A(){if(!w.current)return;w.current=false,r?.(false);let f=C.current;if(C.current=null,!!f){if(f.kind==="arrow"||f.kind==="rect"){let b=f.to.x-f.from.x,v=f.to.y-f.from.y;if(b*b+v*v<16){let R=s.current;R&&ye(R,g,null);return}}else if(f.points.length<2){let b=s.current;b&&ye(b,g,null);return}E(b=>[...b,f].slice(-50));}}return jsxs("div",{ref:c,className:"lumen-annotate-frame",children:[jsx("canvas",{ref:l}),jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:P,onPointerMove:F,onPointerUp:A,onPointerCancel:A})]})});function ye(e,t,n){let o=e.getContext("2d");if(o){o.clearRect(0,0,e.width,e.height);for(let a of t)De(o,a);n&&De(o,n);}}function De(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let n=Math.min(t.from.x,t.to.x),o=Math.min(t.from.y,t.to.y),a=Math.abs(t.to.x-t.from.x),r=Math.abs(t.to.y-t.from.y);e.strokeRect(n,o,a,r);}else if(t.kind==="freehand")_n(e,t.points);else {let{from:n,to:o,width:a}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(o.x,o.y),e.stroke();let r=Math.atan2(o.y-n.y,o.x-n.x),i=Math.max(12,a*4);e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x-i*Math.cos(r-Math.PI/7),o.y-i*Math.sin(r-Math.PI/7)),e.lineTo(o.x-i*Math.cos(r+Math.PI/7),o.y-i*Math.sin(r+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function _n(e,t){if(t.length===0)return;e.beginPath();let n=t[0];if(!n)return;if(e.moveTo(n.x,n.y),t.length===1){e.arc(n.x,n.y,e.lineWidth/2,0,Math.PI*2),e.fill();return}if(t.length===2){let a=t[1];e.lineTo(a.x,a.y),e.stroke();return}for(let a=1;a<t.length-1;a++){let r=t[a],i=t[a+1],l=(r.x+i.x)/2,s=(r.y+i.y)/2;e.quadraticCurveTo(r.x,r.y,l,s);}let o=t[t.length-1];e.lineTo(o.x,o.y),e.stroke();}var Ie=60,Un=60,gt=[{label:"Red",value:"rgb(239, 68, 68)"},{label:"Amber",value:"rgb(245, 158, 11)"},{label:"Blue",value:"rgb(59, 130, 246)"},{label:"Green",value:"rgb(34, 197, 94)"},{label:"Neutral",value:"rgb(244, 244, 245)"}],ht=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],bt=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],Vn=[{value:"shot",label:"Screenshot",hint:"This page, instantly"},{value:"screen",label:"Screen",hint:"Pick a window or tab"},{value:"video",label:"Video",hint:"Record up to 60s"}];function He(){let{client:e,isOpen:t,closeCapture:n,user:o,capture:a,initialCapture:r,initialCaptureError:i}=ue(),[l,s]=useState(1),[c,m]=useState(null),[p,g]=useState({kind:"idle"}),[E,C]=useState(false),[w,k]=useState(0),[M,T]=useState(null),[N,P]=useState(false),[F,A]=useState("arrow"),[f,b]=useState(gt[0].value),[v,R]=useState(ht[1].value),[S,D]=useState(""),[U,K]=useState("bug"),[j,ae]=useState(o?.email??""),[I,B]=useState(null),[_,Y]=useState(null),[ce,ne]=useState(0),[z,oe]=useState(null),[$,V]=useState(null),[O,Z]=useState(false),de=useRef(null),Ve=useRef(null),Be=useRef(null),ie=useRef(false);if(useEffect(()=>{if(t)return ie.current=false,s(1),m(null),D(""),Y(null),ne(0),V(null),C(false),k(0),T(null),P(false),oe(u=>(u?.cancel(),null)),r?(m("shot"),g({kind:"ready",capture:r})):a?.mode==="manual"?g({kind:"manual"}):g({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."}),()=>{ie.current=true;}},[t,a,r,i]),useEffect(()=>{if(!t)return;Be.current=document.activeElement??null;let u=document.documentElement,y=u.style.overflow,H=u.style.paddingRight,W=window.innerWidth-u.clientWidth;u.style.overflow="hidden",W>0&&(u.style.paddingRight=`${W}px`);let q=false,G=()=>{if(!q){q=true,u.style.overflow=y,u.style.paddingRight=H;try{Be.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",G),()=>{window.removeEventListener("pagehide",G),G();}},[t]),useEffect(()=>{if(!t)return;function u(y){if(y.key==="Escape"){y.preventDefault(),n();return}if(y.key!=="Tab")return;let H=Ve.current;if(!H)return;let W=Yn(H);if(W.length===0)return;let q=W[0],G=W[W.length-1],Te=document.activeElement;y.shiftKey&&(Te===q||!H.contains(Te))?(y.preventDefault(),G.focus()):!y.shiftKey&&Te===G&&(y.preventDefault(),q.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),useEffect(()=>{if(!t||p.kind!=="manual")return;function u(y){let q=Array.from(y.clipboardData?.items??[]).find(G=>G.type.startsWith("image/"))?.getAsFile();q&&(y.preventDefault(),We(q));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,p.kind]),useEffect(()=>{if(!I)return;let u=Date.now(),y=window.setInterval(()=>{let H=Math.floor((Date.now()-u)/1e3);ne(H),H>=Ie&&Me();},250);return ()=>window.clearInterval(y)},[I]),!t)return null;async function ke(u){ie.current=false,g({kind:"capturing"});try{let y=await be({...a,mode:u,target:a?.target??document.documentElement});return ie.current?!1:(Wt(y),g({kind:"ready",capture:y}),!0)}catch(y){return ie.current||g({kind:"manual",error:y instanceof Error?y.message:"Automatic screenshot capture was unavailable."}),false}}async function ze(u){m(u),T(null),u!=="video"&&Ke(),u==="shot"?await ke(a?.mode??"auto"):u==="screen"?await ke("true-screen"):await ke(a?.mode??"auto")&&await $e();}function We(u){if(!u.type.startsWith("image/")){toast.error("Choose a PNG, JPEG, or WebP screenshot.");return}let y=tt(u,["Manual screenshot upload used."]);g({kind:"ready",capture:y});}function Wt(u){u.warnings.length!==0&&toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function qe(){try{let u=await ut(Ie);B(u);}catch(u){toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Me(){if(I)try{let u=await I.stop();Y({blob:u.blob,durationMs:u.durationMs});}catch(u){toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{B(null);}}function qt(){I?.cancel(),B(null),Y(null),ne(0);}async function $e(){try{let u=await ct(Un);oe(u),u.stream.getVideoTracks()[0]?.addEventListener("ended",()=>{me();});}catch(u){toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}async function me(){if(!z)return;let u=z;oe(null);try{let y=await u.stop();V({blob:y.blob,durationMs:y.durationMs});}catch(y){toast.error(y instanceof Error?y.message:"Could not stop recording");}}function Ke(){z?.cancel(),oe(null),V(null);}let $t=p.kind==="ready";async function Kt(){if(I&&await Me(),l===1){if(z&&await me(),p.kind==="ready"){let u=await de.current?.flatten();T(u??p.capture.blob),P(u!=null&&u!==p.capture.blob);}s(2);}else l===2?s(3):await Yt();}function jt(){l>1&&s(u=>u-1);}async function Yt(){if(p.kind!=="ready")return;let u=S.trim(),{capture:y}=p;C(true),k(0);try{let H=M??y.blob,W=await e.submit({rawText:u.length>0?u:void 0,category:U,submitterEmail:j.trim()||void 0,screenshot:H,audio:_?.blob,audioDurationMs:_?.durationMs,video:$?.blob,videoDurationMs:$?.durationMs,context:lt(y)},{onUploadProgress:q=>k(Math.min(.95,q))});k(1),toast.success("Feedback sent \u2014 thank you."),W.id,n();}catch(H){toast.error(H instanceof Error?H.message:"Could not submit feedback"),C(false);}}function Gt(u){u.target===u.currentTarget&&!E&&n();}let pe=Math.round(w*100),Re=c==="video",Xt=l===1&&!$t||E,Jt=l<3?"Next":E?pe<95?`Uploading ${pe}%\u2026`:"Almost done\u2026":"Send feedback";return jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:Gt,children:jsxs("div",{ref:Ve,className:"lumen-modal","data-lumen-drawing":O?"true":void 0,children:[jsx(zn,{onDismiss:n}),jsxs("header",{className:"lumen-modal-header",children:[jsxs("h2",{className:"lumen-modal-title",children:[jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsx(Bn,{step:l}),jsxs("div",{className:"lumen-modal-body",children:[l===1?jsxs("div",{className:"lumen-pane",children:[jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:Vn.map(u=>jsxs("button",{type:"button",className:"lumen-method-btn","aria-pressed":c===u.value,onClick:()=>ze(u.value),disabled:p.kind==="capturing",children:[jsx("span",{className:"lumen-method-label",children:u.label}),jsx("span",{className:"lumen-method-hint",children:u.hint})]},u.value))}),p.kind==="idle"?jsxs("div",{className:"lumen-cap-empty",children:[jsx("p",{children:"Pick a capture method above, or upload a screenshot."}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>g({kind:"manual"}),children:"Or upload a screenshot"})]}):null,p.kind==="capturing"?jsxs("p",{className:"lumen-status",children:[jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,p.kind==="manual"?jsxs("div",{className:"lumen-manual-capture",children:[jsx("p",{className:"lumen-status",children:p.error?"Automatic capture was unavailable. Upload or paste a screenshot to continue.":"Upload or paste a screenshot to continue."}),jsxs("label",{className:"lumen-manual-drop",children:[jsx("span",{children:"Choose or paste a screenshot"}),jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:u=>{let y=u.currentTarget.files?.[0];y&&We(y),u.currentTarget.value="";}})]})]}):null,p.kind==="ready"?jsxs(Fragment,{children:[Re?null:jsxs("div",{className:"lumen-toolbar",children:[jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsx(Oe,{label:"Arrow",active:F==="arrow",onClick:()=>A("arrow")}),jsx(Oe,{label:"Box",active:F==="rect",onClick:()=>A("rect")}),jsx(Oe,{label:"Draw",active:F==="freehand",onClick:()=>A("freehand")})]}),jsx("span",{className:"lumen-toolbar-sep"}),jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:gt.map(u=>jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":f===u.value,onClick:()=>b(u.value)},u.value))}),jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:ht.map(u=>jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":v===u.value,onClick:()=>R(u.value),children:jsx("span",{className:"lumen-stroke-size-dot",style:{width:u.dot,height:u.dot}})},u.value))}),jsx("span",{className:"lumen-toolbar-spacer"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>de.current?.undo(),children:"Undo"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>de.current?.reset(),children:"Clear"})]}),jsx("div",{className:"lumen-annotate",children:jsx(ft,{ref:de,screenshot:p.capture.blob,tool:F,color:f,strokeWidth:v,onDrawingChange:Z})}),jsxs("div",{className:"lumen-cap-actions",children:[jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>c&&ze(c),children:Re?"\u21BB Re-record":"\u21BB Recapture"}),Re?z?jsxs("span",{className:"lumen-recording",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsx("span",{className:"lumen-rec-time",children:"Recording\u2026"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:me,children:"Stop"})]}):$?jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round($.durationMs/1e3),"s recorded"]}):null:jsxs("span",{className:"lumen-cap-note",children:[wt(c)," captured \xB7 switch method above anytime"]})]})]}):null]}):null,l===2?jsxs("div",{className:"lumen-pane lumen-form",children:[jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"What happened?"}),jsx("textarea",{value:S,onChange:u=>D(u.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Add a voice note (optional)"}),jsxs("div",{className:"lumen-audio-row",children:[!I&&!_?jsx("button",{type:"button",onClick:qe,className:"lumen-btn-ghost",children:"Record voice note"}):null,I?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-recording",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsx(Wn,{stream:I.stream}),jsxs("span",{className:"lumen-rec-time",children:[ce,"s / ",Ie,"s"]})]}),jsx("button",{type:"button",onClick:Me,className:"lumen-btn-ghost",children:"Stop"}),jsx("button",{type:"button",onClick:qt,className:"lumen-btn-ghost",children:"Cancel"})]}):null,_&&!I?jsxs(Fragment,{children:[jsx($n,{blob:_.blob,durationMs:_.durationMs}),jsx("button",{type:"button",onClick:()=>Y(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]})]}),jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Category"}),jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:bt.map(u=>jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":U===u.value,onClick:()=>K(u.value),children:u.label},u.value))})]}),jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"Your email (optional)"}),jsx("input",{type:"email",value:j,onChange:u=>ae(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,l===3?jsxs("div",{className:"lumen-pane lumen-review",children:[jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxs("span",{className:"lumen-review-v",children:[wt(c),N?" \xB7 annotated":"",jsx("button",{type:"button",className:"lumen-edit",onClick:()=>s(1),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Category"}),jsxs("span",{className:"lumen-review-v",children:[jsx("span",{className:"lumen-chip",children:bt.find(u=>u.value===U)?.label}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>s(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Description"}),jsxs("span",{className:"lumen-review-v",children:[S.trim()?S.trim():jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>s(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Material"}),jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[_?jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(_.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>Y(null),children:"\xD7"})]}):null,$?jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round($.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Ke,children:"\xD7"})]}):null,j.trim()?jsxs("span",{className:"lumen-attach",children:["\u2709 ",j.trim()]}):null,!_&&!I?jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{s(2),qe();},children:"+ Voice note"}):null,z?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-attach",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),"Recording\u2026"]}),jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:me,children:"Stop"})]}):$?null:jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:$e,children:"+ Screen recording"})]})]})]}):null]}),jsxs("footer",{className:"lumen-modal-footer",children:[E?jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":pe,children:jsx("div",{className:"lumen-progress-fill",style:{width:`${pe}%`}})}):null,jsxs("div",{className:"lumen-modal-actions",children:[jsx("button",{type:"button",onClick:l===1?n:jt,className:"lumen-btn-ghost",disabled:E,children:l===1?"Cancel":"Back"}),jsx("button",{type:"button",onClick:Kt,className:"lumen-btn-primary",disabled:Xt,children:Jt})]})]})]})})}function wt(e){return e==="video"?"Screen recording":e==="screen"?"Screen capture":"Screenshot"}function Bn({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,o)=>jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsx("span",{className:"lumen-step-num",children:n.n}),jsx("span",{className:"lumen-step-lbl",children:n.label}),o<t.length-1?jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function Oe({label:e,active:t,onClick:n}){return jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function zn({onDismiss:e}){let t=useRef(null),n=useRef(0),o=useRef(null);function a(l){l.currentTarget.setPointerCapture(l.pointerId),t.current=l.clientY,n.current=performance.now(),o.current=l.currentTarget.parentElement;}function r(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current);o.current.style.transform=`translateY(${s}px)`;}function i(l){if(t.current==null||!o.current)return;let s=Math.max(0,l.clientY-t.current),c=Math.max(1,performance.now()-n.current),m=s/c;o.current.style.transform="",o.current.style.transition="",t.current=null,(s>80||m>.6)&&e();}return jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:a,onPointerMove:r,onPointerUp:i,onPointerCancel:i})}function Wn({stream:e}){let t=useRef(null);return useEffect(()=>{let n=t.current;if(!n)return;let o=Math.min(window.devicePixelRatio||1,2),a=n.clientWidth||88,r=n.clientHeight||22;n.width=Math.round(a*o),n.height=Math.round(r*o);let i=n.getContext("2d");if(!i)return;i.scale(o,o);let l=window.AudioContext??window.webkitAudioContext;if(!l)return;let s=new l,c=s.createMediaStreamSource(e),m=s.createAnalyser();m.fftSize=1024,m.smoothingTimeConstant=.6,c.connect(m);let p=new Uint8Array(m.fftSize),g=18,E=3,C=3,w=Math.max(2,(a-E*(g-1))/g),k=Math.min(w/2,3),M=new Array(g).fill(0),T=0,N=false;function P(){if(N)return;m.getByteTimeDomainData(p);let F=Math.floor(p.length/g);i.clearRect(0,0,a,r),i.fillStyle=Kn("--lumen-danger")||"rgb(239,68,68)";for(let A=0;A<g;A++){let f=0;for(let U=0;U<F;U++){let K=Math.abs((p[A*F+U]??128)-128);K>f&&(f=K);}let b=Math.min(1,f/128*1.8),v=M[A]??0;M[A]=b>v?b:v+(b-v)*.35;let R=Math.max(C,M[A]*r),S=A*(w+E),D=(r-R)/2;qn(i,S,D,w,R,k),i.fill();}T=requestAnimationFrame(P);}return T=requestAnimationFrame(P),()=>{N=true,cancelAnimationFrame(T);try{c.disconnect();}catch{}s.close();}},[e]),jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function qn(e,t,n,o,a,r){let i=Math.min(r,o/2,a/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,o,a,i);return}e.moveTo(t+i,n),e.arcTo(t+o,n,t+o,n+a,i),e.arcTo(t+o,n+a,t,n+a,i),e.arcTo(t,n+a,t,n,i),e.arcTo(t,n,t+o,n,i),e.closePath();}function $n({blob:e,durationMs:t}){let[n,o]=useState("");return useEffect(()=>{let a=URL.createObjectURL(e);return o(a),()=>{URL.revokeObjectURL(a);}},[e]),jsxs("div",{className:"lumen-audio-preview",children:[jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function Kn(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var jn='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Yn(e){return Array.from(e.querySelectorAll(jn)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function vt(){if(typeof document>"u"||typeof window>"u")return 0;let e=window.innerWidth,t=window.innerHeight;if(e===0||t===0)return 0;let n=t-4,o=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],a=new Set,r=0;for(let i of o){let l=document.elementsFromPoint(i,n);for(let s of l){if(a.has(s))continue;a.add(s);let c=window.getComputedStyle(s);if(c.position!=="fixed"&&c.position!=="sticky")continue;let m=s.getBoundingClientRect();m.bottom<t-8||m.bottom>t+8||m.width<e*.6||m.height>r&&(r=m.height);}}return r}function _e(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,o=window.innerHeight,a=0;for(let r of e){let i;try{i=document.querySelectorAll(r);}catch{continue}for(let l of Array.from(i)){let s=l.getBoundingClientRect();if(s.height===0||s.width===0)continue;let c=0;switch(t){case "bottom":if(s.bottom<o-8)break;c=Math.max(0,o-s.top);break;case "top":if(s.top>8)break;c=Math.max(0,s.bottom);break;case "left":if(s.left>8)break;c=Math.max(0,s.right);break;case "right":if(s.right<n-8)break;c=Math.max(0,n-s.left);break}c>a&&(a=c);}}return a}function yt(e){let[t,n]=useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),o=useRef(t),a=Zn(e.avoid),r=e.placement,i=e.offset.x,l=e.offset.y;return useEffect(()=>{if(typeof window>"u")return;let s=0,c=false,m=()=>{if(s=0,c)return;let w=r[0]==="b"?"bottom":"top",k=r[1]==="r"?"right":"left",M=0,T=0;e.avoid==="auto"&&w==="bottom"?M=vt():Array.isArray(e.avoid)&&(M=_e(e.avoid,w),T=_e(e.avoid,k));let N={bottom:w==="bottom"?l+M:0,top:w==="top"?l+M:0,right:k==="right"?i+T:0,left:k==="left"?i+T:0},P=o.current;(N.bottom!==P.bottom||N.top!==P.top||N.right!==P.right||N.left!==P.left)&&(o.current=N,n(N));},p=()=>{s||(s=window.requestAnimationFrame(m));};p();let g=typeof ResizeObserver<"u"?new ResizeObserver(p):null;g?.observe(document.documentElement);let E=typeof MutationObserver<"u"?new MutationObserver(p):null;E?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",p);let C=window.visualViewport;return C?.addEventListener("resize",p),C?.addEventListener("scroll",p),()=>{c=true,s&&window.cancelAnimationFrame(s),g?.disconnect(),E?.disconnect(),window.removeEventListener("resize",p),C?.removeEventListener("resize",p),C?.removeEventListener("scroll",p);}},[r,i,l,a]),t}function Zn(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function Et(e){let[t,n]=useState(false);return useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;let o=window.visualViewport;if(!o||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let a=100,r=0,i=()=>{r=0;let s=window.innerHeight-o.height;n(s>a);},l=()=>{r||(r=window.requestAnimationFrame(i));};return l(),o.addEventListener("resize",l),o.addEventListener("scroll",l),()=>{r&&window.cancelAnimationFrame(r),o.removeEventListener("resize",l),o.removeEventListener("scroll",l);}},[e]),t}function Mt({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:a}){let[r,i]=useState(null),l=useRef(null),s=yt(e),c=Et(e.hideOnKeyboard);if(useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),oo(l,!n&&!c),!r)return null;let m=e.placement,p=m[0]==="b"?"bottom":"top",g=m[1]==="r"?"right":"left",E=p==="bottom"?s.bottom:s.top,C=g==="right"?s.right:s.left,w={position:"fixed",[p]:e.safeArea?`calc(${E}px + env(safe-area-inset-${p}, 0px))`:`${E}px`,[g]:e.safeArea?`calc(${C}px + env(safe-area-inset-${g}, 0px))`:`${C}px`,zIndex:e.zIndex,opacity:n||c?0:1,pointerEvents:n||c?"none":"auto",transition:"opacity 160ms ease"};return createPortal(jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:w,"aria-label":e.label,"aria-hidden":n||c?true:void 0,tabIndex:n||c?-1:0,onPointerDown:k=>o?.(k.nativeEvent),onClick:k=>a(k.nativeEvent),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsx("span",{children:e.label})]}),r)}function oo(e,t){let n=useRef(false);useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let o=window.setTimeout(()=>{let a=e.current;if(!a)return;let r=a.getBoundingClientRect();if(r.width===0||r.height===0)return;let i=r.left+r.width/2,l=r.top+r.height/2,s=document.elementsFromPoint(i,l),c=Ct(window.getComputedStyle(a).zIndex);for(let m of s){if(m===a||a.contains(m))continue;if(Ct(window.getComputedStyle(m).zIndex)>c){n.current=true,console.warn("[lumen] trigger is occluded by",m);break}}},250);return ()=>window.clearTimeout(o)},[t,e]);}function Ct(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function Rt({mount:e,label:t,icon:n,onPointerDown:o,onClick:a}){let[r,i]=useState(null);return useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;i(l);},[e]),r?createPortal(jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onPointerDown:l=>o?.(l.nativeEvent),onClick:l=>a(l.nativeEvent),"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsx("span",{children:t})]}),r):null}function Nt({config:e,portalTarget:t,hidden:n,onPointerDown:o,onClick:a}){let[r,i]=useState(null),[l,s]=useState(false),c=useRef(null);if(useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),!r)return null;let m=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function p(w){o?.(w.nativeEvent),c.current={x:w.clientX,y:w.clientY},s(true),w.currentTarget.setPointerCapture(w.pointerId);}function g(w){let k=c.current;if(!k)return;let M=w.clientX-k.x,T=w.clientY-k.y;(e.edge==="top"&&T>16||e.edge==="bottom"&&T<-16||e.edge==="right"&&M<-16||e.edge==="left"&&M>16)&&(c.current=null,a(w.nativeEvent));}function E(){c.current=null,s(false);}function C(){c.current=null,s(false);}return createPortal(jsxs("button",{type:"button",className:m,style:{zIndex:e.zIndex,opacity:n?0:1,pointerEvents:n?"none":"auto"},"aria-label":e.label,"aria-hidden":n?true:void 0,tabIndex:n?-1:0,onClick:w=>a(w.nativeEvent),onPointerDown:p,onPointerMove:g,onPointerUp:E,onPointerCancel:C,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),r)}function At(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function St(e){return {kind:"floating",placement:e.placement??"br",offset:{x:e.offset?.x??16,y:e.offset?.y??16},safeArea:e.safeArea??true,avoid:e.avoid===false?false:e.avoid==null?"auto":Array.isArray(e.avoid)?e.avoid:[e.avoid],hideOnKeyboard:e.hideOnKeyboard??true,zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var wo={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function Pt(e){let t=useId();useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,o=`data-lumen-theme-${vo(t)}`,a={};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")a["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else for(let[r,i]of Object.entries(wo)){let l=e[i];typeof l=="string"&&l.length>0&&(a[r]=n.style.getPropertyValue(r)||null,n.style.setProperty(r,l));}return n.setAttribute(o,""),()=>{n.removeAttribute(o);for(let[r,i]of Object.entries(a))r.startsWith("--")?i?n.style.setProperty(r,i):n.style.removeProperty(r):i==null?n.removeAttribute(r):n.setAttribute(r,i);}},[e,t]);}function vo(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var Dt=Symbol.for("lumen.history.patched"),Fe="lumen:locationchange";function Co(){if(typeof window>"u")return;let e=window;if(e[Dt])return;e[Dt]=true;let t=()=>window.dispatchEvent(new Event(Fe)),n=history.pushState;history.pushState=function(...a){let r=n.apply(this,a);return t(),r};let o=history.replaceState;history.replaceState=function(...a){let r=o.apply(this,a);return t(),r},window.addEventListener("popstate",t);}function It(e){let[t,n]=useState(false);return useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;Co();let o=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return o(),window.addEventListener(Fe,o),window.addEventListener("popstate",o),()=>{window.removeEventListener(Fe,o),window.removeEventListener("popstate",o);}},[e]),t}var Mo=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function Ot(){let[e,t]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let o=n.webkit;if(o&&o.messageHandlers){t(true);return}let a=navigator.userAgent||"";Mo.some(r=>a.includes(r))&&t(true);},[]),e}var _t="lumen.config.v1.",Lo=3600*1e3;function Ft(e,t){let[n,o]=useState(()=>({trigger:null,enabled:true,shakeToOpen:false,loading:true}));return useEffect(()=>{if(typeof window>"u")return;let a=Po(e);a&&o({trigger:a.trigger,enabled:Ht(a.trigger),shakeToOpen:a.shake,loading:false});let r=new AbortController,i=window.setTimeout(()=>r.abort(),5e3),l=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(l,{method:"GET",mode:"cors",credentials:"omit",signal:r.signal}).then(async s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);let c=await s.json(),m=Ut(c.trigger);if(!m)throw new Error("Malformed config response");let p=So(c.trigger);Do(e,m,p),o({trigger:m,enabled:Ht(m),shakeToOpen:p,loading:false});}).catch(()=>{o(s=>s.loading?{trigger:null,enabled:true,shakeToOpen:false,loading:false}:s);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),r.abort();}},[e,t]),n}function Ht(e){return e.kind!=="headless"}var No=["br","bl","tr","tl"],Ao=["top","right","bottom","left"];function Ut(e){if(!e||typeof e!="object")return null;let t=e;if(t.enabled===false)return {kind:"headless"};let n=typeof t.label=="string"?t.label:"Feedback";return t.kind==="floating"?{kind:"floating",placement:No.find(a=>a===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:Ao.find(a=>a===t.edge)??"top",label:n}:null}function So(e){return !e||typeof e!="object"?false:e.shake===true}function Po(e){try{let t=window.localStorage.getItem(_t+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>Lo)return null;let o=Ut(n.trigger);return o?{fetchedAt:n.fetchedAt,trigger:o,shake:n.shake===!0}:null}catch{return null}}function Do(e,t,n){try{window.localStorage.setItem(_t+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n}));}catch{}}function Oo(e){if(e&&typeof e=="object")return e.type===ve;if(typeof e=="string")try{return JSON.parse(e).type===ve}catch{return false}return false}function Ho(e={}){let t=e.threshold??18,n=e.neededHits??3,o=e.windowMs??700,a=e.throttleMs??60,r=null,i=[];return {push(l,s,c,m){if(!r)return r={x:l,y:s,z:c,t:m},false;if(m-r.t<a)return false;let p=Math.abs(l-r.x)+Math.abs(s-r.y)+Math.abs(c-r.z);return r={x:l,y:s,z:c,t:m},p<t?false:(i=i.filter(g=>m-g<o),i.push(m),i.length>=n?(i=[],true):false)}}}function Vt(e,t,n){useEffect(()=>{if(!e||typeof window>"u")return;let o=0,a=1500;function r(){let m=Date.now();n||m-o<a||(o=m,t());}let i=m=>{Oo(m.data)&&r();};window.addEventListener("message",i),document.addEventListener("message",i);let l=Ho(),s=m=>{let p=m.accelerationIncludingGravity??m.acceleration;!p||p.x==null||p.y==null||p.z==null||l.push(p.x,p.y,p.z,Date.now())&&r();},c=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return c&&window.addEventListener("devicemotion",s),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),c&&window.removeEventListener("devicemotion",s);}},[e,t,n]);}var zt="https://shakebugs.vercel.app";function _o({apiKey:e,apiUrl:t,user:n,amplitude:o,floatingButton:a=true,trigger:r,hideOn:i,theme:l,portalTarget:s,capture:c,shakeToOpen:m,onOpenChange:p,beforeOpen:g,onTriggerActivate:E,children:C}){let[w,k]=useState(false),[M,T]=useState(false),[N,P]=useState(null),[F,A]=useState(null),[f]=useState(false),[b]=useState(null),v=useRef(false),R=useRef(false),S=useRef(null),D=useMemo(()=>new et({apiKey:e,apiUrl:t,user:n,amplitude:o}),[e,t,n?.id,n?.email,n?.name,o?.userId,o?.deviceId,o?.sessionId]);useEffect(()=>{it({ignoreUrlPrefix:(t??zt).replace(/\/$/,"")});},[t]);let U=useRef(p);U.current=p,useEffect(()=>{if(!(typeof document>"u"))return w?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[w]);let K=useRef(null);useEffect(()=>{if(K.current===w)return;let O=K.current;K.current=w,O!==null&&U.current?.(w);},[w]);let j=useRef(g);j.current=g;let ae=useRef(E);ae.current=E;let I=useCallback(O=>{R.current=true,S.current=Promise.resolve().then(()=>j.current?.(O)).then(()=>ae.current?.(O)).then(()=>{});},[]),B=useCallback(O=>{v.current||w||(v.current=true,T(true),P(null),A(null),(async()=>{try{if(R.current?await S.current:(await j.current?.(O),await ae.current?.(O)),c?.mode==="manual")P(null),A(null);else {let Z=await be({...c,mode:c?.mode??"auto",target:c?.target??document.documentElement});P(Z);}}catch(Z){A(Z instanceof Error?Z:new Error(String(Z)));}finally{R.current=false,S.current=null,v.current=false,T(false),k(true);}})());},[c,w]),_=useCallback(()=>k(false),[]),Y=useCallback(D.submit.bind(D),[D]),ce=Ot(),ne=It(i);Pt(l);let z=Ft(r?"":e,t??zt),oe=m??z.shakeToOpen;Vt(oe,B,w);let $=useMemo(()=>({client:D,user:n,isOpen:w,isSubmitting:f,error:b,open:B,close:_,openCapture:B,closeCapture:_,submit:Y,isNativeShell:ce,capture:c,initialCapture:N,initialCaptureError:F,isOpening:M}),[D,n,w,f,b,B,_,Y,ce,c,N,F,M]),V=Fo({explicit:r,remote:z.trigger,remoteLoading:z.loading,floatingButton:a});return jsxs(Se.Provider,{value:$,children:[C,V?.kind==="floating"?jsx(Mt,{config:St(V),portalTarget:s,hidden:ne||M,onPointerDown:I,onClick:O=>B(O)}):null,V?.kind==="notch"?jsx(Nt,{config:At(V),portalTarget:s,hidden:ne||M,onPointerDown:I,onClick:O=>B(O)}):null,V?.kind==="inline"?jsx(Rt,{mount:V.mount,label:V.label??"Feedback",icon:V.icon,onPointerDown:I,onClick:O=>B(O)}):null,jsx(He,{})]})}function Fo(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function Vo({variant:e="default",floating:t=false,className:n,children:o="Feedback",onClick:a,...r}){let{openCapture:i}=ue(),l=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsx("button",{type:"button",className:l,"data-lumen-trigger":"",onClick:s=>{a?.(s),s.defaultPrevented||i(s.nativeEvent);},...r,children:o})}
|
|
4
|
+
export{He as CaptureModal,Vo as FeedbackButton,ve as LUMEN_SHAKE_MESSAGE,_o as LumenProvider,yn as createNativeCaptureProvider,Pn as isLumenEventTarget,ue as useLumen};//# sourceMappingURL=index.js.map
|
|
5
5
|
//# sourceMappingURL=index.js.map
|