web-push-notifications 3.74.0 → 3.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/widget-inbox.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var i in n)("object"==typeof exports?exports:t)[i]=n[i]}}(this,()=>(()=>{"use strict";const t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let e={};t.r(e),t.d(e,{PWInboxWidget:()=>a});const n=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"],i=[{name:"widgetWidth",type:"size"},{name:"borderRadius",type:"size"},{name:"zIndex",type:"number"},{name:"fontFamily",type:"string"},{name:"bgColor",type:"color"},{name:"textColor",type:"color"},{name:"arrowBorderColor",type:"color"},{name:"borderColor",type:"color"},{name:"badgeBgColor",type:"color"},{name:"badgeTextColor",type:"color"},{name:"timeTextColor",type:"color"},{name:"messageTitleColor",type:"color"},{name:"emptyInboxTitleColor",type:"color"},{name:"emptyInboxTextColor",type:"color"}],o={enable:!1,triggerId:"pwInbox",position:"bottom",appendTo:"body",title:"Inbox",bgColor:"#ffffff",textColor:"#333333",fontFamily:"inherit",borderRadius:4,borderColor:"transparent",badgeBgColor:"#ff4c00",badgeTextColor:"#ffffff",widgetWidth:350,zIndex:100,messageTitleColor:"#7a7a7a",timeTextColor:"#c4c4c4",emptyInboxTitle:"You're all caught up",emptyInboxTitleColor:"#333333",emptyInboxText:"There are no new messages. Stay tuned!",emptyInboxTextColor:"#7a7a7a",emptyInboxIconUrl:"https://pushon.pushwoosh.com/static/icon-empty-inbox.png",arrowBorderColor:"rgba(0,0,0,.1)"},s=/^(#([\da-f]{3}){1,2}$|(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0?\.\d+)\)$|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/;function r(t){let e="fixed"===window.getComputedStyle(t).position;return!e&&t.parentElement&&(e=r(t.parentElement)),e}const d=({imageUrl:t,title:e,message:i,sendDate:o})=>`\n<div class="pw-inbox_item-inner">\n <div class="pw-inbox_icon">\n <img src="${t}" alt="${e||i}" class="pw-inbox_message-image">\n </div>\n <div class="pw-inbox_content">\n ${e?`<div class="pw-inbox_item-title">\n ${e}\n </div>`:null}\n <div class="pw-inbox_item-body">\n ${i}\n </div>\n <div class="pw-inbox_item-time">\n ${function(t){const e=new Date(t),i=e.getHours()+e.getTimezoneOffset()/60;e.setHours(i);const o=(new Date).getTime()-e.getTime();if(o<=6e4)return"Just now";if(o<36e5&&o>0)return`${Math.floor(o/6e4)} minutes ago`;if(o<864e5&&o>0)return`${Math.floor(o/36e5)} hours ago`;return`${e.getDate()} ${n[e.getMonth()]} ${e.getFullYear()}, ${e.getHours()}:${`0${e.getMinutes().toString()}`.slice(-2)}`}(o)}\n </div>\n </div>\n</div>\n<span class="pw-inbox_item-remove"></span>`;class a{constructor(t){this.pw=t;const e=this.pw.initParams.inboxWidget;this.config={...o,arrowBorderColor:e.borderColor&&"transparent"!==e.borderColor?e.borderColor:"rgba(0,0,0,.1)",...this.pw.initParams.inboxWidget},this.updateInbox=this.updateInbox.bind(this),this.markVisibleItemsAsRead=this.markVisibleItemsAsRead.bind(this),this.onWidgetClickHandler=this.onWidgetClickHandler.bind(this),this.onTriggerClickHandler=this.onTriggerClickHandler.bind(this),this.onWindowScrollHandler=this.onWindowScrollHandler.bind(this),this.toggle=this.toggle.bind(this)}async run(){this.initTrigger(),this.updateInbox(),this.addListeners()}toggle(t){(void 0===t?!this.isOpened:t)?this.openWidget():this.closeWidget()}initTrigger(){if(!this.pw.pwinbox)throw new Error("Web inbox is not allowed.");const t=document.getElementById(this.config.triggerId);if(!t)throw new Error("Inbox trigger element doesn't exist. You must set triggerId in inboxWidget config. See the documentation.");this.trigger=t,this.trigger.classList.add("pw-inbox-trigger"),this.defaultMargin=12,this.messagesElements={},this.messages=[],this.readItems=[],this.updateCounter(0),this.isOpened=!1,this.renderWidget(),this.isFixed=r(this.trigger)}renderWidget(){this.widget=document.createElement("div"),this.widget.id="pwInboxWidget",this.widget.className="pw-inbox-widget",this.widget.classList.toggle("pw-open",this.isOpened),this.widgetParent=document.querySelector(this.config.appendTo)||document.body,this.widgetParent.appendChild(this.widget),this.widgetParent.appendChild(this.getStyle()),this.renderWidgetInner()}getStyle(){const t=document.createElement("style");return t.innerHTML=this.configureStyle(".pw-inbox-trigger {\n position: relative;\n cursor: pointer;\n}\n\n.pw-inbox-trigger:after {\n content: attr(data-pw-count);\n display: block;\n position: absolute;\n right: 0;\n top: 0;\n background: var(--badgeBgColor);\n border-radius: 8px;\n color: var(--badgeTextColor);\n font-size: 10px;\n font-weight: normal;\n line-height: 16px;\n width: 16px;\n padding: 0 2px;\n box-sizing: border-box;\n text-align: center;\n}\n\n.pw-inbox-trigger.pw-empty:after {\n display: none;\n}\n\n.pw-inbox-widget * {\n position: static;\n box-sizing: border-box;\n font-size: 1em;\n outline: none;\n font-family: var(--fontFamily);\n}\n.pw-inbox-widget {\n font-size: 14px;\n position: absolute;\n top: 0;\n left: -1000px;\n background: var(--bgColor);\n border: solid 1px var(--borderColor);\n border-radius: var(--borderRadius);\n width: var(--widgetWidth);\n box-shadow: 0 1px 4px 0 rgba(0,0,0,.25);\n z-index: var(--zIndex);\n opacity: 0;\n transition: opacity .6s ease;\n transition-delay: 100ms;\n}\n.pw-inbox-widget.pw-open {\n opacity: 1;\n transition-delay: 0ms;\n}\n.pw-inbox-widget.pw-inbox-widget--inset {\n top: auto;\n left: auto;\n display: none;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-open {\n display: block;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-bottom {\n top: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-top {\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-right {\n left: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-left {\n right: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--empty {\n max-height: none;\n}\n.pw-inbox-widget .pw-inbox__arrow {\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget .pw-inbox__arrow:before {\n content: \"\";\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget.pw-top {\n margin-top: -12px;\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow {\n border-top-color: var(--arrowBorderColor);\n bottom: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow:before {\n border-top-color: var(--bgColor);\n top: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-bottom {\n margin-top: 12px;\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow {\n border-bottom-color: var(--arrowBorderColor);\n top: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow:before {\n border-bottom-color: var(--bgColor);\n bottom: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-left {\n margin-left: -12px;\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow {\n border-left-color: var(--arrowBorderColor);\n right: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow:before {\n border-left-color: var(--bgColor);\n left: -11px;\n top: -10px;\n}\n.pw-inbox-widget.pw-right {\n margin-left: 12px;\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow {\n border-right-color: var(--arrowBorderColor);\n left: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow:before {\n border-right-color: var(--bgColor);\n right: -11px;\n top: -10px;\n}\n.pw-inbox_inner {\n overflow: hidden;\n display: flex;\n flex-direction: column;\n height: 100%;\n}\n.pw-inbox_title {\n color: var(--textColor);\n margin: 0;\n padding: 28px 32px 12px;\n font-size: 24px;\n font-weight: 500;\n line-height: 1.1;\n text-align: left;\n flex: 0 0 66px;\n}\n.pw-inbox_list {\n overflow-x: hidden;\n overflow-y: auto;\n min-width: 200px;\n max-height: 300px;\n padding: 0;\n margin: 0;\n list-style: none;\n position: relative;\n flex: 1 1 auto;\n}\n\n.pw-inbox_item {\n position: relative;\n padding: 8px 32px;\n margin: 0;\n text-align: left;\n}\n.pw-inbox_item-inner {\n display: flex;\n cursor: pointer;\n}\n.pw-inbox_icon {\n flex: 0 0 40px;\n}\n.pw-inbox_message-image {\n width: 28px;\n}\n.pw-inbox_content {\n flex: 0 1 100%;\n}\n.pw-inbox_item-title {\n color: var(--messageTitleColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n}\n.pw-inbox_item-body {\n color: var(--textColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n}\n.pw-inbox_item-time {\n color: var(--timeTextColor);\n font-size: 12px;\n line-height: 17px;\n}\n.pw-inbox_item-remove {\n position: absolute;\n z-index: 2;\n top: 8px;\n right: 8px;\n display: none;\n width: 10px;\n height: 10px;\n background: transparent url('https://cdn.pushwoosh.com/webpush/img/iconClose.svg') 50% no-repeat;\n cursor: pointer;\n}\n.pw-inbox_item:hover .pw-inbox_item-remove {\n display: block;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-title {\n color: var(--textColor);\n font-weight: 700;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-body {\n font-weight: 700;\n}\n\n.pw-inbox_list--empty {\n padding: 50px 16px;\n text-align: center;\n max-height: 100%;\n overflow: auto;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-icon {\n text-align: center;\n margin-bottom: 30px;\n}\n.pw-inbox_list--empty .pw-inbox_list-icon img {\n max-width: 100%;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-title {\n font-size: 28px;\n line-height: 36px;\n color: var(--emptyInboxTitleColor);\n margin-bottom: 20px;\n}\n\n.pw-inbox_list--empty .ipw-inbox_list-body {\n font-size: 14px;\n line-height: 18px;\n color: var(--emptyInboxTextColor);\n}\n"),t}configureStyle(t){let e=t.toString();return i.forEach(t=>{const n=new RegExp(`var\\(--${t.name}\\)`,"ig"),i=this.getStyleFormatter(t);e=e.replace(n,i)}),e}getStyleFormatter(t){switch(t.type){case"size":return`${this.config[t.name]||0}px`;case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return"transparent"===(e=this.config[t.name].toString())||s.test(e)?e:"#333";default:return"none"}var e}renderWidgetInner(){if(this.messages.length>0)this.widget.classList.remove("pw-inbox-widget--empty"),this.widget.innerHTML=`\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_inner">\n <div class="pw-inbox_title">\n ${this.config.title}\n </div>\n <ul class="pw-inbox_list">\n\n </ul>\n</div>`,this.renderMessages();else{this.widget.classList.add("pw-inbox-widget--empty");const{emptyInboxTitle:t,emptyInboxText:e,emptyInboxIconUrl:n}=this.config;this.widget.innerHTML=((t,e,n)=>`\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_list--empty">\n <div class="pw-inbox_list-icon">\n <img src="${t}" alt="${e}">\n </div>\n <div class="pw-inbox_list-title">\n ${e}\n </div>\n <div class="ipw-inbox_list-body">\n ${n}\n </div>\n</div>`)(n,t,e)}}renderMessages(){this.list=this.widget.querySelector(".pw-inbox_list")||document.createElement("ul"),this.messages.forEach(t=>{const e=document.createElement("li");e.className="pw-inbox_item",e.classList.toggle("pw-new",!t.isRead),e.classList.toggle("pw-unread",!t.isActionPerformed),e.setAttribute("data-pw-inbox-message-id",t.code),e.innerHTML=d(t),this.list.appendChild(e),this.messagesElements[t.code]=e})}updateCounter(t){this.count=t,this.trigger.setAttribute("data-pw-count",`${this.count}`),this.trigger.classList.toggle("pw-empty",0===this.count)}updateInboxMessages(t){this.messages=t.sort(({sendDate:t},{sendDate:e})=>function(t,e){const n=new Date(t),i=n.getHours()+n.getTimezoneOffset()/60,o=new Date(e),s=o.getHours()+o.getTimezoneOffset()/60;return n.setHours(i),o.setHours(s),o.getTime()-n.getTime()}(t,e)),this.renderWidgetInner()}openWidget(){this.isOpened=!0,this.widget.classList.add("pw-open"),document.addEventListener("click",this.onWidgetClickHandler),window.addEventListener("scroll",this.onWindowScrollHandler),window.addEventListener("resize",this.onWindowScrollHandler),this.markVisibleItemsAsRead(),this.messages.length>0&&this.list.addEventListener("scroll",this.markVisibleItemsAsRead),this.positionWidget()}closeWidget(){this.isOpened=!1,document.removeEventListener("click",this.onWidgetClickHandler),document.removeEventListener("click",this.onWindowScrollHandler),window.removeEventListener("resize",this.onWindowScrollHandler),this.updateReadStatus(),this.messages.length>0&&this.list.removeEventListener("scroll",this.markVisibleItemsAsRead),this.widget.classList.remove("pw-open","pw-top","pw-bottom","pw-right","pw-left"),this.widget.removeAttribute("style")}positionWidget(){this.isOpened&&(this.widgetParent===document.body?this.defaultPlaceWidget():this.customPlaceWidget())}customPlaceWidget(){const{position:t}=this.config;this.widgetParent.style.position="relative",this.widget.classList.add("pw-inbox-widget--inset"),this.widget.classList.add(`pw-${t}`)}defaultPlaceWidget(){const t=this.pw.initParams.inboxWidget.position?this.config.position:this.getDefaultPosition(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0);switch(e.width+2*this.defaultMargin>n&&(this.widget.style.width=n-2*this.defaultMargin+"px"),e.height+24>i&&(this.widget.style.height=i-2*this.defaultMargin+"px"),t){case"top":this.alignWidgetTop();break;case"right":this.alignWidgetRight();break;case"left":this.alignWidgetLeft();break;case"bottom":this.alignWidgetBottom()}}alignWidgetTop(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-top");let o=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2);const s=o<pageXOffset,r=o+e.width>pageXOffset+n;s&&(o=pageXOffset+this.defaultMargin),r&&(o=pageXOffset+n-e.width-this.defaultMargin);const d=pageYOffset+t.top-e.height;this.alignWidgetElement(o,d),i.style.left=t.left+Math.floor(t.width/2)-o+"px";const a=this.widget.getBoundingClientRect().top;if(a<0){const t=this.widget.getBoundingClientRect().height+a-this.defaultMargin,e=this.widget.getBoundingClientRect().top-a+this.defaultMargin;this.widget.style.height=`${t}px`,this.widget.style.top=`${e}px`}}alignWidgetRight(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0),o=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-right");let s=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2);const r=s<pageYOffset,d=pageYOffset+i<s+e.height;r&&(s=pageYOffset+this.defaultMargin),d&&(s=pageYOffset+i-e.height-this.defaultMargin);const a=pageXOffset+t.left+t.width;this.alignWidgetElement(a,s),o.style.top=t.top+Math.floor(t.height/2)-s+"px";const l=n-this.widget.getBoundingClientRect().right;if(l<this.defaultMargin){const t=this.widget.getBoundingClientRect().width+l-this.defaultMargin;this.widget.style.width=`${t}px`}}alignWidgetLeft(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientHeight,window.innerHeight||0),i=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-left");let o=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2);const s=o<pageYOffset,r=pageYOffset+n<o+e.height;s&&(o=pageYOffset+this.defaultMargin),r&&(o=pageYOffset+n-e.height-this.defaultMargin);const d=pageXOffset+t.left-e.width;this.alignWidgetElement(d,o),i.style.top=t.top+Math.floor(t.height/2)-o+"px";const a=this.widget.getBoundingClientRect().left;if(a<0){const t=this.widget.getBoundingClientRect().width+a-this.defaultMargin,e=this.widget.getBoundingClientRect().left-a;this.widget.style.width=`${t}px`,this.widget.style.left=`${e}px`}}alignWidgetBottom(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0),o=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-bottom");let s=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2);const r=s<pageXOffset,d=s+e.width>pageXOffset+n;r&&(s=pageXOffset+this.defaultMargin),d&&(s=pageXOffset+n-e.width-12);const a=pageYOffset+t.top+t.height;this.alignWidgetElement(s,a),o.style.left=t.left+Math.floor(t.width/2)-s+"px";const l=i-this.widget.getBoundingClientRect().bottom;if(l<this.defaultMargin){const t=this.widget.getBoundingClientRect().height+l-this.defaultMargin;this.widget.style.height=`${t}px`}}alignWidgetElement(t,e){this.widget.style.left=`${t}px`,this.widget.style.top=`${e}px`}getDefaultPosition(){const{left:t,top:e,width:n,height:i}=this.trigger.getBoundingClientRect();if(!document.documentElement)return"";const o={right:t,bottom:e,left:Math.max(document.documentElement.clientWidth,window.innerWidth||0)-(t+n),top:Math.max(document.documentElement.clientHeight,window.innerHeight||0)-(e+i)},s=Math.min(t,e,o.left,o.top);let r="bottom";return Object.keys(o).forEach(t=>{o[t]===s&&(r=t)}),r}addListeners(){this.trigger.addEventListener("click",this.onTriggerClickHandler),this.pw.push(["onPutNewMessageToInboxStore",()=>{this.updateInbox()}]),this.pw.push(["onUpdateInboxMessages",()=>{this.updateInbox()}])}markVisibleItemsAsRead(){if(0===this.messages.length)return;const t=this.list.clientHeight+this.list.scrollTop-50;Object.keys(this.messagesElements).forEach(e=>{if(!this.messagesElements[e]||this.messagesElements[e].offsetTop>t)return;const n=this.messages.find(t=>t.code===e);!n||n.isRead||this.readItems.indexOf(e)+1||this.readItems.push(e)})}updateReadStatus(){this.pw.pwinbox.readMessagesWithCodes(this.readItems).then(this.updateInbox)}updateInbox(){this.pw.pwinbox.loadMessages().then(t=>{this.updateInboxMessages(t)}),this.pw.pwinbox.unreadMessagesCount().then(t=>{this.updateCounter(t)})}performMessageAction(t){this.pw.pwinbox.performActionForMessageWithCode(t).then(()=>{this.updateInbox()})}removeMessages(t){t.forEach(t=>{this.readItems=this.readItems.slice(this.readItems.indexOf(t),1)}),this.pw.pwinbox.deleteMessagesWithCodes(t).then(()=>{this.updateInbox()})}onTriggerClickHandler(t){t.stopPropagation(),t.target&&this.toggle()}onWidgetClickHandler(t){if(!t.target)return;const e=t.target.closest(".pw-inbox_item");if(!e)return void this.toggle();const n=e.getAttribute("data-pw-inbox-message-id");if(!n)return;t.target.closest(".pw-inbox_item-remove")?this.removeMessages([n]):this.performMessageAction(n)}onWindowScrollHandler(){this.isFixed&&this.isOpened?this.toggle():this.positionWidget()}}return e})());
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var i in n)("object"==typeof exports?exports:t)[i]=n[i]}}(this,()=>(()=>{"use strict";const t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let e={};t.r(e),t.d(e,{PWInboxWidget:()=>f});const n=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"],i=[{name:"widgetWidth",type:"size"},{name:"borderRadius",type:"size"},{name:"zIndex",type:"number"},{name:"fontFamily",type:"string"},{name:"bgColor",type:"color"},{name:"textColor",type:"color"},{name:"arrowBorderColor",type:"color"},{name:"borderColor",type:"color"},{name:"badgeBgColor",type:"color"},{name:"badgeTextColor",type:"color"},{name:"timeTextColor",type:"color"},{name:"messageTitleColor",type:"color"},{name:"emptyInboxTitleColor",type:"color"},{name:"emptyInboxTextColor",type:"color"},{name:"unreadDotColor",type:"color"},{name:"avatarBgColor",type:"color"},{name:"avatarTextColor",type:"color"},{name:"avatarSize",type:"size"},{name:"mediaRadius",type:"size"},{name:"slideCaptionColor",type:"color"},{name:"slideScrimColor",type:"color"},{name:"pagerDotActiveColor",type:"color"},{name:"pagerDotColor",type:"color"}],o={enable:!1,triggerId:"pwInbox",position:"bottom",appendTo:"body",title:"Inbox",bgColor:"#ffffff",textColor:"#333333",fontFamily:"inherit",borderRadius:4,borderColor:"transparent",badgeBgColor:"#ff4c00",badgeTextColor:"#ffffff",widgetWidth:350,zIndex:100,messageTitleColor:"#7a7a7a",timeTextColor:"#c4c4c4",emptyInboxTitle:"You're all caught up",emptyInboxTitleColor:"#333333",emptyInboxText:"There are no new messages. Stay tuned!",emptyInboxTextColor:"#7a7a7a",emptyInboxIconUrl:"https://pushon.pushwoosh.com/static/icon-empty-inbox.png",arrowBorderColor:"rgba(0,0,0,.1)",legacyClassicCell:!1,unreadDotColor:"#00a2ff",avatarBgColor:"#c4c8cc",avatarTextColor:"#4b5057",avatarSize:52,mediaRadius:8,slideCaptionColor:"#ffffff",slideScrimColor:"rgba(0,0,0,.45)",pagerDotActiveColor:"#00a2ff",pagerDotColor:"#ebf0f5"};function s(t){let e="fixed"===window.getComputedStyle(t).position;return!e&&t.parentElement&&(e=s(t.parentElement)),e}const r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a=/[&<>"']/g,l=RegExp(a.source);function d(t){return t&&l.test(t)?t.replace(a,t=>r[t]):t}const p=({title:t,message:e,sendDate:i,isRead:o})=>`\n<div class="pw-inbox_content">\n <div class="pw-inbox_item-title">\n ${d(t)}${o?"":'<span class="pw-inbox_unread-dot"></span>'}\n </div>\n <div class="pw-inbox_item-body">\n ${d(e)}\n </div>\n <div class="pw-inbox_item-time">\n ${d(function(t){const e=new Date(t),i=(new Date).getTime()-e.getTime();if(i<=6e4)return"Just now";if(i<36e5&&i>0)return`${Math.floor(i/6e4)} minutes ago`;if(i<864e5&&i>0)return`${Math.floor(i/36e5)} hours ago`;return`${e.getDate()} ${n[e.getMonth()]} ${e.getFullYear()}, ${e.getHours()}:${`0${e.getMinutes().toString()}`.slice(-2)}`}(i))}\n </div>\n</div>`,g=(t,e)=>`\n<div class="pw-inbox_media">\n <img src="${d(t)}" alt="${d(e)}" class="pw-inbox_hero">\n</div>`,c=(t,e=0)=>{const{layout:n,heroUrl:i,carousel:o,title:s,message:r}=t,a=s||r;let l;switch(n){case"banner":l=g(i,a);break;case"captioned":l=`${g(i,a)}${p(t)}`;break;case"carousel":l=`${((t,e,n)=>{const i=t[e],o=i.caption?`<span class="pw-inbox_slide-caption">${d(i.caption)}</span>`:"",s=t.length>1?`<div class="pw-inbox_pager">${t.map((t,n)=>`<button type="button" class="pw-inbox_dot${n===e?" pw-active":""}" data-pw-slide="${n}"></button>`).join("")}</div>`:"";return`\n<div class="pw-inbox_media">\n <div class="pw-inbox_slide" data-pw-slide-link="${d(i.link)}">\n <img src="${d(i.imageUrl)}" alt="${d(i.caption||n)}" class="pw-inbox_hero">\n ${o}\n </div>\n ${s}\n</div>`})(o,Math.min(e,o.length-1),a)}${p(t)}`;break;default:l=`<div class="pw-inbox_icon">${(({iconUrl:t,title:e,message:n})=>t?`<img src="${d(t)}" alt="${d(e||n)}" class="pw-inbox_message-image">`:`<span class="pw-inbox_icon-initial">${d(function(t,e){return(t||e||"?").trim().charAt(0).toUpperCase()||"?"}(e,n))}</span>`)(t)}</div>${p(t)}`}return`\n<div class="pw-inbox_item-inner pw-inbox_item--${d(n)}">\n ${l}\n</div>\n<span class="pw-inbox_item-remove"></span>`},h="#333",w=/[;{}]/;let b=null;const m=/^(?:javascript|vbscript|data|blob|file):/i;function x(t){return t.split("").filter(t=>t.charCodeAt(0)>32&&127!==t.charCodeAt(0)).join("")}class f{constructor(t){this.lastSyncAt=0,this.pw=t;const e=this.pw.initParams.inboxWidget;this.config={...o,arrowBorderColor:e.borderColor&&"transparent"!==e.borderColor?e.borderColor:"rgba(0,0,0,.1)",...this.pw.initParams.inboxWidget},this.updateInbox=this.updateInbox.bind(this),this.markVisibleItemsAsRead=this.markVisibleItemsAsRead.bind(this),this.onWidgetClickHandler=this.onWidgetClickHandler.bind(this),this.onTriggerClickHandler=this.onTriggerClickHandler.bind(this),this.onWindowScrollHandler=this.onWindowScrollHandler.bind(this),this.toggle=this.toggle.bind(this)}async run(){this.initTrigger(),this.updateInbox(),this.addListeners()}toggle(t){(void 0===t?!this.isOpened:t)?this.openWidget():this.closeWidget()}initTrigger(){if(!this.pw.pwinbox)throw new Error("Web inbox is not allowed.");const t=document.getElementById(this.config.triggerId);if(!t)throw new Error("Inbox trigger element doesn't exist. You must set triggerId in inboxWidget config. See the documentation.");this.trigger=t,this.trigger.classList.add("pw-inbox-trigger"),this.lastSyncAt=Date.now(),this.defaultMargin=12,this.messagesElements={},this.activeSlides={},this.messages=[],this.readItems=[],this.updateCounter(0),this.isOpened=!1,this.renderWidget(),this.isFixed=s(this.trigger)}renderWidget(){this.widget=document.createElement("div"),this.widget.id="pwInboxWidget",this.widget.className="pw-inbox-widget",this.widget.classList.toggle("pw-open",this.isOpened),this.widget.classList.toggle("pw-inbox-widget--legacy-cell",this.config.legacyClassicCell),this.widgetParent=document.querySelector(this.config.appendTo)||document.body,this.widgetParent.appendChild(this.widget),this.widgetParent.appendChild(this.getStyle()),this.renderWidgetInner()}getStyle(){const t=document.createElement("style");return t.innerHTML=this.configureStyle(".pw-inbox-trigger {\n position: relative;\n cursor: pointer;\n}\n\n.pw-inbox-trigger:after {\n content: attr(data-pw-count);\n display: block;\n position: absolute;\n right: 0;\n top: 0;\n background: var(--badgeBgColor);\n border-radius: 8px;\n color: var(--badgeTextColor);\n font-size: 10px;\n font-weight: normal;\n line-height: 16px;\n width: 16px;\n padding: 0 2px;\n box-sizing: border-box;\n text-align: center;\n}\n\n.pw-inbox-trigger.pw-empty:after {\n display: none;\n}\n\n.pw-inbox-widget * {\n position: static;\n box-sizing: border-box;\n font-size: 1em;\n outline: none;\n font-family: var(--fontFamily);\n}\n.pw-inbox-widget {\n font-size: 14px;\n position: absolute;\n top: 0;\n left: -1000px;\n background: var(--bgColor);\n border: solid 1px var(--borderColor);\n border-radius: var(--borderRadius);\n width: var(--widgetWidth);\n box-shadow: 0 1px 4px 0 rgba(0,0,0,.25);\n z-index: var(--zIndex);\n opacity: 0;\n transition: opacity .6s ease;\n transition-delay: 100ms;\n}\n.pw-inbox-widget.pw-open {\n opacity: 1;\n transition-delay: 0ms;\n}\n.pw-inbox-widget.pw-inbox-widget--inset {\n top: auto;\n left: auto;\n display: none;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-open {\n display: block;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-bottom {\n top: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-top {\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-right {\n left: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-left {\n right: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--empty {\n max-height: none;\n}\n.pw-inbox-widget .pw-inbox__arrow {\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget .pw-inbox__arrow:before {\n content: \"\";\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget.pw-top {\n margin-top: -12px;\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow {\n border-top-color: var(--arrowBorderColor);\n bottom: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow:before {\n border-top-color: var(--bgColor);\n top: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-bottom {\n margin-top: 12px;\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow {\n border-bottom-color: var(--arrowBorderColor);\n top: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow:before {\n border-bottom-color: var(--bgColor);\n bottom: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-left {\n margin-left: -12px;\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow {\n border-left-color: var(--arrowBorderColor);\n right: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow:before {\n border-left-color: var(--bgColor);\n left: -11px;\n top: -10px;\n}\n.pw-inbox-widget.pw-right {\n margin-left: 12px;\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow {\n border-right-color: var(--arrowBorderColor);\n left: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow:before {\n border-right-color: var(--bgColor);\n right: -11px;\n top: -10px;\n}\n.pw-inbox_inner {\n overflow: hidden;\n display: flex;\n flex-direction: column;\n height: 100%;\n}\n.pw-inbox_title {\n color: var(--textColor);\n margin: 0;\n padding: 28px 32px 12px;\n font-size: 24px;\n font-weight: 500;\n line-height: 1.1;\n text-align: left;\n flex: 0 0 66px;\n}\n.pw-inbox_list {\n overflow-x: hidden;\n overflow-y: auto;\n min-width: 200px;\n max-height: 300px;\n padding: 0;\n margin: 0;\n list-style: none;\n position: relative;\n flex: 1 1 auto;\n}\n\n.pw-inbox_item {\n position: relative;\n padding: 8px 32px;\n margin: 0;\n text-align: left;\n}\n.pw-inbox_item-inner {\n display: flex;\n cursor: pointer;\n}\n.pw-inbox_icon {\n flex: 0 0 auto;\n width: var(--avatarSize);\n height: var(--avatarSize);\n margin-right: 14px;\n overflow: hidden;\n border-radius: var(--mediaRadius);\n background: var(--avatarBgColor);\n display: flex;\n align-items: center;\n justify-content: center;\n}\n.pw-inbox_message-image {\n width: 100%;\n height: 100%;\n object-fit: cover;\n display: block;\n}\n.pw-inbox_icon-initial {\n color: var(--avatarTextColor);\n font-size: 22px;\n line-height: 1;\n font-weight: 700;\n}\n.pw-inbox_content {\n flex: 1 1 auto;\n min-width: 0;\n}\n.pw-inbox_item-title {\n color: var(--messageTitleColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n display: flex;\n align-items: center;\n gap: 6px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.pw-inbox_unread-dot {\n flex: 0 0 auto;\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: var(--unreadDotColor);\n}\n.pw-inbox_item-body {\n color: var(--textColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n overflow: hidden;\n}\n.pw-inbox_item-time {\n color: var(--timeTextColor);\n font-size: 12px;\n line-height: 17px;\n}\n.pw-inbox_item-remove {\n position: absolute;\n z-index: 2;\n top: 8px;\n right: 8px;\n display: none;\n width: 10px;\n height: 10px;\n background: transparent url('https://cdn.pushwoosh.com/webpush/img/iconClose.svg') 50% no-repeat;\n cursor: pointer;\n}\n.pw-inbox_item:hover .pw-inbox_item-remove {\n display: block;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-title {\n color: var(--textColor);\n font-weight: 700;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-body {\n font-weight: 700;\n}\n\n.pw-inbox_list--empty {\n padding: 50px 16px;\n text-align: center;\n max-height: 100%;\n overflow: auto;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-icon {\n text-align: center;\n margin-bottom: 30px;\n}\n.pw-inbox_list--empty .pw-inbox_list-icon img {\n max-width: 100%;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-title {\n font-size: 28px;\n line-height: 36px;\n color: var(--emptyInboxTitleColor);\n margin-bottom: 20px;\n}\n\n.pw-inbox_list--empty .ipw-inbox_list-body {\n font-size: 14px;\n line-height: 18px;\n color: var(--emptyInboxTextColor);\n}\n\n/* Cell layouts: banner, captioned and carousel stack their media above the\n texts, so the flex row of the classic cell becomes a column. */\n.pw-inbox_item--banner,\n.pw-inbox_item--captioned,\n.pw-inbox_item--carousel {\n flex-direction: column;\n gap: 12px;\n}\n\n.pw-inbox_media {\n position: relative;\n width: 100%;\n}\n.pw-inbox_hero {\n display: block;\n width: 100%;\n max-width: 100%;\n aspect-ratio: 9 / 4;\n object-fit: cover;\n border-radius: var(--mediaRadius);\n}\n\n.pw-inbox_slide {\n position: relative;\n display: block;\n cursor: pointer;\n}\n.pw-inbox_slide-caption {\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n padding: 14px 10px 6px;\n color: var(--slideCaptionColor);\n font-size: 14px;\n line-height: 20px;\n border-radius: 0 0 var(--mediaRadius) var(--mediaRadius);\n background: linear-gradient(transparent, var(--slideScrimColor));\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n overflow: hidden;\n}\n\n.pw-inbox_pager {\n position: absolute;\n left: 0;\n right: 0;\n bottom: 8px;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n}\n.pw-inbox_dot {\n width: 6px;\n height: 6px;\n padding: 0;\n border: none;\n border-radius: 50%;\n background: var(--pagerDotColor);\n cursor: pointer;\n}\n.pw-inbox_dot.pw-active {\n background: var(--pagerDotActiveColor);\n}\n\n/* `legacyClassicCell` restores the pre-3.75 classic cell. Scoped to classic on\n purpose: the three new layouts have no older look to go back to. */\n.pw-inbox-widget--legacy-cell .pw-inbox_item--classic .pw-inbox_icon {\n display: block;\n flex: 0 0 40px;\n width: auto;\n height: auto;\n margin-right: 0;\n border-radius: 0;\n background: none;\n}\n.pw-inbox-widget--legacy-cell .pw-inbox_item--classic .pw-inbox_message-image {\n width: 28px;\n height: auto;\n object-fit: fill;\n}\n.pw-inbox-widget--legacy-cell .pw-inbox_item--classic .pw-inbox_content {\n flex: 0 1 100%;\n}\n.pw-inbox-widget--legacy-cell .pw-inbox_item--classic .pw-inbox_item-title {\n display: block;\n overflow: visible;\n text-overflow: clip;\n white-space: normal;\n}\n.pw-inbox-widget--legacy-cell .pw-inbox_item--classic .pw-inbox_unread-dot {\n display: none;\n}\n.pw-inbox-widget--legacy-cell .pw-inbox_item--classic .pw-inbox_item-body {\n display: block;\n overflow: visible;\n}\n"),t}configureStyle(t){let e=t.toString();return i.forEach(t=>{const n=new RegExp(`var\\(--${t.name}\\)`,"ig"),i=this.getStyleFormatter(t);e=e.replace(n,i)}),e}getStyleFormatter(t){switch(t.type){case"size":return`${this.config[t.name]||0}px`;case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return e=this.config[t.name].toString(),w.test(e)?h:(b||(b=document.createElement("div")),b.style.color="",b.style.color=e,b.style.color?e:h);default:return"none"}var e}renderWidgetInner(){if(this.messages.length>0)this.widget.classList.remove("pw-inbox-widget--empty"),this.widget.innerHTML=`\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_inner">\n <div class="pw-inbox_title">\n ${this.config.title}\n </div>\n <ul class="pw-inbox_list">\n\n </ul>\n</div>`,this.renderMessages();else{this.widget.classList.add("pw-inbox-widget--empty");const{emptyInboxTitle:t,emptyInboxText:e,emptyInboxIconUrl:n}=this.config;this.widget.innerHTML=((t,e,n)=>`\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_list--empty">\n <div class="pw-inbox_list-icon">\n <img src="${t}" alt="${e}">\n </div>\n <div class="pw-inbox_list-title">\n ${e}\n </div>\n <div class="ipw-inbox_list-body">\n ${n}\n </div>\n</div>`)(n,t,e)}}renderMessages(){this.list=this.widget.querySelector(".pw-inbox_list")||document.createElement("ul"),this.messagesElements={},this.messages.forEach(t=>{const e=document.createElement("li");e.className="pw-inbox_item",e.classList.toggle("pw-new",!t.isRead),e.classList.toggle("pw-unread",!t.isActionPerformed),e.setAttribute("data-pw-inbox-message-id",t.code),e.innerHTML=c(t,this.activeSlides[t.code]||0),this.list.appendChild(e),this.messagesElements[t.code]=e})}updateCounter(t){this.count=t,this.trigger.setAttribute("data-pw-count",`${this.count}`),this.trigger.classList.toggle("pw-empty",0===this.count)}updateInboxMessages(t){this.messages=t.sort(({sendDate:t},{sendDate:e})=>{return n=t,new Date(e).getTime()-new Date(n).getTime();var n}),this.renderWidgetInner()}openWidget(){this.isOpened=!0,this.widget.classList.add("pw-open"),this.syncMessages(),document.addEventListener("click",this.onWidgetClickHandler),window.addEventListener("scroll",this.onWindowScrollHandler),window.addEventListener("resize",this.onWindowScrollHandler),this.markVisibleItemsAsRead(),this.messages.length>0&&this.list.addEventListener("scroll",this.markVisibleItemsAsRead),this.positionWidget()}closeWidget(){this.isOpened=!1,document.removeEventListener("click",this.onWidgetClickHandler),window.removeEventListener("scroll",this.onWindowScrollHandler),window.removeEventListener("resize",this.onWindowScrollHandler),this.updateReadStatus(),this.messages.length>0&&this.list.removeEventListener("scroll",this.markVisibleItemsAsRead),this.widget.classList.remove("pw-open","pw-top","pw-bottom","pw-right","pw-left"),this.widget.removeAttribute("style")}positionWidget(){this.isOpened&&(this.widgetParent===document.body?this.defaultPlaceWidget():this.customPlaceWidget())}customPlaceWidget(){const{position:t}=this.config;this.widgetParent.style.position="relative",this.widget.classList.add("pw-inbox-widget--inset"),this.widget.classList.add(`pw-${t}`)}defaultPlaceWidget(){const t=this.pw.initParams.inboxWidget.position?this.config.position:this.getDefaultPosition(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0);switch(e.width+2*this.defaultMargin>n&&(this.widget.style.width=n-2*this.defaultMargin+"px"),e.height+24>i&&(this.widget.style.height=i-2*this.defaultMargin+"px"),t){case"top":this.alignWidgetTop();break;case"right":this.alignWidgetRight();break;case"left":this.alignWidgetLeft();break;case"bottom":this.alignWidgetBottom()}}alignWidgetTop(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-top");let o=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2);const s=o<pageXOffset,r=o+e.width>pageXOffset+n;s&&(o=pageXOffset+this.defaultMargin),r&&(o=pageXOffset+n-e.width-this.defaultMargin);const a=pageYOffset+t.top-e.height;this.alignWidgetElement(o,a),i.style.left=t.left+Math.floor(t.width/2)-o+"px";const l=this.widget.getBoundingClientRect().top;if(l<0){const t=this.widget.getBoundingClientRect().height+l-this.defaultMargin,e=this.widget.getBoundingClientRect().top-l+this.defaultMargin;this.widget.style.height=`${t}px`,this.widget.style.top=`${e}px`}}alignWidgetRight(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0),o=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-right");let s=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2);const r=s<pageYOffset,a=pageYOffset+i<s+e.height;r&&(s=pageYOffset+this.defaultMargin),a&&(s=pageYOffset+i-e.height-this.defaultMargin);const l=pageXOffset+t.left+t.width;this.alignWidgetElement(l,s),o.style.top=t.top+Math.floor(t.height/2)-s+"px";const d=n-this.widget.getBoundingClientRect().right;if(d<this.defaultMargin){const t=this.widget.getBoundingClientRect().width+d-this.defaultMargin;this.widget.style.width=`${t}px`}}alignWidgetLeft(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientHeight,window.innerHeight||0),i=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-left");let o=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2);const s=o<pageYOffset,r=pageYOffset+n<o+e.height;s&&(o=pageYOffset+this.defaultMargin),r&&(o=pageYOffset+n-e.height-this.defaultMargin);const a=pageXOffset+t.left-e.width;this.alignWidgetElement(a,o),i.style.top=t.top+Math.floor(t.height/2)-o+"px";const l=this.widget.getBoundingClientRect().left;if(l<0){const t=this.widget.getBoundingClientRect().width+l-this.defaultMargin,e=this.widget.getBoundingClientRect().left-l;this.widget.style.width=`${t}px`,this.widget.style.left=`${e}px`}}alignWidgetBottom(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0),o=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-bottom");let s=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2);const r=s<pageXOffset,a=s+e.width>pageXOffset+n;r&&(s=pageXOffset+this.defaultMargin),a&&(s=pageXOffset+n-e.width-12);const l=pageYOffset+t.top+t.height;this.alignWidgetElement(s,l),o.style.left=t.left+Math.floor(t.width/2)-s+"px";const d=i-this.widget.getBoundingClientRect().bottom;if(d<this.defaultMargin){const t=this.widget.getBoundingClientRect().height+d-this.defaultMargin;this.widget.style.height=`${t}px`}}alignWidgetElement(t,e){this.widget.style.left=`${t}px`,this.widget.style.top=`${e}px`}getDefaultPosition(){const{left:t,top:e,width:n,height:i}=this.trigger.getBoundingClientRect();if(!document.documentElement)return"";const o={right:t,bottom:e,left:Math.max(document.documentElement.clientWidth,window.innerWidth||0)-(t+n),top:Math.max(document.documentElement.clientHeight,window.innerHeight||0)-(e+i)},s=Math.min(t,e,o.left,o.top);let r="bottom";return Object.keys(o).forEach(t=>{o[t]===s&&(r=t)}),r}addListeners(){this.trigger.addEventListener("click",this.onTriggerClickHandler),this.pw.push(["onPutNewMessageToInboxStore",()=>{this.updateInbox()}]),this.pw.push(["onUpdateInboxMessages",()=>{this.updateInbox()}])}markVisibleItemsAsRead(){if(0===this.messages.length)return;const t=this.list.clientHeight+this.list.scrollTop-50;Object.keys(this.messagesElements).forEach(e=>{if(!this.messagesElements[e]||this.messagesElements[e].offsetTop>t)return;const n=this.messages.find(t=>t.code===e);!n||n.isRead||this.readItems.indexOf(e)+1||this.readItems.push(e)})}updateReadStatus(){const t=this.readItems;this.readItems=[],this.pw.pwinbox.readMessagesWithCodes(t).then(this.updateInbox)}syncMessages(){Date.now()-this.lastSyncAt<3e4||(this.lastSyncAt=Date.now(),this.pw.pwinbox.syncMessages().catch(t=>{console.error("Pushwoosh: cannot refresh the inbox on open",t)}))}updateInbox(){this.pw.pwinbox.loadMessages().then(t=>{this.updateInboxMessages(t)}),this.pw.pwinbox.unreadMessagesCount().then(t=>{this.updateCounter(t)})}performMessageAction(t){this.pw.pwinbox.performActionForMessageWithCode(t).then(()=>{this.updateInbox()})}removeMessages(t){this.readItems=this.readItems.filter(e=>-1===t.indexOf(e)),this.pw.pwinbox.deleteMessagesWithCodes(t).then(()=>{this.updateInbox()})}onTriggerClickHandler(t){t.stopPropagation(),t.target&&this.toggle()}onWidgetClickHandler(t){if(!t.target)return;const e=t.target.closest(".pw-inbox_item");if(!e)return void this.toggle();const n=e.getAttribute("data-pw-inbox-message-id");if(!n)return;if(t.target.closest(".pw-inbox_item-remove"))return void this.removeMessages([n]);const i=t.target.closest(".pw-inbox_dot");if(i)return void this.showSlide(n,parseInt(i.getAttribute("data-pw-slide")||"0",10));const o=t.target.closest(".pw-inbox_slide"),s=o&&o.getAttribute("data-pw-slide-link");var r;s&&(r=s)&&!m.test(x(r))?document.location.href=s:this.performMessageAction(n)}showSlide(t,e){this.activeSlides[t]=e;const n=this.messagesElements[t],i=this.messages.find(e=>e.code===t);n&&i&&(n.innerHTML=c(i,e))}onWindowScrollHandler(){this.isFixed&&this.isOpened?this.toggle():this.positionWidget()}}return e})());
2
2
  //# sourceMappingURL=widget-inbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget-inbox.js","mappings":"CAAA,SAAAA,EAAAC,GACA,oBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,SACA,sBAAAG,QAAAA,OAAAC,IACAD,OAAA,GAAAH,OACA,CACA,IAAAK,EAAAL,IACA,QAAAM,KAAAD,GAAA,iBAAAJ,QAAAA,QAAAF,GAAAO,GAAAD,EAAAC,EACA,CACC,CATD,CASCC,KAAA,uBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAP,EAAAQ,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAV,EAAAS,IACAE,OAAAC,eAAAZ,EAAAS,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCF,EAAA,CAAAQ,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAT,EAAAP,IACAW,OAAAC,eAAAZ,EAAAoB,OAAAC,YAAA,CAAsDC,MAAA,WACtDX,OAAAC,eAAAZ,EAAA,cAAgDsB,OAAA,mDCDzC,MAEMC,EAAS,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,OAAQ,OAAQ,MAAO,OAAQ,MAAO,MAAO,OAE1FC,EAAsC,CACjD,CAAEC,KAAM,cAAeC,KAAM,QAC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ications/webpack/universalModuleDefinition","webpack://web-push-notifications/webpack/bootstrap","webpack://web-push-notifications/webpack/runtime/define property getters","webpack://web-push-notifications/webpack/runtime/hasOwnProperty shorthand","webpack://web-push-notifications/webpack/runtime/make namespace object","webpack://web-push-notifications/./src/widgets/Inbox/constants.ts","webpack://web-push-notifications/./src/widgets/Inbox/helpers.ts","webpack://web-push-notifications/./src/widgets/Inbox/widgetTemplates.ts","webpack://web-push-notifications/./src/widgets/Inbox/InboxWidget.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { type IConfigStyles, type IInboxWidgetConfig } from './inbox_widget.types';\n\nexport const MILLISECONDS_IN_DAY = 60 * 60 * 24 * 1000;\nexport const MILLISECONDS_IN_HOUR = 60 * 60 * 1000;\nexport const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];\n\nexport const CONFIG_STYLES: Array<IConfigStyles> = [\n { name: 'widgetWidth', type: 'size' },\n { name: 'borderRadius', type: 'size' },\n { name: 'zIndex', type: 'number' },\n { name: 'fontFamily', type: 'string' },\n { name: 'bgColor', type: 'color' },\n { name: 'textColor', type: 'color' },\n { name: 'arrowBorderColor', type: 'color' },\n { name: 'borderColor', type: 'color' },\n { name: 'badgeBgColor', type: 'color' },\n { name: 'badgeTextColor', type: 'color' },\n { name: 'timeTextColor', type: 'color' },\n { name: 'messageTitleColor', type: 'color' },\n { name: 'emptyInboxTitleColor', type: 'color' },\n { name: 'emptyInboxTextColor', type: 'color' },\n];\n\nexport const DEFAULT_CONFIG: IInboxWidgetConfig = {\n enable: false,\n triggerId: 'pwInbox',\n position: 'bottom',\n appendTo: 'body',\n title: 'Inbox',\n bgColor: '#ffffff',\n textColor: '#333333',\n fontFamily: 'inherit',\n borderRadius: 4,\n borderColor: 'transparent',\n badgeBgColor: '#ff4c00',\n badgeTextColor: '#ffffff',\n widgetWidth: 350,\n zIndex: 100,\n messageTitleColor: '#7a7a7a',\n timeTextColor: '#c4c4c4',\n emptyInboxTitle: 'You\\'re all caught up',\n emptyInboxTitleColor: '#333333',\n emptyInboxText: 'There are no new messages. Stay tuned!',\n emptyInboxTextColor: '#7a7a7a',\n emptyInboxIconUrl: 'https://pushon.pushwoosh.com/static/icon-empty-inbox.png',\n arrowBorderColor: 'rgba(0,0,0,.1)',\n};\n\nexport const COLOR_TEST_REGEXP = /^(#([\\da-f]{3}){1,2}$|(rgb|hsl)a\\((\\d{1,3}%?,\\s?){3}(1|0?\\.\\d+)\\)$|(rgb|hsl)\\(\\d{1,3}%?(,\\s?\\d{1,3}%?){2}\\)$)/;\n","import {\n MILLISECONDS_IN_HOUR,\n MILLISECONDS_IN_DAY,\n MONTHS,\n COLOR_TEST_REGEXP,\n} from './constants';\n\nexport function isElementFixed(element: HTMLElement): boolean {\n let isFixed = window.getComputedStyle(element).position === 'fixed';\n if (!isFixed && element.parentElement) {\n isFixed = isElementFixed(element.parentElement);\n }\n return isFixed;\n}\n\nexport function getMessageTime(date: string): string {\n const localDate = new Date(date);\n const localTime = localDate.getHours() + (localDate.getTimezoneOffset() / 60);\n localDate.setHours(localTime);\n const now = new Date();\n\n const gap = (now.getTime() - localDate.getTime());\n\n if (gap <= 60 * 1000) {\n return `Just now`;\n } else if (gap < MILLISECONDS_IN_HOUR && gap > 0) {\n const minutesAgo = Math.floor(gap / (60 * 1000));\n return `${minutesAgo} minutes ago`;\n } else if (gap < MILLISECONDS_IN_DAY && gap > 0) {\n const hoursAgo = Math.floor(gap / (60 * 60 * 1000));\n return `${hoursAgo} hours ago`;\n }\n\n const day = localDate.getDate();\n const month = MONTHS[localDate.getMonth()];\n const year = localDate.getFullYear();\n const hours = localDate.getHours();\n const minutes = `0${localDate.getMinutes().toString()}`.slice(-2); // padStart(2, 0)\n\n return `${day} ${month} ${year}, ${hours}:${minutes}`;\n}\n\nexport function getValidColor(color: string): string {\n if (color === 'transparent') {\n return color;\n }\n\n return COLOR_TEST_REGEXP.test(color)\n ? color\n : '#333';\n}\n\nexport function compareBySendDate(dateOne: string, dateTwo: string): number {\n const localDateOne = new Date(dateOne);\n const localTimeOne = localDateOne.getHours() + (localDateOne.getTimezoneOffset() / 60);\n const localDateTwo = new Date(dateTwo);\n const localTimeTwo = localDateTwo.getHours() + (localDateTwo.getTimezoneOffset() / 60);\n\n localDateOne.setHours(localTimeOne);\n localDateTwo.setHours(localTimeTwo);\n\n return localDateTwo.getTime() - localDateOne.getTime();\n}\n","import { getMessageTime } from './helpers';\nimport { type IInboxMessagePublic } from '../../models/InboxMessages.types';\n\nexport const widgetTemplate = (title: string): string => `\n<div class=\"pw-inbox__arrow\"></div>\n<div class=\"pw-inbox_inner\">\n <div class=\"pw-inbox_title\">\n ${title}\n </div>\n <ul class=\"pw-inbox_list\">\n\n </ul>\n</div>`;\n\nexport const widgetTemplateEmpty = (\n emptyInboxIconUrl: string,\n emptyInboxTitle: string,\n emptyInboxText: string,\n) => `\n<div class=\"pw-inbox__arrow\"></div>\n<div class=\"pw-inbox_list--empty\">\n <div class=\"pw-inbox_list-icon\">\n <img src=\"${emptyInboxIconUrl}\" alt=\"${emptyInboxTitle}\">\n </div>\n <div class=\"pw-inbox_list-title\">\n ${emptyInboxTitle}\n </div>\n <div class=\"ipw-inbox_list-body\">\n ${emptyInboxText}\n </div>\n</div>`;\n\nexport const messageTemplate = ({\n imageUrl,\n title,\n message,\n sendDate,\n}: IInboxMessagePublic) => `\n<div class=\"pw-inbox_item-inner\">\n <div class=\"pw-inbox_icon\">\n <img src=\"${imageUrl}\" alt=\"${title || message}\" class=\"pw-inbox_message-image\">\n </div>\n <div class=\"pw-inbox_content\">\n ${title ? `<div class=\"pw-inbox_item-title\">\n ${title}\n </div>` : null}\n <div class=\"pw-inbox_item-body\">\n ${message}\n </div>\n <div class=\"pw-inbox_item-time\">\n ${getMessageTime(sendDate)}\n </div>\n </div>\n</div>\n<span class=\"pw-inbox_item-remove\"></span>`;\n","import {\n CONFIG_STYLES,\n DEFAULT_CONFIG,\n} from './constants';\nimport inboxWidgetStyleCss from './css/inboxWidgetStyle.css';\nimport {\n getValidColor,\n isElementFixed,\n compareBySendDate,\n} from './helpers';\nimport { type IConfigStyles, type IInboxWidgetConfig, type TMessagesElementsType } from './inbox_widget.types';\nimport {\n messageTemplate,\n widgetTemplate,\n widgetTemplateEmpty,\n} from './widgetTemplates';\nimport { type Pushwoosh } from '../../core/Pushwoosh';\nimport { type IInboxMessagePublic } from '../../models/InboxMessages.types';\n\nexport class PWInboxWidget {\n pw: Pushwoosh;\n widget: HTMLElement;\n trigger: HTMLElement;\n list: HTMLElement;\n widgetParent: HTMLElement;\n count: number;\n messages: Array<IInboxMessagePublic>;\n messagesElements: TMessagesElementsType;\n readItems: Array<string>;\n isOpened: boolean;\n config: IInboxWidgetConfig;\n defaultMargin: number;\n isFixed: boolean;\n\n constructor(pw: Pushwoosh) {\n // Set Pushwoosh object\n this.pw = pw;\n\n const inboxWidgetConfig = this.pw.initParams.inboxWidget!;\n\n this.config = {\n ...DEFAULT_CONFIG,\n arrowBorderColor: inboxWidgetConfig.borderColor && inboxWidgetConfig.borderColor !== 'transparent'\n ? inboxWidgetConfig.borderColor\n : 'rgba(0,0,0,.1)',\n ...this.pw.initParams.inboxWidget,\n };\n\n this.updateInbox = this.updateInbox.bind(this);\n this.markVisibleItemsAsRead = this.markVisibleItemsAsRead.bind(this);\n this.onWidgetClickHandler = this.onWidgetClickHandler.bind(this);\n this.onTriggerClickHandler = this.onTriggerClickHandler.bind(this);\n this.onWindowScrollHandler = this.onWindowScrollHandler.bind(this);\n this.toggle = this.toggle.bind(this);\n }\n\n public async run() {\n this.initTrigger();\n this.updateInbox();\n this.addListeners();\n }\n\n public toggle(isOpened?: boolean) {\n const openWidget = typeof isOpened === 'undefined'\n ? !this.isOpened\n : isOpened;\n\n if (openWidget) {\n this.openWidget();\n } else {\n this.closeWidget();\n }\n }\n\n // set inbox widget to trigger element on page\n private initTrigger() {\n if (!this.pw.pwinbox) {\n throw new Error('Web inbox is not allowed.');\n }\n\n const trigger = document.getElementById(this.config.triggerId);\n\n if (!trigger) {\n throw new Error('Inbox trigger element doesn\\'t exist. You must set triggerId in inboxWidget config. See the documentation.');\n }\n\n this.trigger = trigger;\n this.trigger.classList.add('pw-inbox-trigger');\n\n this.defaultMargin = 12;\n this.messagesElements = {};\n this.messages = [];\n this.readItems = [];\n this.updateCounter(0);\n this.isOpened = false;\n\n this.renderWidget();\n\n this.isFixed = isElementFixed(this.trigger);\n }\n\n private renderWidget() {\n this.widget = document.createElement('div');\n this.widget.id = 'pwInboxWidget';\n this.widget.className = 'pw-inbox-widget';\n this.widget.classList.toggle('pw-open', this.isOpened);\n\n this.widgetParent = document.querySelector(this.config.appendTo) || document.body;\n\n this.widgetParent.appendChild(this.widget);\n this.widgetParent.appendChild(this.getStyle());\n this.renderWidgetInner();\n }\n\n private getStyle(): HTMLStyleElement {\n const styleNode = document.createElement('style');\n styleNode.innerHTML = this.configureStyle(inboxWidgetStyleCss);\n return styleNode;\n }\n\n private configureStyle(styles: string): string {\n let resultStyles = styles.toString();\n CONFIG_STYLES.forEach((style: IConfigStyles) => {\n const template = new RegExp(`var\\\\(--${style.name}\\\\)`, 'ig');\n const result = this.getStyleFormatter(style);\n\n resultStyles = resultStyles.replace(template, result);\n });\n return resultStyles;\n }\n\n private getStyleFormatter(style: IConfigStyles): string {\n switch (style.type) {\n case 'size':\n return `${this.config[style.name] || 0}px`;\n case 'number':\n return parseFloat(this.config[style.name].toString()).toString();\n case 'string':\n return this.config[style.name].toString();\n case 'color':\n return getValidColor(this.config[style.name].toString());\n default:\n return 'none';\n }\n }\n\n private renderWidgetInner() {\n if (this.messages.length > 0) {\n this.widget.classList.remove('pw-inbox-widget--empty');\n this.widget.innerHTML = widgetTemplate(this.config.title);\n this.renderMessages();\n } else {\n this.widget.classList.add('pw-inbox-widget--empty');\n const {\n emptyInboxTitle,\n emptyInboxText,\n emptyInboxIconUrl,\n } = this.config;\n this.widget.innerHTML = widgetTemplateEmpty(emptyInboxIconUrl, emptyInboxTitle, emptyInboxText);\n }\n }\n\n private renderMessages() {\n this.list = this.widget.querySelector('.pw-inbox_list') || document.createElement('ul');\n this.messages.forEach((message: IInboxMessagePublic) => {\n const messageElement = document.createElement('li');\n messageElement.className = 'pw-inbox_item';\n messageElement.classList.toggle('pw-new', !message.isRead);\n messageElement.classList.toggle('pw-unread', !message.isActionPerformed);\n messageElement.setAttribute('data-pw-inbox-message-id', message.code);\n messageElement.innerHTML = messageTemplate(message);\n\n this.list.appendChild(messageElement);\n this.messagesElements[message.code] = messageElement;\n });\n }\n\n private updateCounter(count: number) {\n this.count = count;\n this.trigger.setAttribute('data-pw-count', `${this.count}`);\n this.trigger.classList.toggle('pw-empty', this.count === 0);\n }\n\n private updateInboxMessages(messages: Array<IInboxMessagePublic>) {\n this.messages = messages.sort(({ sendDate: sendDateOne }, { sendDate: sendDateTwo }) => compareBySendDate(sendDateOne, sendDateTwo));\n this.renderWidgetInner();\n }\n\n openWidget() {\n this.isOpened = true;\n this.widget.classList.add('pw-open');\n document.addEventListener('click', this.onWidgetClickHandler);\n window.addEventListener('scroll', this.onWindowScrollHandler);\n window.addEventListener('resize', this.onWindowScrollHandler);\n this.markVisibleItemsAsRead();\n if (this.messages.length > 0) {\n this.list.addEventListener('scroll', this.markVisibleItemsAsRead);\n }\n this.positionWidget();\n }\n\n closeWidget() {\n this.isOpened = false;\n document.removeEventListener('click', this.onWidgetClickHandler);\n document.removeEventListener('click', this.onWindowScrollHandler);\n window.removeEventListener('resize', this.onWindowScrollHandler);\n this.updateReadStatus();\n if (this.messages.length > 0) {\n this.list.removeEventListener('scroll', this.markVisibleItemsAsRead);\n }\n this.widget.classList.remove('pw-open', 'pw-top', 'pw-bottom', 'pw-right', 'pw-left');\n this.widget.removeAttribute('style');\n }\n\n private positionWidget() {\n if (!this.isOpened) {\n return;\n }\n if (this.widgetParent === document.body) {\n this.defaultPlaceWidget();\n } else {\n this.customPlaceWidget();\n }\n }\n\n private customPlaceWidget() {\n const { position } = this.config;\n this.widgetParent.style.position = 'relative';\n this.widget.classList.add('pw-inbox-widget--inset');\n this.widget.classList.add(`pw-${position}`);\n }\n\n private defaultPlaceWidget() {\n const position = this.pw.initParams.inboxWidget!.position ? this.config.position : this.getDefaultPosition();\n\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n\n if (widgetRect.width + (this.defaultMargin * 2) > windowWidth) {\n this.widget.style.width = `${windowWidth - (this.defaultMargin * 2)}px`;\n }\n if (widgetRect.height + 24 > windowHeight) {\n this.widget.style.height = `${windowHeight - (this.defaultMargin * 2)}px`;\n }\n\n switch (position) {\n case 'top': {\n this.alignWidgetTop();\n break;\n }\n case 'right': {\n this.alignWidgetRight();\n break;\n }\n case 'left': {\n this.alignWidgetLeft();\n break;\n }\n case 'bottom': {\n this.alignWidgetBottom();\n break;\n }\n }\n }\n\n private alignWidgetTop() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-top');\n\n let left = pageXOffset + triggerRect.left + Math.floor(triggerRect.width / 2) - Math.floor(widgetRect.width / 2);\n\n const isUnderLeft = left < pageXOffset;\n const isUnderRight = left + widgetRect.width > pageXOffset + windowWidth;\n\n if (isUnderLeft) {\n left = pageXOffset + this.defaultMargin;\n }\n if (isUnderRight) {\n left = pageXOffset + windowWidth - widgetRect.width - this.defaultMargin;\n }\n\n const top = pageYOffset + triggerRect.top - widgetRect.height;\n\n this.alignWidgetElement(left, top);\n arrow.style.left = `${triggerRect.left + Math.floor(triggerRect.width / 2) - left}px`;\n\n const topMargin = this.widget.getBoundingClientRect().top;\n const isUnderTop = topMargin < 0;\n if (isUnderTop) {\n const newHeight = this.widget.getBoundingClientRect().height + topMargin - this.defaultMargin;\n const newTop = this.widget.getBoundingClientRect().top - topMargin + this.defaultMargin;\n this.widget.style.height = `${newHeight}px`;\n this.widget.style.top = `${newTop}px`;\n }\n }\n\n private alignWidgetRight() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-right');\n\n let top = pageYOffset + triggerRect.top + Math.floor(triggerRect.height / 2) - Math.floor(widgetRect.height / 2);\n\n const isUnderTop = top < pageYOffset;\n const isUnderBottom = pageYOffset + windowHeight < top + widgetRect.height;\n\n if (isUnderTop) {\n top = pageYOffset + this.defaultMargin;\n }\n\n if (isUnderBottom) {\n top = pageYOffset + windowHeight - widgetRect.height - this.defaultMargin;\n }\n\n const left = pageXOffset + triggerRect.left + triggerRect.width;\n\n this.alignWidgetElement(left, top);\n arrow.style.top = `${triggerRect.top + Math.floor(triggerRect.height / 2) - top}px`;\n\n const rightMargin = windowWidth - this.widget.getBoundingClientRect().right;\n const isUnderRight = rightMargin < this.defaultMargin;\n if (isUnderRight) {\n const newWidth = this.widget.getBoundingClientRect().width + rightMargin - this.defaultMargin;\n this.widget.style.width = `${newWidth}px`;\n }\n }\n\n private alignWidgetLeft() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-left');\n\n let top = pageYOffset + triggerRect.top + Math.floor(triggerRect.height / 2) - Math.floor(widgetRect.height / 2);\n\n const isUnderTop = top < pageYOffset;\n const isUnderBottom = pageYOffset + windowHeight < top + widgetRect.height;\n\n if (isUnderTop) {\n top = pageYOffset + this.defaultMargin;\n }\n\n if (isUnderBottom) {\n top = pageYOffset + windowHeight - widgetRect.height - this.defaultMargin;\n }\n\n const left = pageXOffset + triggerRect.left - widgetRect.width;\n\n this.alignWidgetElement(left, top);\n arrow.style.top = `${triggerRect.top + Math.floor(triggerRect.height / 2) - top}px`;\n\n const leftMargin = this.widget.getBoundingClientRect().left;\n const isUnderLeft = leftMargin < 0;\n if (isUnderLeft) {\n const newWidth = this.widget.getBoundingClientRect().width + leftMargin - this.defaultMargin;\n const newLeft = this.widget.getBoundingClientRect().left - leftMargin;\n this.widget.style.width = `${newWidth}px`;\n this.widget.style.left = `${newLeft}px`;\n }\n }\n\n private alignWidgetBottom() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-bottom');\n\n let left = pageXOffset + triggerRect.left + Math.floor(triggerRect.width / 2) - Math.floor(widgetRect.width / 2);\n\n const isUnderLeft = left < pageXOffset;\n const isUnderRight = left + widgetRect.width > pageXOffset + windowWidth;\n\n if (isUnderLeft) {\n left = pageXOffset + this.defaultMargin;\n }\n if (isUnderRight) {\n left = pageXOffset + windowWidth - widgetRect.width - 12;\n }\n\n const top = pageYOffset + triggerRect.top + triggerRect.height;\n\n this.alignWidgetElement(left, top);\n arrow.style.left = `${triggerRect.left + Math.floor(triggerRect.width / 2) - left}px`;\n\n const bottomRange = windowHeight - this.widget.getBoundingClientRect().bottom;\n const isUnderBottom = bottomRange < this.defaultMargin;\n if (isUnderBottom) {\n const newHeight = this.widget.getBoundingClientRect().height + bottomRange - this.defaultMargin;\n this.widget.style.height = `${newHeight}px`;\n }\n }\n\n private alignWidgetElement(left: number, top: number) {\n this.widget.style.left = `${left}px`;\n this.widget.style.top = `${top}px`;\n }\n\n private getDefaultPosition(): string {\n const { left, top, width, height } = this.trigger.getBoundingClientRect();\n if (!document.documentElement) {\n return '';\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n\n const antiMargins: { [key: string]: number } = {\n right: left,\n bottom: top,\n left: windowWidth - (left + width),\n top: windowHeight - (top + height),\n };\n\n const leastMargin = Math.min(left, top, antiMargins.left, antiMargins.top);\n\n let position = 'bottom';\n\n Object.keys(antiMargins).forEach((key) => {\n if (antiMargins[key] === leastMargin) {\n position = key;\n }\n });\n\n return position;\n }\n\n private addListeners() {\n this.trigger.addEventListener('click', this.onTriggerClickHandler);\n\n this.pw.push(['onPutNewMessageToInboxStore', () => {\n this.updateInbox();\n }]);\n this.pw.push(['onUpdateInboxMessages', () => {\n this.updateInbox();\n }]);\n }\n\n private markVisibleItemsAsRead() {\n if (this.messages.length === 0) {\n return;\n }\n const scrollTop = (this.list.clientHeight + this.list.scrollTop) - 50;\n Object.keys(this.messagesElements).forEach((code: string) => {\n // check message exists and user saw the message in viewport\n if (!this.messagesElements[code] || this.messagesElements[code].offsetTop > scrollTop) {\n return;\n }\n\n const message = this.messages.find((message: IInboxMessagePublic): boolean => message.code === code);\n\n // mark messages as read\n if (!!message && !message.isRead && !(this.readItems.indexOf(code) + 1)) {\n this.readItems.push(code);\n }\n });\n }\n\n private updateReadStatus() {\n this.pw.pwinbox.readMessagesWithCodes(this.readItems).then(this.updateInbox);\n }\n\n private updateInbox() {\n this.pw.pwinbox.loadMessages().then((messages: Array<IInboxMessagePublic>) => {\n this.updateInboxMessages(messages);\n });\n this.pw.pwinbox.unreadMessagesCount().then((count: number) => {\n this.updateCounter(count);\n });\n }\n\n private performMessageAction(code: string) {\n this.pw.pwinbox.performActionForMessageWithCode(code)\n .then(() => {\n this.updateInbox();\n });\n }\n\n private removeMessages(messages: Array<string>) {\n messages.forEach((code: string) => {\n this.readItems = this.readItems.slice(this.readItems.indexOf(code), 1);\n });\n this.pw.pwinbox.deleteMessagesWithCodes(messages)\n .then(() => {\n this.updateInbox();\n });\n }\n\n // handlers\n\n private onTriggerClickHandler(event: MouseEvent) {\n event.stopPropagation();\n if (!event.target) {\n return;\n }\n\n this.toggle();\n }\n\n private onWidgetClickHandler(event: MouseEvent) {\n if (!event.target) {\n return;\n }\n\n const itemElement = (<HTMLElement>event.target).closest('.pw-inbox_item');\n\n if (!itemElement) {\n this.toggle();\n return;\n }\n\n const messageCode = itemElement.getAttribute('data-pw-inbox-message-id');\n\n if (!messageCode) {\n return;\n }\n\n const removeIconClick = (<HTMLElement>event.target).closest('.pw-inbox_item-remove');\n\n if (removeIconClick) {\n this.removeMessages([messageCode]);\n return;\n }\n\n this.performMessageAction(messageCode);\n }\n\n private onWindowScrollHandler() {\n if (this.isFixed && this.isOpened) {\n this.toggle();\n return;\n }\n this.positionWidget();\n }\n}\n"],"names":["root","factory","exports","module","define","amd","a","i","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MONTHS","CONFIG_STYLES","name","type","DEFAULT_CONFIG","enable","triggerId","position","appendTo","title","bgColor","textColor","fontFamily","borderRadius","borderColor","badgeBgColor","badgeTextColor","widgetWidth","zIndex","messageTitleColor","timeTextColor","emptyInboxTitle","emptyInboxTitleColor","emptyInboxText","emptyInboxTextColor","emptyInboxIconUrl","arrowBorderColor","COLOR_TEST_REGEXP","isElementFixed","element","isFixed","window","getComputedStyle","parentElement","messageTemplate","imageUrl","message","sendDate","date","localDate","Date","localTime","getHours","getTimezoneOffset","setHours","gap","getTime","Math","floor","getDate","getMonth","getFullYear","getMinutes","toString","slice","getMessageTime","PWInboxWidget","constructor","pw","inboxWidgetConfig","initParams","inboxWidget","config","updateInbox","bind","markVisibleItemsAsRead","onWidgetClickHandler","onTriggerClickHandler","onWindowScrollHandler","toggle","run","initTrigger","addListeners","isOpened","openWidget","closeWidget","pwinbox","Error","trigger","document","getElementById","classList","add","defaultMargin","messagesElements","messages","readItems","updateCounter","renderWidget","widget","createElement","id","className","widgetParent","querySelector","body","appendChild","getStyle","renderWidgetInner","styleNode","innerHTML","configureStyle","styles","resultStyles","forEach","style","template","RegExp","result","getStyleFormatter","replace","parseFloat","color","test","length","remove","renderMessages","widgetTemplateEmpty","list","messageElement","isRead","isActionPerformed","setAttribute","code","count","updateInboxMessages","sort","sendDateOne","sendDateTwo","dateOne","dateTwo","localDateOne","localTimeOne","localDateTwo","localTimeTwo","compareBySendDate","addEventListener","positionWidget","removeEventListener","updateReadStatus","removeAttribute","defaultPlaceWidget","customPlaceWidget","getDefaultPosition","widgetRect","getBoundingClientRect","documentElement","windowWidth","max","clientWidth","innerWidth","windowHeight","clientHeight","innerHeight","width","height","alignWidgetTop","alignWidgetRight","alignWidgetLeft","alignWidgetBottom","triggerRect","arrow","left","pageXOffset","isUnderLeft","isUnderRight","top","pageYOffset","alignWidgetElement","topMargin","newHeight","newTop","isUnderTop","isUnderBottom","rightMargin","right","newWidth","leftMargin","newLeft","bottomRange","bottom","antiMargins","leastMargin","min","keys","push","scrollTop","offsetTop","find","indexOf","readMessagesWithCodes","then","loadMessages","unreadMessagesCount","performMessageAction","performActionForMessageWithCode","removeMessages","deleteMessagesWithCodes","event","stopPropagation","target","itemElement","closest","messageCode","getAttribute"],"sourceRoot":""}
1
+ {"version":3,"file":"widget-inbox.js","mappings":"CAAA,SAAAA,EAAAC,GACA,oBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,SACA,sBAAAG,QAAAA,OAAAC,IACAD,OAAA,GAAAH,OACA,CACA,IAAAK,EAAAL,IACA,QAAAM,KAAAD,GAAA,iBAAAJ,QAAAA,QAAAF,GAAAO,GAAAD,EAAAC,EACA,CACC,CATD,CASCC,KAAA,uBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAP,EAAAQ,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAV,EAAAS,IACAE,OAAAC,eAAAZ,EAAAS,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCF,EAAA,CAAAQ,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAT,EAAAP,IACAW,OAAAC,eAAAZ,EAAAoB,OAAAC,YAAA,CAAsDC,MAAA,WACtDX,OAAAC,eAAAZ,EAAA,cAAgDsB,OAAA,mDCAzC,MAIMC,EAAS,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,OAAQ,OAAQ,MAAO,OAAQ,MAAO,MAAO,OAE1FC,EAAsC,CACjD,CAAEC,KAAM,cAAeC,KAAM,QAC7B,CAAED,KAAM,eAAgBC,KAAM,QAC9B,CAAED,KAAM,SAAUC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J,aAAa,sBD3kBzD,IAAmBtL,EC6kBlB2L,ID7kBkB3L,EC6kBK2L,KD5kBZ3J,EAAcvD,KAAKwD,EAAUjC,IC6kB1C8D,SAAS8H,SAASC,KAAOF,EAI3BrR,KAAKsQ,qBAAqBS,EAC5B,CAGQ,SAAAG,CAAUlF,EAAcrF,GAC9B3G,KAAK+J,aAAaiC,GAAQrF,EAE1B,MAAMkF,EAAiB7L,KAAK8J,iBAAiBkC,GACvCzH,EAAUvE,KAAKgK,SAAS4F,KAAM4B,GAAuCA,EAAKxF,OAASA,GAErFH,GAAkBtH,IACpBsH,EAAef,UAAYlF,EAAgBrB,EAASoC,GAExD,CAEQ,qBAAAkC,GACF7I,KAAKwD,SAAWxD,KAAKkJ,SACvBlJ,KAAK8I,SAGP9I,KAAK0M,gBACP","sources":["webpack://web-push-notifications/webpack/universalModuleDefinition","webpack://web-push-notifications/webpack/bootstrap","webpack://web-push-notifications/webpack/runtime/define property getters","webpack://web-push-notifications/webpack/runtime/hasOwnProperty shorthand","webpack://web-push-notifications/webpack/runtime/make namespace object","webpack://web-push-notifications/./src/widgets/Inbox/constants.ts","webpack://web-push-notifications/./src/widgets/Inbox/helpers.ts","webpack://web-push-notifications/./src/helpers/escape.ts","webpack://web-push-notifications/./src/widgets/Inbox/widgetTemplates.ts","webpack://web-push-notifications/./src/models/InboxCell.ts","webpack://web-push-notifications/./src/helpers/cssColor.ts","webpack://web-push-notifications/./src/helpers/url.ts","webpack://web-push-notifications/./src/widgets/Inbox/InboxWidget.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { type IConfigStyles, type IInboxWidgetConfig } from './inbox_widget.types';\n\n/** Shortest gap between two server refreshes triggered by opening the widget. */\nexport const SYNC_INTERVAL = 30 * 1000;\n\nexport const MILLISECONDS_IN_DAY = 60 * 60 * 24 * 1000;\nexport const MILLISECONDS_IN_HOUR = 60 * 60 * 1000;\nexport const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];\n\nexport const CONFIG_STYLES: Array<IConfigStyles> = [\n { name: 'widgetWidth', type: 'size' },\n { name: 'borderRadius', type: 'size' },\n { name: 'zIndex', type: 'number' },\n { name: 'fontFamily', type: 'string' },\n { name: 'bgColor', type: 'color' },\n { name: 'textColor', type: 'color' },\n { name: 'arrowBorderColor', type: 'color' },\n { name: 'borderColor', type: 'color' },\n { name: 'badgeBgColor', type: 'color' },\n { name: 'badgeTextColor', type: 'color' },\n { name: 'timeTextColor', type: 'color' },\n { name: 'messageTitleColor', type: 'color' },\n { name: 'emptyInboxTitleColor', type: 'color' },\n { name: 'emptyInboxTextColor', type: 'color' },\n { name: 'unreadDotColor', type: 'color' },\n { name: 'avatarBgColor', type: 'color' },\n { name: 'avatarTextColor', type: 'color' },\n { name: 'avatarSize', type: 'size' },\n { name: 'mediaRadius', type: 'size' },\n { name: 'slideCaptionColor', type: 'color' },\n { name: 'slideScrimColor', type: 'color' },\n { name: 'pagerDotActiveColor', type: 'color' },\n { name: 'pagerDotColor', type: 'color' },\n];\n\nexport const DEFAULT_CONFIG: IInboxWidgetConfig = {\n enable: false,\n triggerId: 'pwInbox',\n position: 'bottom',\n appendTo: 'body',\n title: 'Inbox',\n bgColor: '#ffffff',\n textColor: '#333333',\n fontFamily: 'inherit',\n borderRadius: 4,\n borderColor: 'transparent',\n badgeBgColor: '#ff4c00',\n badgeTextColor: '#ffffff',\n widgetWidth: 350,\n zIndex: 100,\n messageTitleColor: '#7a7a7a',\n timeTextColor: '#c4c4c4',\n emptyInboxTitle: 'You\\'re all caught up',\n emptyInboxTitleColor: '#333333',\n emptyInboxText: 'There are no new messages. Stay tuned!',\n emptyInboxTextColor: '#7a7a7a',\n emptyInboxIconUrl: 'https://pushon.pushwoosh.com/static/icon-empty-inbox.png',\n arrowBorderColor: 'rgba(0,0,0,.1)',\n legacyClassicCell: false,\n\n // Defaults mirror the control panel preview (dumb-components `InboxPreview`),\n // so a cell looks here the way the campaign editor promised it would.\n unreadDotColor: '#00a2ff', // Color.BRIGHT\n avatarBgColor: '#c4c8cc', // Color.PHANTOM\n avatarTextColor: '#4b5057', // Color.MAIN\n avatarSize: 52,\n mediaRadius: 8, // ShapeRadius.SECTION\n slideCaptionColor: '#ffffff', // Color.CLEAR\n slideScrimColor: 'rgba(0,0,0,.45)',\n pagerDotActiveColor: '#00a2ff', // Color.BRIGHT\n pagerDotColor: '#ebf0f5', // Color.DIVIDER\n};\n","import {\n MILLISECONDS_IN_HOUR,\n MILLISECONDS_IN_DAY,\n MONTHS,\n} from './constants';\n\nexport function isElementFixed(element: HTMLElement): boolean {\n let isFixed = window.getComputedStyle(element).position === 'fixed';\n if (!isFixed && element.parentElement) {\n isFixed = isElementFixed(element.parentElement);\n }\n return isFixed;\n}\n\n// `sendDate` is a real UTC instant now, so the shift that used to undo an\n// equal one in `publicMessageBuilder` is gone.\nexport function getMessageTime(date: string): string {\n const localDate = new Date(date);\n const now = new Date();\n\n const gap = (now.getTime() - localDate.getTime());\n\n if (gap <= 60 * 1000) {\n return `Just now`;\n } else if (gap < MILLISECONDS_IN_HOUR && gap > 0) {\n const minutesAgo = Math.floor(gap / (60 * 1000));\n return `${minutesAgo} minutes ago`;\n } else if (gap < MILLISECONDS_IN_DAY && gap > 0) {\n const hoursAgo = Math.floor(gap / (60 * 60 * 1000));\n return `${hoursAgo} hours ago`;\n }\n\n const day = localDate.getDate();\n const month = MONTHS[localDate.getMonth()];\n const year = localDate.getFullYear();\n const hours = localDate.getHours();\n const minutes = `0${localDate.getMinutes().toString()}`.slice(-2); // padStart(2, 0)\n\n return `${day} ${month} ${year}, ${hours}:${minutes}`;\n}\n\n// Newest first. The timezone shift the two dates used to go through cancelled\n// out for a comparison anyway, and is gone with the one in `getMessageTime`.\nexport function compareBySendDate(dateOne: string, dateTwo: string): number {\n return new Date(dateTwo).getTime() - new Date(dateOne).getTime();\n}\n","/** Used to map characters to HTML entities. */\nconst htmlEscapes: { [key: string]: string } = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n '\\'': '&#39;',\n};\n\n/** Used to match HTML characters and HTML entities. */\nconst reUnescapedHtml = /[&<>\"']/g;\nconst reHasUnescapedHtml = RegExp(reUnescapedHtml.source);\n\n/** Converts `&`, `<`, `>`, `\"` and `'` to HTML entities. The inverse of `unescape`. */\nexport function escape(string: string): string {\n return (string && reHasUnescapedHtml.test(string))\n ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr])\n : string;\n}\n","import { getMessageTime } from './helpers';\nimport { escape } from '../../helpers/escape';\nimport { getIconInitial } from '../../models/InboxCell';\nimport { type IInboxMessageSlide } from '../../models/InboxCell.types';\nimport { type IInboxMessagePublic } from '../../models/InboxMessages.types';\n\nexport const widgetTemplate = (title: string): string => `\n<div class=\"pw-inbox__arrow\"></div>\n<div class=\"pw-inbox_inner\">\n <div class=\"pw-inbox_title\">\n ${title}\n </div>\n <ul class=\"pw-inbox_list\">\n\n </ul>\n</div>`;\n\nexport const widgetTemplateEmpty = (\n emptyInboxIconUrl: string,\n emptyInboxTitle: string,\n emptyInboxText: string,\n) => `\n<div class=\"pw-inbox__arrow\"></div>\n<div class=\"pw-inbox_list--empty\">\n <div class=\"pw-inbox_list-icon\">\n <img src=\"${emptyInboxIconUrl}\" alt=\"${emptyInboxTitle}\">\n </div>\n <div class=\"pw-inbox_list-title\">\n ${emptyInboxTitle}\n </div>\n <div class=\"ipw-inbox_list-body\">\n ${emptyInboxText}\n </div>\n</div>`;\n\n// Campaign content, unlike the config-driven templates above: every value is\n// escaped because it reaches the page from the control panel.\n\n/** Small round avatar, or the colored initial drawn when the campaign sent no icon. */\nconst avatarTemplate = ({ iconUrl, title, message }: IInboxMessagePublic): string => (\n iconUrl\n ? `<img src=\"${escape(iconUrl)}\" alt=\"${escape(title || message)}\" class=\"pw-inbox_message-image\">`\n : `<span class=\"pw-inbox_icon-initial\">${escape(getIconInitial(title, message))}</span>`\n);\n\n/** Title, body and date. Shared by every layout that draws text at all. */\nconst textsTemplate = ({ title, message, sendDate, isRead }: IInboxMessagePublic): string => `\n<div class=\"pw-inbox_content\">\n <div class=\"pw-inbox_item-title\">\n ${escape(title)}${isRead ? '' : '<span class=\"pw-inbox_unread-dot\"></span>'}\n </div>\n <div class=\"pw-inbox_item-body\">\n ${escape(message)}\n </div>\n <div class=\"pw-inbox_item-time\">\n ${escape(getMessageTime(sendDate))}\n </div>\n</div>`;\n\nconst heroTemplate = (url: string, alt: string): string => `\n<div class=\"pw-inbox_media\">\n <img src=\"${escape(url)}\" alt=\"${escape(alt)}\" class=\"pw-inbox_hero\">\n</div>`;\n\nconst carouselTemplate = (slides: Array<IInboxMessageSlide>, activeIndex: number, alt: string): string => {\n const slide = slides[activeIndex];\n const caption = slide.caption\n ? `<span class=\"pw-inbox_slide-caption\">${escape(slide.caption)}</span>`\n : '';\n\n // One slide is in the DOM at a time: the widget replaces its own innerHTML on\n // every refresh, so there is no state to keep in the markup either way.\n const dots = slides.length > 1\n ? `<div class=\"pw-inbox_pager\">${slides\n .map((_slide, index) => `<button type=\"button\" class=\"pw-inbox_dot${index === activeIndex ? ' pw-active' : ''}\" data-pw-slide=\"${index}\"></button>`)\n .join('')}</div>`\n : '';\n\n return `\n<div class=\"pw-inbox_media\">\n <div class=\"pw-inbox_slide\" data-pw-slide-link=\"${escape(slide.link)}\">\n <img src=\"${escape(slide.imageUrl)}\" alt=\"${escape(slide.caption || alt)}\" class=\"pw-inbox_hero\">\n ${caption}\n </div>\n ${dots}\n</div>`;\n};\n\nexport const messageTemplate = (message: IInboxMessagePublic, activeSlide: number = 0): string => {\n const { layout, heroUrl, carousel, title, message: body } = message;\n const alt = title || body;\n\n let inner: string;\n\n switch (layout) {\n case 'banner':\n // Banner is the hero alone: the control panel sends it with no title or\n // body on purpose, and drawing an empty text block looks like a bug.\n inner = heroTemplate(heroUrl, alt);\n break;\n case 'captioned':\n inner = `${heroTemplate(heroUrl, alt)}${textsTemplate(message)}`;\n break;\n case 'carousel':\n inner = `${carouselTemplate(carousel, Math.min(activeSlide, carousel.length - 1), alt)}${textsTemplate(message)}`;\n break;\n default:\n inner = `<div class=\"pw-inbox_icon\">${avatarTemplate(message)}</div>${textsTemplate(message)}`;\n }\n\n return `\n<div class=\"pw-inbox_item-inner pw-inbox_item--${escape(layout)}\">\n ${inner}\n</div>\n<span class=\"pw-inbox_item-remove\"></span>`;\n};\n","import {\n type IInboxMessageSlide,\n type IInboxSlideRaw,\n type IInboxUserData,\n type TInboxLayout,\n} from './InboxCell.types';\nimport { type IInboxMessageActionParams } from './InboxMessages.types';\nimport { isSafeAbsoluteUrl } from '../helpers/url';\n\n// Cap of the sending pipeline (`maxInboxCarouselSlides`) and of the editor.\n// The rpc-v2 proto comment promising ten is wrong.\nexport const MAX_CAROUSEL_SLIDES = 5;\n\n/** Layouts we can draw; anything else falls back to the heuristic. */\nexport const KNOWN_LAYOUTS: ReadonlyArray<TInboxLayout> = ['classic', 'captioned', 'banner', 'carousel'];\n\n// An object from `getInboxMessages`, a JSON string on the push path; both\n// forms are accepted, as in the iOS SDK.\nexport function parseUserData(actionParams: IInboxMessageActionParams): IInboxUserData {\n const userData = actionParams?.u;\n\n if (!userData) {\n return {};\n }\n\n if (typeof userData === 'string') {\n try {\n return JSON.parse(userData) || {};\n } catch {\n return {};\n }\n }\n\n return typeof userData === 'object' ? <IInboxUserData>userData : {};\n}\n\n/** Slides we can draw: the ones with an image, at most {@link MAX_CAROUSEL_SLIDES}. */\nexport function getValidSlides(userData: IInboxUserData): Array<IInboxMessageSlide> {\n const slides: Array<IInboxSlideRaw> = Array.isArray(userData.carousel) ? userData.carousel : [];\n\n return slides\n .filter((slide) => !!slide && !!slide.image)\n .slice(0, MAX_CAROUSEL_SLIDES)\n .map((slide) => ({\n imageUrl: <string>slide.image,\n caption: slide.title || '',\n // Needs a scheme, as in the iOS SDK, and a scheme that is not script:\n // the widget assigns this straight to `location.href` on a tap.\n link: slide.url && isSafeAbsoluteUrl(slide.url) ? slide.url : '',\n }));\n}\n\n// Hero of the banner and captioned layouts. `b` is the campaign's `bannerUrl`\n// and the only hero source for web; the avatar stands in when none was sent.\nexport function getHeroUrl(\n actionParams: IInboxMessageActionParams,\n userData: IInboxUserData,\n messageImage: string,\n): string {\n return actionParams?.b || messageImage || userData.image || '';\n}\n\n/** Small round avatar of a cell: the message image, or the one inside `u`. */\nexport function getIconUrl(userData: IInboxUserData, messageImage: string): string {\n return messageImage || userData.image || '';\n}\n\n// Ported from `resolveInboxLayout` in dumb-components, so a cell draws here as\n// the control panel preview promised. Unrenderable layouts degrade to classic.\nexport function resolveInboxLayout(options: {\n displayType?: string;\n hasTitle: boolean;\n hasBody: boolean;\n /** Hero available to draw, avatar fallback included. Decides degradation. */\n heroUrl: string;\n /** The campaign's own banner, `action_params.b`. Only this may trigger the heuristic. */\n bannerUrl: string;\n slidesCount: number;\n}): TInboxLayout {\n const { hasTitle, hasBody, heroUrl, bannerUrl, slidesCount } = options;\n\n let requested = <TInboxLayout>options.displayType;\n\n if (KNOWN_LAYOUTS.indexOf(requested) === -1) {\n // Narrower than dumb-components on purpose: an icon must not count as a\n // hero here, or every legacy message would flip to captioned.\n if (bannerUrl && !hasTitle) {\n requested = 'banner';\n } else if (bannerUrl && hasTitle && hasBody) {\n requested = 'captioned';\n } else {\n requested = 'classic';\n }\n }\n\n switch (requested) {\n case 'banner':\n return heroUrl ? 'banner' : 'classic';\n case 'captioned':\n return heroUrl && hasTitle && hasBody ? 'captioned' : 'classic';\n case 'carousel':\n return hasTitle && hasBody && slidesCount > 0 ? 'carousel' : 'classic';\n default:\n return 'classic';\n }\n}\n\n/** The colored initial a classic cell shows when the campaign sent no icon. */\nexport function getIconInitial(title: string, body: string): string {\n return (title || body || '?').trim().charAt(0).toUpperCase() || '?';\n}\n\n// The pipeline merges `customData` flat into `u`, so the contract keys are the\n// only ones to strip.\nexport function getCustomData(userData: IInboxUserData): Record<string, unknown> {\n const contractKeys = ['displayType', 'carousel', 'image'];\n\n return Object.keys(userData)\n .filter((key) => contractKeys.indexOf(key) === -1)\n .reduce<Record<string, unknown>>((acc, key) => {\n acc[key] = userData[key];\n\n return acc;\n }, {});\n}\n","/** Drawn when the configured colour is one the browser would refuse. */\nexport const FALLBACK_COLOR = '#333';\n\n// A colour value never needs these, and they are exactly what would end the\n// declaration or the rule it is interpolated into.\nconst RULE_BREAKERS = /[;{}]/;\n\n// One element, reused: the widgets validate every colour of their config on\n// each render.\nlet probe: HTMLElement | null = null;\n\n/** Keeps a colour the browser accepts, and replaces anything else with {@link FALLBACK_COLOR}. */\nexport function getValidColor(color: string): string {\n if (RULE_BREAKERS.test(color)) {\n return FALLBACK_COLOR;\n }\n\n if (!probe) {\n probe = document.createElement('div');\n }\n\n probe.style.color = '';\n probe.style.color = color;\n\n return probe.style.color ? color : FALLBACK_COLOR;\n}\n","// Schemes that run script in the page's own origin; everything else either\n// navigates away or is handed to the OS.\nconst UNSAFE_SCHEME = /^(?:javascript|vbscript|data|blob|file):/i;\nconst HAS_SCHEME = /^[a-z][a-z\\d+\\-.]*:/i;\n\n// Browsers ignore whitespace and control characters while resolving a scheme,\n// so a tab inside \"java<tab>script:\" navigates just as `javascript:` does.\nfunction normalize(url: string): string {\n return url\n .split('')\n .filter((char) => char.charCodeAt(0) > 0x20 && char.charCodeAt(0) !== 0x7F)\n .join('');\n}\n\n/** True when the url is safe to assign to `location.href`. Relative urls qualify. */\nexport function isSafeUrl(url: string): boolean {\n return !!url && !UNSAFE_SCHEME.test(normalize(url));\n}\n\n/** True when the url carries a scheme and that scheme is safe to navigate to. */\nexport function isSafeAbsoluteUrl(url: string): boolean {\n const normalized = normalize(url);\n\n return HAS_SCHEME.test(normalized) && !UNSAFE_SCHEME.test(normalized);\n}\n","import {\n CONFIG_STYLES,\n DEFAULT_CONFIG,\n SYNC_INTERVAL,\n} from './constants';\nimport inboxWidgetStyleCss from './css/inboxWidgetStyle.css';\nimport {\n isElementFixed,\n compareBySendDate,\n} from './helpers';\nimport { type IConfigStyles, type IInboxWidgetConfig, type TMessagesElementsType } from './inbox_widget.types';\nimport {\n messageTemplate,\n widgetTemplate,\n widgetTemplateEmpty,\n} from './widgetTemplates';\nimport { type Pushwoosh } from '../../core/Pushwoosh';\nimport { getValidColor } from '../../helpers/cssColor';\nimport { isSafeUrl } from '../../helpers/url';\nimport { type IInboxMessagePublic } from '../../models/InboxMessages.types';\n\nexport class PWInboxWidget {\n pw: Pushwoosh;\n widget: HTMLElement;\n trigger: HTMLElement;\n list: HTMLElement;\n widgetParent: HTMLElement;\n count: number;\n messages: Array<IInboxMessagePublic>;\n messagesElements: TMessagesElementsType;\n /** Visible slide per carousel message, kept across the widget's re-renders. */\n activeSlides: { [code: string]: number };\n readItems: Array<string>;\n isOpened: boolean;\n config: IInboxWidgetConfig;\n defaultMargin: number;\n isFixed: boolean;\n private lastSyncAt: number = 0;\n\n constructor(pw: Pushwoosh) {\n // Set Pushwoosh object\n this.pw = pw;\n\n const inboxWidgetConfig = this.pw.initParams.inboxWidget!;\n\n this.config = {\n ...DEFAULT_CONFIG,\n arrowBorderColor: inboxWidgetConfig.borderColor && inboxWidgetConfig.borderColor !== 'transparent'\n ? inboxWidgetConfig.borderColor\n : 'rgba(0,0,0,.1)',\n ...this.pw.initParams.inboxWidget,\n };\n\n this.updateInbox = this.updateInbox.bind(this);\n this.markVisibleItemsAsRead = this.markVisibleItemsAsRead.bind(this);\n this.onWidgetClickHandler = this.onWidgetClickHandler.bind(this);\n this.onTriggerClickHandler = this.onTriggerClickHandler.bind(this);\n this.onWindowScrollHandler = this.onWindowScrollHandler.bind(this);\n this.toggle = this.toggle.bind(this);\n }\n\n public async run() {\n this.initTrigger();\n this.updateInbox();\n this.addListeners();\n }\n\n public toggle(isOpened?: boolean) {\n const openWidget = typeof isOpened === 'undefined'\n ? !this.isOpened\n : isOpened;\n\n if (openWidget) {\n this.openWidget();\n } else {\n this.closeWidget();\n }\n }\n\n // set inbox widget to trigger element on page\n private initTrigger() {\n if (!this.pw.pwinbox) {\n throw new Error('Web inbox is not allowed.');\n }\n\n const trigger = document.getElementById(this.config.triggerId);\n\n if (!trigger) {\n throw new Error('Inbox trigger element doesn\\'t exist. You must set triggerId in inboxWidget config. See the documentation.');\n }\n\n this.trigger = trigger;\n this.trigger.classList.add('pw-inbox-trigger');\n\n // Init has just pulled the inbox itself, so the first bell open must not\n // fetch the whole thing again seconds later.\n this.lastSyncAt = Date.now();\n\n this.defaultMargin = 12;\n this.messagesElements = {};\n this.activeSlides = {};\n this.messages = [];\n this.readItems = [];\n this.updateCounter(0);\n this.isOpened = false;\n\n this.renderWidget();\n\n this.isFixed = isElementFixed(this.trigger);\n }\n\n private renderWidget() {\n this.widget = document.createElement('div');\n this.widget.id = 'pwInboxWidget';\n this.widget.className = 'pw-inbox-widget';\n this.widget.classList.toggle('pw-open', this.isOpened);\n this.widget.classList.toggle('pw-inbox-widget--legacy-cell', this.config.legacyClassicCell);\n\n this.widgetParent = document.querySelector(this.config.appendTo) || document.body;\n\n this.widgetParent.appendChild(this.widget);\n this.widgetParent.appendChild(this.getStyle());\n this.renderWidgetInner();\n }\n\n private getStyle(): HTMLStyleElement {\n const styleNode = document.createElement('style');\n styleNode.innerHTML = this.configureStyle(inboxWidgetStyleCss);\n return styleNode;\n }\n\n private configureStyle(styles: string): string {\n let resultStyles = styles.toString();\n CONFIG_STYLES.forEach((style: IConfigStyles) => {\n const template = new RegExp(`var\\\\(--${style.name}\\\\)`, 'ig');\n const result = this.getStyleFormatter(style);\n\n resultStyles = resultStyles.replace(template, result);\n });\n return resultStyles;\n }\n\n private getStyleFormatter(style: IConfigStyles): string {\n switch (style.type) {\n case 'size':\n return `${this.config[style.name] || 0}px`;\n case 'number':\n return parseFloat(this.config[style.name].toString()).toString();\n case 'string':\n return this.config[style.name].toString();\n case 'color':\n return getValidColor(this.config[style.name].toString());\n default:\n return 'none';\n }\n }\n\n private renderWidgetInner() {\n if (this.messages.length > 0) {\n this.widget.classList.remove('pw-inbox-widget--empty');\n this.widget.innerHTML = widgetTemplate(this.config.title);\n this.renderMessages();\n } else {\n this.widget.classList.add('pw-inbox-widget--empty');\n const {\n emptyInboxTitle,\n emptyInboxText,\n emptyInboxIconUrl,\n } = this.config;\n this.widget.innerHTML = widgetTemplateEmpty(emptyInboxIconUrl, emptyInboxTitle, emptyInboxText);\n }\n }\n\n private renderMessages() {\n this.list = this.widget.querySelector('.pw-inbox_list') || document.createElement('ul');\n\n // innerHTML was just replaced, so every element collected last render is\n // detached: keeping them leaks and feeds stale offsets to the viewport check.\n this.messagesElements = {};\n\n this.messages.forEach((message: IInboxMessagePublic) => {\n const messageElement = document.createElement('li');\n messageElement.className = 'pw-inbox_item';\n messageElement.classList.toggle('pw-new', !message.isRead);\n messageElement.classList.toggle('pw-unread', !message.isActionPerformed);\n messageElement.setAttribute('data-pw-inbox-message-id', message.code);\n messageElement.innerHTML = messageTemplate(message, this.activeSlides[message.code] || 0);\n\n this.list.appendChild(messageElement);\n this.messagesElements[message.code] = messageElement;\n });\n }\n\n private updateCounter(count: number) {\n this.count = count;\n this.trigger.setAttribute('data-pw-count', `${this.count}`);\n this.trigger.classList.toggle('pw-empty', this.count === 0);\n }\n\n private updateInboxMessages(messages: Array<IInboxMessagePublic>) {\n this.messages = messages.sort(({ sendDate: sendDateOne }, { sendDate: sendDateTwo }) => compareBySendDate(sendDateOne, sendDateTwo));\n this.renderWidgetInner();\n }\n\n openWidget() {\n this.isOpened = true;\n this.widget.classList.add('pw-open');\n this.syncMessages();\n document.addEventListener('click', this.onWidgetClickHandler);\n window.addEventListener('scroll', this.onWindowScrollHandler);\n window.addEventListener('resize', this.onWindowScrollHandler);\n this.markVisibleItemsAsRead();\n if (this.messages.length > 0) {\n this.list.addEventListener('scroll', this.markVisibleItemsAsRead);\n }\n this.positionWidget();\n }\n\n closeWidget() {\n this.isOpened = false;\n document.removeEventListener('click', this.onWidgetClickHandler);\n window.removeEventListener('scroll', this.onWindowScrollHandler);\n window.removeEventListener('resize', this.onWindowScrollHandler);\n this.updateReadStatus();\n if (this.messages.length > 0) {\n this.list.removeEventListener('scroll', this.markVisibleItemsAsRead);\n }\n this.widget.classList.remove('pw-open', 'pw-top', 'pw-bottom', 'pw-right', 'pw-left');\n this.widget.removeAttribute('style');\n }\n\n private positionWidget() {\n if (!this.isOpened) {\n return;\n }\n if (this.widgetParent === document.body) {\n this.defaultPlaceWidget();\n } else {\n this.customPlaceWidget();\n }\n }\n\n private customPlaceWidget() {\n const { position } = this.config;\n this.widgetParent.style.position = 'relative';\n this.widget.classList.add('pw-inbox-widget--inset');\n this.widget.classList.add(`pw-${position}`);\n }\n\n private defaultPlaceWidget() {\n const position = this.pw.initParams.inboxWidget!.position ? this.config.position : this.getDefaultPosition();\n\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n\n if (widgetRect.width + (this.defaultMargin * 2) > windowWidth) {\n this.widget.style.width = `${windowWidth - (this.defaultMargin * 2)}px`;\n }\n if (widgetRect.height + 24 > windowHeight) {\n this.widget.style.height = `${windowHeight - (this.defaultMargin * 2)}px`;\n }\n\n switch (position) {\n case 'top': {\n this.alignWidgetTop();\n break;\n }\n case 'right': {\n this.alignWidgetRight();\n break;\n }\n case 'left': {\n this.alignWidgetLeft();\n break;\n }\n case 'bottom': {\n this.alignWidgetBottom();\n break;\n }\n }\n }\n\n private alignWidgetTop() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-top');\n\n let left = pageXOffset + triggerRect.left + Math.floor(triggerRect.width / 2) - Math.floor(widgetRect.width / 2);\n\n const isUnderLeft = left < pageXOffset;\n const isUnderRight = left + widgetRect.width > pageXOffset + windowWidth;\n\n if (isUnderLeft) {\n left = pageXOffset + this.defaultMargin;\n }\n if (isUnderRight) {\n left = pageXOffset + windowWidth - widgetRect.width - this.defaultMargin;\n }\n\n const top = pageYOffset + triggerRect.top - widgetRect.height;\n\n this.alignWidgetElement(left, top);\n arrow.style.left = `${triggerRect.left + Math.floor(triggerRect.width / 2) - left}px`;\n\n const topMargin = this.widget.getBoundingClientRect().top;\n const isUnderTop = topMargin < 0;\n if (isUnderTop) {\n const newHeight = this.widget.getBoundingClientRect().height + topMargin - this.defaultMargin;\n const newTop = this.widget.getBoundingClientRect().top - topMargin + this.defaultMargin;\n this.widget.style.height = `${newHeight}px`;\n this.widget.style.top = `${newTop}px`;\n }\n }\n\n private alignWidgetRight() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-right');\n\n let top = pageYOffset + triggerRect.top + Math.floor(triggerRect.height / 2) - Math.floor(widgetRect.height / 2);\n\n const isUnderTop = top < pageYOffset;\n const isUnderBottom = pageYOffset + windowHeight < top + widgetRect.height;\n\n if (isUnderTop) {\n top = pageYOffset + this.defaultMargin;\n }\n\n if (isUnderBottom) {\n top = pageYOffset + windowHeight - widgetRect.height - this.defaultMargin;\n }\n\n const left = pageXOffset + triggerRect.left + triggerRect.width;\n\n this.alignWidgetElement(left, top);\n arrow.style.top = `${triggerRect.top + Math.floor(triggerRect.height / 2) - top}px`;\n\n const rightMargin = windowWidth - this.widget.getBoundingClientRect().right;\n const isUnderRight = rightMargin < this.defaultMargin;\n if (isUnderRight) {\n const newWidth = this.widget.getBoundingClientRect().width + rightMargin - this.defaultMargin;\n this.widget.style.width = `${newWidth}px`;\n }\n }\n\n private alignWidgetLeft() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-left');\n\n let top = pageYOffset + triggerRect.top + Math.floor(triggerRect.height / 2) - Math.floor(widgetRect.height / 2);\n\n const isUnderTop = top < pageYOffset;\n const isUnderBottom = pageYOffset + windowHeight < top + widgetRect.height;\n\n if (isUnderTop) {\n top = pageYOffset + this.defaultMargin;\n }\n\n if (isUnderBottom) {\n top = pageYOffset + windowHeight - widgetRect.height - this.defaultMargin;\n }\n\n const left = pageXOffset + triggerRect.left - widgetRect.width;\n\n this.alignWidgetElement(left, top);\n arrow.style.top = `${triggerRect.top + Math.floor(triggerRect.height / 2) - top}px`;\n\n const leftMargin = this.widget.getBoundingClientRect().left;\n const isUnderLeft = leftMargin < 0;\n if (isUnderLeft) {\n const newWidth = this.widget.getBoundingClientRect().width + leftMargin - this.defaultMargin;\n const newLeft = this.widget.getBoundingClientRect().left - leftMargin;\n this.widget.style.width = `${newWidth}px`;\n this.widget.style.left = `${newLeft}px`;\n }\n }\n\n private alignWidgetBottom() {\n const triggerRect = this.trigger.getBoundingClientRect();\n const widgetRect = this.widget.getBoundingClientRect();\n if (!document.documentElement) {\n return;\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n const arrow: HTMLElement = this.widget.querySelector('.pw-inbox__arrow') || document.createElement('div');\n\n this.widget.classList.add('pw-bottom');\n\n let left = pageXOffset + triggerRect.left + Math.floor(triggerRect.width / 2) - Math.floor(widgetRect.width / 2);\n\n const isUnderLeft = left < pageXOffset;\n const isUnderRight = left + widgetRect.width > pageXOffset + windowWidth;\n\n if (isUnderLeft) {\n left = pageXOffset + this.defaultMargin;\n }\n if (isUnderRight) {\n left = pageXOffset + windowWidth - widgetRect.width - 12;\n }\n\n const top = pageYOffset + triggerRect.top + triggerRect.height;\n\n this.alignWidgetElement(left, top);\n arrow.style.left = `${triggerRect.left + Math.floor(triggerRect.width / 2) - left}px`;\n\n const bottomRange = windowHeight - this.widget.getBoundingClientRect().bottom;\n const isUnderBottom = bottomRange < this.defaultMargin;\n if (isUnderBottom) {\n const newHeight = this.widget.getBoundingClientRect().height + bottomRange - this.defaultMargin;\n this.widget.style.height = `${newHeight}px`;\n }\n }\n\n private alignWidgetElement(left: number, top: number) {\n this.widget.style.left = `${left}px`;\n this.widget.style.top = `${top}px`;\n }\n\n private getDefaultPosition(): string {\n const { left, top, width, height } = this.trigger.getBoundingClientRect();\n if (!document.documentElement) {\n return '';\n }\n const windowWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n const windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);\n\n const antiMargins: { [key: string]: number } = {\n right: left,\n bottom: top,\n left: windowWidth - (left + width),\n top: windowHeight - (top + height),\n };\n\n const leastMargin = Math.min(left, top, antiMargins.left, antiMargins.top);\n\n let position = 'bottom';\n\n Object.keys(antiMargins).forEach((key) => {\n if (antiMargins[key] === leastMargin) {\n position = key;\n }\n });\n\n return position;\n }\n\n private addListeners() {\n this.trigger.addEventListener('click', this.onTriggerClickHandler);\n\n this.pw.push(['onPutNewMessageToInboxStore', () => {\n this.updateInbox();\n }]);\n this.pw.push(['onUpdateInboxMessages', () => {\n this.updateInbox();\n }]);\n }\n\n private markVisibleItemsAsRead() {\n if (this.messages.length === 0) {\n return;\n }\n const scrollTop = (this.list.clientHeight + this.list.scrollTop) - 50;\n Object.keys(this.messagesElements).forEach((code: string) => {\n // check message exists and user saw the message in viewport\n if (!this.messagesElements[code] || this.messagesElements[code].offsetTop > scrollTop) {\n return;\n }\n\n const message = this.messages.find((message: IInboxMessagePublic): boolean => message.code === code);\n\n // mark messages as read\n if (!!message && !message.isRead && !(this.readItems.indexOf(code) + 1)) {\n this.readItems.push(code);\n }\n });\n }\n\n private updateReadStatus() {\n // Taken and cleared in one step: the codes are reported once, and a long\n // session does not keep growing the array across every open/close cycle.\n const codes = this.readItems;\n this.readItems = [];\n\n this.pw.pwinbox.readMessagesWithCodes(codes).then(this.updateInbox);\n }\n\n // Opening the bell is the only refresh besides init: a standalone App Inbox\n // message rides a channel with no sender, so no push announces one.\n private syncMessages() {\n // getInboxMessages returns the whole inbox, with no paging on the server\n // side, so toggling the bell must not turn into a request per click.\n if (Date.now() - this.lastSyncAt < SYNC_INTERVAL) {\n return;\n }\n\n this.lastSyncAt = Date.now();\n\n this.pw.pwinbox.syncMessages().catch((error: unknown) => {\n // Not the SDK Logger: it drags `core/storage` in and costs this bundle\n // ~20 KiB. SubscriptionButton logs the same way for the same reason.\n console.error('Pushwoosh: cannot refresh the inbox on open', error);\n });\n }\n\n private updateInbox() {\n this.pw.pwinbox.loadMessages().then((messages: Array<IInboxMessagePublic>) => {\n this.updateInboxMessages(messages);\n });\n this.pw.pwinbox.unreadMessagesCount().then((count: number) => {\n this.updateCounter(count);\n });\n }\n\n private performMessageAction(code: string) {\n this.pw.pwinbox.performActionForMessageWithCode(code)\n .then(() => {\n this.updateInbox();\n });\n }\n\n private removeMessages(messages: Array<string>) {\n // Was `slice(indexOf(code), 1)`, which returns an empty array for any index\n // past 1 and so discarded every pending read code, not just this one.\n this.readItems = this.readItems.filter((code: string) => messages.indexOf(code) === -1);\n this.pw.pwinbox.deleteMessagesWithCodes(messages)\n .then(() => {\n this.updateInbox();\n });\n }\n\n // handlers\n\n private onTriggerClickHandler(event: MouseEvent) {\n event.stopPropagation();\n if (!event.target) {\n return;\n }\n\n this.toggle();\n }\n\n private onWidgetClickHandler(event: MouseEvent) {\n if (!event.target) {\n return;\n }\n\n const itemElement = (<HTMLElement>event.target).closest('.pw-inbox_item');\n\n if (!itemElement) {\n this.toggle();\n return;\n }\n\n const messageCode = itemElement.getAttribute('data-pw-inbox-message-id');\n\n if (!messageCode) {\n return;\n }\n\n const removeIconClick = (<HTMLElement>event.target).closest('.pw-inbox_item-remove');\n\n if (removeIconClick) {\n this.removeMessages([messageCode]);\n return;\n }\n\n // A pager dot only switches the slide: it must not open the message.\n const dotElement = (<HTMLElement>event.target).closest('.pw-inbox_dot');\n\n if (dotElement) {\n this.showSlide(messageCode, parseInt(dotElement.getAttribute('data-pw-slide') || '0', 10));\n return;\n }\n\n // A slide link goes there instead of the whole message's action, as in the\n // iOS SDK. Re-checked here because the value round-trips through the DOM.\n const slideElement = (<HTMLElement>event.target).closest('.pw-inbox_slide');\n const slideLink = slideElement && slideElement.getAttribute('data-pw-slide-link');\n\n if (slideLink && isSafeUrl(slideLink)) {\n document.location.href = slideLink;\n return;\n }\n\n this.performMessageAction(messageCode);\n }\n\n /** Switch the visible slide of one carousel message and redraw just that cell. */\n private showSlide(code: string, index: number) {\n this.activeSlides[code] = index;\n\n const messageElement = this.messagesElements[code];\n const message = this.messages.find((item: IInboxMessagePublic): boolean => item.code === code);\n\n if (messageElement && message) {\n messageElement.innerHTML = messageTemplate(message, index);\n }\n }\n\n private onWindowScrollHandler() {\n if (this.isFixed && this.isOpened) {\n this.toggle();\n return;\n }\n this.positionWidget();\n }\n}\n"],"names":["root","factory","exports","module","define","amd","a","i","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MONTHS","CONFIG_STYLES","name","type","DEFAULT_CONFIG","enable","triggerId","position","appendTo","title","bgColor","textColor","fontFamily","borderRadius","borderColor","badgeBgColor","badgeTextColor","widgetWidth","zIndex","messageTitleColor","timeTextColor","emptyInboxTitle","emptyInboxTitleColor","emptyInboxText","emptyInboxTextColor","emptyInboxIconUrl","arrowBorderColor","legacyClassicCell","unreadDotColor","avatarBgColor","avatarTextColor","avatarSize","mediaRadius","slideCaptionColor","slideScrimColor","pagerDotActiveColor","pagerDotColor","isElementFixed","element","isFixed","window","getComputedStyle","parentElement","htmlEscapes","reUnescapedHtml","reHasUnescapedHtml","RegExp","source","escape_escape","string","test","replace","chr","textsTemplate","message","sendDate","isRead","date","localDate","Date","gap","getTime","Math","floor","getDate","getMonth","getFullYear","getHours","getMinutes","toString","slice","getMessageTime","heroTemplate","url","alt","messageTemplate","activeSlide","layout","heroUrl","carousel","body","inner","slides","activeIndex","slide","caption","dots","length","map","_slide","index","join","link","imageUrl","carouselTemplate","min","iconUrl","trim","charAt","toUpperCase","getIconInitial","avatarTemplate","FALLBACK_COLOR","RULE_BREAKERS","probe","UNSAFE_SCHEME","normalize","split","filter","char","charCodeAt","PWInboxWidget","constructor","pw","lastSyncAt","inboxWidgetConfig","initParams","inboxWidget","config","updateInbox","bind","markVisibleItemsAsRead","onWidgetClickHandler","onTriggerClickHandler","onWindowScrollHandler","toggle","run","initTrigger","addListeners","isOpened","openWidget","closeWidget","pwinbox","Error","trigger","document","getElementById","classList","add","now","defaultMargin","messagesElements","activeSlides","messages","readItems","updateCounter","renderWidget","widget","createElement","id","className","widgetParent","querySelector","appendChild","getStyle","renderWidgetInner","styleNode","innerHTML","configureStyle","styles","resultStyles","forEach","style","template","result","getStyleFormatter","parseFloat","color","remove","renderMessages","widgetTemplateEmpty","list","messageElement","isActionPerformed","setAttribute","code","count","updateInboxMessages","sort","sendDateOne","sendDateTwo","compareBySendDate","dateOne","syncMessages","addEventListener","positionWidget","removeEventListener","updateReadStatus","removeAttribute","defaultPlaceWidget","customPlaceWidget","getDefaultPosition","widgetRect","getBoundingClientRect","documentElement","windowWidth","max","clientWidth","innerWidth","windowHeight","clientHeight","innerHeight","width","height","alignWidgetTop","alignWidgetRight","alignWidgetLeft","alignWidgetBottom","triggerRect","arrow","left","pageXOffset","isUnderLeft","isUnderRight","top","pageYOffset","alignWidgetElement","topMargin","newHeight","newTop","isUnderTop","isUnderBottom","rightMargin","right","newWidth","leftMargin","newLeft","bottomRange","bottom","antiMargins","leastMargin","keys","push","scrollTop","offsetTop","find","indexOf","codes","readMessagesWithCodes","then","catch","error","console","loadMessages","unreadMessagesCount","performMessageAction","performActionForMessageWithCode","removeMessages","deleteMessagesWithCodes","event","stopPropagation","target","itemElement","closest","messageCode","getAttribute","dotElement","showSlide","parseInt","slideElement","slideLink","location","href","item"],"sourceRoot":""}
@@ -1,2 +1,2 @@
1
- !function(t,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e=n();for(var o in e)("object"==typeof exports?exports:t)[o]=e[o]}}(this,()=>(()=>{"use strict";const t={d:(n,e)=>{for(var o in e)t.o(e,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:e[o]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let n={};t.r(n),t.d(n,{PWSubscribePopupWidget:()=>i});const e={enable:!0,text:"Don’t miss out on our news and updates! Enable push notifications",askLaterButtonText:"Not now",confirmSubscriptionButtonText:"Subscribe",delay:5,retryOffset:604800,overlay:!1,position:"top",mobileViewMargin:"0",bgColor:"#fff",borderColor:"transparent",boxShadow:"0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)",textColor:"#000",textSize:"inherit",textWeight:"normal",fontFamily:"inherit",subscribeBtnBgColor:"#4285f4",subscribeBtnTextColor:"#fff",subscribeBtnTextWeight:"normal",subscribeBtnBorderColor:"transparent",subscribeBtnBorderRadius:"2px",askLaterBtnBgColor:"transparent",askLaterBtnTextColor:"#000",askLaterBtnTextWeight:"normal",askLaterBtnBorderColor:"transparent",askLaterBtnBorderRadius:"2px",theme:"material",viewport:"html"},o=/^(#([\da-f]{3}){1,2}$|(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0?\.\d+)\)$|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/i,p=[{name:"mobileViewMargin",type:"string"},{name:"mobileViewPosition",type:"string"},{name:"mobileViewTransition",type:"string"},{name:"bgColor",type:"color"},{name:"borderColor",type:"color"},{name:"boxShadow",type:"string"},{name:"textColor",type:"color"},{name:"textSize",type:"string"},{name:"textWeight",type:"string"},{name:"fontFamily",type:"string"},{name:"subscribeBtnBgColor",type:"color"},{name:"subscribeBtnTextColor",type:"color"},{name:"subscribeBtnTextWeight",type:"string"},{name:"subscribeBtnBorderColor",type:"color"},{name:"subscribeBtnBorderRadius",type:"string"},{name:"askLaterBtnBgColor",type:"color"},{name:"askLaterBtnTextColor",type:"color"},{name:"askLaterBtnTextWeight",type:"string"},{name:"askLaterBtnBorderColor",type:"color"},{name:"askLaterBtnBorderRadius",type:"string"}];class i{constructor(t){this.pw=t;const{mobileViewMargin:n=""}=t.initParams.subscribePopup||{};this.config={...e,...t.initParams.subscribePopup,mobileViewTransition:n?"none":"bottom .4s ease-out",mobileViewPosition:n?"auto!important":"auto"},this.onAskLaterClick=this.onAskLaterClick.bind(this),this.onSubscribeClick=this.onSubscribeClick.bind(this)}async run(){const t=this.pw.isPushAvailable()?this.pw.driver:null;if(!t)return;const{manualToggle:n}=this.config,[e,o]=await Promise.all([this.pw.isSubscribed(),this.pw.data.getStatusManualUnsubscribed()]);if(e||!n&&o)return;const p=t.getPermission();if("granted"===p||"denied"===p)return;if(this.renderPopup(),this.appendStyles(),this.pw.moduleRegistry.subscribePopup=this,this.pw.dispatchEvent("subscribe-popup-ready",{}),n)return;const i=localStorage.getItem("LAST_OPEN_SUBSCRIPTION_POPUP"),s=i?parseInt(i):0,r=(new Date).getTime();s+1e3*this.config.retryOffset<r&&setTimeout(()=>{this.toggle(!0)},1e3*this.config.delay)}toggle(t){const n=void 0===t?!this.isShown:!!t;n!==this.isShown&&(n?this.show():this.hide())}async show(){if(await this.pw.isSubscribed())return;this.isShown=!0,this.popup.classList.add("pw-show"),document.body.classList.add("pw-popup-opened");const t=new CustomEvent("showPopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});this.popup.dispatchEvent(t);if(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)return;const{theme:n,viewport:e,position:o}=this.config;if("topbar"===n&&"top"===o){const t=document.querySelector(e)||document.createElement("div"),n=window.getComputedStyle(t).marginTop||"0";t.style.transition="margin-top .3s ease-out",t.style.marginTop=`${parseInt(n)+this.popup.getBoundingClientRect().height}px`}this.pw.dispatchEvent("subscribe-popup-show",{})}hide(){this.isShown=!1,this.popup.classList.remove("pw-show"),document.body.classList.remove("pw-popup-opened");const t=new CustomEvent("hidePopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});this.popup.dispatchEvent(t);const n=(new Date).getTime().toString();localStorage.setItem("LAST_OPEN_SUBSCRIPTION_POPUP",n);if(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)return;const{theme:e,viewport:o,position:p}=this.config;if("topbar"===e&&"top"===p){const t=document.querySelector(o)||document.createElement("div"),n=window.getComputedStyle(t).marginTop||"0";t.style.marginTop=parseInt(n)-this.popup.getBoundingClientRect().height+"px"}this.pw.dispatchEvent("subscribe-popup-hide",{})}renderPopup(){this.popup=document.createElement("div"),this.popup.id="pwSubscribePopup";const{text:t,askLaterButtonText:n,confirmSubscriptionButtonText:e,iconUrl:o,iconAlt:p,position:i,overlay:s,theme:r}=this.config;this.popup.className=`pw-subscribe-popup pw-position-${i} pw-subscribe-popup-${r}`,this.popup.classList.toggle("pw-subscribe-popup__overlay",s),this.popup.innerHTML=(({iconUrl:t,iconAlt:n,text:e,askLaterButtonText:o,confirmSubscriptionButtonText:p})=>`<div class="pw-subscription-popup-inner">\n <div class="pw-subscription-popup-content">\n ${t?`<div class="pw-subscription-popup-icon"><img src="${t}" alt="${n||"Subscribe"}"></div>`:""}\n <div class="pw-subscription-popup-text">\n ${e}\n </div>\n </div>\n <div class="pw-subscription-popup-controls">\n <button name="pwAskLater" class="pw-subscribe-popup-button">${o}</button>\n <button name="pwSubscribe" class="pw-subscribe-popup-button pw-subscribe-popup-button-active">${p}</button>\n </div>\n </div>`)({text:t,askLaterButtonText:n,confirmSubscriptionButtonText:e,iconUrl:o,iconAlt:p}),document.body.appendChild(this.popup),this.addListeners()}appendStyles(){const t=document.createElement("style");t.innerHTML=this.configureStyle(".pw-subscribe-popup {\n position: fixed;\n left: 50%;\n transform: translateX(-50%);\n justify-content: center;\n z-index: 1000000;\n display: flex;\n transition: all .4s ease-out;\n}\n\n.pw-subscribe-popup.pw-position-top {\n top: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-top.pw-show {\n top: 0;\n}\n\n.pw-subscribe-popup.pw-position-bottom {\n bottom: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-bottom.pw-show {\n bottom: 0;\n}\n\n.pw-subscribe-popup.pw-position-center {\n display: flex;\n\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n justify-content: center;\n align-items: center;\n\n transform: none;\n}\n\n.pw-subscribe-popup__overlay {\n background: rgba(0,0,0,.4);\n z-index: 1000000;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-subscribe-popup__overlay) {\n pointer-events: none;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-show) {\n display: none;\n}\n\n\n.pw-subscribe-popup__overlay.pw-position-top {\n align-items: flex-start;\n}\n\n.pw-subscribe-popup__overlay.pw-position-bottom {\n align-items: flex-end;\n}\n\n.pw-subscribe-popup__overlay.pw-position-center {\n align-items: center;\n}\n\n.pw-subscription-popup-inner {\n max-width: 400px;\n font-size: var(--textSize);\n color: var(--textColor);\n font-weight: var(--textWeight);\n font-family: var(--fontFamily);\n border-style: solid;\n border-width: 1px;\n border-color: var(--borderColor);\n background: var(--bgColor);\n box-shadow: var(--boxShadow);\n pointer-events: auto;\n}\n\n.pw-subscription-popup-content {\n padding: 16px 16px 4px;\n display: flex;\n justify-content: stretch;\n}\n\n.pw-subscription-popup-icon {\n flex: 0 0 50px;\n margin-right: 12px;\n padding-top: 4px;\n}\n\n.pw-subscription-popup-icon img {\n max-width: 60px;\n max-height: 60px;\n}\n\n.pw-subscription-popup-text {\n flex: 1 1 300px;\n}\n\n.pw-subscription-popup-controls {\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n padding: 8px 16px 16px;\n}\n\nbutton.pw-subscribe-popup-button {\n border: solid 1px var(--askLaterBtnBorderColor);\n border-radius: var(--askLaterBtnBorderRadius);\n display: inline-block;\n height: 36px;\n line-height: 36px;\n padding: 0 16px;\n text-transform: uppercase;\n font-weight: var(--askLaterBtnTextWeight);\n vertical-align: middle;\n -webkit-tap-highlight-color: transparent;\n font-size: 14px;\n outline: 0;\n text-decoration: none;\n color: var(--askLaterBtnTextColor);\n text-align: center;\n letter-spacing: .5px;\n cursor: pointer;\n background: var(--askLaterBtnBgColor);\n margin: 4px 8px;\n}\nbutton.pw-subscribe-popup-button:hover {\n background: rgba(0,0,0,.04);\n}\nbutton.pw-subscribe-popup-button:active {\n background: rgba(0,0,0,.12);\n}\n\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active {\n color: var(--subscribeBtnTextColor);\n background: var(--subscribeBtnBgColor);\n border-radius: var(--subscribeBtnBorderRadius);\n border: solid 1px var(--subscribeBtnBorderColor);\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n font-weight: var(--subscribeBtnTextWeight);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:hover {\n box-shadow: 0 3px 3px 0 rgba(0,0,0,0.14),\n 0 1px 7px 0 rgba(0,0,0,0.12),\n 0 3px 1px -1px rgba(0,0,0,0.2);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:active {\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n}\n\n@media screen and (min-width: 541px) {\n\n .pw-subscribe-popup-topbar {\n width: 100%;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n display: flex;\n flex-direction: row;\n padding: 2px 40px;\n justify-content: center;\n align-items: center;\n flex-wrap: nowrap;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-content {\n padding: 0;\n justify-content: flex-start;\n align-items: center;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-icon img {\n max-width: 28px;\n max-height: 28px;\n }\n\n .pw-subscribe-popup-topbar button.pw-subscribe-popup-button {\n height: 32px;\n line-height: 32px;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-controls {\n padding: 0 0 0 16px;\n align-items: center;\n }\n}\n@media screen and (max-width: 540px) {\n .pw-subscribe-popup,\n .pw-subscribe-popup.pw-position-top,\n .pw-subscribe-popup.pw-position-center,\n .pw-subscribe-popup.pw-position-bottom {\n top: var(--mobileViewPosition);\n bottom: -110%;\n left: 0;\n right: 0;\n transform: none;\n display: flex;\n transition: var(--mobileViewTransition);\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-subscribe-popup__overlay {\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-show {\n bottom: var(--mobileViewMargin);\n }\n\n .pw-subscribe-popup__overlay .pw-subscription-popup-inner {\n align-items: flex-end;\n justify-content: stretch;\n }\n\n .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n }\n}\n"),document.body.appendChild(t)}getStyleFormatter(t){switch(t.type){case"size":return`${this.config[t.name]||0}px`;case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return"transparent"===(n=this.config[t.name].toString())||o.test(n)?n:"#333";default:return"none"}var n}configureStyle(t){let n=t.toString();return p.forEach(t=>{const e=new RegExp(`var\\(--${t.name}\\)`,"ig"),o=this.getStyleFormatter(t);n=n.replace(e,o)}),n}addListeners(){const t=this.popup.querySelector('button[name="pwAskLater"]')||document.createElement("button"),n=this.popup.querySelector('button[name="pwSubscribe"]')||document.createElement("button");t.addEventListener("click",this.onAskLaterClick),n.addEventListener("click",this.onSubscribeClick)}onAskLaterClick(){this.toggle(!1),this.pw.dispatchEvent("subscribe-popup-decline",{})}onSubscribeClick(){this.toggle(!1),this.pw.dispatchEvent("subscribe-popup-accept",{}),this.pw.subscribe()}}return n})());
1
+ !function(t,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e=n();for(var o in e)("object"==typeof exports?exports:t)[o]=e[o]}}(this,()=>(()=>{"use strict";const t={d:(n,e)=>{for(var o in e)t.o(e,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:e[o]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let n={};t.r(n),t.d(n,{PWSubscribePopupWidget:()=>r});const e={enable:!0,text:"Don’t miss out on our news and updates! Enable push notifications",askLaterButtonText:"Not now",confirmSubscriptionButtonText:"Subscribe",delay:5,retryOffset:604800,overlay:!1,position:"top",mobileViewMargin:"0",bgColor:"#fff",borderColor:"transparent",boxShadow:"0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)",textColor:"#000",textSize:"inherit",textWeight:"normal",fontFamily:"inherit",subscribeBtnBgColor:"#4285f4",subscribeBtnTextColor:"#fff",subscribeBtnTextWeight:"normal",subscribeBtnBorderColor:"transparent",subscribeBtnBorderRadius:"2px",askLaterBtnBgColor:"transparent",askLaterBtnTextColor:"#000",askLaterBtnTextWeight:"normal",askLaterBtnBorderColor:"transparent",askLaterBtnBorderRadius:"2px",theme:"material",viewport:"html"},o=[{name:"mobileViewMargin",type:"string"},{name:"mobileViewPosition",type:"string"},{name:"mobileViewTransition",type:"string"},{name:"bgColor",type:"color"},{name:"borderColor",type:"color"},{name:"boxShadow",type:"string"},{name:"textColor",type:"color"},{name:"textSize",type:"string"},{name:"textWeight",type:"string"},{name:"fontFamily",type:"string"},{name:"subscribeBtnBgColor",type:"color"},{name:"subscribeBtnTextColor",type:"color"},{name:"subscribeBtnTextWeight",type:"string"},{name:"subscribeBtnBorderColor",type:"color"},{name:"subscribeBtnBorderRadius",type:"string"},{name:"askLaterBtnBgColor",type:"color"},{name:"askLaterBtnTextColor",type:"color"},{name:"askLaterBtnTextWeight",type:"string"},{name:"askLaterBtnBorderColor",type:"color"},{name:"askLaterBtnBorderRadius",type:"string"}],p="#333",i=/[;{}]/;let s=null;class r{constructor(t){this.pw=t;const{mobileViewMargin:n=""}=t.initParams.subscribePopup||{};this.config={...e,...t.initParams.subscribePopup,mobileViewTransition:n?"none":"bottom .4s ease-out",mobileViewPosition:n?"auto!important":"auto"},this.onAskLaterClick=this.onAskLaterClick.bind(this),this.onSubscribeClick=this.onSubscribeClick.bind(this)}async run(){const t=this.pw.isPushAvailable()?this.pw.driver:null;if(!t)return;const{manualToggle:n}=this.config,[e,o]=await Promise.all([this.pw.isSubscribed(),this.pw.data.getStatusManualUnsubscribed()]);if(e||!n&&o)return;const p=t.getPermission();if("granted"===p||"denied"===p)return;if(this.renderPopup(),this.appendStyles(),this.pw.moduleRegistry.subscribePopup=this,this.pw.dispatchEvent("subscribe-popup-ready",{}),n)return;const i=localStorage.getItem("LAST_OPEN_SUBSCRIPTION_POPUP"),s=i?parseInt(i):0,r=(new Date).getTime();s+1e3*this.config.retryOffset<r&&setTimeout(()=>{this.toggle(!0)},1e3*this.config.delay)}toggle(t){const n=void 0===t?!this.isShown:!!t;n!==this.isShown&&(n?this.show():this.hide())}async show(){if(await this.pw.isSubscribed())return;this.isShown=!0,this.popup.classList.add("pw-show"),document.body.classList.add("pw-popup-opened");const t=new CustomEvent("showPopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});this.popup.dispatchEvent(t);if(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)return;const{theme:n,viewport:e,position:o}=this.config;if("topbar"===n&&"top"===o){const t=document.querySelector(e)||document.createElement("div"),n=window.getComputedStyle(t).marginTop||"0";t.style.transition="margin-top .3s ease-out",t.style.marginTop=`${parseInt(n)+this.popup.getBoundingClientRect().height}px`}this.pw.dispatchEvent("subscribe-popup-show",{})}hide(){this.isShown=!1,this.popup.classList.remove("pw-show"),document.body.classList.remove("pw-popup-opened");const t=new CustomEvent("hidePopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});this.popup.dispatchEvent(t);const n=(new Date).getTime().toString();localStorage.setItem("LAST_OPEN_SUBSCRIPTION_POPUP",n);if(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)return;const{theme:e,viewport:o,position:p}=this.config;if("topbar"===e&&"top"===p){const t=document.querySelector(o)||document.createElement("div"),n=window.getComputedStyle(t).marginTop||"0";t.style.marginTop=parseInt(n)-this.popup.getBoundingClientRect().height+"px"}this.pw.dispatchEvent("subscribe-popup-hide",{})}renderPopup(){this.popup=document.createElement("div"),this.popup.id="pwSubscribePopup";const{text:t,askLaterButtonText:n,confirmSubscriptionButtonText:e,iconUrl:o,iconAlt:p,position:i,overlay:s,theme:r}=this.config;this.popup.className=`pw-subscribe-popup pw-position-${i} pw-subscribe-popup-${r}`,this.popup.classList.toggle("pw-subscribe-popup__overlay",s),this.popup.innerHTML=(({iconUrl:t,iconAlt:n,text:e,askLaterButtonText:o,confirmSubscriptionButtonText:p})=>`<div class="pw-subscription-popup-inner">\n <div class="pw-subscription-popup-content">\n ${t?`<div class="pw-subscription-popup-icon"><img src="${t}" alt="${n||"Subscribe"}"></div>`:""}\n <div class="pw-subscription-popup-text">\n ${e}\n </div>\n </div>\n <div class="pw-subscription-popup-controls">\n <button name="pwAskLater" class="pw-subscribe-popup-button">${o}</button>\n <button name="pwSubscribe" class="pw-subscribe-popup-button pw-subscribe-popup-button-active">${p}</button>\n </div>\n </div>`)({text:t,askLaterButtonText:n,confirmSubscriptionButtonText:e,iconUrl:o,iconAlt:p}),document.body.appendChild(this.popup),this.addListeners()}appendStyles(){const t=document.createElement("style");t.innerHTML=this.configureStyle(".pw-subscribe-popup {\n position: fixed;\n left: 50%;\n transform: translateX(-50%);\n justify-content: center;\n z-index: 1000000;\n display: flex;\n transition: all .4s ease-out;\n}\n\n.pw-subscribe-popup.pw-position-top {\n top: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-top.pw-show {\n top: 0;\n}\n\n.pw-subscribe-popup.pw-position-bottom {\n bottom: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-bottom.pw-show {\n bottom: 0;\n}\n\n.pw-subscribe-popup.pw-position-center {\n display: flex;\n\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n justify-content: center;\n align-items: center;\n\n transform: none;\n}\n\n.pw-subscribe-popup__overlay {\n background: rgba(0,0,0,.4);\n z-index: 1000000;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-subscribe-popup__overlay) {\n pointer-events: none;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-show) {\n display: none;\n}\n\n\n.pw-subscribe-popup__overlay.pw-position-top {\n align-items: flex-start;\n}\n\n.pw-subscribe-popup__overlay.pw-position-bottom {\n align-items: flex-end;\n}\n\n.pw-subscribe-popup__overlay.pw-position-center {\n align-items: center;\n}\n\n.pw-subscription-popup-inner {\n max-width: 400px;\n font-size: var(--textSize);\n color: var(--textColor);\n font-weight: var(--textWeight);\n font-family: var(--fontFamily);\n border-style: solid;\n border-width: 1px;\n border-color: var(--borderColor);\n background: var(--bgColor);\n box-shadow: var(--boxShadow);\n pointer-events: auto;\n}\n\n.pw-subscription-popup-content {\n padding: 16px 16px 4px;\n display: flex;\n justify-content: stretch;\n}\n\n.pw-subscription-popup-icon {\n flex: 0 0 50px;\n margin-right: 12px;\n padding-top: 4px;\n}\n\n.pw-subscription-popup-icon img {\n max-width: 60px;\n max-height: 60px;\n}\n\n.pw-subscription-popup-text {\n flex: 1 1 300px;\n}\n\n.pw-subscription-popup-controls {\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n padding: 8px 16px 16px;\n}\n\nbutton.pw-subscribe-popup-button {\n border: solid 1px var(--askLaterBtnBorderColor);\n border-radius: var(--askLaterBtnBorderRadius);\n display: inline-block;\n height: 36px;\n line-height: 36px;\n padding: 0 16px;\n text-transform: uppercase;\n font-weight: var(--askLaterBtnTextWeight);\n vertical-align: middle;\n -webkit-tap-highlight-color: transparent;\n font-size: 14px;\n outline: 0;\n text-decoration: none;\n color: var(--askLaterBtnTextColor);\n text-align: center;\n letter-spacing: .5px;\n cursor: pointer;\n background: var(--askLaterBtnBgColor);\n margin: 4px 8px;\n}\nbutton.pw-subscribe-popup-button:hover {\n background: rgba(0,0,0,.04);\n}\nbutton.pw-subscribe-popup-button:active {\n background: rgba(0,0,0,.12);\n}\n\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active {\n color: var(--subscribeBtnTextColor);\n background: var(--subscribeBtnBgColor);\n border-radius: var(--subscribeBtnBorderRadius);\n border: solid 1px var(--subscribeBtnBorderColor);\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n font-weight: var(--subscribeBtnTextWeight);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:hover {\n box-shadow: 0 3px 3px 0 rgba(0,0,0,0.14),\n 0 1px 7px 0 rgba(0,0,0,0.12),\n 0 3px 1px -1px rgba(0,0,0,0.2);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:active {\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n}\n\n@media screen and (min-width: 541px) {\n\n .pw-subscribe-popup-topbar {\n width: 100%;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n display: flex;\n flex-direction: row;\n padding: 2px 40px;\n justify-content: center;\n align-items: center;\n flex-wrap: nowrap;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-content {\n padding: 0;\n justify-content: flex-start;\n align-items: center;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-icon img {\n max-width: 28px;\n max-height: 28px;\n }\n\n .pw-subscribe-popup-topbar button.pw-subscribe-popup-button {\n height: 32px;\n line-height: 32px;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-controls {\n padding: 0 0 0 16px;\n align-items: center;\n }\n}\n@media screen and (max-width: 540px) {\n .pw-subscribe-popup,\n .pw-subscribe-popup.pw-position-top,\n .pw-subscribe-popup.pw-position-center,\n .pw-subscribe-popup.pw-position-bottom {\n top: var(--mobileViewPosition);\n bottom: -110%;\n left: 0;\n right: 0;\n transform: none;\n display: flex;\n transition: var(--mobileViewTransition);\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-subscribe-popup__overlay {\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-show {\n bottom: var(--mobileViewMargin);\n }\n\n .pw-subscribe-popup__overlay .pw-subscription-popup-inner {\n align-items: flex-end;\n justify-content: stretch;\n }\n\n .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n }\n}\n"),document.body.appendChild(t)}getStyleFormatter(t){switch(t.type){case"size":return`${this.config[t.name]||0}px`;case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return n=this.config[t.name].toString(),i.test(n)?p:(s||(s=document.createElement("div")),s.style.color="",s.style.color=n,s.style.color?n:p);default:return"none"}var n}configureStyle(t){let n=t.toString();return o.forEach(t=>{const e=new RegExp(`var\\(--${t.name}\\)`,"ig"),o=this.getStyleFormatter(t);n=n.replace(e,o)}),n}addListeners(){const t=this.popup.querySelector('button[name="pwAskLater"]')||document.createElement("button"),n=this.popup.querySelector('button[name="pwSubscribe"]')||document.createElement("button");t.addEventListener("click",this.onAskLaterClick),n.addEventListener("click",this.onSubscribeClick)}onAskLaterClick(){this.toggle(!1),this.pw.dispatchEvent("subscribe-popup-decline",{})}onSubscribeClick(){this.toggle(!1),this.pw.dispatchEvent("subscribe-popup-accept",{}),this.pw.subscribe()}}return n})());
2
2
  //# sourceMappingURL=widget-subscribe-popup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget-subscribe-popup.js","mappings":"CAAA,SAAAA,EAAAC,GACA,oBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,SACA,sBAAAG,QAAAA,OAAAC,IACAD,OAAA,GAAAH,OACA,CACA,IAAAK,EAAAL,IACA,QAAAM,KAAAD,GAAA,iBAAAJ,QAAAA,QAAAF,GAAAO,GAAAD,EAAAC,EACA,CACC,CATD,CASCC,KAAA,uBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAP,EAAAQ,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAV,EAAAS,IACAE,OAAAC,eAAAZ,EAAAS,EAAA,CAAyCI,YAAA,E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H,OAAOtH,KAAKuD,OAAO0D,EAAMjE,MAAMsE,WACjC,IAAK,QACH,ME7MQ,iBADca,EF8MDnI,KAAKuD,OAAO0D,EAAMjE,MAAMsE,aEzM5CxE,EAAkBsF,KAAKD,GAHrBA,EAKL,OFwMA,QACE,MAAO,OEhNR,IAAuBA,CFkN5B,CAEA,cAAAH,CAAeK,GACb,IAAIC,EAAeD,EAAOf,WAS1B,OAPAvE,EAAcwF,QAAStB,IACrB,MAAMuB,EAAW,IAAIC,OAAO,WAAWxB,EAAMjE,UAAW,MAClD0F,EAAS1I,KAAKiI,kBAAkBhB,GAEtCqB,EAAeA,EAAaK,QAAQH,EAAUE,KAGzCJ,CACT,CAEA,YAAAP,GACE,MAAMa,EAAiB5I,KAAK2F,MAAMiB,cAAc,8BAC3Cd,SAASe,cAAc,UACtBgC,EAAkB7I,KAAK2F,MAAMiB,cAAc,+BAC5Cd,SAASe,cAAc,UAE5B+B,EAAeE,iBAAiB,QAAS9I,KAAK0D,iBAC9CmF,EAAgBC,iBAAiB,QAAS9I,KAAK4D,iBACjD,CAEA,eAAAF,GACE1D,KAAKsF,QAAO,GACZtF,KAAKoD,GAAGwB,cAAc,0BAA2B,GACnD,CAEA,gBAAAhB,GACE5D,KAAKsF,QAAO,GACZtF,KAAKoD,GAAGwB,cAAc,yBAA0B,IAChD5E,KAAKoD,GAAG2F,WACV","sources":["webpack://web-push-notifications/webpack/universalModuleDefinition","webpack://web-push-notifications/webpack/bootstrap","webpack://web-push-notifications/webpack/runtime/define property getters","webpack://web-push-notifications/webpack/runtime/hasOwnProperty shorthand","webpack://web-push-notifications/webpack/runtime/make namespace object","webpack://web-push-notifications/./src/widgets/SubscribePopup/constants.ts","webpack://web-push-notifications/./src/widgets/SubscribePopup/SubscribePopup.ts","webpack://web-push-notifications/./src/widgets/SubscribePopup/popupTemplates.ts","webpack://web-push-notifications/./src/widgets/SubscribePopup/helpers.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { type ISubscribePopupConfig, type ISubscribePopupConfigStyles } from './types/subscribe-popup';\n\nexport const DEFAULT_CONFIG: ISubscribePopupConfig = {\n enable: true,\n text: 'Don’t miss out on our news and updates! Enable push notifications',\n askLaterButtonText: 'Not now',\n confirmSubscriptionButtonText: 'Subscribe',\n delay: 5,\n retryOffset: 60 * 60 * 24 * 7,\n overlay: false,\n position: 'top',\n mobileViewMargin: '0',\n\n bgColor: '#fff',\n borderColor: 'transparent',\n boxShadow: '0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)',\n\n textColor: '#000',\n textSize: 'inherit',\n textWeight: 'normal',\n fontFamily: 'inherit',\n\n subscribeBtnBgColor: '#4285f4',\n subscribeBtnTextColor: '#fff',\n subscribeBtnTextWeight: 'normal',\n subscribeBtnBorderColor: 'transparent',\n subscribeBtnBorderRadius: '2px',\n\n askLaterBtnBgColor: 'transparent',\n askLaterBtnTextColor: '#000',\n askLaterBtnTextWeight: 'normal',\n askLaterBtnBorderColor: 'transparent',\n askLaterBtnBorderRadius: '2px',\n\n theme: 'material',\n viewport: 'html',\n};\n\nexport const COLOR_TEST_REGEXP = /^(#([\\da-f]{3}){1,2}$|(rgb|hsl)a\\((\\d{1,3}%?,\\s?){3}(1|0?\\.\\d+)\\)$|(rgb|hsl)\\(\\d{1,3}%?(,\\s?\\d{1,3}%?){2}\\)$)/i;\n\n// Permissions\nexport const PERMISSION_DENIED = 'denied';\nexport const PERMISSION_GRANTED = 'granted';\n\nexport const CONFIG_STYLES: Array<ISubscribePopupConfigStyles> = [\n { name: 'mobileViewMargin', type: 'string' },\n { name: 'mobileViewPosition', type: 'string' },\n { name: 'mobileViewTransition', type: 'string' },\n { name: 'bgColor', type: 'color' },\n { name: 'borderColor', type: 'color' },\n { name: 'boxShadow', type: 'string' },\n { name: 'textColor', type: 'color' },\n { name: 'textSize', type: 'string' },\n { name: 'textWeight', type: 'string' },\n { name: 'fontFamily', type: 'string' },\n { name: 'subscribeBtnBgColor', type: 'color' },\n { name: 'subscribeBtnTextColor', type: 'color' },\n { name: 'subscribeBtnTextWeight', type: 'string' },\n { name: 'subscribeBtnBorderColor', type: 'color' },\n { name: 'subscribeBtnBorderRadius', type: 'string' },\n { name: 'askLaterBtnBgColor', type: 'color' },\n { name: 'askLaterBtnTextColor', type: 'color' },\n { name: 'askLaterBtnTextWeight', type: 'string' },\n { name: 'askLaterBtnBorderColor', type: 'color' },\n { name: 'askLaterBtnBorderRadius', type: 'string' },\n];\n","import {\n DEFAULT_CONFIG,\n CONFIG_STYLES,\n\n PERMISSION_DENIED,\n PERMISSION_GRANTED,\n} from './constants';\nimport { getValidColor } from './helpers';\nimport { innerTemplate } from './popupTemplates';\nimport popupCss from './styles/popup.css';\nimport {\n type ISubscribePopupConfig,\n type ISubscribePopupConfigStyles,\n type ISubscribePopupVariables,\n} from './types/subscribe-popup';\nimport { type Pushwoosh } from '../../core/Pushwoosh';\n\nexport class PWSubscribePopupWidget {\n pw: Pushwoosh;\n config: ISubscribePopupVariables;\n popup: HTMLElement;\n isShown: boolean;\n\n constructor(pw: Pushwoosh) {\n this.pw = pw;\n\n const { mobileViewMargin = '' } = pw.initParams.subscribePopup || ({} as ISubscribePopupConfig);\n\n this.config = {\n ...DEFAULT_CONFIG,\n ...pw.initParams.subscribePopup,\n mobileViewTransition: mobileViewMargin ? 'none' : 'bottom .4s ease-out',\n mobileViewPosition: mobileViewMargin ? 'auto!important' : 'auto',\n };\n\n this.onAskLaterClick = this.onAskLaterClick.bind(this);\n this.onSubscribeClick = this.onSubscribeClick.bind(this);\n }\n\n async run() {\n // Nothing to ask for when push is unavailable; also narrows `driver`.\n const driver = this.pw.isPushAvailable() ? this.pw.driver : null;\n\n if (!driver) {\n return;\n }\n\n const { manualToggle } = this.config;\n const [isSubscribed, isManualUnsubscribed] = await Promise.all([\n this.pw.isSubscribed(),\n this.pw.data.getStatusManualUnsubscribed(),\n ]);\n if (isSubscribed || (!manualToggle && isManualUnsubscribed)) {\n return;\n }\n\n const permission = driver.getPermission();\n if (permission === PERMISSION_GRANTED || permission === PERMISSION_DENIED) {\n return;\n }\n\n this.renderPopup();\n this.appendStyles();\n\n this.pw.moduleRegistry.subscribePopup = this;\n this.pw.dispatchEvent('subscribe-popup-ready', {});\n\n if (manualToggle) {\n return;\n }\n\n const lastPopupOpen = localStorage.getItem('LAST_OPEN_SUBSCRIPTION_POPUP');\n const lastPopupOpenTime = lastPopupOpen ? parseInt(lastPopupOpen) : 0;\n const now = new Date().getTime();\n\n if (lastPopupOpenTime + (this.config.retryOffset * 1000) < now) {\n setTimeout(() => {\n this.toggle(true);\n }, this.config.delay * 1000);\n }\n }\n\n toggle(isShown?: boolean) {\n const isPopupShown = typeof isShown === 'undefined' ? !this.isShown : !!isShown;\n if (isPopupShown !== this.isShown) {\n if (isPopupShown) {\n this.show();\n } else {\n this.hide();\n }\n }\n }\n\n async show() {\n if (await this.pw.isSubscribed()) {\n return;\n }\n this.isShown = true;\n this.popup.classList.add('pw-show');\n document.body.classList.add('pw-popup-opened');\n\n const event = new CustomEvent('showPopup', {\n bubbles: false,\n cancelable: false,\n detail: {\n popup: this.popup,\n },\n });\n this.popup.dispatchEvent(event);\n\n const screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n if (screenWidth < 541) {\n // mobile screen doesn't support themes\n return;\n }\n const {\n theme,\n viewport,\n position,\n } = this.config;\n if (theme === 'topbar' && position === 'top') {\n const viewportElement: HTMLElement = document.querySelector(viewport) || document.createElement('div');\n const currentMarginTop = window.getComputedStyle(viewportElement).marginTop || '0';\n viewportElement.style.transition = 'margin-top .3s ease-out';\n viewportElement.style.marginTop = `${parseInt(currentMarginTop) + this.popup.getBoundingClientRect().height}px`;\n }\n\n this.pw.dispatchEvent('subscribe-popup-show', {});\n }\n\n hide() {\n this.isShown = false;\n this.popup.classList.remove('pw-show');\n document.body.classList.remove('pw-popup-opened');\n\n const event = new CustomEvent('hidePopup', {\n bubbles: false,\n cancelable: false,\n detail: {\n popup: this.popup,\n },\n });\n this.popup.dispatchEvent(event);\n\n const now = new Date().getTime().toString();\n\n localStorage.setItem('LAST_OPEN_SUBSCRIPTION_POPUP', now);\n\n const screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n if (screenWidth < 541) {\n // mobile screen doesn't support themes\n return;\n }\n const {\n theme,\n viewport,\n position,\n } = this.config;\n if (theme === 'topbar' && position === 'top') {\n const viewportElement: HTMLElement = document.querySelector(viewport) || document.createElement('div');\n const currentMarginTop = window.getComputedStyle(viewportElement).marginTop || '0';\n viewportElement.style.marginTop = `${parseInt(currentMarginTop) - this.popup.getBoundingClientRect().height}px`;\n }\n\n this.pw.dispatchEvent('subscribe-popup-hide', {});\n }\n\n renderPopup() {\n this.popup = document.createElement('div');\n this.popup.id = 'pwSubscribePopup';\n const {\n text,\n askLaterButtonText,\n confirmSubscriptionButtonText,\n iconUrl,\n iconAlt,\n position,\n overlay,\n theme,\n } = this.config;\n this.popup.className = `pw-subscribe-popup pw-position-${position} pw-subscribe-popup-${theme}`;\n this.popup.classList.toggle('pw-subscribe-popup__overlay', overlay);\n this.popup.innerHTML = innerTemplate({\n text,\n askLaterButtonText,\n confirmSubscriptionButtonText,\n iconUrl,\n iconAlt,\n });\n document.body.appendChild(this.popup);\n this.addListeners();\n }\n\n appendStyles() {\n const style = document.createElement('style');\n style.innerHTML = this.configureStyle(popupCss);\n document.body.appendChild(style);\n }\n\n private getStyleFormatter(style: ISubscribePopupConfigStyles): string {\n switch (style.type) {\n case 'size':\n return `${this.config[style.name] || 0}px`;\n case 'number':\n return parseFloat(this.config[style.name].toString()).toString();\n case 'string':\n return this.config[style.name].toString();\n case 'color':\n return getValidColor(this.config[style.name].toString());\n default:\n return 'none';\n }\n }\n\n configureStyle(styles: string): string {\n let resultStyles = styles.toString();\n\n CONFIG_STYLES.forEach((style: ISubscribePopupConfigStyles) => {\n const template = new RegExp(`var\\\\(--${style.name}\\\\)`, 'ig');\n const result = this.getStyleFormatter(style);\n\n resultStyles = resultStyles.replace(template, result);\n });\n\n return resultStyles;\n }\n\n addListeners() {\n const askLaterButton = this.popup.querySelector('button[name=\"pwAskLater\"]')\n || document.createElement('button');\n const subscribeButton = this.popup.querySelector('button[name=\"pwSubscribe\"]')\n || document.createElement('button');\n\n askLaterButton.addEventListener('click', this.onAskLaterClick);\n subscribeButton.addEventListener('click', this.onSubscribeClick);\n }\n\n onAskLaterClick() {\n this.toggle(false);\n this.pw.dispatchEvent('subscribe-popup-decline', {});\n }\n\n onSubscribeClick() {\n this.toggle(false);\n this.pw.dispatchEvent('subscribe-popup-accept', {});\n this.pw.subscribe();\n }\n}\n","interface IInnerTemplate {\n iconUrl?: string;\n iconAlt?: string;\n text: string;\n askLaterButtonText: string;\n confirmSubscriptionButtonText: string;\n}\n\nexport const innerTemplate = ({ iconUrl, iconAlt, text, askLaterButtonText, confirmSubscriptionButtonText }: IInnerTemplate): string => {\n return `<div class=\"pw-subscription-popup-inner\">\n <div class=\"pw-subscription-popup-content\">\n ${iconUrl\n ? `<div class=\"pw-subscription-popup-icon\"><img src=\"${iconUrl}\" alt=\"${iconAlt || 'Subscribe'}\"></div>`\n : ''}\n <div class=\"pw-subscription-popup-text\">\n ${text}\n </div>\n </div>\n <div class=\"pw-subscription-popup-controls\">\n <button name=\"pwAskLater\" class=\"pw-subscribe-popup-button\">${askLaterButtonText}</button>\n <button name=\"pwSubscribe\" class=\"pw-subscribe-popup-button pw-subscribe-popup-button-active\">${confirmSubscriptionButtonText}</button>\n </div>\n </div>`;\n};\n","import { COLOR_TEST_REGEXP } from './constants';\n\nexport function getValidColor(color: string): string {\n if (color === 'transparent') {\n return color;\n }\n\n return COLOR_TEST_REGEXP.test(color)\n ? color\n : '#333';\n}\n"],"names":["root","factory","exports","module","define","amd","a","i","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","DEFAULT_CONFIG","enable","text","askLaterButtonText","confirmSubscriptionButtonText","delay","retryOffset","overlay","position","mobileViewMargin","bgColor","borderColor","boxShadow","textColor","textSize","textWeight","fontFamily","subscribeBtnBgColor","subscribeBtnTextColor","subscribeBtnTextWeight","subscribeBtnBorderColor","subscribeBtnBorderRadius","askLaterBtnBgColor","askLaterBtnTextColor","askLaterBtnTextWeight","askLaterBtnBorderColor","askLaterBtnBorderRadius","theme","viewport","COLOR_TEST_REGEXP","CONFIG_STYLES","name","type","PWSubscribePopupWidget","constructor","pw","initParams","subscribePopup","config","mobileViewTransition","mobileViewPosition","onAskLaterClick","bind","onSubscribeClick","run","driver","isPushAvailable","manualToggle","isSubscribed","isManualUnsubscribed","Promise","all","data","getStatusManualUnsubscribed","permission","getPermission","renderPopup","appendStyles","moduleRegistry","dispatchEvent","lastPopupOpen","localStorage","getItem","lastPopupOpenTime","parseInt","now","Date","getTime","setTimeout","toggle","isShown","isPopupShown","show","hide","popup","classList","add","document","body","event","CustomEvent","bubbles","cancelable","detail","Math","max","documentElement","clientWidth","window","innerWidth","viewportElement","querySelector","createElement","currentMarginTop","getComputedStyle","marginTop","style","transition","getBoundingClientRect","height","remove","toString","setItem","id","iconUrl","iconAlt","className","innerHTML","innerTemplate","appendChild","addListeners","configureStyle","getStyleFormatter","parseFloat","color","test","styles","resultStyles","forEach","template","RegExp","result","replace","askLaterButton","subscribeButton","addEventListener","subscribe"],"sourceRoot":""}
1
+ {"version":3,"file":"widget-subscribe-popup.js","mappings":"CAAA,SAAAA,EAAAC,GACA,oBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,SACA,sBAAAG,QAAAA,OAAAC,IACAD,OAAA,GAAAH,OACA,CACA,IAAAK,EAAAL,IACA,QAAAM,KAAAD,GAAA,iBAAAJ,QAAAA,QAAAF,GAAAO,GAAAD,EAAAC,EACA,CACC,CATD,CASCC,KAAA,uBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAP,EAAAQ,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAV,EAAAS,IACAE,OAAAC,eAAAZ,EAAAS,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCF,EAAA,CAAAQ,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAT,EAAAP,IACAW,OAAAC,eAAAZ,EAAAoB,OAAAC,YAAA,CAAsDC,MAAA,WACtDX,OAAAC,eAAAZ,EAAA,cAAgDsB,OAAA,4DCDzC,MAAMC,EAAwC,CACnDC,QAAQ,EACRC,KAAM,oEACNC,mBAAoB,UACpBC,8BAA+B,YAC/BC,MAAO,EACPC,YAAa,OACbC,SAAS,EACTC,SAAU,MACVC,iBAAkB,IAElBC,QAAS,OACTC,YAAa,cACbC,UAAW,yDAEXC,UAAW,OACXC,SAAU,UACVC,WAAY,SACZC,WAAY,UAEZC,oBAAqB,UACrBC,sBAAuB,OACvBC,uBAAwB,SACxBC,wBAAyB,cACzBC,yBAA0B,MAE1BC,mBAAoB,cACpBC,qBAAsB,OACtBC,sBAAuB,SACvBC,uBAAwB,cACxBC,wBAAyB,MAEzB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ACE,MAAMa,EAAiB9I,KAAK6F,MAAMiB,cAAc,8BAC3Cd,SAASe,cAAc,UACtBgC,EAAkB/I,KAAK6F,MAAMiB,cAAc,+BAC5Cd,SAASe,cAAc,UAE5B+B,EAAeE,iBAAiB,QAAShJ,KAAK4D,iBAC9CmF,EAAgBC,iBAAiB,QAAShJ,KAAK8D,iBACjD,CAEA,eAAAF,GACE5D,KAAKwF,QAAO,GACZxF,KAAKsD,GAAGwB,cAAc,0BAA2B,GACnD,CAEA,gBAAAhB,GACE9D,KAAKwF,QAAO,GACZxF,KAAKsD,GAAGwB,cAAc,yBAA0B,IAChD9E,KAAKsD,GAAG2F,WACV","sources":["webpack://web-push-notifications/webpack/universalModuleDefinition","webpack://web-push-notifications/webpack/bootstrap","webpack://web-push-notifications/webpack/runtime/define property getters","webpack://web-push-notifications/webpack/runtime/hasOwnProperty shorthand","webpack://web-push-notifications/webpack/runtime/make namespace object","webpack://web-push-notifications/./src/widgets/SubscribePopup/constants.ts","webpack://web-push-notifications/./src/helpers/cssColor.ts","webpack://web-push-notifications/./src/widgets/SubscribePopup/SubscribePopup.ts","webpack://web-push-notifications/./src/widgets/SubscribePopup/popupTemplates.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { type ISubscribePopupConfig, type ISubscribePopupConfigStyles } from './types/subscribe-popup';\n\nexport const DEFAULT_CONFIG: ISubscribePopupConfig = {\n enable: true,\n text: 'Don’t miss out on our news and updates! Enable push notifications',\n askLaterButtonText: 'Not now',\n confirmSubscriptionButtonText: 'Subscribe',\n delay: 5,\n retryOffset: 60 * 60 * 24 * 7,\n overlay: false,\n position: 'top',\n mobileViewMargin: '0',\n\n bgColor: '#fff',\n borderColor: 'transparent',\n boxShadow: '0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)',\n\n textColor: '#000',\n textSize: 'inherit',\n textWeight: 'normal',\n fontFamily: 'inherit',\n\n subscribeBtnBgColor: '#4285f4',\n subscribeBtnTextColor: '#fff',\n subscribeBtnTextWeight: 'normal',\n subscribeBtnBorderColor: 'transparent',\n subscribeBtnBorderRadius: '2px',\n\n askLaterBtnBgColor: 'transparent',\n askLaterBtnTextColor: '#000',\n askLaterBtnTextWeight: 'normal',\n askLaterBtnBorderColor: 'transparent',\n askLaterBtnBorderRadius: '2px',\n\n theme: 'material',\n viewport: 'html',\n};\n\n// Permissions\nexport const PERMISSION_DENIED = 'denied';\nexport const PERMISSION_GRANTED = 'granted';\n\nexport const CONFIG_STYLES: Array<ISubscribePopupConfigStyles> = [\n { name: 'mobileViewMargin', type: 'string' },\n { name: 'mobileViewPosition', type: 'string' },\n { name: 'mobileViewTransition', type: 'string' },\n { name: 'bgColor', type: 'color' },\n { name: 'borderColor', type: 'color' },\n { name: 'boxShadow', type: 'string' },\n { name: 'textColor', type: 'color' },\n { name: 'textSize', type: 'string' },\n { name: 'textWeight', type: 'string' },\n { name: 'fontFamily', type: 'string' },\n { name: 'subscribeBtnBgColor', type: 'color' },\n { name: 'subscribeBtnTextColor', type: 'color' },\n { name: 'subscribeBtnTextWeight', type: 'string' },\n { name: 'subscribeBtnBorderColor', type: 'color' },\n { name: 'subscribeBtnBorderRadius', type: 'string' },\n { name: 'askLaterBtnBgColor', type: 'color' },\n { name: 'askLaterBtnTextColor', type: 'color' },\n { name: 'askLaterBtnTextWeight', type: 'string' },\n { name: 'askLaterBtnBorderColor', type: 'color' },\n { name: 'askLaterBtnBorderRadius', type: 'string' },\n];\n","/** Drawn when the configured colour is one the browser would refuse. */\nexport const FALLBACK_COLOR = '#333';\n\n// A colour value never needs these, and they are exactly what would end the\n// declaration or the rule it is interpolated into.\nconst RULE_BREAKERS = /[;{}]/;\n\n// One element, reused: the widgets validate every colour of their config on\n// each render.\nlet probe: HTMLElement | null = null;\n\n/** Keeps a colour the browser accepts, and replaces anything else with {@link FALLBACK_COLOR}. */\nexport function getValidColor(color: string): string {\n if (RULE_BREAKERS.test(color)) {\n return FALLBACK_COLOR;\n }\n\n if (!probe) {\n probe = document.createElement('div');\n }\n\n probe.style.color = '';\n probe.style.color = color;\n\n return probe.style.color ? color : FALLBACK_COLOR;\n}\n","import {\n DEFAULT_CONFIG,\n CONFIG_STYLES,\n\n PERMISSION_DENIED,\n PERMISSION_GRANTED,\n} from './constants';\nimport { innerTemplate } from './popupTemplates';\nimport popupCss from './styles/popup.css';\nimport {\n type ISubscribePopupConfig,\n type ISubscribePopupConfigStyles,\n type ISubscribePopupVariables,\n} from './types/subscribe-popup';\nimport { type Pushwoosh } from '../../core/Pushwoosh';\nimport { getValidColor } from '../../helpers/cssColor';\n\nexport class PWSubscribePopupWidget {\n pw: Pushwoosh;\n config: ISubscribePopupVariables;\n popup: HTMLElement;\n isShown: boolean;\n\n constructor(pw: Pushwoosh) {\n this.pw = pw;\n\n const { mobileViewMargin = '' } = pw.initParams.subscribePopup || ({} as ISubscribePopupConfig);\n\n this.config = {\n ...DEFAULT_CONFIG,\n ...pw.initParams.subscribePopup,\n mobileViewTransition: mobileViewMargin ? 'none' : 'bottom .4s ease-out',\n mobileViewPosition: mobileViewMargin ? 'auto!important' : 'auto',\n };\n\n this.onAskLaterClick = this.onAskLaterClick.bind(this);\n this.onSubscribeClick = this.onSubscribeClick.bind(this);\n }\n\n async run() {\n // Nothing to ask for when push is unavailable; also narrows `driver`.\n const driver = this.pw.isPushAvailable() ? this.pw.driver : null;\n\n if (!driver) {\n return;\n }\n\n const { manualToggle } = this.config;\n const [isSubscribed, isManualUnsubscribed] = await Promise.all([\n this.pw.isSubscribed(),\n this.pw.data.getStatusManualUnsubscribed(),\n ]);\n if (isSubscribed || (!manualToggle && isManualUnsubscribed)) {\n return;\n }\n\n const permission = driver.getPermission();\n if (permission === PERMISSION_GRANTED || permission === PERMISSION_DENIED) {\n return;\n }\n\n this.renderPopup();\n this.appendStyles();\n\n this.pw.moduleRegistry.subscribePopup = this;\n this.pw.dispatchEvent('subscribe-popup-ready', {});\n\n if (manualToggle) {\n return;\n }\n\n const lastPopupOpen = localStorage.getItem('LAST_OPEN_SUBSCRIPTION_POPUP');\n const lastPopupOpenTime = lastPopupOpen ? parseInt(lastPopupOpen) : 0;\n const now = new Date().getTime();\n\n if (lastPopupOpenTime + (this.config.retryOffset * 1000) < now) {\n setTimeout(() => {\n this.toggle(true);\n }, this.config.delay * 1000);\n }\n }\n\n toggle(isShown?: boolean) {\n const isPopupShown = typeof isShown === 'undefined' ? !this.isShown : !!isShown;\n if (isPopupShown !== this.isShown) {\n if (isPopupShown) {\n this.show();\n } else {\n this.hide();\n }\n }\n }\n\n async show() {\n if (await this.pw.isSubscribed()) {\n return;\n }\n this.isShown = true;\n this.popup.classList.add('pw-show');\n document.body.classList.add('pw-popup-opened');\n\n const event = new CustomEvent('showPopup', {\n bubbles: false,\n cancelable: false,\n detail: {\n popup: this.popup,\n },\n });\n this.popup.dispatchEvent(event);\n\n const screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n if (screenWidth < 541) {\n // mobile screen doesn't support themes\n return;\n }\n const {\n theme,\n viewport,\n position,\n } = this.config;\n if (theme === 'topbar' && position === 'top') {\n const viewportElement: HTMLElement = document.querySelector(viewport) || document.createElement('div');\n const currentMarginTop = window.getComputedStyle(viewportElement).marginTop || '0';\n viewportElement.style.transition = 'margin-top .3s ease-out';\n viewportElement.style.marginTop = `${parseInt(currentMarginTop) + this.popup.getBoundingClientRect().height}px`;\n }\n\n this.pw.dispatchEvent('subscribe-popup-show', {});\n }\n\n hide() {\n this.isShown = false;\n this.popup.classList.remove('pw-show');\n document.body.classList.remove('pw-popup-opened');\n\n const event = new CustomEvent('hidePopup', {\n bubbles: false,\n cancelable: false,\n detail: {\n popup: this.popup,\n },\n });\n this.popup.dispatchEvent(event);\n\n const now = new Date().getTime().toString();\n\n localStorage.setItem('LAST_OPEN_SUBSCRIPTION_POPUP', now);\n\n const screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);\n if (screenWidth < 541) {\n // mobile screen doesn't support themes\n return;\n }\n const {\n theme,\n viewport,\n position,\n } = this.config;\n if (theme === 'topbar' && position === 'top') {\n const viewportElement: HTMLElement = document.querySelector(viewport) || document.createElement('div');\n const currentMarginTop = window.getComputedStyle(viewportElement).marginTop || '0';\n viewportElement.style.marginTop = `${parseInt(currentMarginTop) - this.popup.getBoundingClientRect().height}px`;\n }\n\n this.pw.dispatchEvent('subscribe-popup-hide', {});\n }\n\n renderPopup() {\n this.popup = document.createElement('div');\n this.popup.id = 'pwSubscribePopup';\n const {\n text,\n askLaterButtonText,\n confirmSubscriptionButtonText,\n iconUrl,\n iconAlt,\n position,\n overlay,\n theme,\n } = this.config;\n this.popup.className = `pw-subscribe-popup pw-position-${position} pw-subscribe-popup-${theme}`;\n this.popup.classList.toggle('pw-subscribe-popup__overlay', overlay);\n this.popup.innerHTML = innerTemplate({\n text,\n askLaterButtonText,\n confirmSubscriptionButtonText,\n iconUrl,\n iconAlt,\n });\n document.body.appendChild(this.popup);\n this.addListeners();\n }\n\n appendStyles() {\n const style = document.createElement('style');\n style.innerHTML = this.configureStyle(popupCss);\n document.body.appendChild(style);\n }\n\n private getStyleFormatter(style: ISubscribePopupConfigStyles): string {\n switch (style.type) {\n case 'size':\n return `${this.config[style.name] || 0}px`;\n case 'number':\n return parseFloat(this.config[style.name].toString()).toString();\n case 'string':\n return this.config[style.name].toString();\n case 'color':\n return getValidColor(this.config[style.name].toString());\n default:\n return 'none';\n }\n }\n\n configureStyle(styles: string): string {\n let resultStyles = styles.toString();\n\n CONFIG_STYLES.forEach((style: ISubscribePopupConfigStyles) => {\n const template = new RegExp(`var\\\\(--${style.name}\\\\)`, 'ig');\n const result = this.getStyleFormatter(style);\n\n resultStyles = resultStyles.replace(template, result);\n });\n\n return resultStyles;\n }\n\n addListeners() {\n const askLaterButton = this.popup.querySelector('button[name=\"pwAskLater\"]')\n || document.createElement('button');\n const subscribeButton = this.popup.querySelector('button[name=\"pwSubscribe\"]')\n || document.createElement('button');\n\n askLaterButton.addEventListener('click', this.onAskLaterClick);\n subscribeButton.addEventListener('click', this.onSubscribeClick);\n }\n\n onAskLaterClick() {\n this.toggle(false);\n this.pw.dispatchEvent('subscribe-popup-decline', {});\n }\n\n onSubscribeClick() {\n this.toggle(false);\n this.pw.dispatchEvent('subscribe-popup-accept', {});\n this.pw.subscribe();\n }\n}\n","interface IInnerTemplate {\n iconUrl?: string;\n iconAlt?: string;\n text: string;\n askLaterButtonText: string;\n confirmSubscriptionButtonText: string;\n}\n\nexport const innerTemplate = ({ iconUrl, iconAlt, text, askLaterButtonText, confirmSubscriptionButtonText }: IInnerTemplate): string => {\n return `<div class=\"pw-subscription-popup-inner\">\n <div class=\"pw-subscription-popup-content\">\n ${iconUrl\n ? `<div class=\"pw-subscription-popup-icon\"><img src=\"${iconUrl}\" alt=\"${iconAlt || 'Subscribe'}\"></div>`\n : ''}\n <div class=\"pw-subscription-popup-text\">\n ${text}\n </div>\n </div>\n <div class=\"pw-subscription-popup-controls\">\n <button name=\"pwAskLater\" class=\"pw-subscribe-popup-button\">${askLaterButtonText}</button>\n <button name=\"pwSubscribe\" class=\"pw-subscribe-popup-button pw-subscribe-popup-button-active\">${confirmSubscriptionButtonText}</button>\n </div>\n </div>`;\n};\n"],"names":["root","factory","exports","module","define","amd","a","i","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","DEFAULT_CONFIG","enable","text","askLaterButtonText","confirmSubscriptionButtonText","delay","retryOffset","overlay","position","mobileViewMargin","bgColor","borderColor","boxShadow","textColor","textSize","textWeight","fontFamily","subscribeBtnBgColor","subscribeBtnTextColor","subscribeBtnTextWeight","subscribeBtnBorderColor","subscribeBtnBorderRadius","askLaterBtnBgColor","askLaterBtnTextColor","askLaterBtnTextWeight","askLaterBtnBorderColor","askLaterBtnBorderRadius","theme","viewport","CONFIG_STYLES","name","type","FALLBACK_COLOR","RULE_BREAKERS","probe","PWSubscribePopupWidget","constructor","pw","initParams","subscribePopup","config","mobileViewTransition","mobileViewPosition","onAskLaterClick","bind","onSubscribeClick","run","driver","isPushAvailable","manualToggle","isSubscribed","isManualUnsubscribed","Promise","all","data","getStatusManualUnsubscribed","permission","getPermission","renderPopup","appendStyles","moduleRegistry","dispatchEvent","lastPopupOpen","localStorage","getItem","lastPopupOpenTime","parseInt","now","Date","getTime","setTimeout","toggle","isShown","isPopupShown","show","hide","popup","classList","add","document","body","event","CustomEvent","bubbles","cancelable","detail","Math","max","documentElement","clientWidth","window","innerWidth","viewportElement","querySelector","createElement","currentMarginTop","getComputedStyle","marginTop","style","transition","getBoundingClientRect","height","remove","toString","setItem","id","iconUrl","iconAlt","className","innerHTML","innerTemplate","appendChild","addListeners","configureStyle","getStyleFormatter","parseFloat","color","test","styles","resultStyles","forEach","template","RegExp","result","replace","askLaterButton","subscribeButton","addEventListener","subscribe"],"sourceRoot":""}