@enjoys/pinglet 1.0.0 → 1.0.1

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 CHANGED
@@ -1,19 +1,16 @@
1
1
  {
2
2
  "name": "@enjoys/pinglet",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Lightweight Customizable Web & CustomPush Notification SDK for modern web apps. Supports customizable layouts, secure delivery, and real-time updates via SSE.",
5
- "main": "./pinglet-sse.js",
6
- "types": "pinglet-sse.d.ts",
5
+ "main": "./v0.0.2/pinglet-sse.js",
6
+ "types": "./v0.0.2/pinglet-sse.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./pinglet-sse.js",
10
10
  "require": "./pinglet-sse.js"
11
11
  }
12
12
  },
13
- "files": [
14
- "pinglet-sse.js",
15
- "pinglet-sse.d.ts"
16
- ],
13
+ "files": ["*" ],
17
14
  "keywords": [
18
15
  "push",
19
16
  "notifications",
@@ -0,0 +1 @@
1
+ !function(){"use strict";(e=>{!function(){const e=document.createElement("link");e.rel="stylesheet",e.href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",document.head.appendChild(e);const t=document.createElement("style");t.innerHTML='\n [class^="pinglet-"],\n [class*=" pinglet-"] {\n font-family: \'Inter\', sans-serif !important;\n }\n ',document.head.appendChild(t)}();const t={style:{color:"#fff",backgroundColor:"#000"},position:"bottom-left",branding:{html:'Powered by <a href="https://pinglet.enjoys.in" style="color:#4da6ff;text-decoration:none;" target="_blank">Pinglet</a> - Enjoys'},duration:2e3},n="pinglet-wrapper";let o=0,i=null;const a={createMediaElement(e,t="Pinglet Notification"){let n;switch(e.type){case"image":default:n=document.createElement("img"),n.src=e.src,n.alt=t;break;case"video":n=document.createElement("video"),n.src=e.src,n.controls=!0,n.setAttribute("playsinline",""),n.setAttribute("muted","");break;case"audio":n=document.createElement("audio"),n.src=e.src,n.controls=!0;break;case"icon":n=document.createElement("span"),n.className=`icon-${e.src}`,n.setAttribute("aria-label",t)}return["image","video","audio"].includes(e.type)&&(Object.assign(n.style,{width:"100%",maxWidth:"320px",height:"auto",borderRadius:"10px",marginBottom:"8px",display:"block"}),"audio"===e.type&&(n.style.height="40px"),"video"!==e.type&&"image"!==e.type||(n.style.height="180px",n.style.objectFit="cover")),n},createWrapper(e="bottom-right"){let t=document.getElementById(n);if(!t){t=document.createElement("div"),t.id=n,Object.assign(t.style,{position:"fixed",zIndex:99999,display:"flex",flexDirection:"column",gap:"10px",maxWidth:"calc(100vw - 20px)",padding:"12px",pointerEvents:"none"});const o={"top-left":{top:"0",left:"0",alignItems:"flex-start"},"top-right":{top:"0",right:"0",alignItems:"flex-end"},"bottom-left":{bottom:"0",left:"0",alignItems:"flex-start"},"bottom-right":{bottom:"0",right:"0",alignItems:"flex-end"},"top-center":{top:"0",left:"50%",transform:"translateX(-50%)",alignItems:"center"},"bottom-center":{bottom:"0",left:"50%",transform:"translateX(-50%)",alignItems:"center"}};Object.assign(t.style,o[e]||o["bottom-right"]),document.body.appendChild(t)}return t},playNotificationSound({play:e,src:t}){if(!e||!t)return;new Audio(t).play().catch((e=>{}))},showToast(e){const{title:n="",description:a="",media:s,buttons:r=[]}=e,{style:l={},position:c,duration:d,branding:p}=t,m=this.createWrapper(c),f=document.createElement("div");f.className="pinglet-toast",o++,Object.assign(f.style,{background:"#1f1f1f",color:"#fff",padding:"16px 20px",borderRadius:"12px",boxShadow:"0 6px 18px rgba(0,0,0,0.25)",fontFamily:"'Inter', sans-serif",fontSize:"14px",lineHeight:"1.5",maxWidth:"360px",minWidth:"280px",pointerEvents:"auto",position:"relative",opacity:"0",transform:"none",transition:"all 0.4s ease",...o>=4?{opacity:.8,scale:.95}:{},...l});const g=document.createElement("span");if(g.innerHTML="&times;",Object.assign(g.style,{position:"absolute",top:"6px",right:"10px",cursor:"pointer",fontSize:"18px",color:"#aaa"}),g.onclick=()=>this.removeToast(f),f.appendChild(g),s){if("icon"===s.type){const e=document.createElement("div");e.innerHTML=`<span style="font-size:14px;margin-right:8px;">${s.src}</span><strong>${n}</strong>`,f.appendChild(e)}else if("image"===s.type||"video"===s.type){const e=this.createMediaElement(s);f.appendChild(e);const t=document.createElement("div");t.innerHTML=`<strong>${n}</strong>`,f.appendChild(t)}}else{const e=document.createElement("div");e.innerHTML=`<strong>${n}</strong>`,f.appendChild(e)}if(a){const e=document.createElement("div");e.textContent=a,e.style.color="#ccc",f.appendChild(e)}if(r.length){const e=document.createElement("div");Object.assign(e.style,{display:"flex",gap:"10px",marginTop:"8px",flexWrap:"wrap"}),r.forEach((t=>{const n=document.createElement("button");if(n.type="button",n.className=`pinglet-toast-btn-${o}`,n.textContent=t.text,Object.assign(n.style,{padding:"6px 12px",background:"#333",border:"1px solid #555",color:"#fff",borderRadius:"6px",cursor:"pointer",fontSize:"13px"}),t.onClick){if("string"==typeof t.onClick)try{t.onClick=new Function(`return (${t.onClick})`)()}catch(e){t.onClick=null}"function"==typeof t.onClick&&n.addEventListener("click",t.onClick)}e.appendChild(n)})),f.appendChild(e)}i||(i=document.createElement("div"),i.innerHTML=p.html,Object.assign(i.style,{fontSize:"11px",color:"#888",textAlign:"right",fontFamily:"'Inter', sans-serif",marginTop:"8px"})),m.appendChild(f),i&&m.appendChild(i),setTimeout((()=>{f.style.opacity="1",f.style.transform="translateX(0)"}),10);let u=setTimeout((()=>this.removeToast(f)),d);f.addEventListener("mouseenter",(()=>clearTimeout(u))),f.addEventListener("mouseleave",(()=>{u=setTimeout((()=>removeToast(f)),2e3)}))},removeToast(e){e&&(e.style.opacity="0",e.style.transform="translateX(100%)",setTimeout((()=>{e.remove(),o--,0===o&&i&&(i.remove(),i=null)}),400))}},s={init({endpoint:e,configuredDomain:t,projectIds:n=[]}){const o=location.hostname.replace(/^www\./,"");if(0===t.length)return void this._showPopup("Domain Configuration Error ","Please ensure you are running Pinglet on a valid domain.");if(0===n.length)return void this._showPopup("Project Configuration Error ","Please add at least one project to your Pinglet configuration.");t==o?n.forEach((t=>{new EventSource(`${e}/sse?projectId=${encodeURIComponent(t)}`).onmessage=e=>{try{const t=JSON.parse(e.data);a.showToast({title:t.title,description:t.description,media:t.media,buttons:t.buttons})}catch(e){}}})):this._showPopup("Domain Configuration Error ",`Your current domain is not allowed. Please ensure it matches one of the following:\n ${t}`)},_showNotification(e){const{title:t="",description:n="",buttons:o=[],media:i=null,style:a={},branding:s={show:!0,html:'Powered by <a href="https://pinglet.enjoys.in" style="color:#4da6ff;text-decoration:none;" target="_blank">Pinglet</a> - Enjoys'}}=e,r=this._getWrapper(),l=document.createElement("div");if(l.className="pinglet-toast",Object.assign(l.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:"360px",opacity:"0",transform:"translateX(100%)",transition:"opacity 0.3s ease, transform 0.3s ease",display:"flex",flexDirection:"column",gap:"12px",...a}),i){if("icon"===i.type){const e=document.createElement("div");Object.assign(e.style,{display:"flex",alignItems:"center",gap:"10px",fontSize:"16px",fontWeight:"600"});const n=document.createElement("span");n.textContent=i.src;const o=document.createElement("span");o.textContent=t,e.appendChild(n),e.appendChild(o),l.appendChild(e)}else if("image"===i.type||"video"===i.type){const e=document.createElement(i.type);Object.assign(e.style,{maxWidth:"100%",borderRadius:"8px"}),e.src=i.src,"video"===i.type&&(e.controls=!0),l.appendChild(e);const n=document.createElement("div");n.textContent=t,Object.assign(n.style,{fontSize:"16px",fontWeight:"600"}),l.appendChild(n)}}else{const e=document.createElement("div");e.textContent=t,Object.assign(e.style,{fontSize:"16px",fontWeight:"600"}),l.appendChild(e)}if(n){const e=document.createElement("div");e.textContent=n,Object.assign(e.style,{fontSize:"13.5px",color:"#ccc",lineHeight:"1.5"}),l.appendChild(e)}if(Array.isArray(o)&&o.length){const e=document.createElement("div");Object.assign(e.style,{display:"flex",gap:"10px",marginTop:"6px"});for(const t of o){const n=document.createElement("button");n.textContent=t.text||"Click",Object.assign(n.style,{padding:"8px 14px",background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"6px",fontSize:"13px",cursor:"pointer",transition:"background 0.3s"}),n.onmouseover=()=>n.style.background="#444",n.onmouseout=()=>n.style.background="#333","function"==typeof t.onClick&&(n.onclick=t.onClick),e.appendChild(n)}l.appendChild(e)}if(r.appendChild(l),!1!==s?.show){const e=document.createElement("div");e.innerHTML=s?.html||"",Object.assign(e.style,{fontSize:"11px",color:"#999",marginTop:"4px",textAlign:"right",fontFamily:"'Inter', sans-serif"}),r.appendChild(e),setTimeout((()=>{l.remove(),e.remove()}),5e3)}else setTimeout((()=>l.remove()),5e3);requestAnimationFrame((()=>{l.style.opacity="1",l.style.transform="translateX(0)"}))},_showPopup(e,t,n=[{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],o="⚠️"){const i="toastContainer";let a=document.getElementById(i);a||(a=document.createElement("div"),a.id=i,Object.assign(a.style,{position:"fixed",bottom:"24px",right:"24px",zIndex:"9999",display:"flex",flexDirection:"column",gap:"4px",alignItems:"flex-end"}),document.body.appendChild(a));const s=document.createElement("div");Object.assign(s.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"});const r=document.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",gap:"10px",fontSize:"16px",fontWeight:"600"});const l=document.createElement("div");l.textContent=o;const c=document.createElement("div");if(c.textContent=e,r.appendChild(l),r.appendChild(c),s.appendChild(r),t){const e=document.createElement("div");e.textContent=t,Object.assign(e.style,{fontSize:"13.5px",fontWeight:"400",color:"#ddd",lineHeight:"1.5"}),s.appendChild(e)}if(Array.isArray(n)&&n.length){const e=document.createElement("div");Object.assign(e.style,{marginTop:"8px",display:"flex",gap:"10px",justifyContent:"flex-start"});for(const t of n){const n=document.createElement("button");n.textContent=t.text||"Click",Object.assign(n.style,{padding:"8px 14px",background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"6px",fontSize:"13px",cursor:"pointer",transition:"background 0.3s"}),n.onmouseover=()=>n.style.background="#444",n.onmouseout=()=>n.style.background="#333","function"==typeof t.onClick&&n.addEventListener("click",t.onClick),e.appendChild(n)}s.appendChild(e)}a.appendChild(s);const d=document.createElement("div");d.innerHTML='Powered by <a href="https://pinglet.enjoys.in" target="_blank" style="color:#4da6ff;text-decoration:none;">Pinglet</a> - Enjoys',Object.assign(d.style,{fontSize:"11px",color:"#999",marginTop:"4px",textAlign:"right",fontFamily:"'Inter', sans-serif"}),a.appendChild(d),requestAnimationFrame((()=>{s.style.opacity="1",s.style.transform="translateX(0)"})),setTimeout((()=>{s.style.opacity="0",s.style.transform="translateX(100%)",setTimeout((()=>{s.remove(),d.remove()}),500)}),5e3)},_getWrapper(){let e=document.getElementById("pinglet-wrapper");return e||(e=document.createElement("div"),e.id="pinglet-wrapper",e.style="position:fixed;bottom:20px;right:20px;z-index:99999;display:flex;flex-direction:column;gap:10px;max-width:300px;font-family:sans-serif",document.body.appendChild(e)),e},_addBranding(e){if(!document.getElementById("pinglet-brand")){const t=document.createElement("div");t.id="pinglet-brand",t.style="font-size:10px;text-align:right;color:#aaa;margin-top:8px",t.innerHTML="Powered by <strong>Pinglet</strong> – Enjoys",e.appendChild(t)}}};e.PingletWidget=s})(window)}();
@@ -0,0 +1,6 @@
1
+ export function changeToObject({ e, k, i, t }: {
2
+ e: any;
3
+ k: any;
4
+ i: any;
5
+ t: any;
6
+ }): Promise<string | undefined>;
@@ -0,0 +1,18 @@
1
+ /** @typedef {import('./types.js').ShowPopup} ShowPopup */
2
+ /** @type {ShowPopup} */
3
+ export function _showPopup(title: any, description: any, buttons?: {
4
+ text: string;
5
+ onClick: () => Window | null;
6
+ }[], icon?: string): HTMLElement;
7
+ /**
8
+ * Injects Manrope font via Google Fonts and applies it to all elements with
9
+ * classes starting with "pinglet-".
10
+ *
11
+ * @returns {void}
12
+ */
13
+ export function injectFont(): void;
14
+ /** @type {TemplateStyleConfig} */
15
+ export const defaultStyles: TemplateStyleConfig;
16
+ /** @type {ProjectConfig} */
17
+ export const defaultConfig: ProjectConfig;
18
+ export type ShowPopup = any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Fetches all templates for a given project from the specified endpoint.
3
+ *
4
+ * @param {string} endpoint - The API endpoint URL.
5
+ * @param {string} projectId - The unique identifier for the project.
6
+ * @param {string} pingletId - The signature associated with the Pinglet instance.
7
+ * @param {string} checksum - The checksum for request validation.
8
+ * @param {string} version - The version of the Pinglet API being used.
9
+ * @returns {Promise<Object|null>} - A promise that resolves to the templates result if successful, or null if unsuccessful.
10
+ */
11
+ export function loadAllTemplates(endpoint: string, projectId: string, pingletId: string, checksum: string, version: string): Promise<Object | null>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * ('./types/index.js').NotificationData
3
+ */
4
+ type _import = any;
5
+ export { _import as import };
@@ -0,0 +1 @@
1
+ !function(){"use strict";function e(e,t,n=[{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],o="⚠️"){const i="toastContainer";let s=document.getElementById(i);s||(s=document.createElement("div"),s.id=i,Object.assign(s.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(s));const a=document.createElement("div");Object.assign(a.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 l=document.createElement("div");Object.assign(l.style,{display:"flex",alignItems:"center",gap:"10px",fontSize:"16px",fontWeight:"600",fontFamily:"Manrope, sans-serif"});const r=document.createElement("div");r.textContent=o;const c=document.createElement("div");if(c.textContent=e,l.appendChild(r),l.appendChild(c),a.appendChild(l),t){const e=document.createElement("div");e.textContent=t,Object.assign(e.style,{fontSize:"13.5px",fontWeight:"400",color:"#ddd",lineHeight:"1.5"}),a.appendChild(e)}if(Array.isArray(n)&&n.length){const e=document.createElement("div");Object.assign(e.style,{marginTop:"8px",display:"flex",gap:"10px",justifyContent:"flex-start"});for(const t of n){const n=document.createElement("button");n.textContent=t.text||"Click",Object.assign(n.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"}),n.onmouseover=()=>n.style.background="#444",n.onmouseout=()=>n.style.background="#333","function"==typeof t.onClick&&n.addEventListener("click",t.onClick),e.appendChild(n)}a.appendChild(e)}s.appendChild(a);const d=document.createElement("div");return d.innerHTML='Notifications by <a href="https://pinglet.enjoys.in" target="_blank" style="color:#4da6ff;text-decoration:none;">Pinglet</a> - Enjoys',Object.assign(d.style,{fontSize:"11px",color:"#999",marginTop:"4px",textAlign:"right",fontFamily:"Manrope, sans-serif"}),s.appendChild(d),requestAnimationFrame((()=>{a.style.opacity="1",a.style.transform="translateX(0)"})),setTimeout((()=>{a.style.opacity="0",a.style.transform="translateX(100%)",setTimeout((()=>{a.remove(),d.remove()}),500)}),5e3),s}const t={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"}}},n={position:"bottom-left",transition:"fade",branding:{show:!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,i,s=null,a=null;function l(e){if(i&&s)return{toastContainer:i,toastStack:s};const t=document.getElementById("pinglet-widget-container");return t?(i=t,s=i.querySelector(".pinglet-widget-stack"),{toastContainer:i,toastStack:s}):(i=document.createElement("div"),i.id="pinglet-widget-container",i.style.position="fixed",i.style.bottom="20px",i.style.left="20px",i.style.zIndex="9999",i.style.display="flex",i.style.flexDirection="column",i.style.alignItems="flex-start",i.style.gap="8px",i.style.maxWidth="360px",i.style.width="calc(100vw - 40px)",i.style.boxSizing="border-box",i.style.pointerEvents="none",i.style.padding="4px",i.style.borderRadius="8px",s=document.createElement("div"),s.className="pinglet-widget-stack",s.style.display="flex",s.style.flexDirection="column",s.style.gap="12px",s.style.pointerEvents="none",s.style.overflow="visible",s.style.flexShrink="0",i.appendChild(s),e?.show&&i.appendChild(function(e){return a||(a=document.createElement("div"),a.className="pinglet-branding",a.innerHTML=e?.html||'Notifications by <a href="https://pinglet.enjoys.in" class="pinglet-link" target="_blank" style="color:#4da6ff;text-decoration:none;">Pinglet</a>',a.style="\n font-size: 11px;\n color: #999;\n text-align: center;\n width: 100%;\n pointer-events: auto;\n ",a)}(e)),document.body.appendChild(i),{toastContainer:i,toastStack:s})}function r(e,t){const n=t.config,{toastContainer:i,toastStack:s}=l(n.branding);var r,d;i.appendChild(a),r=e,d=n.transition,r.style.opacity="0",r.style.transition="all 0.4s ease","fade"===d?(r.style.transform="translateX(20px)",requestAnimationFrame((()=>{r.style.opacity="1",r.style.transform="translateX(0)"}))):"slide"===d?(r.style.transform="translateX(100%)",requestAnimationFrame((()=>{r.style.opacity="1",r.style.transform="translateX(0)"}))):"zoom"===d?(r.style.transform="scale(0.8)",requestAnimationFrame((()=>{r.style.opacity="1",r.style.transform="scale(1)"}))):r.style.opacity="1",e.style.pointerEvents="auto",s.appendChild(e),n.sound?.play&&o&&o.play(),n?.auto_dismiss&&setTimeout((()=>{c(e,n?.transition||"fade")}),n.duration||3e3)}function c(e,t){e&&(e.style.transition="all 0.4s ease",a.style.transition="all 0.4s ease",a.style.transform="translateX(-40px)","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(),s&&0===s.children.length&&a?.remove()}),{once:!0}))}function d(e,o){const i=o.style,l=o.config,r=document.createElement("div");if(r.className=`pinglet-variant pinglet-${e.variant||"default"}`,r.style.display="flex",r.style.flexDirection="column",r.style.alignItems="stretch",r.style.width="100%",r.style.maxHeight="calc(100vh - 40px)",r.style.borderRadius="8px",r.style.overflowY="auto",r.style.boxShadow="0 2px 8px rgba(0, 0, 0, 0.1)",r.style.padding="4px",r.style.backgroundColor="rgba(255, 255, 255, 0.9)",r.style.gap="4px",r.style.pointerEvents="none",r.style.overflow="visible",r.style.flexShrink="0",r.appendChild(function(e=n,t=window.location.hostname,o="just now"){const i=document.createElement("div");i.className="pinglet-row",Object.assign(i.style,{display:"flex",justifyContent:"space-between",alignItems:"center",background:"#fff",fontFamily:"system-ui, sans-serif",fontSize:"10px"});const l=document.createElement("div");l.className="pinglet-left",Object.assign(l.style,{display:"flex",alignItems:"center",gap:"6px",flexGrow:"1"});const r=document.createElement("div");r.className="pinglet-icon",Object.assign(r.style,{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#007bff",flexShrink:"0"});const c=document.createElement("span");c.className="pinglet-domain",c.textContent=t,c.style.color="#333";const d=document.createElement("span");d.className="pinglet-time",d.textContent=`- ${o}`,d.style.color="#666";const p=document.createElement("button");return p.className="pinglet-close",p.textContent="✕",Object.assign(p.style,{background:"none",border:"none",fontSize:"12px",cursor:"pointer",color:"#888"}),p.addEventListener("mouseenter",(()=>{p.style.color="#e00"})),p.addEventListener("mouseleave",(()=>{p.style.color="#888"})),e?.website&&l.appendChild(c),e?.time&&l.appendChild(d),e?.favicon&&l.appendChild(r),i.appendChild(l),e?.dismissible&&i.appendChild(p),p.onclick=()=>{p.parentElement.parentElement.remove(),s&&0===s.children.length&&a?.remove()},i}(l)),e.media?.type){const n=function(e,n,o){switch(e.type){case"logo":{const o=document.createElement("img");return o.src=e.src,Object.assign(o.style,n?.logo||t.media.logo),o}case"image":{const o=document.createElement("img");return o.src=e.src,Object.assign(o.style,n?.image||t.media.image),o}case"video":{const i=document.createElement("video");return i.src=e.src,i.autoplay=o?.video?.autoplay||t.controls.video.autoplay||!1,i.muted=o?.video?.muted||t.controls.video.muted||!1,i.loop=o?.video?.loop||t.controls.video.loop||!1,i.controls=o?.video?.controls||t.controls.video.controls||!1,i.style=n?.video||t.media.video,Object.assign(i.style,n?.video||t.media.video),i}case"audio":{const n=document.createElement("audio");return n.src=e.src,n.autoplay=o?.audio?.controls||t.controls?.audio.autoplay||!1,n.muted=o?.audio?.muted||t.controls?.audio.muted||!1,n.loop=o?.audio?.loop||t.controls?.audio?.loop||!1,n.controls=o?.audio?.controls||t.controls?.audio?.controls||!1,Object.assign(n.style,n?.video||t.media.audio),n}case"icon":{const e=document.createElement("span");return e.className="pinglet-icon",e.style={width:"40px",height:"40px",backgroundPosition:"center",borderRadius:"8px"},e}default:return null}}(e.media,i.media,i.controls);n&&r.appendChild(n)}if(e.title){const n=document.createElement("div");n.className="pinglet-title",n.innerText=e.title,Object.assign(n.style,i.title||t.title),r.appendChild(n)}if(e.description){const n=document.createElement("p");n.className="pinglet-desc",n.innerText=e.description,Object.assign(n.style,i.description||t.description),r.appendChild(n)}if(e.buttons){const t=document.createElement("div");t.className="pinglet-buttons",t.style.fontFamily="Manrope",e.buttons.forEach(((e,n)=>{const o=document.createElement("button");o.innerText=e.text,o.className="pinglet-btn",o.style.cursor="pointer",o.style.padding="6px 10px",o.style.fontFamily="Manrope, sans-serif",o.style.margin="1px 4px",Object.assign(o.style,0===n?i.btn1:i.btn2),o.onclick=new Function(e.onClick),t.appendChild(o)})),r.appendChild(t)}return r}const p=Array.from(document.scripts).find((e=>e.src.includes("pinglet-sse")&&e.dataset.endpoint))||document.currentScript,m=p?.dataset.endpoint,u=p?.dataset.configuredDomain,g=p?.dataset.projectId,f=p?.dataset.pingletId,y=p?.dataset.loadTemplates,x=p?.dataset.checksum;(async i=>{if(i.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)}();let s={};const a={version:"0.0.2",checksum:x.replace("sha384-",""),async init({endpoint:i,configuredDomain:a,projectId:l,pingletId:c}){if("0.0.2"!==this.version)return e("Unsupported Version",`PingletWidget version ${this.version} is not supported. Please update to the latest version.`,[{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],"⚠️"),void console.warn("Unsupported version detected.");if(!this.checksum||!x)return e("Configuration Error","Missing checksum.");const p=await fetch(`${i}/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"}),m=await p.json();if(!m||!m.success)return e("Configuration Error",`Failed to load configuration for PingletWidget. ${m.message||"Unknown error"}`,[{text:"Retry",onClick:()=>window.location.reload()},{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],"❌"),console.error("Failed to load configuration for PingletWidget.");if("true"===y){const t=await async function(e,t,n,o,i){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":o,"X-Pinglet-Version":i},credentials:"omit"}),a=await s.json();return a&&a.success?a.result:null}(i,l,c,this.checksum,this.version);t||e("Configuration Error","Failed to load templates for PingletWidget."),s=t}const u={is_tff:m.result?.is_premium??!1,templates:Object.assign({},{default:{compiled_text:e.toString(),config:n,is_active:!0,is_default:!0}},"true"===y?s:{[String(m.result.template?.id.toString())]:m.result.template}),style:Object.assign({},t,m.result.template?.config),config:Object.assign({},n,m.result.config)};!function(e){if(o)return o;e.sound?.play&&e.sound.src&&(o=new Audio(e.sound.src),o.volume=e.sound.volume??.5)}(u);new EventSource(`${i}/subscribe?projectId=${l}&pingletId=${c}`,{withCredentials:!1}).onmessage=e=>{const t=JSON.parse(e.data);if(t?.template_id){return r(new Function(`return ${u.templates[String(t.template_id)].compiled_text}`)()(t.title,t.description,t.media,t.buttons),u)}const n=d(t,u);u?.is_tdd&&Object.assign(u.config,u.config,t?.overrides??{}),r(n,u)}}};i.PingletWidget=a,document.addEventListener("DOMContentLoaded",(()=>{a.init({endpoint:m,configuredDomain:u,projectId:g,pingletId:f})})),console.log("%cPingletWidget initialized successfully.","color: #1e90ff; font-weight: bold;")})(window)}();
@@ -0,0 +1,53 @@
1
+ type MediaData = {
2
+ type: MediaType;
3
+ src: string;
4
+ };
5
+ type NotificationData = {
6
+ project_id: string;
7
+ template_id?: string | undefined;
8
+ variant?: string | undefined;
9
+ title: string;
10
+ description?: string | undefined;
11
+ media?: MediaData | undefined;
12
+ buttons?: {
13
+ text: string;
14
+ action: string;
15
+ }[] | undefined;
16
+ };
17
+ type ShowPopup = {
18
+ title: string;
19
+ description?: string | undefined;
20
+ buttons?: {
21
+ text: string;
22
+ onClick: (event: MouseEvent) => void;
23
+ }[] | undefined;
24
+ /**
25
+ * -
26
+ */
27
+ icon?: string | undefined;
28
+ };
29
+ type PingletWidget = {
30
+ version: string;
31
+ checksum: string;
32
+ };
33
+ type TemplateData = {
34
+ compiled_text: string;
35
+ config: TemplateStyleConfig;
36
+ is_active: boolean;
37
+ /**
38
+ * /
39
+ * /**
40
+ */
41
+ is_default: boolean;
42
+ };
43
+ type Templates = {
44
+ "": {
45
+ [x: string]: TemplateData;
46
+ };
47
+ };
48
+ type GlobalConfig = {
49
+ is_tff?: string | undefined;
50
+ templates: Templates;
51
+ style: TemplateStyleConfig;
52
+ config: ProjectConfig;
53
+ };
@@ -0,0 +1,45 @@
1
+ type BrandingStyle = CommonStyle;
2
+ type Branding = {
3
+ show: boolean;
4
+ html?: string | undefined;
5
+ style?: CommonStyle | undefined;
6
+ };
7
+ type ProjectConfig = {
8
+ position?: "bottom-left" | "top-right" | "top-left" | "bottom-right" | undefined;
9
+ transition?: "fade" | "slide" | "zoom" | undefined;
10
+ branding?: {
11
+ show: boolean;
12
+ html: string;
13
+ } | undefined;
14
+ sound?: {
15
+ play: boolean;
16
+ src: string;
17
+ volume: number;
18
+ } | undefined;
19
+ duration?: number | undefined;
20
+ auto_dismiss?: boolean | undefined;
21
+ maxVisible?: number | undefined;
22
+ stacking?: boolean | undefined;
23
+ dismissible?: boolean | undefined;
24
+ pauseOnHover?: boolean | undefined;
25
+ website?: string | undefined;
26
+ time?: boolean | undefined;
27
+ favicon?: boolean | undefined;
28
+ theme?: {
29
+ mode?: "light" | "dark" | "auto";
30
+ customClass?: string;
31
+ rounded?: boolean;
32
+ shadow?: boolean;
33
+ border?: boolean;
34
+ } | undefined;
35
+ iconDefaults?: {
36
+ show?: boolean;
37
+ size?: number;
38
+ position?: "left" | "right" | "top";
39
+ } | undefined;
40
+ progressBar?: {
41
+ show?: boolean;
42
+ color?: string;
43
+ height?: number;
44
+ } | undefined;
45
+ };
@@ -0,0 +1,63 @@
1
+ type MediaType = "image" | "video" | "audio" | "icon" | "logo" | "iframe";
2
+ type CommonStyle = {
3
+ color?: string | undefined;
4
+ backgroundColor?: string | undefined;
5
+ fontSize?: string | undefined;
6
+ fontWeight?: string | undefined;
7
+ borderRadius?: string | undefined;
8
+ padding?: string | undefined;
9
+ margin?: string | undefined;
10
+ border?: string | undefined;
11
+ boxShadow?: string | undefined;
12
+ textAlign?: "center" | "right" | "left" | undefined;
13
+ fontFamily?: string | undefined;
14
+ lineHeight?: string | undefined;
15
+ width?: string | number | undefined;
16
+ height?: string | number | undefined;
17
+ };
18
+ type ButtonStyle = CommonStyle;
19
+ type TextStyle = CommonStyle;
20
+ type MediaStyle = {
21
+ objectFit?: "cover" | "contain" | undefined;
22
+ color?: string | undefined;
23
+ backgroundColor?: string | undefined;
24
+ fontSize?: string | undefined;
25
+ fontWeight?: string | undefined;
26
+ borderRadius?: string | undefined;
27
+ padding?: string | undefined;
28
+ margin?: string | undefined;
29
+ border?: string | undefined;
30
+ boxShadow?: string | undefined;
31
+ textAlign?: "center" | "right" | "left" | undefined;
32
+ fontFamily?: string | undefined;
33
+ lineHeight?: string | undefined;
34
+ width?: string | number | undefined;
35
+ height?: string | number | undefined;
36
+ };
37
+ type MediaStyleMapStrict = {
38
+ image?: MediaStyle | undefined;
39
+ video?: MediaStyle | undefined;
40
+ audio?: MediaStyle | undefined;
41
+ icon?: MediaStyle | undefined;
42
+ logo?: MediaStyle | undefined;
43
+ iframe?: MediaStyle | undefined;
44
+ };
45
+ type MediaStyleMap = any;
46
+ type MediaControls = {
47
+ autoplay: boolean;
48
+ muted: boolean;
49
+ loop: boolean;
50
+ controls: boolean;
51
+ };
52
+ type TemplateStyleConfig = {
53
+ btn1?: CommonStyle | undefined;
54
+ btn2?: CommonStyle | undefined;
55
+ title?: CommonStyle | undefined;
56
+ description?: CommonStyle | undefined;
57
+ media?: any;
58
+ duration?: number | undefined;
59
+ controls?: {
60
+ audio?: MediaControls;
61
+ video?: MediaControls;
62
+ } | undefined;
63
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Create a notification variant.
3
+ * @param {NotificationData} data - Notification data
4
+ * @param {GlobalConfig} config - Global configuration
5
+ * @returns {HTMLElement} - A notification wrapper element
6
+ */
7
+ export function createVariant(data: NotificationData, config: GlobalConfig): HTMLElement;
8
+ /**
9
+ * ('./types/index.js')
10
+ */
11
+ type _import = any;
12
+ export { _import as import };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Initialize the widget by creating a sound player if the sound config is
3
+ * enabled and has a valid src.
4
+ *
5
+ * @param {GlobalConfig} globalConfig - Global config object passed to the widget.
6
+ * @returns {Audio|undefined} The created sound player or undefined if the
7
+ * sound config is disabled.
8
+ */
9
+ export function initWidget(globalConfig: GlobalConfig): (new (src?: string) => HTMLAudioElement) | undefined;
10
+ /**
11
+ * Renders a new toast notification with a given content element.
12
+ * @param {HTMLElement} contentEl the content element of the toast notification
13
+ * @param {GlobalConfig} globalConfig the global config object
14
+ */
15
+ export function renderToast(contentEl: HTMLElement, globalConfig: GlobalConfig): void;
16
+ export let toastStack: null;
17
+ export let brandingElement: null;
18
+ /**
19
+ * ('./types/index.js').GlobalConfig
20
+ */
21
+ type _import = any;
22
+ export { _import as import };
package/pinglet-sse.js DELETED
@@ -1 +0,0 @@
1
- !function(){"use strict";function e(e,t,n=[{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],o="⚠️"){const i="toastContainer";let s=document.getElementById(i);s||(s=document.createElement("div"),s.id=i,Object.assign(s.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(s));const a=document.createElement("div");Object.assign(a.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 l=document.createElement("div");Object.assign(l.style,{display:"flex",alignItems:"center",gap:"10px",fontSize:"16px",fontWeight:"600",fontFamily:"Manrope, sans-serif"});const r=document.createElement("div");r.textContent=o;const c=document.createElement("div");if(c.textContent=e,l.appendChild(r),l.appendChild(c),a.appendChild(l),t){const e=document.createElement("div");e.textContent=t,Object.assign(e.style,{fontSize:"13.5px",fontWeight:"400",color:"#ddd",lineHeight:"1.5"}),a.appendChild(e)}if(Array.isArray(n)&&n.length){const e=document.createElement("div");Object.assign(e.style,{marginTop:"8px",display:"flex",gap:"10px",justifyContent:"flex-start"});for(const t of n){const n=document.createElement("button");n.textContent=t.text||"Click",Object.assign(n.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"}),n.onmouseover=()=>n.style.background="#444",n.onmouseout=()=>n.style.background="#333","function"==typeof t.onClick&&n.addEventListener("click",t.onClick),e.appendChild(n)}a.appendChild(e)}s.appendChild(a);const d=document.createElement("div");return d.innerHTML='Notifications by <a href="https://pinglet.enjoys.in" target="_blank" style="color:#4da6ff;text-decoration:none;">Pinglet</a> - Enjoys',Object.assign(d.style,{fontSize:"11px",color:"#999",marginTop:"4px",textAlign:"right",fontFamily:"Manrope, sans-serif"}),s.appendChild(d),requestAnimationFrame((()=>{a.style.opacity="1",a.style.transform="translateX(0)"})),setTimeout((()=>{a.style.opacity="0",a.style.transform="translateX(100%)",setTimeout((()=>{a.remove(),d.remove()}),500)}),5e3),s}const t={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"}}},n={position:"bottom-left",transition:"fade",branding:{show:!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,i,s=null,a=null;function l(e){if(i&&s)return{toastContainer:i,toastStack:s};const t=document.getElementById("pinglet-widget-container");return t?(i=t,s=i.querySelector(".pinglet-widget-stack"),{toastContainer:i,toastStack:s}):(i=document.createElement("div"),i.id="pinglet-widget-container",i.style.position="fixed",i.style.bottom="20px",i.style.left="20px",i.style.zIndex="9999",i.style.display="flex",i.style.flexDirection="column",i.style.alignItems="flex-start",i.style.gap="8px",i.style.maxWidth="360px",i.style.width="calc(100vw - 40px)",i.style.boxSizing="border-box",i.style.pointerEvents="none",i.style.padding="4px",i.style.borderRadius="8px",s=document.createElement("div"),s.className="pinglet-widget-stack",s.style.display="flex",s.style.flexDirection="column",s.style.gap="12px",s.style.pointerEvents="none",s.style.overflow="visible",s.style.flexShrink="0",i.appendChild(s),e?.show&&i.appendChild(function(e){return a||(a=document.createElement("div"),a.className="pinglet-branding",a.innerHTML=e?.html||'Notifications by <a href="https://pinglet.enjoys.in" class="pinglet-link" target="_blank" style="color:#4da6ff;text-decoration:none;">Pinglet</a>',a.style="\n font-size: 11px;\n color: #999;\n text-align: center;\n width: 100%;\n pointer-events: auto;\n ",a)}(e)),document.body.appendChild(i),{toastContainer:i,toastStack:s})}function r(e,t){const n=t.config,{toastContainer:i,toastStack:s}=l(n.branding);var r,d;i.appendChild(a),r=e,d=n.transition,r.style.opacity="0",r.style.transition="all 0.4s ease","fade"===d?(r.style.transform="translateX(20px)",requestAnimationFrame((()=>{r.style.opacity="1",r.style.transform="translateX(0)"}))):"slide"===d?(r.style.transform="translateX(100%)",requestAnimationFrame((()=>{r.style.opacity="1",r.style.transform="translateX(0)"}))):"zoom"===d?(r.style.transform="scale(0.8)",requestAnimationFrame((()=>{r.style.opacity="1",r.style.transform="scale(1)"}))):r.style.opacity="1",e.style.pointerEvents="auto",s.appendChild(e),n.sound?.play&&o&&o.play(),n?.auto_dismiss&&setTimeout((()=>{c(e,n?.transition||"fade")}),n.duration||3e3)}function c(e,t){e&&(e.style.transition="all 0.4s ease",a.style.transition="all 0.4s ease",a.style.transform="translateX(-40px)","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(),s&&0===s.children.length&&a.remove()}),{once:!0}))}function d(e,o){const i=o.style,l=o.config,r=document.createElement("div");if(r.className=`pinglet-variant pinglet-${e.variant||"default"}`,r.style.display="flex",r.style.flexDirection="column",r.style.alignItems="stretch",r.style.width="100%",r.style.maxHeight="calc(100vh - 40px)",r.style.borderRadius="8px",r.style.overflowY="auto",r.style.boxShadow="0 2px 8px rgba(0, 0, 0, 0.1)",r.style.padding="4px",r.style.backgroundColor="rgba(255, 255, 255, 0.9)",r.style.gap="4px",r.style.pointerEvents="none",r.style.overflow="visible",r.style.flexShrink="0",r.appendChild(function(e=n,t=window.location.hostname,o="just now"){const i=document.createElement("div");i.className="pinglet-row",Object.assign(i.style,{display:"flex",justifyContent:"space-between",alignItems:"center",background:"#fff",fontFamily:"system-ui, sans-serif",fontSize:"10px"});const l=document.createElement("div");l.className="pinglet-left",Object.assign(l.style,{display:"flex",alignItems:"center",gap:"6px",flexGrow:"1"});const r=document.createElement("div");r.className="pinglet-icon",Object.assign(r.style,{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#007bff",flexShrink:"0"});const c=document.createElement("span");c.className="pinglet-domain",c.textContent=t,c.style.color="#333";const d=document.createElement("span");d.className="pinglet-time",d.textContent=`- ${o}`,d.style.color="#666";const p=document.createElement("button");return p.className="pinglet-close",p.textContent="✕",Object.assign(p.style,{background:"none",border:"none",fontSize:"12px",cursor:"pointer",color:"#888"}),p.addEventListener("mouseenter",(()=>{p.style.color="#e00"})),p.addEventListener("mouseleave",(()=>{p.style.color="#888"})),e?.website&&l.appendChild(c),e?.time&&l.appendChild(d),e?.favicon&&l.appendChild(r),i.appendChild(l),e?.dismissible&&i.appendChild(p),p.onclick=()=>{p.parentElement.parentElement.remove(),s&&0===s.children.length&&a?.remove()},i}(l)),e.media?.type){const n=function(e,n,o){switch(e.type){case"logo":{const o=document.createElement("img");return o.src=e.src,Object.assign(o.style,n?.logo||t.media.logo),o}case"image":{const o=document.createElement("img");return o.src=e.src,Object.assign(o.style,n?.image||t.media.image),o}case"video":{const i=document.createElement("video");return i.src=e.src,i.autoplay=o?.video?.autoplay||t.controls.video.autoplay||!1,i.muted=o?.video?.muted||t.controls.video.muted||!1,i.loop=o?.video?.loop||t.controls.video.loop||!1,i.controls=o?.video?.controls||t.controls.video.controls||!1,i.style=n?.video||t.media.video,Object.assign(i.style,n?.video||t.media.video),i}case"audio":{const n=document.createElement("audio");return n.src=e.src,n.autoplay=o?.audio?.controls||t.controls?.audio.autoplay||!1,n.muted=o?.audio?.muted||t.controls?.audio.muted||!1,n.loop=o?.audio?.loop||t.controls?.audio?.loop||!1,n.controls=o?.audio?.controls||t.controls?.audio?.controls||!1,Object.assign(n.style,n?.video||t.media.audio),n}case"icon":{const e=document.createElement("span");return e.className="pinglet-icon",e.style={width:"40px",height:"40px",backgroundPosition:"center",borderRadius:"8px"},e}default:return null}}(e.media,i.media,i.controls);n&&r.appendChild(n)}if(e.title){const n=document.createElement("div");n.className="pinglet-title",n.innerText=e.title,Object.assign(n.style,i.title||t.title),r.appendChild(n)}if(e.description){const n=document.createElement("p");n.className="pinglet-desc",n.innerText=e.description,Object.assign(n.style,i.description||t.description),r.appendChild(n)}if(e.buttons){const t=document.createElement("div");t.className="pinglet-buttons",t.style.fontFamily="Manrope",e.buttons.forEach(((e,n)=>{const o=document.createElement("button");o.innerText=e.text,o.className="pinglet-btn",o.style.cursor="pointer",o.style.padding="6px 10px",o.style.fontFamily="Manrope, sans-serif",o.style.margin="1px 4px",Object.assign(o.style,0===n?i.btn1:i.btn2),o.onclick=new Function(e.onClick),t.appendChild(o)})),r.appendChild(t)}return r}const p=Array.from(document.scripts).find((e=>e.src.includes("pinglet-sse")&&e.dataset.endpoint))||document.currentScript,m=p?.dataset.endpoint,u=p?.dataset.configuredDomain,g=p?.dataset.projectId,f=p?.dataset.pingletId,y=p?.dataset.loadTemplates,x=p?.dataset.checksum;(async i=>{if(i.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)}();let s={};const a={version:"0.0.2",checksum:x.replace("sha384-",""),async init({endpoint:i,configuredDomain:a,projectId:l,pingletId:c}){if("0.0.2"!==this.version)return e("Unsupported Version",`PingletWidget version ${this.version} is not supported. Please update to the latest version.`,[{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],"⚠️"),void console.warn("Unsupported version detected.");if(!this.checksum||!x)return e("Configuration Error","Missing checksum.");const p=await fetch(`${i}/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"}),m=await p.json();if(!m||!m.success)return e("Configuration Error",`Failed to load configuration for PingletWidget. ${m.message||"Unknown error"}`,[{text:"Retry",onClick:()=>window.location.reload()},{text:"See Docs",onClick:()=>window.open("https://pinglet.enjoys.in/docs","_blank")}],"❌"),console.error("Failed to load configuration for PingletWidget.");if("true"===y){const t=await async function(e,t,n,o,i){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":o,"X-Pinglet-Version":i},credentials:"omit"}),a=await s.json();return a&&a.success?a.result:null}(i,l,c,this.checksum,this.version);t||e("Configuration Error","Failed to load templates for PingletWidget."),s=t}const u={is_tff:m.result?.is_premium??!1,templates:Object.assign({},{default:{compiled_text:e.toString(),config:n,is_active:!0,is_default:!0}},"true"===y?s:{[String(m.result.template?.id.toString())]:m.result.template}),style:Object.assign({},t,m.result.template?.config),config:Object.assign({},n,m.result.config)};!function(e){if(o)return o;e.sound?.play&&e.sound.src&&(o=new Audio(e.sound.src),o.volume=e.sound.volume??.5)}(u);new EventSource(`${i}/subscribe?projectId=${l}&pingletId=${c}`,{withCredentials:!1}).onmessage=e=>{const t=JSON.parse(e.data);if(t?.template_id){return r(new Function(`return ${u.templates[String(t.template_id)].compiled_text}`)()(t.title,t.description,t.media,t.buttons),u)}const n=d(t,u);u?.is_tdd&&Object.assign(u.config,u.config,t?.overrides??{}),r(n,u)}}};i.PingletWidget=a,document.addEventListener("DOMContentLoaded",(()=>{a.init({endpoint:m,configuredDomain:u,projectId:g,pingletId:f})})),console.log("%cPingletWidget initialized successfully.","color: #1e90ff; font-weight: bold;")})(window)}();