UNPKG

@enjoys/pinglet

Version:

Lightweight Customizable Web & CustomPush Notification SDK for modern web apps. Supports customizable layouts, secure delivery, and real-time updates via SSE.

2 lines (1 loc) 31.2 kB
!function(){"use strict";function e(e,t){switch(e.action){case"redirect":return()=>window.open(e.src,"_blank");case"link":return()=>window.open(e.src);case"alert":return()=>alert(e.src);case"reload":return()=>window.location.reload();case"event":return()=>self.addEventListener(e.src,(()=>{}));case"close":return()=>{window.dispatchEvent(new CustomEvent("pinglet:notificationClosed",{detail:{contentEl:t,reason:"user-dismiss"}}))}}return()=>window.open("https://pinglet.enjoys.in/docs","_blank")}function t(t,n,i=[{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],o="⚠️",s={duration:5e3,auto_dismiss:!0}){const a="toastContainer";let l=document.getElementById(a);l||(l=document.createElement("div"),l.id=a,Object.assign(l.style,{position:"fixed",bottom:"24px",right:"24px",zIndex:"9999",display:"flex",flexDirection:"column",gap:"4px",alignItems:"flex-end",fontFamily:"Manrope, sans-serif"}),document.body.appendChild(l));const r=document.createElement("div");Object.assign(r.style,{background:"#1f1f1f",color:"#fff",padding:"16px 20px",borderRadius:"12px",boxShadow:"0 6px 18px rgba(0, 0, 0, 0.25)",fontFamily:"'Inter', sans-serif",minWidth:"260px",maxWidth:"340px",opacity:"0",transform:"translateX(100%)",transition:"opacity 0.3s ease, transform 0.3s ease",display:"flex",flexDirection:"column",gap:"10px",fontFamily:"Manrope, sans-serif"});const d=document.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",gap:"10px",fontSize:"16px",fontWeight:"600",fontFamily:"Manrope, sans-serif"});const c=document.createElement("div");c.textContent=o;const p=document.createElement("div");if(p.textContent=t,d.appendChild(c),d.appendChild(p),r.appendChild(d),n){const e=document.createElement("div");e.textContent=n,Object.assign(e.style,{fontSize:"13.5px",fontWeight:"400",color:"#ddd",lineHeight:"1.5"}),r.appendChild(e)}if(Array.isArray(i)&&i.length){const t=document.createElement("div");Object.assign(t.style,{marginTop:"8px",display:"flex",gap:"10px",justifyContent:"flex-start"});for(const n of i){const i=document.createElement("button");if(i.textContent=n.text||"Click Here",Object.assign(i.style,{padding:"8px 14px",background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"6px",fontSize:"13px",cursor:"pointer",transition:"background 0.3s",fontFamily:"Manrope, sans-serif"}),i.onmouseover=()=>i.style.background="#444",i.onmouseout=()=>i.style.background="#333",n?.onClick){const e=new Function(`return ${n.onClick}`)();"function"==typeof e&&i.addEventListener("click",e)}else i.addEventListener("click",e(n,i));t.appendChild(i)}r.appendChild(t)}const m=document.createElement("div");return m.innerHTML='Notifications by <a href="https://pinglet.enjoys.in" target="_blank" style="color:#4da6ff;text-decoration:none;">Pinglet</a> - Enjoys',Object.assign(m.style,{fontSize:"11px",color:"#999",marginTop:"4px",textAlign:"right",fontFamily:"Manrope, sans-serif"}),l.appendChild(r),l.appendChild(m),requestAnimationFrame((()=>{r.style.opacity="1",r.style.transform="translateX(0)"})),s.auto_dismiss||setTimeout((()=>{r.style.opacity="0",r.style.transform="translateX(100%)",setTimeout((()=>{r.remove(),m.remove()}),500)}),s.duration||5e3),l}const n={duration:3e3,btn1:{color:"#ffffff",backgroundColor:"#007bff",padding:"6px 10px",borderRadius:"6px",fontSize:"14px",fontWeight:"600",border:"none",boxShadow:"0 2px 6px rgba(0,0,0,0.15)"},btn2:{color:"#333333",backgroundColor:"#f0f0f0",padding:"6px 10px",borderRadius:"6px",fontSize:"14px",fontWeight:"600",border:"1px solid #ccc"},title:{color:"#111111",fontSize:"14px",fontWeight:"500",lineHeight:"1.4",margin:"0 0 0 0",textAlign:"left"},description:{color:"#444444",fontSize:"13px",fontWeight:"400",lineHeight:"1.5",margin:"0 0 10px 0",textAlign:"left"},controls:{video:{autoplay:!1,muted:!1,loop:!1,controls:!1},audio:{autoplay:!1,muted:!1,loop:!1,controls:!1}},media:{image:{width:"100%",height:"200px",borderRadius:"6px",objectFit:"cover",margin:"0 0 8px 0"},icon:{width:"24px",height:"24px",margin:"0 8px 0 0",objectFit:"contain"},logo:{width:"50px",height:"50px",margin:"0 8px 0 0",objectFit:"contain"},video:{width:"100%",height:"140px",borderRadius:"6px",objectFit:"cover",margin:"0 0 10px 0"},iframe:{width:"100%",height:"140px",borderRadius:"6px",objectFit:"cover",margin:"0 0 10px 0"},audio:{width:"100%",margin:"8px 0"}}},i={position:"bottom-left",transition:"fade",branding:{show:!0,once:!0,html:'Notifications by <a href="https://pinglet.enjoys.in" style="color:#4da6ff;text-decoration:none;" target="_blank">Pinglet</a> - Enjoys'},sound:{play:!1,src:"https://pinglet.enjoys.in/api/v1/pinglet-sound.mp3?v=1&ext=mp3",volume:.6},duration:2e3,maxVisible:3,stacking:!0,auto_dismiss:!0,dismissible:!0,website:"https://pinglet.enjoys.in",time:!0,favicon:!0,pauseOnHover:!0,theme:{mode:"light",customClass:"",rounded:!0,shadow:!0,border:!1},iconDefaults:{show:!0,size:20,position:"left"},progressBar:{show:!0,color:"#4da6ff",height:3}};let o,s,a=null,l=null,r=null;function d(e){return l||(l=document.createElement("div"),l.className="pinglet-branding",l.innerHTML=e?.html||'Notifications by <a href="https://pinglet.enjoys.in" class="pinglet-link" target="_blank" style="color:#4da6ff;text-decoration:none;">Pinglet</a>',l.style="\n font-size: 11px;\n color: #808080;\n text-align: right;\n width: 100%;\n pointer-events: auto;\n ",l)}function c(e){if(s&&a)return{toastContainer:s,toastStack:a};const t=document.getElementById("pinglet-widget-container");return t?(s=t,a=s.querySelector(".pinglet-widget-stack"),{toastContainer:s,toastStack:a}):(s=document.createElement("div"),s.id="pinglet-widget-container",s.style.position="fixed",s.style.bottom="20px",s.style.left="20px",s.style.zIndex="9999",s.style.display="flex",s.style.flexDirection="column",s.style.alignItems="flex-start",s.style.gap="8px",s.style.maxWidth="360px",s.style.width="360px",s.style.boxSizing="border-box",s.style.pointerEvents="none",s.style.padding="4px",s.style.borderRadius="8px",a=document.createElement("div"),a.className="pinglet-widget-stack",a.style.display="flex",a.style.flexDirection="column",a.style.gap="12px",a.style.pointerEvents="none",a.style.overflow="visible",a.style.flexShrink="0",s.appendChild(a),e?.show&&e?.once&&s.appendChild(d(e)),document.body.appendChild(s),{toastContainer:s,toastStack:a})}function p(e,t){const n=t.config,{toastContainer:i,toastStack:o}=c(n.branding);var s,a;n?.branding?.show&&n?.branding?.once&&i.appendChild(l),s=e,a=n.transition,s.style.opacity="0",s.style.transition="all 0.4s ease","fade"===a?(s.style.transform="translateX(20px)",requestAnimationFrame((()=>{s.style.opacity="1",s.style.transform="translateX(0)"}))):"slide"===a?(s.style.transform="translateX(100%)",requestAnimationFrame((()=>{s.style.opacity="1",s.style.transform="translateX(0)"}))):"zoom"===a?(s.style.transform="scale(0.8)",requestAnimationFrame((()=>{s.style.opacity="1",s.style.transform="scale(1)"}))):s.style.opacity="1",e.style.pointerEvents="auto",o.appendChild(e),n?.auto_dismiss&&setTimeout((()=>{m(e,n?.transition||"fade")}),n.duration||5e3)}function m(e,t){e&&(e.style.transition="all 0.4s ease","fade"===t?(e.style.opacity="0",e.style.transform="translateX(-40px)"):"slide"===t?(e.style.transform="translateX(-100%)",e.style.opacity="0"):"zoom"===t?(e.style.transform="scale(0.8)",e.style.opacity="0"):e.style.opacity="0",e.addEventListener("transitionend",(()=>{e.remove(),a&&0===a.children.length&&l?.remove()}),{once:!0}))}function g(t,s){const r=s.style,d=s.config,c=(d.theme.mode||{})&&window.matchMedia("(prefers-color-scheme: dark)").matches,p=document.createElement("div");p.id="pinglet-variant",p.setAttribute("data-key",`${Date.now()}-${Math.random().toString(36).slice(2,8)}`),p.className=`pinglet-variant pinglet-${t.variant||"default"}`,Object.assign(p.style,{display:"flex",flexDirection:"column",alignItems:"stretch",width:"320px",maxHeight:"calc(100vh - 40px)",borderRadius:"8px",overflowY:"auto",padding:"4px",gap:"4px",pointerEvents:"none",overflow:"visible",flexShrink:"0",boxShadow:c?"0 2px 8px rgba(0,0,0,0.6)":"0 2px 8px rgba(0,0,0,0.1)",backgroundColor:c?"#1e1e1e":"whitesmoke",color:c?"#f0f0f0":"#000"}),p.appendChild(function(e=i,t=window.location.hostname,n="just now",o=!1){const s=document.createElement("div");s.className="pinglet-row",Object.assign(s.style,{display:"flex",justifyContent:"space-between",alignItems:"center",background:o?"#1a1a1a":"transparent",fontFamily:"system-ui, sans-serif",fontSize:"10px",padding:"6px 10px",borderBottom:o?"1px solid rgba(255, 255, 255, 0.1)":"1px solid rgba(0, 0, 0, 0.05)",color:o?"#f0f0f0":"#000"});const r=document.createElement("div");r.className="pinglet-left",Object.assign(r.style,{display:"flex",alignItems:"center",gap:"6px",flexGrow:"1"});const d=document.createElement("span");d.className="pinglet-icon",d.textContent="- Pinglet",d.onclick=()=>{window.open("https://pinglet.enjoys.in","_blank")},Object.assign(d.style,{alignItems:"center",color:"dodgerblue",flexShrink:"0",fontWeight:"bold",cursor:"pointer"});const c=document.createElement("span");c.className="pinglet-domain",c.textContent=t,c.style.color=o?"#bbb":"#808080";const p=document.createElement("span");p.className="pinglet-time",p.textContent=`- ${n}`,p.style.color=o?"#ccc":"#aaa";const m=document.createElement("button");return m.className="pinglet-close",m.textContent="✕",Object.assign(m.style,{background:"none",border:"none",fontSize:"12px",cursor:"pointer",color:o?"#aaa":"#888",padding:"0 4px"}),m.addEventListener("mouseenter",(()=>{m.style.color="#f44"})),m.addEventListener("mouseleave",(()=>{m.style.color=o?"#aaa":"#888"})),e?.website&&r.appendChild(c),e?.time&&r.appendChild(p),e?.favicon&&r.appendChild(d),s.appendChild(r),e?.dismissible&&s.appendChild(m),m.onclick=()=>{m.parentElement?.parentElement?.remove(),a&&0===a.children.length&&l?.remove()},s}(d,window.location.hostname,"just now",c));let m=null;const g="icon"in t||"logo"in t;if(t.media?.type&&(m=function(e,t,i){switch(e.type){case"image":{const i=document.createElement("img");return i.src=e.src,Object.assign(i.style,t?.image||n.media.image),i}case"video":{const o=document.createElement("video");return o.src=e.src,o.autoplay=i?.video?.autoplay||n.controls.video.autoplay||!1,o.muted=i?.video?.muted||n.controls.video.muted||!1,o.loop=i?.video?.loop||n.controls.video.loop||!1,o.controls=i?.video?.controls||n.controls.video.controls||!1,o.style=t?.video||n.media.video,Object.assign(o.style,t?.video||n.media.video),o}case"audio":return function(e,t,n,i){const o=document.createElement("div");Object.assign(o.style,{maxWidth:"auto",padding:"16px",borderRadius:"20px 20px 6px 20px",background:"#fff",boxShadow:"0 8px 32px rgba(0,0,0,0.12)",position:"relative",fontFamily:"Segoe UI, sans-serif"});const s=document.createElement("div");Object.assign(s.style,{position:"absolute",bottom:"6px",right:"-6px",width:"0",height:"0",borderLeft:"8px solid #ffffff",borderBottom:"8px solid transparent"}),o.appendChild(s);const a=document.createElement("audio");a.src=e,a.autoplay=!0,a.muted=t,a.loop=n,a.controls=i,o.appendChild(a);const l=document.createElement("div");Object.assign(l.style,{display:"flex",alignItems:"center",gap:"14px"});const r=document.createElement("button");r.textContent="▶",Object.assign(r.style,{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",border:"none",borderRadius:"50%",color:"white",width:"44px",height:"44px",fontSize:"18px",cursor:"pointer",flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 16px rgba(102, 126, 234, 0.4)",transition:"transform 0.3s ease"}),l.appendChild(r);const d=document.createElement("div");Object.assign(d.style,{flex:"1",display:"flex",flexDirection:"column",gap:"8px"});const c=document.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",justifyContent:"space-between",height:"32px",padding:"0 4px"});const p=[];for(let e=0;e<20;e++){const t=document.createElement("div");Object.assign(t.style,{width:"4px",background:"linear-gradient(to top, #667eea, #764ba2)",borderRadius:"2px",transition:"all 0.3s ease",height:8+e%5*4+"px",animation:"wave 1.5s infinite ease-in-out",animationDelay:e%5*.15+"s",animationPlayState:"paused"}),p.push(t),c.appendChild(t)}d.appendChild(c);const m=document.createElement("div");Object.assign(m.style,{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:"13px",color:"#666"});const g=document.createElement("div");g.textContent="Voice message",g.style.fontSize="12px",g.style.color="#888";const f=document.createElement("div");f.textContent="0:00",Object.assign(f.style,{fontWeight:"500",color:"#667eea"}),m.appendChild(g),m.appendChild(f),d.appendChild(m),l.appendChild(d),o.appendChild(l);const u=document.createElement("style");function y(e){return`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,"0")}`}return u.textContent="\n @keyframes wave {\n 0%, 100% { opacity: 0.3; transform: scaleY(0.5); }\n 50% { opacity: 1; transform: scaleY(1); }\n }\n ",document.head.appendChild(u),a.addEventListener("loadedmetadata",(()=>{f.textContent=y(a.duration)})),a.addEventListener("timeupdate",(()=>{f.textContent=y(a.currentTime)})),r.addEventListener("click",(()=>{a.paused?(a.play(),r.textContent="⏸",p.forEach((e=>e.style.animationPlayState="running"))):(a.pause(),r.textContent="▶",p.forEach((e=>e.style.animationPlayState="paused")))})),a.addEventListener("ended",(()=>{r.textContent="▶",p.forEach((e=>e.style.animationPlayState="paused")),a.currentTime=0})),o}(e.src,i?.audio?.muted||n.controls?.audio.muted||!1,i?.audio?.loop||n.controls?.audio?.loop||!1,i?.audio?.controls||n.controls?.audio?.controls||!1);default:return null}}(t.media,r.media,r.controls),m.style.marginBottom="12px"),m&&p.appendChild(m),g){const e=document.createElement("div");Object.assign(e.style,{display:"flex",flexDirection:"row",alignItems:"flex-start",gap:"6px"});const i=document.createElement("div");Object.assign(i.style,{flex:"0 0 auto"});const o=function(e,t,i){if("logo"===e){const e=document.createElement("img");return e.src=t,Object.assign(e.style,i?.logo||n.media.logo),e}if("icon"===e){const e=document.createElement("span");if("string"==typeof t){const n=/^data:image\/(png|jpeg|gif|webp);base64,/.test(t),i=/^<svg[\s\S]*<\/svg>$/.test(t.trim());n?(e.style.backgroundImage=`url('${t}')`,e.style.backgroundSize="cover",e.textContent=""):i?e.innerHTML=t:e.textContent=t}return e.className="pinglet-icon",Object.assign(e.style,{width:"40px",height:"40px",display:"inline-flex",alignItems:"center",justifyContent:"center",backgroundPosition:"center",borderRadius:"8px",fontSize:"24px",overflow:"hidden"}),e}return null}("icon"in t?"icon":"logo",t?.icon||t?.logo,s.style.media);o&&i.appendChild(o),e.appendChild(i);const a=document.createElement("div");if(Object.assign(a.style,{display:"flex",flexDirection:"column",flex:"1"}),t.title){const e=document.createElement("div");e.className="pinglet-title",e.innerText=t.title,Object.assign(e.style,{...r.title||n.title,color:c?"#ffffff":"#000000"}),a.appendChild(e)}if(t.description){const e=document.createElement("p");e.className="pinglet-desc",e.innerText=t.description,Object.assign(e.style,{...r.description||n.description,color:c?"#dddddd":"#333333"}),a.appendChild(e)}e.appendChild(a),p.appendChild(e)}else{if(t.title){const e=document.createElement("div");e.className="pinglet-title",e.innerText=t.title,Object.assign(e.style,{...r.title||n.title,color:c?"#ffffff":"#000000"}),p.appendChild(e)}if(t.description){const e=document.createElement("p");e.className="pinglet-desc",e.innerText=t.description,Object.assign(e.style,{...r.description||n.description,color:c?"#dddddd":"#333333"}),p.appendChild(e)}}if(t.buttons){const n=document.createElement("div");n.className="pinglet-buttons",n.style.fontFamily="Manrope",t.buttons.forEach(((t,i)=>{const o=document.createElement("button");if(o.innerText=t.text,o.className="pinglet-btn",Object.assign(o.style,{cursor:"pointer",padding:"6px 10px",fontFamily:"Manrope, sans-serif",margin:"1px 4px",color:c?"#f0f0f0":"#000",backgroundColor:c?"#333":"#f0f0f0",border:"none",borderRadius:"4px"}),Object.assign(o.style,0===i?r.btn1:r.btn2),t?.onClick){const e=new Function(`return ${t.onClick}`)();"function"==typeof e&&o.addEventListener("click",e)}else o.addEventListener("click",e(t,p));n.appendChild(o)})),p.appendChild(n)}return d.sound?.play&&o&&(o.currentTime=0,o.play()),!l||p.contains(l)||d.branding?.once||p.appendChild(l),p}function f(e){const t=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),n=window.atob(t);return Uint8Array.from([...n].map((e=>e.charCodeAt(0))))}function u(e,n,i){"Notification"in window?"granted"===Notification.permission||function(e={}){const{title:t="Stay updated with notifications",description:n="Get notified about important updates, new features, and exclusive content. We'll only send you valuable notifications.",site:i=window.location.hostname,onAllow:o=()=>{},onDeny:s=()=>{}}=e,a=document.createElement("div");a.className="notification-dialog",Object.assign(a.style,{position:"fixed",bottom:"24px",right:"24px",width:"380px",background:"#fff",borderRadius:"16px",boxShadow:"0 20px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255,255,255,0.1)",zIndex:"1000",overflow:"hidden",transform:"translateX(420px)",animation:"slideIn 0.6s ease-out 1s forwards",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"});const l=document.createElement("style");l.textContent="\n @keyframes slideIn { to { transform: translateX(0); } }\n @keyframes pulse {\n 0%, 100% { box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3); }\n 50% { box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5); }\n }\n @media (max-width: 480px) {\n .notification-dialog {\n width: calc(100vw - 32px) !important;\n right: 16px !important;\n bottom: 16px !important;\n transform: translateY(420px) !important;\n }\n @keyframes slideIn { to { transform: translateY(0); } }\n }\n ",document.head.appendChild(l);const r=document.createElement("div");r.style.display="flex",r.style.justifyContent="space-between",r.style.padding="20px 20px 0 20px";const d=document.createElement("div");d.style.display="flex",d.style.alignItems="center",d.style.gap="8px",d.style.color="#6b7280",d.style.fontSize="14px",d.style.fontWeight="500";const c=document.createElement("div");c.style.width="16px",c.style.height="16px",c.style.borderRadius="4px",c.style.background="linear-gradient(135deg, #667eea 0%, #764ba2 100%)",c.style.display="flex",c.style.alignItems="center",c.style.justifyContent="center",c.innerHTML='<svg viewBox="0 0 16 16" fill="white" width="10" height="10"><path d="M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8z"/></svg>';const p=document.createElement("span");p.textContent=i,d.append(c,p);const m=document.createElement("button");m.innerHTML='<svg viewBox="0 0 16 16" fill="currentColor" width="12" height="12">\n <path d="M12.854 4.854a.5.5 0 0 0-.708-.708L8 8.293 3.854 4.146a.5.5 0 1 0-.708.708L7.293 9l-4.147 4.146a.5.5 0 0 0 .708.708L8 9.707l4.146 4.147a.5.5 0 0 0 .708-.708L8.707 9l4.147-4.146z"/>\n </svg>',Object.assign(m.style,{width:"24px",height:"24px",background:"#f3f4f6",border:"none",borderRadius:"6px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280"}),m.onclick=()=>a.remove(),r.append(d,m);const g=document.createElement("div");g.style.padding="16px 24px 24px 24px";const f=document.createElement("div");f.style.width="48px",f.style.height="48px",f.style.borderRadius="12px",f.style.marginBottom="16px",f.style.animation="pulse 2s infinite",f.style.background="linear-gradient(135deg, #667eea 0%, #764ba2 100%)",f.style.display="flex",f.style.alignItems="center",f.style.justifyContent="center",f.innerHTML='<svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" width="24" height="24">\n <path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/>\n </svg>';const u=document.createElement("h3");u.textContent=t,Object.assign(u.style,{fontSize:"18px",fontWeight:"600",color:"#111827",marginBottom:"8px"});const y=document.createElement("p");y.textContent=n,Object.assign(y.style,{fontSize:"14px",color:"#6b7280",lineHeight:"1.5",marginBottom:"20px"});const x=document.createElement("div");x.style.display="flex",x.style.gap="8px";const h=document.createElement("button");h.textContent="Not now",Object.assign(h.style,{flex:1,padding:"10px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:"1px solid #e5e7eb",background:"#f9fafb",color:"#6b7280",cursor:"pointer"}),h.onclick=()=>{s(),a.remove()};const b=document.createElement("button");b.textContent="Allow notifications",Object.assign(b.style,{flex:1,padding:"10px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:"none",background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",color:"#fff",boxShadow:"0 2px 8px rgba(102, 126, 234, 0.3)",cursor:"pointer"}),b.onclick=()=>{o(),a.remove()},x.append(h,b);const w=document.createElement("div");w.style.marginTop="12px",w.style.display="flex",w.style.alignItems="center",w.style.justifyContent="center",w.style.gap="6px",w.style.color="#9ca3af",w.style.fontSize="12px",w.innerHTML='<svg viewBox="0 0 16 16" fill="currentColor" width="12" height="12"><path d="M8 0c-.69 0-1.843.265-2.928.56-1.11.3-2.229.655-2.887.87a1.54 1.54 0 0 0-1.044 1.262c-.596 4.477.787 7.795 2.465 9.99a11.777 11.777 0 0 0 2.517 2.453c.386.273.744.482 1.048.625.28.132.581.24.829.24s.548-.108.829-.24a7.159 7.159 0 0 0 1.048-.625 11.775 11.775 0 0 0 2.517-2.453c1.678-2.195 3.061-5.513 2.465-9.99a1.541 1.541 0 0 0-1.044-1.263 62.467 62.467 0 0 0-2.887-.87C9.843.266 8.69 0 8 0z"/></svg><span>Secure & private • Unsubscribe anytime</span>',g.append(f,u,y,x,w),a.append(r,g),document.body.appendChild(a)}({site:window.location.hostname,onAllow:()=>{Notification.requestPermission().then((async o=>"granted"===o?async function(e,n,i){try{const o=await navigator.serviceWorker.register(e+"/sw.js");if(await o.pushManager.getSubscription())return;const s=await o.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:f(i)}),a=await fetch(`${e}/subscribe?projectId=${n}`,{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"},credentials:"omit"}),l=await a.json();if(l.success)return localStorage.getItem("subscription")?void 0:(localStorage.setItem("subscription","true"),t("Notifications Enabled","You can now receive notifications from this site.",[{text:"See Demo",onClick:'()=>{\n new Notification("Pinglet", {\n body: "This is a demo notification",\n icon: "https://pinglet.enjoys.in/favicon.ico"\n }).onclick = () => {\n window.open("https://pinglet.enjoys.in", "_blank");\n }) \n }'}],"🎉"));t("Something Went Wrong",l.message,[],"❌")}catch(e){}}(e,n,i):t("Permission Denied","You blocked notifications!",[],"😭"))).catch((e=>t("Permission Error","Error requesting notification permission:",[],"😭")))},onDeny:()=>t("Permission Denied","You blocked notifications!",[],"❌")}):t("Unsupported Browser","Notifications not supported.",[],"🚫")}window.addEventListener("pinglet:notificationClosed",(e=>{m(e.detail.contentEl,"fade")})),self.addEventListener("push",(e=>{if(!e.data)return;const t=e.data.json(),n={body:t?.body,icon:t?.icon,badge:t?.badge,tag:t?.tag,requireInteraction:t?.requireInteraction||!0,silent:t?.silent||!1,data:t?.data,actions:t?.actions,image:t?.image,timestamp:Date.now(),vibrate:[200,100,200]};t.data&&t.data.duration&&setTimeout((()=>{self.registration.getNotifications({tag:t.tag}).then((e=>{e.forEach((e=>e.close()))}))}),t.data.duration),e.waitUntil(self.registration.showNotification(t.title,n))})),self.addEventListener("notificationclick",(e=>{if(e.notification.close(),e.notification.data,e.action,"view"===e.action)e.waitUntil(clients.openWindow(e.notification.data.url||"/"));else if("dismiss"===e.action)return})),self.addEventListener("notificationclose",(e=>{console.log("Notification closed:",e.notification.tag)}));const y=Array.from(document.scripts).find((e=>e.src.includes("pinglet-sse")&&e.dataset.endpoint))||document.currentScript,x=y?.dataset.endpoint,h=y?.dataset.configuredDomain,b=y?.dataset.projectId,w=y?.dataset.pingletId,v=y?.dataset.loadTemplates,C=y?.dataset.checksum,E=y?.dataset.testimonials;(async e=>{if(e.PingletWidget)return void console.warn("PingletWidget is already initialized.");!function(){const e=document.createElement("link");e.rel="stylesheet",e.href="https://fonts.googleapis.com/css2?family=Manrope:wght@200..800&display=swap",document.head.appendChild(e);const t=document.createElement("style");t.innerHTML='\n [class^="pinglet-"],\n [class*=" pinglet-"] {\n font-family: \'Manrope\', sans-serif !important;\n font-weight: 400 !important;\n }\n ',document.head.appendChild(t)}(),u(x,b,w),E&&function(){const e=document.getElementById("pinglet-testimonials");if(e)return e;const n=document.createElement("div");n.className="pinglet-floating-btn",n.style.position="fixed",n.style.bottom="30px",n.style.right="30px",n.style.display="flex",n.style.alignItems="center",n.style.background="#667EEA",n.style.borderRadius="50px",n.style.padding="0",n.style.cursor="pointer",n.style.boxShadow="0 4px 14px 0 rgba(102, 126, 234, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.05)",n.style.transition="all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",n.style.overflow="hidden",n.style.width="24px",n.style.height="24px",n.style.zIndex="1000",n.style.backdropFilter="blur(10px)",n.style.border="1px solid rgba(255, 255, 255, 0.1)";const i=document.createElement("div");i.textContent="❔",i.className="icon",i.style.fontSize="20px",i.style.display="flex",i.style.alignItems="center",i.style.justifyContent="center",i.style.transition="all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",i.style.width="24px",i.style.height="24px",i.style.flexShrink="0",i.style.color="white";const o=document.createElement("span");o.textContent="View",o.className="label",o.style.color="white",o.style.fontWeight="500",o.style.fontSize="14px",o.style.marginLeft="8px",o.style.marginRight="16px",o.style.opacity="0",o.style.transform="translateX(-8px)",o.style.transition="all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",o.style.whiteSpace="nowrap",o.style.letterSpacing="0.025em",n.appendChild(i),n.appendChild(o),document.body.appendChild(n),n.addEventListener("mouseenter",(()=>{n.style.width="100px",n.style.borderRadius="28px",n.style.boxShadow="0 8px 25px 0 rgba(102, 126, 234, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.1)",n.style.transform="translateY(-2px)",o.style.opacity="1",o.style.transform="translateX(0)",i.style.transform="scale(1.05)"})),n.addEventListener("mouseleave",(()=>{n.style.width="40px",n.style.height="40px",n.style.borderRadius="50px",n.style.boxShadow="0 4px 14px 0 rgba(102, 126, 234, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.05)",n.style.transform="translateY(0)",o.style.opacity="0",o.style.transform="translateX(-8px)",i.style.transform="scale(1)"})),n.addEventListener("mousedown",(()=>{n.style.transform="translateY(0) scale(0.98)",n.style.boxShadow="0 2px 8px 0 rgba(102, 126, 234, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05)"})),n.addEventListener("mouseup",(()=>{n.style.transform="translateY(-2px)",n.style.boxShadow="0 8px 25px 0 rgba(102, 126, 234, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.1)"})),o.addEventListener("click",(()=>{t("Testimonials Error","There was an error loading testimonials. Please try again later. If the issue persists, please contact support.",[],"❌")}));const s=()=>{window.innerWidth<=768?(n.style.bottom="16px",n.style.right="16px",n.style.width="48px",n.style.height="48px",i.style.width="48px",i.style.height="48px",i.style.fontSize="18px",o.style.fontSize="13px",o.style.marginLeft="6px",o.style.marginRight="12px"):(n.style.bottom="30px",n.style.right="30px",n.style.width="40px",n.style.height="40px",i.style.width="40px",i.style.height="40px",i.style.fontSize="20px",o.style.fontSize="14px",o.style.marginLeft="8px",o.style.marginRight="16px")};s(),window.addEventListener("resize",s)}();let s={};const a={version:"1.0.5",checksum:C.replace("sha384-",""),async init({endpoint:e,configuredDomain:a,projectId:l,pingletId:c}){if(console.log("%cPingletWidget initialized successfully.","color: #1e90ff; font-weight: bold;"),"1.0.5"!==this.version)return t("Pinglet Unsupported Version",`PingletWidget version ${this.version} is not supported. Please update to the latest version.`,[{text:"See Docs",actions:"redirect",src:"https://pinglet.enjoys.in/docs"}],"⚠️"),void console.warn("Unsupported version detected.");if(!this.checksum||!C)return t("Configuration Error","Missing checksum.");const m=await fetch(`${e}/load/projects?projectId=${l}&domain=${a}`,{headers:{"X-Project-ID":l,"X-Timestamp":Date.now(),"X-Pinglet-Signature":c,"X-Pinglet-Checksum":this.checksum,"X-Pinglet-Version":this.version,"X-Configured-Domain":a,"X-Pinglet-Id":c},credentials:"omit"}),f=await m.json();if(!f||!f.success)return t("Configuration Error",`Failed to load configuration for PingletWidget. ${f.message||"Unknown error"}`,[{text:"Retry",action:"reload"},{text:"See Docs",action:"redirect",src:"https://pinglet.enjoys.in/docs"}],"❌"),console.error("Failed to load configuration for PingletWidget.");if(d(f.result.config.branding),"true"===v){const n=await async function(e,t,n,i,o){const s=await fetch(`${e}/load/templates?projectId=${t}`,{headers:{"X-Project-ID":t,"X-Timestamp":Date.now(),"X-Pinglet-Signature":n,"X-Pinglet-Checksum":i,"X-Pinglet-Version":o},credentials:"omit"}),a=await s.json();return a&&a.success?a.result:null}(e,l,c,this.checksum,this.version);n||t("Configuration Error","Failed to load templates for PingletWidget."),s=n}const u={is_tff:f.result?.is_premium??!1,templates:Object.assign({},{default:{compiled_text:t.toString(),config:i,is_active:!0,is_default:!0}},"true"===v?s:{[String(f.result.template?.id.toString())]:f.result.template}),style:Object.assign({},n,f.result.template?.config),config:Object.assign({},i,f.result.config)};!function(e){if(o)return o;e.config.sound?.play&&e.config.sound.src&&(r=e.config.sound.src,o=new Audio(r||e.config.sound.src),o.volume=e.config.sound.volume??.5)}(u);new EventSource(`${e}/sse?projectId=${l}&pingletId=${c}`,{withCredentials:!1}).onmessage=e=>{const t=JSON.parse(e.data),n=t.data;if(u?.is_tdd&&Object.assign(u.config,u.config,n?.overrides??{}),"1"===t?.type&&t?.template_id&&t?.data){return p(interPolateTemplateWithData("",t?.data),u)}if("0"===t?.type&&t?.body){p(g(t.body,u),u)}else!function(e,t,n){new Notification(e,{badge:"🎉",body:t,actions:[{action:"pinglet",title:"Pinglet"}],icon:n,dir:"rtl",lang:"en",silent:!1,tag:"pinglet",vibrate:[100,50,100],requireInteraction:!0}).onclick=()=>{}}(body.title,body.description,body.type?.icon?.src||"")}}};e.PingletWidget=a,a.init({endpoint:x,configuredDomain:h,projectId:b,pingletId:w})})(window)}();