web-push-notifications 3.100.1 → 3.103.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("preact"),require("preact/compat"),require("preact/jsx-runtime"));else if("function"==typeof define&&define.amd)define(["preact","preact/compat","preact/jsx-runtime"],e);else{var n="object"==typeof exports?e(require("preact"),require("preact/compat"),require("preact/jsx-runtime")):e(t.preact,t.preactCompat,t.jsxRuntime);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(this,(t,e,n)=>(()=>{"use strict";var o={524(e){e.exports=t},873(t){t.exports=e},247(t){t.exports=n}};const i={};function r(t){const e=i[t];if(void 0!==e)return e.exports;const n=i[t]={exports:{}};return o[t](n,n.exports,r),n.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let s={};r.r(s),r.d(s,{PWSubscriptionWidget:()=>St});const a=/^(https?:|mailto:|tel:)/i,c="#101828",l="#667085",d="#FFFFFF",u={background:"#FFFFFF",accent:"#2970FF",text:c,textSecondary:l,textInverse:"#FFFFFF"};function h(t,e){return{display:"block",boxSizing:"border-box",width:"100%",padding:"10px 25px",borderRadius:6,fontSize:14,fontWeight:600,fontFamily:"inherit",lineHeight:1.5,textAlign:"center",textDecoration:"none",cursor:"pointer",..."secondary"===t?{backgroundColor:e.surface,color:e.accent,border:`1px solid ${e.accent}`}:{backgroundColor:e.accent,color:e.onAccent,border:"none"}}}const p={card:["top","bottom","top-left","top-right","bottom-left","bottom-right"],bar:["top","bottom"],modal:["center"]},f=Object.keys(p),b=["bottom-right","bottom-left","top-right","top-left"],m=["auto","launcher","manual"],g={delay:[0,3600],cappingCount:[0,100],cappingInterval:[0,8760],borderRadius:[0,32],offset:[0,100],launcherSize:[16,200],zIndex:[0,2147483647]},y={enable:!1,prompt:{enabled:!1,layout:"card",position:"top",borderRadius:12,overlay:!1},launcher:{enabled:!1,position:"bottom-right",offset:20,width:48,height:48},display:{trigger:"auto",delay:5,cappingCount:3,cappingInterval:4},texts:{title:"Stay in the loop",message:"Allow notifications to get our news and special offers first.",acceptText:"Allow",declineText:"Not now",closeText:"Got it",blockedTitle:"Notifications are blocked",blockedMessage:"To get our notifications, allow them for this site in your browser settings.",launcherLabel:"Subscribe to notifications",launcherBlockedLabel:"Notifications are blocked"},colors:u,fontFamily:'Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',zIndex:2147483e3},x=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function w(t){const e=x.exec(t.trim())?.[1];if(!e)return null;const n=3===e.length?e.split("").map(t=>t+t).join(""):e;return[0,2,4].map(t=>parseInt(n.slice(t,t+2),16))}function v([t,e,n]){return`#${[t,e,n].map(t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")).join("")}`}function k(t,e,n){let o=n;return o<0&&(o+=1),o>1&&(o-=1),o<1/6?t+6*(e-t)*o:o<.5?e:o<2/3?t+(e-t)*(2/3-o)*6:t}function M(t){return t>.5?.07+.86*(1-t):t}function S(t){return t<.5?.93-t*((.93-.5)/.5):t}function j(t,e){const n=w(t);if(!n)return t;const[o,i,r]=function([t,e,n]){const[o,i,r]=[t/255,e/255,n/255],s=Math.max(o,i,r),a=Math.min(o,i,r),c=(s+a)/2;if(s===a)return[0,0,c];const l=s-a;let d;return d=s===o?(i-r)/l+(i<r?6:0):s===i?(r-o)/l+2:(o-i)/l+4,[d/6,c>.5?l/(2-s-a):l/(s+a),c]}(n);return v(function([t,e,n]){if(0===e){const t=255*n;return[t,t,t]}const o=n<.5?n*(1+e):n+e-n*e,i=2*n-o;return[255*k(i,o,t+1/3),255*k(i,o,t),255*k(i,o,t-1/3)]}([o,i,"fold"===e?M(r):S(r)]))}function I(t,e,n){const o=w(t),i=w(e);return o&&i?v(o.map((t,e)=>t+(i[e]-t)*n)):t}function C(t){const e=w(t);if(!e)return!1;const[n,o,i]=e;return(.299*n+.587*o+.114*i)/255>.6}function F(t){return{background:j(t.background,"fold"),accent:t.accent,text:j(t.text,"lift"),textSecondary:j(t.textSecondary,"lift"),textInverse:t.textInverse}}function z(t,e){return"light"===e?{surface:u.background,surfaceText:c,border:"#D0D5DD",onAccent:d,error:"#D92D20",chromeIcon:l}:{surface:I(t.background,t.text,.08),surfaceText:t.text,border:I(t.background,t.text,.24),onAccent:C(t.accent)?c:d,error:"#FDA29B",chromeIcon:t.textSecondary}}function A(t){return!0===t.dark?.enabled}function P(t,e="light"){return"dark"===e&&A(t)?"dark":"light"}function E(t,e="light"){const n=P(t,e),o="dark"===n?(i=t.colors,r=t.dark,{...F(i),...r?.colors??{}}):t.colors;var i,r;return{...o,scheme:n,...z(o,n)}}function T(t){const e=(t||"").trim();if(e)return e.startsWith("#")||e.startsWith("/")||e.startsWith("?")||a.test(e)?e:void 0}new Set(["STRONG","B","EM","I","U","BR","A"]);function D(t){return"string"==typeof t&&t?t:void 0}function H(t){const e="object"==typeof t.colors&&null!==t.colors?t.colors:{};return{background:D(e.background)??D(t.background)??u.background,accent:D(e.accent)??D(t.accent)??u.accent,text:D(e.text)??u.text,textSecondary:D(e.textSecondary)??u.textSecondary,textInverse:D(e.textInverse)??u.textInverse}}function L(t,e){const n=t.dark;if("object"!=typeof n||null===n)return;const o=n,i="object"==typeof o.colors&&null!==o.colors?o.colors:{},r=F(e),s=function(t){if("object"!=typeof t||null===t)return;const e=t,n=D(e.color);if(!n)return;return{color:n,opacity:"number"==typeof e.opacity&&Number.isFinite(e.opacity)?Math.max(0,Math.min(1,e.opacity)):1}}(o.overlay);return{enabled:!0===o.enabled,colors:{background:D(i.background)??r.background,accent:D(i.accent)??r.accent,text:D(i.text)??r.text,textSecondary:D(i.textSecondary)??r.textSecondary,textInverse:D(i.textInverse)??r.textInverse},...s?{overlay:s}:{},...D(o.boxShadow)?{boxShadow:o.boxShadow}:{}}}function O(t){return"object"!=typeof t||null===t||Array.isArray(t)?{}:t}function R(t,e,n){return e.includes(t)?t:n}function W(t,[e,n],o){return"number"==typeof t&&Number.isFinite(t)?Math.max(e,Math.min(n,Math.round(t))):o}function q(t,e){if("string"!=typeof t)return e;const n=t.trim();return n?n.slice(0,300):e}function B(t){const e=T("string"==typeof t?t:void 0);return e&&/^(https?:\/\/|\/)/i.test(e)?e:void 0}function U(t,e){const n="string"==typeof e?e.trim().slice(0,64):"";return n?{[t]:n}:{}}function V(t){const e=y.texts,n=Object.keys(e);return Object.fromEntries(n.map(n=>[n,q(t[n],e[n])]))}function _(t){return"default"===t||"denied"===t}function N(t){return"denied"===t?"blocked":"ask"}function $(t,e){return t.launcher.enabled&&_(e)}var G=r(247),K=r(524),X=r(873);const J="(prefers-color-scheme: dark)";function Q(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(J).matches}const Y={bell:"M6 10a6 6 0 0 1 12 0c0 4 1.5 5.5 2 6H4c.5-.5 2-2 2-6M10 20a2 2 0 0 0 4 0",gift:"M3 11h18v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1zM2.5 7h19v4h-19zM12 7v14M12 7c-1 0-3-.2-3.5-1a2 2 0 0 1 3.5-1 2 2 0 0 1 3.5 1c-.5.8-2.5 1-3.5 1z",cart:"M2 4h2.2l2.4 11.2A2 2 0 0 0 8.6 17H19M6 7h15l-2.2 7.5H8M10.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M19.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",chart:"M3 21h18M7 21V11M12 21V6M17 21v-8",lock:"M5 11h14v10H5zM8 11V8a4 4 0 0 1 8 0v3",calendar:"M4 6h16v15H4zM4 10h16M9 3v4M15 3v4",check:"M4 13l5 5L20 6",star:"M12 3l2.9 5.9 6.5.9-4.7 4.6 1.1 6.5-5.8-3.1-5.8 3.1 1.1-6.5L2.6 9.8l6.5-.9z",clock:"M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0M12 7v5l4 2",tag:"M20.6 13.4l-7.2 7.2a2 2 0 0 1-2.8 0l-7-7A2 2 0 0 1 3 12.2V5a2 2 0 0 1 2-2h7.2a2 2 0 0 1 1.4.6l7 7a2 2 0 0 1 0 2.8zM9 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0",mail:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M7 2h10a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1M10 19h4",download:"M12 3v12M7 11l5 5 5-5M4 20h16",play:"M8 5l12 7-12 7z",shield:"M12 3l8 3v6c0 5-3.4 8.6-8 10-4.6-1.4-8-5-8-10V6z",sparkle:"M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8zM18 15l.9 2.1 2.1.9-2.1.9-.9 2.1-.9-2.1L15 18l2.1-.9z",percent:"M19 5L5 19M8.5 8.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0M20.5 15.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0",truck:"M2 7h12v10H2zM14 10h4l3 3v4h-7M8.5 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M20 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",ticket:"M4 7h16v4a2 2 0 0 0 0 4v3H4v-3a2 2 0 0 0 0-4zM14 7v12",user:"M20 21a8 8 0 0 0-16 0M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"},Z=(Object.keys(Y),"0 12px 32px rgba(16, 24, 40, 0.18)");function tt(t,e){const[n,o]=t.split("-");return{[n]:e,[o]:e}}function et(t,e){return e?(t?"pw-subw-drop":"pw-subw-rise")+" 0.3s ease-out backwards":void 0}function nt(t,e,n){const{layout:o,position:i}=t.prompt,r={position:e,zIndex:t.zIndex,boxSizing:"border-box",pointerEvents:"auto"};if("bar"===o)return{...r,left:0,right:0,[i]:0,animation:et("top"===i,n)};if("modal"===o)return{...r,top:"50%",left:"50%",width:"min(420px, calc(100% - 32px))",transform:"translate(-50%, -50%)",animation:n?"pw-subw-fade 0.25s ease-out backwards":void 0};const s="min(360px, calc(100% - 32px))",a=et(i.startsWith("top"),n);return"top"===i||"bottom"===i?{...r,[i]:16,left:"50%",width:s,transform:"translateX(-50%)",animation:a}:{...r,...tt(i,16),width:s,animation:a}}function ot({label:t,primary:e,colors:n,disabled:o,onClick:i}){return(0,G.jsx)("button",{type:"button",disabled:o,onClick:i,style:{...h(e?"primary":"secondary",n),display:"inline-block",width:"auto",padding:"8px 18px",whiteSpace:"nowrap",opacity:o?.6:1,cursor:o?"default":"pointer"},children:t})}function it({config:t,variant:e,colors:n,busy:o,onAccept:i,onDecline:r}){const{prompt:s,texts:a}=t,c="bar"===s.layout,l="blocked"===e;return(0,G.jsxs)("div",{role:"dialog","aria-label":l?a.blockedTitle:a.title,style:{display:"flex",flexDirection:c?"row":"column",alignItems:c?"center":"stretch",flexWrap:c?"wrap":"nowrap",gap:16,padding:c?"12px 20px":20,boxSizing:"border-box",width:"100%",borderRadius:c?0:s.borderRadius,boxShadow:Z,backgroundColor:n.background,color:n.text,fontFamily:t.fontFamily,colorScheme:n.scheme},children:[(0,G.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:12,flex:c?"1 1 240px":void 0},children:[s.iconUrl&&(0,G.jsx)("img",{src:s.iconUrl,alt:"",width:48,height:48,style:{flex:"none",borderRadius:8,objectFit:"cover"}}),(0,G.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0},children:[(0,G.jsx)("div",{style:{fontSize:16,fontWeight:600,lineHeight:1.4},children:l?a.blockedTitle:a.title}),(0,G.jsx)("div",{style:{fontSize:14,lineHeight:1.5,color:n.textSecondary},children:l?a.blockedMessage:a.message})]})]}),(0,G.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,flex:"none"},children:l?(0,G.jsx)(ot,{label:a.closeText,primary:!0,colors:n,onClick:r}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ot,{label:a.declineText,primary:!1,colors:n,onClick:r}),(0,G.jsx)(ot,{label:a.acceptText,primary:!0,colors:n,disabled:o,onClick:i})]})})]})}function rt({config:t,blocked:e,colors:n,onClick:o}){const{width:i,height:r,imageUrl:s}=t.launcher,a=e?t.texts.launcherBlockedLabel:t.texts.launcherLabel,c=Math.round(Math.min(i,r)/2),l={display:"flex",alignItems:"center",justifyContent:"center",width:i,height:r,padding:0,border:"none",cursor:"pointer",opacity:e?.7:1};return s?(0,G.jsx)("button",{type:"button","aria-label":a,title:a,onClick:o,style:{...l,background:"none"},children:(0,G.jsx)("img",{src:s,alt:"",width:i,height:r,style:{display:"block",objectFit:"contain"}})}):(0,G.jsx)("button",{type:"button","aria-label":a,title:a,onClick:o,style:{...l,borderRadius:"50%",backgroundColor:t.launcher.background??n.accent,color:t.launcher.iconColor??n.onAccent,boxShadow:Z},children:(0,G.jsxs)("svg",{width:c,height:c,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,G.jsx)("path",{d:Y.bell}),e&&(0,G.jsx)("path",{d:"M4 4l16 16"})]})})}function st({config:t,permission:e,open:n,mode:o="live",colorScheme:i="auto",busy:r,onAccept:s,onDecline:a,onLauncherClick:c}){const l=E(t,function(t,e){const[n,o]=(0,X.useState)(()=>"auto"===t&&e&&Q()),i=[t,e],[r,s]=(0,X.useState)(null);return(null===r||i.some((t,e)=>t!==r[e]))&&(s(i),"auto"===t&&e&&o(Q())),(0,X.useEffect)(()=>{if("auto"!==t||!e||"undefined"==typeof window||"function"!=typeof window.matchMedia)return;const n=window.matchMedia(J),i=t=>o(t.matches);return n.addEventListener("change",i),()=>n.removeEventListener("change",i)},[t,e]),"auto"!==t?t:n?"dark":"light"}(i,A(t))),d="live"===o,u=d?"fixed":"absolute",h=n&&t.prompt.enabled,p=$(t,e);return h||p?(0,G.jsxs)(G.Fragment,{children:[d&&(0,G.jsx)("style",{children:"\n@keyframes pw-subw-fade { from { opacity: 0; } }\n@keyframes pw-subw-drop { from { opacity: 0; translate: 0 -16px; } }\n@keyframes pw-subw-rise { from { opacity: 0; translate: 0 16px; } }\n"}),h&&t.prompt.overlay&&(0,G.jsx)("div",{style:{position:u,inset:0,zIndex:t.zIndex,backgroundColor:"rgba(16, 24, 40, 0.5)",animation:d?"pw-subw-fade 0.2s ease-out backwards":void 0,pointerEvents:"auto"},onClick:a}),h&&(0,G.jsx)("div",{style:nt(t,u,d),children:(0,G.jsx)(it,{config:t,variant:N(e),colors:l,busy:r,onAccept:s,onDecline:a})}),p&&(0,G.jsx)("div",{style:{position:u,zIndex:t.zIndex,pointerEvents:"auto",...tt(t.launcher.position,t.launcher.offset)},children:(0,G.jsx)(rt,{config:t,blocked:"denied"===e,colors:l,onClick:c})})]}):null}const at="keyValue",ct="messages",lt="inboxMessages";function dt(t,e){return function(n){n.objectStoreNames.contains(t)||e(n)}}const ut=[dt(at,function(t){t.createObjectStore(at,{keyPath:"key"})}),dt("log",function(t){const e=t.createObjectStore("log",{keyPath:"id",autoIncrement:!0});e.createIndex("environment","environment",{unique:!1}),e.createIndex("date","date",{unique:!1}),e.createIndex("type","type",{unique:!1})}),dt(ct,function(t){t.createObjectStore(ct,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}),dt(lt,function(t){const e="status",n=t.createObjectStore(lt,{keyPath:"inbox_id",autoIncrement:!1});n.createIndex(e,e,{unique:!1,multiEntry:!0}),n.createIndex("rt","rt",{unique:!1,multiEntry:!0})})];class ht{get all(){return ut}}class pt{constructor(t,e=new ht){this.db=t,this.migrationsBuilder=e}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.all)}applyMigrationsPack(t){t.forEach(t=>{t(this.db)})}}function ft(t,e){console.info("onversionchange",e),t.close()}let bt;function mt(t){return(bt||(bt=new Promise((t,e)=>{const n=indexedDB.open("PUSHWOOSH_SDK_STORE",7);n.onsuccess=n=>{const o=n.target.result;o.onversionchange=ft.bind(null,o,e),t(o)},n.onerror=()=>e(n.error),n.onupgradeneeded=t=>{const n=t.target.result;n.onversionchange=ft.bind(null,n,e),new pt(n).applyMigrations()}})),bt).then(e=>new Promise((n,o)=>t(e,n,o)))}class gt{_add(t){return mt((e,n,o)=>{const i=e.transaction([this.name],"readwrite").objectStore(this.name).add(t);i.onsuccess=()=>{n(t)},i.onerror=()=>{o(i.error)}}).then(t=>this.getAll().then(e=>{if(Array.isArray(e)){const n=e.map(t=>t.id).sort((t,e)=>t==e?0:t<e?1:-1);if(n.length>this.maxItems)return Promise.all(n.slice(this.maxItems).map(t=>this.delete(t))).then(()=>t)}return t}))}delete(t){return mt((e,n,o)=>{const i=e.transaction([this.name],"readwrite").objectStore(this.name).delete(t);i.onsuccess=()=>{n(i.result)},i.onerror=()=>{o(i.error)}})}getAll(){return mt((t,e,n)=>{const o=[],i=t.transaction(this.name).objectStore(this.name).openCursor();i.onsuccess=t=>{const n=t.target.result;n?(n.value&&o.push(n.value),n.continue()):e(o)},i.onerror=()=>{n(i.error)}})}}yt=at;var yt;const xt=new class extends gt{constructor(){super(...arguments),this.name="log",this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(t,e,n){const o={type:t,environment:this.environment,message:`${e}`,date:new Date};return e instanceof Error&&(o.stack=e.stack),n&&(o.additional=n),this._add(o)}},wt=(new class extends gt{constructor(){super(...arguments),this.name=ct,this.maxItems=25}add(t){return this._add({...t,date:new Date})}},{error:1,info:2,debug:3});let vt=3;const kt={setLevel(t){wt[t]||(t="error"),vt=wt[t]},write(t,e,n){return"error"===t?this.error(e):this.info(e),xt.add(t,e,n)}};Object.keys(wt).forEach(t=>{const e=wt[t];kt[t]=(...n)=>{e<=vt&&(console.groupCollapsed(t),console.info("",...n),console.trace("trace"),console.groupEnd())}});const Mt="Pushwoosh subscription widget:";class St{constructor(t){this.permission="unsupported",this.open=!1,this.busy=!1,this.container=null,this.autoShowTimer=null,this.pw=t,this.config=function(t){const e=y,n=O(t),o=O(n.prompt),i=O(n.launcher),r=O(n.display),s=g,a=R(o.layout,f,e.prompt.layout),c=p[a],l=R(r.trigger,m,e.display.trigger),d=B(o.iconUrl),u=B(i.imageUrl),h=H({colors:n.colors}),x=L({dark:n.dark},h),w=!0===o.enabled,v=!0===i.enabled;return{enable:w||v,prompt:{enabled:w,layout:a,position:R(o.position,c,c[0]),...d?{iconUrl:d}:{},borderRadius:W(o.borderRadius,s.borderRadius,e.prompt.borderRadius),overlay:"modal"===a||!0===o.overlay},launcher:{enabled:v,position:R(i.position,b,e.launcher.position),offset:W(i.offset,s.offset,e.launcher.offset),width:W(i.width,s.launcherSize,e.launcher.width),height:W(i.height,s.launcherSize,e.launcher.height),...u?{imageUrl:u}:{},...U("background",i.background),...U("iconColor",i.iconColor)},display:{trigger:l,delay:W(r.delay,s.delay,e.display.delay),cappingCount:W(r.cappingCount,s.cappingCount,e.display.cappingCount),cappingInterval:W(r.cappingInterval,s.cappingInterval,e.display.cappingInterval)},texts:V(O(n.texts)),colors:h,...x?{dark:x}:{},fontFamily:q(n.fontFamily,e.fontFamily),zIndex:W(n.zIndex,s.zIndex,e.zIndex)}}(t.initParams.subscriptionWidget),this.accept=this.accept.bind(this),this.decline=this.decline.bind(this),this.toggle=this.toggle.bind(this),this.launcherClick=this.launcherClick.bind(this),t.moduleRegistry.subscriptionWidget=this}async run(){const{pw:t,config:e}=this;e.enable&&t.isPushAvailable()&&(this.permission=await this.readPermission(),this.mount(),this.listenSubscriptionChanges(),await this.scheduleAutoShow())}show(){this.container&&this.config.prompt.enabled&&_(this.permission)&&!this.open&&(this.open=!0,this.render(),this.pw.dispatchEvent("show-subscription-widget",{}))}hide(){this.open&&(this.open=!1,this.busy=!1,this.render(),this.pw.dispatchEvent("hide-subscription-widget",{}))}toggle(t){t??!this.open?this.show():this.hide()}isVisible(){return this.open}async readPermission(){const t=this.pw.driver?.getPermission();return"denied"===t?"denied":await this.pw.isSubscribed()?"granted":"default"}mount(){const t=document.createElement("div");t.id="pushwoosh-subscription-widget",t.style.position="fixed",t.style.inset="0",t.style.zIndex=String(this.config.zIndex),t.style.pointerEvents="none",document.body.appendChild(t),this.container=document.createElement("div"),t.attachShadow({mode:"open"}).appendChild(this.container),this.render()}render(){var t;if(this.container)return this.open||$(this.config,this.permission)?void((t,e)=>{(0,K.render)((0,G.jsx)(st,{...e,mode:"live"}),t)})(this.container,{config:this.config,permission:this.permission,open:this.open,busy:this.busy,onAccept:this.accept,onDecline:this.decline,onLauncherClick:this.launcherClick}):(t=this.container,void(0,K.render)(null,t))}async scheduleAutoShow(){const t=await this.pw.data.getSubscriptionWidgetHistory();(function(t,e,n,o){const{trigger:i,cappingCount:r,cappingInterval:s}=t.display;return!(!t.prompt.enabled||"auto"!==i||"default"!==e||r>0&&n.shownCount>=r||!(null===n.lastShownAt||o-n.lastShownAt>=36e5*s))})(this.config,this.permission,t,Date.now())&&(this.autoShowTimer=setTimeout(async()=>{this.autoShowTimer=null,this.open||"default"!==this.permission||(this.show(),await this.pw.data.setSubscriptionWidgetHistory(function(t,e){return{shownCount:t.shownCount+1,lastShownAt:e}}(t,Date.now())))},1e3*this.config.display.delay))}launcherClick(){const t=(e=this.config,n=this.permission,e.prompt.enabled?"prompt":"default"===n?"subscribe":"none");var e,n;"prompt"===t?this.toggle():"subscribe"===t&&this.subscribeFromLauncher()}async subscribeFromLauncher(){try{await this.pw.subscribe()}catch(t){kt.error(t,`${Mt} failed to subscribe`)}this.permission=await this.readPermission(),this.render()}async accept(){this.busy=!0,this.render();try{await this.pw.subscribe()}catch(t){kt.error(t,`${Mt} failed to subscribe`)}if(this.permission=await this.readPermission(),"denied"===this.permission)return this.busy=!1,void this.render();this.hide()}decline(){this.hide()}listenSubscriptionChanges(){const t=async()=>{this.permission=await this.readPermission(),"granted"===this.permission&&(this.cancelAutoShow(),this.hide()),this.render()};this.pw.addEventHandler("subscribe",t),this.pw.addEventHandler("unsubscribe",t),this.pw.addEventHandler("permission-denied",t)}cancelAutoShow(){null!==this.autoShowTimer&&(clearTimeout(this.autoShowTimer),this.autoShowTimer=null)}}return s})());
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("preact"),require("preact/compat"),require("preact/jsx-runtime"));else if("function"==typeof define&&define.amd)define(["preact","preact/compat","preact/jsx-runtime"],e);else{var n="object"==typeof exports?e(require("preact"),require("preact/compat"),require("preact/jsx-runtime")):e(t.preact,t.preactCompat,t.jsxRuntime);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(this,(t,e,n)=>(()=>{"use strict";var o={524(e){e.exports=t},873(t){t.exports=e},247(t){t.exports=n}};const i={};function r(t){const e=i[t];if(void 0!==e)return e.exports;const n=i[t]={exports:{}};return o[t](n,n.exports,r),n.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let s={};r.r(s),r.d(s,{PWSubscriptionWidget:()=>St});const a=/^(https?:|mailto:|tel:)/i,c="#101828",l="#667085",d="#FFFFFF",u={background:"#FFFFFF",accent:"#2970FF",text:c,textSecondary:l,textInverse:"#FFFFFF"};function h(t,e){return{display:"block",boxSizing:"border-box",width:"100%",padding:"10px 25px",borderRadius:6,fontSize:14,fontWeight:600,fontFamily:"inherit",lineHeight:1.5,textAlign:"center",textDecoration:"none",cursor:"pointer",..."secondary"===t?{backgroundColor:e.surface,color:e.accent,border:`1px solid ${e.accent}`}:{backgroundColor:e.accent,color:e.onAccent,border:"none"}}}const p={card:["top","bottom","top-left","top-right","bottom-left","bottom-right"],bar:["top","bottom"],modal:["center"]},f=Object.keys(p),b=["bottom-right","bottom-left","top-right","top-left"],m=["auto","launcher","manual"],g={delay:[0,3600],cappingCount:[0,100],cappingInterval:[0,8760],borderRadius:[0,32],offset:[0,100],launcherSize:[16,200],zIndex:[0,2147483647]},y={enable:!1,prompt:{enabled:!1,layout:"card",position:"top",borderRadius:12,overlay:!1},launcher:{enabled:!1,position:"bottom-right",offset:20,width:48,height:48},display:{trigger:"auto",delay:5,cappingCount:3,cappingInterval:4},texts:{title:"Stay in the loop",message:"Allow notifications to get our news and special offers first.",acceptText:"Allow",declineText:"Not now",closeText:"Got it",blockedTitle:"Notifications are blocked",blockedMessage:"To get our notifications, allow them for this site in your browser settings.",launcherLabel:"Subscribe to notifications",launcherBlockedLabel:"Notifications are blocked"},colors:u,fontFamily:'Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',zIndex:2147483e3},x=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function w(t){const e=x.exec(t.trim())?.[1];if(!e)return null;const n=3===e.length?e.split("").map(t=>t+t).join(""):e;return[0,2,4].map(t=>parseInt(n.slice(t,t+2),16))}function v([t,e,n]){return`#${[t,e,n].map(t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")).join("")}`}function k(t,e,n){let o=n;return o<0&&(o+=1),o>1&&(o-=1),o<1/6?t+6*(e-t)*o:o<.5?e:o<2/3?t+(e-t)*(2/3-o)*6:t}function M(t){return t>.5?.07+.86*(1-t):t}function S(t){return t<.5?.93-t*((.93-.5)/.5):t}function j(t,e){const n=w(t);if(!n)return t;const[o,i,r]=function([t,e,n]){const[o,i,r]=[t/255,e/255,n/255],s=Math.max(o,i,r),a=Math.min(o,i,r),c=(s+a)/2;if(s===a)return[0,0,c];const l=s-a;let d;return d=s===o?(i-r)/l+(i<r?6:0):s===i?(r-o)/l+2:(o-i)/l+4,[d/6,c>.5?l/(2-s-a):l/(s+a),c]}(n);return v(function([t,e,n]){if(0===e){const t=255*n;return[t,t,t]}const o=n<.5?n*(1+e):n+e-n*e,i=2*n-o;return[255*k(i,o,t+1/3),255*k(i,o,t),255*k(i,o,t-1/3)]}([o,i,"fold"===e?M(r):S(r)]))}function I(t,e,n){const o=w(t),i=w(e);return o&&i?v(o.map((t,e)=>t+(i[e]-t)*n)):t}function C(t){const e=w(t);if(!e)return!1;const[n,o,i]=e;return(.299*n+.587*o+.114*i)/255>.6}function F(t){return{background:j(t.background,"fold"),accent:t.accent,text:j(t.text,"lift"),textSecondary:j(t.textSecondary,"lift"),textInverse:t.textInverse}}function z(t,e){return"light"===e?{surface:u.background,surfaceText:c,border:"#D0D5DD",onAccent:d,error:"#D92D20",chromeIcon:l}:{surface:I(t.background,t.text,.08),surfaceText:t.text,border:I(t.background,t.text,.24),onAccent:C(t.accent)?c:d,error:"#FDA29B",chromeIcon:t.textSecondary}}function A(t){return!0===t.dark?.enabled}function P(t,e="light"){return"dark"===e&&A(t)?"dark":"light"}function E(t,e="light"){const n=P(t,e),o="dark"===n?(i=t.colors,r=t.dark,{...F(i),...r?.colors??{}}):t.colors;var i,r;return{...o,scheme:n,...z(o,n)}}function T(t){const e=(t||"").trim();if(e)return e.startsWith("#")||e.startsWith("/")||e.startsWith("?")||a.test(e)?e:void 0}new Set(["STRONG","B","EM","I","U","BR","A"]);function D(t){return"string"==typeof t&&t?t:void 0}function H(t){const e="object"==typeof t.colors&&null!==t.colors?t.colors:{};return{background:D(e.background)??D(t.background)??u.background,accent:D(e.accent)??D(t.accent)??u.accent,text:D(e.text)??u.text,textSecondary:D(e.textSecondary)??u.textSecondary,textInverse:D(e.textInverse)??u.textInverse}}function L(t,e){const n=t.dark;if("object"!=typeof n||null===n)return;const o=n,i="object"==typeof o.colors&&null!==o.colors?o.colors:{},r=F(e),s=function(t){if("object"!=typeof t||null===t)return;const e=t,n=D(e.color);if(!n)return;return{color:n,opacity:"number"==typeof e.opacity&&Number.isFinite(e.opacity)?Math.max(0,Math.min(1,e.opacity)):1}}(o.overlay);return{enabled:!0===o.enabled,colors:{background:D(i.background)??r.background,accent:D(i.accent)??r.accent,text:D(i.text)??r.text,textSecondary:D(i.textSecondary)??r.textSecondary,textInverse:D(i.textInverse)??r.textInverse},...s?{overlay:s}:{},...D(o.boxShadow)?{boxShadow:o.boxShadow}:{}}}function O(t){return"object"!=typeof t||null===t||Array.isArray(t)?{}:t}function R(t,e,n){return e.includes(t)?t:n}function W(t,[e,n],o){return"number"==typeof t&&Number.isFinite(t)?Math.max(e,Math.min(n,Math.round(t))):o}function q(t,e){if("string"!=typeof t)return e;const n=t.trim();return n?n.slice(0,300):e}function B(t){const e=T("string"==typeof t?t:void 0);return e&&/^(https?:\/\/|\/)/i.test(e)?e:void 0}function U(t,e){const n="string"==typeof e?e.trim().slice(0,64):"";return n?{[t]:n}:{}}function V(t){const e=y.texts,n=Object.keys(e);return Object.fromEntries(n.map(n=>[n,q(t[n],e[n])]))}function _(t){return"default"===t||"denied"===t}function N(t){return"denied"===t?"blocked":"ask"}function $(t,e){return t.launcher.enabled&&_(e)}var G=r(247),K=r(524),X=r(873);const J="(prefers-color-scheme: dark)";function Q(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(J).matches}const Y={bell:"M6 10a6 6 0 0 1 12 0c0 4 1.5 5.5 2 6H4c.5-.5 2-2 2-6M10 20a2 2 0 0 0 4 0",gift:"M3 11h18v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1zM2.5 7h19v4h-19zM12 7v14M12 7c-1 0-3-.2-3.5-1a2 2 0 0 1 3.5-1 2 2 0 0 1 3.5 1c-.5.8-2.5 1-3.5 1z",cart:"M2 4h2.2l2.4 11.2A2 2 0 0 0 8.6 17H19M6 7h15l-2.2 7.5H8M10.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M19.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",chart:"M3 21h18M7 21V11M12 21V6M17 21v-8",lock:"M5 11h14v10H5zM8 11V8a4 4 0 0 1 8 0v3",calendar:"M4 6h16v15H4zM4 10h16M9 3v4M15 3v4",check:"M4 13l5 5L20 6",star:"M12 3l2.9 5.9 6.5.9-4.7 4.6 1.1 6.5-5.8-3.1-5.8 3.1 1.1-6.5L2.6 9.8l6.5-.9z",clock:"M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0M12 7v5l4 2",tag:"M20.6 13.4l-7.2 7.2a2 2 0 0 1-2.8 0l-7-7A2 2 0 0 1 3 12.2V5a2 2 0 0 1 2-2h7.2a2 2 0 0 1 1.4.6l7 7a2 2 0 0 1 0 2.8zM9 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0",mail:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M7 2h10a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1M10 19h4",download:"M12 3v12M7 11l5 5 5-5M4 20h16",play:"M8 5l12 7-12 7z",shield:"M12 3l8 3v6c0 5-3.4 8.6-8 10-4.6-1.4-8-5-8-10V6z",sparkle:"M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8zM18 15l.9 2.1 2.1.9-2.1.9-.9 2.1-.9-2.1L15 18l2.1-.9z",percent:"M19 5L5 19M8.5 8.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0M20.5 15.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0",truck:"M2 7h12v10H2zM14 10h4l3 3v4h-7M8.5 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M20 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",ticket:"M4 7h16v4a2 2 0 0 0 0 4v3H4v-3a2 2 0 0 0 0-4zM14 7v12",user:"M20 21a8 8 0 0 0-16 0M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"},Z=(Object.keys(Y),"0 12px 32px rgba(16, 24, 40, 0.18)");function tt(t,e){const[n,o]=t.split("-");return{[n]:e,[o]:e}}function et(t,e){return e?(t?"pw-subw-drop":"pw-subw-rise")+" 0.3s ease-out backwards":void 0}function nt(t,e,n){const{layout:o,position:i}=t.prompt,r={position:e,zIndex:t.zIndex,boxSizing:"border-box",pointerEvents:"auto"};if("bar"===o)return{...r,left:0,right:0,[i]:0,animation:et("top"===i,n)};if("modal"===o)return{...r,top:"50%",left:"50%",width:"min(420px, calc(100% - 32px))",transform:"translate(-50%, -50%)",animation:n?"pw-subw-fade 0.25s ease-out backwards":void 0};const s="min(360px, calc(100% - 32px))",a=et(i.startsWith("top"),n);return"top"===i||"bottom"===i?{...r,[i]:16,left:"50%",width:s,transform:"translateX(-50%)",animation:a}:{...r,...tt(i,16),width:s,animation:a}}function ot({label:t,primary:e,colors:n,disabled:o,onClick:i}){return(0,G.jsx)("button",{type:"button",disabled:o,onClick:i,style:{...h(e?"primary":"secondary",n),display:"inline-block",width:"auto",padding:"8px 18px",whiteSpace:"nowrap",opacity:o?.6:1,cursor:o?"default":"pointer"},children:t})}function it({config:t,variant:e,colors:n,busy:o,onAccept:i,onDecline:r}){const{prompt:s,texts:a}=t,c="bar"===s.layout,l="blocked"===e;return(0,G.jsxs)("div",{role:"dialog","aria-label":l?a.blockedTitle:a.title,style:{display:"flex",flexDirection:c?"row":"column",alignItems:c?"center":"stretch",flexWrap:c?"wrap":"nowrap",gap:16,padding:c?"12px 20px":20,boxSizing:"border-box",width:"100%",borderRadius:c?0:s.borderRadius,boxShadow:Z,backgroundColor:n.background,color:n.text,fontFamily:t.fontFamily,colorScheme:n.scheme},children:[(0,G.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:12,flex:c?"1 1 240px":void 0},children:[s.iconUrl&&(0,G.jsx)("img",{src:s.iconUrl,alt:"",width:48,height:48,style:{flex:"none",borderRadius:8,objectFit:"cover"}}),(0,G.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0},children:[(0,G.jsx)("div",{style:{fontSize:16,fontWeight:600,lineHeight:1.4},children:l?a.blockedTitle:a.title}),(0,G.jsx)("div",{style:{fontSize:14,lineHeight:1.5,color:n.textSecondary},children:l?a.blockedMessage:a.message})]})]}),(0,G.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,flex:"none"},children:l?(0,G.jsx)(ot,{label:a.closeText,primary:!0,colors:n,onClick:r}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ot,{label:a.declineText,primary:!1,colors:n,onClick:r}),(0,G.jsx)(ot,{label:a.acceptText,primary:!0,colors:n,disabled:o,onClick:i})]})})]})}function rt({config:t,blocked:e,colors:n,onClick:o}){const{width:i,height:r,imageUrl:s}=t.launcher,a=e?t.texts.launcherBlockedLabel:t.texts.launcherLabel,c=Math.round(Math.min(i,r)/2),l={display:"flex",alignItems:"center",justifyContent:"center",width:i,height:r,padding:0,border:"none",cursor:"pointer",opacity:e?.7:1};return s?(0,G.jsx)("button",{type:"button","aria-label":a,title:a,onClick:o,style:{...l,background:"none"},children:(0,G.jsx)("img",{src:s,alt:"",width:i,height:r,style:{display:"block",objectFit:"contain"}})}):(0,G.jsx)("button",{type:"button","aria-label":a,title:a,onClick:o,style:{...l,borderRadius:"50%",backgroundColor:t.launcher.background??n.accent,color:t.launcher.iconColor??n.onAccent,boxShadow:Z},children:(0,G.jsxs)("svg",{width:c,height:c,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,G.jsx)("path",{d:Y.bell}),e&&(0,G.jsx)("path",{d:"M4 4l16 16"})]})})}function st({config:t,permission:e,open:n,mode:o="live",colorScheme:i="auto",busy:r,onAccept:s,onDecline:a,onLauncherClick:c}){const l=E(t,function(t,e){const[n,o]=(0,X.useState)(()=>"auto"===t&&e&&Q()),i=[t,e],[r,s]=(0,X.useState)(null);return(null===r||i.some((t,e)=>t!==r[e]))&&(s(i),"auto"===t&&e&&o(Q())),(0,X.useEffect)(()=>{if("auto"!==t||!e||"undefined"==typeof window||"function"!=typeof window.matchMedia)return;const n=window.matchMedia(J),i=t=>o(t.matches);return n.addEventListener("change",i),()=>n.removeEventListener("change",i)},[t,e]),"auto"!==t?t:n?"dark":"light"}(i,A(t))),d="live"===o,u=d?"fixed":"absolute",h=n&&t.prompt.enabled,p=$(t,e);return h||p?(0,G.jsxs)(G.Fragment,{children:[d&&(0,G.jsx)("style",{children:"\n@keyframes pw-subw-fade { from { opacity: 0; } }\n@keyframes pw-subw-drop { from { opacity: 0; translate: 0 -16px; } }\n@keyframes pw-subw-rise { from { opacity: 0; translate: 0 16px; } }\n"}),h&&t.prompt.overlay&&(0,G.jsx)("div",{style:{position:u,inset:0,zIndex:t.zIndex,backgroundColor:"rgba(16, 24, 40, 0.5)",animation:d?"pw-subw-fade 0.2s ease-out backwards":void 0,pointerEvents:"auto"},onClick:a}),h&&(0,G.jsx)("div",{style:nt(t,u,d),children:(0,G.jsx)(it,{config:t,variant:N(e),colors:l,busy:r,onAccept:s,onDecline:a})}),p&&(0,G.jsx)("div",{style:{position:u,zIndex:t.zIndex,pointerEvents:"auto",...tt(t.launcher.position,t.launcher.offset)},children:(0,G.jsx)(rt,{config:t,blocked:"denied"===e,colors:l,onClick:c})})]}):null}const at="keyValue",ct="messages",lt="inboxMessages";function dt(t,e){return function(n){n.objectStoreNames.contains(t)||e(n)}}const ut=[dt(at,function(t){t.createObjectStore(at,{keyPath:"key"})}),dt("log",function(t){const e=t.createObjectStore("log",{keyPath:"id",autoIncrement:!0});e.createIndex("environment","environment",{unique:!1}),e.createIndex("date","date",{unique:!1}),e.createIndex("type","type",{unique:!1})}),dt(ct,function(t){t.createObjectStore(ct,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}),dt(lt,function(t){const e="status",n=t.createObjectStore(lt,{keyPath:"inbox_id",autoIncrement:!1});n.createIndex(e,e,{unique:!1,multiEntry:!0}),n.createIndex("rt","rt",{unique:!1,multiEntry:!0})})];class ht{get all(){return ut}}class pt{constructor(t,e=new ht){this.db=t,this.migrationsBuilder=e}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.all)}applyMigrationsPack(t){t.forEach(t=>{t(this.db)})}}function ft(t,e){console.info("onversionchange",e),t.close()}let bt;function mt(t){return(bt||(bt=new Promise((t,e)=>{const n=indexedDB.open("PUSHWOOSH_SDK_STORE",7);n.onsuccess=n=>{const o=n.target.result;o.onversionchange=ft.bind(null,o,e),t(o)},n.onerror=()=>e(n.error),n.onupgradeneeded=t=>{const n=t.target.result;n.onversionchange=ft.bind(null,n,e),new pt(n).applyMigrations()}})),bt).then(e=>new Promise((n,o)=>t(e,n,o)))}class gt{_add(t){return mt((e,n,o)=>{const i=e.transaction([this.name],"readwrite").objectStore(this.name).add(t);i.onsuccess=()=>{n(t)},i.onerror=()=>{o(i.error)}}).then(t=>this.getAll().then(e=>{if(Array.isArray(e)){const n=e.map(t=>t.id).sort((t,e)=>t==e?0:t<e?1:-1);if(n.length>this.maxItems)return Promise.all(n.slice(this.maxItems).map(t=>this.delete(t))).then(()=>t)}return t}))}delete(t){return mt((e,n,o)=>{const i=e.transaction([this.name],"readwrite").objectStore(this.name).delete(t);i.onsuccess=()=>{n(i.result)},i.onerror=()=>{o(i.error)}})}getAll(){return mt((t,e,n)=>{const o=[],i=t.transaction(this.name).objectStore(this.name).openCursor();i.onsuccess=t=>{const n=t.target.result;n?(n.value&&o.push(n.value),n.continue()):e(o)},i.onerror=()=>{n(i.error)}})}}yt=at;var yt;const xt=new class extends gt{constructor(){super(...arguments),this.name="log",this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(t,e,n){const o={type:t,environment:this.environment,message:`${e}`,date:new Date};return e instanceof Error&&(o.stack=e.stack),n&&(o.additional=n),this._add(o)}},wt=(new class extends gt{constructor(){super(...arguments),this.name=ct,this.maxItems=25}add(t){return this._add({...t,date:new Date})}},{error:1,info:2,debug:3});let vt=3;const kt={setLevel(t){wt[t]||(t="error"),vt=wt[t]},write(t,e,n){return"error"===t?this.error(e):this.info(e),xt.add(t,e,n)}};Object.keys(wt).forEach(t=>{const e=wt[t];kt[t]=(...n)=>{e<=vt&&(console.groupCollapsed(t),console.info("",...n),console.trace("trace"),console.groupEnd())}});const Mt="Pushwoosh subscription widget:";class St{constructor(t){this.permission="unsupported",this.open=!1,this.busy=!1,this.container=null,this.autoShowTimer=null,this.pw=t,this.config=function(t){const e=y,n=O(t),o=O(n.prompt),i=O(n.launcher),r=O(n.display),s=g,a=R(o.layout,f,e.prompt.layout),c=p[a],l=R(r.trigger,m,e.display.trigger),d=B(o.iconUrl),u=B(i.imageUrl),h=H({colors:n.colors}),x=L({dark:n.dark},h),w=!0===o.enabled,v=!0===i.enabled;return{enable:w||v,prompt:{enabled:w,layout:a,position:R(o.position,c,c[0]),...d?{iconUrl:d}:{},borderRadius:W(o.borderRadius,s.borderRadius,e.prompt.borderRadius),overlay:"modal"===a||!0===o.overlay},launcher:{enabled:v,position:R(i.position,b,e.launcher.position),offset:W(i.offset,s.offset,e.launcher.offset),width:W(i.width,s.launcherSize,e.launcher.width),height:W(i.height,s.launcherSize,e.launcher.height),...u?{imageUrl:u}:{},...U("background",i.background),...U("iconColor",i.iconColor)},display:{trigger:l,delay:W(r.delay,s.delay,e.display.delay),cappingCount:W(r.cappingCount,s.cappingCount,e.display.cappingCount),cappingInterval:W(r.cappingInterval,s.cappingInterval,e.display.cappingInterval)},texts:V(O(n.texts)),colors:h,...x?{dark:x}:{},fontFamily:q(n.fontFamily,e.fontFamily),zIndex:W(n.zIndex,s.zIndex,e.zIndex)}}(t.initParams.subscriptionWidget),this.accept=this.accept.bind(this),this.decline=this.decline.bind(this),this.toggle=this.toggle.bind(this),this.launcherClick=this.launcherClick.bind(this),t.moduleRegistry.subscriptionWidget=this}async run(){const{pw:t,config:e}=this;e.enable&&t.isPushAvailable()&&(this.permission=await this.readPermission(),this.mount(),this.listenSubscriptionChanges(),await this.scheduleAutoShow())}show(){this.container&&this.config.prompt.enabled&&_(this.permission)&&!this.open&&(this.open=!0,this.render(),this.pw.dispatchEvent("show-subscription-widget",{}))}hide(){this.open&&(this.open=!1,this.busy=!1,this.render(),this.pw.dispatchEvent("hide-subscription-widget",{}))}toggle(t){t??!this.open?this.show():this.hide()}isVisible(){return this.open}async readPermission(){const t=this.pw.driver?.getPermission();return"denied"===t?"denied":await this.pw.isSubscribed()?"granted":"default"}mount(){const t=document.createElement("div");t.id="pushwoosh-subscription-widget",t.style.position="fixed",t.style.inset="0",t.style.zIndex=String(this.config.zIndex),t.style.pointerEvents="none",document.body.appendChild(t),this.container=document.createElement("div"),t.attachShadow({mode:"open"}).appendChild(this.container),this.render()}render(){var t;if(this.container)return this.open||$(this.config,this.permission)?void((t,e)=>{(0,K.render)((0,G.jsx)(st,{...e,mode:"live"}),t)})(this.container,{config:this.config,permission:this.permission,open:this.open,busy:this.busy,onAccept:this.accept,onDecline:this.decline,onLauncherClick:this.launcherClick}):(t=this.container,void(0,K.render)(null,t))}async scheduleAutoShow(){const t=await this.pw.data.getSubscriptionWidgetHistory();(function(t,e,n,o){const{trigger:i,cappingCount:r,cappingInterval:s}=t.display;return!(!t.prompt.enabled||"auto"!==i||"default"!==e||r>0&&n.shownCount>=r||!(null===n.lastShownAt||o-n.lastShownAt>=36e5*s))})(this.config,this.permission,t,Date.now())&&(this.autoShowTimer=setTimeout(async()=>{this.autoShowTimer=null,this.open||"default"!==this.permission||(this.show(),await this.pw.data.setSubscriptionWidgetHistory(function(t,e){return{shownCount:t.shownCount+1,lastShownAt:e}}(t,Date.now())))},1e3*this.config.display.delay))}launcherClick(){const t=(e=this.config,n=this.permission,e.prompt.enabled?"prompt":"default"===n?"subscribe":"none");var e,n;"prompt"===t?this.toggle():"subscribe"===t&&this.subscribeFromLauncher()}async subscribeFromLauncher(){try{await this.pw.subscribe()}catch(t){kt.error(t,`${Mt} failed to subscribe`)}this.permission=await this.readPermission(),this.render()}async accept(){this.busy=!0,this.render();try{await this.pw.subscribe()}catch(t){kt.error(t,`${Mt} failed to subscribe`)}if(this.permission=await this.readPermission(),"denied"===this.permission)return this.busy=!1,void this.render();this.hide()}decline(){this.hide()}listenSubscriptionChanges(){const t=async()=>{this.permission=await this.readPermission(),"granted"===this.permission&&(this.cancelAutoShow(),this.hide()),this.render()};this.pw.addSdkEventHandler("subscribe",t),this.pw.addSdkEventHandler("unsubscribe",t),this.pw.addSdkEventHandler("permission-denied",t)}cancelAutoShow(){null!==this.autoShowTimer&&(clearTimeout(this.autoShowTimer),this.autoShowTimer=null)}}return s})());
2
2
  //# sourceMappingURL=widget-subscription.js.map