@heedb/web-sdk 0.1.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/widget.js +111 -96
package/package.json
CHANGED
package/widget.js
CHANGED
|
@@ -1,156 +1,171 @@
|
|
|
1
|
-
/* Heedb Widget
|
|
2
|
-
"use strict";(()=>{(function(){var
|
|
3
|
-
.
|
|
4
|
-
position: fixed; bottom: 24px; ${
|
|
5
|
-
width: 52px; height: 52px; border-radius: ${
|
|
1
|
+
/* Heedb Widget */
|
|
2
|
+
"use strict";(()=>{(function(){var te,ae,ne,se,oe;let E=document.currentScript||document.querySelector("script[data-api-key]"),H=(te=E==null?void 0:E.getAttribute("data-api-key"))!=null?te:"",Y=(ae=E==null?void 0:E.src)!=null?ae:"",I=(E==null?void 0:E.getAttribute("data-host"))||(Y?new URL(Y).origin:"");if(!H){console.warn("[Heedb] Missing data-api-key on <script> tag.");return}let ie=1,r={},b=!1,re={primary:"#18181b",text:"#18181b",bg:"#ffffff"},de={primary:"#e4e4e7",text:"#e4e4e7",bg:"#1a1a1a"},B={en:{contactTab:"Message",privacyTab:"Privacy",messagesTab:"Messages",nameLabel:"Name",emailLabel:"Email",messageLabel:"Message",namePlaceholder:"Jane Smith",emailPlaceholder:"jane@example.com",messagePlaceholder:"How can we help?",sendMessage:"Send message",sending:"Sending\u2026",fillAllFields:"Please fill in all fields.",messageSentTitle:"Message sent!",messageSentBody:"We'll get back to you soon. Check your inbox for a confirmation email.",networkError:"Network error. Please try again.",somethingWrong:"Something went wrong.",rateLimited:"Too many messages. Please wait a moment.",requestType:"Request type",deleteData:"Delete my data",accessData:"Access my data",exportData:"Export my data",correctData:"Correct my data",restrictProcessing:"Restrict processing",objectProcessing:"Object to processing",other:"Other",submitRequest:"Submit request",submitting:"Submitting\u2026",requestSubmittedTitle:"Request submitted!",requestSubmittedBody:"Your privacy request has been received. We'll respond within 30 days.",contactUs:"Contact us",feedback:"Feedback",poweredBy:"Powered by Heedb",justNow:"Just now",minutesAgo:"{mins}m ago",hoursAgo:"{hours}h ago",send:"Send",backToMessages:"\u2190 Back to messages",noThreadsAuth:"Send a message below to view your message history.",sendAMessage:"+ Send a message",sendNewMessage:"+ Send a new message",noOpenMessages:"No open messages yet.",loading:"Loading\u2026",failedToLoad:"Failed to load messages.",failedToLoadConvo:"Failed to load conversation.",failedToSend:"Failed to send.",typeReply:"Type a reply\u2026",privacyRequest:"Privacy request",message:"Message"},es:{contactTab:"Mensaje",privacyTab:"Privacidad",messagesTab:"Mensajes",nameLabel:"Nombre",emailLabel:"Correo",messageLabel:"Mensaje",namePlaceholder:"Mar\xEDa Garc\xEDa",emailPlaceholder:"maria@empresa.com",messagePlaceholder:"\xBFC\xF3mo podemos ayudarte?",sendMessage:"Enviar mensaje",sending:"Enviando\u2026",fillAllFields:"Por favor, completa todos los campos.",messageSentTitle:"\xA1Mensaje enviado!",messageSentBody:"Te responderemos pronto. Revisa tu bandeja de entrada para un correo de confirmaci\xF3n.",networkError:"Error de red. Int\xE9ntalo de nuevo.",somethingWrong:"Algo sali\xF3 mal.",rateLimited:"Demasiados mensajes. Espera un momento.",requestType:"Tipo de solicitud",deleteData:"Eliminar mis datos",accessData:"Acceder a mis datos",exportData:"Exportar mis datos",correctData:"Corregir mis datos",restrictProcessing:"Restringir procesamiento",objectProcessing:"Oponerse al procesamiento",other:"Otro",submitRequest:"Enviar solicitud",submitting:"Enviando\u2026",requestSubmittedTitle:"\xA1Solicitud enviada!",requestSubmittedBody:"Tu solicitud de privacidad ha sido recibida. Responderemos en un plazo de 30 d\xEDas.",contactUs:"Cont\xE1ctanos",feedback:"Comentarios",poweredBy:"Impulsado por Heedb",justNow:"Ahora",minutesAgo:"hace {mins}m",hoursAgo:"hace {hours}h",send:"Enviar",backToMessages:"\u2190 Volver a mensajes",noThreadsAuth:"Env\xEDa un mensaje para ver tu historial.",sendAMessage:"+ Enviar un mensaje",sendNewMessage:"+ Enviar un nuevo mensaje",noOpenMessages:"No hay mensajes a\xFAn.",loading:"Cargando\u2026",failedToLoad:"No se pudieron cargar los mensajes.",failedToLoadConvo:"No se pudo cargar la conversaci\xF3n.",failedToSend:"No se pudo enviar.",typeReply:"Escribe una respuesta\u2026",privacyRequest:"Solicitud de privacidad",message:"Mensaje"},pt:{contactTab:"Mensagem",privacyTab:"Privacidade",messagesTab:"Mensagens",nameLabel:"Nome",emailLabel:"Email",messageLabel:"Mensagem",namePlaceholder:"Maria Silva",emailPlaceholder:"maria@empresa.com",messagePlaceholder:"Como podemos ajudar?",sendMessage:"Enviar mensagem",sending:"Enviando\u2026",fillAllFields:"Por favor, preencha todos os campos.",messageSentTitle:"Mensagem enviada!",messageSentBody:"Responderemos em breve. Verifique sua caixa de entrada para um email de confirma\xE7\xE3o.",networkError:"Erro de rede. Tente novamente.",somethingWrong:"Algo deu errado.",rateLimited:"Muitas mensagens. Aguarde um momento.",requestType:"Tipo de solicita\xE7\xE3o",deleteData:"Excluir meus dados",accessData:"Acessar meus dados",exportData:"Exportar meus dados",correctData:"Corrigir meus dados",restrictProcessing:"Restringir processamento",objectProcessing:"Opor-se ao processamento",other:"Outro",submitRequest:"Enviar solicita\xE7\xE3o",submitting:"Enviando\u2026",requestSubmittedTitle:"Solicita\xE7\xE3o enviada!",requestSubmittedBody:"Sua solicita\xE7\xE3o de privacidade foi recebida. Responderemos em at\xE9 30 dias.",contactUs:"Fale conosco",feedback:"Feedback",poweredBy:"Powered by Heedb",justNow:"Agora",minutesAgo:"h\xE1 {mins}m",hoursAgo:"h\xE1 {hours}h",send:"Enviar",backToMessages:"\u2190 Voltar \xE0s mensagens",noThreadsAuth:"Envie uma mensagem para ver seu hist\xF3rico.",sendAMessage:"+ Enviar uma mensagem",sendNewMessage:"+ Enviar uma nova mensagem",noOpenMessages:"Nenhuma mensagem ainda.",loading:"Carregando\u2026",failedToLoad:"N\xE3o foi poss\xEDvel carregar as mensagens.",failedToLoadConvo:"N\xE3o foi poss\xEDvel carregar a conversa.",failedToSend:"N\xE3o foi poss\xEDvel enviar.",typeReply:"Digite uma resposta\u2026",privacyRequest:"Solicita\xE7\xE3o de privacidade",message:"Mensagem"}},R="en";function n(e){var t,a,o;return(o=(a=(t=B[R])==null?void 0:t[e])!=null?a:B.en[e])!=null?o:e}function z(e){if(e)return e[R]||e.en}function G(){var a;let e=E==null?void 0:E.getAttribute("data-lang");if(e&&e in B)return e;if(O&&O in B)return O;if(r.language&&r.language in B)return r.language;let t=(a=document.documentElement.lang)==null?void 0:a.slice(0,2);return t&&t in B?t:"en"}let O;function J(){return r.mode==="dark"?!0:r.mode==="light"?!1:r.mode==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches:!1}function le(){return b?de:re}function j(e,t){let a=r[e];return a!=null?String(a):t}let S=!1,k="contact",V="",A=(ne=localStorage.getItem("heedb_name"))!=null?ne:"",T=(se=localStorage.getItem("heedb_email"))!=null?se:"",M=(oe=localStorage.getItem("heedb_token"))!=null?oe:"",f=null,_=null;async function ce(e,t){try{let a=await F("/api/threads/token",{api_key:H,email:e,userHash:t});if(a.ok){let o=await a.json();if(o.widgetToken){M=o.widgetToken,localStorage.setItem("heedb_token",o.widgetToken);return}}M="",localStorage.removeItem("heedb_token")}catch(a){M="",localStorage.removeItem("heedb_token")}}window.Heedb={version:typeof __HEEDB_VERSION__!="undefined"?__HEEDB_VERSION__:"dev",init(e={}){e.lang&&(O=e.lang,R=G(),Z(),S&&f&&C()),e.name&&(A=e.name,localStorage.setItem("heedb_name",e.name)),e.email&&(T=e.email,localStorage.setItem("heedb_email",e.email),e.userHash?ce(e.email,e.userHash).then(()=>{N(),S&&f&&C()}):(N(),S&&f&&C()))},reset(){A="",T="",M="",localStorage.removeItem("heedb_name"),localStorage.removeItem("heedb_email"),localStorage.removeItem("heedb_token"),k="contact",S=!1,f&&(f.style.display="none"),N()}};function F(e,t){return fetch(`${I}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}function pe(e){let t=new URL(`${I}/api/threads`);return t.searchParams.set("api_key",H),t.searchParams.set("email",e),M&&t.searchParams.set("token",M),fetch(t.toString()).then(a=>a.json())}function me(e){let t=new URL(`${I}/api/threads/${e}`);return t.searchParams.set("api_key",H),t.searchParams.set("email",T),t.searchParams.set("token",M),fetch(t.toString()).then(a=>a.json())}function ge(e,t){return F(`/api/threads/${e}/reply`,{api_key:H,email:T,token:M,message:t})}async function ue(){var e;try{let t=new URL(`${I}/api/widget-config`);t.searchParams.set("api_key",H),t.searchParams.set("v",String(ie));let a=await fetch(t.toString());if(a.ok)return(e=(await a.json()).config)!=null?e:{}}catch(t){}return{}}function X(){var g,y;let e=le(),t=j(b?"darkPrimaryColor":"primaryColor",e.primary),a=j(b?"darkTextColor":"textColor",e.text),o=j(b?"darkBgColor":"bgColor",e.bg),i=(g=r.borderRadius)!=null?g:16,d=(y=r.buttonRadius)!=null?y:50,x=r.fontFamily||"system-ui, -apple-system, sans-serif",u=r.position==="bottom-left",c=d>=50?"50%":`${d}px`,p=Math.round(i*.5),l=r.triggerMode==="tag",m=r.triggerMode==="embedded"||l;return`
|
|
3
|
+
.heedb-btn {
|
|
4
|
+
position: fixed; bottom: 24px; ${u?"left: 24px":"right: 24px"}; z-index: 999998;
|
|
5
|
+
width: 52px; height: 52px; border-radius: ${c}; border: none;
|
|
6
6
|
background: ${t}; color: #fff; font-size: 22px; cursor: pointer;
|
|
7
7
|
box-shadow: 0 4px 16px rgba(0,0,0,.25);
|
|
8
|
-
display: ${
|
|
9
|
-
transition: transform .15s;
|
|
10
|
-
}
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
-
.
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
-
position: fixed !important; ${
|
|
18
|
-
transform: ${
|
|
19
|
-
transform-origin: ${
|
|
8
|
+
display: ${m?"none":"flex"}; align-items: center; justify-content: center;
|
|
9
|
+
font-family: ${x}; transition: transform .15s;
|
|
10
|
+
}
|
|
11
|
+
.heedb-btn:hover { transform: scale(1.08); }
|
|
12
|
+
.heedb-btn-label { font-size: 14px; font-weight: 600; margin-left: 6px; }
|
|
13
|
+
.heedb-btn-icon { display: flex; align-items: center; justify-content: center; }
|
|
14
|
+
.heedb-btn-icon svg { width: 22px; height: 22px; fill: currentColor; }
|
|
15
|
+
.heedb-btn:has(.heedb-btn-label) { width: auto; padding: 0 18px; gap: 4px; }
|
|
16
|
+
.heedb-tag {
|
|
17
|
+
position: fixed !important; ${u?"left: 0 !important":"right: 0 !important"}; top: 50% !important; z-index: 999998 !important;
|
|
18
|
+
transform: ${u?"rotate(90deg) translateX(-50%)":"rotate(-90deg) translateX(50%)"} !important;
|
|
19
|
+
transform-origin: ${u?"left bottom":"right bottom"} !important;
|
|
20
20
|
background: ${t}; color: #fff; border: none; cursor: pointer;
|
|
21
21
|
padding: 8px 18px; font-size: 13px; font-weight: 600;
|
|
22
|
-
font-family: ${
|
|
23
|
-
border-radius: ${Math.min(
|
|
22
|
+
font-family: ${x};
|
|
23
|
+
border-radius: ${Math.min(d,12)}px ${Math.min(d,12)}px 0 0;
|
|
24
24
|
box-shadow: 0 2px 12px rgba(0,0,0,.2);
|
|
25
25
|
display: flex; align-items: center; gap: 6px;
|
|
26
26
|
transition: opacity .15s;
|
|
27
27
|
}
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
.
|
|
31
|
-
position: fixed; bottom: 88px; ${
|
|
32
|
-
width:
|
|
33
|
-
background: ${
|
|
28
|
+
.heedb-tag:hover { opacity: .9; }
|
|
29
|
+
.heedb-tag-icon { font-size: 16px; }
|
|
30
|
+
.heedb-panel {
|
|
31
|
+
position: fixed; bottom: 88px; ${u?"left: 24px":"right: 24px"}; z-index: 999999;
|
|
32
|
+
width: 280px; max-height: 560px; border-radius: ${i}px;
|
|
33
|
+
background: ${o}; box-shadow: 0 8px 32px rgba(0,0,0,.18);
|
|
34
34
|
display: flex; flex-direction: column; overflow: hidden;
|
|
35
|
-
font-family: ${
|
|
35
|
+
font-family: ${x}; font-size: 14px; color: ${a};
|
|
36
36
|
transition: opacity .15s, transform .15s;
|
|
37
37
|
}
|
|
38
|
-
.
|
|
38
|
+
.heedb-header {
|
|
39
39
|
background: ${t}; color: #fff; padding: 14px 16px;
|
|
40
40
|
display: flex; align-items: center; justify-content: space-between;
|
|
41
41
|
}
|
|
42
|
-
.
|
|
43
|
-
.
|
|
42
|
+
.heedb-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
|
|
43
|
+
.heedb-close {
|
|
44
44
|
background: none; border: none; color: #fff; cursor: pointer;
|
|
45
45
|
font-size: 18px; line-height: 1; padding: 0;
|
|
46
46
|
}
|
|
47
|
-
.
|
|
48
|
-
display: flex; border-bottom: 1px solid ${
|
|
47
|
+
.heedb-tabs {
|
|
48
|
+
display: flex; border-bottom: 1px solid ${b?"#333":"#e4e4e7"};
|
|
49
49
|
}
|
|
50
|
-
.
|
|
50
|
+
.heedb-tab {
|
|
51
51
|
flex: 1; padding: 10px 0; border: none; background: none;
|
|
52
52
|
cursor: pointer; font-size: 13px; font-weight: 500; color: #71717a;
|
|
53
53
|
border-bottom: 2px solid transparent; margin-bottom: -1px;
|
|
54
54
|
}
|
|
55
|
-
.
|
|
56
|
-
.
|
|
57
|
-
.
|
|
58
|
-
.
|
|
55
|
+
.heedb-tab.active { color: ${a}; border-bottom-color: ${t}; }
|
|
56
|
+
.heedb-body { padding: 16px; overflow-y: auto; flex: 1; }
|
|
57
|
+
.heedb-label { display: block; font-size: 12px; font-weight: 600; color: #52525b; margin-bottom: 4px; }
|
|
58
|
+
.heedb-input, .heedb-textarea, .heedb-select {
|
|
59
59
|
width: 100%; box-sizing: border-box; padding: 8px 10px;
|
|
60
|
-
border: 1px solid ${
|
|
61
|
-
font-size: 13px; color: ${
|
|
62
|
-
font-family: inherit; background: ${
|
|
60
|
+
border: 1px solid ${b?"#444":"#d4d4d8"}; border-radius: ${p}px;
|
|
61
|
+
font-size: 13px; color: ${a}; margin-bottom: 10px;
|
|
62
|
+
font-family: inherit; background: ${b?"#222":o};
|
|
63
63
|
}
|
|
64
|
-
.
|
|
65
|
-
.
|
|
64
|
+
.heedb-textarea { min-height: 80px; resize: vertical; }
|
|
65
|
+
.heedb-input:focus, .heedb-textarea:focus, .heedb-select:focus {
|
|
66
66
|
outline: none; border-color: ${t};
|
|
67
67
|
}
|
|
68
|
-
.
|
|
68
|
+
.heedb-btn-submit {
|
|
69
69
|
width: 100%; padding: 10px; background: ${t}; color: #fff;
|
|
70
|
-
border: none; border-radius: ${
|
|
70
|
+
border: none; border-radius: ${p}px; font-size: 14px; font-weight: 600;
|
|
71
71
|
cursor: pointer; transition: opacity .15s;
|
|
72
72
|
}
|
|
73
|
-
.
|
|
74
|
-
.
|
|
75
|
-
.
|
|
76
|
-
.
|
|
77
|
-
.
|
|
78
|
-
.
|
|
79
|
-
.
|
|
80
|
-
.
|
|
81
|
-
padding: 10px 12px; border: 1px solid ${
|
|
73
|
+
.heedb-btn-submit:hover { opacity: .85; }
|
|
74
|
+
.heedb-btn-submit:disabled { opacity: .5; cursor: not-allowed; }
|
|
75
|
+
.heedb-error { color: #ef4444; font-size: 12px; margin-bottom: 8px; }
|
|
76
|
+
.heedb-success { text-align: center; padding: 24px 8px; }
|
|
77
|
+
.heedb-success-icon { font-size: 36px; }
|
|
78
|
+
.heedb-success h3 { margin: 12px 0 6px; font-size: 15px; color: ${a}; }
|
|
79
|
+
.heedb-success p { margin: 0; color: #71717a; font-size: 13px; line-height: 1.5; }
|
|
80
|
+
.heedb-thread-item {
|
|
81
|
+
padding: 10px 12px; border: 1px solid ${b?"#333":"#e4e4e7"}; border-radius: ${p}px;
|
|
82
82
|
margin-bottom: 8px; cursor: pointer; display: block; color: inherit;
|
|
83
83
|
transition: background .1s; background: none;
|
|
84
84
|
}
|
|
85
|
-
.
|
|
86
|
-
.
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
-
.
|
|
90
|
-
.
|
|
91
|
-
.
|
|
92
|
-
.
|
|
93
|
-
.
|
|
94
|
-
width: 100%; padding: 8px; background: none; border: 1px solid ${
|
|
95
|
-
border-radius: ${
|
|
96
|
-
}
|
|
97
|
-
.
|
|
98
|
-
.
|
|
99
|
-
padding: 6px 16px; text-align: center; border-top: 1px solid ${
|
|
100
|
-
}
|
|
101
|
-
.
|
|
85
|
+
.heedb-thread-item:hover { background: ${b?"#252525":"#f4f4f5"}; }
|
|
86
|
+
.heedb-thread-label { font-size: 12px; color: #71717a; margin-bottom: 2px; }
|
|
87
|
+
.heedb-thread-text { font-size: 13px; color: ${a}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
88
|
+
.heedb-thread-meta { font-size: 11px; color: #a1a1aa; margin-top: 3px; }
|
|
89
|
+
.heedb-badge { display: inline-block; padding: 1px 6px; border-radius: 9999px; font-size: 10px; font-weight: 600; }
|
|
90
|
+
.heedb-badge-open { background: #d1fae5; color: #065f46; }
|
|
91
|
+
.heedb-badge-replied { background: #dbeafe; color: #1e40af; }
|
|
92
|
+
.heedb-new-msg { margin-top: 12px; padding-top: 12px; border-top: 1px solid ${b?"#333":"#e4e4e7"}; }
|
|
93
|
+
.heedb-new-msg button {
|
|
94
|
+
width: 100%; padding: 8px; background: none; border: 1px solid ${b?"#444":"#d4d4d8"};
|
|
95
|
+
border-radius: ${p}px; font-size: 13px; cursor: pointer; color: ${b?"#999":"#52525b"};
|
|
96
|
+
}
|
|
97
|
+
.heedb-new-msg button:hover { background: ${b?"#252525":"#f4f4f5"}; }
|
|
98
|
+
.heedb-footer {
|
|
99
|
+
padding: 6px 16px; text-align: center; border-top: 1px solid ${b?"#333":"#f0f0f0"};
|
|
100
|
+
}
|
|
101
|
+
.heedb-footer a {
|
|
102
102
|
font-size: 10px; color: #a1a1aa; text-decoration: none; font-weight: 500;
|
|
103
103
|
}
|
|
104
|
-
.
|
|
104
|
+
.heedb-footer a:hover { color: #71717a; text-decoration: underline; }
|
|
105
105
|
|
|
106
106
|
/* Chat view */
|
|
107
|
-
.
|
|
107
|
+
.heedb-chat-back {
|
|
108
108
|
background: none; border: none; cursor: pointer; font-size: 13px;
|
|
109
109
|
color: ${t}; padding: 0; margin-bottom: 12px; font-weight: 500;
|
|
110
110
|
display: flex; align-items: center; gap: 4px;
|
|
111
111
|
}
|
|
112
|
-
.
|
|
113
|
-
.
|
|
112
|
+
.heedb-chat-back:hover { text-decoration: underline; }
|
|
113
|
+
.heedb-chat-messages {
|
|
114
114
|
display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px;
|
|
115
115
|
max-height: 320px; overflow-y: auto;
|
|
116
116
|
}
|
|
117
|
-
.
|
|
118
|
-
padding: 8px 12px; border-radius: ${Math.max(
|
|
117
|
+
.heedb-chat-bubble {
|
|
118
|
+
padding: 8px 12px; border-radius: ${Math.max(p,8)}px; font-size: 13px;
|
|
119
119
|
line-height: 1.45; max-width: 85%; word-wrap: break-word;
|
|
120
120
|
white-space: pre-wrap;
|
|
121
121
|
}
|
|
122
|
-
.
|
|
123
|
-
background: ${
|
|
122
|
+
.heedb-chat-inbound {
|
|
123
|
+
background: ${b?"#252525":"#f4f4f5"}; color: ${a}; align-self: flex-start;
|
|
124
124
|
border-bottom-left-radius: 4px;
|
|
125
125
|
}
|
|
126
|
-
.
|
|
126
|
+
.heedb-chat-outbound {
|
|
127
127
|
background: ${t}; color: #fff; align-self: flex-end;
|
|
128
128
|
border-bottom-right-radius: 4px;
|
|
129
129
|
}
|
|
130
|
-
.
|
|
130
|
+
.heedb-chat-time {
|
|
131
131
|
font-size: 10px; color: #a1a1aa; margin-top: 2px;
|
|
132
132
|
}
|
|
133
|
-
.
|
|
134
|
-
.
|
|
135
|
-
display: flex; gap: 8px; border-top: 1px solid ${
|
|
133
|
+
.heedb-chat-time-right { text-align: right; }
|
|
134
|
+
.heedb-chat-reply {
|
|
135
|
+
display: flex; gap: 8px; border-top: 1px solid ${b?"#333":"#e4e4e7"}; padding-top: 12px;
|
|
136
136
|
}
|
|
137
|
-
.
|
|
138
|
-
flex: 1; padding: 8px 10px; border: 1px solid ${
|
|
139
|
-
font-size: 13px; font-family: inherit; color: ${
|
|
137
|
+
.heedb-chat-reply-input {
|
|
138
|
+
flex: 1; padding: 8px 10px; border: 1px solid ${b?"#444":"#d4d4d8"}; border-radius: ${p}px;
|
|
139
|
+
font-size: 13px; font-family: inherit; color: ${a}; background: ${b?"#222":o};
|
|
140
140
|
resize: none; min-height: 36px; max-height: 80px; box-sizing: border-box;
|
|
141
141
|
}
|
|
142
|
-
.
|
|
143
|
-
.
|
|
142
|
+
.heedb-chat-reply-input:focus { outline: none; border-color: ${t}; }
|
|
143
|
+
.heedb-chat-send {
|
|
144
144
|
padding: 8px 14px; background: ${t}; color: #fff; border: none;
|
|
145
|
-
border-radius: ${
|
|
145
|
+
border-radius: ${p}px; font-size: 13px; font-weight: 600; cursor: pointer;
|
|
146
146
|
transition: opacity .15s; white-space: nowrap; align-self: flex-end;
|
|
147
147
|
}
|
|
148
|
-
.
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
.heedb-chat-send:hover { opacity: .85; }
|
|
149
|
+
.heedb-chat-send:disabled { opacity: .5; cursor: not-allowed; }
|
|
150
|
+
|
|
151
|
+
/* Skeleton loading */
|
|
152
|
+
.heedb-skeleton { pointer-events: none; }
|
|
153
|
+
.heedb-skel-line {
|
|
154
|
+
background: ${b?"#333":"#e4e4e7"};
|
|
155
|
+
border-radius: 4px;
|
|
156
|
+
animation: heedb-pulse 1.5s ease-in-out infinite;
|
|
157
|
+
}
|
|
158
|
+
@keyframes heedb-pulse {
|
|
159
|
+
0%, 100% { opacity: 0.4; }
|
|
160
|
+
50% { opacity: 1; }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* Body fade transition */
|
|
164
|
+
.heedb-body { transition: opacity .15s ease; }
|
|
165
|
+
`}function s(e,t={},a=[]){let o=document.createElement(e);for(let[i,d]of Object.entries(t))i==="class"?o.className=d:i==="style"?o.setAttribute("style",d):i.startsWith("on")&&typeof d=="function"?o.addEventListener(i.slice(2),d):o.setAttribute(i,String(d));for(let i of a)o.appendChild(typeof i=="string"?document.createTextNode(i):i);return o}function W(e,t,a=""){let o=document.createElement("input");return o.type=e,o.id=t,o.placeholder=a,o.className="heedb-input",o}function he(e,t=""){let a=document.createElement("textarea");return a.id=e,a.placeholder=t,a.className="heedb-textarea",a}function be(e,t){let a=document.createElement("select");a.id=e,a.className="heedb-select";for(let o of t){let i=document.createElement("option");i.value=o.value,i.textContent=o.label,a.appendChild(i)}return a}function C(){if(!f)return;let e=f.querySelector(".heedb-body");e.innerHTML="",k==="contact"?fe(e):k==="privacy"?xe(e):k==="threads"?ye(e):k==="thread-detail"&&Te(e),$&&($.style.display=k==="thread-detail"?"none":"flex")}function fe(e,t=""){let a=!!(A&&T),o=s("label",{class:"heedb-label"},[n("nameLabel")]),i=W("text","heedb-name",n("namePlaceholder"));A&&(i.value=A);let d=s("label",{class:"heedb-label"},[n("emailLabel")]),x=W("email","heedb-email",n("emailPlaceholder"));(t||T)&&(x.value=t||T);let u=z(r.messageLabel),c=u?s("label",{class:"heedb-label"},[u]):null,p=he("heedb-message",z(r.messagePlaceholder)||n("messagePlaceholder")),l=s("div",{class:"heedb-error",style:"display:none"}),m=s("button",{class:"heedb-btn-submit"},[n("sendMessage")]);m.onclick=async()=>{var w;let g=i.value.trim(),y=x.value.trim(),h=p.value.trim();if(l.style.display="none",!g||!y||!h){l.textContent=n("fillAllFields"),l.style.display="block";return}m.disabled=!0,m.textContent=n("sending");try{let v=await F("/api/contact",{api_key:H,name:g,email:y,message:h,lang:R});if(v.ok)T=y,localStorage.setItem("heedb_email",y),N(),Q(e,n("messageSentTitle"),n("messageSentBody"));else if(v.status===429){let L=parseInt((w=v.headers.get("Retry-After"))!=null?w:"60",10);l.textContent=n("rateLimited"),l.style.display="block",m.textContent=n("sendMessage"),setTimeout(()=>{m.disabled=!1,l.style.display="none"},L*1e3)}else{let L=await v.json();l.textContent=L.error||n("somethingWrong"),l.style.display="block",m.disabled=!1,m.textContent=n("sendMessage")}}catch(v){l.textContent=n("networkError"),l.style.display="block",m.disabled=!1,m.textContent=n("sendMessage")}},a?(c&&e.append(c),e.append(p,l,m)):(e.append(o,i,d,x),c&&e.append(c),e.append(p,l,m))}function xe(e){let t=!!(A&&T),a=s("label",{class:"heedb-label"},[n("nameLabel")]),o=W("text","heedb-priv-name",n("namePlaceholder"));A&&(o.value=A);let i=s("label",{class:"heedb-label"},[n("emailLabel")]),d=W("email","heedb-priv-email",n("emailPlaceholder"));T&&(d.value=T);let x=s("label",{class:"heedb-label"},[n("requestType")]),u=be("heedb-priv-type",[{value:"deletion",label:n("deleteData")},{value:"access",label:n("accessData")},{value:"portability",label:n("exportData")}]),c=s("div",{class:"heedb-error",style:"display:none"}),p=s("button",{class:"heedb-btn-submit"},[n("submitRequest")]);p.onclick=async()=>{var y;let l=o.value.trim(),m=d.value.trim(),g=u.value;if(c.style.display="none",!l||!m){c.textContent=n("fillAllFields"),c.style.display="block";return}p.disabled=!0,p.textContent=n("submitting");try{let h=await F("/api/privacy-request",{api_key:H,name:l,email:m,request_type:g,lang:R});if(h.ok)T=m,localStorage.setItem("heedb_email",m),N(),Q(e,n("requestSubmittedTitle"),n("requestSubmittedBody"));else if(h.status===429){let w=parseInt((y=h.headers.get("Retry-After"))!=null?y:"60",10);c.textContent=n("rateLimited"),c.style.display="block",p.textContent=n("submitRequest"),setTimeout(()=>{p.disabled=!1,c.style.display="none"},w*1e3)}else{let w=await h.json();c.textContent=w.error||n("somethingWrong"),c.style.display="block",p.disabled=!1,p.textContent=n("submitRequest")}}catch(h){c.textContent=n("networkError"),c.style.display="block",p.disabled=!1,p.textContent=n("submitRequest")}},t?e.append(x,u,c,p):e.append(a,o,i,d,x,u,c,p)}async function ye(e){var t;if(!M){e.innerHTML="";let a=s("p",{style:"color:#71717a;text-align:center;margin:8px 0;font-size:13px;line-height:1.5"},[n("noThreadsAuth")]),o=s("div",{class:"heedb-new-msg"}),i=s("button",{},[n("sendAMessage")]);i.onclick=()=>{k="contact",P("contact"),C()},o.appendChild(i),e.append(a,o);return}e.innerHTML="";for(let a=0;a<3;a++){let o=s("div",{class:"heedb-thread-item heedb-skeleton"});o.append(s("div",{class:"heedb-skel-line",style:"width:40%;height:12px"}),s("div",{class:"heedb-skel-line",style:"width:80%;height:13px;margin-top:6px"}),s("div",{class:"heedb-skel-line",style:"width:30%;height:11px;margin-top:4px"})),e.appendChild(o)}try{let{threads:a}=await pe(T);if(e.innerHTML="",e.style.opacity="0",requestAnimationFrame(()=>{e.style.opacity="1"}),a.length===0){let d=s("p",{style:"color:#71717a;text-align:center;margin:8px 0"},[z(r.emptyStateText)||n("noOpenMessages")]);e.appendChild(d)}else for(let d of a){let x=s("span",{class:`heedb-badge heedb-badge-${d.status}`},[d.status]),u=s("div",{class:"heedb-thread-label"},[d.type==="privacy"?n("privacyRequest"):n("message")," \u2022 "]);u.appendChild(x);let c=s("div",{class:"heedb-thread-text"},[(t=d.preview)!=null?t:""]),p=new Date(d.createdAt).toLocaleDateString(),l=s("div",{class:"heedb-thread-meta"},[p]),m=s("div",{class:"heedb-thread-item"});m.append(u,c,l),m.onclick=()=>ve(d.id),e.appendChild(m)}let o=s("div",{class:"heedb-new-msg"}),i=s("button",{},[n("sendNewMessage")]);i.onclick=()=>{k="contact",P("contact"),C()},o.appendChild(i),e.appendChild(o)}catch(a){e.innerHTML=`<p style="color:#ef4444;text-align:center">${n("failedToLoad")}</p>`}}function ve(e){V=e,k="thread-detail",C()}async function Te(e){e.innerHTML="",e.style.padding="12px";let t=s("div",{class:"heedb-skel-line",style:"width:50%;height:13px;margin-bottom:12px"});e.appendChild(t);let a=s("div",{style:"display:flex;flex-direction:column;gap:8px"}),o=["65%","50%","70%","45%"],i=["flex-start","flex-end","flex-start","flex-end"];for(let x=0;x<4;x++){let u=s("div",{style:`display:flex;flex-direction:column;align-items:${i[x]}`});u.appendChild(s("div",{class:"heedb-skel-line",style:`width:${o[x]};height:32px;border-radius:8px`})),a.appendChild(u)}e.appendChild(a);let d=s("button",{class:"heedb-chat-back"},[n("backToMessages")]);d.onclick=()=>{k="threads",P("threads"),C()};try{let u=(await me(V)).messages||[];e.innerHTML="",e.style.padding="12px",e.appendChild(d);let c=s("div",{class:"heedb-chat-messages"});for(let h of u){let w=h.direction==="inbound",v=s("div",{style:`display:flex;flex-direction:column;${w?"align-items:flex-start":"align-items:flex-end"}`}),L=s("div",{class:`heedb-chat-bubble ${w?"heedb-chat-inbound":"heedb-chat-outbound"}`},[we(h.body)]),K=s("div",{class:`heedb-chat-time ${w?"":"heedb-chat-time-right"}`},[ke(h.createdAt)]);v.append(L,K),c.appendChild(v)}e.appendChild(c),requestAnimationFrame(()=>{c.scrollTop=c.scrollHeight});let p=s("div",{class:"heedb-chat-reply"}),l=document.createElement("textarea");l.className="heedb-chat-reply-input",l.placeholder=n("typeReply"),l.rows=1,l.addEventListener("input",()=>{l.style.height="auto",l.style.height=Math.min(l.scrollHeight,80)+"px"});let m=s("button",{class:"heedb-chat-send"},[n("send")]),g=s("div",{class:"heedb-error",style:"display:none;margin-top:4px"});async function y(){let h=l.value.trim();if(h){m.disabled=!0,m.textContent="\u2026",g.style.display="none";try{let w=await ge(V,h);if(w.ok){let v=s("div",{style:"display:flex;flex-direction:column;align-items:flex-start"}),L=s("div",{class:"heedb-chat-bubble heedb-chat-inbound"},[h]),K=s("div",{class:"heedb-chat-time"},[n("justNow")]);v.append(L,K),c.appendChild(v),c.scrollTop=c.scrollHeight,l.value="",l.style.height="auto"}else{let v=await w.json();g.textContent=v.error||n("failedToSend"),g.style.display="block"}}catch(w){g.textContent=n("networkError"),g.style.display="block"}m.disabled=!1,m.textContent=n("send")}}m.onclick=y,l.addEventListener("keydown",h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),y())}),p.append(l,m),e.append(p,g),requestAnimationFrame(()=>l.focus())}catch(x){e.innerHTML="",e.appendChild(d),e.appendChild(s("p",{style:"color:#ef4444;text-align:center"},[n("failedToLoadConvo")]))}}function we(e){let t=e.split(`
|
|
166
|
+
`),a=[];for(let o of t){let i=o.trim();if(/^(On|Em|El|Le|Am|Il giorno) .+(<[^>]+@[^>]+>).*(wrote|escreveu|escribi|crit|schrieb|scritto)\s?:$/i.test(i)||/<[^>]+@[^>]+>/.test(i)&&i.endsWith(":")||/^-{3,}$/.test(i))break;/^>{1,}\s/.test(i)||a.push(o)}return a.join(`
|
|
167
|
+
`).trim()}function ke(e){let t=new Date(e),o=new Date().getTime()-t.getTime(),i=Math.floor(o/6e4);if(i<1)return n("justNow");if(i<60)return n("minutesAgo").replace("{mins}",String(i));let d=Math.floor(i/60);return d<24?n("hoursAgo").replace("{hours}",String(d)):t.toLocaleDateString()}function Q(e,t,a){e.innerHTML="";let o=s("div",{class:"heedb-success"});o.innerHTML=`
|
|
168
|
+
<div class="heedb-success-icon">\u2705</div>
|
|
154
169
|
<h3>${t}</h3>
|
|
155
|
-
<p>${
|
|
156
|
-
`,e.appendChild(
|
|
170
|
+
<p>${a}</p>
|
|
171
|
+
`,e.appendChild(o)}let $=null,D=null;function P(e){k=e,$&&$.querySelectorAll(".heedb-tab").forEach(t=>{t.classList.toggle("active",t.dataset.mode===e)})}function N(){D&&(D.style.display=T&&M?"":"none")}let q=null;function Z(){b=J(),q&&(q.textContent=X())}async function ee(){if(r=await ue(),R=G(),b=J(),q=document.createElement("style"),q.textContent=X(),document.head.appendChild(q),r.customCSS){let g=document.createElement("style");g.textContent=r.customCSS,document.head.appendChild(g)}r.mode==="system"&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{Z(),S&&f&&C()});let e=r.triggerIcon?r.triggerIcon:r.triggerEmoji||"\u{1F4AC}",t=r.triggerText||"";if(_=s("button",{class:"heedb-btn",title:n("contactUs"),"aria-label":"Open contact widget"}),r.triggerIcon){let g=s("span",{class:"heedb-btn-icon"}),h=new DOMParser().parseFromString(r.triggerIcon,"image/svg+xml").querySelector("svg");if(h){h.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(L=>L.remove());let w=document.createTreeWalker(h,NodeFilter.SHOW_ELEMENT),v;for(;v=w.nextNode();)for(let L of Array.from(v.attributes))(L.name.startsWith("on")||/^\s*javascript:/i.test(L.value))&&v.removeAttribute(L.name);g.appendChild(h)}_.appendChild(g)}else _.appendChild(document.createTextNode(r.triggerEmoji||"\u{1F4AC}"));if(t&&_.appendChild(s("span",{class:"heedb-btn-label"},[t])),_.onclick=U,document.body.appendChild(_),r.triggerMode==="embedded"&&r.triggerSelector){let g=document.querySelector(r.triggerSelector);g&&g.addEventListener("click",y=>{y.preventDefault(),U()})}if(r.triggerMode==="tag"){let g=s("button",{class:"heedb-tag","aria-label":"Open contact widget"}),y=s("span",{class:"heedb-tag-icon"},[r.triggerEmoji||"\u{1F4AC}"]);g.appendChild(y),g.appendChild(document.createTextNode(r.triggerText||n("feedback"))),g.onclick=U,document.body.appendChild(g)}f=s("div",{class:"heedb-panel",style:"display:none"});let a=s("div",{class:"heedb-header"}),o=s("h2",{},[r.headerTitle||n("contactUs")]),i=s("button",{class:"heedb-close","aria-label":"Close"},["\u2715"]);i.onclick=U,a.append(o,i),$=s("div",{class:"heedb-tabs"});let d=s("button",{class:"heedb-tab active","data-mode":"contact"},[z(r.contactTabLabel)||n("contactTab")]),u=r.showPrivacyTab!==!1?s("button",{class:"heedb-tab","data-mode":"privacy"},[n("privacyTab")]):null;D=s("button",{class:"heedb-tab","data-mode":"threads"},[n("messagesTab")]),D.style.display=T&&M?"":"none",d.onclick=()=>{P("contact"),C()},u&&(u.onclick=()=>{P("privacy"),C()}),D.onclick=()=>{P("threads"),C()},$.append(d),u&&$.append(u),$.append(D);let c=s("div",{class:"heedb-body"}),p=s("div",{class:"heedb-footer"}),l=new URLSearchParams({utm_source:"widget",utm_medium:"heedb-widget",utm_campaign:window.location.hostname}),m=s("a",{href:`https://heedb.com?${l.toString()}`,target:"_blank",rel:"noopener noreferrer"},[n("poweredBy")]);p.appendChild(m),f.append(a,$,c,p),document.body.appendChild(f)}function U(){S=!S,f&&(S?(f.style.display="flex",f.style.opacity="0",f.style.transform="translateY(8px)",requestAnimationFrame(()=>{f.style.opacity="1",f.style.transform="translateY(0)"}),T&&M&&k!=="privacy"&&k!=="thread-detail"&&(k="threads",P("threads")),C()):(f.style.opacity="0",f.style.transform="translateY(8px)",setTimeout(()=>{!S&&f&&(f.style.display="none")},150)))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ee):ee()})();})();
|