@heedb/web-sdk 0.1.6 → 0.1.7
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/widget.js +10 -10
- package/package.json +1 -1
- package/widget.js +10 -10
package/dist/widget.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* Heedb Widget v0.1.
|
|
2
|
-
"use strict";(()=>{(function(){var W,U,K,J,V;let w=document.currentScript||document.querySelector("script[data-api-key]"),E=(W=w==null?void 0:w.getAttribute("data-api-key"))!=null?W:"",N=(U=w==null?void 0:w.src)!=null?U:"",I=(w==null?void 0:w.getAttribute("data-host"))||(N?new URL(N).origin:"");if(!E){console.warn("[Heedb] Missing data-api-key on <script> tag.");return}let
|
|
1
|
+
/* Heedb Widget v0.1.7 — https://heedb.com */
|
|
2
|
+
"use strict";(()=>{(function(){var W,U,K,J,V;let w=document.currentScript||document.querySelector("script[data-api-key]"),E=(W=w==null?void 0:w.getAttribute("data-api-key"))!=null?W:"",N=(U=w==null?void 0:w.src)!=null?U:"",I=(w==null?void 0:w.getAttribute("data-host"))||(N?new URL(N).origin:"");if(!E){console.warn("[Heedb] Missing data-api-key on <script> tag.");return}let c={},u=!1,X={primary:"#18181b",text:"#18181b",bg:"#ffffff"},G={primary:"#e4e4e7",text:"#e4e4e7",bg:"#1a1a1a"};function R(){return c.mode==="dark"?!0:c.mode==="light"?!1:c.mode==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches:!1}function Y(){return u?G:X}function $(e,t){let n=c[e];return n!=null?String(n):t}let C=!1,h="contact",A="",L=(K=localStorage.getItem("heedb_name"))!=null?K:"",b=(J=localStorage.getItem("heedb_email"))!=null?J:"",y=(V=localStorage.getItem("heedb_token"))!=null?V:"",v=null,H=null;async function Q(e,t){try{let n=await D("/api/threads/token",{api_key:E,email:e,userHash:t});if(n.ok){let l=await n.json();if(l.widgetToken){y=l.widgetToken,localStorage.setItem("heedb_token",l.widgetToken);return}}y="",localStorage.removeItem("heedb_token")}catch(n){y="",localStorage.removeItem("heedb_token")}}window.Heedb={version:"0.1.7",init(e={}){e.name&&(L=e.name,localStorage.setItem("heedb_name",e.name)),e.email&&(b=e.email,localStorage.setItem("heedb_email",e.email),e.userHash?Q(e.email,e.userHash).then(()=>{z(),C&&v&&k()}):(z(),C&&v&&k()))},reset(){L="",b="",y="",localStorage.removeItem("heedb_name"),localStorage.removeItem("heedb_email"),localStorage.removeItem("heedb_token"),h="contact",C=!1,v&&(v.style.display="none"),z()}};function D(e,t){return fetch(`${I}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}function Z(e){let t=new URL(`${I}/api/threads`);return t.searchParams.set("api_key",E),t.searchParams.set("email",e),y&&t.searchParams.set("token",y),fetch(t.toString()).then(n=>n.json())}function ee(e){let t=new URL(`${I}/api/threads/${e}`);return t.searchParams.set("api_key",E),t.searchParams.set("email",b),t.searchParams.set("token",y),fetch(t.toString()).then(n=>n.json())}function te(e,t){return D(`/api/threads/${e}/reply`,{api_key:E,email:b,token:y,message:t})}async function ne(){var e;try{let t=new URL(`${I}/api/widget-config`);t.searchParams.set("api_key",E);let n=await fetch(t.toString());if(n.ok)return(e=(await n.json()).config)!=null?e:{}}catch(t){}return{}}function O(){var f,x;let e=Y(),t=$(u?"darkPrimaryColor":"primaryColor",e.primary),n=$(u?"darkTextColor":"textColor",e.text),l=$(u?"darkBgColor":"bgColor",e.bg),o=(f=c.borderRadius)!=null?f:16,r=(x=c.buttonRadius)!=null?x:50,d=c.fontFamily||"system-ui, -apple-system, sans-serif",m=c.position==="bottom-left",p=r>=50?"50%":`${r}px`,s=Math.round(o*.5),i=c.triggerMode==="tag",g=c.triggerMode==="embedded"||i;return`
|
|
3
3
|
.llp-btn {
|
|
4
4
|
position: fixed; bottom: 24px; ${m?"left: 24px":"right: 24px"}; z-index: 999998;
|
|
5
|
-
width: 52px; height: 52px; border-radius: ${
|
|
5
|
+
width: 52px; height: 52px; border-radius: ${p}; 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
8
|
display: ${g?"none":"flex"}; align-items: center; justify-content: center;
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
.llp-btn-icon svg { width: 22px; height: 22px; fill: currentColor; }
|
|
15
15
|
.llp-btn:has(.llp-btn-label) { width: auto; padding: 0 18px; gap: 4px; }
|
|
16
16
|
.llp-tag {
|
|
17
|
-
position: fixed; ${m?"left: 0":"right: 0"}; top: 50
|
|
18
|
-
transform: ${m?"rotate(90deg) translateX(-50%)":"rotate(-90deg) translateX(50%)"};
|
|
19
|
-
transform-origin: ${m?"left
|
|
17
|
+
position: fixed !important; ${m?"left: 0 !important":"right: 0 !important"}; top: 50% !important; z-index: 999998 !important;
|
|
18
|
+
transform: ${m?"rotate(90deg) translateX(-50%)":"rotate(-90deg) translateX(50%)"} !important;
|
|
19
|
+
transform-origin: ${m?"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: ${
|
|
22
|
+
font-family: ${d};
|
|
23
23
|
border-radius: ${Math.min(r,12)}px ${Math.min(r,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;
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
width: 370px; max-height: 560px; border-radius: ${o}px;
|
|
33
33
|
background: ${l}; 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: ${d}; font-size: 14px; color: ${n};
|
|
36
36
|
transition: opacity .15s, transform .15s;
|
|
37
37
|
}
|
|
38
38
|
.llp-header {
|
|
@@ -147,10 +147,10 @@
|
|
|
147
147
|
}
|
|
148
148
|
.llp-chat-send:hover { opacity: .85; }
|
|
149
149
|
.llp-chat-send:disabled { opacity: .5; cursor: not-allowed; }
|
|
150
|
-
`}function a(e,t={},n=[]){let l=document.createElement(e);for(let[o,r]of Object.entries(t))o==="class"?l.className=r:o==="style"?l.setAttribute("style",r):o.startsWith("on")&&typeof r=="function"?l.addEventListener(o.slice(2),r):l.setAttribute(o,String(r));for(let o of n)l.appendChild(typeof o=="string"?document.createTextNode(o):o);return l}function P(e,t,n=""){let l=document.createElement("input");return l.type=e,l.id=t,l.placeholder=n,l.className="llp-input",l}function ae(e,t=""){let n=document.createElement("textarea");return n.id=e,n.placeholder=t,n.className="llp-textarea",n}function oe(e,t){let n=document.createElement("select");n.id=e,n.className="llp-select";for(let l of t){let o=document.createElement("option");o.value=l.value,o.textContent=l.label,n.appendChild(o)}return n}function k(){if(!v)return;let e=v.querySelector(".llp-body");e.innerHTML="",h==="contact"?le(e):h==="privacy"?ie(e):h==="threads"?re(e):h==="thread-detail"&&ce(e),M&&(M.style.display=h==="thread-detail"?"none":"flex")}function le(e,t=""){let n=!!(
|
|
150
|
+
`}function a(e,t={},n=[]){let l=document.createElement(e);for(let[o,r]of Object.entries(t))o==="class"?l.className=r:o==="style"?l.setAttribute("style",r):o.startsWith("on")&&typeof r=="function"?l.addEventListener(o.slice(2),r):l.setAttribute(o,String(r));for(let o of n)l.appendChild(typeof o=="string"?document.createTextNode(o):o);return l}function P(e,t,n=""){let l=document.createElement("input");return l.type=e,l.id=t,l.placeholder=n,l.className="llp-input",l}function ae(e,t=""){let n=document.createElement("textarea");return n.id=e,n.placeholder=t,n.className="llp-textarea",n}function oe(e,t){let n=document.createElement("select");n.id=e,n.className="llp-select";for(let l of t){let o=document.createElement("option");o.value=l.value,o.textContent=l.label,n.appendChild(o)}return n}function k(){if(!v)return;let e=v.querySelector(".llp-body");e.innerHTML="",h==="contact"?le(e):h==="privacy"?ie(e):h==="threads"?re(e):h==="thread-detail"&&ce(e),M&&(M.style.display=h==="thread-detail"?"none":"flex")}function le(e,t=""){let n=!!(L&&b),l=a("label",{class:"llp-label"},["Name"]),o=P("text","llp-name","Jane Smith");L&&(o.value=L);let r=a("label",{class:"llp-label"},["Email"]),d=P("email","llp-email","jane@example.com");(t||b)&&(d.value=t||b);let m=a("label",{class:"llp-label"},["Message"]),p=ae("llp-message","How can we help?"),s=a("div",{class:"llp-error",style:"display:none"}),i=a("button",{class:"llp-btn-submit"},["Send message"]);i.onclick=async()=>{let g=o.value.trim(),f=d.value.trim(),x=p.value.trim();if(s.style.display="none",!g||!f||!x){s.textContent="Please fill in all fields.",s.style.display="block";return}i.disabled=!0,i.textContent="Sending\u2026";try{let T=await D("/api/contact",{api_key:E,name:g,email:f,message:x});if(T.ok)b=f,localStorage.setItem("heedb_email",f),z(),q(e,"Message sent!","We'll get back to you soon. Check your inbox for a confirmation email.");else{let me=await T.json();s.textContent=me.error||"Something went wrong.",s.style.display="block",i.disabled=!1,i.textContent="Send message"}}catch(T){s.textContent="Network error. Please try again.",s.style.display="block",i.disabled=!1,i.textContent="Send message"}},n?e.append(m,p,s,i):e.append(l,o,r,d,m,p,s,i)}function ie(e){let t=!!(L&&b),n=a("label",{class:"llp-label"},["Name"]),l=P("text","llp-priv-name","Jane Smith");L&&(l.value=L);let o=a("label",{class:"llp-label"},["Email"]),r=P("email","llp-priv-email","jane@example.com");b&&(r.value=b);let d=a("label",{class:"llp-label"},["Request type"]),m=oe("llp-priv-type",[{value:"deletion",label:"Delete my data"},{value:"access",label:"Access my data"},{value:"portability",label:"Export my data"},{value:"correction",label:"Correct my data"},{value:"restriction",label:"Restrict processing"},{value:"objection",label:"Object to processing"},{value:"other",label:"Other"}]),p=a("div",{class:"llp-error",style:"display:none"}),s=a("button",{class:"llp-btn-submit"},["Submit request"]);s.onclick=async()=>{let i=l.value.trim(),g=r.value.trim(),f=m.value;if(p.style.display="none",!i||!g){p.textContent="Please fill in all fields.",p.style.display="block";return}s.disabled=!0,s.textContent="Submitting\u2026";try{let x=await D("/api/privacy-request",{api_key:E,name:i,email:g,request_type:f});if(x.ok)b=g,localStorage.setItem("heedb_email",g),z(),q(e,"Request submitted!","Your privacy request has been received. We'll respond within 30 days.");else{let T=await x.json();p.textContent=T.error||"Something went wrong.",p.style.display="block",s.disabled=!1,s.textContent="Submit request"}}catch(x){p.textContent="Network error. Please try again.",p.style.display="block",s.disabled=!1,s.textContent="Submit request"}},t?e.append(d,m,p,s):e.append(n,l,o,r,d,m,p,s)}async function re(e){var t;if(!y){e.innerHTML="";let n=a("p",{style:"color:#71717a;text-align:center;margin:8px 0;font-size:13px;line-height:1.5"},["Send a message below to view your message history."]),l=a("div",{class:"llp-new-msg"}),o=a("button",{},["+ Send a message"]);o.onclick=()=>{h="contact",S("contact"),k()},l.appendChild(o),e.append(n,l);return}e.innerHTML='<p style="color:#71717a;text-align:center">Loading\u2026</p>';try{let{threads:n}=await Z(b);if(e.innerHTML="",n.length===0){let r=a("p",{style:"color:#71717a;text-align:center;margin:8px 0"},["No open messages yet."]);e.appendChild(r)}else for(let r of n){let d=a("span",{class:`llp-badge llp-badge-${r.status}`},[r.status]),m=a("div",{class:"llp-thread-label"},[r.type==="privacy"?"Privacy request":"Message"," \u2022 "]);m.appendChild(d);let p=a("div",{class:"llp-thread-text"},[(t=r.preview)!=null?t:""]),s=new Date(r.createdAt).toLocaleDateString(),i=a("div",{class:"llp-thread-meta"},[s]),g=a("div",{class:"llp-thread-item"});g.append(m,p,i),g.onclick=()=>se(r.id),e.appendChild(g)}let l=a("div",{class:"llp-new-msg"}),o=a("button",{},["+ Send a new message"]);o.onclick=()=>{h="contact",S("contact"),k()},l.appendChild(o),e.appendChild(l)}catch(n){e.innerHTML='<p style="color:#ef4444;text-align:center">Failed to load messages.</p>'}}function se(e){A=e,h="thread-detail",k()}async function ce(e){e.innerHTML='<p style="color:#71717a;text-align:center">Loading\u2026</p>';let t=a("button",{class:"llp-chat-back"},["\u2190 Back to messages"]);t.onclick=()=>{h="threads",S("threads"),k()};try{let l=(await ee(A)).messages||[];e.innerHTML="",e.style.padding="12px",e.appendChild(t);let o=a("div",{class:"llp-chat-messages"});for(let i of l){let g=i.direction==="inbound",f=a("div",{style:`display:flex;flex-direction:column;${g?"align-items:flex-start":"align-items:flex-end"}`}),x=a("div",{class:`llp-chat-bubble ${g?"llp-chat-inbound":"llp-chat-outbound"}`},[de(i.body)]),T=a("div",{class:`llp-chat-time ${g?"":"llp-chat-time-right"}`},[pe(i.createdAt)]);f.append(x,T),o.appendChild(f)}e.appendChild(o),requestAnimationFrame(()=>{o.scrollTop=o.scrollHeight});let r=a("div",{class:"llp-chat-reply"}),d=document.createElement("textarea");d.className="llp-chat-reply-input",d.placeholder="Type a reply\u2026",d.rows=1,d.addEventListener("input",()=>{d.style.height="auto",d.style.height=Math.min(d.scrollHeight,80)+"px"});let m=a("button",{class:"llp-chat-send"},["Send"]),p=a("div",{class:"llp-error",style:"display:none;margin-top:4px"});async function s(){let i=d.value.trim();if(i){m.disabled=!0,m.textContent="\u2026",p.style.display="none";try{let g=await te(A,i);if(g.ok){let f=a("div",{style:"display:flex;flex-direction:column;align-items:flex-start"}),x=a("div",{class:"llp-chat-bubble llp-chat-inbound"},[i]),T=a("div",{class:"llp-chat-time"},["Just now"]);f.append(x,T),o.appendChild(f),o.scrollTop=o.scrollHeight,d.value="",d.style.height="auto"}else{let f=await g.json();p.textContent=f.error||"Failed to send.",p.style.display="block"}}catch(g){p.textContent="Network error. Please try again.",p.style.display="block"}m.disabled=!1,m.textContent="Send"}}m.onclick=s,d.addEventListener("keydown",i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),s())}),r.append(d,m),e.append(r,p),requestAnimationFrame(()=>d.focus())}catch(n){e.innerHTML="",e.appendChild(t),e.appendChild(a("p",{style:"color:#ef4444;text-align:center"},["Failed to load conversation."]))}}function de(e){let t=e.split(`
|
|
151
151
|
`),n=[];for(let l of t){let o=l.trim();if(/^(On|Em|El|Le|Am|Il giorno) .+(<[^>]+@[^>]+>).*(wrote|escreveu|escribi|crit|schrieb|scritto)\s?:$/i.test(o)||/<[^>]+@[^>]+>/.test(o)&&o.endsWith(":")||/^-{3,}$/.test(o))break;/^>{1,}\s/.test(o)||n.push(l)}return n.join(`
|
|
152
152
|
`).trim()}function pe(e){let t=new Date(e),l=new Date().getTime()-t.getTime(),o=Math.floor(l/6e4);if(o<1)return"Just now";if(o<60)return`${o}m ago`;let r=Math.floor(o/60);return r<24?`${r}h ago`:t.toLocaleDateString()}function q(e,t,n){e.innerHTML="";let l=a("div",{class:"llp-success"});l.innerHTML=`
|
|
153
153
|
<div class="llp-success-icon">\u2705</div>
|
|
154
154
|
<h3>${t}</h3>
|
|
155
155
|
<p>${n}</p>
|
|
156
|
-
`,e.appendChild(l)}let M=null,_=null;function
|
|
156
|
+
`,e.appendChild(l)}let M=null,_=null;function S(e){h=e,M&&M.querySelectorAll(".llp-tab").forEach(t=>{t.classList.toggle("active",t.dataset.mode===e)})}function z(){_&&(_.style.display=b&&y?"":"none")}let B=null;function ge(){u=R(),B&&(B.textContent=O())}async function F(){if(c=await ne(),u=R(),B=document.createElement("style"),B.textContent=O(),document.head.appendChild(B),c.customCSS){let i=document.createElement("style");i.textContent=c.customCSS,document.head.appendChild(i)}c.mode==="system"&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{ge(),C&&v&&k()});let e=c.triggerIcon?c.triggerIcon:c.triggerEmoji||"\u{1F4AC}",t=c.triggerText||"";if(H=a("button",{class:"llp-btn",title:"Contact us","aria-label":"Open contact widget"}),c.triggerIcon){let i=a("span",{class:"llp-btn-icon"});i.innerHTML=c.triggerIcon,H.appendChild(i)}else H.appendChild(document.createTextNode(c.triggerEmoji||"\u{1F4AC}"));if(t&&H.appendChild(a("span",{class:"llp-btn-label"},[t])),H.onclick=j,document.body.appendChild(H),c.triggerMode==="embedded"&&c.triggerSelector){let i=document.querySelector(c.triggerSelector);i&&i.addEventListener("click",g=>{g.preventDefault(),j()})}if(c.triggerMode==="tag"){let i=a("button",{class:"llp-tag","aria-label":"Open contact widget"}),g=a("span",{class:"llp-tag-icon"},[c.triggerEmoji||"\u{1F4AC}"]);i.appendChild(g),i.appendChild(document.createTextNode(c.triggerText||"Feedback")),i.onclick=j,document.body.appendChild(i)}v=a("div",{class:"llp-panel",style:"display:none"});let n=a("div",{class:"llp-header"}),l=a("h2",{},[c.headerTitle||"Contact us"]),o=a("button",{class:"llp-close","aria-label":"Close"},["\u2715"]);o.onclick=j,n.append(l,o),M=a("div",{class:"llp-tabs"});let r=a("button",{class:"llp-tab active","data-mode":"contact"},["Message"]),d=a("button",{class:"llp-tab","data-mode":"privacy"},["Privacy"]);_=a("button",{class:"llp-tab","data-mode":"threads"},["Messages"]),_.style.display=b&&y?"":"none",r.onclick=()=>{S("contact"),k()},d.onclick=()=>{S("privacy"),k()},_.onclick=()=>{S("threads"),k()},M.append(r,d,_);let m=a("div",{class:"llp-body"}),p=a("div",{class:"llp-footer"}),s=a("a",{href:"https://heedb.com",target:"_blank",rel:"noopener noreferrer"},["Powered by Heedb"]);p.appendChild(s),v.append(n,M,m,p),document.body.appendChild(v)}function j(){C=!C,v&&(v.style.display=C?"flex":"none",C&&(b&&y&&h!=="privacy"&&h!=="thread-detail"&&(h="threads",S("threads")),k()))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",F):F()})();})();
|
package/package.json
CHANGED
package/widget.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* Heedb Widget v0.1.
|
|
2
|
-
"use strict";(()=>{(function(){var W,U,K,J,V;let w=document.currentScript||document.querySelector("script[data-api-key]"),E=(W=w==null?void 0:w.getAttribute("data-api-key"))!=null?W:"",N=(U=w==null?void 0:w.src)!=null?U:"",I=(w==null?void 0:w.getAttribute("data-host"))||(N?new URL(N).origin:"");if(!E){console.warn("[Heedb] Missing data-api-key on <script> tag.");return}let
|
|
1
|
+
/* Heedb Widget v0.1.7 — https://heedb.com */
|
|
2
|
+
"use strict";(()=>{(function(){var W,U,K,J,V;let w=document.currentScript||document.querySelector("script[data-api-key]"),E=(W=w==null?void 0:w.getAttribute("data-api-key"))!=null?W:"",N=(U=w==null?void 0:w.src)!=null?U:"",I=(w==null?void 0:w.getAttribute("data-host"))||(N?new URL(N).origin:"");if(!E){console.warn("[Heedb] Missing data-api-key on <script> tag.");return}let c={},u=!1,X={primary:"#18181b",text:"#18181b",bg:"#ffffff"},G={primary:"#e4e4e7",text:"#e4e4e7",bg:"#1a1a1a"};function R(){return c.mode==="dark"?!0:c.mode==="light"?!1:c.mode==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches:!1}function Y(){return u?G:X}function $(e,t){let n=c[e];return n!=null?String(n):t}let C=!1,h="contact",A="",L=(K=localStorage.getItem("heedb_name"))!=null?K:"",b=(J=localStorage.getItem("heedb_email"))!=null?J:"",y=(V=localStorage.getItem("heedb_token"))!=null?V:"",v=null,H=null;async function Q(e,t){try{let n=await D("/api/threads/token",{api_key:E,email:e,userHash:t});if(n.ok){let l=await n.json();if(l.widgetToken){y=l.widgetToken,localStorage.setItem("heedb_token",l.widgetToken);return}}y="",localStorage.removeItem("heedb_token")}catch(n){y="",localStorage.removeItem("heedb_token")}}window.Heedb={version:"0.1.7",init(e={}){e.name&&(L=e.name,localStorage.setItem("heedb_name",e.name)),e.email&&(b=e.email,localStorage.setItem("heedb_email",e.email),e.userHash?Q(e.email,e.userHash).then(()=>{z(),C&&v&&k()}):(z(),C&&v&&k()))},reset(){L="",b="",y="",localStorage.removeItem("heedb_name"),localStorage.removeItem("heedb_email"),localStorage.removeItem("heedb_token"),h="contact",C=!1,v&&(v.style.display="none"),z()}};function D(e,t){return fetch(`${I}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}function Z(e){let t=new URL(`${I}/api/threads`);return t.searchParams.set("api_key",E),t.searchParams.set("email",e),y&&t.searchParams.set("token",y),fetch(t.toString()).then(n=>n.json())}function ee(e){let t=new URL(`${I}/api/threads/${e}`);return t.searchParams.set("api_key",E),t.searchParams.set("email",b),t.searchParams.set("token",y),fetch(t.toString()).then(n=>n.json())}function te(e,t){return D(`/api/threads/${e}/reply`,{api_key:E,email:b,token:y,message:t})}async function ne(){var e;try{let t=new URL(`${I}/api/widget-config`);t.searchParams.set("api_key",E);let n=await fetch(t.toString());if(n.ok)return(e=(await n.json()).config)!=null?e:{}}catch(t){}return{}}function O(){var f,x;let e=Y(),t=$(u?"darkPrimaryColor":"primaryColor",e.primary),n=$(u?"darkTextColor":"textColor",e.text),l=$(u?"darkBgColor":"bgColor",e.bg),o=(f=c.borderRadius)!=null?f:16,r=(x=c.buttonRadius)!=null?x:50,d=c.fontFamily||"system-ui, -apple-system, sans-serif",m=c.position==="bottom-left",p=r>=50?"50%":`${r}px`,s=Math.round(o*.5),i=c.triggerMode==="tag",g=c.triggerMode==="embedded"||i;return`
|
|
3
3
|
.llp-btn {
|
|
4
4
|
position: fixed; bottom: 24px; ${m?"left: 24px":"right: 24px"}; z-index: 999998;
|
|
5
|
-
width: 52px; height: 52px; border-radius: ${
|
|
5
|
+
width: 52px; height: 52px; border-radius: ${p}; 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
8
|
display: ${g?"none":"flex"}; align-items: center; justify-content: center;
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
.llp-btn-icon svg { width: 22px; height: 22px; fill: currentColor; }
|
|
15
15
|
.llp-btn:has(.llp-btn-label) { width: auto; padding: 0 18px; gap: 4px; }
|
|
16
16
|
.llp-tag {
|
|
17
|
-
position: fixed; ${m?"left: 0":"right: 0"}; top: 50
|
|
18
|
-
transform: ${m?"rotate(90deg) translateX(-50%)":"rotate(-90deg) translateX(50%)"};
|
|
19
|
-
transform-origin: ${m?"left
|
|
17
|
+
position: fixed !important; ${m?"left: 0 !important":"right: 0 !important"}; top: 50% !important; z-index: 999998 !important;
|
|
18
|
+
transform: ${m?"rotate(90deg) translateX(-50%)":"rotate(-90deg) translateX(50%)"} !important;
|
|
19
|
+
transform-origin: ${m?"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: ${
|
|
22
|
+
font-family: ${d};
|
|
23
23
|
border-radius: ${Math.min(r,12)}px ${Math.min(r,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;
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
width: 370px; max-height: 560px; border-radius: ${o}px;
|
|
33
33
|
background: ${l}; 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: ${d}; font-size: 14px; color: ${n};
|
|
36
36
|
transition: opacity .15s, transform .15s;
|
|
37
37
|
}
|
|
38
38
|
.llp-header {
|
|
@@ -147,10 +147,10 @@
|
|
|
147
147
|
}
|
|
148
148
|
.llp-chat-send:hover { opacity: .85; }
|
|
149
149
|
.llp-chat-send:disabled { opacity: .5; cursor: not-allowed; }
|
|
150
|
-
`}function a(e,t={},n=[]){let l=document.createElement(e);for(let[o,r]of Object.entries(t))o==="class"?l.className=r:o==="style"?l.setAttribute("style",r):o.startsWith("on")&&typeof r=="function"?l.addEventListener(o.slice(2),r):l.setAttribute(o,String(r));for(let o of n)l.appendChild(typeof o=="string"?document.createTextNode(o):o);return l}function P(e,t,n=""){let l=document.createElement("input");return l.type=e,l.id=t,l.placeholder=n,l.className="llp-input",l}function ae(e,t=""){let n=document.createElement("textarea");return n.id=e,n.placeholder=t,n.className="llp-textarea",n}function oe(e,t){let n=document.createElement("select");n.id=e,n.className="llp-select";for(let l of t){let o=document.createElement("option");o.value=l.value,o.textContent=l.label,n.appendChild(o)}return n}function k(){if(!v)return;let e=v.querySelector(".llp-body");e.innerHTML="",h==="contact"?le(e):h==="privacy"?ie(e):h==="threads"?re(e):h==="thread-detail"&&ce(e),M&&(M.style.display=h==="thread-detail"?"none":"flex")}function le(e,t=""){let n=!!(
|
|
150
|
+
`}function a(e,t={},n=[]){let l=document.createElement(e);for(let[o,r]of Object.entries(t))o==="class"?l.className=r:o==="style"?l.setAttribute("style",r):o.startsWith("on")&&typeof r=="function"?l.addEventListener(o.slice(2),r):l.setAttribute(o,String(r));for(let o of n)l.appendChild(typeof o=="string"?document.createTextNode(o):o);return l}function P(e,t,n=""){let l=document.createElement("input");return l.type=e,l.id=t,l.placeholder=n,l.className="llp-input",l}function ae(e,t=""){let n=document.createElement("textarea");return n.id=e,n.placeholder=t,n.className="llp-textarea",n}function oe(e,t){let n=document.createElement("select");n.id=e,n.className="llp-select";for(let l of t){let o=document.createElement("option");o.value=l.value,o.textContent=l.label,n.appendChild(o)}return n}function k(){if(!v)return;let e=v.querySelector(".llp-body");e.innerHTML="",h==="contact"?le(e):h==="privacy"?ie(e):h==="threads"?re(e):h==="thread-detail"&&ce(e),M&&(M.style.display=h==="thread-detail"?"none":"flex")}function le(e,t=""){let n=!!(L&&b),l=a("label",{class:"llp-label"},["Name"]),o=P("text","llp-name","Jane Smith");L&&(o.value=L);let r=a("label",{class:"llp-label"},["Email"]),d=P("email","llp-email","jane@example.com");(t||b)&&(d.value=t||b);let m=a("label",{class:"llp-label"},["Message"]),p=ae("llp-message","How can we help?"),s=a("div",{class:"llp-error",style:"display:none"}),i=a("button",{class:"llp-btn-submit"},["Send message"]);i.onclick=async()=>{let g=o.value.trim(),f=d.value.trim(),x=p.value.trim();if(s.style.display="none",!g||!f||!x){s.textContent="Please fill in all fields.",s.style.display="block";return}i.disabled=!0,i.textContent="Sending\u2026";try{let T=await D("/api/contact",{api_key:E,name:g,email:f,message:x});if(T.ok)b=f,localStorage.setItem("heedb_email",f),z(),q(e,"Message sent!","We'll get back to you soon. Check your inbox for a confirmation email.");else{let me=await T.json();s.textContent=me.error||"Something went wrong.",s.style.display="block",i.disabled=!1,i.textContent="Send message"}}catch(T){s.textContent="Network error. Please try again.",s.style.display="block",i.disabled=!1,i.textContent="Send message"}},n?e.append(m,p,s,i):e.append(l,o,r,d,m,p,s,i)}function ie(e){let t=!!(L&&b),n=a("label",{class:"llp-label"},["Name"]),l=P("text","llp-priv-name","Jane Smith");L&&(l.value=L);let o=a("label",{class:"llp-label"},["Email"]),r=P("email","llp-priv-email","jane@example.com");b&&(r.value=b);let d=a("label",{class:"llp-label"},["Request type"]),m=oe("llp-priv-type",[{value:"deletion",label:"Delete my data"},{value:"access",label:"Access my data"},{value:"portability",label:"Export my data"},{value:"correction",label:"Correct my data"},{value:"restriction",label:"Restrict processing"},{value:"objection",label:"Object to processing"},{value:"other",label:"Other"}]),p=a("div",{class:"llp-error",style:"display:none"}),s=a("button",{class:"llp-btn-submit"},["Submit request"]);s.onclick=async()=>{let i=l.value.trim(),g=r.value.trim(),f=m.value;if(p.style.display="none",!i||!g){p.textContent="Please fill in all fields.",p.style.display="block";return}s.disabled=!0,s.textContent="Submitting\u2026";try{let x=await D("/api/privacy-request",{api_key:E,name:i,email:g,request_type:f});if(x.ok)b=g,localStorage.setItem("heedb_email",g),z(),q(e,"Request submitted!","Your privacy request has been received. We'll respond within 30 days.");else{let T=await x.json();p.textContent=T.error||"Something went wrong.",p.style.display="block",s.disabled=!1,s.textContent="Submit request"}}catch(x){p.textContent="Network error. Please try again.",p.style.display="block",s.disabled=!1,s.textContent="Submit request"}},t?e.append(d,m,p,s):e.append(n,l,o,r,d,m,p,s)}async function re(e){var t;if(!y){e.innerHTML="";let n=a("p",{style:"color:#71717a;text-align:center;margin:8px 0;font-size:13px;line-height:1.5"},["Send a message below to view your message history."]),l=a("div",{class:"llp-new-msg"}),o=a("button",{},["+ Send a message"]);o.onclick=()=>{h="contact",S("contact"),k()},l.appendChild(o),e.append(n,l);return}e.innerHTML='<p style="color:#71717a;text-align:center">Loading\u2026</p>';try{let{threads:n}=await Z(b);if(e.innerHTML="",n.length===0){let r=a("p",{style:"color:#71717a;text-align:center;margin:8px 0"},["No open messages yet."]);e.appendChild(r)}else for(let r of n){let d=a("span",{class:`llp-badge llp-badge-${r.status}`},[r.status]),m=a("div",{class:"llp-thread-label"},[r.type==="privacy"?"Privacy request":"Message"," \u2022 "]);m.appendChild(d);let p=a("div",{class:"llp-thread-text"},[(t=r.preview)!=null?t:""]),s=new Date(r.createdAt).toLocaleDateString(),i=a("div",{class:"llp-thread-meta"},[s]),g=a("div",{class:"llp-thread-item"});g.append(m,p,i),g.onclick=()=>se(r.id),e.appendChild(g)}let l=a("div",{class:"llp-new-msg"}),o=a("button",{},["+ Send a new message"]);o.onclick=()=>{h="contact",S("contact"),k()},l.appendChild(o),e.appendChild(l)}catch(n){e.innerHTML='<p style="color:#ef4444;text-align:center">Failed to load messages.</p>'}}function se(e){A=e,h="thread-detail",k()}async function ce(e){e.innerHTML='<p style="color:#71717a;text-align:center">Loading\u2026</p>';let t=a("button",{class:"llp-chat-back"},["\u2190 Back to messages"]);t.onclick=()=>{h="threads",S("threads"),k()};try{let l=(await ee(A)).messages||[];e.innerHTML="",e.style.padding="12px",e.appendChild(t);let o=a("div",{class:"llp-chat-messages"});for(let i of l){let g=i.direction==="inbound",f=a("div",{style:`display:flex;flex-direction:column;${g?"align-items:flex-start":"align-items:flex-end"}`}),x=a("div",{class:`llp-chat-bubble ${g?"llp-chat-inbound":"llp-chat-outbound"}`},[de(i.body)]),T=a("div",{class:`llp-chat-time ${g?"":"llp-chat-time-right"}`},[pe(i.createdAt)]);f.append(x,T),o.appendChild(f)}e.appendChild(o),requestAnimationFrame(()=>{o.scrollTop=o.scrollHeight});let r=a("div",{class:"llp-chat-reply"}),d=document.createElement("textarea");d.className="llp-chat-reply-input",d.placeholder="Type a reply\u2026",d.rows=1,d.addEventListener("input",()=>{d.style.height="auto",d.style.height=Math.min(d.scrollHeight,80)+"px"});let m=a("button",{class:"llp-chat-send"},["Send"]),p=a("div",{class:"llp-error",style:"display:none;margin-top:4px"});async function s(){let i=d.value.trim();if(i){m.disabled=!0,m.textContent="\u2026",p.style.display="none";try{let g=await te(A,i);if(g.ok){let f=a("div",{style:"display:flex;flex-direction:column;align-items:flex-start"}),x=a("div",{class:"llp-chat-bubble llp-chat-inbound"},[i]),T=a("div",{class:"llp-chat-time"},["Just now"]);f.append(x,T),o.appendChild(f),o.scrollTop=o.scrollHeight,d.value="",d.style.height="auto"}else{let f=await g.json();p.textContent=f.error||"Failed to send.",p.style.display="block"}}catch(g){p.textContent="Network error. Please try again.",p.style.display="block"}m.disabled=!1,m.textContent="Send"}}m.onclick=s,d.addEventListener("keydown",i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),s())}),r.append(d,m),e.append(r,p),requestAnimationFrame(()=>d.focus())}catch(n){e.innerHTML="",e.appendChild(t),e.appendChild(a("p",{style:"color:#ef4444;text-align:center"},["Failed to load conversation."]))}}function de(e){let t=e.split(`
|
|
151
151
|
`),n=[];for(let l of t){let o=l.trim();if(/^(On|Em|El|Le|Am|Il giorno) .+(<[^>]+@[^>]+>).*(wrote|escreveu|escribi|crit|schrieb|scritto)\s?:$/i.test(o)||/<[^>]+@[^>]+>/.test(o)&&o.endsWith(":")||/^-{3,}$/.test(o))break;/^>{1,}\s/.test(o)||n.push(l)}return n.join(`
|
|
152
152
|
`).trim()}function pe(e){let t=new Date(e),l=new Date().getTime()-t.getTime(),o=Math.floor(l/6e4);if(o<1)return"Just now";if(o<60)return`${o}m ago`;let r=Math.floor(o/60);return r<24?`${r}h ago`:t.toLocaleDateString()}function q(e,t,n){e.innerHTML="";let l=a("div",{class:"llp-success"});l.innerHTML=`
|
|
153
153
|
<div class="llp-success-icon">\u2705</div>
|
|
154
154
|
<h3>${t}</h3>
|
|
155
155
|
<p>${n}</p>
|
|
156
|
-
`,e.appendChild(l)}let M=null,_=null;function
|
|
156
|
+
`,e.appendChild(l)}let M=null,_=null;function S(e){h=e,M&&M.querySelectorAll(".llp-tab").forEach(t=>{t.classList.toggle("active",t.dataset.mode===e)})}function z(){_&&(_.style.display=b&&y?"":"none")}let B=null;function ge(){u=R(),B&&(B.textContent=O())}async function F(){if(c=await ne(),u=R(),B=document.createElement("style"),B.textContent=O(),document.head.appendChild(B),c.customCSS){let i=document.createElement("style");i.textContent=c.customCSS,document.head.appendChild(i)}c.mode==="system"&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{ge(),C&&v&&k()});let e=c.triggerIcon?c.triggerIcon:c.triggerEmoji||"\u{1F4AC}",t=c.triggerText||"";if(H=a("button",{class:"llp-btn",title:"Contact us","aria-label":"Open contact widget"}),c.triggerIcon){let i=a("span",{class:"llp-btn-icon"});i.innerHTML=c.triggerIcon,H.appendChild(i)}else H.appendChild(document.createTextNode(c.triggerEmoji||"\u{1F4AC}"));if(t&&H.appendChild(a("span",{class:"llp-btn-label"},[t])),H.onclick=j,document.body.appendChild(H),c.triggerMode==="embedded"&&c.triggerSelector){let i=document.querySelector(c.triggerSelector);i&&i.addEventListener("click",g=>{g.preventDefault(),j()})}if(c.triggerMode==="tag"){let i=a("button",{class:"llp-tag","aria-label":"Open contact widget"}),g=a("span",{class:"llp-tag-icon"},[c.triggerEmoji||"\u{1F4AC}"]);i.appendChild(g),i.appendChild(document.createTextNode(c.triggerText||"Feedback")),i.onclick=j,document.body.appendChild(i)}v=a("div",{class:"llp-panel",style:"display:none"});let n=a("div",{class:"llp-header"}),l=a("h2",{},[c.headerTitle||"Contact us"]),o=a("button",{class:"llp-close","aria-label":"Close"},["\u2715"]);o.onclick=j,n.append(l,o),M=a("div",{class:"llp-tabs"});let r=a("button",{class:"llp-tab active","data-mode":"contact"},["Message"]),d=a("button",{class:"llp-tab","data-mode":"privacy"},["Privacy"]);_=a("button",{class:"llp-tab","data-mode":"threads"},["Messages"]),_.style.display=b&&y?"":"none",r.onclick=()=>{S("contact"),k()},d.onclick=()=>{S("privacy"),k()},_.onclick=()=>{S("threads"),k()},M.append(r,d,_);let m=a("div",{class:"llp-body"}),p=a("div",{class:"llp-footer"}),s=a("a",{href:"https://heedb.com",target:"_blank",rel:"noopener noreferrer"},["Powered by Heedb"]);p.appendChild(s),v.append(n,M,m,p),document.body.appendChild(v)}function j(){C=!C,v&&(v.style.display=C?"flex":"none",C&&(b&&y&&h!=="privacy"&&h!=="thread-detail"&&(h="threads",S("threads")),k()))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",F):F()})();})();
|