gotcha-feedback 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var j="https://api.gotcha.cx/v1";var V={ANONYMOUS_ID:"gotcha_anonymous_id"},y={POSITION:"top-right",SIZE:"md",THEME:"auto",SHOW_ON_HOVER:true,TOUCH_BEHAVIOR:"always-visible",SUBMIT_TEXT:"Submit",THANK_YOU_MESSAGE:"Thanks for your feedback!"};var P={MAX_RETRIES:2,BASE_DELAY_MS:500,MAX_DELAY_MS:5e3};function J(){if(typeof window>"u")return `anon_${crypto.randomUUID()}`;let e=localStorage.getItem(V.ANONYMOUS_ID);if(e)return e;let s=`anon_${crypto.randomUUID()}`;return localStorage.setItem(V.ANONYMOUS_ID,s),s}var ee={maxRetries:P.MAX_RETRIES,baseDelayMs:P.BASE_DELAY_MS,maxDelayMs:P.MAX_DELAY_MS};async function we(e,s,o=ee,n=false){let i=null;for(let a=0;a<=o.maxRetries;a++){try{n&&a>0&&console.log(`[Gotcha] Retry attempt ${a}/${o.maxRetries}`);let t=await fetch(e,s);if(t.status>=400&&t.status<500&&t.status!==429||t.ok)return t;i=new Error(`HTTP ${t.status}`);}catch(t){i=t,n&&console.log(`[Gotcha] Network error: ${i.message}`);}if(a<o.maxRetries){let t=Math.min(o.baseDelayMs*Math.pow(2,a),o.maxDelayMs);await new Promise(u=>setTimeout(u,t));}}throw i}function te(e){let{apiKey:s,baseUrl:o=j,debug:n=false}=e,i={"Content-Type":"application/json",Authorization:`Bearer ${s}`};async function a(t,u,r){let l=`${o}${u}`,c=crypto.randomUUID();n&&console.log(`[Gotcha] ${t} ${u}`,r);let p=await we(l,{method:t,headers:{...i,"Idempotency-Key":c},body:r?JSON.stringify(r):void 0},ee,n),d=await p.json();if(!p.ok){let m=d.error;throw n&&console.error(`[Gotcha] Error: ${m.code} - ${m.message}`),m}return n&&console.log("[Gotcha] Response:",d),d}return {async submitResponse(t){let u=t.user||{};u.id||(u.id=J());let r={...t,user:u,context:{url:typeof window<"u"?window.location.href:void 0,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}};return a("POST","/responses",r)},getBaseUrl(){return o}}}var re=react.createContext(null);function Me({apiKey:e,children:s,baseUrl:o,debug:n=false,disabled:i=false,defaultUser:a={}}){let[t,u]=react.useState(null),r=react.useMemo(()=>te({apiKey:e,baseUrl:o,debug:n}),[e,o,n]),l=react.useCallback(d=>{u(d);},[]),c=react.useCallback(()=>{u(null);},[]),p=react.useMemo(()=>({client:r,disabled:i,defaultUser:a,debug:n,activeModalId:t,openModal:l,closeModal:c}),[r,i,a,n,t,l,c]);return jsxRuntime.jsx(re.Provider,{value:p,children:s})}function T(){let e=react.useContext(re);if(!e)throw new Error("useGotchaContext must be used within a GotchaProvider");return e}function ae(e){let{client:s,defaultUser:o}=T(),[n,i]=react.useState(false),[a,t]=react.useState(null);return {submit:react.useCallback(async r=>{i(true),t(null);try{let l=await s.submitResponse({elementId:e.elementId,mode:e.mode,content:r.content,title:r.title,rating:r.rating,vote:r.vote,pollOptions:e.pollOptions,pollSelected:r.pollSelected,experimentId:e.experimentId,variant:e.variant,user:{...o,...e.user}});return e.onSuccess?.(l),l}catch(l){let c=l instanceof Error?l.message:"Something went wrong";throw t(c),e.onError?.(l instanceof Error?l:new Error(c)),l}finally{i(false);}},[s,o,e]),isLoading:n,error:a,clearError:()=>t(null)}}function D(...e){return e.filter(Boolean).join(" ")}var ie=()=>typeof window>"u"?false:"ontouchstart"in window||navigator.maxTouchPoints>0,le=(e,s)=>{let o={sm:{desktop:24,mobile:44},md:{desktop:32,mobile:44},lg:{desktop:40,mobile:48}};return s?o[e].mobile:o[e].desktop};function ue({size:e,theme:s,customStyles:o,showOnHover:n,touchBehavior:i,onClick:a,isOpen:t,isParentHovered:u=false}){let[r,l]=react.useState(false),[c,p]=react.useState(false);react.useEffect(()=>{l(ie());},[]);let d=t?true:!r&&n?u:r&&i==="tap-to-reveal"?c:true,m=()=>{if(r&&i==="tap-to-reveal"&&!c){p(true);return}a();},f=le(e,r),E=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,k={width:f,height:f,borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:E==="dark"?"#374151":"#c7d2dc",color:E==="dark"?"#e5e7eb":"#4b5563",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:d?1:0,transform:d?"scale(1)":"scale(0.6)",pointerEvents:d?"auto":"none",...o?.button};return jsxRuntime.jsx("button",{type:"button",onClick:m,style:k,className:D("gotcha-button",t&&"gotcha-button--open"),"aria-label":"Give feedback on this feature","aria-expanded":t,"aria-haspopup":"dialog",children:jsxRuntime.jsx(_e,{size:f*.75})})}function _e({size:e}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsxRuntime.jsx("text",{x:"50%",y:"50%",dominantBaseline:"central",textAnchor:"middle",fontSize:"16",fontWeight:"bold",fill:"currentColor",fontFamily:"system-ui, -apple-system, sans-serif",children:"G"})})}function de({theme:e,placeholder:s,submitText:o,isLoading:n,onSubmit:i,customStyles:a}){let[t,u]=react.useState(""),[r,l]=react.useState(null),c=e==="dark",p=f=>{f.preventDefault(),!(!t.trim()&&r===null)&&i({content:t.trim()||void 0,rating:r??void 0});},d={width:"100%",padding:"10px 12px",border:`1px solid ${c?"#374151":"#d1d5db"}`,borderRadius:6,backgroundColor:c?"#374151":"#ffffff",color:c?"#f9fafb":"#111827",fontSize:14,resize:"vertical",minHeight:80,fontFamily:"inherit",...a?.input},m={width:"100%",padding:"10px 16px",border:"none",borderRadius:6,backgroundColor:n?c?"#4b5563":"#9ca3af":"#6366f1",color:"#ffffff",fontSize:14,fontWeight:500,cursor:n?"not-allowed":"pointer",transition:"background-color 150ms ease",...a?.submitButton};return jsxRuntime.jsxs("form",{onSubmit:p,children:[jsxRuntime.jsx("div",{style:{marginBottom:12},children:jsxRuntime.jsx(Oe,{value:r,onChange:l,isDark:c})}),jsxRuntime.jsx("textarea",{value:t,onChange:f=>u(f.target.value),placeholder:s||"Share your thoughts...",style:d,disabled:n,"aria-label":"Your feedback"}),jsxRuntime.jsx("button",{type:"submit",disabled:n||!t.trim()&&r===null,style:{...m,marginTop:12,opacity:!t.trim()&&r===null?.5:1},children:n?"Submitting...":o})]})}function Oe({value:e,onChange:s,isDark:o}){let[n,i]=react.useState(null);return jsxRuntime.jsx("div",{style:{display:"flex",gap:4},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(a=>{let t=(n??e??0)>=a;return jsxRuntime.jsx("button",{type:"button",onClick:()=>s(a),onMouseEnter:()=>i(a),onMouseLeave:()=>i(null),"aria-label":`Rate ${a} out of 5`,"aria-pressed":e===a,style:{background:"none",border:"none",cursor:"pointer",padding:2,color:t?"#f59e0b":o?"#4b5563":"#d1d5db",transition:"color 150ms ease"},children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"})})},a)})})}function pe({theme:e,isLoading:s,onSubmit:o}){let n=e==="dark",i={flex:1,padding:"12px 16px",border:`1px solid ${n?"#374151":"#e5e7eb"}`,borderRadius:8,backgroundColor:n?"#374151":"#f9fafb",color:n?"#f9fafb":"#111827",fontSize:24,cursor:s?"not-allowed":"pointer",transition:"all 150ms ease",display:"flex",alignItems:"center",justifyContent:"center",gap:8};return jsxRuntime.jsxs("div",{style:{display:"flex",gap:12},role:"group","aria-label":"Vote",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>o({vote:"up"}),disabled:s,style:i,"aria-label":"Vote up - I like this",children:[jsxRuntime.jsx(De,{}),jsxRuntime.jsx("span",{style:{fontSize:14,fontWeight:500},children:"Like"})]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>o({vote:"down"}),disabled:s,style:i,"aria-label":"Vote down - I don't like this",children:[jsxRuntime.jsx(Le,{}),jsxRuntime.jsx("span",{style:{fontSize:14,fontWeight:500},children:"Dislike"})]})]})}function De(){return jsxRuntime.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}function Le(){return jsxRuntime.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"})})}function he({mode:e,theme:s,customStyles:o,promptText:n,placeholder:i,submitText:a,thankYouMessage:t,isLoading:u,isSubmitted:r,error:l,onSubmit:c,onClose:p,anchorRect:d}){let m=react.useRef(null),f=react.useRef(null),[E,k]=react.useState(false);react.useEffect(()=>{let x=requestAnimationFrame(()=>k(true));return ()=>cancelAnimationFrame(x)},[]);let G=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,h=G==="dark",M=(d?window.innerHeight-d.bottom:window.innerHeight/2)<280+20;react.useEffect(()=>{let x=m.current;if(!x)return;f.current?.focus();let I=b=>{if(b.key==="Escape"){p();return}if(b.key==="Tab"){let C=x.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),w=C[0],_=C[C.length-1];b.shiftKey&&document.activeElement===w?(b.preventDefault(),_?.focus()):!b.shiftKey&&document.activeElement===_&&(b.preventDefault(),w?.focus());}};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[p]);let B=e==="vote"?"What do you think?":"What do you think of this feature?",H={position:"absolute",left:"50%",width:320,padding:16,borderRadius:8,backgroundColor:h?"#1f2937":"#ffffff",color:h?"#f9fafb":"#111827",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.15)",border:`1px solid ${h?"#374151":"#e5e7eb"}`,zIndex:9999,...M?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:E?1:0,transform:E?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.95) translateY(${M?"10px":"-10px"})`,...o?.modal};return jsxRuntime.jsxs("div",{ref:m,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:H,className:D("gotcha-modal",h&&"gotcha-modal--dark"),children:[jsxRuntime.jsx("button",{ref:f,type:"button",onClick:p,"aria-label":"Close feedback form",style:{position:"absolute",top:8,right:8,width:24,height:24,border:"none",background:"none",cursor:"pointer",color:h?"#9ca3af":"#6b7280",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:jsxRuntime.jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}),jsxRuntime.jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 12px 0",fontSize:14,fontWeight:500,paddingRight:24},children:n||B}),r&&jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"20px 0",color:h?"#10b981":"#059669"},children:[jsxRuntime.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",style:{margin:"0 auto 8px"},children:jsxRuntime.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),jsxRuntime.jsx("p",{style:{margin:0,fontSize:14},children:t})]}),l&&!r&&jsxRuntime.jsx("div",{style:{padding:8,marginBottom:12,borderRadius:4,backgroundColor:h?"#7f1d1d":"#fef2f2",color:h?"#fecaca":"#dc2626",fontSize:13},children:l}),!r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e==="feedback"&&jsxRuntime.jsx(de,{theme:G,placeholder:i,submitText:a,isLoading:u,onSubmit:c,customStyles:o}),e==="vote"&&jsxRuntime.jsx(pe,{theme:G,isLoading:u,onSubmit:c})]}),jsxRuntime.jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[r&&"Thank you! Your feedback has been submitted.",l&&`Error: ${l}`]})]})}function ze({elementId:e,user:s,mode:o="feedback",experimentId:n,variant:i,options:a,allowMultiple:t=false,showResults:u=true,position:r=y.POSITION,size:l=y.SIZE,theme:c=y.THEME,customStyles:p,visible:d=true,showOnHover:m=y.SHOW_ON_HOVER,touchBehavior:f=y.TOUCH_BEHAVIOR,promptText:E,placeholder:k,submitText:G=y.SUBMIT_TEXT,thankYouMessage:h=y.THANK_YOU_MESSAGE,onSubmit:K,onOpen:N,onClose:M,onError:B}){let{disabled:H,activeModalId:x,openModal:I,closeModal:b}=T(),[C,w]=react.useState(false),[_,X]=react.useState(false),[ge,ve]=react.useState(null),O=react.useRef(null),z=x===e;react.useEffect(()=>{if(!m)return;let v=O.current;if(!v)return;let A=v.parentElement;if(!A)return;let Q=()=>X(true),Z=()=>X(false);return A.addEventListener("mouseenter",Q),A.addEventListener("mouseleave",Z),()=>{A.removeEventListener("mouseenter",Q),A.removeEventListener("mouseleave",Z);}},[m]);let{submit:q,isLoading:ye,error:Se}=ae({elementId:e,mode:o,experimentId:n,variant:i,pollOptions:a,user:s,onSuccess:v=>{w(true),K?.(v),setTimeout(()=>{b(),w(false);},2500);},onError:v=>{B?.(v);}}),Re=react.useCallback(()=>{O.current&&ve(O.current.getBoundingClientRect()),I(e),N?.();},[e,I,N]),Ee=react.useCallback(()=>{b(),w(false),M?.();},[b,M]),xe=react.useCallback(v=>{q(v);},[q]);return H||!d?null:jsxRuntime.jsxs("div",{ref:O,style:{...{"top-right":{position:"absolute",top:0,right:0,transform:"translate(50%, -50%)"},"top-left":{position:"absolute",top:0,left:0,transform:"translate(-50%, -50%)"},"bottom-right":{position:"absolute",bottom:0,right:0,transform:"translate(50%, 50%)"},"bottom-left":{position:"absolute",bottom:0,left:0,transform:"translate(-50%, 50%)"},inline:{position:"relative",display:"inline-flex"}}[r],zIndex:z?1e4:50},className:"gotcha-container","data-gotcha-element":e,children:[jsxRuntime.jsx(ue,{size:l,theme:c,customStyles:p,showOnHover:m,touchBehavior:f,onClick:Re,isOpen:z,isParentHovered:_}),z&&jsxRuntime.jsx(he,{mode:o,theme:c,customStyles:p,promptText:E,placeholder:k,submitText:G,thankYouMessage:h,isLoading:ye,isSubmitted:C,error:Se,onSubmit:xe,onClose:Ee,anchorRect:ge||void 0})]})}function Ye(){let{client:e,disabled:s,defaultUser:o,debug:n}=T();return {client:e,disabled:s,defaultUser:o,debug:n,submitFeedback:e.submitResponse.bind(e)}}
2
- exports.Gotcha=ze;exports.GotchaProvider=Me;exports.useGotcha=Ye;//# sourceMappingURL=index.js.map
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');var ce="https://api.gotcha.cx/v1";var Q={ANONYMOUS_ID:"gotcha_anonymous_id"},R={POSITION:"top-right",SIZE:"md",THEME:"auto",SHOW_ON_HOVER:true,TOUCH_BEHAVIOR:"always-visible",SUBMIT_TEXT:"Submit",THANK_YOU_MESSAGE:"Thanks for your feedback!"};var H={MAX_RETRIES:2,BASE_DELAY_MS:500,MAX_DELAY_MS:5e3};function de(){if(typeof window>"u")return `anon_${crypto.randomUUID()}`;let e=localStorage.getItem(Q.ANONYMOUS_ID);if(e)return e;let s=`anon_${crypto.randomUUID()}`;return localStorage.setItem(Q.ANONYMOUS_ID,s),s}var ue={maxRetries:H.MAX_RETRIES,baseDelayMs:H.BASE_DELAY_MS,maxDelayMs:H.MAX_DELAY_MS};async function Ie(e,s,r=ue,o=false){let c=null;for(let a=0;a<=r.maxRetries;a++){try{o&&a>0&&console.log(`[Gotcha] Retry attempt ${a}/${r.maxRetries}`);let t=await fetch(e,s);if(t.status>=400&&t.status<500&&t.status!==429||t.ok)return t;c=new Error(`HTTP ${t.status}`);}catch(t){c=t,o&&console.log(`[Gotcha] Network error: ${c.message}`);}if(a<r.maxRetries){let t=Math.min(r.baseDelayMs*Math.pow(2,a),r.maxDelayMs);await new Promise(d=>setTimeout(d,t));}}throw c}function pe(e){let{apiKey:s,baseUrl:r=ce,debug:o=false}=e,c={"Content-Type":"application/json",Authorization:`Bearer ${s}`};async function a(t,d,n){let l=`${r}${d}`,i=crypto.randomUUID();o&&console.log(`[Gotcha] ${t} ${d}`,n);let p=await Ie(l,{method:t,headers:{...c,"Idempotency-Key":i},body:n?JSON.stringify(n):void 0},ue,o),u=await p.json();if(!p.ok){let f=u.error;throw o&&console.error(`[Gotcha] Error: ${f.code} - ${f.message}`),f}return o&&console.log("[Gotcha] Response:",u),u}return {async submitResponse(t){let d=t.user||{};d.id||(d.id=de());let n={...t,user:d,context:{url:typeof window<"u"?window.location.href:void 0,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}};return a("POST","/responses",n)},getBaseUrl(){return r}}}var he=react.createContext(null);function _e({apiKey:e,children:s,baseUrl:r,debug:o=false,disabled:c=false,defaultUser:a={}}){let[t,d]=react.useState(null),n=react.useMemo(()=>pe({apiKey:e,baseUrl:r,debug:o}),[e,r,o]),l=react.useCallback(u=>{d(u);},[]),i=react.useCallback(()=>{d(null);},[]),p=react.useMemo(()=>({client:n,disabled:c,defaultUser:a,debug:o,activeModalId:t,openModal:l,closeModal:i}),[n,c,a,o,t,l,i]);return jsxRuntime.jsx(he.Provider,{value:p,children:s})}function I(){let e=react.useContext(he);if(!e)throw new Error("useGotchaContext must be used within a GotchaProvider");return e}function ge(e){let{client:s,defaultUser:r}=I(),[o,c]=react.useState(false),[a,t]=react.useState(null);return {submit:react.useCallback(async n=>{c(true),t(null);try{let l=await s.submitResponse({elementId:e.elementId,mode:e.mode,content:n.content,title:n.title,rating:n.rating,vote:n.vote,pollOptions:e.pollOptions,pollSelected:n.pollSelected,experimentId:e.experimentId,variant:e.variant,user:{...r,...e.user}});return e.onSuccess?.(l),l}catch(l){let i=l instanceof Error?l.message:"Something went wrong";throw t(i),e.onError?.(l instanceof Error?l:new Error(i)),l}finally{c(false);}},[s,r,e]),isLoading:o,error:a,clearError:()=>t(null)}}function V(...e){return e.filter(Boolean).join(" ")}var G=()=>typeof window>"u"?false:"ontouchstart"in window||navigator.maxTouchPoints>0,ve=(e,s)=>{let r={sm:{desktop:24,mobile:32},md:{desktop:32,mobile:36},lg:{desktop:40,mobile:40}};return s?r[e].mobile:r[e].desktop};function Se({size:e,theme:s,customStyles:r,showOnHover:o,touchBehavior:c,onClick:a,isOpen:t,isParentHovered:d=false}){let[n,l]=react.useState(false),[i,p]=react.useState(false);react.useEffect(()=>{l(G());},[]);let u=t?true:!n&&o?d:n&&c==="tap-to-reveal"?i:true,f=()=>{if(n&&c==="tap-to-reveal"&&!i){p(true);return}a();},g=ve(e,n),b=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,v={width:g,height:g,borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:b==="dark"?"#374151":"#c7d2dc",color:b==="dark"?"#e5e7eb":"#4b5563",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:u?1:0,transform:u?"scale(1)":"scale(0.6)",pointerEvents:u?"auto":"none",...r?.button};return jsxRuntime.jsx("button",{type:"button",onClick:f,style:v,className:V("gotcha-button",t&&"gotcha-button--open"),"aria-label":"Give feedback on this feature","aria-expanded":t,"aria-haspopup":"dialog",children:jsxRuntime.jsx(Le,{size:g*.75})})}function Le({size:e}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsxRuntime.jsx("text",{x:"50%",y:"50%",dominantBaseline:"central",textAnchor:"middle",fontSize:"16",fontWeight:"bold",fill:"currentColor",fontFamily:"system-ui, -apple-system, sans-serif",children:"G"})})}function xe({theme:e,placeholder:s,submitText:r,isLoading:o,onSubmit:c,customStyles:a}){let[t,d]=react.useState(""),[n,l]=react.useState(null),[i,p]=react.useState(false);react.useEffect(()=>{p(G());},[]);let u=e==="dark",f=v=>{v.preventDefault(),!(!t.trim()&&n===null)&&c({content:t.trim()||void 0,rating:n??void 0});},g={width:"100%",padding:i?"12px 14px":"10px 12px",border:`1px solid ${u?"#374151":"#d1d5db"}`,borderRadius:i?8:6,backgroundColor:u?"#374151":"#ffffff",color:u?"#f9fafb":"#111827",fontSize:i?16:14,resize:"vertical",minHeight:i?100:80,fontFamily:"inherit",...a?.input},b={width:"100%",padding:i?"14px 16px":"10px 16px",border:"none",borderRadius:i?8:6,backgroundColor:o?u?"#4b5563":"#9ca3af":"#6366f1",color:"#ffffff",fontSize:i?16:14,fontWeight:500,cursor:o?"not-allowed":"pointer",transition:"background-color 150ms ease",...a?.submitButton};return jsxRuntime.jsxs("form",{onSubmit:f,children:[jsxRuntime.jsx("div",{style:{marginBottom:i?16:12},children:jsxRuntime.jsx(Ne,{value:n,onChange:l,isDark:u,isTouch:i})}),jsxRuntime.jsx("textarea",{value:t,onChange:v=>d(v.target.value),placeholder:s||"Share your thoughts...",style:g,disabled:o,"aria-label":"Your feedback"}),jsxRuntime.jsx("button",{type:"submit",disabled:o||!t.trim()&&n===null,style:{...b,marginTop:12,opacity:!t.trim()&&n===null?.5:1},children:o?"Submitting...":r})]})}function Ne({value:e,onChange:s,isDark:r,isTouch:o}){let[c,a]=react.useState(null),t=o?32:20,d=o?6:2;return jsxRuntime.jsx("div",{style:{display:"flex",gap:o?8:4},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(n=>{let l=(c??e??0)>=n;return jsxRuntime.jsx("button",{type:"button",onClick:()=>s(n),onMouseEnter:()=>a(n),onMouseLeave:()=>a(null),"aria-label":`Rate ${n} out of 5`,"aria-pressed":e===n,style:{background:"none",border:"none",cursor:"pointer",padding:d,color:l?"#f59e0b":r?"#4b5563":"#d1d5db",transition:"color 150ms ease"},children:jsxRuntime.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"})})},n)})})}function Re({theme:e,isLoading:s,onSubmit:r}){let[o,c]=react.useState(false);react.useEffect(()=>{c(G());},[]);let a=e==="dark",t={flex:1,padding:o?"16px 20px":"12px 16px",border:`1px solid ${a?"#374151":"#e5e7eb"}`,borderRadius:o?12:8,backgroundColor:a?"#374151":"#f9fafb",color:a?"#f9fafb":"#111827",fontSize:o?28:24,cursor:s?"not-allowed":"pointer",transition:"all 150ms ease",display:"flex",alignItems:"center",justifyContent:"center",gap:o?10:8},d=o?28:24;return jsxRuntime.jsxs("div",{style:{display:"flex",gap:o?16:12},role:"group","aria-label":"Vote",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>r({vote:"up"}),disabled:s,style:t,"aria-label":"Vote up - I like this",children:[jsxRuntime.jsx(Ve,{size:d}),jsxRuntime.jsx("span",{style:{fontSize:o?16:14,fontWeight:500},children:"Like"})]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>r({vote:"down"}),disabled:s,style:t,"aria-label":"Vote down - I don't like this",children:[jsxRuntime.jsx(Ye,{size:d}),jsxRuntime.jsx("span",{style:{fontSize:o?16:14,fontWeight:500},children:"Dislike"})]})]})}function Ve({size:e=24}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}function Ye({size:e=24}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"})})}function J({mode:e,theme:s,customStyles:r,promptText:o,placeholder:c,submitText:a,thankYouMessage:t,isLoading:d,isSubmitted:n,error:l,onSubmit:i,onClose:p,anchorRect:u}){let f=react.useRef(null),g=react.useRef(null),[b,v]=react.useState(false),[h,L]=react.useState(false);react.useEffect(()=>{L(window.innerWidth<640);},[]),react.useEffect(()=>{let T=requestAnimationFrame(()=>v(true));return ()=>cancelAnimationFrame(T)},[]);let C=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,m=C==="dark",U=(u?window.innerHeight-u.bottom:window.innerHeight/2)<280+20;react.useEffect(()=>{let T=f.current;if(!T)return;g.current?.focus();let k=x=>{if(x.key==="Escape"){p();return}if(x.key==="Tab"){let M=T.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),P=M[0],N=M[M.length-1];x.shiftKey&&document.activeElement===P?(x.preventDefault(),N?.focus()):!x.shiftKey&&document.activeElement===N&&(x.preventDefault(),P?.focus());}};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[p]);let X=e==="vote"?"What do you think?":"What do you think of this feature?",A=h?20:16,_=h?{position:"fixed",left:"50%",top:"50%",width:"calc(100vw - 32px)",maxWidth:320,padding:A,borderRadius:12,backgroundColor:m?"#1f2937":"#ffffff",color:m?"#f9fafb":"#111827",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.2)",border:`1px solid ${m?"#374151":"#e5e7eb"}`,zIndex:9999,transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:b?1:0,transform:b?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0.95)",...r?.modal}:{position:"absolute",left:"50%",width:320,padding:A,borderRadius:8,backgroundColor:m?"#1f2937":"#ffffff",color:m?"#f9fafb":"#111827",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.15)",border:`1px solid ${m?"#374151":"#e5e7eb"}`,zIndex:9999,...U?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:b?1:0,transform:b?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.95) translateY(${U?"10px":"-10px"})`,...r?.modal};return jsxRuntime.jsxs("div",{ref:f,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:_,className:V("gotcha-modal",m&&"gotcha-modal--dark"),children:[jsxRuntime.jsx("button",{ref:g,type:"button",onClick:p,"aria-label":"Close feedback form",style:{position:"absolute",top:h?12:8,right:h?12:8,width:h?36:24,height:h?36:24,border:"none",background:"none",cursor:"pointer",color:m?"#9ca3af":"#6b7280",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},children:jsxRuntime.jsx("svg",{width:h?18:14,height:h?18:14,viewBox:"0 0 14 14",fill:"none",children:jsxRuntime.jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}),jsxRuntime.jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 12px 0",fontSize:h?16:14,fontWeight:500,paddingRight:h?40:24},children:o||X}),n&&jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"20px 0",color:m?"#10b981":"#059669"},children:[jsxRuntime.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",style:{margin:"0 auto 8px"},children:jsxRuntime.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),jsxRuntime.jsx("p",{style:{margin:0,fontSize:14},children:t})]}),l&&!n&&jsxRuntime.jsx("div",{style:{padding:8,marginBottom:12,borderRadius:4,backgroundColor:m?"#7f1d1d":"#fef2f2",color:m?"#fecaca":"#dc2626",fontSize:13},children:l}),!n&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e==="feedback"&&jsxRuntime.jsx(xe,{theme:C,placeholder:c,submitText:a,isLoading:d,onSubmit:i,customStyles:r}),e==="vote"&&jsxRuntime.jsx(Re,{theme:C,isLoading:d,onSubmit:i})]}),jsxRuntime.jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[n&&"Thank you! Your feedback has been submitted.",l&&`Error: ${l}`]})]})}function Ke({elementId:e,user:s,mode:r="feedback",experimentId:o,variant:c,options:a,allowMultiple:t=false,showResults:d=true,position:n=R.POSITION,size:l=R.SIZE,theme:i=R.THEME,customStyles:p,visible:u=true,showOnHover:f=R.SHOW_ON_HOVER,touchBehavior:g=R.TOUCH_BEHAVIOR,promptText:b,placeholder:v,submitText:h=R.SUBMIT_TEXT,thankYouMessage:L=R.THANK_YOU_MESSAGE,onSubmit:C,onOpen:m,onClose:K,onError:te}){let{disabled:U,activeModalId:X,openModal:A,closeModal:_}=I(),[T,k]=react.useState(false),[x,M]=react.useState(false),[P,N]=react.useState(null),[oe,ke]=react.useState(false),B=react.useRef(null);react.useEffect(()=>{ke(window.innerWidth<640);},[]);let z=X===e;react.useEffect(()=>{if(!f)return;let y=B.current;if(!y)return;let O=y.parentElement;if(!O)return;let ie=()=>M(true),le=()=>M(false);return O.addEventListener("mouseenter",ie),O.addEventListener("mouseleave",le),()=>{O.removeEventListener("mouseenter",ie),O.removeEventListener("mouseleave",le);}},[f]);let{submit:ne,isLoading:re,error:se}=ge({elementId:e,mode:r,experimentId:o,variant:c,pollOptions:a,user:s,onSuccess:y=>{k(true),C?.(y),setTimeout(()=>{_(),k(false);},2500);},onError:y=>{te?.(y);}}),Me=react.useCallback(()=>{B.current&&N(B.current.getBoundingClientRect()),A(e),m?.();},[e,A,m]),q=react.useCallback(()=>{_(),k(false),K?.();},[_,K]),ae=react.useCallback(y=>{ne(y);},[ne]);return U||!u?null:jsxRuntime.jsxs("div",{ref:B,style:{...{"top-right":{position:"absolute",top:0,right:0,transform:"translate(50%, -50%)"},"top-left":{position:"absolute",top:0,left:0,transform:"translate(-50%, -50%)"},"bottom-right":{position:"absolute",bottom:0,right:0,transform:"translate(50%, 50%)"},"bottom-left":{position:"absolute",bottom:0,left:0,transform:"translate(-50%, 50%)"},inline:{position:"relative",display:"inline-flex"}}[n],zIndex:z?1e4:50},className:"gotcha-container","data-gotcha-element":e,children:[jsxRuntime.jsx(Se,{size:l,theme:i,customStyles:p,showOnHover:f,touchBehavior:g,onClick:Me,isOpen:z,isParentHovered:x}),z&&!oe&&jsxRuntime.jsx(J,{mode:r,theme:i,customStyles:p,promptText:b,placeholder:v,submitText:h,thankYouMessage:L,isLoading:re,isSubmitted:T,error:se,onSubmit:ae,onClose:q,anchorRect:P||void 0}),z&&oe&&reactDom.createPortal(jsxRuntime.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,backgroundColor:"rgba(0, 0, 0, 0.3)"},onClick:q,"aria-hidden":"true",children:jsxRuntime.jsx("div",{onClick:y=>y.stopPropagation(),children:jsxRuntime.jsx(J,{mode:r,theme:i,customStyles:p,promptText:b,placeholder:v,submitText:h,thankYouMessage:L,isLoading:re,isSubmitted:T,error:se,onSubmit:ae,onClose:q,anchorRect:P||void 0})})}),document.body)]})}function qe(){let{client:e,disabled:s,defaultUser:r,debug:o}=I();return {client:e,disabled:s,defaultUser:r,debug:o,submitFeedback:e.submitResponse.bind(e)}}
2
+ exports.Gotcha=Ke;exports.GotchaProvider=_e;exports.useGotcha=qe;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/utils/anonymous.ts","../src/api/client.ts","../src/components/GotchaProvider.tsx","../src/hooks/useSubmit.ts","../src/utils/cn.ts","../src/utils/device.ts","../src/components/GotchaButton.tsx","../src/components/modes/FeedbackMode.tsx","../src/components/modes/VoteMode.tsx","../src/components/GotchaModal.tsx","../src/components/Gotcha.tsx","../src/hooks/useGotcha.ts"],"names":["API_BASE_URL","STORAGE_KEYS","DEFAULTS","RETRY_CONFIG","getAnonymousId","stored","id","DEFAULT_RETRY_CONFIG","fetchWithRetry","url","options","config","debug","lastError","attempt","response","error","delay","resolve","createApiClient","apiKey","baseUrl","headers","request","method","endpoint","body","idempotencyKey","data","payload","user","fullPayload","GotchaContext","createContext","GotchaProvider","children","disabled","defaultUser","activeModalId","setActiveModalId","useState","client","useMemo","openModal","useCallback","elementId","closeModal","value","jsx","useGotchaContext","context","useContext","useSubmit","isLoading","setIsLoading","setError","err","errorMessage","cn","classes","isTouchDevice","getResponsiveSize","size","isTouch","sizes","GotchaButton","theme","customStyles","showOnHover","touchBehavior","onClick","isOpen","isParentHovered","setIsTouch","tapRevealed","setTapRevealed","useEffect","shouldShow","handleClick","buttonSize","resolvedTheme","baseStyles","GotchaIcon","FeedbackMode","placeholder","submitText","onSubmit","content","setContent","rating","setRating","isDark","handleSubmit","e","inputStyles","buttonStyles","jsxs","StarRating","onChange","hovered","setHovered","star","isFilled","VoteMode","buttonBase","ThumbsUpIcon","ThumbsDownIcon","GotchaModal","mode","promptText","thankYouMessage","isSubmitted","onClose","anchorRect","modalRef","useRef","firstFocusableRef","isVisible","setIsVisible","timer","showAbove","modal","handleKeyDown","focusableElements","firstElement","lastElement","defaultPrompt","modalStyles","Fragment","Gotcha","experimentId","variant","allowMultiple","showResults","position","visible","onOpen","onError","setIsSubmitted","setIsParentHovered","setAnchorRect","containerRef","container","parent","handleMouseEnter","handleMouseLeave","submit","handleOpen","handleClose","useGotcha"],"mappings":"gFACO,IAAMA,CAAAA,CAAe,0BAAA,CAerB,IAAMC,CAAAA,CAAe,CAC1B,YAAA,CAAc,qBAEhB,CAAA,CAGaC,CAAAA,CAAW,CACtB,QAAA,CAAU,WAAA,CACV,IAAA,CAAM,IAAA,CACN,MAAO,MAAA,CACP,aAAA,CAAe,IAAA,CACf,cAAA,CAAgB,iBAChB,WAAA,CAAa,QAAA,CACb,iBAAA,CAAmB,2BACrB,CAAA,CAUO,IAAMC,CAAAA,CAAe,CAC1B,YAAa,CAAA,CACb,aAAA,CAAe,GAAA,CACf,YAAA,CAAc,GAChB,CAAA,CCtCO,SAASC,CAAAA,EAAyB,CACvC,GAAI,OAAO,MAAA,CAAW,GAAA,CAEpB,OAAO,QAAQ,MAAA,CAAO,UAAA,EAAY,CAAA,CAAA,CAGpC,IAAMC,CAAAA,CAAS,YAAA,CAAa,OAAA,CAAQJ,CAAAA,CAAa,YAAY,CAAA,CAC7D,GAAII,CAAAA,CAAQ,OAAOA,EAEnB,IAAMC,CAAAA,CAAK,CAAA,KAAA,EAAQ,MAAA,CAAO,UAAA,EAAY,CAAA,CAAA,CACtC,OAAA,YAAA,CAAa,QAAQL,CAAAA,CAAa,YAAA,CAAcK,CAAE,CAAA,CAC3CA,CACT,CCFA,IAAMC,EAAAA,CAAoC,CACxC,WAAYJ,CAAAA,CAAa,WAAA,CACzB,WAAA,CAAaA,CAAAA,CAAa,cAC1B,UAAA,CAAYA,CAAAA,CAAa,YAC3B,CAAA,CAKA,eAAeK,EAAAA,CACbC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAAsBJ,GACtBK,CAAAA,CAAiB,KAAA,CACE,CACnB,IAAIC,EAA0B,IAAA,CAE9B,IAAA,IAASC,CAAAA,CAAU,CAAA,CAAGA,CAAAA,EAAW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AAA,CAAaC,CAAAA,CACb,aAAA,CAAeC,CAAAA,CACf,OAAA,CAAS8E,EAAAA,CACT,MAAA,CAAQ5E,EACR,eAAA,CAAiBC,CAAAA,CACnB,CAAA,CAECD,CAAAA,EACCvB,eAAC2D,EAAAA,CAAA,CACC,IAAA,CAAMC,CAAAA,CACN,MAAO1C,CAAAA,CACP,YAAA,CAAcC,CAAAA,CACd,UAAA,CAAY0C,EACZ,WAAA,CAAazB,CAAAA,CACb,UAAA,CAAYC,CAAAA,CACZ,gBAAiByB,CAAAA,CACjB,SAAA,CAAWzD,EAAAA,CACX,WAAA,CAAa0D,EACb,KAAA,CAAO/F,EAAAA,CACP,QAAA,CAAU4E,EAAAA,CACV,QAASwD,EAAAA,CACT,UAAA,CAAYnC,EAAAA,EAAc,MAAA,CAC5B,CAAA,CAAA,CAEJ,CAEJ,CChOO,SAASoC,IAAY,CAC1B,GAAM,CAAE,MAAA,CAAA5G,EAAQ,QAAA,CAAAL,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,MAAAzB,CAAM,CAAA,CAAIqC,CAAAA,EAAiB,CAElE,OAAO,CAEL,MAAA,CAAAR,CAAAA,CAEA,QAAA,CAAAL,EAEA,WAAA,CAAAC,CAAAA,CAEA,KAAA,CAAAzB,CAAAA,CAEA,eAAgB6B,CAAAA,CAAO,cAAA,CAAe,IAAA,CAAKA,CAAM,CACnD,CACF","file":"index.js","sourcesContent":["// API URLs\nexport const API_BASE_URL = 'https://api.gotcha.cx/v1';\nexport const API_STAGING_URL = 'https://api.staging.gotcha.cx/v1';\n\n// Error codes\nexport const ERROR_CODES = {\n INVALID_API_KEY: 'INVALID_API_KEY',\n ORIGIN_NOT_ALLOWED: 'ORIGIN_NOT_ALLOWED',\n RATE_LIMITED: 'RATE_LIMITED',\n QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',\n INVALID_REQUEST: 'INVALID_REQUEST',\n USER_NOT_FOUND: 'USER_NOT_FOUND',\n INTERNAL_ERROR: 'INTERNAL_ERROR',\n} as const;\n\n// Local storage keys\nexport const STORAGE_KEYS = {\n ANONYMOUS_ID: 'gotcha_anonymous_id',\n OFFLINE_QUEUE: 'gotcha_offline_queue',\n} as const;\n\n// Default values\nexport const DEFAULTS = {\n POSITION: 'top-right' as const,\n SIZE: 'md' as const,\n THEME: 'auto' as const,\n SHOW_ON_HOVER: true,\n TOUCH_BEHAVIOR: 'always-visible' as const,\n SUBMIT_TEXT: 'Submit',\n THANK_YOU_MESSAGE: 'Thanks for your feedback!',\n} as const;\n\n// Size mappings (desktop/mobile in pixels)\nexport const SIZE_MAP = {\n sm: { desktop: 24, mobile: 44 },\n md: { desktop: 32, mobile: 44 },\n lg: { desktop: 40, mobile: 48 },\n} as const;\n\n// Retry config\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 2,\n BASE_DELAY_MS: 500,\n MAX_DELAY_MS: 5000,\n} as const;\n","import { STORAGE_KEYS } from '../constants';\n\n/**\n * Get or create an anonymous user ID\n * Stored in localStorage for consistency across sessions\n */\nexport function getAnonymousId(): string {\n if (typeof window === 'undefined') {\n // SSR fallback - generate but don't persist\n return `anon_${crypto.randomUUID()}`;\n }\n\n const stored = localStorage.getItem(STORAGE_KEYS.ANONYMOUS_ID);\n if (stored) return stored;\n\n const id = `anon_${crypto.randomUUID()}`;\n localStorage.setItem(STORAGE_KEYS.ANONYMOUS_ID, id);\n return id;\n}\n\n/**\n * Clear the anonymous ID (useful for testing)\n */\nexport function clearAnonymousId(): void {\n if (typeof window !== 'undefined') {\n localStorage.removeItem(STORAGE_KEYS.ANONYMOUS_ID);\n }\n}\n","import { API_BASE_URL, RETRY_CONFIG } from '../constants';\nimport { SubmitResponsePayload, GotchaResponse, GotchaError } from '../types';\nimport { getAnonymousId } from '../utils/anonymous';\n\ninterface ApiClientConfig {\n apiKey: string;\n baseUrl?: string;\n debug?: boolean;\n}\n\ninterface RetryConfig {\n maxRetries: number;\n baseDelayMs: number;\n maxDelayMs: number;\n}\n\nconst DEFAULT_RETRY_CONFIG: RetryConfig = {\n maxRetries: RETRY_CONFIG.MAX_RETRIES,\n baseDelayMs: RETRY_CONFIG.BASE_DELAY_MS,\n maxDelayMs: RETRY_CONFIG.MAX_DELAY_MS,\n};\n\n/**\n * Fetch with automatic retry and exponential backoff\n */\nasync function fetchWithRetry(\n url: string,\n options: RequestInit,\n config: RetryConfig = DEFAULT_RETRY_CONFIG,\n debug: boolean = false\n): Promise<Response> {\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt <= config.maxRetries; attempt++) {\n try {\n if (debug && attempt > 0) {\n console.log(`[Gotcha] Retry attempt ${attempt}/${config.maxRetries}`);\n }\n\n const response = await fetch(url, options);\n\n // Don't retry client errors (4xx) except 429 (rate limit)\n if (response.status >= 400 && response.status < 500 && response.status !== 429) {\n return response;\n }\n\n // Success - return immediately\n if (response.ok) {\n return response;\n }\n\n lastError = new Error(`HTTP ${response.status}`);\n } catch (error) {\n // Network error - retry\n lastError = error as Error;\n if (debug) {\n console.log(`[Gotcha] Network error: ${lastError.message}`);\n }\n }\n\n // Don't delay after last attempt\n if (attempt < config.maxRetries) {\n const delay = Math.min(\n config.baseDelayMs * Math.pow(2, attempt),\n config.maxDelayMs\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw lastError;\n}\n\nexport function createApiClient(config: ApiClientConfig) {\n const { apiKey, baseUrl = API_BASE_URL, debug = false } = config;\n\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n };\n\n async function request<T>(\n method: string,\n endpoint: string,\n body?: unknown\n ): Promise<T> {\n const url = `${baseUrl}${endpoint}`;\n const idempotencyKey = crypto.randomUUID();\n\n if (debug) {\n console.log(`[Gotcha] ${method} ${endpoint}`, body);\n }\n\n const response = await fetchWithRetry(\n url,\n {\n method,\n headers: {\n ...headers,\n 'Idempotency-Key': idempotencyKey,\n },\n body: body ? JSON.stringify(body) : undefined,\n },\n DEFAULT_RETRY_CONFIG,\n debug\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n const error = data.error as GotchaError;\n if (debug) {\n console.error(`[Gotcha] Error: ${error.code} - ${error.message}`);\n }\n throw error;\n }\n\n if (debug) {\n console.log(`[Gotcha] Response:`, data);\n }\n\n return data as T;\n }\n\n return {\n /**\n * Submit a response (feedback, vote, etc.)\n */\n async submitResponse(\n payload: Omit<SubmitResponsePayload, 'context'>\n ): Promise<GotchaResponse> {\n // Ensure user has an ID (anonymous if not provided)\n const user = payload.user || {};\n if (!user.id) {\n user.id = getAnonymousId();\n }\n\n const fullPayload: SubmitResponsePayload = {\n ...payload,\n user,\n context: {\n url: typeof window !== 'undefined' ? window.location.href : undefined,\n userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,\n },\n };\n\n return request<GotchaResponse>('POST', '/responses', fullPayload);\n },\n\n /**\n * Get the base URL (for debugging)\n */\n getBaseUrl(): string {\n return baseUrl;\n },\n };\n}\n\nexport type ApiClient = ReturnType<typeof createApiClient>;\n","import React, { createContext, useContext, useMemo, useState, useCallback } from 'react';\nimport { createApiClient, ApiClient } from '../api/client';\nimport { GotchaUser } from '../types';\n\nexport interface GotchaProviderProps {\n /** Your Gotcha API key */\n apiKey: string;\n /** React children */\n children: React.ReactNode;\n /** Override the API base URL (for testing/staging) */\n baseUrl?: string;\n /** Enable debug logging */\n debug?: boolean;\n /** Disable all Gotcha buttons globally */\n disabled?: boolean;\n /** Default user metadata applied to all submissions */\n defaultUser?: GotchaUser;\n}\n\nexport interface GotchaContextValue {\n client: ApiClient;\n disabled: boolean;\n defaultUser: GotchaUser;\n debug: boolean;\n // Modal management - only one open at a time\n activeModalId: string | null;\n openModal: (elementId: string) => void;\n closeModal: () => void;\n}\n\nconst GotchaContext = createContext<GotchaContextValue | null>(null);\n\nexport function GotchaProvider({\n apiKey,\n children,\n baseUrl,\n debug = false,\n disabled = false,\n defaultUser = {},\n}: GotchaProviderProps) {\n const [activeModalId, setActiveModalId] = useState<string | null>(null);\n\n const client = useMemo(\n () => createApiClient({ apiKey, baseUrl, debug }),\n [apiKey, baseUrl, debug]\n );\n\n const openModal = useCallback((elementId: string) => {\n setActiveModalId(elementId);\n }, []);\n\n const closeModal = useCallback(() => {\n setActiveModalId(null);\n }, []);\n\n const value: GotchaContextValue = useMemo(\n () => ({\n client,\n disabled,\n defaultUser,\n debug,\n activeModalId,\n openModal,\n closeModal,\n }),\n [client, disabled, defaultUser, debug, activeModalId, openModal, closeModal]\n );\n\n return (\n <GotchaContext.Provider value={value}>{children}</GotchaContext.Provider>\n );\n}\n\nexport function useGotchaContext(): GotchaContextValue {\n const context = useContext(GotchaContext);\n if (!context) {\n throw new Error('useGotchaContext must be used within a GotchaProvider');\n }\n return context;\n}\n","import { useState, useCallback } from 'react';\nimport { useGotchaContext } from '../components/GotchaProvider';\nimport { ResponseMode, GotchaUser, GotchaResponse, VoteType } from '../types';\n\ninterface UseSubmitOptions {\n elementId: string;\n mode: ResponseMode;\n experimentId?: string;\n variant?: string;\n pollOptions?: string[];\n user?: GotchaUser;\n onSuccess?: (response: GotchaResponse) => void;\n onError?: (error: Error) => void;\n}\n\ninterface SubmitData {\n content?: string;\n title?: string;\n rating?: number;\n vote?: VoteType;\n pollSelected?: string[];\n}\n\nexport function useSubmit(options: UseSubmitOptions) {\n const { client, defaultUser } = useGotchaContext();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const submit = useCallback(\n async (data: SubmitData) => {\n setIsLoading(true);\n setError(null);\n\n try {\n const response = await client.submitResponse({\n elementId: options.elementId,\n mode: options.mode,\n content: data.content,\n title: data.title,\n rating: data.rating,\n vote: data.vote,\n pollOptions: options.pollOptions,\n pollSelected: data.pollSelected,\n experimentId: options.experimentId,\n variant: options.variant,\n user: { ...defaultUser, ...options.user },\n });\n\n options.onSuccess?.(response);\n return response;\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Something went wrong';\n setError(errorMessage);\n options.onError?.(err instanceof Error ? err : new Error(errorMessage));\n throw err;\n } finally {\n setIsLoading(false);\n }\n },\n [client, defaultUser, options]\n );\n\n return {\n submit,\n isLoading,\n error,\n clearError: () => setError(null),\n };\n}\n","/**\n * Simple class name utility\n * Combines class names, filtering out falsy values\n */\nexport function cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n","/**\n * Detect if the device supports touch\n */\nexport const isTouchDevice = (): boolean => {\n if (typeof window === 'undefined') return false;\n return 'ontouchstart' in window || navigator.maxTouchPoints > 0;\n};\n\n/**\n * Get the appropriate size based on device type\n */\nexport const getResponsiveSize = (\n size: 'sm' | 'md' | 'lg',\n isTouch: boolean\n): number => {\n const sizes = {\n sm: { desktop: 24, mobile: 44 },\n md: { desktop: 32, mobile: 44 },\n lg: { desktop: 40, mobile: 48 },\n };\n\n return isTouch ? sizes[size].mobile : sizes[size].desktop;\n};\n","import React, { useState, useEffect } from 'react';\nimport { Size, Theme, GotchaStyles } from '../types';\nimport { cn } from '../utils/cn';\nimport { isTouchDevice, getResponsiveSize } from '../utils/device';\n\nexport interface GotchaButtonProps {\n size: Size;\n theme: Theme;\n customStyles?: GotchaStyles;\n showOnHover: boolean;\n touchBehavior: 'always-visible' | 'tap-to-reveal';\n onClick: () => void;\n isOpen: boolean;\n isParentHovered?: boolean;\n}\n\nexport function GotchaButton({\n size,\n theme,\n customStyles,\n showOnHover,\n touchBehavior,\n onClick,\n isOpen,\n isParentHovered = false,\n}: GotchaButtonProps) {\n const [isTouch, setIsTouch] = useState(false);\n const [tapRevealed, setTapRevealed] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n // Determine visibility\n const shouldShow = (() => {\n // Always show if modal is open\n if (isOpen) return true;\n\n // Desktop with showOnHover: only show when parent is hovered\n if (!isTouch && showOnHover) {\n return isParentHovered;\n }\n\n // Touch device with tap-to-reveal: show only after first tap\n if (isTouch && touchBehavior === 'tap-to-reveal') {\n return tapRevealed;\n }\n\n // All other cases: always visible\n return true;\n })();\n\n const handleClick = () => {\n // For tap-to-reveal on touch: first tap reveals, second tap opens\n if (isTouch && touchBehavior === 'tap-to-reveal' && !tapRevealed) {\n setTapRevealed(true);\n return;\n }\n onClick();\n };\n\n const buttonSize = getResponsiveSize(size, isTouch);\n\n // Determine theme colors\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const baseStyles: React.CSSProperties = {\n width: buttonSize,\n height: buttonSize,\n borderRadius: '50%',\n border: 'none',\n cursor: 'pointer',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundColor: resolvedTheme === 'dark' ? '#374151' : '#c7d2dc',\n color: resolvedTheme === 'dark' ? '#e5e7eb' : '#4b5563',\n boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)',\n // CSS transition for animations\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: shouldShow ? 1 : 0,\n transform: shouldShow ? 'scale(1)' : 'scale(0.6)',\n pointerEvents: shouldShow ? 'auto' : 'none',\n ...customStyles?.button,\n };\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n style={baseStyles}\n className={cn('gotcha-button', isOpen && 'gotcha-button--open')}\n aria-label=\"Give feedback on this feature\"\n aria-expanded={isOpen}\n aria-haspopup=\"dialog\"\n >\n <GotchaIcon size={buttonSize * 0.75} />\n </button>\n );\n}\n\nfunction GotchaIcon({ size }: { size: number }) {\n return (\n <svg\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n aria-hidden=\"true\"\n >\n <text\n x=\"50%\"\n y=\"50%\"\n dominantBaseline=\"central\"\n textAnchor=\"middle\"\n fontSize=\"16\"\n fontWeight=\"bold\"\n fill=\"currentColor\"\n fontFamily=\"system-ui, -apple-system, sans-serif\"\n >\n G\n </text>\n </svg>\n );\n}\n","import React, { useState } from 'react';\nimport { GotchaStyles } from '../../types';\n\ninterface FeedbackModeProps {\n theme: 'light' | 'dark' | 'custom';\n placeholder?: string;\n submitText: string;\n isLoading: boolean;\n onSubmit: (data: { content?: string; rating?: number }) => void;\n customStyles?: GotchaStyles;\n}\n\nexport function FeedbackMode({\n theme,\n placeholder,\n submitText,\n isLoading,\n onSubmit,\n customStyles,\n}: FeedbackModeProps) {\n const [content, setContent] = useState('');\n const [rating, setRating] = useState<number | null>(null);\n\n const isDark = theme === 'dark';\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n if (!content.trim() && rating === null) return;\n onSubmit({ content: content.trim() || undefined, rating: rating ?? undefined });\n };\n\n const inputStyles: React.CSSProperties = {\n width: '100%',\n padding: '10px 12px',\n border: `1px solid ${isDark ? '#374151' : '#d1d5db'}`,\n borderRadius: 6,\n backgroundColor: isDark ? '#374151' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: 14,\n resize: 'vertical',\n minHeight: 80,\n fontFamily: 'inherit',\n ...customStyles?.input,\n };\n\n const buttonStyles: React.CSSProperties = {\n width: '100%',\n padding: '10px 16px',\n border: 'none',\n borderRadius: 6,\n backgroundColor: isLoading ? (isDark ? '#4b5563' : '#9ca3af') : '#6366f1',\n color: '#ffffff',\n fontSize: 14,\n fontWeight: 500,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'background-color 150ms ease',\n ...customStyles?.submitButton,\n };\n\n return (\n <form onSubmit={handleSubmit}>\n {/* Rating (optional) */}\n <div style={{ marginBottom: 12 }}>\n <StarRating value={rating} onChange={setRating} isDark={isDark} />\n </div>\n\n {/* Text input */}\n <textarea\n value={content}\n onChange={(e) => setContent(e.target.value)}\n placeholder={placeholder || 'Share your thoughts...'}\n style={inputStyles}\n disabled={isLoading}\n aria-label=\"Your feedback\"\n />\n\n {/* Submit button */}\n <button\n type=\"submit\"\n disabled={isLoading || (!content.trim() && rating === null)}\n style={{\n ...buttonStyles,\n marginTop: 12,\n opacity: (!content.trim() && rating === null) ? 0.5 : 1,\n }}\n >\n {isLoading ? 'Submitting...' : submitText}\n </button>\n </form>\n );\n}\n\ninterface StarRatingProps {\n value: number | null;\n onChange: (rating: number) => void;\n isDark: boolean;\n}\n\nfunction StarRating({ value, onChange, isDark }: StarRatingProps) {\n const [hovered, setHovered] = useState<number | null>(null);\n\n return (\n <div\n style={{\n display: 'flex',\n gap: 4,\n }}\n role=\"group\"\n aria-label=\"Rating\"\n >\n {[1, 2, 3, 4, 5].map((star) => {\n const isFilled = (hovered ?? value ?? 0) >= star;\n return (\n <button\n key={star}\n type=\"button\"\n onClick={() => onChange(star)}\n onMouseEnter={() => setHovered(star)}\n onMouseLeave={() => setHovered(null)}\n aria-label={`Rate ${star} out of 5`}\n aria-pressed={value === star}\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n padding: 2,\n color: isFilled ? '#f59e0b' : (isDark ? '#4b5563' : '#d1d5db'),\n transition: 'color 150ms ease',\n }}\n >\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z\" />\n </svg>\n </button>\n );\n })}\n </div>\n );\n}\n","import React from 'react';\n\ninterface VoteModeProps {\n theme: 'light' | 'dark' | 'custom';\n isLoading: boolean;\n onSubmit: (data: { vote: 'up' | 'down' }) => void;\n}\n\nexport function VoteMode({ theme, isLoading, onSubmit }: VoteModeProps) {\n const isDark = theme === 'dark';\n\n const buttonBase: React.CSSProperties = {\n flex: 1,\n padding: '12px 16px',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n borderRadius: 8,\n backgroundColor: isDark ? '#374151' : '#f9fafb',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: 24,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'all 150ms ease',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 8,\n };\n\n return (\n <div\n style={{\n display: 'flex',\n gap: 12,\n }}\n role=\"group\"\n aria-label=\"Vote\"\n >\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'up' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote up - I like this\"\n >\n <ThumbsUpIcon />\n <span style={{ fontSize: 14, fontWeight: 500 }}>Like</span>\n </button>\n\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'down' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote down - I don't like this\"\n >\n <ThumbsDownIcon />\n <span style={{ fontSize: 14, fontWeight: 500 }}>Dislike</span>\n </button>\n </div>\n );\n}\n\nfunction ThumbsUpIcon() {\n return (\n <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\" />\n </svg>\n );\n}\n\nfunction ThumbsDownIcon() {\n return (\n <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\" />\n </svg>\n );\n}\n","import React, { useRef, useEffect, useState } from 'react';\nimport { Theme, GotchaStyles, ResponseMode } from '../types';\nimport { cn } from '../utils/cn';\nimport { FeedbackMode } from './modes/FeedbackMode';\nimport { VoteMode } from './modes/VoteMode';\n\nexport interface GotchaModalProps {\n mode: ResponseMode;\n theme: Theme;\n customStyles?: GotchaStyles;\n promptText?: string;\n placeholder?: string;\n submitText: string;\n thankYouMessage: string;\n // State\n isLoading: boolean;\n isSubmitted: boolean;\n error: string | null;\n // Handlers\n onSubmit: (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => void;\n onClose: () => void;\n // Position info from parent\n anchorRect?: DOMRect;\n}\n\nexport function GotchaModal({\n mode,\n theme,\n customStyles,\n promptText,\n placeholder,\n submitText,\n thankYouMessage,\n isLoading,\n isSubmitted,\n error,\n onSubmit,\n onClose,\n anchorRect,\n}: GotchaModalProps) {\n const modalRef = useRef<HTMLDivElement>(null);\n const firstFocusableRef = useRef<HTMLButtonElement>(null);\n const [isVisible, setIsVisible] = useState(false);\n\n // Trigger animation after mount\n useEffect(() => {\n // Small delay to ensure CSS transition works\n const timer = requestAnimationFrame(() => setIsVisible(true));\n return () => cancelAnimationFrame(timer);\n }, []);\n\n // Resolve theme\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const isDark = resolvedTheme === 'dark';\n\n // Determine if modal should appear above or below\n const modalHeight = 280; // approximate modal height\n const spaceBelow = anchorRect\n ? window.innerHeight - anchorRect.bottom\n : window.innerHeight / 2;\n const showAbove = spaceBelow < modalHeight + 20;\n\n // Focus trap\n useEffect(() => {\n const modal = modalRef.current;\n if (!modal) return;\n\n // Focus first element\n firstFocusableRef.current?.focus();\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n onClose();\n return;\n }\n\n if (e.key === 'Tab') {\n const focusableElements = modal.querySelectorAll<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n );\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey && document.activeElement === firstElement) {\n e.preventDefault();\n lastElement?.focus();\n } else if (!e.shiftKey && document.activeElement === lastElement) {\n e.preventDefault();\n firstElement?.focus();\n }\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [onClose]);\n\n const defaultPrompt = mode === 'vote'\n ? 'What do you think?'\n : 'What do you think of this feature?';\n\n const modalStyles: React.CSSProperties = {\n position: 'absolute',\n left: '50%',\n width: 320,\n padding: 16,\n borderRadius: 8,\n backgroundColor: isDark ? '#1f2937' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n boxShadow: '0 10px 25px rgba(0, 0, 0, 0.15)',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n zIndex: 9999,\n ...(showAbove\n ? { bottom: '100%', marginBottom: 8 }\n : { top: '100%', marginTop: 8 }),\n // CSS transition for animations\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: isVisible ? 1 : 0,\n transform: isVisible\n ? 'translateX(-50%) scale(1) translateY(0)'\n : `translateX(-50%) scale(0.95) translateY(${showAbove ? '10px' : '-10px'})`,\n ...customStyles?.modal,\n };\n\n return (\n <div\n ref={modalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby=\"gotcha-modal-title\"\n style={modalStyles}\n className={cn('gotcha-modal', isDark && 'gotcha-modal--dark')}\n >\n {/* Close button */}\n <button\n ref={firstFocusableRef}\n type=\"button\"\n onClick={onClose}\n aria-label=\"Close feedback form\"\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n width: 24,\n height: 24,\n border: 'none',\n background: 'none',\n cursor: 'pointer',\n color: isDark ? '#9ca3af' : '#6b7280',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: 4,\n }}\n >\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\">\n <path\n d=\"M1 1L13 13M1 13L13 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n />\n </svg>\n </button>\n\n {/* Title */}\n <h2\n id=\"gotcha-modal-title\"\n style={{\n margin: '0 0 12px 0',\n fontSize: 14,\n fontWeight: 500,\n paddingRight: 24,\n }}\n >\n {promptText || defaultPrompt}\n </h2>\n\n {/* Success state */}\n {isSubmitted && (\n <div\n style={{\n textAlign: 'center',\n padding: '20px 0',\n color: isDark ? '#10b981' : '#059669',\n }}\n >\n <svg\n width=\"32\"\n height=\"32\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n style={{ margin: '0 auto 8px' }}\n >\n <path\n d=\"M20 6L9 17L4 12\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n <p style={{ margin: 0, fontSize: 14 }}>{thankYouMessage}</p>\n </div>\n )}\n\n {/* Error state */}\n {error && !isSubmitted && (\n <div\n style={{\n padding: 8,\n marginBottom: 12,\n borderRadius: 4,\n backgroundColor: isDark ? '#7f1d1d' : '#fef2f2',\n color: isDark ? '#fecaca' : '#dc2626',\n fontSize: 13,\n }}\n >\n {error}\n </div>\n )}\n\n {/* Form content based on mode */}\n {!isSubmitted && (\n <>\n {mode === 'feedback' && (\n <FeedbackMode\n theme={resolvedTheme}\n placeholder={placeholder}\n submitText={submitText}\n isLoading={isLoading}\n onSubmit={onSubmit}\n customStyles={customStyles}\n />\n )}\n {mode === 'vote' && (\n <VoteMode\n theme={resolvedTheme}\n isLoading={isLoading}\n onSubmit={onSubmit}\n />\n )}\n </>\n )}\n\n {/* Screen reader announcement */}\n <div aria-live=\"polite\" className=\"sr-only\" style={{ position: 'absolute', left: -9999 }}>\n {isSubmitted && 'Thank you! Your feedback has been submitted.'}\n {error && `Error: ${error}`}\n </div>\n </div>\n );\n}\n","import React, { useState, useCallback, useEffect, useRef } from 'react';\nimport {\n ResponseMode,\n GotchaUser,\n Position,\n Size,\n Theme,\n TouchBehavior,\n GotchaStyles,\n GotchaResponse,\n GotchaError,\n} from '../types';\nimport { DEFAULTS } from '../constants';\nimport { useGotchaContext } from './GotchaProvider';\nimport { useSubmit } from '../hooks/useSubmit';\nimport { GotchaButton } from './GotchaButton';\nimport { GotchaModal } from './GotchaModal';\n\nexport interface GotchaProps {\n /** Unique identifier for this element */\n elementId: string;\n\n // User data\n /** User metadata for segmentation */\n user?: GotchaUser;\n\n // Behavior\n /** Feedback mode */\n mode?: ResponseMode;\n /** Required if mode is 'ab' */\n experimentId?: string;\n /** Current A/B variant shown to user */\n variant?: string;\n\n // Poll mode specific (Phase 2)\n /** Required if mode is 'poll' (2-6 options) */\n options?: string[];\n /** Allow selecting multiple options */\n allowMultiple?: boolean;\n /** Show results after voting */\n showResults?: boolean;\n\n // Appearance\n /** Button position relative to parent */\n position?: Position;\n /** Button size */\n size?: Size;\n /** Color theme */\n theme?: Theme;\n /** Custom style overrides */\n customStyles?: GotchaStyles;\n /** Control visibility programmatically */\n visible?: boolean;\n /** Only show when parent is hovered (default: true) */\n showOnHover?: boolean;\n /** Mobile behavior (default: 'always-visible') */\n touchBehavior?: TouchBehavior;\n\n // Content\n /** Custom prompt text */\n promptText?: string;\n /** Input placeholder text */\n placeholder?: string;\n /** Submit button text */\n submitText?: string;\n /** Post-submission message */\n thankYouMessage?: string;\n\n // Callbacks\n /** Called after successful submission */\n onSubmit?: (response: GotchaResponse) => void;\n /** Called when modal opens */\n onOpen?: () => void;\n /** Called when modal closes */\n onClose?: () => void;\n /** Called on error */\n onError?: (error: GotchaError) => void;\n}\n\nexport function Gotcha({\n elementId,\n user,\n mode = 'feedback',\n experimentId,\n variant,\n options,\n allowMultiple = false,\n showResults = true,\n position = DEFAULTS.POSITION,\n size = DEFAULTS.SIZE,\n theme = DEFAULTS.THEME,\n customStyles,\n visible = true,\n showOnHover = DEFAULTS.SHOW_ON_HOVER,\n touchBehavior = DEFAULTS.TOUCH_BEHAVIOR,\n promptText,\n placeholder,\n submitText = DEFAULTS.SUBMIT_TEXT,\n thankYouMessage = DEFAULTS.THANK_YOU_MESSAGE,\n onSubmit,\n onOpen,\n onClose,\n onError,\n}: GotchaProps) {\n const { disabled, activeModalId, openModal, closeModal } = useGotchaContext();\n const [isSubmitted, setIsSubmitted] = useState(false);\n const [isParentHovered, setIsParentHovered] = useState(false);\n const [anchorRect, setAnchorRect] = useState<DOMRect | null>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n\n // This instance's modal is open if activeModalId matches our elementId\n const isOpen = activeModalId === elementId;\n\n // Attach hover listeners to the parent element (not the button container)\n useEffect(() => {\n if (!showOnHover) return;\n\n const container = containerRef.current;\n if (!container) return;\n\n // Find the parent element with position: relative\n const parent = container.parentElement;\n if (!parent) return;\n\n const handleMouseEnter = () => setIsParentHovered(true);\n const handleMouseLeave = () => setIsParentHovered(false);\n\n parent.addEventListener('mouseenter', handleMouseEnter);\n parent.addEventListener('mouseleave', handleMouseLeave);\n\n return () => {\n parent.removeEventListener('mouseenter', handleMouseEnter);\n parent.removeEventListener('mouseleave', handleMouseLeave);\n };\n }, [showOnHover]);\n\n const { submit, isLoading, error } = useSubmit({\n elementId,\n mode,\n experimentId,\n variant,\n pollOptions: options,\n user,\n onSuccess: (response) => {\n setIsSubmitted(true);\n onSubmit?.(response);\n // Auto-close after 2.5 seconds\n setTimeout(() => {\n closeModal();\n setIsSubmitted(false);\n }, 2500);\n },\n onError: (err) => {\n onError?.(err as unknown as GotchaError);\n },\n });\n\n const handleOpen = useCallback(() => {\n if (containerRef.current) {\n setAnchorRect(containerRef.current.getBoundingClientRect());\n }\n openModal(elementId);\n onOpen?.();\n }, [elementId, openModal, onOpen]);\n\n const handleClose = useCallback(() => {\n closeModal();\n setIsSubmitted(false);\n onClose?.();\n }, [closeModal, onClose]);\n\n const handleSubmit = useCallback(\n (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => {\n submit(data);\n },\n [submit]\n );\n\n // Don't render if disabled or not visible\n if (disabled || !visible) return null;\n\n // Position styles\n const positionStyles: Record<Position, React.CSSProperties> = {\n 'top-right': { position: 'absolute', top: 0, right: 0, transform: 'translate(50%, -50%)' },\n 'top-left': { position: 'absolute', top: 0, left: 0, transform: 'translate(-50%, -50%)' },\n 'bottom-right': { position: 'absolute', bottom: 0, right: 0, transform: 'translate(50%, 50%)' },\n 'bottom-left': { position: 'absolute', bottom: 0, left: 0, transform: 'translate(-50%, 50%)' },\n 'inline': { position: 'relative', display: 'inline-flex' },\n };\n\n return (\n <div\n ref={containerRef}\n style={{\n ...positionStyles[position],\n zIndex: isOpen ? 10000 : 50,\n }}\n className=\"gotcha-container\"\n data-gotcha-element={elementId}\n >\n <GotchaButton\n size={size}\n theme={theme}\n customStyles={customStyles}\n showOnHover={showOnHover}\n touchBehavior={touchBehavior}\n onClick={handleOpen}\n isOpen={isOpen}\n isParentHovered={isParentHovered}\n />\n\n {isOpen && (\n <GotchaModal\n mode={mode}\n theme={theme}\n customStyles={customStyles}\n promptText={promptText}\n placeholder={placeholder}\n submitText={submitText}\n thankYouMessage={thankYouMessage}\n isLoading={isLoading}\n isSubmitted={isSubmitted}\n error={error}\n onSubmit={handleSubmit}\n onClose={handleClose}\n anchorRect={anchorRect || undefined}\n />\n )}\n </div>\n );\n}\n","import { useGotchaContext } from '../components/GotchaProvider';\n\n/**\n * Hook to access Gotcha context\n * Must be used within a GotchaProvider\n */\nexport function useGotcha() {\n const { client, disabled, defaultUser, debug } = useGotchaContext();\n\n return {\n /** The API client for manual submissions */\n client,\n /** Whether Gotcha is globally disabled */\n disabled,\n /** Default user metadata */\n defaultUser,\n /** Whether debug mode is enabled */\n debug,\n /** Submit feedback programmatically */\n submitFeedback: client.submitResponse.bind(client),\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/utils/anonymous.ts","../src/api/client.ts","../src/components/GotchaProvider.tsx","../src/hooks/useSubmit.ts","../src/utils/cn.ts","../src/utils/device.ts","../src/components/GotchaButton.tsx","../src/components/modes/FeedbackMode.tsx","../src/components/modes/VoteMode.tsx","../src/components/GotchaModal.tsx","../src/components/Gotcha.tsx","../src/hooks/useGotcha.ts"],"names":["API_BASE_URL","STORAGE_KEYS","DEFAULTS","RETRY_CONFIG","getAnonymousId","stored","id","DEFAULT_RETRY_CONFIG","fetchWithRetry","url","options","config","debug","lastError","attempt","response","error","delay","resolve","createApiClient","apiKey","baseUrl","headers","request","method","endpoint","body","idempotencyKey","data","payload","user","fullPayload","GotchaContext","createContext","GotchaProvider","children","disabled","defaultUser","activeModalId","setActiveModalId","useState","client","useMemo","openModal","useCallback","elementId","closeModal","value","jsx","useGotchaContext","context","useContext","useSubmit","isLoading","setIsLoading","setError","err","errorMessage","cn","classes","isTouchDevice","getResponsiveSize","size","isTouch","sizes","GotchaButton","theme","customStyles","showOnHover","touchBehavior","onClick","isOpen","isParentHovered","setIsTouch","tapRevealed","setTapRevealed","useEffect","shouldShow","handleClick","buttonSize","resolvedTheme","baseStyles","GotchaIcon","FeedbackMode","placeholder","submitText","onSubmit","content","setContent","rating","setRating","isDark","handleSubmit","e","inputStyles","buttonStyles","jsxs","StarRating","onChange","hovered","setHovered","starSize","buttonPadding","star","isFilled","VoteMode","buttonBase","iconSize","ThumbsUpIcon","ThumbsDownIcon","GotchaModal","mode","promptText","thankYouMessage","isSubmitted","onClose","anchorRect","modalRef","useRef","firstFocusableRef","isVisible","setIsVisible","isMobile","setIsMobile","timer","showAbove","modal","handleKeyDown","focusableElements","firstElement","lastElement","defaultPrompt","modalPadding","modalStyles","Fragment","Gotcha","experimentId","variant","allowMultiple","showResults","position","visible","onOpen","onError","setIsSubmitted","setIsParentHovered","setAnchorRect","containerRef","container","parent","handleMouseEnter","handleMouseLeave","submit","handleOpen","handleClose","createPortal","useGotcha"],"mappings":"8GACO,IAAMA,EAAAA,CAAe,2BAerB,IAAMC,CAAAA,CAAe,CAC1B,YAAA,CAAc,qBAEhB,EAGaC,CAAAA,CAAW,CACtB,SAAU,WAAA,CACV,IAAA,CAAM,KACN,KAAA,CAAO,MAAA,CACP,aAAA,CAAe,IAAA,CACf,eAAgB,gBAAA,CAChB,WAAA,CAAa,SACb,iBAAA,CAAmB,2BACrB,EAUO,IAAMC,CAAAA,CAAe,CAC1B,WAAA,CAAa,EACb,aAAA,CAAe,GAAA,CACf,YAAA,CAAc,GAChB,ECtCO,SAASC,EA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Ae,IAAA,CAAKA,CAAM,CACnD,CACF","file":"index.js","sourcesContent":["// API URLs\nexport const API_BASE_URL = 'https://api.gotcha.cx/v1';\nexport const API_STAGING_URL = 'https://api.staging.gotcha.cx/v1';\n\n// Error codes\nexport const ERROR_CODES = {\n INVALID_API_KEY: 'INVALID_API_KEY',\n ORIGIN_NOT_ALLOWED: 'ORIGIN_NOT_ALLOWED',\n RATE_LIMITED: 'RATE_LIMITED',\n QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',\n INVALID_REQUEST: 'INVALID_REQUEST',\n USER_NOT_FOUND: 'USER_NOT_FOUND',\n INTERNAL_ERROR: 'INTERNAL_ERROR',\n} as const;\n\n// Local storage keys\nexport const STORAGE_KEYS = {\n ANONYMOUS_ID: 'gotcha_anonymous_id',\n OFFLINE_QUEUE: 'gotcha_offline_queue',\n} as const;\n\n// Default values\nexport const DEFAULTS = {\n POSITION: 'top-right' as const,\n SIZE: 'md' as const,\n THEME: 'auto' as const,\n SHOW_ON_HOVER: true,\n TOUCH_BEHAVIOR: 'always-visible' as const,\n SUBMIT_TEXT: 'Submit',\n THANK_YOU_MESSAGE: 'Thanks for your feedback!',\n} as const;\n\n// Size mappings (desktop/mobile in pixels)\nexport const SIZE_MAP = {\n sm: { desktop: 24, mobile: 44 },\n md: { desktop: 32, mobile: 44 },\n lg: { desktop: 40, mobile: 48 },\n} as const;\n\n// Retry config\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 2,\n BASE_DELAY_MS: 500,\n MAX_DELAY_MS: 5000,\n} as const;\n","import { STORAGE_KEYS } from '../constants';\n\n/**\n * Get or create an anonymous user ID\n * Stored in localStorage for consistency across sessions\n */\nexport function getAnonymousId(): string {\n if (typeof window === 'undefined') {\n // SSR fallback - generate but don't persist\n return `anon_${crypto.randomUUID()}`;\n }\n\n const stored = localStorage.getItem(STORAGE_KEYS.ANONYMOUS_ID);\n if (stored) return stored;\n\n const id = `anon_${crypto.randomUUID()}`;\n localStorage.setItem(STORAGE_KEYS.ANONYMOUS_ID, id);\n return id;\n}\n\n/**\n * Clear the anonymous ID (useful for testing)\n */\nexport function clearAnonymousId(): void {\n if (typeof window !== 'undefined') {\n localStorage.removeItem(STORAGE_KEYS.ANONYMOUS_ID);\n }\n}\n","import { API_BASE_URL, RETRY_CONFIG } from '../constants';\nimport { SubmitResponsePayload, GotchaResponse, GotchaError } from '../types';\nimport { getAnonymousId } from '../utils/anonymous';\n\ninterface ApiClientConfig {\n apiKey: string;\n baseUrl?: string;\n debug?: boolean;\n}\n\ninterface RetryConfig {\n maxRetries: number;\n baseDelayMs: number;\n maxDelayMs: number;\n}\n\nconst DEFAULT_RETRY_CONFIG: RetryConfig = {\n maxRetries: RETRY_CONFIG.MAX_RETRIES,\n baseDelayMs: RETRY_CONFIG.BASE_DELAY_MS,\n maxDelayMs: RETRY_CONFIG.MAX_DELAY_MS,\n};\n\n/**\n * Fetch with automatic retry and exponential backoff\n */\nasync function fetchWithRetry(\n url: string,\n options: RequestInit,\n config: RetryConfig = DEFAULT_RETRY_CONFIG,\n debug: boolean = false\n): Promise<Response> {\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt <= config.maxRetries; attempt++) {\n try {\n if (debug && attempt > 0) {\n console.log(`[Gotcha] Retry attempt ${attempt}/${config.maxRetries}`);\n }\n\n const response = await fetch(url, options);\n\n // Don't retry client errors (4xx) except 429 (rate limit)\n if (response.status >= 400 && response.status < 500 && response.status !== 429) {\n return response;\n }\n\n // Success - return immediately\n if (response.ok) {\n return response;\n }\n\n lastError = new Error(`HTTP ${response.status}`);\n } catch (error) {\n // Network error - retry\n lastError = error as Error;\n if (debug) {\n console.log(`[Gotcha] Network error: ${lastError.message}`);\n }\n }\n\n // Don't delay after last attempt\n if (attempt < config.maxRetries) {\n const delay = Math.min(\n config.baseDelayMs * Math.pow(2, attempt),\n config.maxDelayMs\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw lastError;\n}\n\nexport function createApiClient(config: ApiClientConfig) {\n const { apiKey, baseUrl = API_BASE_URL, debug = false } = config;\n\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n };\n\n async function request<T>(\n method: string,\n endpoint: string,\n body?: unknown\n ): Promise<T> {\n const url = `${baseUrl}${endpoint}`;\n const idempotencyKey = crypto.randomUUID();\n\n if (debug) {\n console.log(`[Gotcha] ${method} ${endpoint}`, body);\n }\n\n const response = await fetchWithRetry(\n url,\n {\n method,\n headers: {\n ...headers,\n 'Idempotency-Key': idempotencyKey,\n },\n body: body ? JSON.stringify(body) : undefined,\n },\n DEFAULT_RETRY_CONFIG,\n debug\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n const error = data.error as GotchaError;\n if (debug) {\n console.error(`[Gotcha] Error: ${error.code} - ${error.message}`);\n }\n throw error;\n }\n\n if (debug) {\n console.log(`[Gotcha] Response:`, data);\n }\n\n return data as T;\n }\n\n return {\n /**\n * Submit a response (feedback, vote, etc.)\n */\n async submitResponse(\n payload: Omit<SubmitResponsePayload, 'context'>\n ): Promise<GotchaResponse> {\n // Ensure user has an ID (anonymous if not provided)\n const user = payload.user || {};\n if (!user.id) {\n user.id = getAnonymousId();\n }\n\n const fullPayload: SubmitResponsePayload = {\n ...payload,\n user,\n context: {\n url: typeof window !== 'undefined' ? window.location.href : undefined,\n userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,\n },\n };\n\n return request<GotchaResponse>('POST', '/responses', fullPayload);\n },\n\n /**\n * Get the base URL (for debugging)\n */\n getBaseUrl(): string {\n return baseUrl;\n },\n };\n}\n\nexport type ApiClient = ReturnType<typeof createApiClient>;\n","import React, { createContext, useContext, useMemo, useState, useCallback } from 'react';\nimport { createApiClient, ApiClient } from '../api/client';\nimport { GotchaUser } from '../types';\n\nexport interface GotchaProviderProps {\n /** Your Gotcha API key */\n apiKey: string;\n /** React children */\n children: React.ReactNode;\n /** Override the API base URL (for testing/staging) */\n baseUrl?: string;\n /** Enable debug logging */\n debug?: boolean;\n /** Disable all Gotcha buttons globally */\n disabled?: boolean;\n /** Default user metadata applied to all submissions */\n defaultUser?: GotchaUser;\n}\n\nexport interface GotchaContextValue {\n client: ApiClient;\n disabled: boolean;\n defaultUser: GotchaUser;\n debug: boolean;\n // Modal management - only one open at a time\n activeModalId: string | null;\n openModal: (elementId: string) => void;\n closeModal: () => void;\n}\n\nconst GotchaContext = createContext<GotchaContextValue | null>(null);\n\nexport function GotchaProvider({\n apiKey,\n children,\n baseUrl,\n debug = false,\n disabled = false,\n defaultUser = {},\n}: GotchaProviderProps) {\n const [activeModalId, setActiveModalId] = useState<string | null>(null);\n\n const client = useMemo(\n () => createApiClient({ apiKey, baseUrl, debug }),\n [apiKey, baseUrl, debug]\n );\n\n const openModal = useCallback((elementId: string) => {\n setActiveModalId(elementId);\n }, []);\n\n const closeModal = useCallback(() => {\n setActiveModalId(null);\n }, []);\n\n const value: GotchaContextValue = useMemo(\n () => ({\n client,\n disabled,\n defaultUser,\n debug,\n activeModalId,\n openModal,\n closeModal,\n }),\n [client, disabled, defaultUser, debug, activeModalId, openModal, closeModal]\n );\n\n return (\n <GotchaContext.Provider value={value}>{children}</GotchaContext.Provider>\n );\n}\n\nexport function useGotchaContext(): GotchaContextValue {\n const context = useContext(GotchaContext);\n if (!context) {\n throw new Error('useGotchaContext must be used within a GotchaProvider');\n }\n return context;\n}\n","import { useState, useCallback } from 'react';\nimport { useGotchaContext } from '../components/GotchaProvider';\nimport { ResponseMode, GotchaUser, GotchaResponse, VoteType } from '../types';\n\ninterface UseSubmitOptions {\n elementId: string;\n mode: ResponseMode;\n experimentId?: string;\n variant?: string;\n pollOptions?: string[];\n user?: GotchaUser;\n onSuccess?: (response: GotchaResponse) => void;\n onError?: (error: Error) => void;\n}\n\ninterface SubmitData {\n content?: string;\n title?: string;\n rating?: number;\n vote?: VoteType;\n pollSelected?: string[];\n}\n\nexport function useSubmit(options: UseSubmitOptions) {\n const { client, defaultUser } = useGotchaContext();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const submit = useCallback(\n async (data: SubmitData) => {\n setIsLoading(true);\n setError(null);\n\n try {\n const response = await client.submitResponse({\n elementId: options.elementId,\n mode: options.mode,\n content: data.content,\n title: data.title,\n rating: data.rating,\n vote: data.vote,\n pollOptions: options.pollOptions,\n pollSelected: data.pollSelected,\n experimentId: options.experimentId,\n variant: options.variant,\n user: { ...defaultUser, ...options.user },\n });\n\n options.onSuccess?.(response);\n return response;\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Something went wrong';\n setError(errorMessage);\n options.onError?.(err instanceof Error ? err : new Error(errorMessage));\n throw err;\n } finally {\n setIsLoading(false);\n }\n },\n [client, defaultUser, options]\n );\n\n return {\n submit,\n isLoading,\n error,\n clearError: () => setError(null),\n };\n}\n","/**\n * Simple class name utility\n * Combines class names, filtering out falsy values\n */\nexport function cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n","/**\n * Detect if the device supports touch\n */\nexport const isTouchDevice = (): boolean => {\n if (typeof window === 'undefined') return false;\n return 'ontouchstart' in window || navigator.maxTouchPoints > 0;\n};\n\n/**\n * Get the appropriate size based on device type\n */\nexport const getResponsiveSize = (\n size: 'sm' | 'md' | 'lg',\n isTouch: boolean\n): number => {\n const sizes = {\n sm: { desktop: 24, mobile: 32 },\n md: { desktop: 32, mobile: 36 },\n lg: { desktop: 40, mobile: 40 },\n };\n\n return isTouch ? sizes[size].mobile : sizes[size].desktop;\n};\n","import React, { useState, useEffect } from 'react';\nimport { Size, Theme, GotchaStyles } from '../types';\nimport { cn } from '../utils/cn';\nimport { isTouchDevice, getResponsiveSize } from '../utils/device';\n\nexport interface GotchaButtonProps {\n size: Size;\n theme: Theme;\n customStyles?: GotchaStyles;\n showOnHover: boolean;\n touchBehavior: 'always-visible' | 'tap-to-reveal';\n onClick: () => void;\n isOpen: boolean;\n isParentHovered?: boolean;\n}\n\nexport function GotchaButton({\n size,\n theme,\n customStyles,\n showOnHover,\n touchBehavior,\n onClick,\n isOpen,\n isParentHovered = false,\n}: GotchaButtonProps) {\n const [isTouch, setIsTouch] = useState(false);\n const [tapRevealed, setTapRevealed] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n // Determine visibility\n const shouldShow = (() => {\n // Always show if modal is open\n if (isOpen) return true;\n\n // Desktop with showOnHover: only show when parent is hovered\n if (!isTouch && showOnHover) {\n return isParentHovered;\n }\n\n // Touch device with tap-to-reveal: show only after first tap\n if (isTouch && touchBehavior === 'tap-to-reveal') {\n return tapRevealed;\n }\n\n // All other cases: always visible\n return true;\n })();\n\n const handleClick = () => {\n // For tap-to-reveal on touch: first tap reveals, second tap opens\n if (isTouch && touchBehavior === 'tap-to-reveal' && !tapRevealed) {\n setTapRevealed(true);\n return;\n }\n onClick();\n };\n\n const buttonSize = getResponsiveSize(size, isTouch);\n\n // Determine theme colors\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const baseStyles: React.CSSProperties = {\n width: buttonSize,\n height: buttonSize,\n borderRadius: '50%',\n border: 'none',\n cursor: 'pointer',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundColor: resolvedTheme === 'dark' ? '#374151' : '#c7d2dc',\n color: resolvedTheme === 'dark' ? '#e5e7eb' : '#4b5563',\n boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)',\n // CSS transition for animations\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: shouldShow ? 1 : 0,\n transform: shouldShow ? 'scale(1)' : 'scale(0.6)',\n pointerEvents: shouldShow ? 'auto' : 'none',\n ...customStyles?.button,\n };\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n style={baseStyles}\n className={cn('gotcha-button', isOpen && 'gotcha-button--open')}\n aria-label=\"Give feedback on this feature\"\n aria-expanded={isOpen}\n aria-haspopup=\"dialog\"\n >\n <GotchaIcon size={buttonSize * 0.75} />\n </button>\n );\n}\n\nfunction GotchaIcon({ size }: { size: number }) {\n return (\n <svg\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n aria-hidden=\"true\"\n >\n <text\n x=\"50%\"\n y=\"50%\"\n dominantBaseline=\"central\"\n textAnchor=\"middle\"\n fontSize=\"16\"\n fontWeight=\"bold\"\n fill=\"currentColor\"\n fontFamily=\"system-ui, -apple-system, sans-serif\"\n >\n G\n </text>\n </svg>\n );\n}\n","import React, { useState, useEffect } from 'react';\nimport { GotchaStyles } from '../../types';\nimport { isTouchDevice } from '../../utils/device';\n\ninterface FeedbackModeProps {\n theme: 'light' | 'dark' | 'custom';\n placeholder?: string;\n submitText: string;\n isLoading: boolean;\n onSubmit: (data: { content?: string; rating?: number }) => void;\n customStyles?: GotchaStyles;\n}\n\nexport function FeedbackMode({\n theme,\n placeholder,\n submitText,\n isLoading,\n onSubmit,\n customStyles,\n}: FeedbackModeProps) {\n const [content, setContent] = useState('');\n const [rating, setRating] = useState<number | null>(null);\n const [isTouch, setIsTouch] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n const isDark = theme === 'dark';\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n if (!content.trim() && rating === null) return;\n onSubmit({ content: content.trim() || undefined, rating: rating ?? undefined });\n };\n\n const inputStyles: React.CSSProperties = {\n width: '100%',\n padding: isTouch ? '12px 14px' : '10px 12px',\n border: `1px solid ${isDark ? '#374151' : '#d1d5db'}`,\n borderRadius: isTouch ? 8 : 6,\n backgroundColor: isDark ? '#374151' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: isTouch ? 16 : 14, // 16px prevents iOS zoom on focus\n resize: 'vertical',\n minHeight: isTouch ? 100 : 80,\n fontFamily: 'inherit',\n ...customStyles?.input,\n };\n\n const buttonStyles: React.CSSProperties = {\n width: '100%',\n padding: isTouch ? '14px 16px' : '10px 16px',\n border: 'none',\n borderRadius: isTouch ? 8 : 6,\n backgroundColor: isLoading ? (isDark ? '#4b5563' : '#9ca3af') : '#6366f1',\n color: '#ffffff',\n fontSize: isTouch ? 16 : 14,\n fontWeight: 500,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'background-color 150ms ease',\n ...customStyles?.submitButton,\n };\n\n return (\n <form onSubmit={handleSubmit}>\n {/* Rating (optional) */}\n <div style={{ marginBottom: isTouch ? 16 : 12 }}>\n <StarRating value={rating} onChange={setRating} isDark={isDark} isTouch={isTouch} />\n </div>\n\n {/* Text input */}\n <textarea\n value={content}\n onChange={(e) => setContent(e.target.value)}\n placeholder={placeholder || 'Share your thoughts...'}\n style={inputStyles}\n disabled={isLoading}\n aria-label=\"Your feedback\"\n />\n\n {/* Submit button */}\n <button\n type=\"submit\"\n disabled={isLoading || (!content.trim() && rating === null)}\n style={{\n ...buttonStyles,\n marginTop: 12,\n opacity: (!content.trim() && rating === null) ? 0.5 : 1,\n }}\n >\n {isLoading ? 'Submitting...' : submitText}\n </button>\n </form>\n );\n}\n\ninterface StarRatingProps {\n value: number | null;\n onChange: (rating: number) => void;\n isDark: boolean;\n isTouch: boolean;\n}\n\nfunction StarRating({ value, onChange, isDark, isTouch }: StarRatingProps) {\n const [hovered, setHovered] = useState<number | null>(null);\n const starSize = isTouch ? 32 : 20;\n const buttonPadding = isTouch ? 6 : 2;\n\n return (\n <div\n style={{\n display: 'flex',\n gap: isTouch ? 8 : 4,\n }}\n role=\"group\"\n aria-label=\"Rating\"\n >\n {[1, 2, 3, 4, 5].map((star) => {\n const isFilled = (hovered ?? value ?? 0) >= star;\n return (\n <button\n key={star}\n type=\"button\"\n onClick={() => onChange(star)}\n onMouseEnter={() => setHovered(star)}\n onMouseLeave={() => setHovered(null)}\n aria-label={`Rate ${star} out of 5`}\n aria-pressed={value === star}\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n padding: buttonPadding,\n color: isFilled ? '#f59e0b' : (isDark ? '#4b5563' : '#d1d5db'),\n transition: 'color 150ms ease',\n }}\n >\n <svg width={starSize} height={starSize} viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z\" />\n </svg>\n </button>\n );\n })}\n </div>\n );\n}\n","import React, { useEffect, useState } from 'react';\nimport { isTouchDevice } from '../../utils/device';\n\ninterface VoteModeProps {\n theme: 'light' | 'dark' | 'custom';\n isLoading: boolean;\n onSubmit: (data: { vote: 'up' | 'down' }) => void;\n}\n\nexport function VoteMode({ theme, isLoading, onSubmit }: VoteModeProps) {\n const [isTouch, setIsTouch] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n const isDark = theme === 'dark';\n\n const buttonBase: React.CSSProperties = {\n flex: 1,\n padding: isTouch ? '16px 20px' : '12px 16px',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n borderRadius: isTouch ? 12 : 8,\n backgroundColor: isDark ? '#374151' : '#f9fafb',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: isTouch ? 28 : 24,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'all 150ms ease',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: isTouch ? 10 : 8,\n };\n\n const iconSize = isTouch ? 28 : 24;\n\n return (\n <div\n style={{\n display: 'flex',\n gap: isTouch ? 16 : 12,\n }}\n role=\"group\"\n aria-label=\"Vote\"\n >\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'up' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote up - I like this\"\n >\n <ThumbsUpIcon size={iconSize} />\n <span style={{ fontSize: isTouch ? 16 : 14, fontWeight: 500 }}>Like</span>\n </button>\n\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'down' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote down - I don't like this\"\n >\n <ThumbsDownIcon size={iconSize} />\n <span style={{ fontSize: isTouch ? 16 : 14, fontWeight: 500 }}>Dislike</span>\n </button>\n </div>\n );\n}\n\nfunction ThumbsUpIcon({ size = 24 }: { size?: number }) {\n return (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\" />\n </svg>\n );\n}\n\nfunction ThumbsDownIcon({ size = 24 }: { size?: number }) {\n return (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\" />\n </svg>\n );\n}\n","import React, { useRef, useEffect, useState } from 'react';\nimport { Theme, GotchaStyles, ResponseMode } from '../types';\nimport { cn } from '../utils/cn';\nimport { FeedbackMode } from './modes/FeedbackMode';\nimport { VoteMode } from './modes/VoteMode';\n\nexport interface GotchaModalProps {\n mode: ResponseMode;\n theme: Theme;\n customStyles?: GotchaStyles;\n promptText?: string;\n placeholder?: string;\n submitText: string;\n thankYouMessage: string;\n // State\n isLoading: boolean;\n isSubmitted: boolean;\n error: string | null;\n // Handlers\n onSubmit: (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => void;\n onClose: () => void;\n // Position info from parent\n anchorRect?: DOMRect;\n}\n\nexport function GotchaModal({\n mode,\n theme,\n customStyles,\n promptText,\n placeholder,\n submitText,\n thankYouMessage,\n isLoading,\n isSubmitted,\n error,\n onSubmit,\n onClose,\n anchorRect,\n}: GotchaModalProps) {\n const modalRef = useRef<HTMLDivElement>(null);\n const firstFocusableRef = useRef<HTMLButtonElement>(null);\n const [isVisible, setIsVisible] = useState(false);\n const [isMobile, setIsMobile] = useState(false);\n\n // Detect mobile based on screen width after mount (SSR-safe)\n useEffect(() => {\n setIsMobile(window.innerWidth < 640);\n }, []);\n\n // Trigger animation after mount\n useEffect(() => {\n const timer = requestAnimationFrame(() => setIsVisible(true));\n return () => cancelAnimationFrame(timer);\n }, []);\n\n // Resolve theme\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const isDark = resolvedTheme === 'dark';\n\n // Determine if modal should appear above or below\n const modalHeight = 280; // approximate modal height\n const spaceBelow = anchorRect\n ? window.innerHeight - anchorRect.bottom\n : window.innerHeight / 2;\n const showAbove = spaceBelow < modalHeight + 20;\n\n // Focus trap\n useEffect(() => {\n const modal = modalRef.current;\n if (!modal) return;\n\n // Focus first element\n firstFocusableRef.current?.focus();\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n onClose();\n return;\n }\n\n if (e.key === 'Tab') {\n const focusableElements = modal.querySelectorAll<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n );\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey && document.activeElement === firstElement) {\n e.preventDefault();\n lastElement?.focus();\n } else if (!e.shiftKey && document.activeElement === lastElement) {\n e.preventDefault();\n firstElement?.focus();\n }\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [onClose]);\n\n const defaultPrompt = mode === 'vote'\n ? 'What do you think?'\n : 'What do you think of this feature?';\n\n // Responsive sizing - on mobile, use fixed positioning centered on screen\n const modalPadding = isMobile ? 20 : 16;\n\n const modalStyles: React.CSSProperties = isMobile\n ? {\n // Mobile: fixed position, centered on screen\n position: 'fixed',\n left: '50%',\n top: '50%',\n width: 'calc(100vw - 32px)',\n maxWidth: 320,\n padding: modalPadding,\n borderRadius: 12,\n backgroundColor: isDark ? '#1f2937' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n boxShadow: '0 10px 25px rgba(0, 0, 0, 0.2)',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n zIndex: 9999,\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: isVisible ? 1 : 0,\n transform: isVisible\n ? 'translate(-50%, -50%) scale(1)'\n : 'translate(-50%, -50%) scale(0.95)',\n ...customStyles?.modal,\n }\n : {\n // Desktop: absolute position relative to button\n position: 'absolute',\n left: '50%',\n width: 320,\n padding: modalPadding,\n borderRadius: 8,\n backgroundColor: isDark ? '#1f2937' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n boxShadow: '0 10px 25px rgba(0, 0, 0, 0.15)',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n zIndex: 9999,\n ...(showAbove\n ? { bottom: '100%', marginBottom: 8 }\n : { top: '100%', marginTop: 8 }),\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: isVisible ? 1 : 0,\n transform: isVisible\n ? 'translateX(-50%) scale(1) translateY(0)'\n : `translateX(-50%) scale(0.95) translateY(${showAbove ? '10px' : '-10px'})`,\n ...customStyles?.modal,\n };\n\n return (\n <div\n ref={modalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby=\"gotcha-modal-title\"\n style={modalStyles}\n className={cn('gotcha-modal', isDark && 'gotcha-modal--dark')}\n >\n {/* Close button - larger on touch devices */}\n <button\n ref={firstFocusableRef}\n type=\"button\"\n onClick={onClose}\n aria-label=\"Close feedback form\"\n style={{\n position: 'absolute',\n top: isMobile ? 12 : 8,\n right: isMobile ? 12 : 8,\n width: isMobile ? 36 : 24,\n height: isMobile ? 36 : 24,\n border: 'none',\n background: 'none',\n cursor: 'pointer',\n color: isDark ? '#9ca3af' : '#6b7280',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: 4,\n }}\n >\n <svg width={isMobile ? 18 : 14} height={isMobile ? 18 : 14} viewBox=\"0 0 14 14\" fill=\"none\">\n <path\n d=\"M1 1L13 13M1 13L13 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n />\n </svg>\n </button>\n\n {/* Title */}\n <h2\n id=\"gotcha-modal-title\"\n style={{\n margin: '0 0 12px 0',\n fontSize: isMobile ? 16 : 14,\n fontWeight: 500,\n paddingRight: isMobile ? 40 : 24,\n }}\n >\n {promptText || defaultPrompt}\n </h2>\n\n {/* Success state */}\n {isSubmitted && (\n <div\n style={{\n textAlign: 'center',\n padding: '20px 0',\n color: isDark ? '#10b981' : '#059669',\n }}\n >\n <svg\n width=\"32\"\n height=\"32\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n style={{ margin: '0 auto 8px' }}\n >\n <path\n d=\"M20 6L9 17L4 12\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n <p style={{ margin: 0, fontSize: 14 }}>{thankYouMessage}</p>\n </div>\n )}\n\n {/* Error state */}\n {error && !isSubmitted && (\n <div\n style={{\n padding: 8,\n marginBottom: 12,\n borderRadius: 4,\n backgroundColor: isDark ? '#7f1d1d' : '#fef2f2',\n color: isDark ? '#fecaca' : '#dc2626',\n fontSize: 13,\n }}\n >\n {error}\n </div>\n )}\n\n {/* Form content based on mode */}\n {!isSubmitted && (\n <>\n {mode === 'feedback' && (\n <FeedbackMode\n theme={resolvedTheme}\n placeholder={placeholder}\n submitText={submitText}\n isLoading={isLoading}\n onSubmit={onSubmit}\n customStyles={customStyles}\n />\n )}\n {mode === 'vote' && (\n <VoteMode\n theme={resolvedTheme}\n isLoading={isLoading}\n onSubmit={onSubmit}\n />\n )}\n </>\n )}\n\n {/* Screen reader announcement */}\n <div aria-live=\"polite\" className=\"sr-only\" style={{ position: 'absolute', left: -9999 }}>\n {isSubmitted && 'Thank you! Your feedback has been submitted.'}\n {error && `Error: ${error}`}\n </div>\n </div>\n );\n}\n","import React, { useState, useCallback, useEffect, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport {\n ResponseMode,\n GotchaUser,\n Position,\n Size,\n Theme,\n TouchBehavior,\n GotchaStyles,\n GotchaResponse,\n GotchaError,\n} from '../types';\nimport { DEFAULTS } from '../constants';\nimport { useGotchaContext } from './GotchaProvider';\nimport { useSubmit } from '../hooks/useSubmit';\nimport { GotchaButton } from './GotchaButton';\nimport { GotchaModal } from './GotchaModal';\n\nexport interface GotchaProps {\n /** Unique identifier for this element */\n elementId: string;\n\n // User data\n /** User metadata for segmentation */\n user?: GotchaUser;\n\n // Behavior\n /** Feedback mode */\n mode?: ResponseMode;\n /** Required if mode is 'ab' */\n experimentId?: string;\n /** Current A/B variant shown to user */\n variant?: string;\n\n // Poll mode specific (Phase 2)\n /** Required if mode is 'poll' (2-6 options) */\n options?: string[];\n /** Allow selecting multiple options */\n allowMultiple?: boolean;\n /** Show results after voting */\n showResults?: boolean;\n\n // Appearance\n /** Button position relative to parent */\n position?: Position;\n /** Button size */\n size?: Size;\n /** Color theme */\n theme?: Theme;\n /** Custom style overrides */\n customStyles?: GotchaStyles;\n /** Control visibility programmatically */\n visible?: boolean;\n /** Only show when parent is hovered (default: true) */\n showOnHover?: boolean;\n /** Mobile behavior (default: 'always-visible') */\n touchBehavior?: TouchBehavior;\n\n // Content\n /** Custom prompt text */\n promptText?: string;\n /** Input placeholder text */\n placeholder?: string;\n /** Submit button text */\n submitText?: string;\n /** Post-submission message */\n thankYouMessage?: string;\n\n // Callbacks\n /** Called after successful submission */\n onSubmit?: (response: GotchaResponse) => void;\n /** Called when modal opens */\n onOpen?: () => void;\n /** Called when modal closes */\n onClose?: () => void;\n /** Called on error */\n onError?: (error: GotchaError) => void;\n}\n\nexport function Gotcha({\n elementId,\n user,\n mode = 'feedback',\n experimentId,\n variant,\n options,\n allowMultiple = false,\n showResults = true,\n position = DEFAULTS.POSITION,\n size = DEFAULTS.SIZE,\n theme = DEFAULTS.THEME,\n customStyles,\n visible = true,\n showOnHover = DEFAULTS.SHOW_ON_HOVER,\n touchBehavior = DEFAULTS.TOUCH_BEHAVIOR,\n promptText,\n placeholder,\n submitText = DEFAULTS.SUBMIT_TEXT,\n thankYouMessage = DEFAULTS.THANK_YOU_MESSAGE,\n onSubmit,\n onOpen,\n onClose,\n onError,\n}: GotchaProps) {\n const { disabled, activeModalId, openModal, closeModal } = useGotchaContext();\n const [isSubmitted, setIsSubmitted] = useState(false);\n const [isParentHovered, setIsParentHovered] = useState(false);\n const [anchorRect, setAnchorRect] = useState<DOMRect | null>(null);\n const [isMobile, setIsMobile] = useState(false);\n const containerRef = useRef<HTMLDivElement>(null);\n\n // Detect mobile for portal rendering (SSR-safe)\n useEffect(() => {\n setIsMobile(window.innerWidth < 640);\n }, []);\n\n // This instance's modal is open if activeModalId matches our elementId\n const isOpen = activeModalId === elementId;\n\n // Attach hover listeners to the parent element (not the button container)\n useEffect(() => {\n if (!showOnHover) return;\n\n const container = containerRef.current;\n if (!container) return;\n\n // Find the parent element with position: relative\n const parent = container.parentElement;\n if (!parent) return;\n\n const handleMouseEnter = () => setIsParentHovered(true);\n const handleMouseLeave = () => setIsParentHovered(false);\n\n parent.addEventListener('mouseenter', handleMouseEnter);\n parent.addEventListener('mouseleave', handleMouseLeave);\n\n return () => {\n parent.removeEventListener('mouseenter', handleMouseEnter);\n parent.removeEventListener('mouseleave', handleMouseLeave);\n };\n }, [showOnHover]);\n\n const { submit, isLoading, error } = useSubmit({\n elementId,\n mode,\n experimentId,\n variant,\n pollOptions: options,\n user,\n onSuccess: (response) => {\n setIsSubmitted(true);\n onSubmit?.(response);\n // Auto-close after 2.5 seconds\n setTimeout(() => {\n closeModal();\n setIsSubmitted(false);\n }, 2500);\n },\n onError: (err) => {\n onError?.(err as unknown as GotchaError);\n },\n });\n\n const handleOpen = useCallback(() => {\n if (containerRef.current) {\n setAnchorRect(containerRef.current.getBoundingClientRect());\n }\n openModal(elementId);\n onOpen?.();\n }, [elementId, openModal, onOpen]);\n\n const handleClose = useCallback(() => {\n closeModal();\n setIsSubmitted(false);\n onClose?.();\n }, [closeModal, onClose]);\n\n const handleSubmit = useCallback(\n (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => {\n submit(data);\n },\n [submit]\n );\n\n // Don't render if disabled or not visible\n if (disabled || !visible) return null;\n\n // Position styles\n const positionStyles: Record<Position, React.CSSProperties> = {\n 'top-right': { position: 'absolute', top: 0, right: 0, transform: 'translate(50%, -50%)' },\n 'top-left': { position: 'absolute', top: 0, left: 0, transform: 'translate(-50%, -50%)' },\n 'bottom-right': { position: 'absolute', bottom: 0, right: 0, transform: 'translate(50%, 50%)' },\n 'bottom-left': { position: 'absolute', bottom: 0, left: 0, transform: 'translate(-50%, 50%)' },\n 'inline': { position: 'relative', display: 'inline-flex' },\n };\n\n return (\n <div\n ref={containerRef}\n style={{\n ...positionStyles[position],\n zIndex: isOpen ? 10000 : 50,\n }}\n className=\"gotcha-container\"\n data-gotcha-element={elementId}\n >\n <GotchaButton\n size={size}\n theme={theme}\n customStyles={customStyles}\n showOnHover={showOnHover}\n touchBehavior={touchBehavior}\n onClick={handleOpen}\n isOpen={isOpen}\n isParentHovered={isParentHovered}\n />\n\n {isOpen && !isMobile && (\n <GotchaModal\n mode={mode}\n theme={theme}\n customStyles={customStyles}\n promptText={promptText}\n placeholder={placeholder}\n submitText={submitText}\n thankYouMessage={thankYouMessage}\n isLoading={isLoading}\n isSubmitted={isSubmitted}\n error={error}\n onSubmit={handleSubmit}\n onClose={handleClose}\n anchorRect={anchorRect || undefined}\n />\n )}\n\n {/* On mobile, render modal via portal to escape parent transform */}\n {isOpen && isMobile && createPortal(\n <div\n style={{\n position: 'fixed',\n inset: 0,\n zIndex: 99999,\n backgroundColor: 'rgba(0, 0, 0, 0.3)',\n }}\n onClick={handleClose}\n aria-hidden=\"true\"\n >\n <div onClick={(e) => e.stopPropagation()}>\n <GotchaModal\n mode={mode}\n theme={theme}\n customStyles={customStyles}\n promptText={promptText}\n placeholder={placeholder}\n submitText={submitText}\n thankYouMessage={thankYouMessage}\n isLoading={isLoading}\n isSubmitted={isSubmitted}\n error={error}\n onSubmit={handleSubmit}\n onClose={handleClose}\n anchorRect={anchorRect || undefined}\n />\n </div>\n </div>,\n document.body\n )}\n </div>\n );\n}\n","import { useGotchaContext } from '../components/GotchaProvider';\n\n/**\n * Hook to access Gotcha context\n * Must be used within a GotchaProvider\n */\nexport function useGotcha() {\n const { client, disabled, defaultUser, debug } = useGotchaContext();\n\n return {\n /** The API client for manual submissions */\n client,\n /** Whether Gotcha is globally disabled */\n disabled,\n /** Default user metadata */\n defaultUser,\n /** Whether debug mode is enabled */\n debug,\n /** Submit feedback programmatically */\n submitFeedback: client.submitResponse.bind(client),\n };\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import {createContext,useState,useMemo,useCallback,useRef,useEffect,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var j="https://api.gotcha.cx/v1";var V={ANONYMOUS_ID:"gotcha_anonymous_id"},y={POSITION:"top-right",SIZE:"md",THEME:"auto",SHOW_ON_HOVER:true,TOUCH_BEHAVIOR:"always-visible",SUBMIT_TEXT:"Submit",THANK_YOU_MESSAGE:"Thanks for your feedback!"};var P={MAX_RETRIES:2,BASE_DELAY_MS:500,MAX_DELAY_MS:5e3};function J(){if(typeof window>"u")return `anon_${crypto.randomUUID()}`;let e=localStorage.getItem(V.ANONYMOUS_ID);if(e)return e;let s=`anon_${crypto.randomUUID()}`;return localStorage.setItem(V.ANONYMOUS_ID,s),s}var ee={maxRetries:P.MAX_RETRIES,baseDelayMs:P.BASE_DELAY_MS,maxDelayMs:P.MAX_DELAY_MS};async function we(e,s,o=ee,n=false){let i=null;for(let a=0;a<=o.maxRetries;a++){try{n&&a>0&&console.log(`[Gotcha] Retry attempt ${a}/${o.maxRetries}`);let t=await fetch(e,s);if(t.status>=400&&t.status<500&&t.status!==429||t.ok)return t;i=new Error(`HTTP ${t.status}`);}catch(t){i=t,n&&console.log(`[Gotcha] Network error: ${i.message}`);}if(a<o.maxRetries){let t=Math.min(o.baseDelayMs*Math.pow(2,a),o.maxDelayMs);await new Promise(u=>setTimeout(u,t));}}throw i}function te(e){let{apiKey:s,baseUrl:o=j,debug:n=false}=e,i={"Content-Type":"application/json",Authorization:`Bearer ${s}`};async function a(t,u,r){let l=`${o}${u}`,c=crypto.randomUUID();n&&console.log(`[Gotcha] ${t} ${u}`,r);let p=await we(l,{method:t,headers:{...i,"Idempotency-Key":c},body:r?JSON.stringify(r):void 0},ee,n),d=await p.json();if(!p.ok){let m=d.error;throw n&&console.error(`[Gotcha] Error: ${m.code} - ${m.message}`),m}return n&&console.log("[Gotcha] Response:",d),d}return {async submitResponse(t){let u=t.user||{};u.id||(u.id=J());let r={...t,user:u,context:{url:typeof window<"u"?window.location.href:void 0,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}};return a("POST","/responses",r)},getBaseUrl(){return o}}}var re=createContext(null);function Me({apiKey:e,children:s,baseUrl:o,debug:n=false,disabled:i=false,defaultUser:a={}}){let[t,u]=useState(null),r=useMemo(()=>te({apiKey:e,baseUrl:o,debug:n}),[e,o,n]),l=useCallback(d=>{u(d);},[]),c=useCallback(()=>{u(null);},[]),p=useMemo(()=>({client:r,disabled:i,defaultUser:a,debug:n,activeModalId:t,openModal:l,closeModal:c}),[r,i,a,n,t,l,c]);return jsx(re.Provider,{value:p,children:s})}function T(){let e=useContext(re);if(!e)throw new Error("useGotchaContext must be used within a GotchaProvider");return e}function ae(e){let{client:s,defaultUser:o}=T(),[n,i]=useState(false),[a,t]=useState(null);return {submit:useCallback(async r=>{i(true),t(null);try{let l=await s.submitResponse({elementId:e.elementId,mode:e.mode,content:r.content,title:r.title,rating:r.rating,vote:r.vote,pollOptions:e.pollOptions,pollSelected:r.pollSelected,experimentId:e.experimentId,variant:e.variant,user:{...o,...e.user}});return e.onSuccess?.(l),l}catch(l){let c=l instanceof Error?l.message:"Something went wrong";throw t(c),e.onError?.(l instanceof Error?l:new Error(c)),l}finally{i(false);}},[s,o,e]),isLoading:n,error:a,clearError:()=>t(null)}}function D(...e){return e.filter(Boolean).join(" ")}var ie=()=>typeof window>"u"?false:"ontouchstart"in window||navigator.maxTouchPoints>0,le=(e,s)=>{let o={sm:{desktop:24,mobile:44},md:{desktop:32,mobile:44},lg:{desktop:40,mobile:48}};return s?o[e].mobile:o[e].desktop};function ue({size:e,theme:s,customStyles:o,showOnHover:n,touchBehavior:i,onClick:a,isOpen:t,isParentHovered:u=false}){let[r,l]=useState(false),[c,p]=useState(false);useEffect(()=>{l(ie());},[]);let d=t?true:!r&&n?u:r&&i==="tap-to-reveal"?c:true,m=()=>{if(r&&i==="tap-to-reveal"&&!c){p(true);return}a();},f=le(e,r),E=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,k={width:f,height:f,borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:E==="dark"?"#374151":"#c7d2dc",color:E==="dark"?"#e5e7eb":"#4b5563",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:d?1:0,transform:d?"scale(1)":"scale(0.6)",pointerEvents:d?"auto":"none",...o?.button};return jsx("button",{type:"button",onClick:m,style:k,className:D("gotcha-button",t&&"gotcha-button--open"),"aria-label":"Give feedback on this feature","aria-expanded":t,"aria-haspopup":"dialog",children:jsx(_e,{size:f*.75})})}function _e({size:e}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsx("text",{x:"50%",y:"50%",dominantBaseline:"central",textAnchor:"middle",fontSize:"16",fontWeight:"bold",fill:"currentColor",fontFamily:"system-ui, -apple-system, sans-serif",children:"G"})})}function de({theme:e,placeholder:s,submitText:o,isLoading:n,onSubmit:i,customStyles:a}){let[t,u]=useState(""),[r,l]=useState(null),c=e==="dark",p=f=>{f.preventDefault(),!(!t.trim()&&r===null)&&i({content:t.trim()||void 0,rating:r??void 0});},d={width:"100%",padding:"10px 12px",border:`1px solid ${c?"#374151":"#d1d5db"}`,borderRadius:6,backgroundColor:c?"#374151":"#ffffff",color:c?"#f9fafb":"#111827",fontSize:14,resize:"vertical",minHeight:80,fontFamily:"inherit",...a?.input},m={width:"100%",padding:"10px 16px",border:"none",borderRadius:6,backgroundColor:n?c?"#4b5563":"#9ca3af":"#6366f1",color:"#ffffff",fontSize:14,fontWeight:500,cursor:n?"not-allowed":"pointer",transition:"background-color 150ms ease",...a?.submitButton};return jsxs("form",{onSubmit:p,children:[jsx("div",{style:{marginBottom:12},children:jsx(Oe,{value:r,onChange:l,isDark:c})}),jsx("textarea",{value:t,onChange:f=>u(f.target.value),placeholder:s||"Share your thoughts...",style:d,disabled:n,"aria-label":"Your feedback"}),jsx("button",{type:"submit",disabled:n||!t.trim()&&r===null,style:{...m,marginTop:12,opacity:!t.trim()&&r===null?.5:1},children:n?"Submitting...":o})]})}function Oe({value:e,onChange:s,isDark:o}){let[n,i]=useState(null);return jsx("div",{style:{display:"flex",gap:4},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(a=>{let t=(n??e??0)>=a;return jsx("button",{type:"button",onClick:()=>s(a),onMouseEnter:()=>i(a),onMouseLeave:()=>i(null),"aria-label":`Rate ${a} out of 5`,"aria-pressed":e===a,style:{background:"none",border:"none",cursor:"pointer",padding:2,color:t?"#f59e0b":o?"#4b5563":"#d1d5db",transition:"color 150ms ease"},children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor",children:jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"})})},a)})})}function pe({theme:e,isLoading:s,onSubmit:o}){let n=e==="dark",i={flex:1,padding:"12px 16px",border:`1px solid ${n?"#374151":"#e5e7eb"}`,borderRadius:8,backgroundColor:n?"#374151":"#f9fafb",color:n?"#f9fafb":"#111827",fontSize:24,cursor:s?"not-allowed":"pointer",transition:"all 150ms ease",display:"flex",alignItems:"center",justifyContent:"center",gap:8};return jsxs("div",{style:{display:"flex",gap:12},role:"group","aria-label":"Vote",children:[jsxs("button",{type:"button",onClick:()=>o({vote:"up"}),disabled:s,style:i,"aria-label":"Vote up - I like this",children:[jsx(De,{}),jsx("span",{style:{fontSize:14,fontWeight:500},children:"Like"})]}),jsxs("button",{type:"button",onClick:()=>o({vote:"down"}),disabled:s,style:i,"aria-label":"Vote down - I don't like this",children:[jsx(Le,{}),jsx("span",{style:{fontSize:14,fontWeight:500},children:"Dislike"})]})]})}function De(){return jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}function Le(){return jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"})})}function he({mode:e,theme:s,customStyles:o,promptText:n,placeholder:i,submitText:a,thankYouMessage:t,isLoading:u,isSubmitted:r,error:l,onSubmit:c,onClose:p,anchorRect:d}){let m=useRef(null),f=useRef(null),[E,k]=useState(false);useEffect(()=>{let x=requestAnimationFrame(()=>k(true));return ()=>cancelAnimationFrame(x)},[]);let G=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,h=G==="dark",M=(d?window.innerHeight-d.bottom:window.innerHeight/2)<280+20;useEffect(()=>{let x=m.current;if(!x)return;f.current?.focus();let I=b=>{if(b.key==="Escape"){p();return}if(b.key==="Tab"){let C=x.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),w=C[0],_=C[C.length-1];b.shiftKey&&document.activeElement===w?(b.preventDefault(),_?.focus()):!b.shiftKey&&document.activeElement===_&&(b.preventDefault(),w?.focus());}};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[p]);let B=e==="vote"?"What do you think?":"What do you think of this feature?",H={position:"absolute",left:"50%",width:320,padding:16,borderRadius:8,backgroundColor:h?"#1f2937":"#ffffff",color:h?"#f9fafb":"#111827",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.15)",border:`1px solid ${h?"#374151":"#e5e7eb"}`,zIndex:9999,...M?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:E?1:0,transform:E?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.95) translateY(${M?"10px":"-10px"})`,...o?.modal};return jsxs("div",{ref:m,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:H,className:D("gotcha-modal",h&&"gotcha-modal--dark"),children:[jsx("button",{ref:f,type:"button",onClick:p,"aria-label":"Close feedback form",style:{position:"absolute",top:8,right:8,width:24,height:24,border:"none",background:"none",cursor:"pointer",color:h?"#9ca3af":"#6b7280",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}),jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 12px 0",fontSize:14,fontWeight:500,paddingRight:24},children:n||B}),r&&jsxs("div",{style:{textAlign:"center",padding:"20px 0",color:h?"#10b981":"#059669"},children:[jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",style:{margin:"0 auto 8px"},children:jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),jsx("p",{style:{margin:0,fontSize:14},children:t})]}),l&&!r&&jsx("div",{style:{padding:8,marginBottom:12,borderRadius:4,backgroundColor:h?"#7f1d1d":"#fef2f2",color:h?"#fecaca":"#dc2626",fontSize:13},children:l}),!r&&jsxs(Fragment,{children:[e==="feedback"&&jsx(de,{theme:G,placeholder:i,submitText:a,isLoading:u,onSubmit:c,customStyles:o}),e==="vote"&&jsx(pe,{theme:G,isLoading:u,onSubmit:c})]}),jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[r&&"Thank you! Your feedback has been submitted.",l&&`Error: ${l}`]})]})}function ze({elementId:e,user:s,mode:o="feedback",experimentId:n,variant:i,options:a,allowMultiple:t=false,showResults:u=true,position:r=y.POSITION,size:l=y.SIZE,theme:c=y.THEME,customStyles:p,visible:d=true,showOnHover:m=y.SHOW_ON_HOVER,touchBehavior:f=y.TOUCH_BEHAVIOR,promptText:E,placeholder:k,submitText:G=y.SUBMIT_TEXT,thankYouMessage:h=y.THANK_YOU_MESSAGE,onSubmit:K,onOpen:N,onClose:M,onError:B}){let{disabled:H,activeModalId:x,openModal:I,closeModal:b}=T(),[C,w]=useState(false),[_,X]=useState(false),[ge,ve]=useState(null),O=useRef(null),z=x===e;useEffect(()=>{if(!m)return;let v=O.current;if(!v)return;let A=v.parentElement;if(!A)return;let Q=()=>X(true),Z=()=>X(false);return A.addEventListener("mouseenter",Q),A.addEventListener("mouseleave",Z),()=>{A.removeEventListener("mouseenter",Q),A.removeEventListener("mouseleave",Z);}},[m]);let{submit:q,isLoading:ye,error:Se}=ae({elementId:e,mode:o,experimentId:n,variant:i,pollOptions:a,user:s,onSuccess:v=>{w(true),K?.(v),setTimeout(()=>{b(),w(false);},2500);},onError:v=>{B?.(v);}}),Re=useCallback(()=>{O.current&&ve(O.current.getBoundingClientRect()),I(e),N?.();},[e,I,N]),Ee=useCallback(()=>{b(),w(false),M?.();},[b,M]),xe=useCallback(v=>{q(v);},[q]);return H||!d?null:jsxs("div",{ref:O,style:{...{"top-right":{position:"absolute",top:0,right:0,transform:"translate(50%, -50%)"},"top-left":{position:"absolute",top:0,left:0,transform:"translate(-50%, -50%)"},"bottom-right":{position:"absolute",bottom:0,right:0,transform:"translate(50%, 50%)"},"bottom-left":{position:"absolute",bottom:0,left:0,transform:"translate(-50%, 50%)"},inline:{position:"relative",display:"inline-flex"}}[r],zIndex:z?1e4:50},className:"gotcha-container","data-gotcha-element":e,children:[jsx(ue,{size:l,theme:c,customStyles:p,showOnHover:m,touchBehavior:f,onClick:Re,isOpen:z,isParentHovered:_}),z&&jsx(he,{mode:o,theme:c,customStyles:p,promptText:E,placeholder:k,submitText:G,thankYouMessage:h,isLoading:ye,isSubmitted:C,error:Se,onSubmit:xe,onClose:Ee,anchorRect:ge||void 0})]})}function Ye(){let{client:e,disabled:s,defaultUser:o,debug:n}=T();return {client:e,disabled:s,defaultUser:o,debug:n,submitFeedback:e.submitResponse.bind(e)}}
2
- export{ze as Gotcha,Me as GotchaProvider,Ye as useGotcha};//# sourceMappingURL=index.mjs.map
1
+ import {createContext,useState,useMemo,useCallback,useRef,useEffect,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';var ce="https://api.gotcha.cx/v1";var Q={ANONYMOUS_ID:"gotcha_anonymous_id"},R={POSITION:"top-right",SIZE:"md",THEME:"auto",SHOW_ON_HOVER:true,TOUCH_BEHAVIOR:"always-visible",SUBMIT_TEXT:"Submit",THANK_YOU_MESSAGE:"Thanks for your feedback!"};var H={MAX_RETRIES:2,BASE_DELAY_MS:500,MAX_DELAY_MS:5e3};function de(){if(typeof window>"u")return `anon_${crypto.randomUUID()}`;let e=localStorage.getItem(Q.ANONYMOUS_ID);if(e)return e;let s=`anon_${crypto.randomUUID()}`;return localStorage.setItem(Q.ANONYMOUS_ID,s),s}var ue={maxRetries:H.MAX_RETRIES,baseDelayMs:H.BASE_DELAY_MS,maxDelayMs:H.MAX_DELAY_MS};async function Ie(e,s,r=ue,o=false){let c=null;for(let a=0;a<=r.maxRetries;a++){try{o&&a>0&&console.log(`[Gotcha] Retry attempt ${a}/${r.maxRetries}`);let t=await fetch(e,s);if(t.status>=400&&t.status<500&&t.status!==429||t.ok)return t;c=new Error(`HTTP ${t.status}`);}catch(t){c=t,o&&console.log(`[Gotcha] Network error: ${c.message}`);}if(a<r.maxRetries){let t=Math.min(r.baseDelayMs*Math.pow(2,a),r.maxDelayMs);await new Promise(d=>setTimeout(d,t));}}throw c}function pe(e){let{apiKey:s,baseUrl:r=ce,debug:o=false}=e,c={"Content-Type":"application/json",Authorization:`Bearer ${s}`};async function a(t,d,n){let l=`${r}${d}`,i=crypto.randomUUID();o&&console.log(`[Gotcha] ${t} ${d}`,n);let p=await Ie(l,{method:t,headers:{...c,"Idempotency-Key":i},body:n?JSON.stringify(n):void 0},ue,o),u=await p.json();if(!p.ok){let f=u.error;throw o&&console.error(`[Gotcha] Error: ${f.code} - ${f.message}`),f}return o&&console.log("[Gotcha] Response:",u),u}return {async submitResponse(t){let d=t.user||{};d.id||(d.id=de());let n={...t,user:d,context:{url:typeof window<"u"?window.location.href:void 0,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}};return a("POST","/responses",n)},getBaseUrl(){return r}}}var he=createContext(null);function _e({apiKey:e,children:s,baseUrl:r,debug:o=false,disabled:c=false,defaultUser:a={}}){let[t,d]=useState(null),n=useMemo(()=>pe({apiKey:e,baseUrl:r,debug:o}),[e,r,o]),l=useCallback(u=>{d(u);},[]),i=useCallback(()=>{d(null);},[]),p=useMemo(()=>({client:n,disabled:c,defaultUser:a,debug:o,activeModalId:t,openModal:l,closeModal:i}),[n,c,a,o,t,l,i]);return jsx(he.Provider,{value:p,children:s})}function I(){let e=useContext(he);if(!e)throw new Error("useGotchaContext must be used within a GotchaProvider");return e}function ge(e){let{client:s,defaultUser:r}=I(),[o,c]=useState(false),[a,t]=useState(null);return {submit:useCallback(async n=>{c(true),t(null);try{let l=await s.submitResponse({elementId:e.elementId,mode:e.mode,content:n.content,title:n.title,rating:n.rating,vote:n.vote,pollOptions:e.pollOptions,pollSelected:n.pollSelected,experimentId:e.experimentId,variant:e.variant,user:{...r,...e.user}});return e.onSuccess?.(l),l}catch(l){let i=l instanceof Error?l.message:"Something went wrong";throw t(i),e.onError?.(l instanceof Error?l:new Error(i)),l}finally{c(false);}},[s,r,e]),isLoading:o,error:a,clearError:()=>t(null)}}function V(...e){return e.filter(Boolean).join(" ")}var G=()=>typeof window>"u"?false:"ontouchstart"in window||navigator.maxTouchPoints>0,ve=(e,s)=>{let r={sm:{desktop:24,mobile:32},md:{desktop:32,mobile:36},lg:{desktop:40,mobile:40}};return s?r[e].mobile:r[e].desktop};function Se({size:e,theme:s,customStyles:r,showOnHover:o,touchBehavior:c,onClick:a,isOpen:t,isParentHovered:d=false}){let[n,l]=useState(false),[i,p]=useState(false);useEffect(()=>{l(G());},[]);let u=t?true:!n&&o?d:n&&c==="tap-to-reveal"?i:true,f=()=>{if(n&&c==="tap-to-reveal"&&!i){p(true);return}a();},g=ve(e,n),b=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,v={width:g,height:g,borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:b==="dark"?"#374151":"#c7d2dc",color:b==="dark"?"#e5e7eb":"#4b5563",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:u?1:0,transform:u?"scale(1)":"scale(0.6)",pointerEvents:u?"auto":"none",...r?.button};return jsx("button",{type:"button",onClick:f,style:v,className:V("gotcha-button",t&&"gotcha-button--open"),"aria-label":"Give feedback on this feature","aria-expanded":t,"aria-haspopup":"dialog",children:jsx(Le,{size:g*.75})})}function Le({size:e}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsx("text",{x:"50%",y:"50%",dominantBaseline:"central",textAnchor:"middle",fontSize:"16",fontWeight:"bold",fill:"currentColor",fontFamily:"system-ui, -apple-system, sans-serif",children:"G"})})}function xe({theme:e,placeholder:s,submitText:r,isLoading:o,onSubmit:c,customStyles:a}){let[t,d]=useState(""),[n,l]=useState(null),[i,p]=useState(false);useEffect(()=>{p(G());},[]);let u=e==="dark",f=v=>{v.preventDefault(),!(!t.trim()&&n===null)&&c({content:t.trim()||void 0,rating:n??void 0});},g={width:"100%",padding:i?"12px 14px":"10px 12px",border:`1px solid ${u?"#374151":"#d1d5db"}`,borderRadius:i?8:6,backgroundColor:u?"#374151":"#ffffff",color:u?"#f9fafb":"#111827",fontSize:i?16:14,resize:"vertical",minHeight:i?100:80,fontFamily:"inherit",...a?.input},b={width:"100%",padding:i?"14px 16px":"10px 16px",border:"none",borderRadius:i?8:6,backgroundColor:o?u?"#4b5563":"#9ca3af":"#6366f1",color:"#ffffff",fontSize:i?16:14,fontWeight:500,cursor:o?"not-allowed":"pointer",transition:"background-color 150ms ease",...a?.submitButton};return jsxs("form",{onSubmit:f,children:[jsx("div",{style:{marginBottom:i?16:12},children:jsx(Ne,{value:n,onChange:l,isDark:u,isTouch:i})}),jsx("textarea",{value:t,onChange:v=>d(v.target.value),placeholder:s||"Share your thoughts...",style:g,disabled:o,"aria-label":"Your feedback"}),jsx("button",{type:"submit",disabled:o||!t.trim()&&n===null,style:{...b,marginTop:12,opacity:!t.trim()&&n===null?.5:1},children:o?"Submitting...":r})]})}function Ne({value:e,onChange:s,isDark:r,isTouch:o}){let[c,a]=useState(null),t=o?32:20,d=o?6:2;return jsx("div",{style:{display:"flex",gap:o?8:4},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(n=>{let l=(c??e??0)>=n;return jsx("button",{type:"button",onClick:()=>s(n),onMouseEnter:()=>a(n),onMouseLeave:()=>a(null),"aria-label":`Rate ${n} out of 5`,"aria-pressed":e===n,style:{background:"none",border:"none",cursor:"pointer",padding:d,color:l?"#f59e0b":r?"#4b5563":"#d1d5db",transition:"color 150ms ease"},children:jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",children:jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"})})},n)})})}function Re({theme:e,isLoading:s,onSubmit:r}){let[o,c]=useState(false);useEffect(()=>{c(G());},[]);let a=e==="dark",t={flex:1,padding:o?"16px 20px":"12px 16px",border:`1px solid ${a?"#374151":"#e5e7eb"}`,borderRadius:o?12:8,backgroundColor:a?"#374151":"#f9fafb",color:a?"#f9fafb":"#111827",fontSize:o?28:24,cursor:s?"not-allowed":"pointer",transition:"all 150ms ease",display:"flex",alignItems:"center",justifyContent:"center",gap:o?10:8},d=o?28:24;return jsxs("div",{style:{display:"flex",gap:o?16:12},role:"group","aria-label":"Vote",children:[jsxs("button",{type:"button",onClick:()=>r({vote:"up"}),disabled:s,style:t,"aria-label":"Vote up - I like this",children:[jsx(Ve,{size:d}),jsx("span",{style:{fontSize:o?16:14,fontWeight:500},children:"Like"})]}),jsxs("button",{type:"button",onClick:()=>r({vote:"down"}),disabled:s,style:t,"aria-label":"Vote down - I don't like this",children:[jsx(Ye,{size:d}),jsx("span",{style:{fontSize:o?16:14,fontWeight:500},children:"Dislike"})]})]})}function Ve({size:e=24}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}function Ye({size:e=24}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"})})}function J({mode:e,theme:s,customStyles:r,promptText:o,placeholder:c,submitText:a,thankYouMessage:t,isLoading:d,isSubmitted:n,error:l,onSubmit:i,onClose:p,anchorRect:u}){let f=useRef(null),g=useRef(null),[b,v]=useState(false),[h,L]=useState(false);useEffect(()=>{L(window.innerWidth<640);},[]),useEffect(()=>{let T=requestAnimationFrame(()=>v(true));return ()=>cancelAnimationFrame(T)},[]);let C=s==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":s,m=C==="dark",U=(u?window.innerHeight-u.bottom:window.innerHeight/2)<280+20;useEffect(()=>{let T=f.current;if(!T)return;g.current?.focus();let k=x=>{if(x.key==="Escape"){p();return}if(x.key==="Tab"){let M=T.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),P=M[0],N=M[M.length-1];x.shiftKey&&document.activeElement===P?(x.preventDefault(),N?.focus()):!x.shiftKey&&document.activeElement===N&&(x.preventDefault(),P?.focus());}};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[p]);let X=e==="vote"?"What do you think?":"What do you think of this feature?",A=h?20:16,_=h?{position:"fixed",left:"50%",top:"50%",width:"calc(100vw - 32px)",maxWidth:320,padding:A,borderRadius:12,backgroundColor:m?"#1f2937":"#ffffff",color:m?"#f9fafb":"#111827",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.2)",border:`1px solid ${m?"#374151":"#e5e7eb"}`,zIndex:9999,transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:b?1:0,transform:b?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0.95)",...r?.modal}:{position:"absolute",left:"50%",width:320,padding:A,borderRadius:8,backgroundColor:m?"#1f2937":"#ffffff",color:m?"#f9fafb":"#111827",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.15)",border:`1px solid ${m?"#374151":"#e5e7eb"}`,zIndex:9999,...U?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.2s ease-out, transform 0.2s ease-out",opacity:b?1:0,transform:b?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.95) translateY(${U?"10px":"-10px"})`,...r?.modal};return jsxs("div",{ref:f,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:_,className:V("gotcha-modal",m&&"gotcha-modal--dark"),children:[jsx("button",{ref:g,type:"button",onClick:p,"aria-label":"Close feedback form",style:{position:"absolute",top:h?12:8,right:h?12:8,width:h?36:24,height:h?36:24,border:"none",background:"none",cursor:"pointer",color:m?"#9ca3af":"#6b7280",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},children:jsx("svg",{width:h?18:14,height:h?18:14,viewBox:"0 0 14 14",fill:"none",children:jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}),jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 12px 0",fontSize:h?16:14,fontWeight:500,paddingRight:h?40:24},children:o||X}),n&&jsxs("div",{style:{textAlign:"center",padding:"20px 0",color:m?"#10b981":"#059669"},children:[jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",style:{margin:"0 auto 8px"},children:jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),jsx("p",{style:{margin:0,fontSize:14},children:t})]}),l&&!n&&jsx("div",{style:{padding:8,marginBottom:12,borderRadius:4,backgroundColor:m?"#7f1d1d":"#fef2f2",color:m?"#fecaca":"#dc2626",fontSize:13},children:l}),!n&&jsxs(Fragment,{children:[e==="feedback"&&jsx(xe,{theme:C,placeholder:c,submitText:a,isLoading:d,onSubmit:i,customStyles:r}),e==="vote"&&jsx(Re,{theme:C,isLoading:d,onSubmit:i})]}),jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[n&&"Thank you! Your feedback has been submitted.",l&&`Error: ${l}`]})]})}function Ke({elementId:e,user:s,mode:r="feedback",experimentId:o,variant:c,options:a,allowMultiple:t=false,showResults:d=true,position:n=R.POSITION,size:l=R.SIZE,theme:i=R.THEME,customStyles:p,visible:u=true,showOnHover:f=R.SHOW_ON_HOVER,touchBehavior:g=R.TOUCH_BEHAVIOR,promptText:b,placeholder:v,submitText:h=R.SUBMIT_TEXT,thankYouMessage:L=R.THANK_YOU_MESSAGE,onSubmit:C,onOpen:m,onClose:K,onError:te}){let{disabled:U,activeModalId:X,openModal:A,closeModal:_}=I(),[T,k]=useState(false),[x,M]=useState(false),[P,N]=useState(null),[oe,ke]=useState(false),B=useRef(null);useEffect(()=>{ke(window.innerWidth<640);},[]);let z=X===e;useEffect(()=>{if(!f)return;let y=B.current;if(!y)return;let O=y.parentElement;if(!O)return;let ie=()=>M(true),le=()=>M(false);return O.addEventListener("mouseenter",ie),O.addEventListener("mouseleave",le),()=>{O.removeEventListener("mouseenter",ie),O.removeEventListener("mouseleave",le);}},[f]);let{submit:ne,isLoading:re,error:se}=ge({elementId:e,mode:r,experimentId:o,variant:c,pollOptions:a,user:s,onSuccess:y=>{k(true),C?.(y),setTimeout(()=>{_(),k(false);},2500);},onError:y=>{te?.(y);}}),Me=useCallback(()=>{B.current&&N(B.current.getBoundingClientRect()),A(e),m?.();},[e,A,m]),q=useCallback(()=>{_(),k(false),K?.();},[_,K]),ae=useCallback(y=>{ne(y);},[ne]);return U||!u?null:jsxs("div",{ref:B,style:{...{"top-right":{position:"absolute",top:0,right:0,transform:"translate(50%, -50%)"},"top-left":{position:"absolute",top:0,left:0,transform:"translate(-50%, -50%)"},"bottom-right":{position:"absolute",bottom:0,right:0,transform:"translate(50%, 50%)"},"bottom-left":{position:"absolute",bottom:0,left:0,transform:"translate(-50%, 50%)"},inline:{position:"relative",display:"inline-flex"}}[n],zIndex:z?1e4:50},className:"gotcha-container","data-gotcha-element":e,children:[jsx(Se,{size:l,theme:i,customStyles:p,showOnHover:f,touchBehavior:g,onClick:Me,isOpen:z,isParentHovered:x}),z&&!oe&&jsx(J,{mode:r,theme:i,customStyles:p,promptText:b,placeholder:v,submitText:h,thankYouMessage:L,isLoading:re,isSubmitted:T,error:se,onSubmit:ae,onClose:q,anchorRect:P||void 0}),z&&oe&&createPortal(jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,backgroundColor:"rgba(0, 0, 0, 0.3)"},onClick:q,"aria-hidden":"true",children:jsx("div",{onClick:y=>y.stopPropagation(),children:jsx(J,{mode:r,theme:i,customStyles:p,promptText:b,placeholder:v,submitText:h,thankYouMessage:L,isLoading:re,isSubmitted:T,error:se,onSubmit:ae,onClose:q,anchorRect:P||void 0})})}),document.body)]})}function qe(){let{client:e,disabled:s,defaultUser:r,debug:o}=I();return {client:e,disabled:s,defaultUser:r,debug:o,submitFeedback:e.submitResponse.bind(e)}}
2
+ export{Ke as Gotcha,_e as GotchaProvider,qe as useGotcha};//# sourceMappingURL=index.mjs.map
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/utils/anonymous.ts","../src/api/client.ts","../src/components/GotchaProvider.tsx","../src/hooks/useSubmit.ts","../src/utils/cn.ts","../src/utils/device.ts","../src/components/GotchaButton.tsx","../src/components/modes/FeedbackMode.tsx","../src/components/modes/VoteMode.tsx","../src/components/GotchaModal.tsx","../src/components/Gotcha.tsx","../src/hooks/useGotcha.ts"],"names":["API_BASE_URL","STORAGE_KEYS","DEFAULTS","RETRY_CONFIG","getAnonymousId","stored","id","DEFAULT_RETRY_CONFIG","fetchWithRetry","url","options","config","debug","lastError","attempt","response","error","delay","resolve","createApiClient","apiKey","baseUrl","headers","request","method","endpoint","body","idempotencyKey","data","payload","user","fullPayload","GotchaContext","createContext","GotchaProvider","children","disabled","defaultUser","activeModalId","setActiveModalId","useState","client","useMemo","openModal","useCallback","elementId","closeModal","value","jsx","useGotchaContext","context","useContext","useSubmit","isLoading","setIsLoading","setError","err","errorMessage","cn","classes","isTouchDevice","getResponsiveSize","size","isTouch","sizes","GotchaButton","theme","customStyles","showOnHover","touchBehavior","onClick","isOpen","isParentHovered","setIsTouch","tapRevealed","setTapRevealed","useEffect","shouldShow","handleClick","buttonSize","resolvedTheme","baseStyles","GotchaIcon","FeedbackMode","placeholder","submitText","onSubmit","content","setContent","rating","setRating","isDark","handleSubmit","e","inputStyles","buttonStyles","jsxs","StarRating","onChange","hovered","setHovered","star","isFilled","VoteMode","buttonBase","ThumbsUpIcon","ThumbsDownIcon","GotchaModal","mode","promptText","thankYouMessage","isSubmitted","onClose","anchorRect","modalRef","useRef","firstFocusableRef","isVisible","setIsVisible","timer","showAbove","modal","handleKeyDown","focusableElements","firstElement","lastElement","defaultPrompt","modalStyles","Fragment","Gotcha","experimentId","variant","allowMultiple","showResults","position","visible","onOpen","onError","setIsSubmitted","setIsParentHovered","setAnchorRect","containerRef","container","parent","handleMouseEnter","handleMouseLeave","submit","handleOpen","handleClose","useGotcha"],"mappings":"6IACO,IAAMA,CAAAA,CAAe,0BAAA,CAerB,IAAMC,CAAAA,CAAe,CAC1B,YAAA,CAAc,qBAEhB,CAAA,CAGaC,CAAAA,CAAW,CACtB,QAAA,CAAU,WAAA,CACV,IAAA,CAAM,IAAA,CACN,MAAO,MAAA,CACP,aAAA,CAAe,IAAA,CACf,cAAA,CAAgB,iBAChB,WAAA,CAAa,QAAA,CACb,iBAAA,CAAmB,2BACrB,CAAA,CAUO,IAAMC,CAAAA,CAAe,CAC1B,YAAa,CAAA,CACb,aAA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AAA,EAAc,MAAA,CAC5B,CAAA,CAAA,CAEJ,CAEJ,CChOO,SAASoC,IAAY,CAC1B,GAAM,CAAE,MAAA,CAAA5G,EAAQ,QAAA,CAAAL,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,MAAAzB,CAAM,CAAA,CAAIqC,CAAAA,EAAiB,CAElE,OAAO,CAEL,MAAA,CAAAR,CAAAA,CAEA,QAAA,CAAAL,EAEA,WAAA,CAAAC,CAAAA,CAEA,KAAA,CAAAzB,CAAAA,CAEA,eAAgB6B,CAAAA,CAAO,cAAA,CAAe,IAAA,CAAKA,CAAM,CACnD,CACF","file":"index.mjs","sourcesContent":["// API URLs\nexport const API_BASE_URL = 'https://api.gotcha.cx/v1';\nexport const API_STAGING_URL = 'https://api.staging.gotcha.cx/v1';\n\n// Error codes\nexport const ERROR_CODES = {\n INVALID_API_KEY: 'INVALID_API_KEY',\n ORIGIN_NOT_ALLOWED: 'ORIGIN_NOT_ALLOWED',\n RATE_LIMITED: 'RATE_LIMITED',\n QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',\n INVALID_REQUEST: 'INVALID_REQUEST',\n USER_NOT_FOUND: 'USER_NOT_FOUND',\n INTERNAL_ERROR: 'INTERNAL_ERROR',\n} as const;\n\n// Local storage keys\nexport const STORAGE_KEYS = {\n ANONYMOUS_ID: 'gotcha_anonymous_id',\n OFFLINE_QUEUE: 'gotcha_offline_queue',\n} as const;\n\n// Default values\nexport const DEFAULTS = {\n POSITION: 'top-right' as const,\n SIZE: 'md' as const,\n THEME: 'auto' as const,\n SHOW_ON_HOVER: true,\n TOUCH_BEHAVIOR: 'always-visible' as const,\n SUBMIT_TEXT: 'Submit',\n THANK_YOU_MESSAGE: 'Thanks for your feedback!',\n} as const;\n\n// Size mappings (desktop/mobile in pixels)\nexport const SIZE_MAP = {\n sm: { desktop: 24, mobile: 44 },\n md: { desktop: 32, mobile: 44 },\n lg: { desktop: 40, mobile: 48 },\n} as const;\n\n// Retry config\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 2,\n BASE_DELAY_MS: 500,\n MAX_DELAY_MS: 5000,\n} as const;\n","import { STORAGE_KEYS } from '../constants';\n\n/**\n * Get or create an anonymous user ID\n * Stored in localStorage for consistency across sessions\n */\nexport function getAnonymousId(): string {\n if (typeof window === 'undefined') {\n // SSR fallback - generate but don't persist\n return `anon_${crypto.randomUUID()}`;\n }\n\n const stored = localStorage.getItem(STORAGE_KEYS.ANONYMOUS_ID);\n if (stored) return stored;\n\n const id = `anon_${crypto.randomUUID()}`;\n localStorage.setItem(STORAGE_KEYS.ANONYMOUS_ID, id);\n return id;\n}\n\n/**\n * Clear the anonymous ID (useful for testing)\n */\nexport function clearAnonymousId(): void {\n if (typeof window !== 'undefined') {\n localStorage.removeItem(STORAGE_KEYS.ANONYMOUS_ID);\n }\n}\n","import { API_BASE_URL, RETRY_CONFIG } from '../constants';\nimport { SubmitResponsePayload, GotchaResponse, GotchaError } from '../types';\nimport { getAnonymousId } from '../utils/anonymous';\n\ninterface ApiClientConfig {\n apiKey: string;\n baseUrl?: string;\n debug?: boolean;\n}\n\ninterface RetryConfig {\n maxRetries: number;\n baseDelayMs: number;\n maxDelayMs: number;\n}\n\nconst DEFAULT_RETRY_CONFIG: RetryConfig = {\n maxRetries: RETRY_CONFIG.MAX_RETRIES,\n baseDelayMs: RETRY_CONFIG.BASE_DELAY_MS,\n maxDelayMs: RETRY_CONFIG.MAX_DELAY_MS,\n};\n\n/**\n * Fetch with automatic retry and exponential backoff\n */\nasync function fetchWithRetry(\n url: string,\n options: RequestInit,\n config: RetryConfig = DEFAULT_RETRY_CONFIG,\n debug: boolean = false\n): Promise<Response> {\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt <= config.maxRetries; attempt++) {\n try {\n if (debug && attempt > 0) {\n console.log(`[Gotcha] Retry attempt ${attempt}/${config.maxRetries}`);\n }\n\n const response = await fetch(url, options);\n\n // Don't retry client errors (4xx) except 429 (rate limit)\n if (response.status >= 400 && response.status < 500 && response.status !== 429) {\n return response;\n }\n\n // Success - return immediately\n if (response.ok) {\n return response;\n }\n\n lastError = new Error(`HTTP ${response.status}`);\n } catch (error) {\n // Network error - retry\n lastError = error as Error;\n if (debug) {\n console.log(`[Gotcha] Network error: ${lastError.message}`);\n }\n }\n\n // Don't delay after last attempt\n if (attempt < config.maxRetries) {\n const delay = Math.min(\n config.baseDelayMs * Math.pow(2, attempt),\n config.maxDelayMs\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw lastError;\n}\n\nexport function createApiClient(config: ApiClientConfig) {\n const { apiKey, baseUrl = API_BASE_URL, debug = false } = config;\n\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n };\n\n async function request<T>(\n method: string,\n endpoint: string,\n body?: unknown\n ): Promise<T> {\n const url = `${baseUrl}${endpoint}`;\n const idempotencyKey = crypto.randomUUID();\n\n if (debug) {\n console.log(`[Gotcha] ${method} ${endpoint}`, body);\n }\n\n const response = await fetchWithRetry(\n url,\n {\n method,\n headers: {\n ...headers,\n 'Idempotency-Key': idempotencyKey,\n },\n body: body ? JSON.stringify(body) : undefined,\n },\n DEFAULT_RETRY_CONFIG,\n debug\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n const error = data.error as GotchaError;\n if (debug) {\n console.error(`[Gotcha] Error: ${error.code} - ${error.message}`);\n }\n throw error;\n }\n\n if (debug) {\n console.log(`[Gotcha] Response:`, data);\n }\n\n return data as T;\n }\n\n return {\n /**\n * Submit a response (feedback, vote, etc.)\n */\n async submitResponse(\n payload: Omit<SubmitResponsePayload, 'context'>\n ): Promise<GotchaResponse> {\n // Ensure user has an ID (anonymous if not provided)\n const user = payload.user || {};\n if (!user.id) {\n user.id = getAnonymousId();\n }\n\n const fullPayload: SubmitResponsePayload = {\n ...payload,\n user,\n context: {\n url: typeof window !== 'undefined' ? window.location.href : undefined,\n userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,\n },\n };\n\n return request<GotchaResponse>('POST', '/responses', fullPayload);\n },\n\n /**\n * Get the base URL (for debugging)\n */\n getBaseUrl(): string {\n return baseUrl;\n },\n };\n}\n\nexport type ApiClient = ReturnType<typeof createApiClient>;\n","import React, { createContext, useContext, useMemo, useState, useCallback } from 'react';\nimport { createApiClient, ApiClient } from '../api/client';\nimport { GotchaUser } from '../types';\n\nexport interface GotchaProviderProps {\n /** Your Gotcha API key */\n apiKey: string;\n /** React children */\n children: React.ReactNode;\n /** Override the API base URL (for testing/staging) */\n baseUrl?: string;\n /** Enable debug logging */\n debug?: boolean;\n /** Disable all Gotcha buttons globally */\n disabled?: boolean;\n /** Default user metadata applied to all submissions */\n defaultUser?: GotchaUser;\n}\n\nexport interface GotchaContextValue {\n client: ApiClient;\n disabled: boolean;\n defaultUser: GotchaUser;\n debug: boolean;\n // Modal management - only one open at a time\n activeModalId: string | null;\n openModal: (elementId: string) => void;\n closeModal: () => void;\n}\n\nconst GotchaContext = createContext<GotchaContextValue | null>(null);\n\nexport function GotchaProvider({\n apiKey,\n children,\n baseUrl,\n debug = false,\n disabled = false,\n defaultUser = {},\n}: GotchaProviderProps) {\n const [activeModalId, setActiveModalId] = useState<string | null>(null);\n\n const client = useMemo(\n () => createApiClient({ apiKey, baseUrl, debug }),\n [apiKey, baseUrl, debug]\n );\n\n const openModal = useCallback((elementId: string) => {\n setActiveModalId(elementId);\n }, []);\n\n const closeModal = useCallback(() => {\n setActiveModalId(null);\n }, []);\n\n const value: GotchaContextValue = useMemo(\n () => ({\n client,\n disabled,\n defaultUser,\n debug,\n activeModalId,\n openModal,\n closeModal,\n }),\n [client, disabled, defaultUser, debug, activeModalId, openModal, closeModal]\n );\n\n return (\n <GotchaContext.Provider value={value}>{children}</GotchaContext.Provider>\n );\n}\n\nexport function useGotchaContext(): GotchaContextValue {\n const context = useContext(GotchaContext);\n if (!context) {\n throw new Error('useGotchaContext must be used within a GotchaProvider');\n }\n return context;\n}\n","import { useState, useCallback } from 'react';\nimport { useGotchaContext } from '../components/GotchaProvider';\nimport { ResponseMode, GotchaUser, GotchaResponse, VoteType } from '../types';\n\ninterface UseSubmitOptions {\n elementId: string;\n mode: ResponseMode;\n experimentId?: string;\n variant?: string;\n pollOptions?: string[];\n user?: GotchaUser;\n onSuccess?: (response: GotchaResponse) => void;\n onError?: (error: Error) => void;\n}\n\ninterface SubmitData {\n content?: string;\n title?: string;\n rating?: number;\n vote?: VoteType;\n pollSelected?: string[];\n}\n\nexport function useSubmit(options: UseSubmitOptions) {\n const { client, defaultUser } = useGotchaContext();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const submit = useCallback(\n async (data: SubmitData) => {\n setIsLoading(true);\n setError(null);\n\n try {\n const response = await client.submitResponse({\n elementId: options.elementId,\n mode: options.mode,\n content: data.content,\n title: data.title,\n rating: data.rating,\n vote: data.vote,\n pollOptions: options.pollOptions,\n pollSelected: data.pollSelected,\n experimentId: options.experimentId,\n variant: options.variant,\n user: { ...defaultUser, ...options.user },\n });\n\n options.onSuccess?.(response);\n return response;\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Something went wrong';\n setError(errorMessage);\n options.onError?.(err instanceof Error ? err : new Error(errorMessage));\n throw err;\n } finally {\n setIsLoading(false);\n }\n },\n [client, defaultUser, options]\n );\n\n return {\n submit,\n isLoading,\n error,\n clearError: () => setError(null),\n };\n}\n","/**\n * Simple class name utility\n * Combines class names, filtering out falsy values\n */\nexport function cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n","/**\n * Detect if the device supports touch\n */\nexport const isTouchDevice = (): boolean => {\n if (typeof window === 'undefined') return false;\n return 'ontouchstart' in window || navigator.maxTouchPoints > 0;\n};\n\n/**\n * Get the appropriate size based on device type\n */\nexport const getResponsiveSize = (\n size: 'sm' | 'md' | 'lg',\n isTouch: boolean\n): number => {\n const sizes = {\n sm: { desktop: 24, mobile: 44 },\n md: { desktop: 32, mobile: 44 },\n lg: { desktop: 40, mobile: 48 },\n };\n\n return isTouch ? sizes[size].mobile : sizes[size].desktop;\n};\n","import React, { useState, useEffect } from 'react';\nimport { Size, Theme, GotchaStyles } from '../types';\nimport { cn } from '../utils/cn';\nimport { isTouchDevice, getResponsiveSize } from '../utils/device';\n\nexport interface GotchaButtonProps {\n size: Size;\n theme: Theme;\n customStyles?: GotchaStyles;\n showOnHover: boolean;\n touchBehavior: 'always-visible' | 'tap-to-reveal';\n onClick: () => void;\n isOpen: boolean;\n isParentHovered?: boolean;\n}\n\nexport function GotchaButton({\n size,\n theme,\n customStyles,\n showOnHover,\n touchBehavior,\n onClick,\n isOpen,\n isParentHovered = false,\n}: GotchaButtonProps) {\n const [isTouch, setIsTouch] = useState(false);\n const [tapRevealed, setTapRevealed] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n // Determine visibility\n const shouldShow = (() => {\n // Always show if modal is open\n if (isOpen) return true;\n\n // Desktop with showOnHover: only show when parent is hovered\n if (!isTouch && showOnHover) {\n return isParentHovered;\n }\n\n // Touch device with tap-to-reveal: show only after first tap\n if (isTouch && touchBehavior === 'tap-to-reveal') {\n return tapRevealed;\n }\n\n // All other cases: always visible\n return true;\n })();\n\n const handleClick = () => {\n // For tap-to-reveal on touch: first tap reveals, second tap opens\n if (isTouch && touchBehavior === 'tap-to-reveal' && !tapRevealed) {\n setTapRevealed(true);\n return;\n }\n onClick();\n };\n\n const buttonSize = getResponsiveSize(size, isTouch);\n\n // Determine theme colors\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const baseStyles: React.CSSProperties = {\n width: buttonSize,\n height: buttonSize,\n borderRadius: '50%',\n border: 'none',\n cursor: 'pointer',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundColor: resolvedTheme === 'dark' ? '#374151' : '#c7d2dc',\n color: resolvedTheme === 'dark' ? '#e5e7eb' : '#4b5563',\n boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)',\n // CSS transition for animations\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: shouldShow ? 1 : 0,\n transform: shouldShow ? 'scale(1)' : 'scale(0.6)',\n pointerEvents: shouldShow ? 'auto' : 'none',\n ...customStyles?.button,\n };\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n style={baseStyles}\n className={cn('gotcha-button', isOpen && 'gotcha-button--open')}\n aria-label=\"Give feedback on this feature\"\n aria-expanded={isOpen}\n aria-haspopup=\"dialog\"\n >\n <GotchaIcon size={buttonSize * 0.75} />\n </button>\n );\n}\n\nfunction GotchaIcon({ size }: { size: number }) {\n return (\n <svg\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n aria-hidden=\"true\"\n >\n <text\n x=\"50%\"\n y=\"50%\"\n dominantBaseline=\"central\"\n textAnchor=\"middle\"\n fontSize=\"16\"\n fontWeight=\"bold\"\n fill=\"currentColor\"\n fontFamily=\"system-ui, -apple-system, sans-serif\"\n >\n G\n </text>\n </svg>\n );\n}\n","import React, { useState } from 'react';\nimport { GotchaStyles } from '../../types';\n\ninterface FeedbackModeProps {\n theme: 'light' | 'dark' | 'custom';\n placeholder?: string;\n submitText: string;\n isLoading: boolean;\n onSubmit: (data: { content?: string; rating?: number }) => void;\n customStyles?: GotchaStyles;\n}\n\nexport function FeedbackMode({\n theme,\n placeholder,\n submitText,\n isLoading,\n onSubmit,\n customStyles,\n}: FeedbackModeProps) {\n const [content, setContent] = useState('');\n const [rating, setRating] = useState<number | null>(null);\n\n const isDark = theme === 'dark';\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n if (!content.trim() && rating === null) return;\n onSubmit({ content: content.trim() || undefined, rating: rating ?? undefined });\n };\n\n const inputStyles: React.CSSProperties = {\n width: '100%',\n padding: '10px 12px',\n border: `1px solid ${isDark ? '#374151' : '#d1d5db'}`,\n borderRadius: 6,\n backgroundColor: isDark ? '#374151' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: 14,\n resize: 'vertical',\n minHeight: 80,\n fontFamily: 'inherit',\n ...customStyles?.input,\n };\n\n const buttonStyles: React.CSSProperties = {\n width: '100%',\n padding: '10px 16px',\n border: 'none',\n borderRadius: 6,\n backgroundColor: isLoading ? (isDark ? '#4b5563' : '#9ca3af') : '#6366f1',\n color: '#ffffff',\n fontSize: 14,\n fontWeight: 500,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'background-color 150ms ease',\n ...customStyles?.submitButton,\n };\n\n return (\n <form onSubmit={handleSubmit}>\n {/* Rating (optional) */}\n <div style={{ marginBottom: 12 }}>\n <StarRating value={rating} onChange={setRating} isDark={isDark} />\n </div>\n\n {/* Text input */}\n <textarea\n value={content}\n onChange={(e) => setContent(e.target.value)}\n placeholder={placeholder || 'Share your thoughts...'}\n style={inputStyles}\n disabled={isLoading}\n aria-label=\"Your feedback\"\n />\n\n {/* Submit button */}\n <button\n type=\"submit\"\n disabled={isLoading || (!content.trim() && rating === null)}\n style={{\n ...buttonStyles,\n marginTop: 12,\n opacity: (!content.trim() && rating === null) ? 0.5 : 1,\n }}\n >\n {isLoading ? 'Submitting...' : submitText}\n </button>\n </form>\n );\n}\n\ninterface StarRatingProps {\n value: number | null;\n onChange: (rating: number) => void;\n isDark: boolean;\n}\n\nfunction StarRating({ value, onChange, isDark }: StarRatingProps) {\n const [hovered, setHovered] = useState<number | null>(null);\n\n return (\n <div\n style={{\n display: 'flex',\n gap: 4,\n }}\n role=\"group\"\n aria-label=\"Rating\"\n >\n {[1, 2, 3, 4, 5].map((star) => {\n const isFilled = (hovered ?? value ?? 0) >= star;\n return (\n <button\n key={star}\n type=\"button\"\n onClick={() => onChange(star)}\n onMouseEnter={() => setHovered(star)}\n onMouseLeave={() => setHovered(null)}\n aria-label={`Rate ${star} out of 5`}\n aria-pressed={value === star}\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n padding: 2,\n color: isFilled ? '#f59e0b' : (isDark ? '#4b5563' : '#d1d5db'),\n transition: 'color 150ms ease',\n }}\n >\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z\" />\n </svg>\n </button>\n );\n })}\n </div>\n );\n}\n","import React from 'react';\n\ninterface VoteModeProps {\n theme: 'light' | 'dark' | 'custom';\n isLoading: boolean;\n onSubmit: (data: { vote: 'up' | 'down' }) => void;\n}\n\nexport function VoteMode({ theme, isLoading, onSubmit }: VoteModeProps) {\n const isDark = theme === 'dark';\n\n const buttonBase: React.CSSProperties = {\n flex: 1,\n padding: '12px 16px',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n borderRadius: 8,\n backgroundColor: isDark ? '#374151' : '#f9fafb',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: 24,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'all 150ms ease',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 8,\n };\n\n return (\n <div\n style={{\n display: 'flex',\n gap: 12,\n }}\n role=\"group\"\n aria-label=\"Vote\"\n >\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'up' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote up - I like this\"\n >\n <ThumbsUpIcon />\n <span style={{ fontSize: 14, fontWeight: 500 }}>Like</span>\n </button>\n\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'down' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote down - I don't like this\"\n >\n <ThumbsDownIcon />\n <span style={{ fontSize: 14, fontWeight: 500 }}>Dislike</span>\n </button>\n </div>\n );\n}\n\nfunction ThumbsUpIcon() {\n return (\n <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\" />\n </svg>\n );\n}\n\nfunction ThumbsDownIcon() {\n return (\n <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\" />\n </svg>\n );\n}\n","import React, { useRef, useEffect, useState } from 'react';\nimport { Theme, GotchaStyles, ResponseMode } from '../types';\nimport { cn } from '../utils/cn';\nimport { FeedbackMode } from './modes/FeedbackMode';\nimport { VoteMode } from './modes/VoteMode';\n\nexport interface GotchaModalProps {\n mode: ResponseMode;\n theme: Theme;\n customStyles?: GotchaStyles;\n promptText?: string;\n placeholder?: string;\n submitText: string;\n thankYouMessage: string;\n // State\n isLoading: boolean;\n isSubmitted: boolean;\n error: string | null;\n // Handlers\n onSubmit: (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => void;\n onClose: () => void;\n // Position info from parent\n anchorRect?: DOMRect;\n}\n\nexport function GotchaModal({\n mode,\n theme,\n customStyles,\n promptText,\n placeholder,\n submitText,\n thankYouMessage,\n isLoading,\n isSubmitted,\n error,\n onSubmit,\n onClose,\n anchorRect,\n}: GotchaModalProps) {\n const modalRef = useRef<HTMLDivElement>(null);\n const firstFocusableRef = useRef<HTMLButtonElement>(null);\n const [isVisible, setIsVisible] = useState(false);\n\n // Trigger animation after mount\n useEffect(() => {\n // Small delay to ensure CSS transition works\n const timer = requestAnimationFrame(() => setIsVisible(true));\n return () => cancelAnimationFrame(timer);\n }, []);\n\n // Resolve theme\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const isDark = resolvedTheme === 'dark';\n\n // Determine if modal should appear above or below\n const modalHeight = 280; // approximate modal height\n const spaceBelow = anchorRect\n ? window.innerHeight - anchorRect.bottom\n : window.innerHeight / 2;\n const showAbove = spaceBelow < modalHeight + 20;\n\n // Focus trap\n useEffect(() => {\n const modal = modalRef.current;\n if (!modal) return;\n\n // Focus first element\n firstFocusableRef.current?.focus();\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n onClose();\n return;\n }\n\n if (e.key === 'Tab') {\n const focusableElements = modal.querySelectorAll<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n );\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey && document.activeElement === firstElement) {\n e.preventDefault();\n lastElement?.focus();\n } else if (!e.shiftKey && document.activeElement === lastElement) {\n e.preventDefault();\n firstElement?.focus();\n }\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [onClose]);\n\n const defaultPrompt = mode === 'vote'\n ? 'What do you think?'\n : 'What do you think of this feature?';\n\n const modalStyles: React.CSSProperties = {\n position: 'absolute',\n left: '50%',\n width: 320,\n padding: 16,\n borderRadius: 8,\n backgroundColor: isDark ? '#1f2937' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n boxShadow: '0 10px 25px rgba(0, 0, 0, 0.15)',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n zIndex: 9999,\n ...(showAbove\n ? { bottom: '100%', marginBottom: 8 }\n : { top: '100%', marginTop: 8 }),\n // CSS transition for animations\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: isVisible ? 1 : 0,\n transform: isVisible\n ? 'translateX(-50%) scale(1) translateY(0)'\n : `translateX(-50%) scale(0.95) translateY(${showAbove ? '10px' : '-10px'})`,\n ...customStyles?.modal,\n };\n\n return (\n <div\n ref={modalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby=\"gotcha-modal-title\"\n style={modalStyles}\n className={cn('gotcha-modal', isDark && 'gotcha-modal--dark')}\n >\n {/* Close button */}\n <button\n ref={firstFocusableRef}\n type=\"button\"\n onClick={onClose}\n aria-label=\"Close feedback form\"\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n width: 24,\n height: 24,\n border: 'none',\n background: 'none',\n cursor: 'pointer',\n color: isDark ? '#9ca3af' : '#6b7280',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: 4,\n }}\n >\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\">\n <path\n d=\"M1 1L13 13M1 13L13 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n />\n </svg>\n </button>\n\n {/* Title */}\n <h2\n id=\"gotcha-modal-title\"\n style={{\n margin: '0 0 12px 0',\n fontSize: 14,\n fontWeight: 500,\n paddingRight: 24,\n }}\n >\n {promptText || defaultPrompt}\n </h2>\n\n {/* Success state */}\n {isSubmitted && (\n <div\n style={{\n textAlign: 'center',\n padding: '20px 0',\n color: isDark ? '#10b981' : '#059669',\n }}\n >\n <svg\n width=\"32\"\n height=\"32\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n style={{ margin: '0 auto 8px' }}\n >\n <path\n d=\"M20 6L9 17L4 12\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n <p style={{ margin: 0, fontSize: 14 }}>{thankYouMessage}</p>\n </div>\n )}\n\n {/* Error state */}\n {error && !isSubmitted && (\n <div\n style={{\n padding: 8,\n marginBottom: 12,\n borderRadius: 4,\n backgroundColor: isDark ? '#7f1d1d' : '#fef2f2',\n color: isDark ? '#fecaca' : '#dc2626',\n fontSize: 13,\n }}\n >\n {error}\n </div>\n )}\n\n {/* Form content based on mode */}\n {!isSubmitted && (\n <>\n {mode === 'feedback' && (\n <FeedbackMode\n theme={resolvedTheme}\n placeholder={placeholder}\n submitText={submitText}\n isLoading={isLoading}\n onSubmit={onSubmit}\n customStyles={customStyles}\n />\n )}\n {mode === 'vote' && (\n <VoteMode\n theme={resolvedTheme}\n isLoading={isLoading}\n onSubmit={onSubmit}\n />\n )}\n </>\n )}\n\n {/* Screen reader announcement */}\n <div aria-live=\"polite\" className=\"sr-only\" style={{ position: 'absolute', left: -9999 }}>\n {isSubmitted && 'Thank you! Your feedback has been submitted.'}\n {error && `Error: ${error}`}\n </div>\n </div>\n );\n}\n","import React, { useState, useCallback, useEffect, useRef } from 'react';\nimport {\n ResponseMode,\n GotchaUser,\n Position,\n Size,\n Theme,\n TouchBehavior,\n GotchaStyles,\n GotchaResponse,\n GotchaError,\n} from '../types';\nimport { DEFAULTS } from '../constants';\nimport { useGotchaContext } from './GotchaProvider';\nimport { useSubmit } from '../hooks/useSubmit';\nimport { GotchaButton } from './GotchaButton';\nimport { GotchaModal } from './GotchaModal';\n\nexport interface GotchaProps {\n /** Unique identifier for this element */\n elementId: string;\n\n // User data\n /** User metadata for segmentation */\n user?: GotchaUser;\n\n // Behavior\n /** Feedback mode */\n mode?: ResponseMode;\n /** Required if mode is 'ab' */\n experimentId?: string;\n /** Current A/B variant shown to user */\n variant?: string;\n\n // Poll mode specific (Phase 2)\n /** Required if mode is 'poll' (2-6 options) */\n options?: string[];\n /** Allow selecting multiple options */\n allowMultiple?: boolean;\n /** Show results after voting */\n showResults?: boolean;\n\n // Appearance\n /** Button position relative to parent */\n position?: Position;\n /** Button size */\n size?: Size;\n /** Color theme */\n theme?: Theme;\n /** Custom style overrides */\n customStyles?: GotchaStyles;\n /** Control visibility programmatically */\n visible?: boolean;\n /** Only show when parent is hovered (default: true) */\n showOnHover?: boolean;\n /** Mobile behavior (default: 'always-visible') */\n touchBehavior?: TouchBehavior;\n\n // Content\n /** Custom prompt text */\n promptText?: string;\n /** Input placeholder text */\n placeholder?: string;\n /** Submit button text */\n submitText?: string;\n /** Post-submission message */\n thankYouMessage?: string;\n\n // Callbacks\n /** Called after successful submission */\n onSubmit?: (response: GotchaResponse) => void;\n /** Called when modal opens */\n onOpen?: () => void;\n /** Called when modal closes */\n onClose?: () => void;\n /** Called on error */\n onError?: (error: GotchaError) => void;\n}\n\nexport function Gotcha({\n elementId,\n user,\n mode = 'feedback',\n experimentId,\n variant,\n options,\n allowMultiple = false,\n showResults = true,\n position = DEFAULTS.POSITION,\n size = DEFAULTS.SIZE,\n theme = DEFAULTS.THEME,\n customStyles,\n visible = true,\n showOnHover = DEFAULTS.SHOW_ON_HOVER,\n touchBehavior = DEFAULTS.TOUCH_BEHAVIOR,\n promptText,\n placeholder,\n submitText = DEFAULTS.SUBMIT_TEXT,\n thankYouMessage = DEFAULTS.THANK_YOU_MESSAGE,\n onSubmit,\n onOpen,\n onClose,\n onError,\n}: GotchaProps) {\n const { disabled, activeModalId, openModal, closeModal } = useGotchaContext();\n const [isSubmitted, setIsSubmitted] = useState(false);\n const [isParentHovered, setIsParentHovered] = useState(false);\n const [anchorRect, setAnchorRect] = useState<DOMRect | null>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n\n // This instance's modal is open if activeModalId matches our elementId\n const isOpen = activeModalId === elementId;\n\n // Attach hover listeners to the parent element (not the button container)\n useEffect(() => {\n if (!showOnHover) return;\n\n const container = containerRef.current;\n if (!container) return;\n\n // Find the parent element with position: relative\n const parent = container.parentElement;\n if (!parent) return;\n\n const handleMouseEnter = () => setIsParentHovered(true);\n const handleMouseLeave = () => setIsParentHovered(false);\n\n parent.addEventListener('mouseenter', handleMouseEnter);\n parent.addEventListener('mouseleave', handleMouseLeave);\n\n return () => {\n parent.removeEventListener('mouseenter', handleMouseEnter);\n parent.removeEventListener('mouseleave', handleMouseLeave);\n };\n }, [showOnHover]);\n\n const { submit, isLoading, error } = useSubmit({\n elementId,\n mode,\n experimentId,\n variant,\n pollOptions: options,\n user,\n onSuccess: (response) => {\n setIsSubmitted(true);\n onSubmit?.(response);\n // Auto-close after 2.5 seconds\n setTimeout(() => {\n closeModal();\n setIsSubmitted(false);\n }, 2500);\n },\n onError: (err) => {\n onError?.(err as unknown as GotchaError);\n },\n });\n\n const handleOpen = useCallback(() => {\n if (containerRef.current) {\n setAnchorRect(containerRef.current.getBoundingClientRect());\n }\n openModal(elementId);\n onOpen?.();\n }, [elementId, openModal, onOpen]);\n\n const handleClose = useCallback(() => {\n closeModal();\n setIsSubmitted(false);\n onClose?.();\n }, [closeModal, onClose]);\n\n const handleSubmit = useCallback(\n (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => {\n submit(data);\n },\n [submit]\n );\n\n // Don't render if disabled or not visible\n if (disabled || !visible) return null;\n\n // Position styles\n const positionStyles: Record<Position, React.CSSProperties> = {\n 'top-right': { position: 'absolute', top: 0, right: 0, transform: 'translate(50%, -50%)' },\n 'top-left': { position: 'absolute', top: 0, left: 0, transform: 'translate(-50%, -50%)' },\n 'bottom-right': { position: 'absolute', bottom: 0, right: 0, transform: 'translate(50%, 50%)' },\n 'bottom-left': { position: 'absolute', bottom: 0, left: 0, transform: 'translate(-50%, 50%)' },\n 'inline': { position: 'relative', display: 'inline-flex' },\n };\n\n return (\n <div\n ref={containerRef}\n style={{\n ...positionStyles[position],\n zIndex: isOpen ? 10000 : 50,\n }}\n className=\"gotcha-container\"\n data-gotcha-element={elementId}\n >\n <GotchaButton\n size={size}\n theme={theme}\n customStyles={customStyles}\n showOnHover={showOnHover}\n touchBehavior={touchBehavior}\n onClick={handleOpen}\n isOpen={isOpen}\n isParentHovered={isParentHovered}\n />\n\n {isOpen && (\n <GotchaModal\n mode={mode}\n theme={theme}\n customStyles={customStyles}\n promptText={promptText}\n placeholder={placeholder}\n submitText={submitText}\n thankYouMessage={thankYouMessage}\n isLoading={isLoading}\n isSubmitted={isSubmitted}\n error={error}\n onSubmit={handleSubmit}\n onClose={handleClose}\n anchorRect={anchorRect || undefined}\n />\n )}\n </div>\n );\n}\n","import { useGotchaContext } from '../components/GotchaProvider';\n\n/**\n * Hook to access Gotcha context\n * Must be used within a GotchaProvider\n */\nexport function useGotcha() {\n const { client, disabled, defaultUser, debug } = useGotchaContext();\n\n return {\n /** The API client for manual submissions */\n client,\n /** Whether Gotcha is globally disabled */\n disabled,\n /** Default user metadata */\n defaultUser,\n /** Whether debug mode is enabled */\n debug,\n /** Submit feedback programmatically */\n submitFeedback: client.submitResponse.bind(client),\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/utils/anonymous.ts","../src/api/client.ts","../src/components/GotchaProvider.tsx","../src/hooks/useSubmit.ts","../src/utils/cn.ts","../src/utils/device.ts","../src/components/GotchaButton.tsx","../src/components/modes/FeedbackMode.tsx","../src/components/modes/VoteMode.tsx","../src/components/GotchaModal.tsx","../src/components/Gotcha.tsx","../src/hooks/useGotcha.ts"],"names":["API_BASE_URL","STORAGE_KEYS","DEFAULTS","RETRY_CONFIG","getAnonymousId","stored","id","DEFAULT_RETRY_CONFIG","fetchWithRetry","url","options","config","debug","lastError","attempt","response","error","delay","resolve","createApiClient","apiKey","baseUrl","headers","request","method","endpoint","body","idempotencyKey","data","payload","user","fullPayload","GotchaContext","createContext","GotchaProvider","children","disabled","defaultUser","activeModalId","setActiveModalId","useState","client","useMemo","openModal","useCallback","elementId","closeModal","value","jsx","useGotchaContext","context","useContext","useSubmit","isLoading","setIsLoading","setError","err","errorMessage","cn","classes","isTouchDevice","getResponsiveSize","size","isTouch","sizes","GotchaButton","theme","customStyles","showOnHover","touchBehavior","onClick","isOpen","isParentHovered","setIsTouch","tapRevealed","setTapRevealed","useEffect","shouldShow","handleClick","buttonSize","resolvedTheme","baseStyles","GotchaIcon","FeedbackMode","placeholder","submitText","onSubmit","content","setContent","rating","setRating","isDark","handleSubmit","e","inputStyles","buttonStyles","jsxs","StarRating","onChange","hovered","setHovered","starSize","buttonPadding","star","isFilled","VoteMode","buttonBase","iconSize","ThumbsUpIcon","ThumbsDownIcon","GotchaModal","mode","promptText","thankYouMessage","isSubmitted","onClose","anchorRect","modalRef","useRef","firstFocusableRef","isVisible","setIsVisible","isMobile","setIsMobile","timer","showAbove","modal","handleKeyDown","focusableElements","firstElement","lastElement","defaultPrompt","modalPadding","modalStyles","Fragment","Gotcha","experimentId","variant","allowMultiple","showResults","position","visible","onOpen","onError","setIsSubmitted","setIsParentHovered","setAnchorRect","containerRef","container","parent","handleMouseEnter","handleMouseLeave","submit","handleOpen","handleClose","createPortal","useGotcha"],"mappings":"kLACO,IAAMA,EAAAA,CAAe,2BAerB,IAAMC,CAAAA,CAAe,CAC1B,YAAA,CAAc,qBAEhB,EAGaC,CAAAA,CAAW,CACtB,SAAU,WAAA,CACV,IAAA,CAAM,KACN,KAAA,CAAO,MAAA,CACP,aAAA,CAAe,IAAA,CACf,eAAgB,gBAAA,CAChB,WAAA,CAAa,SACb,iBAAA,CAAmB,2BACrB,EAUO,IAAMC,CAAAA,CAAe,CAC1B,WAAA,CAAa,EACb,aAAA,CAAe,GAAA,CACf,YAAA,CAAc,GAChB,ECtCO,SAASC,EAAAA,EAAyB,CACvC,GAAI,OAAO,MAAA,CAAW,GAAA,CAEpB,OAAO,CAAA,KAAA,EAAQ,MAAA,CAAO,YAAY,CAAA,CAAA,CAGpC,IAAMC,CAAAA,CAAS,aAAa,OAAA,CAAQJ,CAAAA,CAAa,YAAY,CAAA,CAC7D,GAAII,EAAQ,OAAOA,CAAAA,CAEnB,IAAMC,CAAAA,CAAK,QAAQ,MAAA,CAAO,UAAA,EAAY,CAAA,CAAA,CACtC,OAAA,YAAA,CAAa,QAAQL,CAAAA,CAAa,YAAA,CAAcK,CAAE,CAAA,CAC3CA,CACT,CCFA,IAAMC,EAAAA,CAAoC,CACxC,WAAYJ,CAAAA,CAAa,WAAA,CACzB,WAAA,CAAaA,CAAAA,CAAa,cAC1B,U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A,CAAE,iBAAgB,CACrC,QAAA,CAAA7C,IAAC8D,CAAAA,CAAA,CACC,KAAMC,CAAAA,CACN,KAAA,CAAO7C,CAAAA,CACP,YAAA,CAAcC,EACd,UAAA,CAAY6C,CAAAA,CACZ,YAAa5B,CAAAA,CACb,UAAA,CAAYC,EACZ,eAAA,CAAiB4B,CAAAA,CACjB,SAAA,CAAW5D,EAAAA,CACX,YAAa6D,CAAAA,CACb,KAAA,CAAOlG,GACP,QAAA,CAAU4E,EAAAA,CACV,QAAS8D,CAAAA,CACT,UAAA,CAAYtC,CAAAA,EAAc,MAAA,CAC5B,EACF,CAAA,CACF,CAAA,CACA,SAAS,IACX,CAAA,CAAA,CACF,CAEJ,CCxQO,SAASwC,EAAAA,EAAY,CAC1B,GAAM,CAAE,MAAA,CAAAnH,EAAQ,QAAA,CAAAL,CAAAA,CAAU,YAAAC,CAAAA,CAAa,KAAA,CAAAzB,CAAM,CAAA,CAAIqC,GAAiB,CAElE,OAAO,CAEL,MAAA,CAAAR,CAAAA,CAEA,SAAAL,CAAAA,CAEA,WAAA,CAAAC,CAAAA,CAEA,KAAA,CAAAzB,EAEA,cAAA,CAAgB6B,CAAAA,CAAO,eAAe,IAAA,CAAKA,CAAM,CACnD,CACF","file":"index.mjs","sourcesContent":["// API URLs\nexport const API_BASE_URL = 'https://api.gotcha.cx/v1';\nexport const API_STAGING_URL = 'https://api.staging.gotcha.cx/v1';\n\n// Error codes\nexport const ERROR_CODES = {\n INVALID_API_KEY: 'INVALID_API_KEY',\n ORIGIN_NOT_ALLOWED: 'ORIGIN_NOT_ALLOWED',\n RATE_LIMITED: 'RATE_LIMITED',\n QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',\n INVALID_REQUEST: 'INVALID_REQUEST',\n USER_NOT_FOUND: 'USER_NOT_FOUND',\n INTERNAL_ERROR: 'INTERNAL_ERROR',\n} as const;\n\n// Local storage keys\nexport const STORAGE_KEYS = {\n ANONYMOUS_ID: 'gotcha_anonymous_id',\n OFFLINE_QUEUE: 'gotcha_offline_queue',\n} as const;\n\n// Default values\nexport const DEFAULTS = {\n POSITION: 'top-right' as const,\n SIZE: 'md' as const,\n THEME: 'auto' as const,\n SHOW_ON_HOVER: true,\n TOUCH_BEHAVIOR: 'always-visible' as const,\n SUBMIT_TEXT: 'Submit',\n THANK_YOU_MESSAGE: 'Thanks for your feedback!',\n} as const;\n\n// Size mappings (desktop/mobile in pixels)\nexport const SIZE_MAP = {\n sm: { desktop: 24, mobile: 44 },\n md: { desktop: 32, mobile: 44 },\n lg: { desktop: 40, mobile: 48 },\n} as const;\n\n// Retry config\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 2,\n BASE_DELAY_MS: 500,\n MAX_DELAY_MS: 5000,\n} as const;\n","import { STORAGE_KEYS } from '../constants';\n\n/**\n * Get or create an anonymous user ID\n * Stored in localStorage for consistency across sessions\n */\nexport function getAnonymousId(): string {\n if (typeof window === 'undefined') {\n // SSR fallback - generate but don't persist\n return `anon_${crypto.randomUUID()}`;\n }\n\n const stored = localStorage.getItem(STORAGE_KEYS.ANONYMOUS_ID);\n if (stored) return stored;\n\n const id = `anon_${crypto.randomUUID()}`;\n localStorage.setItem(STORAGE_KEYS.ANONYMOUS_ID, id);\n return id;\n}\n\n/**\n * Clear the anonymous ID (useful for testing)\n */\nexport function clearAnonymousId(): void {\n if (typeof window !== 'undefined') {\n localStorage.removeItem(STORAGE_KEYS.ANONYMOUS_ID);\n }\n}\n","import { API_BASE_URL, RETRY_CONFIG } from '../constants';\nimport { SubmitResponsePayload, GotchaResponse, GotchaError } from '../types';\nimport { getAnonymousId } from '../utils/anonymous';\n\ninterface ApiClientConfig {\n apiKey: string;\n baseUrl?: string;\n debug?: boolean;\n}\n\ninterface RetryConfig {\n maxRetries: number;\n baseDelayMs: number;\n maxDelayMs: number;\n}\n\nconst DEFAULT_RETRY_CONFIG: RetryConfig = {\n maxRetries: RETRY_CONFIG.MAX_RETRIES,\n baseDelayMs: RETRY_CONFIG.BASE_DELAY_MS,\n maxDelayMs: RETRY_CONFIG.MAX_DELAY_MS,\n};\n\n/**\n * Fetch with automatic retry and exponential backoff\n */\nasync function fetchWithRetry(\n url: string,\n options: RequestInit,\n config: RetryConfig = DEFAULT_RETRY_CONFIG,\n debug: boolean = false\n): Promise<Response> {\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt <= config.maxRetries; attempt++) {\n try {\n if (debug && attempt > 0) {\n console.log(`[Gotcha] Retry attempt ${attempt}/${config.maxRetries}`);\n }\n\n const response = await fetch(url, options);\n\n // Don't retry client errors (4xx) except 429 (rate limit)\n if (response.status >= 400 && response.status < 500 && response.status !== 429) {\n return response;\n }\n\n // Success - return immediately\n if (response.ok) {\n return response;\n }\n\n lastError = new Error(`HTTP ${response.status}`);\n } catch (error) {\n // Network error - retry\n lastError = error as Error;\n if (debug) {\n console.log(`[Gotcha] Network error: ${lastError.message}`);\n }\n }\n\n // Don't delay after last attempt\n if (attempt < config.maxRetries) {\n const delay = Math.min(\n config.baseDelayMs * Math.pow(2, attempt),\n config.maxDelayMs\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw lastError;\n}\n\nexport function createApiClient(config: ApiClientConfig) {\n const { apiKey, baseUrl = API_BASE_URL, debug = false } = config;\n\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n };\n\n async function request<T>(\n method: string,\n endpoint: string,\n body?: unknown\n ): Promise<T> {\n const url = `${baseUrl}${endpoint}`;\n const idempotencyKey = crypto.randomUUID();\n\n if (debug) {\n console.log(`[Gotcha] ${method} ${endpoint}`, body);\n }\n\n const response = await fetchWithRetry(\n url,\n {\n method,\n headers: {\n ...headers,\n 'Idempotency-Key': idempotencyKey,\n },\n body: body ? JSON.stringify(body) : undefined,\n },\n DEFAULT_RETRY_CONFIG,\n debug\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n const error = data.error as GotchaError;\n if (debug) {\n console.error(`[Gotcha] Error: ${error.code} - ${error.message}`);\n }\n throw error;\n }\n\n if (debug) {\n console.log(`[Gotcha] Response:`, data);\n }\n\n return data as T;\n }\n\n return {\n /**\n * Submit a response (feedback, vote, etc.)\n */\n async submitResponse(\n payload: Omit<SubmitResponsePayload, 'context'>\n ): Promise<GotchaResponse> {\n // Ensure user has an ID (anonymous if not provided)\n const user = payload.user || {};\n if (!user.id) {\n user.id = getAnonymousId();\n }\n\n const fullPayload: SubmitResponsePayload = {\n ...payload,\n user,\n context: {\n url: typeof window !== 'undefined' ? window.location.href : undefined,\n userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,\n },\n };\n\n return request<GotchaResponse>('POST', '/responses', fullPayload);\n },\n\n /**\n * Get the base URL (for debugging)\n */\n getBaseUrl(): string {\n return baseUrl;\n },\n };\n}\n\nexport type ApiClient = ReturnType<typeof createApiClient>;\n","import React, { createContext, useContext, useMemo, useState, useCallback } from 'react';\nimport { createApiClient, ApiClient } from '../api/client';\nimport { GotchaUser } from '../types';\n\nexport interface GotchaProviderProps {\n /** Your Gotcha API key */\n apiKey: string;\n /** React children */\n children: React.ReactNode;\n /** Override the API base URL (for testing/staging) */\n baseUrl?: string;\n /** Enable debug logging */\n debug?: boolean;\n /** Disable all Gotcha buttons globally */\n disabled?: boolean;\n /** Default user metadata applied to all submissions */\n defaultUser?: GotchaUser;\n}\n\nexport interface GotchaContextValue {\n client: ApiClient;\n disabled: boolean;\n defaultUser: GotchaUser;\n debug: boolean;\n // Modal management - only one open at a time\n activeModalId: string | null;\n openModal: (elementId: string) => void;\n closeModal: () => void;\n}\n\nconst GotchaContext = createContext<GotchaContextValue | null>(null);\n\nexport function GotchaProvider({\n apiKey,\n children,\n baseUrl,\n debug = false,\n disabled = false,\n defaultUser = {},\n}: GotchaProviderProps) {\n const [activeModalId, setActiveModalId] = useState<string | null>(null);\n\n const client = useMemo(\n () => createApiClient({ apiKey, baseUrl, debug }),\n [apiKey, baseUrl, debug]\n );\n\n const openModal = useCallback((elementId: string) => {\n setActiveModalId(elementId);\n }, []);\n\n const closeModal = useCallback(() => {\n setActiveModalId(null);\n }, []);\n\n const value: GotchaContextValue = useMemo(\n () => ({\n client,\n disabled,\n defaultUser,\n debug,\n activeModalId,\n openModal,\n closeModal,\n }),\n [client, disabled, defaultUser, debug, activeModalId, openModal, closeModal]\n );\n\n return (\n <GotchaContext.Provider value={value}>{children}</GotchaContext.Provider>\n );\n}\n\nexport function useGotchaContext(): GotchaContextValue {\n const context = useContext(GotchaContext);\n if (!context) {\n throw new Error('useGotchaContext must be used within a GotchaProvider');\n }\n return context;\n}\n","import { useState, useCallback } from 'react';\nimport { useGotchaContext } from '../components/GotchaProvider';\nimport { ResponseMode, GotchaUser, GotchaResponse, VoteType } from '../types';\n\ninterface UseSubmitOptions {\n elementId: string;\n mode: ResponseMode;\n experimentId?: string;\n variant?: string;\n pollOptions?: string[];\n user?: GotchaUser;\n onSuccess?: (response: GotchaResponse) => void;\n onError?: (error: Error) => void;\n}\n\ninterface SubmitData {\n content?: string;\n title?: string;\n rating?: number;\n vote?: VoteType;\n pollSelected?: string[];\n}\n\nexport function useSubmit(options: UseSubmitOptions) {\n const { client, defaultUser } = useGotchaContext();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const submit = useCallback(\n async (data: SubmitData) => {\n setIsLoading(true);\n setError(null);\n\n try {\n const response = await client.submitResponse({\n elementId: options.elementId,\n mode: options.mode,\n content: data.content,\n title: data.title,\n rating: data.rating,\n vote: data.vote,\n pollOptions: options.pollOptions,\n pollSelected: data.pollSelected,\n experimentId: options.experimentId,\n variant: options.variant,\n user: { ...defaultUser, ...options.user },\n });\n\n options.onSuccess?.(response);\n return response;\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Something went wrong';\n setError(errorMessage);\n options.onError?.(err instanceof Error ? err : new Error(errorMessage));\n throw err;\n } finally {\n setIsLoading(false);\n }\n },\n [client, defaultUser, options]\n );\n\n return {\n submit,\n isLoading,\n error,\n clearError: () => setError(null),\n };\n}\n","/**\n * Simple class name utility\n * Combines class names, filtering out falsy values\n */\nexport function cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n","/**\n * Detect if the device supports touch\n */\nexport const isTouchDevice = (): boolean => {\n if (typeof window === 'undefined') return false;\n return 'ontouchstart' in window || navigator.maxTouchPoints > 0;\n};\n\n/**\n * Get the appropriate size based on device type\n */\nexport const getResponsiveSize = (\n size: 'sm' | 'md' | 'lg',\n isTouch: boolean\n): number => {\n const sizes = {\n sm: { desktop: 24, mobile: 32 },\n md: { desktop: 32, mobile: 36 },\n lg: { desktop: 40, mobile: 40 },\n };\n\n return isTouch ? sizes[size].mobile : sizes[size].desktop;\n};\n","import React, { useState, useEffect } from 'react';\nimport { Size, Theme, GotchaStyles } from '../types';\nimport { cn } from '../utils/cn';\nimport { isTouchDevice, getResponsiveSize } from '../utils/device';\n\nexport interface GotchaButtonProps {\n size: Size;\n theme: Theme;\n customStyles?: GotchaStyles;\n showOnHover: boolean;\n touchBehavior: 'always-visible' | 'tap-to-reveal';\n onClick: () => void;\n isOpen: boolean;\n isParentHovered?: boolean;\n}\n\nexport function GotchaButton({\n size,\n theme,\n customStyles,\n showOnHover,\n touchBehavior,\n onClick,\n isOpen,\n isParentHovered = false,\n}: GotchaButtonProps) {\n const [isTouch, setIsTouch] = useState(false);\n const [tapRevealed, setTapRevealed] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n // Determine visibility\n const shouldShow = (() => {\n // Always show if modal is open\n if (isOpen) return true;\n\n // Desktop with showOnHover: only show when parent is hovered\n if (!isTouch && showOnHover) {\n return isParentHovered;\n }\n\n // Touch device with tap-to-reveal: show only after first tap\n if (isTouch && touchBehavior === 'tap-to-reveal') {\n return tapRevealed;\n }\n\n // All other cases: always visible\n return true;\n })();\n\n const handleClick = () => {\n // For tap-to-reveal on touch: first tap reveals, second tap opens\n if (isTouch && touchBehavior === 'tap-to-reveal' && !tapRevealed) {\n setTapRevealed(true);\n return;\n }\n onClick();\n };\n\n const buttonSize = getResponsiveSize(size, isTouch);\n\n // Determine theme colors\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const baseStyles: React.CSSProperties = {\n width: buttonSize,\n height: buttonSize,\n borderRadius: '50%',\n border: 'none',\n cursor: 'pointer',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundColor: resolvedTheme === 'dark' ? '#374151' : '#c7d2dc',\n color: resolvedTheme === 'dark' ? '#e5e7eb' : '#4b5563',\n boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)',\n // CSS transition for animations\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: shouldShow ? 1 : 0,\n transform: shouldShow ? 'scale(1)' : 'scale(0.6)',\n pointerEvents: shouldShow ? 'auto' : 'none',\n ...customStyles?.button,\n };\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n style={baseStyles}\n className={cn('gotcha-button', isOpen && 'gotcha-button--open')}\n aria-label=\"Give feedback on this feature\"\n aria-expanded={isOpen}\n aria-haspopup=\"dialog\"\n >\n <GotchaIcon size={buttonSize * 0.75} />\n </button>\n );\n}\n\nfunction GotchaIcon({ size }: { size: number }) {\n return (\n <svg\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n aria-hidden=\"true\"\n >\n <text\n x=\"50%\"\n y=\"50%\"\n dominantBaseline=\"central\"\n textAnchor=\"middle\"\n fontSize=\"16\"\n fontWeight=\"bold\"\n fill=\"currentColor\"\n fontFamily=\"system-ui, -apple-system, sans-serif\"\n >\n G\n </text>\n </svg>\n );\n}\n","import React, { useState, useEffect } from 'react';\nimport { GotchaStyles } from '../../types';\nimport { isTouchDevice } from '../../utils/device';\n\ninterface FeedbackModeProps {\n theme: 'light' | 'dark' | 'custom';\n placeholder?: string;\n submitText: string;\n isLoading: boolean;\n onSubmit: (data: { content?: string; rating?: number }) => void;\n customStyles?: GotchaStyles;\n}\n\nexport function FeedbackMode({\n theme,\n placeholder,\n submitText,\n isLoading,\n onSubmit,\n customStyles,\n}: FeedbackModeProps) {\n const [content, setContent] = useState('');\n const [rating, setRating] = useState<number | null>(null);\n const [isTouch, setIsTouch] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n const isDark = theme === 'dark';\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n if (!content.trim() && rating === null) return;\n onSubmit({ content: content.trim() || undefined, rating: rating ?? undefined });\n };\n\n const inputStyles: React.CSSProperties = {\n width: '100%',\n padding: isTouch ? '12px 14px' : '10px 12px',\n border: `1px solid ${isDark ? '#374151' : '#d1d5db'}`,\n borderRadius: isTouch ? 8 : 6,\n backgroundColor: isDark ? '#374151' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: isTouch ? 16 : 14, // 16px prevents iOS zoom on focus\n resize: 'vertical',\n minHeight: isTouch ? 100 : 80,\n fontFamily: 'inherit',\n ...customStyles?.input,\n };\n\n const buttonStyles: React.CSSProperties = {\n width: '100%',\n padding: isTouch ? '14px 16px' : '10px 16px',\n border: 'none',\n borderRadius: isTouch ? 8 : 6,\n backgroundColor: isLoading ? (isDark ? '#4b5563' : '#9ca3af') : '#6366f1',\n color: '#ffffff',\n fontSize: isTouch ? 16 : 14,\n fontWeight: 500,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'background-color 150ms ease',\n ...customStyles?.submitButton,\n };\n\n return (\n <form onSubmit={handleSubmit}>\n {/* Rating (optional) */}\n <div style={{ marginBottom: isTouch ? 16 : 12 }}>\n <StarRating value={rating} onChange={setRating} isDark={isDark} isTouch={isTouch} />\n </div>\n\n {/* Text input */}\n <textarea\n value={content}\n onChange={(e) => setContent(e.target.value)}\n placeholder={placeholder || 'Share your thoughts...'}\n style={inputStyles}\n disabled={isLoading}\n aria-label=\"Your feedback\"\n />\n\n {/* Submit button */}\n <button\n type=\"submit\"\n disabled={isLoading || (!content.trim() && rating === null)}\n style={{\n ...buttonStyles,\n marginTop: 12,\n opacity: (!content.trim() && rating === null) ? 0.5 : 1,\n }}\n >\n {isLoading ? 'Submitting...' : submitText}\n </button>\n </form>\n );\n}\n\ninterface StarRatingProps {\n value: number | null;\n onChange: (rating: number) => void;\n isDark: boolean;\n isTouch: boolean;\n}\n\nfunction StarRating({ value, onChange, isDark, isTouch }: StarRatingProps) {\n const [hovered, setHovered] = useState<number | null>(null);\n const starSize = isTouch ? 32 : 20;\n const buttonPadding = isTouch ? 6 : 2;\n\n return (\n <div\n style={{\n display: 'flex',\n gap: isTouch ? 8 : 4,\n }}\n role=\"group\"\n aria-label=\"Rating\"\n >\n {[1, 2, 3, 4, 5].map((star) => {\n const isFilled = (hovered ?? value ?? 0) >= star;\n return (\n <button\n key={star}\n type=\"button\"\n onClick={() => onChange(star)}\n onMouseEnter={() => setHovered(star)}\n onMouseLeave={() => setHovered(null)}\n aria-label={`Rate ${star} out of 5`}\n aria-pressed={value === star}\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n padding: buttonPadding,\n color: isFilled ? '#f59e0b' : (isDark ? '#4b5563' : '#d1d5db'),\n transition: 'color 150ms ease',\n }}\n >\n <svg width={starSize} height={starSize} viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z\" />\n </svg>\n </button>\n );\n })}\n </div>\n );\n}\n","import React, { useEffect, useState } from 'react';\nimport { isTouchDevice } from '../../utils/device';\n\ninterface VoteModeProps {\n theme: 'light' | 'dark' | 'custom';\n isLoading: boolean;\n onSubmit: (data: { vote: 'up' | 'down' }) => void;\n}\n\nexport function VoteMode({ theme, isLoading, onSubmit }: VoteModeProps) {\n const [isTouch, setIsTouch] = useState(false);\n\n useEffect(() => {\n setIsTouch(isTouchDevice());\n }, []);\n\n const isDark = theme === 'dark';\n\n const buttonBase: React.CSSProperties = {\n flex: 1,\n padding: isTouch ? '16px 20px' : '12px 16px',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n borderRadius: isTouch ? 12 : 8,\n backgroundColor: isDark ? '#374151' : '#f9fafb',\n color: isDark ? '#f9fafb' : '#111827',\n fontSize: isTouch ? 28 : 24,\n cursor: isLoading ? 'not-allowed' : 'pointer',\n transition: 'all 150ms ease',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: isTouch ? 10 : 8,\n };\n\n const iconSize = isTouch ? 28 : 24;\n\n return (\n <div\n style={{\n display: 'flex',\n gap: isTouch ? 16 : 12,\n }}\n role=\"group\"\n aria-label=\"Vote\"\n >\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'up' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote up - I like this\"\n >\n <ThumbsUpIcon size={iconSize} />\n <span style={{ fontSize: isTouch ? 16 : 14, fontWeight: 500 }}>Like</span>\n </button>\n\n <button\n type=\"button\"\n onClick={() => onSubmit({ vote: 'down' })}\n disabled={isLoading}\n style={buttonBase}\n aria-label=\"Vote down - I don't like this\"\n >\n <ThumbsDownIcon size={iconSize} />\n <span style={{ fontSize: isTouch ? 16 : 14, fontWeight: 500 }}>Dislike</span>\n </button>\n </div>\n );\n}\n\nfunction ThumbsUpIcon({ size = 24 }: { size?: number }) {\n return (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\" />\n </svg>\n );\n}\n\nfunction ThumbsDownIcon({ size = 24 }: { size?: number }) {\n return (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\">\n <path d=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\" />\n </svg>\n );\n}\n","import React, { useRef, useEffect, useState } from 'react';\nimport { Theme, GotchaStyles, ResponseMode } from '../types';\nimport { cn } from '../utils/cn';\nimport { FeedbackMode } from './modes/FeedbackMode';\nimport { VoteMode } from './modes/VoteMode';\n\nexport interface GotchaModalProps {\n mode: ResponseMode;\n theme: Theme;\n customStyles?: GotchaStyles;\n promptText?: string;\n placeholder?: string;\n submitText: string;\n thankYouMessage: string;\n // State\n isLoading: boolean;\n isSubmitted: boolean;\n error: string | null;\n // Handlers\n onSubmit: (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => void;\n onClose: () => void;\n // Position info from parent\n anchorRect?: DOMRect;\n}\n\nexport function GotchaModal({\n mode,\n theme,\n customStyles,\n promptText,\n placeholder,\n submitText,\n thankYouMessage,\n isLoading,\n isSubmitted,\n error,\n onSubmit,\n onClose,\n anchorRect,\n}: GotchaModalProps) {\n const modalRef = useRef<HTMLDivElement>(null);\n const firstFocusableRef = useRef<HTMLButtonElement>(null);\n const [isVisible, setIsVisible] = useState(false);\n const [isMobile, setIsMobile] = useState(false);\n\n // Detect mobile based on screen width after mount (SSR-safe)\n useEffect(() => {\n setIsMobile(window.innerWidth < 640);\n }, []);\n\n // Trigger animation after mount\n useEffect(() => {\n const timer = requestAnimationFrame(() => setIsVisible(true));\n return () => cancelAnimationFrame(timer);\n }, []);\n\n // Resolve theme\n const resolvedTheme = theme === 'auto'\n ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')\n : theme;\n\n const isDark = resolvedTheme === 'dark';\n\n // Determine if modal should appear above or below\n const modalHeight = 280; // approximate modal height\n const spaceBelow = anchorRect\n ? window.innerHeight - anchorRect.bottom\n : window.innerHeight / 2;\n const showAbove = spaceBelow < modalHeight + 20;\n\n // Focus trap\n useEffect(() => {\n const modal = modalRef.current;\n if (!modal) return;\n\n // Focus first element\n firstFocusableRef.current?.focus();\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n onClose();\n return;\n }\n\n if (e.key === 'Tab') {\n const focusableElements = modal.querySelectorAll<HTMLElement>(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n );\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey && document.activeElement === firstElement) {\n e.preventDefault();\n lastElement?.focus();\n } else if (!e.shiftKey && document.activeElement === lastElement) {\n e.preventDefault();\n firstElement?.focus();\n }\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [onClose]);\n\n const defaultPrompt = mode === 'vote'\n ? 'What do you think?'\n : 'What do you think of this feature?';\n\n // Responsive sizing - on mobile, use fixed positioning centered on screen\n const modalPadding = isMobile ? 20 : 16;\n\n const modalStyles: React.CSSProperties = isMobile\n ? {\n // Mobile: fixed position, centered on screen\n position: 'fixed',\n left: '50%',\n top: '50%',\n width: 'calc(100vw - 32px)',\n maxWidth: 320,\n padding: modalPadding,\n borderRadius: 12,\n backgroundColor: isDark ? '#1f2937' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n boxShadow: '0 10px 25px rgba(0, 0, 0, 0.2)',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n zIndex: 9999,\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: isVisible ? 1 : 0,\n transform: isVisible\n ? 'translate(-50%, -50%) scale(1)'\n : 'translate(-50%, -50%) scale(0.95)',\n ...customStyles?.modal,\n }\n : {\n // Desktop: absolute position relative to button\n position: 'absolute',\n left: '50%',\n width: 320,\n padding: modalPadding,\n borderRadius: 8,\n backgroundColor: isDark ? '#1f2937' : '#ffffff',\n color: isDark ? '#f9fafb' : '#111827',\n boxShadow: '0 10px 25px rgba(0, 0, 0, 0.15)',\n border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`,\n zIndex: 9999,\n ...(showAbove\n ? { bottom: '100%', marginBottom: 8 }\n : { top: '100%', marginTop: 8 }),\n transition: 'opacity 0.2s ease-out, transform 0.2s ease-out',\n opacity: isVisible ? 1 : 0,\n transform: isVisible\n ? 'translateX(-50%) scale(1) translateY(0)'\n : `translateX(-50%) scale(0.95) translateY(${showAbove ? '10px' : '-10px'})`,\n ...customStyles?.modal,\n };\n\n return (\n <div\n ref={modalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby=\"gotcha-modal-title\"\n style={modalStyles}\n className={cn('gotcha-modal', isDark && 'gotcha-modal--dark')}\n >\n {/* Close button - larger on touch devices */}\n <button\n ref={firstFocusableRef}\n type=\"button\"\n onClick={onClose}\n aria-label=\"Close feedback form\"\n style={{\n position: 'absolute',\n top: isMobile ? 12 : 8,\n right: isMobile ? 12 : 8,\n width: isMobile ? 36 : 24,\n height: isMobile ? 36 : 24,\n border: 'none',\n background: 'none',\n cursor: 'pointer',\n color: isDark ? '#9ca3af' : '#6b7280',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: 4,\n }}\n >\n <svg width={isMobile ? 18 : 14} height={isMobile ? 18 : 14} viewBox=\"0 0 14 14\" fill=\"none\">\n <path\n d=\"M1 1L13 13M1 13L13 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n />\n </svg>\n </button>\n\n {/* Title */}\n <h2\n id=\"gotcha-modal-title\"\n style={{\n margin: '0 0 12px 0',\n fontSize: isMobile ? 16 : 14,\n fontWeight: 500,\n paddingRight: isMobile ? 40 : 24,\n }}\n >\n {promptText || defaultPrompt}\n </h2>\n\n {/* Success state */}\n {isSubmitted && (\n <div\n style={{\n textAlign: 'center',\n padding: '20px 0',\n color: isDark ? '#10b981' : '#059669',\n }}\n >\n <svg\n width=\"32\"\n height=\"32\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n style={{ margin: '0 auto 8px' }}\n >\n <path\n d=\"M20 6L9 17L4 12\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n <p style={{ margin: 0, fontSize: 14 }}>{thankYouMessage}</p>\n </div>\n )}\n\n {/* Error state */}\n {error && !isSubmitted && (\n <div\n style={{\n padding: 8,\n marginBottom: 12,\n borderRadius: 4,\n backgroundColor: isDark ? '#7f1d1d' : '#fef2f2',\n color: isDark ? '#fecaca' : '#dc2626',\n fontSize: 13,\n }}\n >\n {error}\n </div>\n )}\n\n {/* Form content based on mode */}\n {!isSubmitted && (\n <>\n {mode === 'feedback' && (\n <FeedbackMode\n theme={resolvedTheme}\n placeholder={placeholder}\n submitText={submitText}\n isLoading={isLoading}\n onSubmit={onSubmit}\n customStyles={customStyles}\n />\n )}\n {mode === 'vote' && (\n <VoteMode\n theme={resolvedTheme}\n isLoading={isLoading}\n onSubmit={onSubmit}\n />\n )}\n </>\n )}\n\n {/* Screen reader announcement */}\n <div aria-live=\"polite\" className=\"sr-only\" style={{ position: 'absolute', left: -9999 }}>\n {isSubmitted && 'Thank you! Your feedback has been submitted.'}\n {error && `Error: ${error}`}\n </div>\n </div>\n );\n}\n","import React, { useState, useCallback, useEffect, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport {\n ResponseMode,\n GotchaUser,\n Position,\n Size,\n Theme,\n TouchBehavior,\n GotchaStyles,\n GotchaResponse,\n GotchaError,\n} from '../types';\nimport { DEFAULTS } from '../constants';\nimport { useGotchaContext } from './GotchaProvider';\nimport { useSubmit } from '../hooks/useSubmit';\nimport { GotchaButton } from './GotchaButton';\nimport { GotchaModal } from './GotchaModal';\n\nexport interface GotchaProps {\n /** Unique identifier for this element */\n elementId: string;\n\n // User data\n /** User metadata for segmentation */\n user?: GotchaUser;\n\n // Behavior\n /** Feedback mode */\n mode?: ResponseMode;\n /** Required if mode is 'ab' */\n experimentId?: string;\n /** Current A/B variant shown to user */\n variant?: string;\n\n // Poll mode specific (Phase 2)\n /** Required if mode is 'poll' (2-6 options) */\n options?: string[];\n /** Allow selecting multiple options */\n allowMultiple?: boolean;\n /** Show results after voting */\n showResults?: boolean;\n\n // Appearance\n /** Button position relative to parent */\n position?: Position;\n /** Button size */\n size?: Size;\n /** Color theme */\n theme?: Theme;\n /** Custom style overrides */\n customStyles?: GotchaStyles;\n /** Control visibility programmatically */\n visible?: boolean;\n /** Only show when parent is hovered (default: true) */\n showOnHover?: boolean;\n /** Mobile behavior (default: 'always-visible') */\n touchBehavior?: TouchBehavior;\n\n // Content\n /** Custom prompt text */\n promptText?: string;\n /** Input placeholder text */\n placeholder?: string;\n /** Submit button text */\n submitText?: string;\n /** Post-submission message */\n thankYouMessage?: string;\n\n // Callbacks\n /** Called after successful submission */\n onSubmit?: (response: GotchaResponse) => void;\n /** Called when modal opens */\n onOpen?: () => void;\n /** Called when modal closes */\n onClose?: () => void;\n /** Called on error */\n onError?: (error: GotchaError) => void;\n}\n\nexport function Gotcha({\n elementId,\n user,\n mode = 'feedback',\n experimentId,\n variant,\n options,\n allowMultiple = false,\n showResults = true,\n position = DEFAULTS.POSITION,\n size = DEFAULTS.SIZE,\n theme = DEFAULTS.THEME,\n customStyles,\n visible = true,\n showOnHover = DEFAULTS.SHOW_ON_HOVER,\n touchBehavior = DEFAULTS.TOUCH_BEHAVIOR,\n promptText,\n placeholder,\n submitText = DEFAULTS.SUBMIT_TEXT,\n thankYouMessage = DEFAULTS.THANK_YOU_MESSAGE,\n onSubmit,\n onOpen,\n onClose,\n onError,\n}: GotchaProps) {\n const { disabled, activeModalId, openModal, closeModal } = useGotchaContext();\n const [isSubmitted, setIsSubmitted] = useState(false);\n const [isParentHovered, setIsParentHovered] = useState(false);\n const [anchorRect, setAnchorRect] = useState<DOMRect | null>(null);\n const [isMobile, setIsMobile] = useState(false);\n const containerRef = useRef<HTMLDivElement>(null);\n\n // Detect mobile for portal rendering (SSR-safe)\n useEffect(() => {\n setIsMobile(window.innerWidth < 640);\n }, []);\n\n // This instance's modal is open if activeModalId matches our elementId\n const isOpen = activeModalId === elementId;\n\n // Attach hover listeners to the parent element (not the button container)\n useEffect(() => {\n if (!showOnHover) return;\n\n const container = containerRef.current;\n if (!container) return;\n\n // Find the parent element with position: relative\n const parent = container.parentElement;\n if (!parent) return;\n\n const handleMouseEnter = () => setIsParentHovered(true);\n const handleMouseLeave = () => setIsParentHovered(false);\n\n parent.addEventListener('mouseenter', handleMouseEnter);\n parent.addEventListener('mouseleave', handleMouseLeave);\n\n return () => {\n parent.removeEventListener('mouseenter', handleMouseEnter);\n parent.removeEventListener('mouseleave', handleMouseLeave);\n };\n }, [showOnHover]);\n\n const { submit, isLoading, error } = useSubmit({\n elementId,\n mode,\n experimentId,\n variant,\n pollOptions: options,\n user,\n onSuccess: (response) => {\n setIsSubmitted(true);\n onSubmit?.(response);\n // Auto-close after 2.5 seconds\n setTimeout(() => {\n closeModal();\n setIsSubmitted(false);\n }, 2500);\n },\n onError: (err) => {\n onError?.(err as unknown as GotchaError);\n },\n });\n\n const handleOpen = useCallback(() => {\n if (containerRef.current) {\n setAnchorRect(containerRef.current.getBoundingClientRect());\n }\n openModal(elementId);\n onOpen?.();\n }, [elementId, openModal, onOpen]);\n\n const handleClose = useCallback(() => {\n closeModal();\n setIsSubmitted(false);\n onClose?.();\n }, [closeModal, onClose]);\n\n const handleSubmit = useCallback(\n (data: { content?: string; rating?: number; vote?: 'up' | 'down' }) => {\n submit(data);\n },\n [submit]\n );\n\n // Don't render if disabled or not visible\n if (disabled || !visible) return null;\n\n // Position styles\n const positionStyles: Record<Position, React.CSSProperties> = {\n 'top-right': { position: 'absolute', top: 0, right: 0, transform: 'translate(50%, -50%)' },\n 'top-left': { position: 'absolute', top: 0, left: 0, transform: 'translate(-50%, -50%)' },\n 'bottom-right': { position: 'absolute', bottom: 0, right: 0, transform: 'translate(50%, 50%)' },\n 'bottom-left': { position: 'absolute', bottom: 0, left: 0, transform: 'translate(-50%, 50%)' },\n 'inline': { position: 'relative', display: 'inline-flex' },\n };\n\n return (\n <div\n ref={containerRef}\n style={{\n ...positionStyles[position],\n zIndex: isOpen ? 10000 : 50,\n }}\n className=\"gotcha-container\"\n data-gotcha-element={elementId}\n >\n <GotchaButton\n size={size}\n theme={theme}\n customStyles={customStyles}\n showOnHover={showOnHover}\n touchBehavior={touchBehavior}\n onClick={handleOpen}\n isOpen={isOpen}\n isParentHovered={isParentHovered}\n />\n\n {isOpen && !isMobile && (\n <GotchaModal\n mode={mode}\n theme={theme}\n customStyles={customStyles}\n promptText={promptText}\n placeholder={placeholder}\n submitText={submitText}\n thankYouMessage={thankYouMessage}\n isLoading={isLoading}\n isSubmitted={isSubmitted}\n error={error}\n onSubmit={handleSubmit}\n onClose={handleClose}\n anchorRect={anchorRect || undefined}\n />\n )}\n\n {/* On mobile, render modal via portal to escape parent transform */}\n {isOpen && isMobile && createPortal(\n <div\n style={{\n position: 'fixed',\n inset: 0,\n zIndex: 99999,\n backgroundColor: 'rgba(0, 0, 0, 0.3)',\n }}\n onClick={handleClose}\n aria-hidden=\"true\"\n >\n <div onClick={(e) => e.stopPropagation()}>\n <GotchaModal\n mode={mode}\n theme={theme}\n customStyles={customStyles}\n promptText={promptText}\n placeholder={placeholder}\n submitText={submitText}\n thankYouMessage={thankYouMessage}\n isLoading={isLoading}\n isSubmitted={isSubmitted}\n error={error}\n onSubmit={handleSubmit}\n onClose={handleClose}\n anchorRect={anchorRect || undefined}\n />\n </div>\n </div>,\n document.body\n )}\n </div>\n );\n}\n","import { useGotchaContext } from '../components/GotchaProvider';\n\n/**\n * Hook to access Gotcha context\n * Must be used within a GotchaProvider\n */\nexport function useGotcha() {\n const { client, disabled, defaultUser, debug } = useGotchaContext();\n\n return {\n /** The API client for manual submissions */\n client,\n /** Whether Gotcha is globally disabled */\n disabled,\n /** Default user metadata */\n defaultUser,\n /** Whether debug mode is enabled */\n debug,\n /** Submit feedback programmatically */\n submitFeedback: client.submitResponse.bind(client),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gotcha-feedback",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Developer-first contextual feedback SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",