web-push-notifications 3.125.0 → 3.126.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/CHANGELOG.md +15 -0
- package/models/InboxCell.types.d.ts +6 -2
- package/npm.js +1 -1
- package/npm.js.map +1 -1
- package/package.json +2 -2
- package/service-worker.js +1 -1
- package/service-worker.js.map +1 -1
- package/widget-inbox.js +1 -1
- package/widget-inbox.js.map +1 -1
package/widget-inbox.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("preact"),require("preact/compat"),require("preact/jsx-runtime"));else if("function"==typeof define&&define.amd)define(["preact","preact/compat","preact/jsx-runtime"],t);else{var n="object"==typeof exports?t(require("preact"),require("preact/compat"),require("preact/jsx-runtime")):t(e.preact,e.preactCompat,e.jsxRuntime);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this,(e,t,n)=>(()=>{"use strict";var i={524(t){t.exports=e},873(e){e.exports=t},247(e){e.exports=n}};const o={};function s(e){const t=o[e];if(void 0!==t)return t.exports;const n=o[e]={exports:{}};return i[e](n,n.exports,s),n.exports}s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{Object.defineProperties(e,{[Symbol.toStringTag]:{value:"Module"},__esModule:{value:!0}})};let r={};s.r(r),s.d(r,{PWInboxWidget:()=>G});const a=["classic","captioned","banner","carousel"],l="pw-inbox",d=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"],p=[{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"}],c={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"};const g=6e4,h=36e5,w=/[;{}]/;function x(e){return(Array.isArray(e)?e:[]).filter(e=>!!e&&!!e.imageUrl).slice(0,5)}function b(e){return e.bannerUrl||e.iconUrl||""}function m(e){const t=!!e.title,n=!!e.body,i=b(e);let o=e.layoutType;switch(a.includes(o)||(o=e.bannerUrl&&!t?"banner":e.bannerUrl&&t&&n?"captioned":"classic"),o){case"banner":return i?"banner":"classic";case"captioned":return i&&t&&n?"captioned":"classic";case"carousel":return t&&n&&x(e.carousel).length>0?"carousel":"classic";default:return"classic"}}function u(e){return(e.title||e.body||"?").trim().charAt(0).toUpperCase()||"?"}function f(e,t=Date.now()){const n=new Date(e),i=t-n.getTime();if(i<=g)return"Just now";if(i<h)return`${Math.floor(i/g)} minutes ago`;if(i<864e5)return`${Math.floor(i/h)} hours ago`;const o=`0${n.getMinutes()}`.slice(-2);return`${n.getDate()} ${d[n.getMonth()]} ${n.getFullYear()}, ${n.getHours()}:${o}`}function y(e){const t={};return p.forEach(({name:n,type:i})=>{const o=function(e,t){switch(e){case"size":{if(null==t||""===t)return null;const e=Number(t);return Number.isFinite(e)?`${e}px`:null}case"number":{const e=parseFloat(String(t));return Number.isFinite(e)?String(e):null}default:{const e=String(t??"").trim();return e&&!w.test(e)?e:null}}}(i,e[n]);null!==o&&(t[`--${l}-${n}`]=o)}),t}const v=/^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;function C(e){return"string"==typeof e&&v.test(e)?e:void 0}const _=l,k=[...p],M=["badgeBgColor","badgeTextColor"],W=k.filter(e=>-1!==M.indexOf(e.name)),j={enable:!1,triggerId:"pwInbox",position:"bottom",appendTo:"body",...c};function I(e){let t="fixed"===window.getComputedStyle(e).position;return!t&&e.parentElement&&(t=I(e.parentElement)),t}var S=s(247),R=s(524),T=s(873);const E={display:"flex",gap:8,marginTop:8,minWidth:0},B={flex:"1 1 0",minWidth:0,height:28,padding:"0 8px",border:"none",borderRadius:6,fontFamily:"inherit",fontSize:12,fontWeight:500,lineHeight:"28px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"};function N(e){const{buttons:t,variant:n,renderText:i=e=>e,onButtonClick:o}=e,s=function(e){return(e??[]).map((e,t)=>({button:e,index:t})).filter(({button:e})=>"string"==typeof e.text&&!!e.text.trim()).slice(0,3)}(t);if(!s.length)return null;const r="preview"===n;return(0,S.jsx)("div",{className:"pw-inbox_buttons",style:r?E:void 0,children:s.map(({button:e,index:t})=>{const n=C(e.bgColor),s=C(e.textColor),a=r?{...B,background:n??"transparent",color:s??(n?"#FFFFFF":"#00A2FF")}:{background:n,color:s};return(0,S.jsx)("button",{type:"button",className:n?"pw-inbox_button":"pw-inbox_button pw-inbox_button--link",style:a,onClick:e=>{e.stopPropagation(),o?.(t)},children:i(e.text)},t)})})}function O(e){return t=>{t.stopPropagation(),e?.()}}function A({slides:e,alt:t,onSlideLinkClick:n}){const[i,o]=(0,T.useState)(0),s=Math.min(i,e.length-1),r=e[s],a=r.link?O(()=>n?.(r.link)):void 0;return(0,S.jsxs)("div",{className:"pw-inbox_media",children:[(0,S.jsxs)("div",{className:"pw-inbox_slide",onClick:a,children:[(0,S.jsx)("img",{alt:r.caption||t,className:"pw-inbox_hero",src:r.imageUrl}),!!r.caption&&(0,S.jsx)("span",{className:"pw-inbox_slide-caption",children:r.caption})]}),e.length>1&&(0,S.jsx)("div",{className:"pw-inbox_pager",children:e.map((e,t)=>(0,S.jsx)("button",{className:t===s?"pw-inbox_dot pw-active":"pw-inbox_dot",onClick:O(()=>o(t)),type:"button"},t))})]})}function L({url:e,alt:t,placeholder:n}){return(0,S.jsx)("div",{className:"pw-inbox_media",children:n?(0,S.jsx)("div",{className:"pw-inbox_hero pw-inbox_hero--placeholder"}):(0,S.jsx)("img",{alt:t,className:"pw-inbox_hero",src:e})})}function z(e){const{content:t,layout:n,title:i,body:o,timeLabel:s,isRead:r,isActionPerformed:a,code:l,placeholder:d,onClick:p,onRemove:c,onSlideLinkClick:g,onButtonClick:h}=e,w=(0,S.jsx)(N,{variant:"widget",buttons:t.buttons,onButtonClick:h}),m=t.title||t.body||"",f=(0,S.jsxs)("div",{className:"pw-inbox_content",children:[(0,S.jsxs)("div",{className:"pw-inbox_item-title",children:[i,!r&&(0,S.jsx)("span",{className:"pw-inbox_unread-dot"})]}),(0,S.jsx)("div",{className:"pw-inbox_item-body",children:o}),w,(0,S.jsx)("div",{className:"pw-inbox_item-time",children:s})]});let y,v;"carousel"!==n||d?"classic"!==n&&(y=(0,S.jsx)(L,{alt:m,placeholder:d,url:b(t)})):y=(0,S.jsx)(A,{alt:m,onSlideLinkClick:g,slides:x(t.carousel)}),v=d?(0,S.jsx)("div",{className:"pw-inbox_icon pw-inbox_icon--placeholder"}):(0,S.jsx)("div",{className:"pw-inbox_icon",children:t.iconUrl?(0,S.jsx)("img",{alt:m,className:"pw-inbox_message-image",src:t.iconUrl}):(0,S.jsx)("span",{className:"pw-inbox_icon-initial",children:u(t)})});const C=["pw-inbox_item",!r&&"pw-new",!a&&"pw-unread"].filter(Boolean).join(" ");return(0,S.jsxs)("li",{className:C,"data-pw-inbox-message-id":l,onClick:p,children:[(0,S.jsxs)("div",{className:`pw-inbox_item-inner pw-inbox_item--${n}`,children:["classic"===n?v:y,"banner"===n?w:f]}),(0,S.jsx)("span",{className:"pw-inbox_item-remove",onClick:O(c)})]})}function P({messages:e,appearance:t,now:n,onMessageClick:i,onMessageRemove:o,onSlideLinkClick:s,onButtonClick:r}){return 0===e.length?(0,S.jsxs)("div",{className:"pw-inbox_list--empty",children:[(0,S.jsx)("div",{className:"pw-inbox_list-icon",children:(0,S.jsx)("img",{alt:t.emptyInboxTitle,src:t.emptyInboxIconUrl})}),(0,S.jsx)("div",{className:"pw-inbox_list-title",children:t.emptyInboxTitle}),(0,S.jsx)("div",{className:"ipw-inbox_list-body",children:t.emptyInboxText})]}):(0,S.jsxs)("div",{className:"pw-inbox_inner",children:[(0,S.jsx)("div",{className:"pw-inbox_title",children:t.title}),(0,S.jsx)("ul",{className:"pw-inbox_list",children:e.map(e=>(0,S.jsx)(z,{body:e.body,code:e.code,content:e,isActionPerformed:e.isActionPerformed,isRead:e.isRead,layout:m(e),onClick:()=>i?.(e.code),onRemove:()=>o?.(e.code),onSlideLinkClick:t=>s?.(e.code,t),onButtonClick:t=>r?.(e.code,t),timeLabel:f(e.sendDate,n),title:e.title},e.code))})]})}function H(e){const{mode:t,messages:n,now:i,onMessageClick:o,onMessageRemove:s,onSlideLinkClick:r,onButtonClick:a}=e,l=function(e){const{borderColor:t}=e||{};return{...c,arrowBorderColor:t&&"transparent"!==t?t:c.arrowBorderColor,...e}}(e.appearance),d=(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("style",{children:"\n.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(--pw-inbox-badgeBgColor, #ff4c00);\n border-radius: 8px;\n color: var(--pw-inbox-badgeTextColor, #ffffff);\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(--pw-inbox-fontFamily, inherit);\n}\n.pw-inbox-widget {\n font-size: 14px;\n position: absolute;\n top: 0;\n left: -1000px;\n background: var(--pw-inbox-bgColor, #ffffff);\n border: solid 1px var(--pw-inbox-borderColor, transparent);\n border-radius: var(--pw-inbox-borderRadius, 4px);\n width: var(--pw-inbox-widgetWidth, 350px);\n box-shadow: 0 1px 4px 0 rgba(0,0,0,.25);\n z-index: var(--pw-inbox-zIndex, 100);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-textColor, #333333);\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(--pw-inbox-avatarSize, 52px);\n height: var(--pw-inbox-avatarSize, 52px);\n margin-right: 14px;\n overflow: hidden;\n border-radius: var(--pw-inbox-mediaRadius, 8px);\n background: var(--pw-inbox-avatarBgColor, #c4c8cc);\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(--pw-inbox-avatarTextColor, #4b5057);\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(--pw-inbox-messageTitleColor, #7a7a7a);\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(--pw-inbox-unreadDotColor, #00a2ff);\n}\n.pw-inbox_item-body {\n color: var(--pw-inbox-textColor, #333333);\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(--pw-inbox-timeTextColor, #c4c4c4);\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(--pw-inbox-textColor, #333333);\n font-weight: 700;\n}\n\n.pw-inbox_buttons {\n display: flex;\n gap: 8px;\n margin-top: 8px;\n min-width: 0;\n}\n\n.pw-inbox_button {\n flex: 1 1 0;\n min-width: 0;\n height: 28px;\n padding: 0 8px;\n border: none;\n border-radius: 6px;\n background: transparent;\n color: #ffffff;\n font-family: inherit;\n font-size: 12px;\n font-weight: 500;\n line-height: 28px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n cursor: pointer;\n}\n\n.pw-inbox_button--link {\n color: #00a2ff;\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(--pw-inbox-emptyInboxTitleColor, #333333);\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(--pw-inbox-emptyInboxTextColor, #7a7a7a);\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: 2 / 1;\n object-fit: cover;\n border-radius: var(--pw-inbox-mediaRadius, 8px);\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(--pw-inbox-slideCaptionColor, #ffffff);\n font-size: 14px;\n line-height: 20px;\n border-radius: 0 0 var(--pw-inbox-mediaRadius, 8px) var(--pw-inbox-mediaRadius, 8px);\n background: linear-gradient(transparent, var(--pw-inbox-slideScrimColor, rgba(0,0,0,.45)));\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(--pw-inbox-pagerDotColor, #ebf0f5);\n cursor: pointer;\n}\n.pw-inbox_dot.pw-active {\n background: var(--pw-inbox-pagerDotActiveColor, #00a2ff);\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\n.pw-inbox-widget.pw-inbox-widget--preview {\n position: relative;\n top: auto;\n left: auto;\n max-width: 100%;\n opacity: 1;\n transition: none;\n}\n.pw-inbox-widget--preview .pw-inbox__arrow {\n display: none;\n}\n.pw-inbox-widget--cell .pw-inbox_item {\n padding: 16px;\n}\n.pw-inbox_icon--placeholder {\n border: 1px dashed #00a2ff;\n background: #80b7ff33;\n}\n.pw-inbox_hero--placeholder {\n border: 1px dashed #00a2ff;\n background: #80b7ff33;\n}\n"}),(0,S.jsx)("div",{className:"pw-inbox__arrow"}),(0,S.jsx)(P,{appearance:l,messages:n,now:i,onMessageClick:o,onMessageRemove:s,onSlideLinkClick:r,onButtonClick:a})]});if("live"===t)return d;const p=function(e,t){return{className:["pw-inbox-widget pw-inbox-widget--preview",t,e.legacyClassicCell&&"pw-inbox-widget--legacy-cell"].filter(Boolean).join(" "),style:y(e)}}(l,0===n.length?"pw-inbox-widget--empty":void 0);return(0,S.jsx)("div",{className:p.className,style:p.style,children:d})}const F=e=>({code:e.code,title:e.title,body:e.message,iconUrl:e.iconUrl,bannerUrl:e.heroUrl,layoutType:e.layout,carousel:e.carousel,buttons:(e.buttons||[]).map(e=>({text:e.title,textColor:e.textColor,bgColor:e.bgColor,action:e.action,url:e.url,copyText:e.copyText,data:e.data})),sendDate:e.sendDate,isRead:e.isRead,isActionPerformed:e.isActionPerformed}),$="#333",D=/[;{}]/;let Y=null;function X(e,t){switch(e){case"size":{const e=Number(t??0);return Number.isFinite(e)?`${e}px`:null}case"number":{const e=parseFloat(String(t));return Number.isFinite(e)?String(e):null}case"color":{const e=String(t);return function(e){return D.test(e)?$:(Y||(Y=document.createElement("div")),Y.style.color="",Y.style.color=e,Y.style.color?e:$)}(e)===e?e:null}default:return String(t).trim()||null}}function U(e,t,n,i){n.forEach(({name:n,type:o})=>{const s=X(o,i[n]);null!==s&&e.style.setProperty(function(e,t){return`--${e}-${t}`}(t,n),s)})}const q=/^(?:javascript|vbscript|data|blob|file):/i;function V(e){return e.split("").filter(e=>e.charCodeAt(0)>32&&127!==e.charCodeAt(0)).join("")}function J(e){return!!e&&!q.test(V(e))}class G{constructor(e){this.lastSyncAt=0,this.pw=e;const t=this.pw.initParams.inboxWidget;this.config={...j,arrowBorderColor:t.borderColor&&"transparent"!==t.borderColor?t.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(){!1!==this.pw.initParams.inboxWidget?.enable&&(this.initTrigger(),this.updateInbox(),this.addListeners())}toggle(e){(void 0===e?!this.isOpened:e)?this.openWidget():this.closeWidget()}initTrigger(){if(!this.pw.pwinbox)throw new Error("Web inbox is not allowed.");const e=document.getElementById(this.config.triggerId);if(!e)throw new Error(`Pushwoosh: inbox trigger element #${this.config.triggerId} is not on the page. Add it, or change Trigger ID in the Pushwoosh Control Panel or inboxWidget.triggerId in the snippet.`);this.trigger=e,this.trigger.classList.add("pw-inbox-trigger"),this.lastSyncAt=Date.now(),this.defaultMargin=12,this.messagesElements={},this.messages=[],this.readItems=[],this.updateCounter(0),this.isOpened=!1,this.renderWidget(),this.isFixed=I(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.applyStyleVariables(),this.renderWidgetInner()}applyStyleVariables(){U(this.widget,_,k,this.config),U(this.trigger,_,W,this.config)}renderWidgetInner(){var e,t,n,i;this.widget.classList.toggle("pw-inbox-widget--empty",0===this.messages.length),e=this.widget,t=this.messages,n=this.config,i={onMessageClick:e=>this.performMessageAction(e),onMessageRemove:e=>this.removeMessages([e]),onButtonClick:(e,t)=>this.performButtonAction(e,t),onSlideLinkClick:(e,t)=>{J(t)?document.location.href=t:this.performMessageAction(e)}},(0,R.render)((0,S.jsx)(H,{mode:"live",messages:t.map(F),appearance:n,onMessageClick:i.onMessageClick,onMessageRemove:i.onMessageRemove,onSlideLinkClick:i.onSlideLinkClick,onButtonClick:i.onButtonClick}),e),this.list=this.widget.querySelector(".pw-inbox_list")||document.createElement("ul"),this.messagesElements={},this.widget.querySelectorAll("[data-pw-inbox-message-id]").forEach(e=>{this.messagesElements[e.getAttribute("data-pw-inbox-message-id")||""]=e})}updateCounter(e){this.count=e,this.trigger.setAttribute("data-pw-count",`${this.count}`),this.trigger.classList.toggle("pw-empty",0===this.count)}updateInboxMessages(e){this.messages=e.sort(({sendDate:e},{sendDate:t})=>{return n=e,new Date(t).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:e}=this.config;this.widgetParent.style.position="relative",this.widget.classList.add("pw-inbox-widget--inset"),this.widget.classList.add(`pw-${e}`)}defaultPlaceWidget(){const e=this.pw.initParams.inboxWidget.position?this.config.position:this.getDefaultPosition(),t=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(t.width+2*this.defaultMargin>n&&(this.widget.style.width=n-2*this.defaultMargin+"px"),t.height+24>i&&(this.widget.style.height=i-2*this.defaultMargin+"px"),e){case"top":this.alignWidgetTop();break;case"right":this.alignWidgetRight();break;case"left":this.alignWidgetLeft();break;case"bottom":this.alignWidgetBottom()}}alignWidgetTop(){const e=this.trigger.getBoundingClientRect(),t=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+e.left+Math.floor(e.width/2)-Math.floor(t.width/2);const s=o<pageXOffset,r=o+t.width>pageXOffset+n;s&&(o=pageXOffset+this.defaultMargin),r&&(o=pageXOffset+n-t.width-this.defaultMargin);const a=pageYOffset+e.top-t.height;this.alignWidgetElement(o,a),i.style.left=e.left+Math.floor(e.width/2)-o+"px";const l=this.widget.getBoundingClientRect().top;if(l<0){const e=this.widget.getBoundingClientRect().height+l-this.defaultMargin,t=this.widget.getBoundingClientRect().top-l+this.defaultMargin;this.widget.style.height=`${e}px`,this.widget.style.top=`${t}px`}}alignWidgetRight(){const e=this.trigger.getBoundingClientRect(),t=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+e.top+Math.floor(e.height/2)-Math.floor(t.height/2);const r=s<pageYOffset,a=pageYOffset+i<s+t.height;r&&(s=pageYOffset+this.defaultMargin),a&&(s=pageYOffset+i-t.height-this.defaultMargin);const l=pageXOffset+e.left+e.width;this.alignWidgetElement(l,s),o.style.top=e.top+Math.floor(e.height/2)-s+"px";const d=n-this.widget.getBoundingClientRect().right;if(d<this.defaultMargin){const e=this.widget.getBoundingClientRect().width+d-this.defaultMargin;this.widget.style.width=`${e}px`}}alignWidgetLeft(){const e=this.trigger.getBoundingClientRect(),t=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+e.top+Math.floor(e.height/2)-Math.floor(t.height/2);const s=o<pageYOffset,r=pageYOffset+n<o+t.height;s&&(o=pageYOffset+this.defaultMargin),r&&(o=pageYOffset+n-t.height-this.defaultMargin);const a=pageXOffset+e.left-t.width;this.alignWidgetElement(a,o),i.style.top=e.top+Math.floor(e.height/2)-o+"px";const l=this.widget.getBoundingClientRect().left;if(l<0){const e=this.widget.getBoundingClientRect().width+l-this.defaultMargin,t=this.widget.getBoundingClientRect().left-l;this.widget.style.width=`${e}px`,this.widget.style.left=`${t}px`}}alignWidgetBottom(){const e=this.trigger.getBoundingClientRect(),t=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+e.left+Math.floor(e.width/2)-Math.floor(t.width/2);const r=s<pageXOffset,a=s+t.width>pageXOffset+n;r&&(s=pageXOffset+this.defaultMargin),a&&(s=pageXOffset+n-t.width-12);const l=pageYOffset+e.top+e.height;this.alignWidgetElement(s,l),o.style.left=e.left+Math.floor(e.width/2)-s+"px";const d=i-this.widget.getBoundingClientRect().bottom;if(d<this.defaultMargin){const e=this.widget.getBoundingClientRect().height+d-this.defaultMargin;this.widget.style.height=`${e}px`}}alignWidgetElement(e,t){this.widget.style.left=`${e}px`,this.widget.style.top=`${t}px`}getDefaultPosition(){const{left:e,top:t,width:n,height:i}=this.trigger.getBoundingClientRect();if(!document.documentElement)return"";const o={right:e,bottom:t,left:Math.max(document.documentElement.clientWidth,window.innerWidth||0)-(e+n),top:Math.max(document.documentElement.clientHeight,window.innerHeight||0)-(t+i)},s=Math.min(e,t,o.left,o.top);let r="bottom";return Object.keys(o).forEach(e=>{o[e]===s&&(r=e)}),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 e=this.list.clientHeight+this.list.scrollTop-50;Object.keys(this.messagesElements).forEach(t=>{if(!this.messagesElements[t]||this.messagesElements[t].offsetTop>e)return;const n=this.messages.find(e=>e.code===t);!n||n.isRead||this.readItems.indexOf(t)+1||this.readItems.push(t)})}updateReadStatus(){const e=this.readItems;this.readItems=[],this.pw.pwinbox.readMessagesWithCodes(e).then(this.updateInbox)}syncMessages(){Date.now()-this.lastSyncAt<3e4||(this.lastSyncAt=Date.now(),this.pw.pwinbox.syncMessages().catch(e=>{console.error("Pushwoosh: cannot refresh the inbox on open",e)}))}updateInbox(){this.pw.pwinbox.loadMessages().then(e=>{this.updateInboxMessages(e)}),this.pw.pwinbox.unreadMessagesCount().then(e=>{this.updateCounter(e)})}performMessageAction(e){const t=this.messages.find(t=>t.code===e);t&&t.webPopupCode&&this.toggle(!1),this.pw.pwinbox.performActionForMessageWithCode(e).then(()=>{this.updateInbox()})}async performButtonAction(e,t){const n=this.messages.find(t=>t.code===e),i=n?.buttons?.[t];if(!i)return;const o=this.pw.pwinbox.reportButtonClick(e,i.id).catch(e=>console.error("Pushwoosh: cannot report the inbox button click",e));switch(i.action){case"open":if(i.url&&J(i.url))return await o,void(document.location.href=i.url);break;case"copy":this.copyText(i.copyText);break;default:this.pw.dispatchEvent("click-inbox-button",{messageCode:e,buttonId:i.id,data:i.data})}await o,this.updateInbox()}copyText(e){e&&navigator.clipboard&&navigator.clipboard.writeText(e).then(()=>this.showToast("Copied")).catch(e=>console.error("Pushwoosh: cannot copy the inbox button text",e))}showToast(e){const t=document.createElement("div");t.className="pw-inbox_toast",t.setAttribute("role","status"),t.textContent=e,Object.assign(t.style,{position:"fixed",left:"50%",bottom:"24px",transform:"translateX(-50%)",padding:"8px 16px",borderRadius:"6px",background:"rgba(0, 0, 0, 0.8)",color:"#fff",fontFamily:"inherit",fontSize:"13px",zIndex:String(Number(this.config.zIndex)+1)}),document.body.appendChild(t),setTimeout(()=>t.remove(),1500)}removeMessages(e){this.readItems=this.readItems.filter(t=>-1===e.indexOf(t)),this.pw.pwinbox.deleteMessagesWithCodes(e).then(()=>{this.updateInbox()})}onTriggerClickHandler(e){e.stopPropagation(),e.target&&this.toggle()}onWidgetClickHandler(e){e.target&&(e.target.closest(".pw-inbox_item")||this.toggle())}onWindowScrollHandler(){this.isFixed&&this.isOpened?this.toggle():this.positionWidget()}}return r})());
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("preact"),require("preact/compat"),require("preact/jsx-runtime"));else if("function"==typeof define&&define.amd)define(["preact","preact/compat","preact/jsx-runtime"],t);else{var n="object"==typeof exports?t(require("preact"),require("preact/compat"),require("preact/jsx-runtime")):t(e.preact,e.preactCompat,e.jsxRuntime);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this,(e,t,n)=>(()=>{"use strict";var i={524(t){t.exports=e},873(e){e.exports=t},247(e){e.exports=n}};const o={};function r(e){const t=o[e];if(void 0!==t)return t.exports;const n=o[e]={exports:{}};return i[e](n,n.exports,r),n.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{Object.defineProperties(e,{[Symbol.toStringTag]:{value:"Module"},__esModule:{value:!0}})};let s={};r.r(s),r.d(s,{PWInboxWidget:()=>G});const a=["classic","captioned","banner","carousel"],l="pw-inbox",d=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"],p=[{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"}],c={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"};const g=6e4,h=36e5,w=/[;{}]/;function x(e){return(Array.isArray(e)?e:[]).filter(e=>!!e&&!!e.imageUrl).slice(0,5)}function b(e){return e.bannerUrl||e.iconUrl||""}function m(e){const t=!!e.title,n=!!e.body,i=b(e);let o=e.layoutType;switch(a.includes(o)||(o=e.bannerUrl&&!t?"banner":e.bannerUrl&&t&&n?"captioned":"classic"),o){case"banner":return i?"banner":"classic";case"captioned":return i&&t&&n?"captioned":"classic";case"carousel":return t&&n&&x(e.carousel).length>0?"carousel":"classic";default:return"classic"}}function u(e){return(e.title||e.body||"?").trim().charAt(0).toUpperCase()||"?"}function f(e,t=Date.now()){const n=new Date(e),i=t-n.getTime();if(i<=g)return"Just now";if(i<h)return`${Math.floor(i/g)} minutes ago`;if(i<864e5)return`${Math.floor(i/h)} hours ago`;const o=`0${n.getMinutes()}`.slice(-2);return`${n.getDate()} ${d[n.getMonth()]} ${n.getFullYear()}, ${n.getHours()}:${o}`}function y(e){const t={};return p.forEach(({name:n,type:i})=>{const o=function(e,t){switch(e){case"size":{if(null==t||""===t)return null;const e=Number(t);return Number.isFinite(e)?`${e}px`:null}case"number":{const e=parseFloat(String(t));return Number.isFinite(e)?String(e):null}default:{const e=String(t??"").trim();return e&&!w.test(e)?e:null}}}(i,e[n]);null!==o&&(t[`--${l}-${n}`]=o)}),t}const C=/^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;function v(e){return"string"==typeof e&&C.test(e)?e:void 0}const _=l,k=[...p],M=["badgeBgColor","badgeTextColor"],W=k.filter(e=>-1!==M.indexOf(e.name)),j={enable:!1,triggerId:"pwInbox",position:"bottom",appendTo:"body",...c};function I(e){let t="fixed"===window.getComputedStyle(e).position;return!t&&e.parentElement&&(t=I(e.parentElement)),t}var S=r(247),E=r(524),R=r(873);const T={display:"flex",flexDirection:"column",gap:8,marginTop:8,minWidth:0},B={flex:"none",width:"100%",minWidth:0,height:28,padding:"0 8px",border:"none",borderRadius:6,fontFamily:"inherit",fontSize:12,fontWeight:500,lineHeight:"28px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"};function N(e){const{buttons:t,variant:n,renderText:i=e=>e,onButtonClick:o}=e,r=function(e){return(e??[]).map((e,t)=>({button:e,index:t})).filter(({button:e})=>"string"==typeof e.text&&!!e.text.trim()).slice(0,3)}(t);if(!r.length)return null;const s="preview"===n;return(0,S.jsx)("div",{className:"pw-inbox_buttons",style:s?T:void 0,children:r.map(({button:e,index:t})=>{const n=v(e.bgColor),r=v(e.textColor),a=v(e.borderColor),l=a?{boxShadow:`inset 0 0 0 1px ${a}`}:{},d=s?{...B,background:n??"transparent",color:r??(n?"#FFFFFF":"#00A2FF"),...l}:{background:n,color:r,...l};return(0,S.jsx)("button",{type:"button",className:n?"pw-inbox_button":"pw-inbox_button pw-inbox_button--link",style:d,onClick:e=>{e.stopPropagation(),o?.(t)},children:i(e.text)},t)})})}function O(e){return t=>{t.stopPropagation(),e?.()}}function A({slides:e,alt:t,onSlideLinkClick:n}){const[i,o]=(0,R.useState)(0),r=Math.min(i,e.length-1),s=e[r],a=s.link?O(()=>n?.(s.link)):void 0;return(0,S.jsxs)("div",{className:"pw-inbox_media",children:[(0,S.jsxs)("div",{className:"pw-inbox_slide",onClick:a,children:[(0,S.jsx)("img",{alt:s.caption||t,className:"pw-inbox_hero",src:s.imageUrl}),!!s.caption&&(0,S.jsx)("span",{className:"pw-inbox_slide-caption",children:s.caption})]}),e.length>1&&(0,S.jsx)("div",{className:"pw-inbox_pager",children:e.map((e,t)=>(0,S.jsx)("button",{className:t===r?"pw-inbox_dot pw-active":"pw-inbox_dot",onClick:O(()=>o(t)),type:"button"},t))})]})}function L({url:e,alt:t,placeholder:n}){return(0,S.jsx)("div",{className:"pw-inbox_media",children:n?(0,S.jsx)("div",{className:"pw-inbox_hero pw-inbox_hero--placeholder"}):(0,S.jsx)("img",{alt:t,className:"pw-inbox_hero",src:e})})}function z(e){const{content:t,layout:n,title:i,body:o,timeLabel:r,isRead:s,isActionPerformed:a,code:l,placeholder:d,onClick:p,onRemove:c,onSlideLinkClick:g,onButtonClick:h}=e,w=(0,S.jsx)(N,{variant:"widget",buttons:t.buttons,onButtonClick:h}),m=t.title||t.body||"",f=(0,S.jsxs)("div",{className:"pw-inbox_content",children:[(0,S.jsxs)("div",{className:"pw-inbox_item-title",children:[i,!s&&(0,S.jsx)("span",{className:"pw-inbox_unread-dot"})]}),(0,S.jsx)("div",{className:"pw-inbox_item-body",children:o}),w,(0,S.jsx)("div",{className:"pw-inbox_item-time",children:r})]});let y,C;"carousel"!==n||d?"classic"!==n&&(y=(0,S.jsx)(L,{alt:m,placeholder:d,url:b(t)})):y=(0,S.jsx)(A,{alt:m,onSlideLinkClick:g,slides:x(t.carousel)}),C=d?(0,S.jsx)("div",{className:"pw-inbox_icon pw-inbox_icon--placeholder"}):(0,S.jsx)("div",{className:"pw-inbox_icon",children:t.iconUrl?(0,S.jsx)("img",{alt:m,className:"pw-inbox_message-image",src:t.iconUrl}):(0,S.jsx)("span",{className:"pw-inbox_icon-initial",children:u(t)})});const v=["pw-inbox_item",!s&&"pw-new",!a&&"pw-unread"].filter(Boolean).join(" ");return(0,S.jsxs)("li",{className:v,"data-pw-inbox-message-id":l,onClick:p,children:[(0,S.jsxs)("div",{className:`pw-inbox_item-inner pw-inbox_item--${n}`,children:["classic"===n?C:y,"banner"===n?w:f]}),(0,S.jsx)("span",{className:"pw-inbox_item-remove",onClick:O(c)})]})}function P({messages:e,appearance:t,now:n,onMessageClick:i,onMessageRemove:o,onSlideLinkClick:r,onButtonClick:s}){return 0===e.length?(0,S.jsxs)("div",{className:"pw-inbox_list--empty",children:[(0,S.jsx)("div",{className:"pw-inbox_list-icon",children:(0,S.jsx)("img",{alt:t.emptyInboxTitle,src:t.emptyInboxIconUrl})}),(0,S.jsx)("div",{className:"pw-inbox_list-title",children:t.emptyInboxTitle}),(0,S.jsx)("div",{className:"ipw-inbox_list-body",children:t.emptyInboxText})]}):(0,S.jsxs)("div",{className:"pw-inbox_inner",children:[(0,S.jsx)("div",{className:"pw-inbox_title",children:t.title}),(0,S.jsx)("ul",{className:"pw-inbox_list",children:e.map(e=>(0,S.jsx)(z,{body:e.body,code:e.code,content:e,isActionPerformed:e.isActionPerformed,isRead:e.isRead,layout:m(e),onClick:()=>i?.(e.code),onRemove:()=>o?.(e.code),onSlideLinkClick:t=>r?.(e.code,t),onButtonClick:t=>s?.(e.code,t),timeLabel:f(e.sendDate,n),title:e.title},e.code))})]})}function H(e){const{mode:t,messages:n,now:i,onMessageClick:o,onMessageRemove:r,onSlideLinkClick:s,onButtonClick:a}=e,l=function(e){const{borderColor:t}=e||{};return{...c,arrowBorderColor:t&&"transparent"!==t?t:c.arrowBorderColor,...e}}(e.appearance),d=(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("style",{children:"\n.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(--pw-inbox-badgeBgColor, #ff4c00);\n border-radius: 8px;\n color: var(--pw-inbox-badgeTextColor, #ffffff);\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(--pw-inbox-fontFamily, inherit);\n}\n.pw-inbox-widget {\n font-size: 14px;\n position: absolute;\n top: 0;\n left: -1000px;\n background: var(--pw-inbox-bgColor, #ffffff);\n border: solid 1px var(--pw-inbox-borderColor, transparent);\n border-radius: var(--pw-inbox-borderRadius, 4px);\n width: var(--pw-inbox-widgetWidth, 350px);\n box-shadow: 0 1px 4px 0 rgba(0,0,0,.25);\n z-index: var(--pw-inbox-zIndex, 100);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-arrowBorderColor, rgba(0,0,0,.1));\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(--pw-inbox-bgColor, #ffffff);\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(--pw-inbox-textColor, #333333);\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(--pw-inbox-avatarSize, 52px);\n height: var(--pw-inbox-avatarSize, 52px);\n margin-right: 14px;\n overflow: hidden;\n border-radius: var(--pw-inbox-mediaRadius, 8px);\n background: var(--pw-inbox-avatarBgColor, #c4c8cc);\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(--pw-inbox-avatarTextColor, #4b5057);\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(--pw-inbox-messageTitleColor, #7a7a7a);\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(--pw-inbox-unreadDotColor, #00a2ff);\n}\n.pw-inbox_item-body {\n color: var(--pw-inbox-textColor, #333333);\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(--pw-inbox-timeTextColor, #c4c4c4);\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(--pw-inbox-textColor, #333333);\n font-weight: 700;\n}\n\n.pw-inbox_buttons {\n display: flex;\n flex-direction: column;\n gap: 8px;\n margin-top: 8px;\n min-width: 0;\n}\n\n.pw-inbox_button {\n flex: none;\n width: 100%;\n min-width: 0;\n height: 28px;\n padding: 0 8px;\n border: none;\n border-radius: 6px;\n background: transparent;\n color: #ffffff;\n font-family: inherit;\n font-size: 12px;\n font-weight: 500;\n line-height: 28px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n cursor: pointer;\n}\n\n.pw-inbox_button--link {\n color: #00a2ff;\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(--pw-inbox-emptyInboxTitleColor, #333333);\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(--pw-inbox-emptyInboxTextColor, #7a7a7a);\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: 2 / 1;\n object-fit: cover;\n border-radius: var(--pw-inbox-mediaRadius, 8px);\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(--pw-inbox-slideCaptionColor, #ffffff);\n font-size: 14px;\n line-height: 20px;\n border-radius: 0 0 var(--pw-inbox-mediaRadius, 8px) var(--pw-inbox-mediaRadius, 8px);\n background: linear-gradient(transparent, var(--pw-inbox-slideScrimColor, rgba(0,0,0,.45)));\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(--pw-inbox-pagerDotColor, #ebf0f5);\n cursor: pointer;\n}\n.pw-inbox_dot.pw-active {\n background: var(--pw-inbox-pagerDotActiveColor, #00a2ff);\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\n.pw-inbox-widget.pw-inbox-widget--preview {\n position: relative;\n top: auto;\n left: auto;\n max-width: 100%;\n opacity: 1;\n transition: none;\n}\n.pw-inbox-widget--preview .pw-inbox__arrow {\n display: none;\n}\n.pw-inbox-widget--cell .pw-inbox_item {\n padding: 16px;\n}\n.pw-inbox_icon--placeholder {\n border: 1px dashed #00a2ff;\n background: #80b7ff33;\n}\n.pw-inbox_hero--placeholder {\n border: 1px dashed #00a2ff;\n background: #80b7ff33;\n}\n"}),(0,S.jsx)("div",{className:"pw-inbox__arrow"}),(0,S.jsx)(P,{appearance:l,messages:n,now:i,onMessageClick:o,onMessageRemove:r,onSlideLinkClick:s,onButtonClick:a})]});if("live"===t)return d;const p=function(e,t){return{className:["pw-inbox-widget pw-inbox-widget--preview",t,e.legacyClassicCell&&"pw-inbox-widget--legacy-cell"].filter(Boolean).join(" "),style:y(e)}}(l,0===n.length?"pw-inbox-widget--empty":void 0);return(0,S.jsx)("div",{className:p.className,style:p.style,children:d})}const $=e=>({code:e.code,title:e.title,body:e.message,iconUrl:e.iconUrl,bannerUrl:e.heroUrl,layoutType:e.layout,carousel:e.carousel,buttons:(e.buttons||[]).map(e=>({text:e.title,textColor:e.textColor,bgColor:e.bgColor,borderColor:e.borderColor,action:e.action,url:e.url,copyText:e.copyText,data:e.data})),sendDate:e.sendDate,isRead:e.isRead,isActionPerformed:e.isActionPerformed}),D="#333",F=/[;{}]/;let Y=null;function X(e,t){switch(e){case"size":{const e=Number(t??0);return Number.isFinite(e)?`${e}px`:null}case"number":{const e=parseFloat(String(t));return Number.isFinite(e)?String(e):null}case"color":{const e=String(t);return function(e){return F.test(e)?D:(Y||(Y=document.createElement("div")),Y.style.color="",Y.style.color=e,Y.style.color?e:D)}(e)===e?e:null}default:return String(t).trim()||null}}function U(e,t,n,i){n.forEach(({name:n,type:o})=>{const r=X(o,i[n]);null!==r&&e.style.setProperty(function(e,t){return`--${e}-${t}`}(t,n),r)})}const q=/^(?:javascript|vbscript|data|blob|file):/i;function V(e){return e.split("").filter(e=>e.charCodeAt(0)>32&&127!==e.charCodeAt(0)).join("")}function J(e){return!!e&&!q.test(V(e))}class G{constructor(e){this.lastSyncAt=0,this.pw=e;const t=this.pw.initParams.inboxWidget;this.config={...j,arrowBorderColor:t.borderColor&&"transparent"!==t.borderColor?t.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(){!1!==this.pw.initParams.inboxWidget?.enable&&(this.initTrigger(),this.updateInbox(),this.addListeners())}toggle(e){(void 0===e?!this.isOpened:e)?this.openWidget():this.closeWidget()}initTrigger(){if(!this.pw.pwinbox)throw new Error("Web inbox is not allowed.");const e=document.getElementById(this.config.triggerId);if(!e)throw new Error(`Pushwoosh: inbox trigger element #${this.config.triggerId} is not on the page. Add it, or change Trigger ID in the Pushwoosh Control Panel or inboxWidget.triggerId in the snippet.`);this.trigger=e,this.trigger.classList.add("pw-inbox-trigger"),this.lastSyncAt=Date.now(),this.defaultMargin=12,this.messagesElements={},this.messages=[],this.readItems=[],this.updateCounter(0),this.isOpened=!1,this.renderWidget(),this.isFixed=I(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.applyStyleVariables(),this.renderWidgetInner()}applyStyleVariables(){U(this.widget,_,k,this.config),U(this.trigger,_,W,this.config)}renderWidgetInner(){var e,t,n,i;this.widget.classList.toggle("pw-inbox-widget--empty",0===this.messages.length),e=this.widget,t=this.messages,n=this.config,i={onMessageClick:e=>this.performMessageAction(e),onMessageRemove:e=>this.removeMessages([e]),onButtonClick:(e,t)=>this.performButtonAction(e,t),onSlideLinkClick:(e,t)=>{J(t)?document.location.href=t:this.performMessageAction(e)}},(0,E.render)((0,S.jsx)(H,{mode:"live",messages:t.map($),appearance:n,onMessageClick:i.onMessageClick,onMessageRemove:i.onMessageRemove,onSlideLinkClick:i.onSlideLinkClick,onButtonClick:i.onButtonClick}),e),this.list=this.widget.querySelector(".pw-inbox_list")||document.createElement("ul"),this.messagesElements={},this.widget.querySelectorAll("[data-pw-inbox-message-id]").forEach(e=>{this.messagesElements[e.getAttribute("data-pw-inbox-message-id")||""]=e})}updateCounter(e){this.count=e,this.trigger.setAttribute("data-pw-count",`${this.count}`),this.trigger.classList.toggle("pw-empty",0===this.count)}updateInboxMessages(e){this.messages=e.sort(({sendDate:e},{sendDate:t})=>{return n=e,new Date(t).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:e}=this.config;this.widgetParent.style.position="relative",this.widget.classList.add("pw-inbox-widget--inset"),this.widget.classList.add(`pw-${e}`)}defaultPlaceWidget(){const e=this.pw.initParams.inboxWidget.position?this.config.position:this.getDefaultPosition(),t=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(t.width+2*this.defaultMargin>n&&(this.widget.style.width=n-2*this.defaultMargin+"px"),t.height+24>i&&(this.widget.style.height=i-2*this.defaultMargin+"px"),e){case"top":this.alignWidgetTop();break;case"right":this.alignWidgetRight();break;case"left":this.alignWidgetLeft();break;case"bottom":this.alignWidgetBottom()}}alignWidgetTop(){const e=this.trigger.getBoundingClientRect(),t=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+e.left+Math.floor(e.width/2)-Math.floor(t.width/2);const r=o<pageXOffset,s=o+t.width>pageXOffset+n;r&&(o=pageXOffset+this.defaultMargin),s&&(o=pageXOffset+n-t.width-this.defaultMargin);const a=pageYOffset+e.top-t.height;this.alignWidgetElement(o,a),i.style.left=e.left+Math.floor(e.width/2)-o+"px";const l=this.widget.getBoundingClientRect().top;if(l<0){const e=this.widget.getBoundingClientRect().height+l-this.defaultMargin,t=this.widget.getBoundingClientRect().top-l+this.defaultMargin;this.widget.style.height=`${e}px`,this.widget.style.top=`${t}px`}}alignWidgetRight(){const e=this.trigger.getBoundingClientRect(),t=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 r=pageYOffset+e.top+Math.floor(e.height/2)-Math.floor(t.height/2);const s=r<pageYOffset,a=pageYOffset+i<r+t.height;s&&(r=pageYOffset+this.defaultMargin),a&&(r=pageYOffset+i-t.height-this.defaultMargin);const l=pageXOffset+e.left+e.width;this.alignWidgetElement(l,r),o.style.top=e.top+Math.floor(e.height/2)-r+"px";const d=n-this.widget.getBoundingClientRect().right;if(d<this.defaultMargin){const e=this.widget.getBoundingClientRect().width+d-this.defaultMargin;this.widget.style.width=`${e}px`}}alignWidgetLeft(){const e=this.trigger.getBoundingClientRect(),t=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+e.top+Math.floor(e.height/2)-Math.floor(t.height/2);const r=o<pageYOffset,s=pageYOffset+n<o+t.height;r&&(o=pageYOffset+this.defaultMargin),s&&(o=pageYOffset+n-t.height-this.defaultMargin);const a=pageXOffset+e.left-t.width;this.alignWidgetElement(a,o),i.style.top=e.top+Math.floor(e.height/2)-o+"px";const l=this.widget.getBoundingClientRect().left;if(l<0){const e=this.widget.getBoundingClientRect().width+l-this.defaultMargin,t=this.widget.getBoundingClientRect().left-l;this.widget.style.width=`${e}px`,this.widget.style.left=`${t}px`}}alignWidgetBottom(){const e=this.trigger.getBoundingClientRect(),t=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 r=pageXOffset+e.left+Math.floor(e.width/2)-Math.floor(t.width/2);const s=r<pageXOffset,a=r+t.width>pageXOffset+n;s&&(r=pageXOffset+this.defaultMargin),a&&(r=pageXOffset+n-t.width-12);const l=pageYOffset+e.top+e.height;this.alignWidgetElement(r,l),o.style.left=e.left+Math.floor(e.width/2)-r+"px";const d=i-this.widget.getBoundingClientRect().bottom;if(d<this.defaultMargin){const e=this.widget.getBoundingClientRect().height+d-this.defaultMargin;this.widget.style.height=`${e}px`}}alignWidgetElement(e,t){this.widget.style.left=`${e}px`,this.widget.style.top=`${t}px`}getDefaultPosition(){const{left:e,top:t,width:n,height:i}=this.trigger.getBoundingClientRect();if(!document.documentElement)return"";const o={right:e,bottom:t,left:Math.max(document.documentElement.clientWidth,window.innerWidth||0)-(e+n),top:Math.max(document.documentElement.clientHeight,window.innerHeight||0)-(t+i)},r=Math.min(e,t,o.left,o.top);let s="bottom";return Object.keys(o).forEach(e=>{o[e]===r&&(s=e)}),s}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 e=this.list.clientHeight+this.list.scrollTop-50;Object.keys(this.messagesElements).forEach(t=>{if(!this.messagesElements[t]||this.messagesElements[t].offsetTop>e)return;const n=this.messages.find(e=>e.code===t);!n||n.isRead||this.readItems.indexOf(t)+1||this.readItems.push(t)})}updateReadStatus(){const e=this.readItems;this.readItems=[],this.pw.pwinbox.readMessagesWithCodes(e).then(this.updateInbox)}syncMessages(){Date.now()-this.lastSyncAt<3e4||(this.lastSyncAt=Date.now(),this.pw.pwinbox.syncMessages().catch(e=>{console.error("Pushwoosh: cannot refresh the inbox on open",e)}))}updateInbox(){this.pw.pwinbox.loadMessages().then(e=>{this.updateInboxMessages(e)}),this.pw.pwinbox.unreadMessagesCount().then(e=>{this.updateCounter(e)})}performMessageAction(e){const t=this.messages.find(t=>t.code===e);t&&t.webPopupCode&&this.toggle(!1),this.pw.pwinbox.performActionForMessageWithCode(e).then(()=>{this.updateInbox()})}async performButtonAction(e,t){const n=this.messages.find(t=>t.code===e),i=n?.buttons?.[t];if(!i)return;const o=this.pw.pwinbox.reportButtonClick(e,i.id).catch(e=>console.error("Pushwoosh: cannot report the inbox button click",e));switch("custom"!==i.action&&Object.keys(i.data).length>0&&this.pw.dispatchEvent("click-inbox-button",{messageCode:e,buttonId:i.id,data:i.data}),i.action){case"open":if(i.url&&J(i.url))return await o,void(document.location.href=i.url);break;case"copy":this.copyText(i.copyText);break;default:this.pw.dispatchEvent("click-inbox-button",{messageCode:e,buttonId:i.id,data:i.data})}await o,this.updateInbox()}copyText(e){e&&navigator.clipboard&&navigator.clipboard.writeText(e).then(()=>this.showToast("Copied")).catch(e=>console.error("Pushwoosh: cannot copy the inbox button text",e))}showToast(e){const t=document.createElement("div");t.className="pw-inbox_toast",t.setAttribute("role","status"),t.textContent=e,Object.assign(t.style,{position:"fixed",left:"50%",bottom:"24px",transform:"translateX(-50%)",padding:"8px 16px",borderRadius:"6px",background:"rgba(0, 0, 0, 0.8)",color:"#fff",fontFamily:"inherit",fontSize:"13px",zIndex:String(Number(this.config.zIndex)+1)}),document.body.appendChild(t),setTimeout(()=>t.remove(),1500)}removeMessages(e){this.readItems=this.readItems.filter(t=>-1===e.indexOf(t)),this.pw.pwinbox.deleteMessagesWithCodes(e).then(()=>{this.updateInbox()})}onTriggerClickHandler(e){e.stopPropagation(),e.target&&this.toggle()}onWidgetClickHandler(e){e.target&&(e.target.closest(".pw-inbox_item")||this.toggle())}onWindowScrollHandler(){this.isFixed&&this.isOpened?this.toggle():this.positionWidget()}}return s})());
|
|
2
2
|
//# sourceMappingURL=widget-inbox.js.map
|