gotcha-feedback 1.0.16 → 1.0.18
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.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
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://gotcha.cx/api/v1";var ue={ANONYMOUS_ID:"gotcha_anonymous_id"},P={POSITION:"top-right",SIZE:"md",THEME:"light",SHOW_ON_HOVER:true,TOUCH_BEHAVIOR:"always-visible",SUBMIT_TEXT:"Submit",THANK_YOU_MESSAGE:"Thanks for your feedback!"};var J={MAX_RETRIES:2,BASE_DELAY_MS:500,MAX_DELAY_MS:5e3};function Me(){if(typeof window>"u")return `anon_${crypto.randomUUID()}`;let e=localStorage.getItem(ue.ANONYMOUS_ID);if(e)return e;let a=`anon_${crypto.randomUUID()}`;return localStorage.setItem(ue.ANONYMOUS_ID,a),a}var ee={maxRetries:J.MAX_RETRIES,baseDelayMs:J.BASE_DELAY_MS,maxDelayMs:J.MAX_DELAY_MS};async function pe(e,a,l=ee,n=false){let g=null;for(let b=0;b<=l.maxRetries;b++){try{n&&b>0&&console.log(`[Gotcha] Retry attempt ${b}/${l.maxRetries}`);let t=await fetch(e,a);if(t.status>=400&&t.status<500&&t.status!==429||t.ok)return t;g=new Error(`HTTP ${t.status}`);}catch(t){g=t,n&&console.log(`[Gotcha] Network error: ${g.message}`);}if(b<l.maxRetries){let t=Math.min(l.baseDelayMs*Math.pow(2,b),l.maxDelayMs);await new Promise(i=>setTimeout(i,t));}}throw g}function Ie(e){let{apiKey:a,baseUrl:l=Ce,debug:n=false}=e,g={"Content-Type":"application/json",Authorization:`Bearer ${a}`};async function b(t,i,s){let r=`${l}${i}`,d=crypto.randomUUID();n&&console.log(`[Gotcha] ${t} ${i}`,s);let c=await pe(r,{method:t,headers:{...g,"Idempotency-Key":d},body:s?JSON.stringify(s):void 0},ee,n),u=await c.json();if(!c.ok){let p=u.error;throw n&&console.error(`[Gotcha] Error: ${p.code} - ${p.message}`),p}return n&&console.log("[Gotcha] Response:",u),u}return {async submitResponse(t){let i=t.user||{};i.id||(i.id=Me());let s={...t,user:i,context:{url:typeof window<"u"?window.location.href:void 0,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}};return b("POST","/responses",s)},async checkExistingResponse(t,i){let s=`${l}/responses/check?elementId=${encodeURIComponent(t)}&userId=${encodeURIComponent(i)}`;n&&console.log("[Gotcha] GET /responses/check");let r=await pe(s,{method:"GET",headers:g},ee,n),d=await r.json();if(!r.ok){let c=d.error;throw n&&console.error(`[Gotcha] Error: ${c.code} - ${c.message}`),c}return d.exists?(n&&console.log("[Gotcha] Found existing response:",d.response),d.response):null},async updateResponse(t,i,s){let r=`${l}/responses/${t}${s?`?userId=${encodeURIComponent(s)}`:""}`;n&&console.log(`[Gotcha] PATCH /responses/${t}`,i);let d=await pe(r,{method:"PATCH",headers:g,body:JSON.stringify(i)},ee,n),c=await d.json();if(!d.ok){let u=c.error;throw n&&console.error(`[Gotcha] Error: ${u.code} - ${u.message}`),u}return n&&console.log("[Gotcha] Response updated:",c),c},getBaseUrl(){return l}}}var Ae=createContext(null);function qe({apiKey:e,children:a,baseUrl:l,debug:n=false,disabled:g=false,defaultUser:b={}}){let[t,i]=useState(null),s=useMemo(()=>Ie({apiKey:e,baseUrl:l,debug:n}),[e,l,n]),r=useCallback(u=>{i(u);},[]),d=useCallback(()=>{i(null);},[]),c=useMemo(()=>({client:s,disabled:g,defaultUser:b,debug:n,activeModalId:t,openModal:r,closeModal:d}),[s,g,b,n,t,r,d]);return jsx(Ae.Provider,{value:c,children:a})}function U(){let e=useContext(Ae);if(!e)throw new Error("useGotchaContext must be used within a GotchaProvider");return e}function Oe(e){let{client:a,defaultUser:l}=U(),[n,g]=useState(false),[b,t]=useState(false),[i,s]=useState(null),[r,d]=useState(null);return useEffect(()=>{let u=e.user?.id||l?.id;if(!u){d(null);return}let p=false;return (async()=>{t(true);try{let f=await a.checkExistingResponse(e.elementId,u);p||d(f);}catch{p||d(null);}finally{p||t(false);}})(),()=>{p=true;}},[a,e.elementId,e.user?.id,l?.id]),{submit:useCallback(async u=>{g(true),s(null);try{let p=e.user?.id||l?.id,m;return r&&p?m=await a.updateResponse(r.id,{content:u.content,title:u.title,rating:u.rating,vote:u.vote,pollSelected:u.pollSelected},p):m=await a.submitResponse({elementId:e.elementId,mode:e.mode,content:u.content,title:u.title,rating:u.rating,vote:u.vote,pollOptions:e.pollOptions,pollSelected:u.pollSelected,experimentId:e.experimentId,variant:e.variant,user:{...l,...e.user}}),e.onSuccess?.(m),m}catch(p){let m=p instanceof Error?p.message:"Something went wrong";throw s(m),e.onError?.(p instanceof Error?p:new Error(m)),p}finally{g(false);}},[a,l,e,r]),isLoading:n,isCheckingExisting:b,error:i,existingResponse:r,isEditing:!!r,clearError:()=>s(null)}}function oe(...e){return e.filter(Boolean).join(" ")}var A=()=>typeof window>"u"?false:"ontouchstart"in window||navigator.maxTouchPoints>0,_e=(e,a)=>{let l={sm:{desktop:24,mobile:32},md:{desktop:32,mobile:36},lg:{desktop:40,mobile:40}};return a?l[e].mobile:l[e].desktop};function tt(){return typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Ue({size:e,theme:a,customStyles:l,showOnHover:n,touchBehavior:g,onClick:b,isOpen:t,isParentHovered:i=false}){let[s,r]=useState(false),[d,c]=useState(false),[u,p]=useState(tt);useEffect(()=>{r(A());let C=window.matchMedia("(prefers-color-scheme: dark)"),h=G=>p(G.matches?"dark":"light");return C.addEventListener("change",h),()=>C.removeEventListener("change",h)},[]);let m=t?true:!s&&n?i:s&&g==="tap-to-reveal"?d:true,f=()=>{if(s&&g==="tap-to-reveal"&&!d){c(true);return}b();},o=_e(e,s),v=(a==="auto"?u:a)==="dark",I={width:o,height:o,borderRadius:"50%",border:v?"1px solid rgba(255,255,255,0.15)":"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",background:v?"linear-gradient(180deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.04) 60%, rgba(0,0,0,0.05) 100%)":"linear-gradient(160deg, rgba(255,255,255,0.7) 0%, rgba(200,210,230,0.4) 40%, rgba(180,192,220,0.5) 100%)",backdropFilter:"blur(16px) saturate(170%)",WebkitBackdropFilter:"blur(16px) saturate(170%)",color:v?"rgba(255,255,255,0.88)":"rgba(0,0,0,0.75)",boxShadow:v?"0 4px 14px rgba(0,0,0,0.45), 0 1px 3px rgba(0,0,0,0.35)":"0 3px 12px rgba(0,0,0,0.12), 0 0 1px rgba(0,0,0,0.2)",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",opacity:m?1:0,transform:m?"scale(1)":"scale(0.6)",pointerEvents:m?"auto":"none",...l?.button};return jsx("button",{type:"button",onClick:f,style:I,className:oe("gotcha-button",t&&"gotcha-button--open"),"aria-label":"Give feedback on this feature","aria-expanded":t,"aria-haspopup":"dialog",children:jsx(nt,{size:o*.65})})}var De="gotcha-carter-one";function ot(){useEffect(()=>{if(document.getElementById(De))return;let e=document.createElement("link");e.id=De,e.rel="stylesheet",e.href="https://fonts.googleapis.com/css2?family=Carter+One&display=swap",document.head.appendChild(e);},[]);}function nt({size:e}){return ot(),jsx("span",{"aria-hidden":"true",style:{fontFamily:"'Carter One', cursive",fontSize:e,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",marginTop:e*.05,marginRight:e*.05,userSelect:"none"},children:"G"})}function D({size:e=16,color:a="currentColor"}){return jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",style:{animation:"gotcha-spin 0.8s linear infinite"},children:[jsx("style",{children:`
|
|
2
2
|
@keyframes gotcha-spin {
|
|
3
3
|
from { transform: rotate(0deg); }
|
|
4
4
|
to { transform: rotate(360deg); }
|
|
@@ -8,5 +8,5 @@ import {createContext,useState,useMemo,useCallback,useRef,useEffect,useContext}f
|
|
|
8
8
|
50% { stroke-dasharray: 40, 62; stroke-dashoffset: -12; }
|
|
9
9
|
100% { stroke-dasharray: 1, 62; stroke-dashoffset: -62; }
|
|
10
10
|
}
|
|
11
|
-
`}),jsx("circle",{cx:"12",cy:"12",r:"10",stroke:a,strokeWidth:"2",strokeOpacity:"0.12"}),jsx("circle",{cx:"12",cy:"12",r:"10",stroke:a,strokeWidth:"2",strokeLinecap:"round",style:{animation:"gotcha-dash 1.2s ease-in-out infinite"}})]})}function ze({theme:e,placeholder:a,submitText:l,isLoading:o,onSubmit:b,customStyles:m,initialValues:t,isEditing:c=false}){let[r,u]=useState(t?.content||""),[d,s]=useState(t?.rating??null),[i,f]=useState(false);useEffect(()=>{f(I());},[]),useEffect(()=>{t?.content!==void 0&&u(t.content||""),t?.rating!==void 0&&s(t.rating??null);},[t?.content,t?.rating]);let p=e==="dark",g=h=>{h.preventDefault(),!(!r.trim()&&d===null)&&b({content:r.trim()||void 0,rating:d??void 0});},n={width:"100%",padding:i?"12px 14px":"10px 12px",border:`1px solid ${p?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:8,backgroundColor:p?"rgba(55,65,81,0.5)":"#fafbfc",color:p?"#f9fafb":"#111827",fontSize:i?16:14,resize:"vertical",minHeight:i?100:80,fontFamily:"inherit",outline:"none",transition:"border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1)",lineHeight:1.5,...m?.input},v={width:"100%",padding:i?"14px 16px":"10px 16px",border:"none",borderRadius:8,backgroundColor:p?"#e2e8f0":"#1e293b",color:p?"#1e293b":"#ffffff",fontSize:i?16:14,fontWeight:500,cursor:o?"not-allowed":"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",letterSpacing:"0.01em",...m?.submitButton};return jsxs("form",{onSubmit:g,children:[jsx("div",{style:{marginBottom:i?16:12},children:jsx(rt,{value:d,onChange:s,isDark:p,isTouch:i})}),jsx("textarea",{value:r,onChange:h=>u(h.target.value),placeholder:a||"Share your thoughts...",style:n,disabled:o,"aria-label":"Your feedback",onFocus:h=>{h.currentTarget.style.borderColor="#1e293b",h.currentTarget.style.boxShadow="0 0 0 2px rgba(30,41,59,0.15)",h.currentTarget.style.backgroundColor=p?"rgba(55,65,81,0.7)":"#ffffff";},onBlur:h=>{h.currentTarget.style.borderColor=p?"rgba(255,255,255,0.08)":"#e2e8f0",h.currentTarget.style.boxShadow="none",h.currentTarget.style.backgroundColor=p?"rgba(55,65,81,0.5)":"#fafbfc";}}),jsxs("button",{type:"submit",disabled:o||!r.trim()&&d===null,style:{...v,marginTop:12,opacity:o?.8:1,backgroundColor:!r.trim()&&d===null?p?"#374151":"#e2e8f0":p?"#e2e8f0":"#1e293b",color:!r.trim()&&d===null?p?"#6b7280":"#94a3b8":p?"#1e293b":"#ffffff",display:"flex",alignItems:"center",justifyContent:"center",gap:8},onMouseEnter:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=p?"#cbd5e1":"#334155");},onMouseLeave:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=p?"#e2e8f0":"#1e293b");},children:[o&&jsx(_,{size:i?18:16,color:p?"#1e293b":"#ffffff"}),o?c?"Updating...":"Submitting...":c?"Update":l]})]})}function rt({value:e,onChange:a,isDark:l,isTouch:o}){let[b,m]=useState(null),t=o?28:18,c=o?6:3;return jsx("div",{style:{display:"flex",gap:o?6:2},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(r=>{let u=(b??e??0)>=r;return jsx("button",{type:"button",onClick:()=>a(r),onMouseEnter:()=>m(r),onMouseLeave:()=>m(null),"aria-label":`Rate ${r} out of 5`,"aria-pressed":e===r,style:{background:"none",border:"none",cursor:"pointer",padding:c,color:u?"#f59e0b":l?"rgba(255,255,255,0.12)":"#e2e8f0",transition:"color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1)",transform:b!==null&&b>=r?"scale(1.1)":"scale(1)"},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"})})},r)})})}function Ne({theme:e,isLoading:a,onSubmit:l,initialVote:o,isEditing:b=false,labels:m}){let[t,c]=useState(false),[r,u]=useState(o||null),[d,s]=useState(o||null);useEffect(()=>{c(I());},[]),useEffect(()=>{o!==void 0&&(s(o),u(o));},[o]),useEffect(()=>{!a&&!b&&u(null);},[a,b]);let i=n=>{u(n),l({vote:n});},f=e==="dark",p=n=>{let v=d===n;return {flex:1,minWidth:0,overflow:"hidden",padding:t?"14px 18px":"10px 14px",border:`1px solid ${v?n==="up"?f?"rgba(16,185,129,0.3)":"rgba(16,185,129,0.25)":f?"rgba(239,68,68,0.3)":"rgba(239,68,68,0.25)":f?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:t?10:8,backgroundColor:v?n==="up"?f?"rgba(16,185,129,0.08)":"rgba(16,185,129,0.06)":f?"rgba(239,68,68,0.08)":"rgba(239,68,68,0.06)":f?"rgba(55,65,81,0.5)":"#fafbfc",color:v?n==="up"?"#10b981":"#ef4444":f?"#d1d5db":"#64748b",fontSize:t?28:24,cursor:a?"not-allowed":"pointer",transition:"background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s",display:"flex",alignItems:"center",justifyContent:"center",gap:t?10:8}},g=t?24:20;return jsxs("div",{style:{display:"flex",gap:t?12:10},role:"group","aria-label":"Vote",children:[jsx("button",{type:"button",onClick:()=>i("up"),disabled:a,style:p("up"),"aria-label":"Vote up - I like this","aria-pressed":d==="up",onMouseEnter:n=>{a||(n.currentTarget.style.transform="translateY(-1px)",n.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:n=>{n.currentTarget.style.transform="translateY(0)",n.currentTarget.style.boxShadow="none";},children:a&&r==="up"?jsxs(Fragment,{children:[jsx(_,{size:g,color:f?"#f9fafb":"#111827"}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:b?"Updating...":"Sending..."})]}):jsxs(Fragment,{children:[jsx(nt,{size:g}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:m?.up||(d==="up"?"Liked":"Like")})]})}),jsx("button",{type:"button",onClick:()=>i("down"),disabled:a,style:p("down"),"aria-label":"Vote down - I don't like this","aria-pressed":d==="down",onMouseEnter:n=>{a||(n.currentTarget.style.transform="translateY(-1px)",n.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:n=>{n.currentTarget.style.transform="translateY(0)",n.currentTarget.style.boxShadow="none";},children:a&&r==="down"?jsxs(Fragment,{children:[jsx(_,{size:g,color:f?"#f9fafb":"#111827"}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:b?"Updating...":"Sending..."})]}):jsxs(Fragment,{children:[jsx(st,{size:g}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:m?.down||(d==="down"?"Disliked":"Dislike")})]})})]})}function nt({size:e=24}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",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 st({size:e=24}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",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 $e({theme:e,options:a,allowMultiple:l,isLoading:o,onSubmit:b,initialSelected:m,isEditing:t=false}){let[c,r]=useState(m||[]),[u,d]=useState(false);useEffect(()=>{d(I());},[]),useEffect(()=>{m&&r(m);},[m]);let s=e==="dark",i=g=>{r(l?n=>n.includes(g)?n.filter(v=>v!==g):[...n,g]:n=>n.includes(g)?[]:[g]);},f=()=>{c.length!==0&&b({pollSelected:c});},p=g=>{let n=c.includes(g);return {width:"100%",padding:u?"12px 14px":"9px 12px",border:`1px solid ${n?s?"rgba(226,232,240,0.25)":"rgba(30,41,59,0.25)":s?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:u?10:8,backgroundColor:n?s?"rgba(226,232,240,0.08)":"rgba(30,41,59,0.05)":s?"rgba(55,65,81,0.5)":"#fafbfc",color:n?s?"#e2e8f0":"#1e293b":s?"#d1d5db":"#374151",fontSize:u?15:13,fontWeight:500,cursor:o?"not-allowed":"pointer",transition:"background-color 0.2s, border-color 0.2s, color 0.2s",textAlign:"left",letterSpacing:"0.01em",display:"flex",alignItems:"center",gap:8}};return jsxs("div",{children:[jsx("div",{style:{display:"flex",flexDirection:"column",gap:u?8:6},role:"group","aria-label":l?"Select one or more options":"Select an option",children:a.map(g=>{let n=c.includes(g);return jsxs("button",{type:"button",onClick:()=>i(g),disabled:o,style:p(g),"aria-pressed":n,children:[jsx("span",{style:{width:16,height:16,borderRadius:l?4:"50%",border:`2px solid ${n?s?"#e2e8f0":"#1e293b":s?"rgba(255,255,255,0.2)":"#cbd5e1"}`,backgroundColor:n?s?"#e2e8f0":"#1e293b":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"all 0.15s"},children:n&&jsx("svg",{width:10,height:10,viewBox:"0 0 12 12",fill:"none",children:jsx("path",{d:"M2 6l3 3 5-5",stroke:"#fff",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),g]},g)})}),jsxs("button",{type:"button",onClick:f,disabled:o||c.length===0,style:{width:"100%",marginTop:12,padding:u?"14px 16px":"10px 16px",border:"none",borderRadius:8,backgroundColor:c.length===0?s?"#374151":"#e2e8f0":s?"#e2e8f0":"#1e293b",color:c.length===0?s?"#6b7280":"#94a3b8":s?"#1e293b":"#ffffff",fontSize:u?16:14,fontWeight:500,cursor:o||c.length===0?"not-allowed":"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",letterSpacing:"0.01em",display:"flex",alignItems:"center",justifyContent:"center",gap:8,opacity:o?.8:1},onMouseEnter:g=>{g.currentTarget.disabled||(g.currentTarget.style.backgroundColor=s?"#cbd5e1":"#334155");},onMouseLeave:g=>{g.currentTarget.disabled||(g.currentTarget.style.backgroundColor=c.length===0?s?"#374151":"#e2e8f0":s?"#e2e8f0":"#1e293b");},children:[o&&jsx(_,{size:u?18:16,color:s?"#1e293b":"#ffffff"}),o?t?"Updating...":"Submitting...":t?"Update":"Submit"]})]})}function xe({mode:e,theme:a,customStyles:l,promptText:o,placeholder:b,submitText:m,thankYouMessage:t,isLoading:c,isSubmitted:r,error:u,existingResponse:d,isEditing:s=false,voteLabels:i,options:f,allowMultiple:p=false,onSubmit:g,onClose:n,anchorRect:v}){let h=useRef(null),P=useRef(null),[C,A]=useState(false),[S,se]=useState(false),[ae,F]=useState("light");useEffect(()=>{se(window.innerWidth<640);let x=window.matchMedia("(prefers-color-scheme: dark)");F(x.matches?"dark":"light");let w=E=>F(E.matches?"dark":"light");return x.addEventListener("change",w),()=>x.removeEventListener("change",w)},[]),useEffect(()=>{let x=requestAnimationFrame(()=>A(true));return ()=>cancelAnimationFrame(x)},[]);let O=a==="auto"?ae:a,y=O==="dark",V=(v?window.innerHeight-v.bottom:window.innerHeight/2)<280+20;useEffect(()=>{let x=h.current;if(!x)return;P.current?.focus();let w=E=>{if(E.key==="Escape"){n();return}if(E.key==="Tab"){let D=x.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),z=D[0],N=D[D.length-1];E.shiftKey&&document.activeElement===z?(E.preventDefault(),N?.focus()):!E.shiftKey&&document.activeElement===N&&(E.preventDefault(),z?.focus());}};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[n]);let K=e==="vote"?"What do you think?":e==="poll"?"Cast your vote":"What do you think of this feature?",U=S?20:16,X=y?"0 1px 2px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.3), 0 12px 32px rgba(0,0,0,0.2)":"0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.06)",j=S?{position:"fixed",left:"50%",top:"50%",width:"calc(100vw - 32px)",maxWidth:320,padding:U,borderRadius:12,backgroundColor:y?"#1f2937":"#ffffff",color:y?"#f9fafb":"#111827",boxShadow:X,border:`1px solid ${y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:C?1:0,transform:C?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0.96)",...l?.modal}:{position:"absolute",left:"50%",width:320,padding:U,borderRadius:10,backgroundColor:y?"#1f2937":"#ffffff",color:y?"#f9fafb":"#111827",boxShadow:X,border:`1px solid ${y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,...V?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:C?1:0,transform:C?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.96) translateY(${V?"6px":"-6px"})`,...l?.modal};return jsxs("div",{ref:h,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:j,className:ee("gotcha-modal",y&&"gotcha-modal--dark"),children:[jsx("button",{ref:P,type:"button",onClick:n,"aria-label":"Close feedback form",style:{position:"absolute",top:S?12:8,right:S?12:8,width:S?36:28,height:S?36:28,border:"none",background:"transparent",cursor:"pointer",color:y?"#6b7280":"#9ca3af",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:6,transition:"all 0.15s cubic-bezier(0.4, 0, 0.2, 1)"},onMouseEnter:x=>{x.currentTarget.style.backgroundColor=y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.04)",x.currentTarget.style.color=y?"#9ca3af":"#6b7280";},onMouseLeave:x=>{x.currentTarget.style.backgroundColor="transparent",x.currentTarget.style.color=y?"#6b7280":"#9ca3af";},children:jsx("svg",{width:S?16:12,height:S?16:12,viewBox:"0 0 14 14",fill:"none",children:jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}),jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 16px 0",fontSize:S?16:14,fontWeight:600,paddingRight:S?40:32,letterSpacing:"-0.01em",lineHeight:1.4},children:o||K}),r&&jsxs("div",{style:{textAlign:"center",padding:"24px 0",color:y?"#10b981":"#059669"},children:[jsx("div",{style:{width:44,height:44,borderRadius:"50%",backgroundColor:y?"rgba(16,185,129,0.1)":"rgba(5,150,105,0.08)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 12px"},children:jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",children:jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("p",{style:{margin:0,fontSize:13,fontWeight:500,color:y?"#d1d5db":"#374151"},children:t})]}),u&&!r&&jsx("div",{style:{padding:"8px 10px",marginBottom:12,borderRadius:8,backgroundColor:y?"rgba(127,29,29,0.3)":"#fef2f2",border:`1px solid ${y?"rgba(254,202,202,0.1)":"rgba(220,38,38,0.1)"}`,color:y?"#fecaca":"#dc2626",fontSize:13,lineHeight:1.4},children:u}),!r&&jsxs(Fragment,{children:[e==="feedback"&&jsx(ze,{theme:O,placeholder:b,submitText:m,isLoading:c,onSubmit:g,customStyles:l,initialValues:d?{content:d.content,rating:d.rating}:void 0,isEditing:s}),e==="vote"&&jsx(Ne,{theme:O,isLoading:c,onSubmit:g,initialVote:d?.vote||void 0,isEditing:s,labels:i}),e==="poll"&&f&&f.length>0&&jsx($e,{theme:O,options:f,allowMultiple:p,isLoading:c,onSubmit:g,initialSelected:d?.pollSelected||void 0,isEditing:s})]}),jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[r&&"Thank you! Your feedback has been submitted.",u&&`Error: ${u}`]})]})}function ct({elementId:e,user:a,mode:l="feedback",experimentId:o,variant:b,voteLabels:m,options:t,allowMultiple:c=false,showResults:r=true,position:u=M.POSITION,size:d=M.SIZE,theme:s=M.THEME,customStyles:i,visible:f=true,showOnHover:p=M.SHOW_ON_HOVER,touchBehavior:g=M.TOUCH_BEHAVIOR,promptText:n,placeholder:v,submitText:h=M.SUBMIT_TEXT,thankYouMessage:P=M.THANK_YOU_MESSAGE,onSubmit:C,onOpen:A,onClose:S,onError:se}){let{disabled:ae,activeModalId:F,openModal:O,closeModal:y}=L(),[ie,W]=useState(false),[V,K]=useState(false),[U,X]=useState(null),[j,x]=useState(false),w=useRef(null);useEffect(()=>{x(window.innerWidth<640);},[]);let E=F===e;useEffect(()=>{if(!p)return;let R=w.current;if(!R)return;let B=R.parentElement;if(!B)return;let Ee=()=>K(true),Re=()=>K(false);return B.addEventListener("mouseenter",Ee),B.addEventListener("mouseleave",Re),()=>{B.removeEventListener("mouseenter",Ee),B.removeEventListener("mouseleave",Re);}},[p]);let{submit:D,isLoading:z,error:N,existingResponse:ve,isEditing:Q}=Pe({elementId:e,mode:l,experimentId:o,variant:b,pollOptions:t,user:a,onSuccess:R=>{W(true),C?.(R),setTimeout(()=>{y(),W(false);},3e3);},onError:R=>{console.warn("[Gotcha] Submission failed:",R instanceof Error?R.message:R),se?.(R);}}),We=useCallback(()=>{w.current&&X(w.current.getBoundingClientRect()),O(e),A?.();},[e,O,A]),le=useCallback(()=>{y(),W(false),S?.();},[y,S]),ke=useCallback(R=>{D(R);},[D]);return ae||!f?null:jsxs("div",{ref:w,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"}}[u],zIndex:E?1e4:"auto"},className:"gotcha-container","data-gotcha-element":e,children:[jsx(De,{size:d,theme:s,customStyles:i,showOnHover:p,touchBehavior:g,onClick:We,isOpen:E,isParentHovered:V}),E&&!j&&jsx(xe,{mode:l,theme:s,customStyles:i,promptText:n,placeholder:v,submitText:h,thankYouMessage:Q?"Your feedback has been updated!":P,isLoading:z,isSubmitted:ie,error:N,existingResponse:ve,isEditing:Q,voteLabels:m,options:t,allowMultiple:c,onSubmit:ke,onClose:le,anchorRect:U||void 0}),E&&j&&createPortal(jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,backgroundColor:"rgba(0, 0, 0, 0.3)"},onClick:le,"aria-hidden":"true",children:jsx("div",{onClick:R=>R.stopPropagation(),children:jsx(xe,{mode:l,theme:s,customStyles:i,promptText:n,placeholder:v,submitText:h,thankYouMessage:Q?"Your feedback has been updated!":P,isLoading:z,isSubmitted:ie,error:N,existingResponse:ve,isEditing:Q,voteLabels:m,options:t,allowMultiple:c,onSubmit:ke,onClose:le,anchorRect:U||void 0})})}),document.body)]})}function ut(){let{client:e,disabled:a,defaultUser:l,debug:o}=L();return {client:e,disabled:a,defaultUser:l,debug:o,submitFeedback:e.submitResponse.bind(e)}}export{ct as Gotcha,je as GotchaProvider,ut as useGotcha};//# sourceMappingURL=index.mjs.map
|
|
11
|
+
`}),jsx("circle",{cx:"12",cy:"12",r:"10",stroke:a,strokeWidth:"2",strokeOpacity:"0.12"}),jsx("circle",{cx:"12",cy:"12",r:"10",stroke:a,strokeWidth:"2",strokeLinecap:"round",style:{animation:"gotcha-dash 1.2s ease-in-out infinite"}})]})}function Be({theme:e,placeholder:a,submitText:l,isLoading:n,onSubmit:g,customStyles:b,initialValues:t,isEditing:i=false,showText:s=true,showRating:r=true}){let[d,c]=useState(t?.content||""),[u,p]=useState(t?.rating??null),[m,f]=useState(false);useEffect(()=>{f(A());},[]),useEffect(()=>{t?.content!==void 0&&c(t.content||""),t?.rating!==void 0&&p(t.rating??null);},[t?.content,t?.rating]);let o=e==="dark",x=s&&r?d.trim().length>0||u!==null:s?d.trim().length>0:r?u!==null:false,v=h=>{h.preventDefault(),x&&g({content:s&&d.trim()?d.trim():void 0,rating:r&&u!==null?u:void 0});},I={width:"100%",padding:m?"12px 14px":"10px 12px",border:`1px solid ${o?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:8,backgroundColor:o?"rgba(55,65,81,0.5)":"#fafbfc",color:o?"#f9fafb":"#111827",fontSize:m?16:14,resize:"vertical",minHeight:m?100:80,fontFamily:"inherit",outline:"none",transition:"border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1)",lineHeight:1.5,...b?.input},C={width:"100%",padding:m?"14px 16px":"10px 16px",border:"none",borderRadius:8,backgroundColor:o?"#e2e8f0":"#1e293b",color:o?"#1e293b":"#ffffff",fontSize:m?16:14,fontWeight:500,cursor:n?"not-allowed":"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",letterSpacing:"0.01em",...b?.submitButton};return jsxs("form",{onSubmit:v,children:[r&&jsx("div",{style:{marginBottom:s?m?16:12:0,...s?{}:{display:"flex",justifyContent:"center",padding:"8px 0"}},children:jsx(st,{value:u,onChange:p,isDark:o,isTouch:m,large:!s})}),s&&jsx("textarea",{value:d,onChange:h=>c(h.target.value),placeholder:a||"Share your thoughts...",style:I,disabled:n,"aria-label":"Your feedback",onFocus:h=>{h.currentTarget.style.borderColor="#1e293b",h.currentTarget.style.boxShadow="0 0 0 2px rgba(30,41,59,0.15)",h.currentTarget.style.backgroundColor=o?"rgba(55,65,81,0.7)":"#ffffff";},onBlur:h=>{h.currentTarget.style.borderColor=o?"rgba(255,255,255,0.08)":"#e2e8f0",h.currentTarget.style.boxShadow="none",h.currentTarget.style.backgroundColor=o?"rgba(55,65,81,0.5)":"#fafbfc";}}),jsxs("button",{type:"submit",disabled:n||!x,style:{...C,marginTop:12,opacity:n?.8:1,backgroundColor:x?o?"#e2e8f0":"#1e293b":o?"#374151":"#e2e8f0",color:x?o?"#1e293b":"#ffffff":o?"#6b7280":"#94a3b8",display:"flex",alignItems:"center",justifyContent:"center",gap:8},onMouseEnter:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=o?"#cbd5e1":"#334155");},onMouseLeave:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=o?"#e2e8f0":"#1e293b");},children:[n&&jsx(D,{size:m?18:16,color:o?"#1e293b":"#ffffff"}),n?i?"Updating...":"Submitting...":i?"Update":l]})]})}function st({value:e,onChange:a,isDark:l,isTouch:n,large:g=false}){let[b,t]=useState(null),i=g?n?36:28:n?28:18,s=g?n?8:5:n?6:3;return jsx("div",{style:{display:"flex",gap:g?n?8:6:n?6:2},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(r=>{let d=(b??e??0)>=r;return jsx("button",{type:"button",onClick:()=>a(r),onMouseEnter:()=>t(r),onMouseLeave:()=>t(null),"aria-label":`Rate ${r} out of 5`,"aria-pressed":e===r,style:{background:"none",border:"none",cursor:"pointer",padding:s,color:d?"#f59e0b":l?"rgba(255,255,255,0.12)":"#e2e8f0",transition:"color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1)",transform:b!==null&&b>=r?"scale(1.1)":"scale(1)"},children:jsx("svg",{width:i,height:i,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"})})},r)})})}function He({theme:e,isLoading:a,onSubmit:l,initialVote:n,isEditing:g=false,labels:b}){let[t,i]=useState(false),[s,r]=useState(n||null),[d,c]=useState(n||null);useEffect(()=>{i(A());},[]),useEffect(()=>{n!==void 0&&(c(n),r(n));},[n]),useEffect(()=>{!a&&!g&&r(null);},[a,g]);let u=o=>{r(o),l({vote:o});},p=e==="dark",m=o=>{let x=d===o;return {flex:1,minWidth:0,overflow:"hidden",padding:t?"14px 18px":"10px 14px",border:`1px solid ${x?o==="up"?p?"rgba(16,185,129,0.3)":"rgba(16,185,129,0.25)":p?"rgba(239,68,68,0.3)":"rgba(239,68,68,0.25)":p?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:t?10:8,backgroundColor:x?o==="up"?p?"rgba(16,185,129,0.08)":"rgba(16,185,129,0.06)":p?"rgba(239,68,68,0.08)":"rgba(239,68,68,0.06)":p?"rgba(55,65,81,0.5)":"#fafbfc",color:x?o==="up"?"#10b981":"#ef4444":p?"#d1d5db":"#64748b",fontSize:t?28:24,cursor:a?"not-allowed":"pointer",transition:"background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s",display:"flex",alignItems:"center",justifyContent:"center",gap:t?10:8}},f=t?24:20;return jsxs("div",{style:{display:"flex",gap:t?12:10},role:"group","aria-label":"Vote",children:[jsx("button",{type:"button",onClick:()=>u("up"),disabled:a,style:m("up"),"aria-label":"Vote up - I like this","aria-pressed":d==="up",onMouseEnter:o=>{a||(o.currentTarget.style.transform="translateY(-1px)",o.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:o=>{o.currentTarget.style.transform="translateY(0)",o.currentTarget.style.boxShadow="none";},children:a&&s==="up"?jsxs(Fragment,{children:[jsx(D,{size:f,color:p?"#f9fafb":"#111827"}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:g?"Updating...":"Sending..."})]}):jsxs(Fragment,{children:[jsx(at,{size:f}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:b?.up||(d==="up"?"Liked":"Like")})]})}),jsx("button",{type:"button",onClick:()=>u("down"),disabled:a,style:m("down"),"aria-label":"Vote down - I don't like this","aria-pressed":d==="down",onMouseEnter:o=>{a||(o.currentTarget.style.transform="translateY(-1px)",o.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:o=>{o.currentTarget.style.transform="translateY(0)",o.currentTarget.style.boxShadow="none";},children:a&&s==="down"?jsxs(Fragment,{children:[jsx(D,{size:f,color:p?"#f9fafb":"#111827"}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:g?"Updating...":"Sending..."})]}):jsxs(Fragment,{children:[jsx(it,{size:f}),jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:b?.down||(d==="down"?"Disliked":"Dislike")})]})})]})}function at({size:e=24}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",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 it({size:e=24}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",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 Fe({theme:e,options:a,allowMultiple:l,isLoading:n,onSubmit:g,initialSelected:b,isEditing:t=false}){let[i,s]=useState(b||[]),[r,d]=useState(false);useEffect(()=>{d(A());},[]),useEffect(()=>{b&&s(b);},[b]);let c=e==="dark",u=f=>{s(l?o=>o.includes(f)?o.filter(x=>x!==f):[...o,f]:o=>o.includes(f)?[]:[f]);},p=()=>{i.length!==0&&g({pollSelected:i});},m=f=>{let o=i.includes(f);return {width:"100%",padding:r?"12px 14px":"9px 12px",border:`1px solid ${o?c?"rgba(226,232,240,0.25)":"rgba(30,41,59,0.25)":c?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:r?10:8,backgroundColor:o?c?"rgba(226,232,240,0.08)":"rgba(30,41,59,0.05)":c?"rgba(55,65,81,0.5)":"#fafbfc",color:o?c?"#e2e8f0":"#1e293b":c?"#d1d5db":"#374151",fontSize:r?15:13,fontWeight:500,cursor:n?"not-allowed":"pointer",transition:"background-color 0.2s, border-color 0.2s, color 0.2s",textAlign:"left",letterSpacing:"0.01em",display:"flex",alignItems:"center",gap:8}};return jsxs("div",{children:[jsx("div",{style:{display:"flex",flexDirection:"column",gap:r?8:6},role:"group","aria-label":l?"Select one or more options":"Select an option",children:a.map(f=>{let o=i.includes(f);return jsxs("button",{type:"button",onClick:()=>u(f),disabled:n,style:m(f),"aria-pressed":o,children:[jsx("span",{style:{width:16,height:16,borderRadius:l?4:"50%",border:`2px solid ${o?c?"#e2e8f0":"#1e293b":c?"rgba(255,255,255,0.2)":"#cbd5e1"}`,backgroundColor:o?c?"#e2e8f0":"#1e293b":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"all 0.15s"},children:o&&jsx("svg",{width:10,height:10,viewBox:"0 0 12 12",fill:"none",children:jsx("path",{d:"M2 6l3 3 5-5",stroke:"#fff",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),f]},f)})}),jsxs("button",{type:"button",onClick:p,disabled:n||i.length===0,style:{width:"100%",marginTop:12,padding:r?"14px 16px":"10px 16px",border:"none",borderRadius:8,backgroundColor:i.length===0?c?"#374151":"#e2e8f0":c?"#e2e8f0":"#1e293b",color:i.length===0?c?"#6b7280":"#94a3b8":c?"#1e293b":"#ffffff",fontSize:r?16:14,fontWeight:500,cursor:n||i.length===0?"not-allowed":"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",letterSpacing:"0.01em",display:"flex",alignItems:"center",justifyContent:"center",gap:8,opacity:n?.8:1},onMouseEnter:f=>{f.currentTarget.disabled||(f.currentTarget.style.backgroundColor=c?"#cbd5e1":"#334155");},onMouseLeave:f=>{f.currentTarget.disabled||(f.currentTarget.style.backgroundColor=i.length===0?c?"#374151":"#e2e8f0":c?"#e2e8f0":"#1e293b");},children:[n&&jsx(D,{size:r?18:16,color:c?"#1e293b":"#ffffff"}),n?t?"Updating...":"Submitting...":t?"Update":"Submit"]})]})}function ve({mode:e,theme:a,customStyles:l,promptText:n,placeholder:g,submitText:b,thankYouMessage:t,isLoading:i,isSubmitted:s,error:r,existingResponse:d,isEditing:c=false,showText:u=true,showRating:p=true,voteLabels:m,options:f,allowMultiple:o=false,onSubmit:x,onClose:v,anchorRect:I}){let C=useRef(null),h=useRef(null),[G,W]=useState(false),[E,ie]=useState(false),[le,V]=useState("light");useEffect(()=>{ie(window.innerWidth<640);let S=window.matchMedia("(prefers-color-scheme: dark)");V(S.matches?"dark":"light");let M=R=>V(R.matches?"dark":"light");return S.addEventListener("change",M),()=>S.removeEventListener("change",M)},[]),useEffect(()=>{let S=requestAnimationFrame(()=>W(true));return ()=>cancelAnimationFrame(S)},[]);let _=a==="auto"?le:a,y=_==="dark",j=(I?window.innerHeight-I.bottom:window.innerHeight/2)<280+20;useEffect(()=>{let S=C.current;if(!S)return;h.current?.focus();let M=R=>{if(R.key==="Escape"){v();return}if(R.key==="Tab"){let L=S.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),N=L[0],B=L[L.length-1];R.shiftKey&&document.activeElement===N?(R.preventDefault(),B?.focus()):!R.shiftKey&&document.activeElement===B&&(R.preventDefault(),N?.focus());}};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[v]);let X=e==="vote"?"What do you think?":e==="poll"?"Cast your vote":"What do you think of this feature?",z=E?20:16,Q=y?"0 1px 2px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.3), 0 12px 32px rgba(0,0,0,0.2)":"0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.06)",q=E?{position:"fixed",left:"50%",top:"50%",width:"calc(100vw - 32px)",maxWidth:320,padding:z,borderRadius:12,backgroundColor:y?"#1f2937":"#ffffff",color:y?"#f9fafb":"#111827",boxShadow:Q,border:`1px solid ${y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:G?1:0,transform:G?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0.96)",...l?.modal,textAlign:"left"}:{position:"absolute",left:"50%",width:320,padding:z,borderRadius:10,backgroundColor:y?"#1f2937":"#ffffff",color:y?"#f9fafb":"#111827",boxShadow:Q,border:`1px solid ${y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,...j?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:G?1:0,transform:G?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.96) translateY(${j?"6px":"-6px"})`,...l?.modal,textAlign:"left"};return jsxs("div",{ref:C,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:q,className:oe("gotcha-modal",y&&"gotcha-modal--dark"),children:[jsx("button",{ref:h,type:"button",onClick:v,"aria-label":"Close feedback form",style:{position:"absolute",top:E?12:8,right:E?12:8,width:E?36:28,height:E?36:28,border:"none",background:"transparent",cursor:"pointer",color:y?"#6b7280":"#9ca3af",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:6,transition:"all 0.15s cubic-bezier(0.4, 0, 0.2, 1)"},onMouseEnter:S=>{S.currentTarget.style.backgroundColor=y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.04)",S.currentTarget.style.color=y?"#9ca3af":"#6b7280";},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="transparent",S.currentTarget.style.color=y?"#6b7280":"#9ca3af";},children:jsx("svg",{width:E?16:12,height:E?16:12,viewBox:"0 0 14 14",fill:"none",children:jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}),jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 16px 0",fontSize:E?16:14,fontWeight:600,paddingRight:E?40:32,letterSpacing:"-0.01em",lineHeight:1.4,textAlign:"left"},children:n||X}),s&&jsxs("div",{style:{textAlign:"center",padding:"24px 0",color:y?"#10b981":"#059669"},children:[jsx("div",{style:{width:44,height:44,borderRadius:"50%",backgroundColor:y?"rgba(16,185,129,0.1)":"rgba(5,150,105,0.08)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 12px"},children:jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",children:jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("p",{style:{margin:0,fontSize:13,fontWeight:500,color:y?"#d1d5db":"#374151"},children:t})]}),r&&!s&&jsx("div",{style:{padding:"8px 10px",marginBottom:12,borderRadius:8,backgroundColor:y?"rgba(127,29,29,0.3)":"#fef2f2",border:`1px solid ${y?"rgba(254,202,202,0.1)":"rgba(220,38,38,0.1)"}`,color:y?"#fecaca":"#dc2626",fontSize:13,lineHeight:1.4},children:r}),!s&&jsxs(Fragment,{children:[e==="feedback"&&jsx(Be,{theme:_,placeholder:g,submitText:b,isLoading:i,onSubmit:x,customStyles:l,initialValues:d?{content:d.content,rating:d.rating}:void 0,isEditing:c,showText:u,showRating:p}),e==="vote"&&jsx(He,{theme:_,isLoading:i,onSubmit:x,initialVote:d?.vote||void 0,isEditing:c,labels:m}),e==="poll"&&f&&f.length>0&&jsx(Fe,{theme:_,options:f,allowMultiple:o,isLoading:i,onSubmit:x,initialSelected:d?.pollSelected||void 0,isEditing:c})]}),jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[s&&"Thank you! Your feedback has been submitted.",r&&`Error: ${r}`]})]})}function ut({elementId:e,user:a,mode:l="feedback",showText:n=true,showRating:g=true,experimentId:b,variant:t,voteLabels:i,options:s,allowMultiple:r=false,showResults:d=true,position:c=P.POSITION,size:u=P.SIZE,theme:p=P.THEME,customStyles:m,visible:f=true,showOnHover:o=P.SHOW_ON_HOVER,touchBehavior:x=P.TOUCH_BEHAVIOR,promptText:v,placeholder:I,submitText:C=P.SUBMIT_TEXT,thankYouMessage:h=P.THANK_YOU_MESSAGE,onSubmit:G,onOpen:W,onClose:E,onError:ie}){let{disabled:le,activeModalId:V,openModal:_,closeModal:y}=U(),[ce,K]=useState(false),[j,X]=useState(false),[z,Q]=useState(null),[q,S]=useState(false),M=useRef(null);useEffect(()=>{S(window.innerWidth<640);},[]);let R=V===e;useEffect(()=>{if(!o)return;let w=M.current;if(!w)return;let H=w.parentElement;if(!H)return;let we=()=>X(true),Te=()=>X(false);return H.addEventListener("mouseenter",we),H.addEventListener("mouseleave",Te),()=>{H.removeEventListener("mouseenter",we),H.removeEventListener("mouseleave",Te);}},[o]);let{submit:L,isLoading:N,error:B,existingResponse:Ee,isEditing:Z}=Oe({elementId:e,mode:l,experimentId:b,variant:t,pollOptions:s,user:a,onSuccess:w=>{K(true),G?.(w),setTimeout(()=>{y(),K(false);},3e3);},onError:w=>{console.warn("[Gotcha] Submission failed:",w instanceof Error?w.message:w),ie?.(w);}}),Ke=useCallback(()=>{M.current&&Q(M.current.getBoundingClientRect()),_(e),W?.();},[e,_,W]),de=useCallback(()=>{y(),K(false),E?.();},[y,E]),Re=useCallback(w=>{L(w);},[L]);return le||!f?null:jsxs("div",{ref:M,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"}}[c],zIndex:R?1e4:"auto"},className:"gotcha-container","data-gotcha-element":e,children:[jsx(Ue,{size:u,theme:p,customStyles:m,showOnHover:o,touchBehavior:x,onClick:Ke,isOpen:R,isParentHovered:j}),R&&!q&&jsx(ve,{mode:l,theme:p,customStyles:m,promptText:v,placeholder:I,submitText:C,thankYouMessage:Z?"Your feedback has been updated!":h,isLoading:N,isSubmitted:ce,error:B,existingResponse:Ee,isEditing:Z,showText:n,showRating:g,voteLabels:i,options:s,allowMultiple:r,onSubmit:Re,onClose:de,anchorRect:z||void 0}),R&&q&&createPortal(jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,backgroundColor:"rgba(0, 0, 0, 0.3)"},onClick:de,"aria-hidden":"true",children:jsx("div",{onClick:w=>w.stopPropagation(),children:jsx(ve,{mode:l,theme:p,customStyles:m,promptText:v,placeholder:I,submitText:C,thankYouMessage:Z?"Your feedback has been updated!":h,isLoading:N,isSubmitted:ce,error:B,existingResponse:Ee,isEditing:Z,showText:n,showRating:g,voteLabels:i,options:s,allowMultiple:r,onSubmit:Re,onClose:de,anchorRect:z||void 0})})}),document.body)]})}function ft(){let{client:e,disabled:a,defaultUser:l,debug:n}=U();return {client:e,disabled:a,defaultUser:l,debug:n,submitFeedback:e.submitResponse.bind(e)}}export{ut as Gotcha,qe as GotchaProvider,ft as useGotcha};//# sourceMappingURL=index.mjs.map
|
|
12
12
|
//# sourceMappingURL=index.mjs.map
|