web-push-notifications 3.75.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.
@@ -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,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,MAEzBC,MAAO,WACPC,SAAU,QAGCC,EAAoB,iHAMpBC,EAAo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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,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SACH,OAAOxH,KAAKyD,OAAO0D,EAAMpE,MAAMyE,WACjC,IAAK,QACH,ODpMsBa,ECoMDrI,KAAKyD,OAAO0D,EAAMpE,MAAMyE,WDnM/CtE,EAAcoF,KAAKD,GACdpF,GAGJE,IACHA,EAAQ6C,SAASe,cAAc,QAGjC5D,EAAMgE,MAAMkB,MAAQ,GACpBlF,EAAMgE,MAAMkB,MAAQA,EAEblF,EAAMgE,MAAMkB,MAAQA,EAAQpF,GCyL/B,QACE,MAAO,ODtMR,IAAuBoF,CCwM5B,CAEA,cAAAH,CAAeK,GACb,IAAIC,EAAeD,EAAOf,WAS1B,OAPA1E,EAAc2F,QAAStB,IACrB,MAAMuB,EAAW,IAAIC,OAAO,WAAWxB,EAAMpE,UAAW,MAClD6F,EAAS5I,KAAKmI,kBAAkBhB,GAEtCqB,EAAeA,EAAaK,QAAQH,EAAUE,KAGzCJ,CACT,CAEA,YAAAP,GACE,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":""}
@@ -6,4 +6,3 @@ export declare const MILLISECONDS_IN_HOUR: number;
6
6
  export declare const MONTHS: string[];
7
7
  export declare const CONFIG_STYLES: Array<IConfigStyles>;
8
8
  export declare const DEFAULT_CONFIG: IInboxWidgetConfig;
9
- export declare const COLOR_TEST_REGEXP: RegExp;
@@ -1,4 +1,3 @@
1
1
  export declare function isElementFixed(element: HTMLElement): boolean;
2
2
  export declare function getMessageTime(date: string): string;
3
- export declare function getValidColor(color: string): string;
4
3
  export declare function compareBySendDate(dateOne: string, dateTwo: string): number;
@@ -1,6 +1,5 @@
1
1
  import { type ISubscribePopupConfig, type ISubscribePopupConfigStyles } from './types/subscribe-popup';
2
2
  export declare const DEFAULT_CONFIG: ISubscribePopupConfig;
3
- export declare const COLOR_TEST_REGEXP: RegExp;
4
3
  export declare const PERMISSION_DENIED = "denied";
5
4
  export declare const PERMISSION_GRANTED = "granted";
6
5
  export declare const CONFIG_STYLES: Array<ISubscribePopupConfigStyles>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare function getValidColor(color: string): string;