web-push-notifications 3.89.0 → 3.90.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-push-notifications",
3
- "version": "3.89.0",
3
+ "version": "3.90.1",
4
4
  "description": "Pushwoosh web push notifications",
5
5
  "main": "npm.js",
6
6
  "types": "npm.d.ts",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "homepage": "https://github.com/Pushwoosh/web-push-notifications#readme",
35
35
  "dependencies": {
36
- "@pushwoosh/websdk-common": "^6.17.0",
36
+ "@pushwoosh/websdk-common": "^6.18.0",
37
37
  "preact": "^10.0.0"
38
38
  },
39
39
  "devDependencies": {
package/service-worker.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var a in s)("object"==typeof exports?exports:e)[a]=s[a]}}(this,()=>(()=>{"use strict";const e="deviceRegistrationStatus",t="registered",s="unregistered";function a(e,t){if("string"==typeof e)try{return JSON.parse(e)}catch(e){console.log(e)}return void 0===e&&void 0!==t?t:e}function i(){return crypto.randomUUID?.()||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}const r=e=>"function"==typeof e,n="keyValue",o="messages",c="inboxMessages";function u(e,t){return function(s){s.objectStoreNames.contains(e)||t(s)}}const h=[u(n,function(e){e.createObjectStore(n,{keyPath:"key"})}),u("log",function(e){const t=e.createObjectStore("log",{keyPath:"id",autoIncrement:!0});t.createIndex("environment","environment",{unique:!1}),t.createIndex("date","date",{unique:!1}),t.createIndex("type","type",{unique:!1})}),u(o,function(e){e.createObjectStore(o,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}),u(c,function(e){const t="status",s=e.createObjectStore(c,{keyPath:"inbox_id",autoIncrement:!1});s.createIndex(t,t,{unique:!1,multiEntry:!0}),s.createIndex("rt","rt",{unique:!1,multiEntry:!0})})];class d{get all(){return h}}class l{constructor(e,t=new d){this.db=e,this.migrationsBuilder=t}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.all)}applyMigrationsPack(e){e.forEach(e=>{e(this.db)})}}function g(e,t){console.info("onversionchange",t),e.close()}let p;function m(){return p||(p=new Promise((e,t)=>{const s=indexedDB.open("PUSHWOOSH_SDK_STORE",7);s.onsuccess=s=>{const a=s.target.result;a.onversionchange=g.bind(null,a,t),e(a)},s.onerror=()=>t(s.error),s.onupgradeneeded=e=>{const s=e.target.result;s.onversionchange=g.bind(null,s,t);new l(s).applyMigrations()}})),p}function w(e){return m().then(t=>new Promise((s,a)=>e(t,s,a)))}class y{_add(e){return w((t,s,a)=>{const i=t.transaction([this.name],"readwrite").objectStore(this.name).add(e);i.onsuccess=()=>{s(e)},i.onerror=()=>{a(i.error)}}).then(e=>this.getAll().then(t=>{if(Array.isArray(t)){const s=t.map(e=>e.id).sort((e,t)=>e==t?0:e<t?1:-1);if(s.length>this.maxItems)return Promise.all(s.slice(this.maxItems).map(e=>this.delete(e))).then(()=>e)}return e}))}delete(e){return w((t,s,a)=>{const i=t.transaction([this.name],"readwrite").objectStore(this.name).delete(e);i.onsuccess=()=>{s(i.result)},i.onerror=()=>{a(i.error)}})}getAll(){return w((e,t,s)=>{const a=[],i=e.transaction(this.name).objectStore(this.name).openCursor();i.onsuccess=e=>{const s=e.target.result;s?(s.value&&a.push(s.value),s.continue()):t(a)},i.onerror=()=>{s(i.error)}})}}const b=(f=n,{get:(e,t)=>w((s,a,i)=>{const r=s.transaction(f).objectStore(f).get(e);let n,o=!1,c=!1;const u=()=>{clearTimeout(n),o?a(r.result?.value||t):c?i(r.error):n=setTimeout(u,0)};r.onsuccess=()=>o=!0,r.onerror=()=>c=!0,u()}),getAll:()=>w((e,t,s)=>{const a={},i=e.transaction(f).objectStore(f).openCursor();let r,n=!1,o=!1;const c=()=>{clearTimeout(r),n?t(a):o?s(i.error):r=setTimeout(c,0)};i.onsuccess=e=>{const t=e.target.result;t?(a[t.key]=t.value.value,t.continue()):n=!0},i.onerror=()=>o=!0,c()}),async extend(e,t){const s=await this.get(e),{...a}=t;await this.set(e,{...s,...a})},set:(e,t)=>w((s,a,i)=>{const r=s.transaction([f],"readwrite").objectStore(f).put({key:e,value:t});let n,o=!1,c=!1;const u=()=>{clearTimeout(n),o?a(e):c?i(r.error):n=setTimeout(u,0)};r.onsuccess=()=>o=!0,r.onerror=()=>c=!0,u()})});var f;const v=new class extends y{constructor(){super(...arguments),this.name="log",this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(e,t,s){const a={type:e,environment:this.environment,message:`${t}`,date:new Date};return t instanceof Error&&(a.stack=t.stack),s&&(a.additional=s),this._add(a)}},C=new class extends y{constructor(){super(...arguments),this.name=o,this.maxItems=25}add(e){return this._add({...e,date:new Date})}},S={error:1,info:2,debug:3};let x=3;const P={setLevel(e){S[e]||(e="error"),x=S[e]},write(e,t,s){return"error"===e?this.error(t):this.info(t),v.add(e,t,s)}};Object.keys(S).forEach(e=>{const t=S[e];P[e]=(...s)=>{t<=x&&(console.groupCollapsed(e),console.info("",...s),console.trace("trace"),console.groupEnd())}});const D="silent",I="fatal",k="error",T="warn",M="info",E="debug",R={[D]:0,[I]:10,[k]:20,[T]:30,[M]:40,[E]:50};function A(e){const{code:t,text:s,type:a}=e,i=function(e){switch(e){case"fatal":case"error":return console.error;case"warn":case"info":case"debug":return console.log}}(a);console.groupCollapsed(a),i(t?`${t}: ${s}`:s),console.groupEnd()}const W=new class{constructor(e){this.relations=R,this.level=e&&void 0!==e.level?e.level:"error",this.applicationType=e&&void 0!==e.applicationType?e.applicationType:"sdk",this.subscribers=e&&void 0!==e.subscribers?e.subscribers:[]}updateLogLevel(e){this.level=e}updateApplicationType(e){this.applicationType=e}updateApplicationCode(e){this.applicationCode=e}updateDomain(e){this.domain=e}updateDeviceInfo(e){this.deviceInfo=e}subscribe(e,t){this.subscribers.push({handler:t,level:e})}async log(e){const t=[],{options:s,...a}=e;let i=a;if(s){const{handler:e,...t}=s;i={...a,...t}}const r=this.getMessage(i);this.subscribers.forEach(s=>{s.level===e.type&&this.relations[s.level]<=this.relations[this.level]&&t.push(s.handler.call(null,r))}),s&&s.handler&&"silent"!==this.level&&s.handler.call(null,r),await Promise.all(t)}async debug(e,t){return this.log({type:"debug",text:e,options:t})}async info(e,t){return this.log({type:"info",text:e,options:t})}async warn(e,t,s){return this.log({type:"warn",text:e,code:t,options:s})}async error(e,t,s){return this.log({type:"error",text:e,code:t,options:s})}async fatal(e,t,s){return this.log({type:"fatal",text:e,code:t,options:s})}async errorAndThrow(e,t,s){return this.logAndThrow({type:"error",text:e,code:t,options:s})}async errorAndReject(e,t,s,a){return this.logAndReject(e,{type:"error",text:t,code:s,options:a})}async fatalAndThrow(e,t,s){return this.logAndThrow({type:"fatal",text:e,code:t,options:s})}async fatalAndReject(e,t,s,a){return this.logAndReject(e,{type:"fatal",text:t,code:s,options:a})}async logAndThrow(e){await this.log(e);const t=new Error(e.text);throw e.code&&(t.code=e.code),t}async logAndReject(e,t){await this.log(t);const s=new Error(t.text);t.code&&(s.code=t.code),e(s)}getMessage(e){return{applicationCode:this.applicationCode,domain:this.domain,applicationType:this.applicationType,deviceInfo:this.deviceInfo,...e}}}({level:"error",subscribers:[{level:"fatal",handler:A},{level:"error",handler:A}]});async function _(e){const t=q(e);return W.fatal(t.text,t.code,t.options)}function q(e){const{message:t,code:s,error:a,...i}=e,r=function(e){let t=new Error("unknown error");"string"!=typeof e&&"number"!=typeof e&&"boolean"!=typeof e||(t.message=e.toString());e instanceof Error&&(t=e);return t}(a);return{text:t,code:s,options:{...i,errorText:r.message,errorStack:r.stack}}}class N{constructor(e=new Date){this._date=e}set date(e){this._date=e}get date(){return this._date}getUtcTimestamp(){return Math.floor((this.date.getTime()+60*this.date.getTimezoneOffset()*1e3)/1e3)}getTimestamp(){return Math.round(this.date.getTime()/1e3)}setLocal(){const e=this._date.getTime()-60*this.date.getTimezoneOffset()*1e3;this._date=new Date(e)}addDays(e){const t=this._date.getTime()+24*e*60*60*1e3;this._date=new Date(t)}getInboxFakeOrder(){return(100*this._date.getTime()+9e9).toString()}}const L=/^(?:javascript|vbscript|data|blob|file):/i,U=/^[a-z][a-z\d+\-.]*:/i;function O(e){return e.split("").filter(e=>e.charCodeAt(0)>32&&127!==e.charCodeAt(0)).join("")}function j(e){const t=O(e);return U.test(t)&&!L.test(t)}const B=["classic","captioned","banner","carousel"];function V(e){const t=["displayType","carousel","image"];return Object.keys(e).filter(e=>-1===t.indexOf(e)).reduce((t,s)=>(t[s]=e[s],t),{})}class F{constructor(e,t,s,a={},i=new N){this.data=e,this.api=t,this.inboxModel=s,this.moduleRegistry=a,this.dateModule=i,this.publicMessageBuilder=this.publicMessageBuilder.bind(this)}parseActionParams(e){try{return JSON.parse(e)||{}}catch(t){return P.write("error",`Pushwoosh: cannot parse inbox action_params: ${e}`,t),{}}}messageTypeFactory(e,t){let s=0;return 2===e?s=1:"l"in t&&null!=t.l&&(s=t.l.startsWith("http")?2:3),s}async updateMessagesStatusWithCodes(e,t,s){const a=[],i=[];t.forEach(async t=>{-1!==e.indexOf(t.inbox_id)&&(t.status=s,a.push(t),i.push(this.api.inboxStatus(t.order,t.status)))}),await this.inboxModel.putBulkMessages(a),await Promise.all(i)}async publicMessageBuilder({action_type:e,action_params:t,image:s,title:a,send_date:i,inbox_id:r,text:n,status:o}){const c=this.parseActionParams(t),u=function(e){const t=e?.u;if(!t)return{};if("string"==typeof t)try{return JSON.parse(t)||{}}catch{return{}}return"object"==typeof t?t:{}}(c),h=function(e){return(Array.isArray(e.carousel)?e.carousel:[]).filter(e=>!!e&&!!e.image).slice(0,5).map(e=>({imageUrl:e.image,caption:e.title||"",link:e.url&&j(e.url)?e.url:""}))}(u),d=function(e,t,s){return e?.b||s||t.image||""}(c,u,s),l=function(e){const{hasTitle:t,hasBody:s,heroUrl:a,bannerUrl:i,slidesCount:r}=e;let n=e.displayType;switch(-1===B.indexOf(n)&&(n=i&&!t?"banner":i&&t&&s?"captioned":"classic"),n){case"banner":return a?"banner":"classic";case"captioned":return a&&t&&s?"captioned":"classic";case"carousel":return t&&s&&r>0?"carousel":"classic";default:return"classic"}}({displayType:u.displayType,hasTitle:!!a,hasBody:!!n,heroUrl:d,bannerUrl:c.b||"",slidesCount:h.length}),g=function(e,t){return t||e.image||""}(u,s)||await this.data.getDefaultNotificationImage(),p=a||await this.data.getDefaultNotificationTitle();return this.dateModule.date=new Date(1e3*parseInt(i)),{title:p,imageUrl:g,iconUrl:g,heroUrl:d,layout:l,carousel:h,customData:V(u),webPopupCode:c.wp||"",code:r,message:n,sendDate:this.dateModule.date.toISOString(),type:this.messageTypeFactory(e,c),link:c?.l||"/",isRead:2===o||3===o,isActionPerformed:3===o}}messagesWithNoActionPerformedCount(){return this.inboxModel.getDeliveredReadMessagesCount()}unreadMessagesCount(){return this.inboxModel.getDeliveredMessagesCount()}messagesCount(){return this.inboxModel.messagesCount()}async loadMessages(){const e=[...await this.inboxModel.getReadOpenMessages(),...await this.inboxModel.getDeliveredMessages()].sort((e,t)=>parseInt(t.send_date,10)-parseInt(e.send_date,10)).sort((e,t)=>parseInt(t.order||"0",10)-parseInt(e.order||"0",10)).map(this.publicMessageBuilder);return Promise.all(e)}async readMessagesWithCodes(e){const t=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(e,t,2)}async performActionForMessageWithCode(e){const t=await this.inboxModel.getMessage(e),s=this.parseActionParams(t.action_params),a=this.messageTypeFactory(t.action_type,s),i=2===a||3===a;var r;!await this.showWebPopup(s.wp)&&i&&null!=s.l&&((r=s.l)&&!L.test(O(r)))&&(document.location.href=s.l),t.status=3,await this.inboxModel.putMessage(t),await this.api.inboxStatus(t.order,t.status)}async showWebPopup(e){if(!e)return!1;const{webPopups:t}=this.moduleRegistry;return t?t.show(e):(P.write("error",`Pushwoosh: inbox message opens web popup "${e}", but the web popups widget is not initialized`),!1)}async deleteMessagesWithCodes(e){const t=await this.inboxModel.getReadOpenMessages(),s=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(e,[...t,...s],4)}async syncMessages(){await this.api.ensureDeviceRegistered(),await this.inboxModel.updateMessages()}}class H{constructor(e,t){this.name=t,this.store=e.transaction(this.name,"readwrite").objectStore(this.name)}set index(e){this.store.indexNames.contains(e)?this._index=this.store.index(e):console.warn(`Index "${e}" in `)}writeRequestPromise(e,t){return new Promise((s,a)=>{e.onsuccess=()=>{s(t)},e.onerror=()=>{a(e.error)}})}readRequestPromise(e,t){return new Promise((s,a)=>{e.onsuccess=e=>{const a=e.target;s(a.result||t)},e.onerror=()=>{a(e.error)}})}put(e,t){const s=this.store.put(e,t);return this.writeRequestPromise(s,t)}add(e,t){return this.put(e,t)}delete(e){const t=this.store.delete(e);return this.writeRequestPromise(t)}get(e,t){const s=this.store.get(e);return this.readRequestPromise(s,t)}getAll(){const e=this.store.openCursor(),t=[];return new Promise((s,a)=>{e.onsuccess=e=>{const a=e.target.result;a?(t.push(a.value),a.continue()):s(t)},e.onerror=()=>{a(e.error)}})}count(e){const t=this.store.count(e);return this.readRequestPromise(t,0)}countByIndex(e){const t=this._index.count(e);return this.readRequestPromise(t,0)}}class ${getDB(){return m()}async put(e,t,s){const a=await this.getDB();return new H(a,e).put(t,s)}async delete(e,t){const s=await this.getDB();return new H(s,e).delete(t)}async get(e,t,s){const a=await this.getDB();return new H(a,e).get(t,s)}async getAll(e){const t=await this.getDB(),s=new H(t,e);return await s.getAll()||[]}async count(e,t){const s=await this.getDB();return new H(s,e).count(t)}async countByIndex(e,t,s){const a=await this.getDB(),i=new H(a,e);return i.index=t,i.countByIndex(s)}}class K{constructor(e,t,s,a=new $,i=new N){this.eventBus=e,this.data=t,this.api=s,this.storage=a,this.storeName="inboxMessages",this.dateModule=i}async getInboxMessages(){const e=await this.api.getInboxMessages();return await this.storeGetInboxMessagesRequestParams(e.next,e.new_inbox),e}async storeGetInboxMessagesRequestParams(e,t){this.dateModule.date=new Date,await this.data.setInboxLastRequestTime(this.dateModule.getUtcTimestamp()),await this.data.setInboxLastRequestCode(e),await this.data.setInboxNewMessagesCount(t)}async putServerMessages(e){const t=e.map(async e=>{const t=await this.storage.get(this.storeName,e.inbox_id,{});return"status"in t&&(e.status=t.status),this.putMessage(e)});return Promise.all(t)}putMessage(e){return this.storage.put(this.storeName,e)}putBulkMessages(e){const t=e.map(e=>this.putMessage(e));return Promise.all(t)}deleteMessages(e){const t=e.map(e=>this.storage.delete(this.storeName,e));return Promise.all(t)}async deleteExpiredMessages(){this.dateModule.date=new Date;const e=this.dateModule.getTimestamp().toString(),t=(await this.storage.getAll(this.storeName)).filter(t=>t.rt<e).map(e=>e.inbox_id);return this.deleteMessages(t)}getMessage(e){return this.storage.get(this.storeName,e)}async getReadOpenMessages(){return(await this.storage.getAll(this.storeName)).filter(e=>2===e.status||3===e.status)}async getDeliveredMessages(){return(await this.storage.getAll(this.storeName)).filter(e=>1===e.status)}async messagesCount(){return this.storage.count(this.storeName)}async getDeliveredMessagesCount(){return this.storage.countByIndex(this.storeName,"status",1)}async getReadMessagesCount(){return this.storage.countByIndex(this.storeName,"status",2)}async getDeliveredReadMessagesCount(){const[e,t]=[2,3],s=IDBKeyRange.bound(e,t);return this.storage.countByIndex(this.storeName,"status",s)}async updateMessages(){const e=await this.getInboxMessages();await this.deleteExpiredMessages(),e.deleted&&await this.deleteMessages(e.deleted),await this.putServerMessages(e.messages),this.eventBus.dispatchEvent("update-inbox-messages",{messages:new F(this.data,this.api,this)})}}const z={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},J=/&(?:amp|lt|gt|quot|#39);/g,G=RegExp(J.source);const Y=e=>`params.${e}`;class Q{constructor(e=b){this.store=e}async clearAll(){const e=["applicationCode","apiToken","hwid","deviceType","deviceModel","language","languageWasChanged","apiEntrypoint","tokens","applicationServerKey","isVapidChanged","webSitePushId","defaultNotificationImage","defaultNotificationTitle","userId","userIdWasChanged","email","emailWasChanged","isLastPermissionStatus","isManualUnsubscribed","isCommunicationDisabled","communicationEnabled","isDropAllData","sdkVersion","serviceWorkerVersion","serviceWorkerUrl","serviceWorkerScope","lastOpenMessage","lastOpenApplicationTime","features","init","inbox.lastRequestCode","inbox.lastRequestTime","inbox.newMessagesCount","delayedEvent","promptDisplayCount","promptLastSeenTime","logLevel","shownWebPopups","isRecurringVisitor"];for(const t of e)await this.store.set(Y(t),void 0)}async setApplicationCode(e){await this.store.set(Y("applicationCode"),e)}async getApplicationCode(){return this.store.get(Y("applicationCode"))}async setApiToken(e){return await this.store.set(Y("apiToken"),e)}async getApiToken(){return this.store.get(Y("apiToken"))}async setHwid(e){await this.store.set(Y("hwid"),e)}async getHwid(){return this.store.get(Y("hwid"))}async setDeviceType(e){await this.store.set(Y("deviceType"),e)}async getDeviceType(){return this.store.get(Y("deviceType"))}async setFormFactor(e){await this.store.set(Y("formFactor"),e)}async getFormFactor(){return this.store.get(Y("formFactor"))}async setDeviceModel(e){await this.store.set(Y("deviceModel"),e)}async getDeviceModel(){return this.store.get(Y("deviceModel"))}async setLanguage(e){await this.store.set(Y("language"),e)}async getLanguage(){return this.store.get(Y("language"),"en")}async setStatusLanguageWasChanged(e){await this.store.set(Y("languageWasChanged"),e)}async getStatusLanguageWasChanged(){return this.store.get(Y("languageWasChanged"),!1)}async setApiEntrypoint(e){await this.store.set(Y("apiEntrypoint"),e)}async getApiEntrypoint(){return this.store.get(Y("apiEntrypoint"),"https://api.pushwoosh.com/json/1.3/")}async setTokens(e){await this.store.set(Y("tokens"),e)}getTokens(){return this.store.get(Y("tokens"))}async setApplicationServerKey(e){await this.store.set(Y("applicationServerKey"),e)}async getApplicationServerKey(){return this.store.get(Y("applicationServerKey"))}async setIsVapidChanged(e){await this.store.set(Y("isVapidChanged"),e)}async getIsVapidChanged(){return this.store.get(Y("isVapidChanged"),!1)}async setWebSitePushId(e){await this.store.set(Y("webSitePushId"),e)}async getWebSitePushId(){return this.store.get(Y("webSitePushId"))}async setDefaultNotificationImage(e){await this.store.set(Y("defaultNotificationImage"),e)}async getDefaultNotificationImage(){return this.store.get(Y("defaultNotificationImage"),"https://cp.pushwoosh.com/img/logo-medium.png")}async setDefaultNotificationTitle(e){await this.store.set(Y("defaultNotificationTitle"),e)}async getDefaultNotificationTitle(){return this.store.get(Y("defaultNotificationTitle"),"Pushwoosh notification")}async setUserId(e){await this.store.set(Y("userId"),e?`${e}`:void 0)}async getUserId(){return this.store.get(Y("userId"))}async setStatusUserIdWasChanged(e){await this.store.set(Y("userIdWasChanged"),e)}async getStatusUserIdWasChanged(){return this.store.get(Y("userIdWasChanged"),!1)}async setEmail(e){await this.store.set(Y("email"),e?`${e}`:void 0)}async getEmail(){return this.store.get(Y("email"))}async setStatusEmailWasChanged(e){await this.store.set(Y("emailWasChanged"),e)}async getStatusEmailWasChanged(){return this.store.get(Y("emailWasChanged"),!1)}async setSmsNumber(e){await this.store.set(Y("smsNumber"),e?`${e}`:void 0)}async getSmsNumber(){return this.store.get(Y("smsNumber"))}async setStatusSmsNumberWasChanged(e){await this.store.set(Y("smsNumberWasChanged"),e)}async getStatusSmsNumberWasChanged(){return this.store.get(Y("smsNumberWasChanged"),!1)}async setWhatsAppNumber(e){await this.store.set(Y("whatsAppNumber"),e?`${e}`:void 0)}async getWhatsAppNumber(){return this.store.get(Y("whatsAppNumber"))}async setStatusWhatsAppNumberWasChanged(e){await this.store.set(Y("whatsAppNumberWasChanged"),e)}async getStatusWhatsAppNumberWasChanged(){return this.store.get(Y("whatsAppNumberWasChanged"),!1)}async setLastPermissionStatus(e){await this.store.set(Y("isLastPermissionStatus"),e)}async getLastPermissionStatus(){return this.store.get(Y("isLastPermissionStatus"))}async setStatusManualUnsubscribed(e){await this.store.set(Y("isManualUnsubscribed"),e)}getStatusManualUnsubscribed(){return this.store.get(Y("isManualUnsubscribed"),!1)}async setStatusCommunicationDisabled(e){await this.store.set(Y("isCommunicationDisabled"),e)}getStatusCommunicationDisabled(){return this.store.get(Y("isCommunicationDisabled"),!1)}async setCommunicationEnabled(e){await this.store.set(Y("communicationEnabled"),e)}getCommunicationEnabled(){return this.store.get(Y("communicationEnabled"))}async setStatusDropAllData(e){await this.store.set(Y("isDropAllData"),e)}getStatusDropAllData(){return this.store.get(Y("isDropAllData"),!1)}async setSdkVersion(e){await this.store.set(Y("sdkVersion"),e)}async getSdkVersion(){return this.store.get(Y("sdkVersion"))}async setServiceWorkerVersion(e){await this.store.set(Y("serviceWorkerVersion"),e)}getServiceWorkerVersion(){return this.store.get(Y("serviceWorkerVersion"))}async setServiceWorkerUrl(e){e&&await this.store.set(Y("serviceWorkerUrl"),e)}async getServiceWorkerUrl(){return this.store.get(Y("serviceWorkerUrl"),"/pushwoosh-service-worker.js")}async setServiceWorkerScope(e){e&&await this.store.set(Y("serviceWorkerScope"),e)}async getServiceWorkerScope(){return this.store.get(Y("serviceWorkerScope"))}async setLastOpenMessage(e){await this.store.set(Y("lastOpenMessage"),e)}getLastOpenMessage(){return this.store.get(Y("lastOpenMessage"))}async setLastOpenApplicationTime(e){await this.store.set(Y("lastOpenApplicationTime"),e)}async getLastOpenApplicationTime(){return this.store.get(Y("lastOpenApplicationTime"))}async setFeatures(e){await this.store.set(Y("features"),e)}async getFeatures(){return this.store.get(Y("features"))}async setInitParams(e){await this.store.set(Y("init"),e)}async getInitParams(){return this.store.get(Y("init"))}async setInboxLastRequestCode(e){await this.store.set(Y("inbox.lastRequestCode"),e)}async getInboxLastRequestCode(){return this.store.get(Y("inbox.lastRequestCode"),"")}async setInboxLastRequestTime(e){await this.store.set(Y("inbox.lastRequestTime"),e)}async getInboxLastRequestTime(){return this.store.get(Y("inbox.lastRequestTime"),0)}async setInboxNewMessagesCount(e){await this.store.set(Y("inbox.newMessagesCount"),e)}async getInboxNewMessagesCount(){return this.store.get(Y("inbox.newMessagesCount"),0)}async setDelayedEvent(e){await this.store.set(Y("delayedEvent"),e)}getDelayedEvent(){return this.store.get(Y("delayedEvent"))}async setPromptDisplayCount(e){await this.store.set(Y("promptDisplayCount"),e)}async getPromptDisplayCount(){return this.store.get(Y("promptDisplayCount"),0)}async setPromptLastSeenTime(e){await this.store.set(Y("promptLastSeenTime"),e)}async getPromptLastSeenTime(){return this.store.get(Y("promptLastSeenTime"),0)}async setSubscriptionWidgetHistory(e){await this.store.set(Y("subscriptionWidgetHistory"),e)}async getSubscriptionWidgetHistory(){return this.store.get(Y("subscriptionWidgetHistory"),{shownCount:0,lastShownAt:null})}async setLogLevel(e){await this.store.set(Y("logLevel"),e)}async getLogLevel(){return this.store.get(Y("logLevel"),"error")}async getShownWebPopups(){return this.store.get(Y("shownWebPopups"),[])}async addShownWebPopup(e){const t=await this.getShownWebPopups();t.includes(e)||(t.push(e),await this.store.set(Y("shownWebPopups"),t))}async setIsRecurringVisitor(e){await this.store.set(Y("isRecurringVisitor"),e)}async getIsRecurringVisitor(){return this.store.get(Y("isRecurringVisitor"),!1)}}class X{constructor(e,t=new Q,s=new N){if("data"in e){const t=e;this.payload=t.data}else this.payload=e;this.data=t,this.code=`notificationCode-${Date.now()}-${Math.random().toString(16).slice(2,10)}`,this.dateModule=s}async getIcon(){return this.payload.i||await this.data.getDefaultNotificationImage()}async getTitle(){return this.payload.header||await this.data.getDefaultNotificationTitle()}get silent(){return Boolean(this.payload.silent)}get body(){return this.payload.body}get messageHash(){return this.payload.p||""}get metaData(){return this.payload.md?a(this.payload.md):{}}get image(){return this.payload.image||""}get buttons(){return this.payload.buttons?a(this.payload.buttons):[]}get customData(){return this.payload.u?a(this.payload.u):{}}get campaignCode(){return this.payload.pwcid||""}get link(){return this.payload.l?(e=this.payload.l)&&G.test(e)?e.replace(J,e=>z[e]):e:"/";var e}get inboxId(){return this.payload.pw_inbox||""}get inboxParams(){return this.payload.inbox_params?a(this.payload.inbox_params):{}}get inboxRemovalTime(){return this.inboxParams&&this.inboxParams.rt?this.inboxParams.rt:(this.dateModule.date=new Date,this.dateModule.addDays(1),this.dateModule.getUtcTimestamp().toString())}async getInboxImage(){return this.inboxParams&&this.inboxParams.image?this.inboxParams.image:""}get rootParams(){const{body:e,p:t,header:s,i:a,u:i,l:r,pwcid:n,image:o,buttons:c,pw_inbox:u,inbox_params:h,...d}=this.payload;return d}async getNotificationOptionsPayload(){const e=await this.getTitle(),t=await this.getIcon();return{...this.rootParams,body:this.body,title:e,icon:t,image:this.image,buttons:this.buttons,customData:this.customData,metaData:this.metaData,campaignCode:this.campaignCode,openUrl:this.link,messageHash:this.messageHash}}async getShowNotificationOptions(){const e=await this.getIcon(),t=this.buttons.map((e,t)=>(e.action=`action-${t}`,e));return{renotify:!0,...this.rootParams,body:this.body,icon:e,tag:JSON.stringify({url:this.link,messageHash:this.messageHash,customData:this.customData,metaData:this.metaData}),data:{code:this.code,buttons:t,image:this.image,campaignCode:this.campaignCode,inboxId:this.inboxId},silent:this.silent,actions:t,image:this.image,buttons:t}}async getInboxMessage(){this.dateModule.date=new Date;const e=this.dateModule.getTimestamp().toString();return{title:this.payload.header||"",image:await this.getInboxImage(),status:1,order:this.dateModule.getInboxFakeOrder(),inbox_id:this.inboxId,send_date:e,rt:this.inboxRemovalTime,text:this.body,action_type:1,action_params:JSON.stringify({l:this.link})}}}class Z extends Error{constructor(e,t){super(e),this.name="ApiRequestError",this.statusCode=t}}class ee{constructor(e=new Q,t=P){this.data=e,this.logger=t}checkDevice(e){return this.createRequest("checkDevice",e)}getConfig(e){return this.createRequest("getConfig",e)}getPopupForms(e){return this.createRequest("getPopupForms",e)}getPopupFormContent(e){return this.createRequest("getPopupFormContent",e)}recordPopupFormEvent(e){return this.createRequest("recordPopupFormEvent",e)}applicationOpen(e){return this.createRequest("applicationOpen",e)}registerDevice(e){return this.createRequest("registerDevice",e)}unregisterDevice(e){return this.createRequest("unregisterDevice",e)}deleteDevice(e){return this.createRequest("deleteDevice",e)}messageDeliveryEvent(e){return this.createRequest("messageDeliveryEvent",e)}pushStat(e){return this.createRequest("pushStat",e)}setTags(e){return this.createRequest("setTags",e)}getTags(e){return this.createRequest("getTags",e)}registerUser(e){return this.createRequest("registerUser",e)}registerEmail(e){return this.createRequest("registerEmail",e)}registerEmailUser(e){return this.createRequest("registerEmailUser",e)}setEmailTags(e){return this.createRequest("setEmailTags",e)}postEvent(e){return this.createRequest("postEvent",e)}getInboxMessages(e){return this.createRequest("getInboxMessages",e)}inboxStatus(e){return this.createRequest("inboxStatus",e)}multiRegisterDevice(e){return this.createRequest("multiRegisterDevice",e)}async createRequest(e,t){const s=await this.data.getApiEntrypoint(),a=await this.data.getApiToken(),i=s+e,r=a?{headers:{Authorization:`Token ${a}`,"Content-Type":"text/plain;charset=UTF-8",Origin:globalThis.location.origin},credentials:"include"}:{},n=await fetch(i,{method:"POST",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:JSON.stringify({request:t}),...r}),o=await this.checkResponse(n);return o.base_url&&await this.data.setApiEntrypoint(o.base_url),await this.logger.write("apirequest",`${e} call with arguments: ${JSON.stringify(t)} to Pushwoosh has been successful. Result: ${JSON.stringify(o.response)}`),o.response}async checkResponse(e){if(200!==e.status){let t,s=`status: ${e.status}. statusText: ${e.statusText}.`;try{const a=await e.json();a&&"number"==typeof a.status_code&&(t=a.status_code),a&&a.status_message&&(s+=` status_code: ${a.status_code}. status_message: ${a.status_message}.`)}catch(e){}throw new Z(s,t)}const t=await e.json();if(200!==t.status_code)throw new Z(`Error code: ${t.status_code}. Error text: ${t.status_message}`,"number"==typeof t.status_code?t.status_code:void 0);return t}}class te{constructor(e,t,s){this.api=e,this.data=t,this.config=s}getPermission(){return Notification.permission}checkIsPermissionGranted(){return"granted"===this.getPermission()}checkIsPermissionDefault(){return"default"===this.getPermission()}async checkIsManualUnsubscribed(){return this.data.getStatusManualUnsubscribed()}async askPermission(){await Notification.requestPermission()}async getTokens(){return this.data.getTokens()}async subscribe(e){const t=e||await this.trySubscribe();if(!this.checkIsPermissionGranted())return void P.error("You must have permission granted before subscribe!");const s=this.getPushToken(t),a=t.getKey("p256dh"),i=t.getKey("auth");if(!a||!i)throw new Error("Can't get subscription keys!");const r=btoa(String.fromCharCode.apply(String,new Uint8Array(a))),n=btoa(String.fromCharCode.apply(String,new Uint8Array(i)));await this.data.setTokens({publicKey:r,pushToken:s,authToken:n,endpoint:t.endpoint}),await this.api.registerDevice()}async unsubscribe(){const e=await this.getServiceWorkerRegistration(),t=await e.pushManager.getSubscription();await this.data.setTokens({}),await this.data.setStatusManualUnsubscribed(!0),await this.api.unregisterDevice(),t&&await t.unsubscribe()}async checkIsRegister(){return this.api.checkDeviceSubscribeForPushNotifications()}async checkIsNeedResubscribe(){const e=await this.data.getLastPermissionStatus(),t=this.getPermission();if(e!==t&&(await this.data.setLastPermissionStatus(t),void 0!==e))return!0;const s=await this.getCredentials(),a=this.getPushToken(s),i=await this.data.getTokens(),r=a===(i&&i.pushToken||""),n=await this.data.getIsVapidChanged();return!r||n}async getServiceWorkerRegistration(){if(!this.registration){await this.registerServiceWorker();const e=await this.data.getServiceWorkerUrl();this.registration=await navigator.serviceWorker.getRegistration(e),await this.registration.update()}if(!this.registration)throw new Error("Internal Error: Can't register service worker!");return this.registration}async registerServiceWorker(){const e=await this.data.getServiceWorkerUrl(),t=await this.data.getServiceWorkerScope();let s="";await this.data.getSdkVersion()!==await this.data.getServiceWorkerVersion()&&(s=`?cache_clean=${i()}`),await navigator.serviceWorker.register(`${e}${s}`,{scope:t})}async trySubscribe(){try{return await this.subscribePushManager()}catch(e){return console.error(e),await this.unsubscribe(),this.subscribePushManager()}}async subscribePushManager(){const e=await this.getServiceWorkerRegistration(),t=await this.getApplicationServerKey();return e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:t?this.urlBase64ToUint8Array(t):null})}async getCredentials(){const e=await this.getServiceWorkerRegistration();return await e.pushManager.getSubscription()}getPushToken(e){return e?e.endpoint:""}async getApplicationServerKey(){return await this.data.getApplicationServerKey()}urlBase64ToUint8Array(e){const t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),s=atob(t),a=new Uint8Array(s.length);for(let e=0;e<s.length;++e)a[e]=s.charCodeAt(e);return a}}class se{constructor(e,t,s){this._canceled=!1,this.showNotificationOptions=e,this.body=t,this.title=s}async show(){if(this._canceled)return;const e=this.showNotificationOptions;e.silent||await self.registration.showNotification(this.title,e)}cancel(){this._canceled=!0}}const ae=new class{constructor(){this.addEventHandler=(e,t)=>{let s=this.handlers[e];s||(s=[]),s.push(t),this.handlers[e]=s},this.removeEventHandler=(e,t)=>{const s=this.handlers[e];s&&(this.handlers[e]=s.filter(e=>e!==t))},this.dispatchEvent=(e,t)=>{const s=t.eventId||i(),a=this.handlers[e];return a?(a.forEach(e=>{r(e)&&setTimeout(()=>{e({...t,eventId:s})},0)}),s):s},this.handlers={}}},ie=new Q,re=new class{constructor(e,t=new Q,s=new ee,a=()=>!1,i=()=>{}){this.ensureDeviceRegisteredPromise=null,this.checkDevicePromise=null,this.eventBus=e,this.data=t,this.apiClient=s,this.getIsCommunicationDisabled=a,this.getInitUserId=i}async checkDevice(){return this.checkDevicePromise||(this.checkDevicePromise=this.requestCheckDevice().catch(e=>{throw this.checkDevicePromise=null,e})),this.checkDevicePromise}async requestCheckDevice(){const e=await this.getRequestParams();return await this.apiClient.checkDevice(e)}async checkDeviceSubscribeForPushNotifications(a=!0){let i=localStorage.getItem(e);if(null===i||!a){const{exist:a,push_token_exist:r}=await this.checkDevice();localStorage.setItem(e,a&&r?t:s),i=localStorage.getItem(e)}return i===t}async ensureDeviceRegistered(){return!this.getIsCommunicationDisabled()&&(this.ensureDeviceRegisteredPromise||(this.ensureDeviceRegisteredPromise=this.registerDeviceIfNotExist().catch(e=>{throw this.ensureDeviceRegisteredPromise=null,e})),this.ensureDeviceRegisteredPromise)}async registerDeviceIfNotExist(){const{exist:e}=await this.checkDevice();return!e&&(await this.apiClient.registerDevice(await this.getRequestParams()),this.checkDevicePromise=null,!0)}async getConfig(e){const t=await this.getRequestParams();return this.apiClient.getConfig({...t,features:e})}async applicationOpen(){const e=await this.getRequestParams();return await this.data.setLastOpenApplicationTime(Date.now()),this.apiClient.applicationOpen(e)}async registerDevice(){if(await this.data.getStatusCommunicationDisabled())throw new Error("Can't register device: Communication is disabled!");const s=await this.getRequestParams(),a=await this.data.getTokens();if(!a.pushToken)throw new Error("Can't register device: pushToken is not exist!");const i=await this.apiClient.registerDevice({...s,push_token:a.pushToken,auth_token:a.authToken,public_key:a.publicKey});return this.checkDevicePromise=null,await this.data.setStatusManualUnsubscribed(!1),localStorage.setItem(e,t),this.eventBus.dispatchEvent("register",{}),i}async unregisterDevice(){const t=await this.getRequestParams(),a=await this.apiClient.unregisterDevice(t);return this.checkDevicePromise=null,localStorage.setItem(e,s),this.eventBus.dispatchEvent("unsubscribe",{}),a}async deleteDevice(){const t=await this.getRequestParams(),a=await this.apiClient.deleteDevice(t);return this.checkDevicePromise=null,await this.data.setStatusManualUnsubscribed(!0),localStorage.setItem(e,s),this.eventBus.dispatchEvent("unsubscribe",{}),a}async messageDeliveryEvent(e,t,s={}){const a=await this.getRequestParams();return await this.apiClient.messageDeliveryEvent({...a,hash:e,metaData:s})}async pushStat(e,t,s={}){const a=await this.getRequestParams();return await this.apiClient.pushStat({...a,hash:e,metaData:s})}async setTags(e){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const{hwid:t,device_type:s,...a}=await this.getRequestParams(),i=await this.data.getEmail();return i&&await this.apiClient.setEmailTags({...a,email:i,tags:e}),this.apiClient.setTags({...a,hwid:t,device_type:s,tags:e})}async getTags(){const e=await this.getRequestParams();return this.apiClient.getTags(e)}async setLanguage(e){return this.getIsCommunicationDisabled()?Promise.reject(new Error("Communication is disabled")):(await this.data.setLanguage(e),await this.data.setStatusLanguageWasChanged(!0),this.setTags({Language:e}))}async registerUser(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const{hwid:s,device_type:a,...i}=await this.getRequestParams(),r=await this.data.getDeviceType(),n=`${e}`,o=await this.apiClient.registerUser({...i,hwid:s,userId:n,ts_offset:60*-(new Date).getTimezoneOffset(),device_type:r});return await this.data.setUserId(n),t&&await this.data.setStatusUserIdWasChanged(!0),o}async registerEmail(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));if(!/^\S+@\S+\.\S+$/.test(e))return Promise.reject(new Error("Invalid Email format"));const s=await this.getIdentityRequestParams(),a=await this.apiClient.registerEmail({...s,email:e,ts_offset:60*-(new Date).getTimezoneOffset()});return await this.data.setEmail(e),t&&await this.data.setStatusEmailWasChanged(!0),a}async registerSmsNumber(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));if(!/^\+?[0-9]+$/.test(e))return Promise.reject(new Error("Invalid Phone number format: +1234567890"));const{application:s,userId:a}=await this.getIdentityRequestParams(),i=await this.apiClient.registerDevice({application:s,userId:a,hwid:e,device_type:18});return await this.data.setSmsNumber(e),t&&await this.data.setStatusSmsNumberWasChanged(!0),i}async registerWhatsappNumber(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));if(!/^(whatsapp:)?\+?[0-9]+$/.test(e))return Promise.reject(new Error("Invalid WhatsApp number format: +1234567890"));const{application:s,userId:a}=await this.getIdentityRequestParams(),i=await this.apiClient.registerDevice({application:s,userId:a,hwid:e,device_type:21});return await this.data.setWhatsAppNumber(e),t&&await this.data.setStatusWhatsAppNumberWasChanged(!0),i}async getPopupForms(){if(this.getIsCommunicationDisabled())return[];return(await this.apiClient.getPopupForms(await this.getRequestParams())).popup_forms??[]}async getPopupFormContent(e){return this.getIsCommunicationDisabled()?Promise.reject(new Error("Communication is disabled")):this.apiClient.getPopupFormContent({...await this.getRequestParams(),code:e})}async recordPopupFormEvent(e,t){return this.getIsCommunicationDisabled()?Promise.reject(new Error("Communication is disabled")):this.apiClient.recordPopupFormEvent({...await this.getRequestParams(),code:e,event:t})}async postEvent(e,t){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const s=await this.getRequestParams(),a=new Date,i=a.getTime(),r=Math.floor(i/1e3),n=r-a.getTimezoneOffset()/60*3600,o=await this.data.getLastOpenMessage();if(o&&o.expiry>Date.now()){if(t.msgHash)return Promise.reject(new Error("attribute msgHash already defined"));t={...t,msgHash:o.messageHash}}await this.data.setLastOpenMessage(void 0);const c=await this.apiClient.postEvent({...s,event:e,timestampUTC:r,timestampCurrent:n,attributes:t});return c&&c.code&&this.eventBus.dispatchEvent("receive-in-app-code",{code:c.code}),c}async getInboxMessages(e=0){const t=await this.getRequestParams(),s=await this.data.getInboxLastRequestCode(),a=await this.data.getInboxLastRequestTime();return this.apiClient.getInboxMessages({...t,count:e,last_code:s,last_request_time:a})}async inboxStatus(e,t){const s=await this.getRequestParams();return this.apiClient.inboxStatus({...s,inbox_code:e,status:t,time:(new Date).getTime()})}async multiRegisterDevice(s){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const a=await this.data.getApplicationCode(),i=await this.data.getDeviceModel(),r=await this.data.getDeviceType(),n=await this.data.getLanguage(),o=await this.data.getSdkVersion(),c=await this.data.getTokens(),u=await this.data.getHwid();!s.push_devices&&c.pushToken&&await this.requireHwid();const h={application:a,...s};if(s.user_id){h.user_id=String(s.user_id);await this.data.getUserId()!==h.user_id&&(await this.data.setUserId(h.user_id),await this.data.setStatusUserIdWasChanged(!0))}if(s.email){if(!/^\S+@\S+\.\S+$/.test(s.email))return Promise.reject(new Error("Invalid Email format"));await this.data.getEmail()!==s.email&&(await this.data.setEmail(s.email),await this.data.setStatusEmailWasChanged(!0))}if(s.sms_phone_number){if(!/^\+?[0-9]+$/.test(s.sms_phone_number))return Promise.reject(new Error("Invalid Phone number format: +1234567890"));await this.data.getSmsNumber()!==s.sms_phone_number&&(await this.data.setSmsNumber(s.sms_phone_number),await this.data.setStatusSmsNumberWasChanged(!0))}if(s.whatsapp_phone_number){if(!/^(whatsapp:)?\+?[0-9]+$/.test(s.whatsapp_phone_number))return Promise.reject(new Error("Invalid WhatsApp number format: +1234567890"));await this.data.getWhatsAppNumber()!==s.whatsapp_phone_number&&(await this.data.setWhatsAppNumber(s.whatsapp_phone_number),await this.data.setStatusWhatsAppNumberWasChanged(!0))}if(h.language?(await this.data.setLanguage(h.language),await this.data.setStatusLanguageWasChanged(!0)):h.language=n,!h.timezone){const e=60*-(new Date).getTimezoneOffset();h.timezone=String(e)}if(!h.push_devices&&c.pushToken){const e={hwid:u,platform:r,push_token:c.pushToken,sdk_version:o};if(c.publicKey||c.authToken||i){const t={};c.publicKey&&(t.public_key=c.publicKey),c.authToken&&(t.auth_token=c.authToken),i&&(t.browser=i),e.platformData=t}h.push_devices=[e]}const d=await this.apiClient.multiRegisterDevice(h);return h.push_devices?.length&&(this.checkDevicePromise=null,await this.data.setStatusManualUnsubscribed(!1),localStorage.setItem(e,t),this.eventBus.dispatchEvent("register",{})),d}async getParams(){return{applicationCode:await this.data.getApplicationCode(),hwid:await this.data.getHwid(),...await this.data.getTokens(),...await this.data.getInitParams()}}async getRequestParams(){const e=await this.requireHwid(),t=await this.data.getDeviceType();return{...await this.getIdentityRequestParams(),hwid:e,device_type:t}}async getIdentityRequestParams(){const e=await this.data.getApplicationCode(),t=await this.data.getHwid(),s=await this.data.getUserId()||this.getInitUserId(),a=await this.data.getDeviceModel(),i=await this.data.getLanguage(),r=await this.data.getSdkVersion(),n=60*-(new Date).getTimezoneOffset();if(!s&&!t)throw new Error("Pushwoosh: neither a userId nor an hwid is available, so there is nothing to register the email, SMS or WhatsApp channel to. Pass a userId in the init params.");return{application:e,userId:s||t,device_model:a,timezone:n,language:i,v:r}}async requireHwid(){const e=await this.data.getHwid();if(!e)throw new Error("Pushwoosh: the SDK storage does not keep the hwid in this browser (in-app webview, private window or insecure context), so this device cannot be identified. Requests that need an hwid are not sent.");return e}}(ae,ie);ie.getLogLevel().then(e=>{e&&P.setLevel(e)});const ne=self.Pushwoosh=new class{constructor(e,t,s){this._listeners={},this.eventBus=e,this.data=t,this.api=s}push(e){Array.isArray(e)&&"onPush"===e[0]&&r(e[1])&&(this._listeners[e[0]]||(this._listeners[e[0]]=[]),this._listeners[e[0]].push(e[1]))}getListeners(e){return this._listeners[e]||[]}async initApi(){return Promise.resolve()}}(ae,ie,re),oe=[];async function ce(e){(await self.clients.matchAll()).forEach(t=>t.postMessage(e))}async function ue(e){const{notification:t={}}=e,{data:s}=t,i=a(t.tag,{});let r="";if(e.action&&Array.isArray(s.buttons)){r=(s.buttons.find(t=>t.action===e.action)||{}).url}else r=i.url;return{title:t.title,body:t.body,icon:t.icon,buttons:s.buttons,image:s.image,code:s.code,campaignCode:s.campaignCode,inboxId:s.inboxId,messageHash:i.messageHash,customData:i.customData,metaData:i.metaData,openUrl:i.url,tag:t.tag,url:r}}async function he(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onInstallEventHandler",code:"FATAL-SW-001",error:e,applicationCode:t,workerVersion:s})}async function de(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onActivateEventHandler",code:"FATAL-SW-002",error:e,applicationCode:t,workerVersion:s})}async function le(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onNotificationClickEventHandler",code:"FATAL-SW-004",error:e,applicationCode:t,workerVersion:s})}async function ge(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onNotificationCloseEventHandler",code:"FATAL-SW-005",error:e,applicationCode:t,workerVersion:s})}async function pe(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onPushSubscriptionChange",code:"FATAL-SW-006",error:e,applicationCode:t,workerVersion:s})}return self.addEventListener("install",function(e){return e.waitUntil(async function(){await Promise.all([ne.data.setServiceWorkerVersion("3.89.0"),P.write("info","install")]),await self.skipWaiting()}().catch(he))}),self.addEventListener("activate",function(e){e.waitUntil(async function(){await Promise.all([P.write("info","activate")]),await self.clients.claim()}().catch(de))}),self.addEventListener("push",function(e){e.waitUntil(async function(e){await self.clients.claim();const t=await e.data.json(),s=new X(t),a=await s.getNotificationOptionsPayload(),i=await s.getShowNotificationOptions(),r=s.messageHash;await P.write("info",JSON.stringify(a),"onPush");const n=new se(i,s.body,await s.getTitle()),o=ne.getListeners("onPush");await o.reduce((e,t)=>e.then(()=>t(n)),Promise.resolve());const c=[n.show(),C.add({payload:t,parsedPayload:a,showOptions:i}),ce({type:"onPushDelivery",payload:a})];if(r&&c.push(ne.initApi().then(()=>ne.api.messageDeliveryEvent(r,!0,a.metaData))),""!==s.inboxId){const e=new K(ne.eventBus,ne.data,ne.api),t=new F(ne.data,ne.api,e),a=await s.getInboxMessage(),i=await t.publicMessageBuilder(a);c.push(e.putMessage(a),ce({type:"onPutNewMessageToInboxStore",payload:i}))}await Promise.all(c)}(e).catch(t=>async function(e,t){const s=await ne.data.getApplicationCode(),a=await ne.data.getServiceWorkerVersion();await _({message:"Error in onPushEventHandler",code:"FATAL-SW-003",error:e,applicationCode:s,workerVersion:a}),e instanceof Error||(e=new Error(e));return C.add({error:`${e}`,stack:e.stack,payload:t.data&&t.data.text()})}(t,e)))}),self.addEventListener("notificationclick",function(e){e.waitUntil(async function(e){await self.clients.claim();const t=await ue(e),{messageHash:s,metaData:a,url:i,code:r,inboxId:n}=t;if(r&&oe.push(r),""!==n){const e=new K(ne.eventBus,ne.data,ne.api),t=await e.getMessage(n);t.status=3,await e.putMessage(t)}e.notification.close();const o={type:"onNotificationClick",payload:t};return i&&e.waitUntil(self.clients.matchAll({type:"window"}).then(e=>async function(e,t){const{hostname:s,pathname:a}=new URL(t,self.location.origin),i=e.find(e=>{const{hostname:t,pathname:i}=new URL(e.url);return t===s&&i===a});return i?(await i.focus(),!1):(await self.clients.openWindow(t).then(e=>{e&&e.focus()}),!0)}(e,i)).then(e=>{e&&ne.data.setDelayedEvent(o)})),Promise.all([ne.initApi().then(()=>ne.api.pushStat(s,!0,a)),ne.data.setLastOpenMessage({url:i,messageHash:s,expiry:Date.now()+864e5}),ce(o)])}(e).catch(le))}),self.addEventListener("notificationclose",function(e){e.waitUntil(async function(e){await self.clients.claim();const t=await ue(e),{code:s}=t;if(e.notification.close(),!s)return;const a=oe.indexOf(s);if(!(a>=0))return ce({type:"onNotificationClose",payload:t});oe.splice(a,1)}(e).catch(ge))}),self.addEventListener("pushsubscriptionchange",async function(e){e.waitUntil(async function(e){let t=e.newSubscription;if(!t&&(t=await self.registration.pushManager.getSubscription(),!t))return;const s=new te(re,ie,{});await s.subscribe(t)}(e).catch(pe))}),{}})());
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var a in s)("object"==typeof exports?exports:e)[a]=s[a]}}(this,()=>(()=>{"use strict";const e="deviceRegistrationStatus",t="registered",s="unregistered";function a(e,t){if("string"==typeof e)try{return JSON.parse(e)}catch(e){console.log(e)}return void 0===e&&void 0!==t?t:e}function i(){return crypto.randomUUID?.()||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}const r=e=>"function"==typeof e,n="keyValue",o="messages",c="inboxMessages";function u(e,t){return function(s){s.objectStoreNames.contains(e)||t(s)}}const h=[u(n,function(e){e.createObjectStore(n,{keyPath:"key"})}),u("log",function(e){const t=e.createObjectStore("log",{keyPath:"id",autoIncrement:!0});t.createIndex("environment","environment",{unique:!1}),t.createIndex("date","date",{unique:!1}),t.createIndex("type","type",{unique:!1})}),u(o,function(e){e.createObjectStore(o,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}),u(c,function(e){const t="status",s=e.createObjectStore(c,{keyPath:"inbox_id",autoIncrement:!1});s.createIndex(t,t,{unique:!1,multiEntry:!0}),s.createIndex("rt","rt",{unique:!1,multiEntry:!0})})];class d{get all(){return h}}class l{constructor(e,t=new d){this.db=e,this.migrationsBuilder=t}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.all)}applyMigrationsPack(e){e.forEach(e=>{e(this.db)})}}function g(e,t){console.info("onversionchange",t),e.close()}let p;function m(){return p||(p=new Promise((e,t)=>{const s=indexedDB.open("PUSHWOOSH_SDK_STORE",7);s.onsuccess=s=>{const a=s.target.result;a.onversionchange=g.bind(null,a,t),e(a)},s.onerror=()=>t(s.error),s.onupgradeneeded=e=>{const s=e.target.result;s.onversionchange=g.bind(null,s,t);new l(s).applyMigrations()}})),p}function w(e){return m().then(t=>new Promise((s,a)=>e(t,s,a)))}class y{_add(e){return w((t,s,a)=>{const i=t.transaction([this.name],"readwrite").objectStore(this.name).add(e);i.onsuccess=()=>{s(e)},i.onerror=()=>{a(i.error)}}).then(e=>this.getAll().then(t=>{if(Array.isArray(t)){const s=t.map(e=>e.id).sort((e,t)=>e==t?0:e<t?1:-1);if(s.length>this.maxItems)return Promise.all(s.slice(this.maxItems).map(e=>this.delete(e))).then(()=>e)}return e}))}delete(e){return w((t,s,a)=>{const i=t.transaction([this.name],"readwrite").objectStore(this.name).delete(e);i.onsuccess=()=>{s(i.result)},i.onerror=()=>{a(i.error)}})}getAll(){return w((e,t,s)=>{const a=[],i=e.transaction(this.name).objectStore(this.name).openCursor();i.onsuccess=e=>{const s=e.target.result;s?(s.value&&a.push(s.value),s.continue()):t(a)},i.onerror=()=>{s(i.error)}})}}const b=(f=n,{get:(e,t)=>w((s,a,i)=>{const r=s.transaction(f).objectStore(f).get(e);let n,o=!1,c=!1;const u=()=>{clearTimeout(n),o?a(r.result?.value||t):c?i(r.error):n=setTimeout(u,0)};r.onsuccess=()=>o=!0,r.onerror=()=>c=!0,u()}),getAll:()=>w((e,t,s)=>{const a={},i=e.transaction(f).objectStore(f).openCursor();let r,n=!1,o=!1;const c=()=>{clearTimeout(r),n?t(a):o?s(i.error):r=setTimeout(c,0)};i.onsuccess=e=>{const t=e.target.result;t?(a[t.key]=t.value.value,t.continue()):n=!0},i.onerror=()=>o=!0,c()}),async extend(e,t){const s=await this.get(e),{...a}=t;await this.set(e,{...s,...a})},set:(e,t)=>w((s,a,i)=>{const r=s.transaction([f],"readwrite").objectStore(f).put({key:e,value:t});let n,o=!1,c=!1;const u=()=>{clearTimeout(n),o?a(e):c?i(r.error):n=setTimeout(u,0)};r.onsuccess=()=>o=!0,r.onerror=()=>c=!0,u()})});var f;const v=new class extends y{constructor(){super(...arguments),this.name="log",this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(e,t,s){const a={type:e,environment:this.environment,message:`${t}`,date:new Date};return t instanceof Error&&(a.stack=t.stack),s&&(a.additional=s),this._add(a)}},C=new class extends y{constructor(){super(...arguments),this.name=o,this.maxItems=25}add(e){return this._add({...e,date:new Date})}},S={error:1,info:2,debug:3};let x=3;const P={setLevel(e){S[e]||(e="error"),x=S[e]},write(e,t,s){return"error"===e?this.error(t):this.info(t),v.add(e,t,s)}};Object.keys(S).forEach(e=>{const t=S[e];P[e]=(...s)=>{t<=x&&(console.groupCollapsed(e),console.info("",...s),console.trace("trace"),console.groupEnd())}});const D="silent",I="fatal",k="error",T="warn",M="info",E="debug",R={[D]:0,[I]:10,[k]:20,[T]:30,[M]:40,[E]:50};function A(e){const{code:t,text:s,type:a}=e,i=function(e){switch(e){case"fatal":case"error":return console.error;case"warn":case"info":case"debug":return console.log}}(a);console.groupCollapsed(a),i(t?`${t}: ${s}`:s),console.groupEnd()}const W=new class{constructor(e){this.relations=R,this.level=e&&void 0!==e.level?e.level:"error",this.applicationType=e&&void 0!==e.applicationType?e.applicationType:"sdk",this.subscribers=e&&void 0!==e.subscribers?e.subscribers:[]}updateLogLevel(e){this.level=e}updateApplicationType(e){this.applicationType=e}updateApplicationCode(e){this.applicationCode=e}updateDomain(e){this.domain=e}updateDeviceInfo(e){this.deviceInfo=e}subscribe(e,t){this.subscribers.push({handler:t,level:e})}async log(e){const t=[],{options:s,...a}=e;let i=a;if(s){const{handler:e,...t}=s;i={...a,...t}}const r=this.getMessage(i);this.subscribers.forEach(s=>{s.level===e.type&&this.relations[s.level]<=this.relations[this.level]&&t.push(s.handler.call(null,r))}),s&&s.handler&&"silent"!==this.level&&s.handler.call(null,r),await Promise.all(t)}async debug(e,t){return this.log({type:"debug",text:e,options:t})}async info(e,t){return this.log({type:"info",text:e,options:t})}async warn(e,t,s){return this.log({type:"warn",text:e,code:t,options:s})}async error(e,t,s){return this.log({type:"error",text:e,code:t,options:s})}async fatal(e,t,s){return this.log({type:"fatal",text:e,code:t,options:s})}async errorAndThrow(e,t,s){return this.logAndThrow({type:"error",text:e,code:t,options:s})}async errorAndReject(e,t,s,a){return this.logAndReject(e,{type:"error",text:t,code:s,options:a})}async fatalAndThrow(e,t,s){return this.logAndThrow({type:"fatal",text:e,code:t,options:s})}async fatalAndReject(e,t,s,a){return this.logAndReject(e,{type:"fatal",text:t,code:s,options:a})}async logAndThrow(e){await this.log(e);const t=new Error(e.text);throw e.code&&(t.code=e.code),t}async logAndReject(e,t){await this.log(t);const s=new Error(t.text);t.code&&(s.code=t.code),e(s)}getMessage(e){return{applicationCode:this.applicationCode,domain:this.domain,applicationType:this.applicationType,deviceInfo:this.deviceInfo,...e}}}({level:"error",subscribers:[{level:"fatal",handler:A},{level:"error",handler:A}]});async function _(e){const t=q(e);return W.fatal(t.text,t.code,t.options)}function q(e){const{message:t,code:s,error:a,...i}=e,r=function(e){let t=new Error("unknown error");"string"!=typeof e&&"number"!=typeof e&&"boolean"!=typeof e||(t.message=e.toString());e instanceof Error&&(t=e);return t}(a);return{text:t,code:s,options:{...i,errorText:r.message,errorStack:r.stack}}}class N{constructor(e=new Date){this._date=e}set date(e){this._date=e}get date(){return this._date}getUtcTimestamp(){return Math.floor((this.date.getTime()+60*this.date.getTimezoneOffset()*1e3)/1e3)}getTimestamp(){return Math.round(this.date.getTime()/1e3)}setLocal(){const e=this._date.getTime()-60*this.date.getTimezoneOffset()*1e3;this._date=new Date(e)}addDays(e){const t=this._date.getTime()+24*e*60*60*1e3;this._date=new Date(t)}getInboxFakeOrder(){return(100*this._date.getTime()+9e9).toString()}}const L=/^(?:javascript|vbscript|data|blob|file):/i,U=/^[a-z][a-z\d+\-.]*:/i;function O(e){return e.split("").filter(e=>e.charCodeAt(0)>32&&127!==e.charCodeAt(0)).join("")}function j(e){const t=O(e);return U.test(t)&&!L.test(t)}const B=["classic","captioned","banner","carousel"];function V(e){const t=["displayType","carousel","image"];return Object.keys(e).filter(e=>-1===t.indexOf(e)).reduce((t,s)=>(t[s]=e[s],t),{})}class F{constructor(e,t,s,a={},i=new N){this.data=e,this.api=t,this.inboxModel=s,this.moduleRegistry=a,this.dateModule=i,this.publicMessageBuilder=this.publicMessageBuilder.bind(this)}parseActionParams(e){try{return JSON.parse(e)||{}}catch(t){return P.write("error",`Pushwoosh: cannot parse inbox action_params: ${e}`,t),{}}}messageTypeFactory(e,t){let s=0;return 2===e?s=1:"l"in t&&null!=t.l&&(s=t.l.startsWith("http")?2:3),s}async updateMessagesStatusWithCodes(e,t,s){const a=[],i=[];t.forEach(async t=>{-1!==e.indexOf(t.inbox_id)&&(t.status=s,a.push(t),i.push(this.api.inboxStatus(t.order,t.status)))}),await this.inboxModel.putBulkMessages(a),await Promise.all(i)}async publicMessageBuilder({action_type:e,action_params:t,image:s,title:a,send_date:i,inbox_id:r,text:n,status:o}){const c=this.parseActionParams(t),u=function(e){const t=e?.u;if(!t)return{};if("string"==typeof t)try{return JSON.parse(t)||{}}catch{return{}}return"object"==typeof t?t:{}}(c),h=function(e){return(Array.isArray(e.carousel)?e.carousel:[]).filter(e=>!!e&&!!e.image).slice(0,5).map(e=>({imageUrl:e.image,caption:e.title||"",link:e.url&&j(e.url)?e.url:""}))}(u),d=function(e,t,s){return e?.b||s||t.image||""}(c,u,s),l=function(e){const{hasTitle:t,hasBody:s,heroUrl:a,bannerUrl:i,slidesCount:r}=e;let n=e.displayType;switch(-1===B.indexOf(n)&&(n=i&&!t?"banner":i&&t&&s?"captioned":"classic"),n){case"banner":return a?"banner":"classic";case"captioned":return a&&t&&s?"captioned":"classic";case"carousel":return t&&s&&r>0?"carousel":"classic";default:return"classic"}}({displayType:u.displayType,hasTitle:!!a,hasBody:!!n,heroUrl:d,bannerUrl:c.b||"",slidesCount:h.length}),g=function(e,t){return t||e.image||""}(u,s)||await this.data.getDefaultNotificationImage(),p=a||await this.data.getDefaultNotificationTitle();return this.dateModule.date=new Date(1e3*parseInt(i)),{title:p,imageUrl:g,iconUrl:g,heroUrl:d,layout:l,carousel:h,customData:V(u),webPopupCode:c.wp||"",code:r,message:n,sendDate:this.dateModule.date.toISOString(),type:this.messageTypeFactory(e,c),link:c?.l||"/",isRead:2===o||3===o,isActionPerformed:3===o}}messagesWithNoActionPerformedCount(){return this.inboxModel.getDeliveredReadMessagesCount()}unreadMessagesCount(){return this.inboxModel.getDeliveredMessagesCount()}messagesCount(){return this.inboxModel.messagesCount()}async loadMessages(){const e=[...await this.inboxModel.getReadOpenMessages(),...await this.inboxModel.getDeliveredMessages()].sort((e,t)=>parseInt(t.send_date,10)-parseInt(e.send_date,10)).sort((e,t)=>parseInt(t.order||"0",10)-parseInt(e.order||"0",10)).map(this.publicMessageBuilder);return Promise.all(e)}async readMessagesWithCodes(e){const t=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(e,t,2)}async performActionForMessageWithCode(e){const t=await this.inboxModel.getMessage(e),s=this.parseActionParams(t.action_params),a=this.messageTypeFactory(t.action_type,s),i=2===a||3===a;var r;!await this.showWebPopup(s.wp)&&i&&null!=s.l&&((r=s.l)&&!L.test(O(r)))&&(document.location.href=s.l),t.status=3,await this.inboxModel.putMessage(t),await this.api.inboxStatus(t.order,t.status)}async showWebPopup(e){if(!e)return!1;const{webPopups:t}=this.moduleRegistry;return t?t.show(e):(P.write("error",`Pushwoosh: inbox message opens web popup "${e}", but the web popups widget is not initialized`),!1)}async deleteMessagesWithCodes(e){const t=await this.inboxModel.getReadOpenMessages(),s=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(e,[...t,...s],4)}async syncMessages(){await this.api.ensureDeviceRegistered(),await this.inboxModel.updateMessages()}}class H{constructor(e,t){this.name=t,this.store=e.transaction(this.name,"readwrite").objectStore(this.name)}set index(e){this.store.indexNames.contains(e)?this._index=this.store.index(e):console.warn(`Index "${e}" in `)}writeRequestPromise(e,t){return new Promise((s,a)=>{e.onsuccess=()=>{s(t)},e.onerror=()=>{a(e.error)}})}readRequestPromise(e,t){return new Promise((s,a)=>{e.onsuccess=e=>{const a=e.target;s(a.result||t)},e.onerror=()=>{a(e.error)}})}put(e,t){const s=this.store.put(e,t);return this.writeRequestPromise(s,t)}add(e,t){return this.put(e,t)}delete(e){const t=this.store.delete(e);return this.writeRequestPromise(t)}get(e,t){const s=this.store.get(e);return this.readRequestPromise(s,t)}getAll(){const e=this.store.openCursor(),t=[];return new Promise((s,a)=>{e.onsuccess=e=>{const a=e.target.result;a?(t.push(a.value),a.continue()):s(t)},e.onerror=()=>{a(e.error)}})}count(e){const t=this.store.count(e);return this.readRequestPromise(t,0)}countByIndex(e){const t=this._index.count(e);return this.readRequestPromise(t,0)}}class ${getDB(){return m()}async put(e,t,s){const a=await this.getDB();return new H(a,e).put(t,s)}async delete(e,t){const s=await this.getDB();return new H(s,e).delete(t)}async get(e,t,s){const a=await this.getDB();return new H(a,e).get(t,s)}async getAll(e){const t=await this.getDB(),s=new H(t,e);return await s.getAll()||[]}async count(e,t){const s=await this.getDB();return new H(s,e).count(t)}async countByIndex(e,t,s){const a=await this.getDB(),i=new H(a,e);return i.index=t,i.countByIndex(s)}}class K{constructor(e,t,s,a=new $,i=new N){this.eventBus=e,this.data=t,this.api=s,this.storage=a,this.storeName="inboxMessages",this.dateModule=i}async getInboxMessages(){const e=await this.api.getInboxMessages();return await this.storeGetInboxMessagesRequestParams(e.next,e.new_inbox),e}async storeGetInboxMessagesRequestParams(e,t){this.dateModule.date=new Date,await this.data.setInboxLastRequestTime(this.dateModule.getUtcTimestamp()),await this.data.setInboxLastRequestCode(e),await this.data.setInboxNewMessagesCount(t)}async putServerMessages(e){const t=e.map(async e=>{const t=await this.storage.get(this.storeName,e.inbox_id,{});return"status"in t&&(e.status=t.status),this.putMessage(e)});return Promise.all(t)}putMessage(e){return this.storage.put(this.storeName,e)}putBulkMessages(e){const t=e.map(e=>this.putMessage(e));return Promise.all(t)}deleteMessages(e){const t=e.map(e=>this.storage.delete(this.storeName,e));return Promise.all(t)}async deleteExpiredMessages(){this.dateModule.date=new Date;const e=this.dateModule.getTimestamp().toString(),t=(await this.storage.getAll(this.storeName)).filter(t=>t.rt<e).map(e=>e.inbox_id);return this.deleteMessages(t)}getMessage(e){return this.storage.get(this.storeName,e)}async getReadOpenMessages(){return(await this.storage.getAll(this.storeName)).filter(e=>2===e.status||3===e.status)}async getDeliveredMessages(){return(await this.storage.getAll(this.storeName)).filter(e=>1===e.status)}async messagesCount(){return this.storage.count(this.storeName)}async getDeliveredMessagesCount(){return this.storage.countByIndex(this.storeName,"status",1)}async getReadMessagesCount(){return this.storage.countByIndex(this.storeName,"status",2)}async getDeliveredReadMessagesCount(){const[e,t]=[2,3],s=IDBKeyRange.bound(e,t);return this.storage.countByIndex(this.storeName,"status",s)}async updateMessages(){const e=await this.getInboxMessages();await this.deleteExpiredMessages(),e.deleted&&await this.deleteMessages(e.deleted),await this.putServerMessages(e.messages),this.eventBus.dispatchEvent("update-inbox-messages",{messages:new F(this.data,this.api,this)})}}const z={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},J=/&(?:amp|lt|gt|quot|#39);/g,G=RegExp(J.source);const Y=e=>`params.${e}`;class Q{constructor(e=b){this.store=e}async clearAll(){const e=["applicationCode","apiToken","hwid","deviceType","deviceModel","language","languageWasChanged","apiEntrypoint","tokens","applicationServerKey","isVapidChanged","webSitePushId","defaultNotificationImage","defaultNotificationTitle","userId","userIdWasChanged","email","emailWasChanged","isLastPermissionStatus","isManualUnsubscribed","isCommunicationDisabled","communicationEnabled","isDropAllData","sdkVersion","serviceWorkerVersion","serviceWorkerUrl","serviceWorkerScope","lastOpenMessage","lastOpenApplicationTime","features","init","inbox.lastRequestCode","inbox.lastRequestTime","inbox.newMessagesCount","delayedEvent","promptDisplayCount","promptLastSeenTime","logLevel","shownWebPopups","isRecurringVisitor"];for(const t of e)await this.store.set(Y(t),void 0)}async setApplicationCode(e){await this.store.set(Y("applicationCode"),e)}async getApplicationCode(){return this.store.get(Y("applicationCode"))}async setApiToken(e){return await this.store.set(Y("apiToken"),e)}async getApiToken(){return this.store.get(Y("apiToken"))}async setHwid(e){await this.store.set(Y("hwid"),e)}async getHwid(){return this.store.get(Y("hwid"))}async setDeviceType(e){await this.store.set(Y("deviceType"),e)}async getDeviceType(){return this.store.get(Y("deviceType"))}async setFormFactor(e){await this.store.set(Y("formFactor"),e)}async getFormFactor(){return this.store.get(Y("formFactor"))}async setDeviceModel(e){await this.store.set(Y("deviceModel"),e)}async getDeviceModel(){return this.store.get(Y("deviceModel"))}async setLanguage(e){await this.store.set(Y("language"),e)}async getLanguage(){return this.store.get(Y("language"),"en")}async setStatusLanguageWasChanged(e){await this.store.set(Y("languageWasChanged"),e)}async getStatusLanguageWasChanged(){return this.store.get(Y("languageWasChanged"),!1)}async setApiEntrypoint(e){await this.store.set(Y("apiEntrypoint"),e)}async getApiEntrypoint(){return this.store.get(Y("apiEntrypoint"),"https://api.pushwoosh.com/json/1.3/")}async setTokens(e){await this.store.set(Y("tokens"),e)}getTokens(){return this.store.get(Y("tokens"))}async setApplicationServerKey(e){await this.store.set(Y("applicationServerKey"),e)}async getApplicationServerKey(){return this.store.get(Y("applicationServerKey"))}async setIsVapidChanged(e){await this.store.set(Y("isVapidChanged"),e)}async getIsVapidChanged(){return this.store.get(Y("isVapidChanged"),!1)}async setWebSitePushId(e){await this.store.set(Y("webSitePushId"),e)}async getWebSitePushId(){return this.store.get(Y("webSitePushId"))}async setDefaultNotificationImage(e){await this.store.set(Y("defaultNotificationImage"),e)}async getDefaultNotificationImage(){return this.store.get(Y("defaultNotificationImage"),"https://cp.pushwoosh.com/img/logo-medium.png")}async setDefaultNotificationTitle(e){await this.store.set(Y("defaultNotificationTitle"),e)}async getDefaultNotificationTitle(){return this.store.get(Y("defaultNotificationTitle"),"Pushwoosh notification")}async setUserId(e){await this.store.set(Y("userId"),e?`${e}`:void 0)}async getUserId(){return this.store.get(Y("userId"))}async setStatusUserIdWasChanged(e){await this.store.set(Y("userIdWasChanged"),e)}async getStatusUserIdWasChanged(){return this.store.get(Y("userIdWasChanged"),!1)}async setEmail(e){await this.store.set(Y("email"),e?`${e}`:void 0)}async getEmail(){return this.store.get(Y("email"))}async setStatusEmailWasChanged(e){await this.store.set(Y("emailWasChanged"),e)}async getStatusEmailWasChanged(){return this.store.get(Y("emailWasChanged"),!1)}async setSmsNumber(e){await this.store.set(Y("smsNumber"),e?`${e}`:void 0)}async getSmsNumber(){return this.store.get(Y("smsNumber"))}async setStatusSmsNumberWasChanged(e){await this.store.set(Y("smsNumberWasChanged"),e)}async getStatusSmsNumberWasChanged(){return this.store.get(Y("smsNumberWasChanged"),!1)}async setWhatsAppNumber(e){await this.store.set(Y("whatsAppNumber"),e?`${e}`:void 0)}async getWhatsAppNumber(){return this.store.get(Y("whatsAppNumber"))}async setStatusWhatsAppNumberWasChanged(e){await this.store.set(Y("whatsAppNumberWasChanged"),e)}async getStatusWhatsAppNumberWasChanged(){return this.store.get(Y("whatsAppNumberWasChanged"),!1)}async setLastPermissionStatus(e){await this.store.set(Y("isLastPermissionStatus"),e)}async getLastPermissionStatus(){return this.store.get(Y("isLastPermissionStatus"))}async setStatusManualUnsubscribed(e){await this.store.set(Y("isManualUnsubscribed"),e)}getStatusManualUnsubscribed(){return this.store.get(Y("isManualUnsubscribed"),!1)}async setStatusCommunicationDisabled(e){await this.store.set(Y("isCommunicationDisabled"),e)}getStatusCommunicationDisabled(){return this.store.get(Y("isCommunicationDisabled"),!1)}async setCommunicationEnabled(e){await this.store.set(Y("communicationEnabled"),e)}getCommunicationEnabled(){return this.store.get(Y("communicationEnabled"))}async setStatusDropAllData(e){await this.store.set(Y("isDropAllData"),e)}getStatusDropAllData(){return this.store.get(Y("isDropAllData"),!1)}async setSdkVersion(e){await this.store.set(Y("sdkVersion"),e)}async getSdkVersion(){return this.store.get(Y("sdkVersion"))}async setServiceWorkerVersion(e){await this.store.set(Y("serviceWorkerVersion"),e)}getServiceWorkerVersion(){return this.store.get(Y("serviceWorkerVersion"))}async setServiceWorkerUrl(e){e&&await this.store.set(Y("serviceWorkerUrl"),e)}async getServiceWorkerUrl(){return this.store.get(Y("serviceWorkerUrl"),"/pushwoosh-service-worker.js")}async setServiceWorkerScope(e){e&&await this.store.set(Y("serviceWorkerScope"),e)}async getServiceWorkerScope(){return this.store.get(Y("serviceWorkerScope"))}async setLastOpenMessage(e){await this.store.set(Y("lastOpenMessage"),e)}getLastOpenMessage(){return this.store.get(Y("lastOpenMessage"))}async setLastOpenApplicationTime(e){await this.store.set(Y("lastOpenApplicationTime"),e)}async getLastOpenApplicationTime(){return this.store.get(Y("lastOpenApplicationTime"))}async setFeatures(e){await this.store.set(Y("features"),e)}async getFeatures(){return this.store.get(Y("features"))}async setInitParams(e){await this.store.set(Y("init"),e)}async getInitParams(){return this.store.get(Y("init"))}async setInboxLastRequestCode(e){await this.store.set(Y("inbox.lastRequestCode"),e)}async getInboxLastRequestCode(){return this.store.get(Y("inbox.lastRequestCode"),"")}async setInboxLastRequestTime(e){await this.store.set(Y("inbox.lastRequestTime"),e)}async getInboxLastRequestTime(){return this.store.get(Y("inbox.lastRequestTime"),0)}async setInboxNewMessagesCount(e){await this.store.set(Y("inbox.newMessagesCount"),e)}async getInboxNewMessagesCount(){return this.store.get(Y("inbox.newMessagesCount"),0)}async setDelayedEvent(e){await this.store.set(Y("delayedEvent"),e)}getDelayedEvent(){return this.store.get(Y("delayedEvent"))}async setPromptDisplayCount(e){await this.store.set(Y("promptDisplayCount"),e)}async getPromptDisplayCount(){return this.store.get(Y("promptDisplayCount"),0)}async setPromptLastSeenTime(e){await this.store.set(Y("promptLastSeenTime"),e)}async getPromptLastSeenTime(){return this.store.get(Y("promptLastSeenTime"),0)}async setSubscriptionWidgetHistory(e){await this.store.set(Y("subscriptionWidgetHistory"),e)}async getSubscriptionWidgetHistory(){return this.store.get(Y("subscriptionWidgetHistory"),{shownCount:0,lastShownAt:null})}async setLogLevel(e){await this.store.set(Y("logLevel"),e)}async getLogLevel(){return this.store.get(Y("logLevel"),"error")}async getShownWebPopups(){return this.store.get(Y("shownWebPopups"),[])}async addShownWebPopup(e){const t=await this.getShownWebPopups();t.includes(e)||(t.push(e),await this.store.set(Y("shownWebPopups"),t))}async setIsRecurringVisitor(e){await this.store.set(Y("isRecurringVisitor"),e)}async getIsRecurringVisitor(){return this.store.get(Y("isRecurringVisitor"),!1)}}class X{constructor(e,t=new Q,s=new N){if("data"in e){const t=e;this.payload=t.data}else this.payload=e;this.data=t,this.code=`notificationCode-${Date.now()}-${Math.random().toString(16).slice(2,10)}`,this.dateModule=s}async getIcon(){return this.payload.i||await this.data.getDefaultNotificationImage()}async getTitle(){return this.payload.header||await this.data.getDefaultNotificationTitle()}get silent(){return Boolean(this.payload.silent)}get body(){return this.payload.body}get messageHash(){return this.payload.p||""}get metaData(){return this.payload.md?a(this.payload.md):{}}get image(){return this.payload.image||""}get buttons(){return this.payload.buttons?a(this.payload.buttons):[]}get customData(){return this.payload.u?a(this.payload.u):{}}get campaignCode(){return this.payload.pwcid||""}get link(){return this.payload.l?(e=this.payload.l)&&G.test(e)?e.replace(J,e=>z[e]):e:"/";var e}get inboxId(){return this.payload.pw_inbox||""}get inboxParams(){return this.payload.inbox_params?a(this.payload.inbox_params):{}}get inboxRemovalTime(){return this.inboxParams&&this.inboxParams.rt?this.inboxParams.rt:(this.dateModule.date=new Date,this.dateModule.addDays(1),this.dateModule.getUtcTimestamp().toString())}async getInboxImage(){return this.inboxParams&&this.inboxParams.image?this.inboxParams.image:""}get rootParams(){const{body:e,p:t,header:s,i:a,u:i,l:r,pwcid:n,image:o,buttons:c,pw_inbox:u,inbox_params:h,...d}=this.payload;return d}async getNotificationOptionsPayload(){const e=await this.getTitle(),t=await this.getIcon();return{...this.rootParams,body:this.body,title:e,icon:t,image:this.image,buttons:this.buttons,customData:this.customData,metaData:this.metaData,campaignCode:this.campaignCode,openUrl:this.link,messageHash:this.messageHash}}async getShowNotificationOptions(){const e=await this.getIcon(),t=this.buttons.map((e,t)=>(e.action=`action-${t}`,e));return{renotify:!0,...this.rootParams,body:this.body,icon:e,tag:JSON.stringify({url:this.link,messageHash:this.messageHash,customData:this.customData,metaData:this.metaData}),data:{code:this.code,buttons:t,image:this.image,campaignCode:this.campaignCode,inboxId:this.inboxId},silent:this.silent,actions:t,image:this.image,buttons:t}}async getInboxMessage(){this.dateModule.date=new Date;const e=this.dateModule.getTimestamp().toString();return{title:this.payload.header||"",image:await this.getInboxImage(),status:1,order:this.dateModule.getInboxFakeOrder(),inbox_id:this.inboxId,send_date:e,rt:this.inboxRemovalTime,text:this.body,action_type:1,action_params:JSON.stringify({l:this.link})}}}class Z extends Error{constructor(e,t){super(e),this.name="ApiRequestError",this.statusCode=t}}class ee{constructor(e=new Q,t=P){this.data=e,this.logger=t}checkDevice(e){return this.createRequest("checkDevice",e)}getConfig(e){return this.createRequest("getConfig",e)}getPopupForms(e){return this.createRequest("getPopupForms",e)}getPopupFormContent(e){return this.createRequest("getPopupFormContent",e)}recordPopupFormEvent(e){return this.createRequest("recordPopupFormEvent",e)}applicationOpen(e){return this.createRequest("applicationOpen",e)}registerDevice(e){return this.createRequest("registerDevice",e)}unregisterDevice(e){return this.createRequest("unregisterDevice",e)}deleteDevice(e){return this.createRequest("deleteDevice",e)}messageDeliveryEvent(e){return this.createRequest("messageDeliveryEvent",e)}pushStat(e){return this.createRequest("pushStat",e)}setTags(e){return this.createRequest("setTags",e)}getTags(e){return this.createRequest("getTags",e)}registerUser(e){return this.createRequest("registerUser",e)}registerEmail(e){return this.createRequest("registerEmail",e)}registerEmailUser(e){return this.createRequest("registerEmailUser",e)}setEmailTags(e){return this.createRequest("setEmailTags",e)}postEvent(e){return this.createRequest("postEvent",e)}getInboxMessages(e){return this.createRequest("getInboxMessages",e)}inboxStatus(e){return this.createRequest("inboxStatus",e)}multiRegisterDevice(e){return this.createRequest("multiRegisterDevice",e)}async createRequest(e,t){const s=await this.data.getApiEntrypoint(),a=await this.data.getApiToken(),i=s+e,r=a?{headers:{Authorization:`Token ${a}`,"Content-Type":"text/plain;charset=UTF-8",Origin:globalThis.location.origin},credentials:"include"}:{},n=await fetch(i,{method:"POST",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:JSON.stringify({request:t}),...r}),o=await this.checkResponse(n);return o.base_url&&await this.data.setApiEntrypoint(o.base_url),await this.logger.write("apirequest",`${e} call with arguments: ${JSON.stringify(t)} to Pushwoosh has been successful. Result: ${JSON.stringify(o.response)}`),o.response}async checkResponse(e){if(200!==e.status){let t,s=`status: ${e.status}. statusText: ${e.statusText}.`;try{const a=await e.json();a&&"number"==typeof a.status_code&&(t=a.status_code),a&&a.status_message&&(s+=` status_code: ${a.status_code}. status_message: ${a.status_message}.`)}catch(e){}throw new Z(s,t)}const t=await e.json();if(200!==t.status_code)throw new Z(`Error code: ${t.status_code}. Error text: ${t.status_message}`,"number"==typeof t.status_code?t.status_code:void 0);return t}}class te{constructor(e,t,s){this.api=e,this.data=t,this.config=s}getPermission(){return Notification.permission}checkIsPermissionGranted(){return"granted"===this.getPermission()}checkIsPermissionDefault(){return"default"===this.getPermission()}async checkIsManualUnsubscribed(){return this.data.getStatusManualUnsubscribed()}async askPermission(){await Notification.requestPermission()}async getTokens(){return this.data.getTokens()}async subscribe(e){const t=e||await this.trySubscribe();if(!this.checkIsPermissionGranted())return void P.error("You must have permission granted before subscribe!");const s=this.getPushToken(t),a=t.getKey("p256dh"),i=t.getKey("auth");if(!a||!i)throw new Error("Can't get subscription keys!");const r=btoa(String.fromCharCode.apply(String,new Uint8Array(a))),n=btoa(String.fromCharCode.apply(String,new Uint8Array(i)));await this.data.setTokens({publicKey:r,pushToken:s,authToken:n,endpoint:t.endpoint}),await this.api.registerDevice()}async unsubscribe(){const e=await this.getServiceWorkerRegistration(),t=await e.pushManager.getSubscription();await this.data.setTokens({}),await this.data.setStatusManualUnsubscribed(!0),await this.api.unregisterDevice(),t&&await t.unsubscribe()}async checkIsRegister(){return this.api.checkDeviceSubscribeForPushNotifications()}async checkIsNeedResubscribe(){const e=await this.data.getLastPermissionStatus(),t=this.getPermission();if(e!==t&&(await this.data.setLastPermissionStatus(t),void 0!==e))return!0;const s=await this.getCredentials(),a=this.getPushToken(s),i=await this.data.getTokens(),r=a===(i&&i.pushToken||""),n=await this.data.getIsVapidChanged();return!r||n}async getServiceWorkerRegistration(){if(!this.registration){await this.registerServiceWorker();const e=await this.data.getServiceWorkerUrl();this.registration=await navigator.serviceWorker.getRegistration(e),await this.registration.update()}if(!this.registration)throw new Error("Internal Error: Can't register service worker!");return this.registration}async registerServiceWorker(){const e=await this.data.getServiceWorkerUrl(),t=await this.data.getServiceWorkerScope();let s="";await this.data.getSdkVersion()!==await this.data.getServiceWorkerVersion()&&(s=`?cache_clean=${i()}`),await navigator.serviceWorker.register(`${e}${s}`,{scope:t})}async trySubscribe(){try{return await this.subscribePushManager()}catch(e){return console.error(e),await this.unsubscribe(),this.subscribePushManager()}}async subscribePushManager(){const e=await this.getServiceWorkerRegistration(),t=await this.getApplicationServerKey();return e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:t?this.urlBase64ToUint8Array(t):null})}async getCredentials(){const e=await this.getServiceWorkerRegistration();return await e.pushManager.getSubscription()}getPushToken(e){return e?e.endpoint:""}async getApplicationServerKey(){return await this.data.getApplicationServerKey()}urlBase64ToUint8Array(e){const t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),s=atob(t),a=new Uint8Array(s.length);for(let e=0;e<s.length;++e)a[e]=s.charCodeAt(e);return a}}class se{constructor(e,t,s){this._canceled=!1,this.showNotificationOptions=e,this.body=t,this.title=s}async show(){if(this._canceled)return;const e=this.showNotificationOptions;e.silent||await self.registration.showNotification(this.title,e)}cancel(){this._canceled=!0}}const ae=new class{constructor(){this.addEventHandler=(e,t)=>{let s=this.handlers[e];s||(s=[]),s.push(t),this.handlers[e]=s},this.removeEventHandler=(e,t)=>{const s=this.handlers[e];s&&(this.handlers[e]=s.filter(e=>e!==t))},this.dispatchEvent=(e,t)=>{const s=t.eventId||i(),a=this.handlers[e];return a?(a.forEach(e=>{r(e)&&setTimeout(()=>{e({...t,eventId:s})},0)}),s):s},this.handlers={}}},ie=new Q,re=new class{constructor(e,t=new Q,s=new ee,a=()=>!1,i=()=>{}){this.ensureDeviceRegisteredPromise=null,this.checkDevicePromise=null,this.eventBus=e,this.data=t,this.apiClient=s,this.getIsCommunicationDisabled=a,this.getInitUserId=i}async checkDevice(){return this.checkDevicePromise||(this.checkDevicePromise=this.requestCheckDevice().catch(e=>{throw this.checkDevicePromise=null,e})),this.checkDevicePromise}async requestCheckDevice(){const e=await this.getRequestParams();return await this.apiClient.checkDevice(e)}async checkDeviceSubscribeForPushNotifications(a=!0){let i=localStorage.getItem(e);if(null===i||!a){const{exist:a,push_token_exist:r}=await this.checkDevice();localStorage.setItem(e,a&&r?t:s),i=localStorage.getItem(e)}return i===t}async ensureDeviceRegistered(){return!this.getIsCommunicationDisabled()&&(this.ensureDeviceRegisteredPromise||(this.ensureDeviceRegisteredPromise=this.registerDeviceIfNotExist().catch(e=>{throw this.ensureDeviceRegisteredPromise=null,e})),this.ensureDeviceRegisteredPromise)}async registerDeviceIfNotExist(){const{exist:e}=await this.checkDevice();return!e&&(await this.apiClient.registerDevice(await this.getRequestParams()),this.checkDevicePromise=null,!0)}async getConfig(e){const t=await this.getRequestParams();return this.apiClient.getConfig({...t,features:e})}async applicationOpen(){const e=await this.getRequestParams();return await this.data.setLastOpenApplicationTime(Date.now()),this.apiClient.applicationOpen(e)}async registerDevice(){if(await this.data.getStatusCommunicationDisabled())throw new Error("Can't register device: Communication is disabled!");const s=await this.getRequestParams(),a=await this.data.getTokens();if(!a.pushToken)throw new Error("Can't register device: pushToken is not exist!");const i=await this.apiClient.registerDevice({...s,push_token:a.pushToken,auth_token:a.authToken,public_key:a.publicKey});return this.checkDevicePromise=null,await this.data.setStatusManualUnsubscribed(!1),localStorage.setItem(e,t),this.eventBus.dispatchEvent("register",{}),i}async unregisterDevice(){const t=await this.getRequestParams(),a=await this.apiClient.unregisterDevice(t);return this.checkDevicePromise=null,localStorage.setItem(e,s),this.eventBus.dispatchEvent("unsubscribe",{}),a}async deleteDevice(){const t=await this.getRequestParams(),a=await this.apiClient.deleteDevice(t);return this.checkDevicePromise=null,await this.data.setStatusManualUnsubscribed(!0),localStorage.setItem(e,s),this.eventBus.dispatchEvent("unsubscribe",{}),a}async messageDeliveryEvent(e,t,s={}){const a=await this.getRequestParams();return await this.apiClient.messageDeliveryEvent({...a,hash:e,metaData:s})}async pushStat(e,t,s={}){const a=await this.getRequestParams();return await this.apiClient.pushStat({...a,hash:e,metaData:s})}async setTags(e){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const{hwid:t,device_type:s,...a}=await this.getRequestParams(),i=await this.data.getEmail();return i&&await this.apiClient.setEmailTags({...a,email:i,tags:e}),this.apiClient.setTags({...a,hwid:t,device_type:s,tags:e})}async getTags(){const e=await this.getRequestParams();return this.apiClient.getTags(e)}async setLanguage(e){return this.getIsCommunicationDisabled()?Promise.reject(new Error("Communication is disabled")):(await this.data.setLanguage(e),await this.data.setStatusLanguageWasChanged(!0),this.setTags({Language:e}))}async registerUser(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const{hwid:s,device_type:a,...i}=await this.getRequestParams(),r=await this.data.getDeviceType(),n=`${e}`,o=await this.apiClient.registerUser({...i,hwid:s,userId:n,ts_offset:60*-(new Date).getTimezoneOffset(),device_type:r});return await this.data.setUserId(n),t&&await this.data.setStatusUserIdWasChanged(!0),o}async registerEmail(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));if(!/^\S+@\S+\.\S+$/.test(e))return Promise.reject(new Error("Invalid Email format"));const s=await this.getIdentityRequestParams(),a=await this.apiClient.registerEmail({...s,email:e,ts_offset:60*-(new Date).getTimezoneOffset()});return await this.data.setEmail(e),t&&await this.data.setStatusEmailWasChanged(!0),a}async registerSmsNumber(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));if(!/^\+?[0-9]+$/.test(e))return Promise.reject(new Error("Invalid Phone number format: +1234567890"));const{application:s,userId:a}=await this.getIdentityRequestParams(),i=await this.apiClient.registerDevice({application:s,userId:a,hwid:e,device_type:18});return await this.data.setSmsNumber(e),t&&await this.data.setStatusSmsNumberWasChanged(!0),i}async registerWhatsappNumber(e,t=!0){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));if(!/^(whatsapp:)?\+?[0-9]+$/.test(e))return Promise.reject(new Error("Invalid WhatsApp number format: +1234567890"));const{application:s,userId:a}=await this.getIdentityRequestParams(),i=await this.apiClient.registerDevice({application:s,userId:a,hwid:e,device_type:21});return await this.data.setWhatsAppNumber(e),t&&await this.data.setStatusWhatsAppNumberWasChanged(!0),i}async getPopupForms(){if(this.getIsCommunicationDisabled())return[];return(await this.apiClient.getPopupForms(await this.getRequestParams())).popup_forms??[]}async getPopupFormContent(e){return this.getIsCommunicationDisabled()?Promise.reject(new Error("Communication is disabled")):this.apiClient.getPopupFormContent({...await this.getRequestParams(),code:e})}async recordPopupFormEvent(e,t){return this.getIsCommunicationDisabled()?Promise.reject(new Error("Communication is disabled")):this.apiClient.recordPopupFormEvent({...await this.getRequestParams(),code:e,event:t})}async postEvent(e,t){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const s=await this.getRequestParams(),a=new Date,i=a.getTime(),r=Math.floor(i/1e3),n=r-a.getTimezoneOffset()/60*3600,o=await this.data.getLastOpenMessage();if(o&&o.expiry>Date.now()){if(t.msgHash)return Promise.reject(new Error("attribute msgHash already defined"));t={...t,msgHash:o.messageHash}}await this.data.setLastOpenMessage(void 0);const c=await this.apiClient.postEvent({...s,event:e,timestampUTC:r,timestampCurrent:n,attributes:t});return c&&c.code&&this.eventBus.dispatchEvent("receive-in-app-code",{code:c.code}),c}async getInboxMessages(e=0){const t=await this.getRequestParams(),s=await this.data.getInboxLastRequestCode(),a=await this.data.getInboxLastRequestTime();return this.apiClient.getInboxMessages({...t,count:e,last_code:s,last_request_time:a})}async inboxStatus(e,t){const s=await this.getRequestParams();return this.apiClient.inboxStatus({...s,inbox_code:e,status:t,time:(new Date).getTime()})}async multiRegisterDevice(s){if(this.getIsCommunicationDisabled())return Promise.reject(new Error("Communication is disabled"));const a=await this.data.getApplicationCode(),i=await this.data.getDeviceModel(),r=await this.data.getDeviceType(),n=await this.data.getLanguage(),o=await this.data.getSdkVersion(),c=await this.data.getTokens(),u=await this.data.getHwid();!s.push_devices&&c.pushToken&&await this.requireHwid();const h={application:a,...s};if(s.user_id){h.user_id=String(s.user_id);await this.data.getUserId()!==h.user_id&&(await this.data.setUserId(h.user_id),await this.data.setStatusUserIdWasChanged(!0))}if(s.email){if(!/^\S+@\S+\.\S+$/.test(s.email))return Promise.reject(new Error("Invalid Email format"));await this.data.getEmail()!==s.email&&(await this.data.setEmail(s.email),await this.data.setStatusEmailWasChanged(!0))}if(s.sms_phone_number){if(!/^\+?[0-9]+$/.test(s.sms_phone_number))return Promise.reject(new Error("Invalid Phone number format: +1234567890"));await this.data.getSmsNumber()!==s.sms_phone_number&&(await this.data.setSmsNumber(s.sms_phone_number),await this.data.setStatusSmsNumberWasChanged(!0))}if(s.whatsapp_phone_number){if(!/^(whatsapp:)?\+?[0-9]+$/.test(s.whatsapp_phone_number))return Promise.reject(new Error("Invalid WhatsApp number format: +1234567890"));await this.data.getWhatsAppNumber()!==s.whatsapp_phone_number&&(await this.data.setWhatsAppNumber(s.whatsapp_phone_number),await this.data.setStatusWhatsAppNumberWasChanged(!0))}if(h.language?(await this.data.setLanguage(h.language),await this.data.setStatusLanguageWasChanged(!0)):h.language=n,!h.timezone){const e=60*-(new Date).getTimezoneOffset();h.timezone=String(e)}if(!h.push_devices&&c.pushToken){const e={hwid:u,platform:r,push_token:c.pushToken,sdk_version:o};if(c.publicKey||c.authToken||i){const t={};c.publicKey&&(t.public_key=c.publicKey),c.authToken&&(t.auth_token=c.authToken),i&&(t.browser=i),e.platformData=t}h.push_devices=[e]}const d=await this.apiClient.multiRegisterDevice(h);return h.push_devices?.length&&(this.checkDevicePromise=null,await this.data.setStatusManualUnsubscribed(!1),localStorage.setItem(e,t),this.eventBus.dispatchEvent("register",{})),d}async getParams(){return{applicationCode:await this.data.getApplicationCode(),hwid:await this.data.getHwid(),...await this.data.getTokens(),...await this.data.getInitParams()}}async getRequestParams(){const e=await this.requireHwid(),t=await this.data.getDeviceType();return{...await this.getIdentityRequestParams(),hwid:e,device_type:t}}async getIdentityRequestParams(){const e=await this.data.getApplicationCode(),t=await this.data.getHwid(),s=await this.data.getUserId()||this.getInitUserId(),a=await this.data.getDeviceModel(),i=await this.data.getLanguage(),r=await this.data.getSdkVersion(),n=60*-(new Date).getTimezoneOffset();if(!s&&!t)throw new Error("Pushwoosh: neither a userId nor an hwid is available, so there is nothing to register the email, SMS or WhatsApp channel to. Pass a userId in the init params.");return{application:e,userId:s||t,device_model:a,timezone:n,language:i,v:r}}async requireHwid(){const e=await this.data.getHwid();if(!e)throw new Error("Pushwoosh: the SDK storage does not keep the hwid in this browser (in-app webview, private window or insecure context), so this device cannot be identified. Requests that need an hwid are not sent.");return e}}(ae,ie);ie.getLogLevel().then(e=>{e&&P.setLevel(e)});const ne=self.Pushwoosh=new class{constructor(e,t,s){this._listeners={},this.eventBus=e,this.data=t,this.api=s}push(e){Array.isArray(e)&&"onPush"===e[0]&&r(e[1])&&(this._listeners[e[0]]||(this._listeners[e[0]]=[]),this._listeners[e[0]].push(e[1]))}getListeners(e){return this._listeners[e]||[]}async initApi(){return Promise.resolve()}}(ae,ie,re),oe=[];async function ce(e){(await self.clients.matchAll()).forEach(t=>t.postMessage(e))}async function ue(e){const{notification:t={}}=e,{data:s}=t,i=a(t.tag,{});let r="";if(e.action&&Array.isArray(s.buttons)){r=(s.buttons.find(t=>t.action===e.action)||{}).url}else r=i.url;return{title:t.title,body:t.body,icon:t.icon,buttons:s.buttons,image:s.image,code:s.code,campaignCode:s.campaignCode,inboxId:s.inboxId,messageHash:i.messageHash,customData:i.customData,metaData:i.metaData,openUrl:i.url,tag:t.tag,url:r}}async function he(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onInstallEventHandler",code:"FATAL-SW-001",error:e,applicationCode:t,workerVersion:s})}async function de(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onActivateEventHandler",code:"FATAL-SW-002",error:e,applicationCode:t,workerVersion:s})}async function le(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onNotificationClickEventHandler",code:"FATAL-SW-004",error:e,applicationCode:t,workerVersion:s})}async function ge(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onNotificationCloseEventHandler",code:"FATAL-SW-005",error:e,applicationCode:t,workerVersion:s})}async function pe(e){const t=await ne.data.getApplicationCode(),s=await ne.data.getServiceWorkerVersion();await _({message:"Error in onPushSubscriptionChange",code:"FATAL-SW-006",error:e,applicationCode:t,workerVersion:s})}return self.addEventListener("install",function(e){return e.waitUntil(async function(){await Promise.all([ne.data.setServiceWorkerVersion("3.90.1"),P.write("info","install")]),await self.skipWaiting()}().catch(he))}),self.addEventListener("activate",function(e){e.waitUntil(async function(){await Promise.all([P.write("info","activate")]),await self.clients.claim()}().catch(de))}),self.addEventListener("push",function(e){e.waitUntil(async function(e){await self.clients.claim();const t=await e.data.json(),s=new X(t),a=await s.getNotificationOptionsPayload(),i=await s.getShowNotificationOptions(),r=s.messageHash;await P.write("info",JSON.stringify(a),"onPush");const n=new se(i,s.body,await s.getTitle()),o=ne.getListeners("onPush");await o.reduce((e,t)=>e.then(()=>t(n)),Promise.resolve());const c=[n.show(),C.add({payload:t,parsedPayload:a,showOptions:i}),ce({type:"onPushDelivery",payload:a})];if(r&&c.push(ne.initApi().then(()=>ne.api.messageDeliveryEvent(r,!0,a.metaData))),""!==s.inboxId){const e=new K(ne.eventBus,ne.data,ne.api),t=new F(ne.data,ne.api,e),a=await s.getInboxMessage(),i=await t.publicMessageBuilder(a);c.push(e.putMessage(a),ce({type:"onPutNewMessageToInboxStore",payload:i}))}await Promise.all(c)}(e).catch(t=>async function(e,t){const s=await ne.data.getApplicationCode(),a=await ne.data.getServiceWorkerVersion();await _({message:"Error in onPushEventHandler",code:"FATAL-SW-003",error:e,applicationCode:s,workerVersion:a}),e instanceof Error||(e=new Error(e));return C.add({error:`${e}`,stack:e.stack,payload:t.data&&t.data.text()})}(t,e)))}),self.addEventListener("notificationclick",function(e){e.waitUntil(async function(e){await self.clients.claim();const t=await ue(e),{messageHash:s,metaData:a,url:i,code:r,inboxId:n}=t;if(r&&oe.push(r),""!==n){const e=new K(ne.eventBus,ne.data,ne.api),t=await e.getMessage(n);t.status=3,await e.putMessage(t)}e.notification.close();const o={type:"onNotificationClick",payload:t};return i&&e.waitUntil(self.clients.matchAll({type:"window"}).then(e=>async function(e,t){const{hostname:s,pathname:a}=new URL(t,self.location.origin),i=e.find(e=>{const{hostname:t,pathname:i}=new URL(e.url);return t===s&&i===a});return i?(await i.focus(),!1):(await self.clients.openWindow(t).then(e=>{e&&e.focus()}),!0)}(e,i)).then(e=>{e&&ne.data.setDelayedEvent(o)})),Promise.all([ne.initApi().then(()=>ne.api.pushStat(s,!0,a)),ne.data.setLastOpenMessage({url:i,messageHash:s,expiry:Date.now()+864e5}),ce(o)])}(e).catch(le))}),self.addEventListener("notificationclose",function(e){e.waitUntil(async function(e){await self.clients.claim();const t=await ue(e),{code:s}=t;if(e.notification.close(),!s)return;const a=oe.indexOf(s);if(!(a>=0))return ce({type:"onNotificationClose",payload:t});oe.splice(a,1)}(e).catch(ge))}),self.addEventListener("pushsubscriptionchange",async function(e){e.waitUntil(async function(e){let t=e.newSubscription;if(!t&&(t=await self.registration.pushManager.getSubscription(),!t))return;const s=new te(re,ie,{});await s.subscribe(t)}(e).catch(pe))}),{}})());
2
2
  //# sourceMappingURL=service-worker.js.map
@@ -1,2 +1,2 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,()=>(()=>{"use strict";const e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{PWSubscriptionWidget:()=>Yt});const n=/^(https?:|mailto:|tel:)/i,o="#101828",r="#667085",i="#FFFFFF",l={background:"#FFFFFF",accent:"#2970FF",text:o,textSecondary:r,textInverse:"#FFFFFF"};function s(e,t){return{display:"block",boxSizing:"border-box",width:"100%",padding:"10px 25px",borderRadius:6,fontSize:14,fontWeight:600,fontFamily:"inherit",lineHeight:1.5,textAlign:"center",textDecoration:"none",cursor:"pointer",..."secondary"===e?{backgroundColor:t.surface,color:t.accent,border:`1px solid ${t.accent}`}:{backgroundColor:t.accent,color:t.onAccent,border:"none"}}}const a={card:["top","bottom","top-left","top-right","bottom-left","bottom-right"],bar:["top","bottom"],modal:["center"]},c=Object.keys(a),_=["bottom-right","bottom-left","top-right","top-left"],u=["auto","launcher","manual"],d={delay:[0,3600],cappingCount:[0,100],cappingInterval:[0,8760],borderRadius:[0,32],offset:[0,100],size:[32,80],zIndex:[0,2147483647]},p={enable:!1,prompt:{layout:"card",position:"top",borderRadius:12,overlay:!1},launcher:{enabled:!1,position:"bottom-right",offset:20,size:48},display:{trigger:"auto",delay:5,cappingCount:3,cappingInterval:4},texts:{title:"Stay in the loop",message:"Allow notifications to get our news and special offers first.",acceptText:"Allow",declineText:"Not now",closeText:"Got it",blockedTitle:"Notifications are blocked",blockedMessage:"To get our notifications, allow them for this site in your browser settings.",launcherLabel:"Subscribe to notifications",launcherBlockedLabel:"Notifications are blocked"},colors:l,fontFamily:'Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',zIndex:2147483e3},f=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function h(e){const t=f.exec(e.trim())?.[1];if(!t)return null;const n=3===t.length?t.split("").map(e=>e+e).join(""):t;return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))}function m([e,t,n]){return`#${[e,t,n].map(e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0")).join("")}`}function v(e,t,n){let o=n;return o<0&&(o+=1),o>1&&(o-=1),o<1/6?e+6*(t-e)*o:o<.5?t:o<2/3?e+(t-e)*(2/3-o)*6:e}function y(e){return e>.5?.07+.86*(1-e):e}function b(e){return e<.5?.93-e*((.93-.5)/.5):e}function g(e,t){const n=h(e);if(!n)return e;const[o,r,i]=function([e,t,n]){const[o,r,i]=[e/255,t/255,n/255],l=Math.max(o,r,i),s=Math.min(o,r,i),a=(l+s)/2;if(l===s)return[0,0,a];const c=l-s;let _;return _=l===o?(r-i)/c+(r<i?6:0):l===r?(i-o)/c+2:(o-r)/c+4,[_/6,a>.5?c/(2-l-s):c/(l+s),a]}(n);return m(function([e,t,n]){if(0===t){const e=255*n;return[e,e,e]}const o=n<.5?n*(1+t):n+t-n*t,r=2*n-o;return[255*v(r,o,e+1/3),255*v(r,o,e),255*v(r,o,e-1/3)]}([o,r,"fold"===t?y(i):b(i)]))}function w(e,t,n){const o=h(e),r=h(t);return o&&r?m(o.map((e,t)=>e+(r[t]-e)*n)):e}function x(e){const t=h(e);if(!t)return!1;const[n,o,r]=t;return(.299*n+.587*o+.114*r)/255>.6}function k(e){return{background:g(e.background,"fold"),accent:e.accent,text:g(e.text,"lift"),textSecondary:g(e.textSecondary,"lift"),textInverse:e.textInverse}}function S(e,t){return"light"===t?{surface:l.background,surfaceText:o,border:"#D0D5DD",onAccent:i,error:"#D92D20",chromeIcon:r}:{surface:w(e.background,e.text,.08),surfaceText:e.text,border:w(e.background,e.text,.24),onAccent:x(e.accent)?o:i,error:"#FDA29B",chromeIcon:e.textSecondary}}function M(e){return!0===e.dark?.enabled}function P(e,t="light"){return"dark"===t&&M(e)?"dark":"light"}function C(e,t="light"){const n=P(e,t),o="dark"===n?(r=e.colors,i=e.dark,{...k(r),...i?.colors??{}}):e.colors;var r,i;return{...o,scheme:n,...S(o,n)}}function I(e){const t=(e||"").trim();if(t)return t.startsWith("#")||t.startsWith("/")||t.startsWith("?")||n.test(t)?t:void 0}new Set(["STRONG","B","EM","I","U","BR","A"]);function A(e){return"string"==typeof e&&e?e:void 0}function F(e){const t="object"==typeof e.colors&&null!==e.colors?e.colors:{};return{background:A(t.background)??A(e.background)??l.background,accent:A(t.accent)??A(e.accent)??l.accent,text:A(t.text)??l.text,textSecondary:A(t.textSecondary)??l.textSecondary,textInverse:A(t.textInverse)??l.textInverse}}function z(e,t){const n=e.dark;if("object"!=typeof n||null===n)return;const o=n,r="object"==typeof o.colors&&null!==o.colors?o.colors:{},i=k(t),l=function(e){if("object"!=typeof e||null===e)return;const t=e,n=A(t.color);if(!n)return;return{color:n,opacity:"number"==typeof t.opacity&&Number.isFinite(t.opacity)?Math.max(0,Math.min(1,t.opacity)):1}}(o.overlay);return{enabled:!0===o.enabled,colors:{background:A(r.background)??i.background,accent:A(r.accent)??i.accent,text:A(r.text)??i.text,textSecondary:A(r.textSecondary)??i.textSecondary,textInverse:A(r.textInverse)??i.textInverse},...l?{overlay:l}:{},...A(o.boxShadow)?{boxShadow:o.boxShadow}:{}}}function H(e){return"object"!=typeof e||null===e||Array.isArray(e)?{}:e}function T(e,t,n){return t.includes(e)?e:n}function E(e,[t,n],o){return"number"==typeof e&&Number.isFinite(e)?Math.max(t,Math.min(n,Math.round(e))):o}function j(e,t){if("string"!=typeof e)return t;const n=e.trim();return n?n.slice(0,300):t}function D(e){const t=p.texts,n=Object.keys(t);return Object.fromEntries(n.map(n=>[n,j(e[n],t[n])]))}function O(e){const t=p,n=H(e),o=H(n.prompt),r=H(n.launcher),i=H(n.display),l=d,s=T(o.layout,c,t.prompt.layout),f=a[s],h=T(i.trigger,u,t.display.trigger),m=function(e){const t=I("string"==typeof e?e:void 0);return t&&/^(https?:\/\/|\/)/i.test(t)?t:void 0}(o.iconUrl),v=F({colors:n.colors}),y=z({dark:n.dark},v);return{enable:!0===n.enable,prompt:{layout:s,position:T(o.position,f,f[0]),...m?{iconUrl:m}:{},borderRadius:E(o.borderRadius,l.borderRadius,t.prompt.borderRadius),overlay:"modal"===s||!0===o.overlay},launcher:{enabled:"launcher"===h||!0===r.enabled,position:T(r.position,_,t.launcher.position),offset:E(r.offset,l.offset,t.launcher.offset),size:E(r.size,l.size,t.launcher.size)},display:{trigger:h,delay:E(i.delay,l.delay,t.display.delay),cappingCount:E(i.cappingCount,l.cappingCount,t.display.cappingCount),cappingInterval:E(i.cappingInterval,l.cappingInterval,t.display.cappingInterval)},texts:D(H(n.texts)),colors:v,...y?{dark:y}:{},fontFamily:j(n.fontFamily,t.fontFamily),zIndex:E(n.zIndex,l.zIndex,t.zIndex)}}function N(e){return"default"===e||"denied"===e}function U(e){return"denied"===e?"blocked":"ask"}function W(e,t){return e.enable&&e.launcher.enabled&&N(t)}var L,R,B,V,$,q,G,Z,K,X,J,Q,Y,ee,te={},ne=[],oe=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,re=Array.isArray;function ie(e,t){for(var n in t)e[n]=t[n];return e}function le(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function se(e,t,n){var o,r,i,l={};for(i in t)"key"==i?o=t[i]:"ref"==i?r=t[i]:l[i]=t[i];if(arguments.length>2&&(l.children=arguments.length>3?L.call(arguments,2):n),"function"==typeof e&&null!=e.defaultProps)for(i in e.defaultProps)void 0===l[i]&&(l[i]=e.defaultProps[i]);return ae(e,l,o,r,null)}function ae(e,t,n,o,r){var i={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:r??++B,__i:-1,__u:0};return null==r&&null!=R.vnode&&R.vnode(i),i}function ce(e){return e.children}function _e(e,t){this.props=e,this.context=t}function ue(e,t){if(null==t)return e.__?ue(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?ue(e):null}function de(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],i=ie({},t);i.__v=t.__v+1,R.vnode&&R.vnode(i),Se(e.__P,i,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n??ue(t),!!(32&t.__u),r),i.__v=t.__v,i.__.__k[i.__i]=i,Pe(o,i,r),t.__e=t.__=null,i.__e!=n&&pe(i)}}function pe(e){if(null!=(e=e.__)&&null!=e.__c)return e.__e=e.__c.base=null,e.__k.some(function(t){if(null!=t&&null!=t.__e)return e.__e=e.__c.base=t.__e}),pe(e)}function fe(e){(!e.__d&&(e.__d=!0)&&V.push(e)&&!he.__r++||$!=R.debounceRendering)&&(($=R.debounceRendering)||q)(he)}function he(){try{for(var e,t=1;V.length;)V.length>t&&V.sort(G),e=V.shift(),t=V.length,de(e)}finally{V.length=he.__r=0}}function me(e,t,n,o,r,i,l,s,a,c,_){var u,d,p,f,h,m,v=o&&o.__k||ne,y=t.length;for(a=ve(n,t,v,a,y),u=0;u<y;u++)null!=(p=n.__k[u])&&(d=-1!=p.__i&&v[p.__i]||te,p.__i=u,m=Se(e,p,d,r,i,l,s,a,c,_),f=p.__e,p.ref&&d.ref!=p.ref&&(d.ref&&Ae(d.ref,null,p),_.push(p.ref,p.__c||f,p)),null==h&&null!=f&&(h=f),4&p.__u?(a=ye(p,a,e),d.__e&&(d.__e=null)):"function"==typeof p.type&&void 0!==m?a=m:f&&(a=f.nextSibling),p.__u&=-7);return n.__e=h,a}function ve(e,t,n,o,r){var i,l,s,a,c,_=n.length,u=_,d=0;for(e.__k=new Array(r),i=0;i<r;i++)null!=(l=t[i])&&"boolean"!=typeof l&&"function"!=typeof l?("string"==typeof l||"number"==typeof l||"bigint"==typeof l||l.constructor==String?l=e.__k[i]=ae(null,l,null,null,null):re(l)?l=e.__k[i]=ae(ce,{children:l},null,null,null):void 0===l.constructor&&l.__b>0?l=e.__k[i]=ae(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):e.__k[i]=l,a=i+d,l.__=e,l.__b=e.__b+1,s=null,-1!=(c=l.__i=ge(l,n,a,u))&&(u--,(s=n[c])&&(s.__u|=2)),null==s||null==s.__v?(-1==c&&(r>_?d--:r<_&&d++),"function"!=typeof l.type&&(l.__u|=4)):c!=a&&(c==a-1?d--:c==a+1?d++:(c>a?d--:d++,l.__u|=4))):e.__k[i]=null;if(u)for(i=0;i<_;i++)null!=(s=n[i])&&!(2&s.__u)&&(s.__e==o&&(o=ue(s)),Fe(s,s));return o}function ye(e,t,n){var o,r;if("function"==typeof e.type){for(o=e.__k,r=0;o&&r<o.length;r++)o[r]&&(o[r].__=e,t=ye(o[r],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=ue(e)),t=n.insertBefore(e.__e,t||null));do{t=t&&t.nextSibling}while(null!=t&&8==t.nodeType);return t}function be(e,t){return t=t||[],null==e||"boolean"==typeof e||(re(e)?e.some(function(e){be(e,t)}):t.push(e)),t}function ge(e,t,n,o){var r,i,l,s=e.key,a=e.type,c=t[n],_=null!=c&&!(2&c.__u);if(null===c&&null==s||_&&s==c.key&&a==c.type)return n;if(o>(_?1:0))for(r=n-1,i=n+1;r>=0||i<t.length;)if(null!=(c=t[l=r>=0?r--:i++])&&!(2&c.__u)&&s==c.key&&a==c.type)return l;return-1}function we(e,t,n){"-"==t[0]?e.setProperty(t,n??""):e[t]=null==n?"":"number"!=typeof n||oe.test(t)?n:n+"px"}function xe(e,t,n,o,r){var i,l;e:if("style"==t)if("string"==typeof n)e.style.cssText=n;else{if("string"==typeof o&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||we(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||we(e.style,t,n[t])}else if("o"==t[0]&&"n"==t[1])i=t!=(t=t.replace(J,"$1")),l=t.toLowerCase(),t=l in e||"onFocusOut"==t||"onFocusIn"==t?l.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+i]=n,n?o?n[X]=o[X]:(n[X]=Q,e.addEventListener(t,i?ee:Y,i)):e.removeEventListener(t,i?ee:Y,i);else{if("http://www.w3.org/2000/svg"==r)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=t&&"height"!=t&&"href"!=t&&"list"!=t&&"form"!=t&&"tabIndex"!=t&&"download"!=t&&"rowSpan"!=t&&"colSpan"!=t&&"role"!=t&&"popover"!=t&&t in e)try{e[t]=n??"";break e}catch(e){}"function"==typeof n||(null==n||!1===n&&"-"!=t[4]?e.removeAttribute(t):e.setAttribute(t,"popover"==t&&1==n?"":n))}}function ke(e){return function(t){if(this.l){var n=this.l[t.type+e];if(null==t[K])t[K]=Q++;else if(t[K]<n[X])return;return n(R.event?R.event(t):t)}}}function Se(e,t,n,o,r,i,l,s,a,c){var _,u,d,p,f,h,m,v,y,b,g,w,x,k,S,M,P=t.type;if(void 0!==t.constructor)return null;128&n.__u&&(a=!!(32&n.__u),i=[s=t.__e=n.__e]),(_=R.__b)&&_(t);e:if("function"==typeof P){u=l.length;try{if(y=t.props,b=P.prototype&&P.prototype.render,g=(_=P.contextType)&&o[_.__c],w=_?g?g.props.value:_.__:o,n.__c?v=(d=t.__c=n.__c).__=d.__E:(b?t.__c=d=new P(y,w):(t.__c=d=new _e(y,w),d.constructor=P,d.render=ze),g&&g.sub(d),d.state||(d.state={}),d.__n=o,p=d.__d=!0,d.__h=[],d._sb=[]),b&&null==d.__s&&(d.__s=d.state),b&&null!=P.getDerivedStateFromProps&&(d.__s==d.state&&(d.__s=ie({},d.__s)),ie(d.__s,P.getDerivedStateFromProps(y,d.__s))),f=d.props,h=d.state,d.__v=t,p)b&&null==P.getDerivedStateFromProps&&null!=d.componentWillMount&&d.componentWillMount(),b&&null!=d.componentDidMount&&d.__h.push(d.componentDidMount);else{if(b&&null==P.getDerivedStateFromProps&&y!==f&&null!=d.componentWillReceiveProps&&d.componentWillReceiveProps(y,w),t.__v==n.__v||!d.__e&&null!=d.shouldComponentUpdate&&!1===d.shouldComponentUpdate(y,d.__s,w)){t.__v!=n.__v&&(d.props=y,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),ne.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&l.push(d),s=ue(n);break e}null!=d.componentWillUpdate&&d.componentWillUpdate(y,d.__s,w),b&&null!=d.componentDidUpdate&&d.__h.push(function(){d.componentDidUpdate(f,h,m)})}if(d.context=w,d.props=y,d.__P=e,d.__e=!1,x=R.__r,k=0,b)d.state=d.__s,d.__d=!1,x&&x(t),_=d.render(d.props,d.state,d.context),ne.push.apply(d.__h,d._sb),d._sb=[];else do{d.__d=!1,x&&x(t),_=d.render(d.props,d.state,d.context),d.state=d.__s}while(d.__d&&++k<25);d.state=d.__s,null!=d.getChildContext&&(o=ie(ie({},o),d.getChildContext())),b&&!p&&null!=d.getSnapshotBeforeUpdate&&(m=d.getSnapshotBeforeUpdate(f,h)),S=null!=_&&_.type===ce&&null==_.key?Ce(_.props.children):_,s=me(e,re(S)?S:[S],t,n,o,r,i,l,s,a,c),d.base=t.__e,t.__u&=-161,d.__h.length&&l.push(d),v&&(d.__E=d.__=null)}catch(e){if(l.length=u,t.__v=null,a||null!=i){if(e.then){for(t.__u|=a?160:128;s&&8==s.nodeType&&s.nextSibling;)s=s.nextSibling;null!=i&&(i[i.indexOf(s)]=null),t.__e=s}else if(null!=i)for(M=i.length;M--;)le(i[M])}else t.__e=n.__e;null==t.__k&&(t.__k=n.__k||[]),e.then||Me(t),R.__e(e,t,n)}}else null==i&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):s=t.__e=Ie(n.__e,t,n,o,r,i,l,a,c);return(_=R.diffed)&&_(t),128&t.__u?void 0:s}function Me(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Me))}function Pe(e,t,n){for(var o=0;o<n.length;o++)Ae(n[o],n[++o],n[++o]);R.__c&&R.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){R.__e(e,t.__v)}})}function Ce(e){return"object"!=typeof e||null==e||e.__b>0?e:re(e)?e.map(Ce):void 0!==e.constructor?null:ie({},e)}function Ie(e,t,n,o,r,i,l,s,a){var c,_,u,d,p,f,h,m=n.props||te,v=t.props,y=t.type;if("svg"==y?r="http://www.w3.org/2000/svg":"math"==y?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),null!=i)for(c=0;c<i.length;c++)if((p=i[c])&&"setAttribute"in p==!!y&&(y?p.localName==y:3==p.nodeType)){e=p,i[c]=null;break}if(null==e){if(null==y)return document.createTextNode(v);e=document.createElementNS(r,y,v.is&&v),s&&(R.__m&&R.__m(t,i),s=!1),i=null}if(null==y)m===v||s&&e.data==v||(e.data=v);else{if(i="textarea"==y&&null!=v.defaultValue?null:i&&L.call(e.childNodes),!s&&null!=i)for(m={},c=0;c<e.attributes.length;c++)m[(p=e.attributes[c]).name]=p.value;for(c in m)p=m[c],"dangerouslySetInnerHTML"==c?u=p:"children"==c||c in v||"value"==c&&"defaultValue"in v||"checked"==c&&"defaultChecked"in v||xe(e,c,null,p,r);for(c in v)p=v[c],"children"==c?d=p:"dangerouslySetInnerHTML"==c?_=p:"value"==c?f=p:"checked"==c?h=p:s&&"function"!=typeof p||m[c]===p||xe(e,c,p,m[c],r);if(_)s||u&&(_.__html==u.__html||_.__html==e.innerHTML)||(e.innerHTML=_.__html),t.__k=[];else if(u&&(e.innerHTML=""),me("template"==t.type?e.content:e,re(d)?d:[d],t,n,o,"foreignObject"==y?"http://www.w3.org/1999/xhtml":r,i,l,i?i[0]:n.__k&&ue(n,0),s,a),null!=i)for(c=i.length;c--;)le(i[c]);s&&"textarea"!=y||(c="value","progress"==y&&null==f?e.removeAttribute("value"):null!=f&&(f!==e[c]||"progress"==y&&!f||"option"==y&&f!=m[c])&&xe(e,c,f,m[c],r),c="checked",null!=h&&h!=e[c]&&xe(e,c,h,m[c],r))}return e}function Ae(e,t,n){try{if("function"==typeof e){var o="function"==typeof e.__u;o&&e.__u(),o&&null==t||(e.__u=e(t))}else e.current=t}catch(e){R.__e(e,n)}}function Fe(e,t,n){var o,r;if(R.unmount&&R.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Ae(o,null,t)),null!=(o=e.__c)){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(e){R.__e(e,t)}o.base=o.__P=o.__n=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&Fe(o[r],t,n||"function"!=typeof e.type);n||le(e.__e),e.__c=e.__=e.__e=void 0}function ze(e,t,n){return this.constructor(e,n)}function He(e,t,n){var o,r,i,l;t==document&&(t=document.documentElement),R.__&&R.__(e,t),r=(o="function"==typeof n)?null:n&&n.__k||t.__k,i=[],l=[],Se(t,e=(!o&&n||t).__k=se(ce,null,[e]),r||te,te,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?L.call(t.childNodes):null,i,!o&&n?n:r?r.__e:t.firstChild,o,l),Pe(i,e,l),e.props.children=null}L=ne.slice,R={__e:function(e,t,n,o){for(var r,i,l;t=t.__;)if((r=t.__c)&&!r.__)try{if((i=r.constructor)&&null!=i.getDerivedStateFromError&&(r.setState(i.getDerivedStateFromError(e)),l=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(e,o||{}),l=r.__d),l)return r.__E=r}catch(t){e=t}throw e}},B=0,_e.prototype.setState=function(e,t){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=ie({},this.state),"function"==typeof e&&(e=e(ie({},n),this.props)),e&&ie(n,e),null!=e&&this.__v&&(t&&this._sb.push(t),fe(this))},_e.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),fe(this))},_e.prototype.render=ce,V=[],q="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,G=function(e,t){return e.__v.__b-t.__v.__b},he.__r=0,Z=Math.random().toString(8),K="__d"+Z,X="__a"+Z,J=/(PointerCapture)$|Capture$/i,Q=0,Y=ke(!1),ee=ke(!0);var Te=0;Array.isArray;function Ee(e,t,n,o,r,i){t||(t={});var l,s,a=t;if("ref"in a)for(s in a={},t)"ref"==s?l=t[s]:a[s]=t[s];var c={type:e,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Te,__i:-1,__u:0,__source:r,__self:i};if("function"==typeof e&&(l=e.defaultProps))for(s in l)void 0===a[s]&&(a[s]=l[s]);return R.vnode&&R.vnode(c),c}var je,De,Oe,Ne,Ue=0,We=[],Le=R,Re=Le.__b,Be=Le.__r,Ve=Le.diffed,$e=Le.__c,qe=Le.unmount,Ge=Le.__;function Ze(e,t){Le.__h&&Le.__h(De,e,Ue||t),Ue=0;var n=De.__H||(De.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function Ke(e){return Ue=1,function(e,t,n){var o=Ze(je++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):nt(void 0,t),function(e){var t=o.__N?o.__N[0]:o.__[0],n=o.t(t,e);t!==n&&(o.__N=[n,o.__[1]],o.__c.setState({}))}],o.__c=De,!De.__f)){var r=function(e,t,n){if(!o.__c.__H)return!0;var r=!1,l=o.__c.props!==e;if(o.__c.__H.__.some(function(e){if(e.__N){r=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(l=!0)}}),i){var s=i.call(this,e,t,n);return r?s||l:s}return!r||l};De.__f=!0;var i=De.shouldComponentUpdate,l=De.componentWillUpdate;De.componentWillUpdate=function(e,t,n){if(this.__e){var o=i;i=void 0,r(e,t,n),i=o}l&&l.call(this,e,t,n)},De.shouldComponentUpdate=r}return o.__N||o.__}(nt,e)}function Xe(){for(var e;e=We.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Ye),t.__h.some(et),t.__h=[]}catch(n){t.__h=[],Le.__e(n,e.__v)}}}Le.__b=function(e){De=null,Re&&Re(e)},Le.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ge&&Ge(e,t)},Le.__r=function(e){Be&&Be(e),je=0;var t=(De=e.__c).__H;t&&(Oe===De?(t.__h=[],De.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(Ye),t.__h.some(et),t.__h=[],je=0)),Oe=De},Le.diffed=function(e){Ve&&Ve(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(1!==We.push(t)&&Ne===Le.requestAnimationFrame||((Ne=Le.requestAnimationFrame)||Qe)(Xe)),t.__H.__.some(function(e){e.u&&(e.__H=e.u,e.u=void 0)})),Oe=De=null},Le.__c=function(e,t){t.some(function(e){try{e.__h.some(Ye),e.__h=e.__h.filter(function(e){return!e.__||et(e)})}catch(n){t.some(function(e){e.__h&&(e.__h=[])}),t=[],Le.__e(n,e.__v)}}),$e&&$e(e,t)},Le.unmount=function(e){qe&&qe(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{Ye(e)}catch(e){t=e}}),n.__H=void 0,t&&Le.__e(t,n.__v))};var Je="function"==typeof requestAnimationFrame;function Qe(e){var t,n=function(){clearTimeout(o),Je&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Je&&(t=requestAnimationFrame(n))}function Ye(e){var t=De,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),De=t}function et(e){var t=De;e.__c=e.__(),De=t}function tt(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function nt(e,t){return"function"==typeof t?t(e):t}function ot(e,t){for(var n in t)e[n]=t[n];return e}function rt(e,t){for(var n in e)if("__source"!==n&&!(n in t))return!0;for(var o in t)if("__source"!==o&&e[o]!==t[o])return!0;return!1}function it(e,t){this.props=e,this.context=t}(it.prototype=new _e).isPureReactComponent=!0,it.prototype.shouldComponentUpdate=function(e,t){return rt(this.props,e)||rt(this.state,t)};var lt=R.__b;R.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),lt&&lt(e)};"undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.forward_ref");var st=R.__e;R.__e=function(e,t,n,o){if(e.then)for(var r,i=t;i=i.__;)if((r=i.__c)&&r.__c)return null==t.__e&&(t.__e=n.__e,t.__k=n.__k||[]),r.__c(e,t);st(e,t,n,o)};var at=R.unmount;function ct(e,t,n){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(e){"function"==typeof e.__c&&e.__c()}),e.__c.__H=null),null!=(e=ot({},e)).__c&&(e.__c.__P===n&&(e.__c.__P=t),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(e){return ct(e,t,n)})),e}function _t(e,t,n){return e&&n&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(e){return _t(e,t,n)}),e.__c&&e.__c.__P===t&&(e.__e&&n.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=n)),e}function ut(){this.__u=0,this.o=null,this.__b=null}function dt(e){var t=e.__&&e.__.__c;return t&&t.__a&&t.__a(e)}function pt(){this.i=null,this.l=null}R.unmount=function(e){var t=e.__c;t&&(t.__z=!0),t&&t.__R&&t.__R(),t&&32&e.__u&&(e.type=null),at&&at(e)},(ut.prototype=new _e).__c=function(e,t){var n=t.__c,o=this;null==o.o&&(o.o=[]),o.o.push(n);var r=dt(o.__v),i=!1,l=function(){i||o.__z||(i=!0,n.__R=null,r?r(a):a())};n.__R=l;var s=n.__P;n.__P=null;var a=function(){if(! --o.__u){if(o.state.__a){var e=o.state.__a;o.__v.__k[0]=_t(e,e.__c.__P,e.__c.__O)}var t;for(o.setState({__a:o.__b=null});t=o.o.pop();)t.__P=s,t.forceUpdate()}};o.__u++||32&t.__u||o.setState({__a:o.__b=o.__v.__k[0]}),e.then(l,l)},ut.prototype.componentWillUnmount=function(){this.o=[]},ut.prototype.render=function(e,t){if(this.__b){if(this.__v.__k){var n=document.createElement("div"),o=this.__v.__k[0].__c;this.__v.__k[0]=ct(this.__b,n,o.__O=o.__P)}this.__b=null}var r=t.__a&&se(ce,null,e.fallback);return r&&(r.__u&=-33),[se(ce,null,t.__a?null:e.children),r]};var ft=function(e,t,n){if(++n[1]===n[0]&&e.l.delete(t),e.props.revealOrder&&("t"!==e.props.revealOrder[0]||!e.l.size))for(n=e.i;n;){for(;n.length>3;)n.pop()();if(n[1]<n[0])break;e.i=n=n[2]}};(pt.prototype=new _e).__a=function(e){var t=this,n=dt(t.__v),o=t.l.get(e);return o[0]++,function(r){var i=function(){t.props.revealOrder?(o.push(r),ft(t,e,o)):r()};n?n(i):i()}},pt.prototype.render=function(e){this.i=null,this.l=new Map;var t=be(e.children);e.revealOrder&&"b"===e.revealOrder[0]&&t.reverse();for(var n=t.length;n--;)this.l.set(t[n],this.i=[1,0,this.i]);return e.children},pt.prototype.componentDidUpdate=pt.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(t,n){ft(e,n,t)})};var ht="undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,mt=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,vt=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,yt=/[A-Z0-9]/g,bt="undefined"!=typeof document,gt=function(e){return("undefined"!=typeof Symbol&&"symbol"==typeof Symbol()?/fil|che|rad/:/fil|che|ra/).test(e)};_e.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(_e.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:t})}})});var wt=R.event;R.event=function(e){return wt&&(e=wt(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var xt={configurable:!0,get:function(){return this.class}},kt=R.vnode;R.vnode=function(e){"string"==typeof e.type&&function(e){var t=e.props,n=e.type,o={},r=-1==n.indexOf("-");for(var i in t){var l=t[i];if(!("value"===i&&"defaultValue"in t&&null==l||bt&&"children"===i&&"noscript"===n||"class"===i||"className"===i)){var s=i.toLowerCase();"defaultValue"===i&&"value"in t&&null==t.value?i="value":"download"===i&&!0===l?l="":"translate"===s&&"no"===l?l=!1:"o"===s[0]&&"n"===s[1]?"ondoubleclick"===s?i="ondblclick":"onchange"!==s||"input"!==n&&"textarea"!==n||gt(t.type)?"onfocus"===s?i="onfocusin":"onblur"===s?i="onfocusout":vt.test(i)&&(i=s):s=i="oninput":r&&mt.test(i)?i=i.replace(yt,"-$&").toLowerCase():null===l&&(l=void 0),"oninput"===s&&o[i=s]&&(i="oninputCapture"),o[i]=l}}"select"==n&&(o.multiple&&Array.isArray(o.value)&&(o.value=be(t.children).forEach(function(e){e.props.selected=-1!=o.value.indexOf(e.props.value)})),null!=o.defaultValue&&(o.value=be(t.children).forEach(function(e){e.props.selected=o.multiple?-1!=o.defaultValue.indexOf(e.props.value):o.defaultValue==e.props.value}))),t.class&&!t.className?(o.class=t.class,Object.defineProperty(o,"className",xt)):t.className&&(o.class=o.className=t.className),e.props=o}(e),e.$$typeof=ht,kt&&kt(e)};var St=R.__r;R.__r=function(e){St&&St(e),e.__c};var Mt=R.diffed;R.diffed=function(e){Mt&&Mt(e);var t=e.props,n=e.__e;null!=n&&"textarea"===e.type&&"value"in t&&t.value!==n.value&&(n.value=null==t.value?"":t.value)};const Pt="(prefers-color-scheme: dark)";function Ct(e,t){const[n,o]=Ke(()=>"auto"===e&&t&&"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(Pt).matches);return function(e,t){var n=Ze(je++,3);!Le.__s&&tt(n.__H,t)&&(n.__=e,n.u=t,De.__H.__h.push(n))}(()=>{if("auto"!==e||!t||"undefined"==typeof window||"function"!=typeof window.matchMedia)return;const n=window.matchMedia(Pt),r=e=>o(e.matches);return o(n.matches),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[e,t]),"auto"!==e?e:n?"dark":"light"}const It={bell:"M6 10a6 6 0 0 1 12 0c0 4 1.5 5.5 2 6H4c.5-.5 2-2 2-6M10 20a2 2 0 0 0 4 0",gift:"M3 11h18v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1zM2.5 7h19v4h-19zM12 7v14M12 7c-1 0-3-.2-3.5-1a2 2 0 0 1 3.5-1 2 2 0 0 1 3.5 1c-.5.8-2.5 1-3.5 1z",cart:"M2 4h2.2l2.4 11.2A2 2 0 0 0 8.6 17H19M6 7h15l-2.2 7.5H8M10.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M19.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",chart:"M3 21h18M7 21V11M12 21V6M17 21v-8",lock:"M5 11h14v10H5zM8 11V8a4 4 0 0 1 8 0v3",calendar:"M4 6h16v15H4zM4 10h16M9 3v4M15 3v4",check:"M4 13l5 5L20 6",star:"M12 3l2.9 5.9 6.5.9-4.7 4.6 1.1 6.5-5.8-3.1-5.8 3.1 1.1-6.5L2.6 9.8l6.5-.9z",clock:"M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0M12 7v5l4 2",tag:"M20.6 13.4l-7.2 7.2a2 2 0 0 1-2.8 0l-7-7A2 2 0 0 1 3 12.2V5a2 2 0 0 1 2-2h7.2a2 2 0 0 1 1.4.6l7 7a2 2 0 0 1 0 2.8zM9 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0",mail:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M7 2h10a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1M10 19h4",download:"M12 3v12M7 11l5 5 5-5M4 20h16",play:"M8 5l12 7-12 7z",shield:"M12 3l8 3v6c0 5-3.4 8.6-8 10-4.6-1.4-8-5-8-10V6z",sparkle:"M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8zM18 15l.9 2.1 2.1.9-2.1.9-.9 2.1-.9-2.1L15 18l2.1-.9z",percent:"M19 5L5 19M8.5 8.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0M20.5 15.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0",truck:"M2 7h12v10H2zM14 10h4l3 3v4h-7M8.5 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M20 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",ticket:"M4 7h16v4a2 2 0 0 0 0 4v3H4v-3a2 2 0 0 0 0-4zM14 7v12",user:"M20 21a8 8 0 0 0-16 0M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"},At=(Object.keys(It),"0 12px 32px rgba(16, 24, 40, 0.18)");function Ft(e,t){const[n,o]=e.split("-");return{[n]:t,[o]:t}}function zt(e,t){return t?(e?"pw-subw-drop":"pw-subw-rise")+" 0.3s ease-out backwards":void 0}function Ht(e,t,n){const{layout:o,position:r}=e.prompt,i={position:t,zIndex:e.zIndex,boxSizing:"border-box",pointerEvents:"auto"};if("bar"===o)return{...i,left:0,right:0,[r]:0,animation:zt("top"===r,n)};if("modal"===o)return{...i,top:"50%",left:"50%",width:"min(420px, calc(100% - 32px))",transform:"translate(-50%, -50%)",animation:n?"pw-subw-fade 0.25s ease-out backwards":void 0};const l="min(360px, calc(100% - 32px))",s=zt(r.startsWith("top"),n);return"top"===r||"bottom"===r?{...i,[r]:16,left:"50%",width:l,transform:"translateX(-50%)",animation:s}:{...i,...Ft(r,16),width:l,animation:s}}function Tt({label:e,primary:t,colors:n,disabled:o,onClick:r}){return Ee("button",{type:"button",disabled:o,onClick:r,style:{...s(t?"primary":"secondary",n),display:"inline-block",width:"auto",padding:"8px 18px",whiteSpace:"nowrap",opacity:o?.6:1,cursor:o?"default":"pointer"},children:e})}function Et({config:e,variant:t,colors:n,busy:o,onAccept:r,onDecline:i}){const{prompt:l,texts:s}=e,a="bar"===l.layout,c="blocked"===t;return Ee("div",{role:"dialog","aria-label":c?s.blockedTitle:s.title,style:{display:"flex",flexDirection:a?"row":"column",alignItems:a?"center":"stretch",flexWrap:a?"wrap":"nowrap",gap:16,padding:a?"12px 20px":20,boxSizing:"border-box",width:"100%",borderRadius:a?0:l.borderRadius,boxShadow:At,backgroundColor:n.background,color:n.text,fontFamily:e.fontFamily,colorScheme:n.scheme},children:[Ee("div",{style:{display:"flex",alignItems:"flex-start",gap:12,flex:a?"1 1 240px":void 0},children:[l.iconUrl&&Ee("img",{src:l.iconUrl,alt:"",width:48,height:48,style:{flex:"none",borderRadius:8,objectFit:"cover"}}),Ee("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0},children:[Ee("div",{style:{fontSize:16,fontWeight:600,lineHeight:1.4},children:c?s.blockedTitle:s.title}),Ee("div",{style:{fontSize:14,lineHeight:1.5,color:n.textSecondary},children:c?s.blockedMessage:s.message})]})]}),Ee("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,flex:"none"},children:c?Ee(Tt,{label:s.closeText,primary:!0,colors:n,onClick:i}):Ee(ce,{children:[Ee(Tt,{label:s.declineText,primary:!1,colors:n,onClick:i}),Ee(Tt,{label:s.acceptText,primary:!0,colors:n,disabled:o,onClick:r})]})})]})}function jt({config:e,blocked:t,colors:n,onClick:o}){const{size:r}=e.launcher,i=t?e.texts.launcherBlockedLabel:e.texts.launcherLabel,l=Math.round(r/2);return Ee("button",{type:"button","aria-label":i,title:i,onClick:o,style:{display:"flex",alignItems:"center",justifyContent:"center",width:r,height:r,padding:0,border:"none",borderRadius:"50%",backgroundColor:n.accent,color:n.onAccent,boxShadow:At,cursor:"pointer",opacity:t?.7:1},children:Ee("svg",{width:l,height:l,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[Ee("path",{d:It.bell}),t&&Ee("path",{d:"M4 4l16 16"})]})})}function Dt({config:e,permission:t,open:n,mode:o="live",colorScheme:r="auto",busy:i,onAccept:l,onDecline:s,onLauncherClick:a}){const c=C(e,Ct(r,M(e))),_="live"===o,u=_?"fixed":"absolute",d=W(e,t);return e.enable&&(n||d)?Ee(ce,{children:[_&&Ee("style",{children:"\n@keyframes pw-subw-fade { from { opacity: 0; } }\n@keyframes pw-subw-drop { from { opacity: 0; translate: 0 -16px; } }\n@keyframes pw-subw-rise { from { opacity: 0; translate: 0 16px; } }\n"}),d&&Ee("div",{style:{position:u,zIndex:e.zIndex,pointerEvents:"auto",...Ft(e.launcher.position,e.launcher.offset)},children:Ee(jt,{config:e,blocked:"denied"===t,colors:c,onClick:a})}),n&&e.prompt.overlay&&Ee("div",{style:{position:u,inset:0,zIndex:e.zIndex,backgroundColor:"rgba(16, 24, 40, 0.5)",animation:_?"pw-subw-fade 0.2s ease-out backwards":void 0,pointerEvents:"auto"},onClick:s}),n&&Ee("div",{style:Ht(e,u,_),children:Ee(Et,{config:e,variant:U(t),colors:c,busy:i,onAccept:l,onDecline:s})})]}):null}const Ot="keyValue",Nt="messages",Ut="inboxMessages";function Wt(e,t){return function(n){n.objectStoreNames.contains(e)||t(n)}}const Lt=[Wt(Ot,function(e){e.createObjectStore(Ot,{keyPath:"key"})}),Wt("log",function(e){const t=e.createObjectStore("log",{keyPath:"id",autoIncrement:!0});t.createIndex("environment","environment",{unique:!1}),t.createIndex("date","date",{unique:!1}),t.createIndex("type","type",{unique:!1})}),Wt(Nt,function(e){e.createObjectStore(Nt,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}),Wt(Ut,function(e){const t="status",n=e.createObjectStore(Ut,{keyPath:"inbox_id",autoIncrement:!1});n.createIndex(t,t,{unique:!1,multiEntry:!0}),n.createIndex("rt","rt",{unique:!1,multiEntry:!0})})];class Rt{get all(){return Lt}}class Bt{constructor(e,t=new Rt){this.db=e,this.migrationsBuilder=t}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.all)}applyMigrationsPack(e){e.forEach(e=>{e(this.db)})}}function Vt(e,t){console.info("onversionchange",t),e.close()}let $t;function qt(e){return($t||($t=new Promise((e,t)=>{const n=indexedDB.open("PUSHWOOSH_SDK_STORE",7);n.onsuccess=n=>{const o=n.target.result;o.onversionchange=Vt.bind(null,o,t),e(o)},n.onerror=()=>t(n.error),n.onupgradeneeded=e=>{const n=e.target.result;n.onversionchange=Vt.bind(null,n,t),new Bt(n).applyMigrations()}})),$t).then(t=>new Promise((n,o)=>e(t,n,o)))}class Gt{_add(e){return qt((t,n,o)=>{const r=t.transaction([this.name],"readwrite").objectStore(this.name).add(e);r.onsuccess=()=>{n(e)},r.onerror=()=>{o(r.error)}}).then(e=>this.getAll().then(t=>{if(Array.isArray(t)){const n=t.map(e=>e.id).sort((e,t)=>e==t?0:e<t?1:-1);if(n.length>this.maxItems)return Promise.all(n.slice(this.maxItems).map(e=>this.delete(e))).then(()=>e)}return e}))}delete(e){return qt((t,n,o)=>{const r=t.transaction([this.name],"readwrite").objectStore(this.name).delete(e);r.onsuccess=()=>{n(r.result)},r.onerror=()=>{o(r.error)}})}getAll(){return qt((e,t,n)=>{const o=[],r=e.transaction(this.name).objectStore(this.name).openCursor();r.onsuccess=e=>{const n=e.target.result;n?(n.value&&o.push(n.value),n.continue()):t(o)},r.onerror=()=>{n(r.error)}})}}Zt=Ot;var Zt;const Kt=new class extends Gt{constructor(){super(...arguments),this.name="log",this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(e,t,n){const o={type:e,environment:this.environment,message:`${t}`,date:new Date};return t instanceof Error&&(o.stack=t.stack),n&&(o.additional=n),this._add(o)}},Xt=(new class extends Gt{constructor(){super(...arguments),this.name=Nt,this.maxItems=25}add(e){return this._add({...e,date:new Date})}},{error:1,info:2,debug:3});let Jt=3;const Qt={setLevel(e){Xt[e]||(e="error"),Jt=Xt[e]},write(e,t,n){return"error"===e?this.error(t):this.info(t),Kt.add(e,t,n)}};Object.keys(Xt).forEach(e=>{const t=Xt[e];Qt[e]=(...n)=>{t<=Jt&&(console.groupCollapsed(e),console.info("",...n),console.trace("trace"),console.groupEnd())}});class Yt{constructor(e){this.permission="unsupported",this.open=!1,this.busy=!1,this.container=null,this.autoShowTimer=null,this.pw=e,this.config=O(e.initParams.subscriptionWidget),this.accept=this.accept.bind(this),this.decline=this.decline.bind(this),this.toggle=this.toggle.bind(this),e.moduleRegistry.subscriptionWidget=this}async run(){const{pw:e,config:t}=this;t.enable&&e.isPushAvailable()&&(this.permission=await this.readPermission(),this.mount(),this.listenSubscriptionChanges(),await this.scheduleAutoShow())}show(){this.container&&N(this.permission)&&!this.open&&(this.open=!0,this.render(),this.pw.dispatchEvent("show-subscription-widget",{}))}hide(){this.open&&(this.open=!1,this.busy=!1,this.render(),this.pw.dispatchEvent("hide-subscription-widget",{}))}toggle(e){e??!this.open?this.show():this.hide()}isVisible(){return this.open}async readPermission(){const e=this.pw.driver?.getPermission();return"denied"===e?"denied":await this.pw.isSubscribed()?"granted":"default"}mount(){const e=document.createElement("div");e.id="pushwoosh-subscription-widget",e.style.position="fixed",e.style.inset="0",e.style.zIndex=String(this.config.zIndex),e.style.pointerEvents="none",document.body.appendChild(e),this.container=document.createElement("div"),e.attachShadow({mode:"open"}).appendChild(this.container),this.render()}render(){this.container&&(this.open||W(this.config,this.permission)?((e,t)=>{He(Ee(Dt,{...t,mode:"live"}),e)})(this.container,{config:this.config,permission:this.permission,open:this.open,busy:this.busy,onAccept:this.accept,onDecline:this.decline,onLauncherClick:this.toggle}):He(null,this.container))}async scheduleAutoShow(){const e=await this.pw.data.getSubscriptionWidgetHistory();(function(e,t,n,o){const{trigger:r,cappingCount:i,cappingInterval:l}=e.display;return!(!e.enable||"auto"!==r||"default"!==t||i>0&&n.shownCount>=i||!(null===n.lastShownAt||o-n.lastShownAt>=36e5*l))})(this.config,this.permission,e,Date.now())&&(this.autoShowTimer=setTimeout(async()=>{this.autoShowTimer=null,this.open||"default"!==this.permission||(this.show(),await this.pw.data.setSubscriptionWidgetHistory(function(e,t){return{shownCount:e.shownCount+1,lastShownAt:t}}(e,Date.now())))},1e3*this.config.display.delay))}async accept(){this.busy=!0,this.render();try{await this.pw.subscribe()}catch(e){Qt.error(e,"Pushwoosh subscription widget: failed to subscribe")}if(this.permission=await this.readPermission(),"denied"===this.permission)return this.busy=!1,void this.render();this.hide()}decline(){this.hide()}listenSubscriptionChanges(){const e=async()=>{this.permission=await this.readPermission(),"granted"===this.permission&&(this.cancelAutoShow(),this.hide()),this.render()};this.pw.addEventHandler("subscribe",e),this.pw.addEventHandler("unsubscribe",e),this.pw.addEventHandler("permission-denied",e)}cancelAutoShow(){null!==this.autoShowTimer&&(clearTimeout(this.autoShowTimer),this.autoShowTimer=null)}}return t})());
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,()=>(()=>{"use strict";const e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{PWSubscriptionWidget:()=>tn});const n=/^(https?:|mailto:|tel:)/i,o="#101828",r="#667085",i="#FFFFFF",l={background:"#FFFFFF",accent:"#2970FF",text:o,textSecondary:r,textInverse:"#FFFFFF"};function s(e,t){return{display:"block",boxSizing:"border-box",width:"100%",padding:"10px 25px",borderRadius:6,fontSize:14,fontWeight:600,fontFamily:"inherit",lineHeight:1.5,textAlign:"center",textDecoration:"none",cursor:"pointer",..."secondary"===e?{backgroundColor:t.surface,color:t.accent,border:`1px solid ${t.accent}`}:{backgroundColor:t.accent,color:t.onAccent,border:"none"}}}const a={card:["top","bottom","top-left","top-right","bottom-left","bottom-right"],bar:["top","bottom"],modal:["center"]},c=Object.keys(a),u=["bottom-right","bottom-left","top-right","top-left"],_=["auto","launcher","manual"],d={delay:[0,3600],cappingCount:[0,100],cappingInterval:[0,8760],borderRadius:[0,32],offset:[0,100],launcherSize:[16,200],zIndex:[0,2147483647]},p={enable:!1,prompt:{enabled:!1,layout:"card",position:"top",borderRadius:12,overlay:!1},launcher:{enabled:!1,position:"bottom-right",offset:20,width:48,height:48},display:{trigger:"auto",delay:5,cappingCount:3,cappingInterval:4},texts:{title:"Stay in the loop",message:"Allow notifications to get our news and special offers first.",acceptText:"Allow",declineText:"Not now",closeText:"Got it",blockedTitle:"Notifications are blocked",blockedMessage:"To get our notifications, allow them for this site in your browser settings.",launcherLabel:"Subscribe to notifications",launcherBlockedLabel:"Notifications are blocked"},colors:l,fontFamily:'Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',zIndex:2147483e3},f=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function h(e){const t=f.exec(e.trim())?.[1];if(!t)return null;const n=3===t.length?t.split("").map(e=>e+e).join(""):t;return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))}function m([e,t,n]){return`#${[e,t,n].map(e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0")).join("")}`}function y(e,t,n){let o=n;return o<0&&(o+=1),o>1&&(o-=1),o<1/6?e+6*(t-e)*o:o<.5?t:o<2/3?e+(t-e)*(2/3-o)*6:e}function v(e){return e>.5?.07+.86*(1-e):e}function b(e){return e<.5?.93-e*((.93-.5)/.5):e}function g(e,t){const n=h(e);if(!n)return e;const[o,r,i]=function([e,t,n]){const[o,r,i]=[e/255,t/255,n/255],l=Math.max(o,r,i),s=Math.min(o,r,i),a=(l+s)/2;if(l===s)return[0,0,a];const c=l-s;let u;return u=l===o?(r-i)/c+(r<i?6:0):l===r?(i-o)/c+2:(o-r)/c+4,[u/6,a>.5?c/(2-l-s):c/(l+s),a]}(n);return m(function([e,t,n]){if(0===t){const e=255*n;return[e,e,e]}const o=n<.5?n*(1+t):n+t-n*t,r=2*n-o;return[255*y(r,o,e+1/3),255*y(r,o,e),255*y(r,o,e-1/3)]}([o,r,"fold"===t?v(i):b(i)]))}function w(e,t,n){const o=h(e),r=h(t);return o&&r?m(o.map((e,t)=>e+(r[t]-e)*n)):e}function k(e){const t=h(e);if(!t)return!1;const[n,o,r]=t;return(.299*n+.587*o+.114*r)/255>.6}function x(e){return{background:g(e.background,"fold"),accent:e.accent,text:g(e.text,"lift"),textSecondary:g(e.textSecondary,"lift"),textInverse:e.textInverse}}function S(e,t){return"light"===t?{surface:l.background,surfaceText:o,border:"#D0D5DD",onAccent:i,error:"#D92D20",chromeIcon:r}:{surface:w(e.background,e.text,.08),surfaceText:e.text,border:w(e.background,e.text,.24),onAccent:k(e.accent)?o:i,error:"#FDA29B",chromeIcon:e.textSecondary}}function M(e){return!0===e.dark?.enabled}function C(e,t="light"){return"dark"===t&&M(e)?"dark":"light"}function P(e,t="light"){const n=C(e,t),o="dark"===n?(r=e.colors,i=e.dark,{...x(r),...i?.colors??{}}):e.colors;var r,i;return{...o,scheme:n,...S(o,n)}}function I(e){const t=(e||"").trim();if(t)return t.startsWith("#")||t.startsWith("/")||t.startsWith("?")||n.test(t)?t:void 0}new Set(["STRONG","B","EM","I","U","BR","A"]);function A(e){return"string"==typeof e&&e?e:void 0}function F(e){const t="object"==typeof e.colors&&null!==e.colors?e.colors:{};return{background:A(t.background)??A(e.background)??l.background,accent:A(t.accent)??A(e.accent)??l.accent,text:A(t.text)??l.text,textSecondary:A(t.textSecondary)??l.textSecondary,textInverse:A(t.textInverse)??l.textInverse}}function H(e,t){const n=e.dark;if("object"!=typeof n||null===n)return;const o=n,r="object"==typeof o.colors&&null!==o.colors?o.colors:{},i=x(t),l=function(e){if("object"!=typeof e||null===e)return;const t=e,n=A(t.color);if(!n)return;return{color:n,opacity:"number"==typeof t.opacity&&Number.isFinite(t.opacity)?Math.max(0,Math.min(1,t.opacity)):1}}(o.overlay);return{enabled:!0===o.enabled,colors:{background:A(r.background)??i.background,accent:A(r.accent)??i.accent,text:A(r.text)??i.text,textSecondary:A(r.textSecondary)??i.textSecondary,textInverse:A(r.textInverse)??i.textInverse},...l?{overlay:l}:{},...A(o.boxShadow)?{boxShadow:o.boxShadow}:{}}}function z(e){return"object"!=typeof e||null===e||Array.isArray(e)?{}:e}function T(e,t,n){return t.includes(e)?e:n}function E(e,[t,n],o){return"number"==typeof e&&Number.isFinite(e)?Math.max(t,Math.min(n,Math.round(e))):o}function j(e,t){if("string"!=typeof e)return t;const n=e.trim();return n?n.slice(0,300):t}function D(e){const t=I("string"==typeof e?e:void 0);return t&&/^(https?:\/\/|\/)/i.test(t)?t:void 0}function U(e,t){const n="string"==typeof t?t.trim().slice(0,64):"";return n?{[e]:n}:{}}function O(e){const t=p.texts,n=Object.keys(t);return Object.fromEntries(n.map(n=>[n,j(e[n],t[n])]))}function N(e){return"default"===e||"denied"===e}function L(e){return"denied"===e?"blocked":"ask"}function W(e,t){return e.launcher.enabled&&N(t)}var R,B,V,$,q,G,Z,K,X,J,Q,Y,ee,te,ne={},oe=[],re=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ie=Array.isArray;function le(e,t){for(var n in t)e[n]=t[n];return e}function se(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function ae(e,t,n){var o,r,i,l={};for(i in t)"key"==i?o=t[i]:"ref"==i?r=t[i]:l[i]=t[i];if(arguments.length>2&&(l.children=arguments.length>3?R.call(arguments,2):n),"function"==typeof e&&null!=e.defaultProps)for(i in e.defaultProps)void 0===l[i]&&(l[i]=e.defaultProps[i]);return ce(e,l,o,r,null)}function ce(e,t,n,o,r){var i={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:r??++V,__i:-1,__u:0};return null==r&&null!=B.vnode&&B.vnode(i),i}function ue(e){return e.children}function _e(e,t){this.props=e,this.context=t}function de(e,t){if(null==t)return e.__?de(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?de(e):null}function pe(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],i=le({},t);i.__v=t.__v+1,B.vnode&&B.vnode(i),Me(e.__P,i,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n??de(t),!!(32&t.__u),r),i.__v=t.__v,i.__.__k[i.__i]=i,Pe(o,i,r),t.__e=t.__=null,i.__e!=n&&fe(i)}}function fe(e){if(null!=(e=e.__)&&null!=e.__c)return e.__e=e.__c.base=null,e.__k.some(function(t){if(null!=t&&null!=t.__e)return e.__e=e.__c.base=t.__e}),fe(e)}function he(e){(!e.__d&&(e.__d=!0)&&$.push(e)&&!me.__r++||q!=B.debounceRendering)&&((q=B.debounceRendering)||G)(me)}function me(){try{for(var e,t=1;$.length;)$.length>t&&$.sort(Z),e=$.shift(),t=$.length,pe(e)}finally{$.length=me.__r=0}}function ye(e,t,n,o,r,i,l,s,a,c,u){var _,d,p,f,h,m,y=o&&o.__k||oe,v=t.length;for(a=ve(n,t,y,a,v),_=0;_<v;_++)null!=(p=n.__k[_])&&(d=-1!=p.__i&&y[p.__i]||ne,p.__i=_,m=Me(e,p,d,r,i,l,s,a,c,u),f=p.__e,p.ref&&d.ref!=p.ref&&(d.ref&&Fe(d.ref,null,p),u.push(p.ref,p.__c||f,p)),null==h&&null!=f&&(h=f),4&p.__u?(a=be(p,a,e),d.__e&&(d.__e=null)):"function"==typeof p.type&&void 0!==m?a=m:f&&(a=f.nextSibling),p.__u&=-7);return n.__e=h,a}function ve(e,t,n,o,r){var i,l,s,a,c,u=n.length,_=u,d=0;for(e.__k=new Array(r),i=0;i<r;i++)null!=(l=t[i])&&"boolean"!=typeof l&&"function"!=typeof l?("string"==typeof l||"number"==typeof l||"bigint"==typeof l||l.constructor==String?l=e.__k[i]=ce(null,l,null,null,null):ie(l)?l=e.__k[i]=ce(ue,{children:l},null,null,null):void 0===l.constructor&&l.__b>0?l=e.__k[i]=ce(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):e.__k[i]=l,a=i+d,l.__=e,l.__b=e.__b+1,s=null,-1!=(c=l.__i=we(l,n,a,_))&&(_--,(s=n[c])&&(s.__u|=2)),null==s||null==s.__v?(-1==c&&(r>u?d--:r<u&&d++),"function"!=typeof l.type&&(l.__u|=4)):c!=a&&(c==a-1?d--:c==a+1?d++:(c>a?d--:d++,l.__u|=4))):e.__k[i]=null;if(_)for(i=0;i<u;i++)null!=(s=n[i])&&!(2&s.__u)&&(s.__e==o&&(o=de(s)),He(s,s));return o}function be(e,t,n){var o,r;if("function"==typeof e.type){for(o=e.__k,r=0;o&&r<o.length;r++)o[r]&&(o[r].__=e,t=be(o[r],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=de(e)),t=n.insertBefore(e.__e,t||null));do{t=t&&t.nextSibling}while(null!=t&&8==t.nodeType);return t}function ge(e,t){return t=t||[],null==e||"boolean"==typeof e||(ie(e)?e.some(function(e){ge(e,t)}):t.push(e)),t}function we(e,t,n,o){var r,i,l,s=e.key,a=e.type,c=t[n],u=null!=c&&!(2&c.__u);if(null===c&&null==s||u&&s==c.key&&a==c.type)return n;if(o>(u?1:0))for(r=n-1,i=n+1;r>=0||i<t.length;)if(null!=(c=t[l=r>=0?r--:i++])&&!(2&c.__u)&&s==c.key&&a==c.type)return l;return-1}function ke(e,t,n){"-"==t[0]?e.setProperty(t,n??""):e[t]=null==n?"":"number"!=typeof n||re.test(t)?n:n+"px"}function xe(e,t,n,o,r){var i,l;e:if("style"==t)if("string"==typeof n)e.style.cssText=n;else{if("string"==typeof o&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||ke(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||ke(e.style,t,n[t])}else if("o"==t[0]&&"n"==t[1])i=t!=(t=t.replace(Q,"$1")),l=t.toLowerCase(),t=l in e||"onFocusOut"==t||"onFocusIn"==t?l.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+i]=n,n?o?n[J]=o[J]:(n[J]=Y,e.addEventListener(t,i?te:ee,i)):e.removeEventListener(t,i?te:ee,i);else{if("http://www.w3.org/2000/svg"==r)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=t&&"height"!=t&&"href"!=t&&"list"!=t&&"form"!=t&&"tabIndex"!=t&&"download"!=t&&"rowSpan"!=t&&"colSpan"!=t&&"role"!=t&&"popover"!=t&&t in e)try{e[t]=n??"";break e}catch(e){}"function"==typeof n||(null==n||!1===n&&"-"!=t[4]?e.removeAttribute(t):e.setAttribute(t,"popover"==t&&1==n?"":n))}}function Se(e){return function(t){if(this.l){var n=this.l[t.type+e];if(null==t[X])t[X]=Y++;else if(t[X]<n[J])return;return n(B.event?B.event(t):t)}}}function Me(e,t,n,o,r,i,l,s,a,c){var u,_,d,p,f,h,m,y,v,b,g,w,k,x,S,M,C=t.type;if(void 0!==t.constructor)return null;128&n.__u&&(a=!!(32&n.__u),i=[s=t.__e=n.__e]),(u=B.__b)&&u(t);e:if("function"==typeof C){_=l.length;try{if(v=t.props,b=C.prototype&&C.prototype.render,g=(u=C.contextType)&&o[u.__c],w=u?g?g.props.value:u.__:o,n.__c?y=(d=t.__c=n.__c).__=d.__E:(b?t.__c=d=new C(v,w):(t.__c=d=new _e(v,w),d.constructor=C,d.render=ze),g&&g.sub(d),d.state||(d.state={}),d.__n=o,p=d.__d=!0,d.__h=[],d._sb=[]),b&&null==d.__s&&(d.__s=d.state),b&&null!=C.getDerivedStateFromProps&&(d.__s==d.state&&(d.__s=le({},d.__s)),le(d.__s,C.getDerivedStateFromProps(v,d.__s))),f=d.props,h=d.state,d.__v=t,p)b&&null==C.getDerivedStateFromProps&&null!=d.componentWillMount&&d.componentWillMount(),b&&null!=d.componentDidMount&&d.__h.push(d.componentDidMount);else{if(b&&null==C.getDerivedStateFromProps&&v!==f&&null!=d.componentWillReceiveProps&&d.componentWillReceiveProps(v,w),t.__v==n.__v||!d.__e&&null!=d.shouldComponentUpdate&&!1===d.shouldComponentUpdate(v,d.__s,w)){t.__v!=n.__v&&(d.props=v,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),oe.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&l.push(d),s=de(n);break e}null!=d.componentWillUpdate&&d.componentWillUpdate(v,d.__s,w),b&&null!=d.componentDidUpdate&&d.__h.push(function(){d.componentDidUpdate(f,h,m)})}if(d.context=w,d.props=v,d.__P=e,d.__e=!1,k=B.__r,x=0,b)d.state=d.__s,d.__d=!1,k&&k(t),u=d.render(d.props,d.state,d.context),oe.push.apply(d.__h,d._sb),d._sb=[];else do{d.__d=!1,k&&k(t),u=d.render(d.props,d.state,d.context),d.state=d.__s}while(d.__d&&++x<25);d.state=d.__s,null!=d.getChildContext&&(o=le(le({},o),d.getChildContext())),b&&!p&&null!=d.getSnapshotBeforeUpdate&&(m=d.getSnapshotBeforeUpdate(f,h)),S=null!=u&&u.type===ue&&null==u.key?Ie(u.props.children):u,s=ye(e,ie(S)?S:[S],t,n,o,r,i,l,s,a,c),d.base=t.__e,t.__u&=-161,d.__h.length&&l.push(d),y&&(d.__E=d.__=null)}catch(e){if(l.length=_,t.__v=null,a||null!=i){if(e.then){for(t.__u|=a?160:128;s&&8==s.nodeType&&s.nextSibling;)s=s.nextSibling;null!=i&&(i[i.indexOf(s)]=null),t.__e=s}else if(null!=i)for(M=i.length;M--;)se(i[M])}else t.__e=n.__e;null==t.__k&&(t.__k=n.__k||[]),e.then||Ce(t),B.__e(e,t,n)}}else null==i&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):s=t.__e=Ae(n.__e,t,n,o,r,i,l,a,c);return(u=B.diffed)&&u(t),128&t.__u?void 0:s}function Ce(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Ce))}function Pe(e,t,n){for(var o=0;o<n.length;o++)Fe(n[o],n[++o],n[++o]);B.__c&&B.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){B.__e(e,t.__v)}})}function Ie(e){return"object"!=typeof e||null==e||e.__b>0?e:ie(e)?e.map(Ie):void 0!==e.constructor?null:le({},e)}function Ae(e,t,n,o,r,i,l,s,a){var c,u,_,d,p,f,h,m=n.props||ne,y=t.props,v=t.type;if("svg"==v?r="http://www.w3.org/2000/svg":"math"==v?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),null!=i)for(c=0;c<i.length;c++)if((p=i[c])&&"setAttribute"in p==!!v&&(v?p.localName==v:3==p.nodeType)){e=p,i[c]=null;break}if(null==e){if(null==v)return document.createTextNode(y);e=document.createElementNS(r,v,y.is&&y),s&&(B.__m&&B.__m(t,i),s=!1),i=null}if(null==v)m===y||s&&e.data==y||(e.data=y);else{if(i="textarea"==v&&null!=y.defaultValue?null:i&&R.call(e.childNodes),!s&&null!=i)for(m={},c=0;c<e.attributes.length;c++)m[(p=e.attributes[c]).name]=p.value;for(c in m)p=m[c],"dangerouslySetInnerHTML"==c?_=p:"children"==c||c in y||"value"==c&&"defaultValue"in y||"checked"==c&&"defaultChecked"in y||xe(e,c,null,p,r);for(c in y)p=y[c],"children"==c?d=p:"dangerouslySetInnerHTML"==c?u=p:"value"==c?f=p:"checked"==c?h=p:s&&"function"!=typeof p||m[c]===p||xe(e,c,p,m[c],r);if(u)s||_&&(u.__html==_.__html||u.__html==e.innerHTML)||(e.innerHTML=u.__html),t.__k=[];else if(_&&(e.innerHTML=""),ye("template"==t.type?e.content:e,ie(d)?d:[d],t,n,o,"foreignObject"==v?"http://www.w3.org/1999/xhtml":r,i,l,i?i[0]:n.__k&&de(n,0),s,a),null!=i)for(c=i.length;c--;)se(i[c]);s&&"textarea"!=v||(c="value","progress"==v&&null==f?e.removeAttribute("value"):null!=f&&(f!==e[c]||"progress"==v&&!f||"option"==v&&f!=m[c])&&xe(e,c,f,m[c],r),c="checked",null!=h&&h!=e[c]&&xe(e,c,h,m[c],r))}return e}function Fe(e,t,n){try{if("function"==typeof e){var o="function"==typeof e.__u;o&&e.__u(),o&&null==t||(e.__u=e(t))}else e.current=t}catch(e){B.__e(e,n)}}function He(e,t,n){var o,r;if(B.unmount&&B.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Fe(o,null,t)),null!=(o=e.__c)){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(e){B.__e(e,t)}o.base=o.__P=o.__n=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&He(o[r],t,n||"function"!=typeof e.type);n||se(e.__e),e.__c=e.__=e.__e=void 0}function ze(e,t,n){return this.constructor(e,n)}function Te(e,t,n){var o,r,i,l;t==document&&(t=document.documentElement),B.__&&B.__(e,t),r=(o="function"==typeof n)?null:n&&n.__k||t.__k,i=[],l=[],Me(t,e=(!o&&n||t).__k=ae(ue,null,[e]),r||ne,ne,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?R.call(t.childNodes):null,i,!o&&n?n:r?r.__e:t.firstChild,o,l),Pe(i,e,l),e.props.children=null}R=oe.slice,B={__e:function(e,t,n,o){for(var r,i,l;t=t.__;)if((r=t.__c)&&!r.__)try{if((i=r.constructor)&&null!=i.getDerivedStateFromError&&(r.setState(i.getDerivedStateFromError(e)),l=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(e,o||{}),l=r.__d),l)return r.__E=r}catch(t){e=t}throw e}},V=0,_e.prototype.setState=function(e,t){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=le({},this.state),"function"==typeof e&&(e=e(le({},n),this.props)),e&&le(n,e),null!=e&&this.__v&&(t&&this._sb.push(t),he(this))},_e.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),he(this))},_e.prototype.render=ue,$=[],G="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Z=function(e,t){return e.__v.__b-t.__v.__b},me.__r=0,K=Math.random().toString(8),X="__d"+K,J="__a"+K,Q=/(PointerCapture)$|Capture$/i,Y=0,ee=Se(!1),te=Se(!0);var Ee=0;Array.isArray;function je(e,t,n,o,r,i){t||(t={});var l,s,a=t;if("ref"in a)for(s in a={},t)"ref"==s?l=t[s]:a[s]=t[s];var c={type:e,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ee,__i:-1,__u:0,__source:r,__self:i};if("function"==typeof e&&(l=e.defaultProps))for(s in l)void 0===a[s]&&(a[s]=l[s]);return B.vnode&&B.vnode(c),c}var De,Ue,Oe,Ne,Le=0,We=[],Re=B,Be=Re.__b,Ve=Re.__r,$e=Re.diffed,qe=Re.__c,Ge=Re.unmount,Ze=Re.__;function Ke(e,t){Re.__h&&Re.__h(Ue,e,Le||t),Le=0;var n=Ue.__H||(Ue.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function Xe(e){return Le=1,function(e,t,n){var o=Ke(De++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):ot(void 0,t),function(e){var t=o.__N?o.__N[0]:o.__[0],n=o.t(t,e);t!==n&&(o.__N=[n,o.__[1]],o.__c.setState({}))}],o.__c=Ue,!Ue.__f)){var r=function(e,t,n){if(!o.__c.__H)return!0;var r=!1,l=o.__c.props!==e;if(o.__c.__H.__.some(function(e){if(e.__N){r=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(l=!0)}}),i){var s=i.call(this,e,t,n);return r?s||l:s}return!r||l};Ue.__f=!0;var i=Ue.shouldComponentUpdate,l=Ue.componentWillUpdate;Ue.componentWillUpdate=function(e,t,n){if(this.__e){var o=i;i=void 0,r(e,t,n),i=o}l&&l.call(this,e,t,n)},Ue.shouldComponentUpdate=r}return o.__N||o.__}(ot,e)}function Je(){for(var e;e=We.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(et),t.__h.some(tt),t.__h=[]}catch(n){t.__h=[],Re.__e(n,e.__v)}}}Re.__b=function(e){Ue=null,Be&&Be(e)},Re.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ze&&Ze(e,t)},Re.__r=function(e){Ve&&Ve(e),De=0;var t=(Ue=e.__c).__H;t&&(Oe===Ue?(t.__h=[],Ue.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(et),t.__h.some(tt),t.__h=[],De=0)),Oe=Ue},Re.diffed=function(e){$e&&$e(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(1!==We.push(t)&&Ne===Re.requestAnimationFrame||((Ne=Re.requestAnimationFrame)||Ye)(Je)),t.__H.__.some(function(e){e.u&&(e.__H=e.u,e.u=void 0)})),Oe=Ue=null},Re.__c=function(e,t){t.some(function(e){try{e.__h.some(et),e.__h=e.__h.filter(function(e){return!e.__||tt(e)})}catch(n){t.some(function(e){e.__h&&(e.__h=[])}),t=[],Re.__e(n,e.__v)}}),qe&&qe(e,t)},Re.unmount=function(e){Ge&&Ge(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{et(e)}catch(e){t=e}}),n.__H=void 0,t&&Re.__e(t,n.__v))};var Qe="function"==typeof requestAnimationFrame;function Ye(e){var t,n=function(){clearTimeout(o),Qe&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Qe&&(t=requestAnimationFrame(n))}function et(e){var t=Ue,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),Ue=t}function tt(e){var t=Ue;e.__c=e.__(),Ue=t}function nt(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function ot(e,t){return"function"==typeof t?t(e):t}function rt(e,t){for(var n in t)e[n]=t[n];return e}function it(e,t){for(var n in e)if("__source"!==n&&!(n in t))return!0;for(var o in t)if("__source"!==o&&e[o]!==t[o])return!0;return!1}function lt(e,t){this.props=e,this.context=t}(lt.prototype=new _e).isPureReactComponent=!0,lt.prototype.shouldComponentUpdate=function(e,t){return it(this.props,e)||it(this.state,t)};var st=B.__b;B.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),st&&st(e)};"undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.forward_ref");var at=B.__e;B.__e=function(e,t,n,o){if(e.then)for(var r,i=t;i=i.__;)if((r=i.__c)&&r.__c)return null==t.__e&&(t.__e=n.__e,t.__k=n.__k||[]),r.__c(e,t);at(e,t,n,o)};var ct=B.unmount;function ut(e,t,n){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(e){"function"==typeof e.__c&&e.__c()}),e.__c.__H=null),null!=(e=rt({},e)).__c&&(e.__c.__P===n&&(e.__c.__P=t),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(e){return ut(e,t,n)})),e}function _t(e,t,n){return e&&n&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(e){return _t(e,t,n)}),e.__c&&e.__c.__P===t&&(e.__e&&n.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=n)),e}function dt(){this.__u=0,this.o=null,this.__b=null}function pt(e){var t=e.__&&e.__.__c;return t&&t.__a&&t.__a(e)}function ft(){this.i=null,this.l=null}B.unmount=function(e){var t=e.__c;t&&(t.__z=!0),t&&t.__R&&t.__R(),t&&32&e.__u&&(e.type=null),ct&&ct(e)},(dt.prototype=new _e).__c=function(e,t){var n=t.__c,o=this;null==o.o&&(o.o=[]),o.o.push(n);var r=pt(o.__v),i=!1,l=function(){i||o.__z||(i=!0,n.__R=null,r?r(a):a())};n.__R=l;var s=n.__P;n.__P=null;var a=function(){if(! --o.__u){if(o.state.__a){var e=o.state.__a;o.__v.__k[0]=_t(e,e.__c.__P,e.__c.__O)}var t;for(o.setState({__a:o.__b=null});t=o.o.pop();)t.__P=s,t.forceUpdate()}};o.__u++||32&t.__u||o.setState({__a:o.__b=o.__v.__k[0]}),e.then(l,l)},dt.prototype.componentWillUnmount=function(){this.o=[]},dt.prototype.render=function(e,t){if(this.__b){if(this.__v.__k){var n=document.createElement("div"),o=this.__v.__k[0].__c;this.__v.__k[0]=ut(this.__b,n,o.__O=o.__P)}this.__b=null}var r=t.__a&&ae(ue,null,e.fallback);return r&&(r.__u&=-33),[ae(ue,null,t.__a?null:e.children),r]};var ht=function(e,t,n){if(++n[1]===n[0]&&e.l.delete(t),e.props.revealOrder&&("t"!==e.props.revealOrder[0]||!e.l.size))for(n=e.i;n;){for(;n.length>3;)n.pop()();if(n[1]<n[0])break;e.i=n=n[2]}};(ft.prototype=new _e).__a=function(e){var t=this,n=pt(t.__v),o=t.l.get(e);return o[0]++,function(r){var i=function(){t.props.revealOrder?(o.push(r),ht(t,e,o)):r()};n?n(i):i()}},ft.prototype.render=function(e){this.i=null,this.l=new Map;var t=ge(e.children);e.revealOrder&&"b"===e.revealOrder[0]&&t.reverse();for(var n=t.length;n--;)this.l.set(t[n],this.i=[1,0,this.i]);return e.children},ft.prototype.componentDidUpdate=ft.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(t,n){ht(e,n,t)})};var mt="undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,yt=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,vt=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,bt=/[A-Z0-9]/g,gt="undefined"!=typeof document,wt=function(e){return("undefined"!=typeof Symbol&&"symbol"==typeof Symbol()?/fil|che|rad/:/fil|che|ra/).test(e)};_e.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(_e.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:t})}})});var kt=B.event;B.event=function(e){return kt&&(e=kt(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var xt={configurable:!0,get:function(){return this.class}},St=B.vnode;B.vnode=function(e){"string"==typeof e.type&&function(e){var t=e.props,n=e.type,o={},r=-1==n.indexOf("-");for(var i in t){var l=t[i];if(!("value"===i&&"defaultValue"in t&&null==l||gt&&"children"===i&&"noscript"===n||"class"===i||"className"===i)){var s=i.toLowerCase();"defaultValue"===i&&"value"in t&&null==t.value?i="value":"download"===i&&!0===l?l="":"translate"===s&&"no"===l?l=!1:"o"===s[0]&&"n"===s[1]?"ondoubleclick"===s?i="ondblclick":"onchange"!==s||"input"!==n&&"textarea"!==n||wt(t.type)?"onfocus"===s?i="onfocusin":"onblur"===s?i="onfocusout":vt.test(i)&&(i=s):s=i="oninput":r&&yt.test(i)?i=i.replace(bt,"-$&").toLowerCase():null===l&&(l=void 0),"oninput"===s&&o[i=s]&&(i="oninputCapture"),o[i]=l}}"select"==n&&(o.multiple&&Array.isArray(o.value)&&(o.value=ge(t.children).forEach(function(e){e.props.selected=-1!=o.value.indexOf(e.props.value)})),null!=o.defaultValue&&(o.value=ge(t.children).forEach(function(e){e.props.selected=o.multiple?-1!=o.defaultValue.indexOf(e.props.value):o.defaultValue==e.props.value}))),t.class&&!t.className?(o.class=t.class,Object.defineProperty(o,"className",xt)):t.className&&(o.class=o.className=t.className),e.props=o}(e),e.$$typeof=mt,St&&St(e)};var Mt=B.__r;B.__r=function(e){Mt&&Mt(e),e.__c};var Ct=B.diffed;B.diffed=function(e){Ct&&Ct(e);var t=e.props,n=e.__e;null!=n&&"textarea"===e.type&&"value"in t&&t.value!==n.value&&(n.value=null==t.value?"":t.value)};const Pt="(prefers-color-scheme: dark)";function It(e,t){const[n,o]=Xe(()=>"auto"===e&&t&&"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(Pt).matches);return function(e,t){var n=Ke(De++,3);!Re.__s&&nt(n.__H,t)&&(n.__=e,n.u=t,Ue.__H.__h.push(n))}(()=>{if("auto"!==e||!t||"undefined"==typeof window||"function"!=typeof window.matchMedia)return;const n=window.matchMedia(Pt),r=e=>o(e.matches);return o(n.matches),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[e,t]),"auto"!==e?e:n?"dark":"light"}const At={bell:"M6 10a6 6 0 0 1 12 0c0 4 1.5 5.5 2 6H4c.5-.5 2-2 2-6M10 20a2 2 0 0 0 4 0",gift:"M3 11h18v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1zM2.5 7h19v4h-19zM12 7v14M12 7c-1 0-3-.2-3.5-1a2 2 0 0 1 3.5-1 2 2 0 0 1 3.5 1c-.5.8-2.5 1-3.5 1z",cart:"M2 4h2.2l2.4 11.2A2 2 0 0 0 8.6 17H19M6 7h15l-2.2 7.5H8M10.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M19.5 20a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",chart:"M3 21h18M7 21V11M12 21V6M17 21v-8",lock:"M5 11h14v10H5zM8 11V8a4 4 0 0 1 8 0v3",calendar:"M4 6h16v15H4zM4 10h16M9 3v4M15 3v4",check:"M4 13l5 5L20 6",star:"M12 3l2.9 5.9 6.5.9-4.7 4.6 1.1 6.5-5.8-3.1-5.8 3.1 1.1-6.5L2.6 9.8l6.5-.9z",clock:"M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0M12 7v5l4 2",tag:"M20.6 13.4l-7.2 7.2a2 2 0 0 1-2.8 0l-7-7A2 2 0 0 1 3 12.2V5a2 2 0 0 1 2-2h7.2a2 2 0 0 1 1.4.6l7 7a2 2 0 0 1 0 2.8zM9 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0",mail:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M7 2h10a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1M10 19h4",download:"M12 3v12M7 11l5 5 5-5M4 20h16",play:"M8 5l12 7-12 7z",shield:"M12 3l8 3v6c0 5-3.4 8.6-8 10-4.6-1.4-8-5-8-10V6z",sparkle:"M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8zM18 15l.9 2.1 2.1.9-2.1.9-.9 2.1-.9-2.1L15 18l2.1-.9z",percent:"M19 5L5 19M8.5 8.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0M20.5 15.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0",truck:"M2 7h12v10H2zM14 10h4l3 3v4h-7M8.5 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M20 19a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0",ticket:"M4 7h16v4a2 2 0 0 0 0 4v3H4v-3a2 2 0 0 0 0-4zM14 7v12",user:"M20 21a8 8 0 0 0-16 0M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"},Ft=(Object.keys(At),"0 12px 32px rgba(16, 24, 40, 0.18)");function Ht(e,t){const[n,o]=e.split("-");return{[n]:t,[o]:t}}function zt(e,t){return t?(e?"pw-subw-drop":"pw-subw-rise")+" 0.3s ease-out backwards":void 0}function Tt(e,t,n){const{layout:o,position:r}=e.prompt,i={position:t,zIndex:e.zIndex,boxSizing:"border-box",pointerEvents:"auto"};if("bar"===o)return{...i,left:0,right:0,[r]:0,animation:zt("top"===r,n)};if("modal"===o)return{...i,top:"50%",left:"50%",width:"min(420px, calc(100% - 32px))",transform:"translate(-50%, -50%)",animation:n?"pw-subw-fade 0.25s ease-out backwards":void 0};const l="min(360px, calc(100% - 32px))",s=zt(r.startsWith("top"),n);return"top"===r||"bottom"===r?{...i,[r]:16,left:"50%",width:l,transform:"translateX(-50%)",animation:s}:{...i,...Ht(r,16),width:l,animation:s}}function Et({label:e,primary:t,colors:n,disabled:o,onClick:r}){return je("button",{type:"button",disabled:o,onClick:r,style:{...s(t?"primary":"secondary",n),display:"inline-block",width:"auto",padding:"8px 18px",whiteSpace:"nowrap",opacity:o?.6:1,cursor:o?"default":"pointer"},children:e})}function jt({config:e,variant:t,colors:n,busy:o,onAccept:r,onDecline:i}){const{prompt:l,texts:s}=e,a="bar"===l.layout,c="blocked"===t;return je("div",{role:"dialog","aria-label":c?s.blockedTitle:s.title,style:{display:"flex",flexDirection:a?"row":"column",alignItems:a?"center":"stretch",flexWrap:a?"wrap":"nowrap",gap:16,padding:a?"12px 20px":20,boxSizing:"border-box",width:"100%",borderRadius:a?0:l.borderRadius,boxShadow:Ft,backgroundColor:n.background,color:n.text,fontFamily:e.fontFamily,colorScheme:n.scheme},children:[je("div",{style:{display:"flex",alignItems:"flex-start",gap:12,flex:a?"1 1 240px":void 0},children:[l.iconUrl&&je("img",{src:l.iconUrl,alt:"",width:48,height:48,style:{flex:"none",borderRadius:8,objectFit:"cover"}}),je("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0},children:[je("div",{style:{fontSize:16,fontWeight:600,lineHeight:1.4},children:c?s.blockedTitle:s.title}),je("div",{style:{fontSize:14,lineHeight:1.5,color:n.textSecondary},children:c?s.blockedMessage:s.message})]})]}),je("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,flex:"none"},children:c?je(Et,{label:s.closeText,primary:!0,colors:n,onClick:i}):je(ue,{children:[je(Et,{label:s.declineText,primary:!1,colors:n,onClick:i}),je(Et,{label:s.acceptText,primary:!0,colors:n,disabled:o,onClick:r})]})})]})}function Dt({config:e,blocked:t,colors:n,onClick:o}){const{width:r,height:i,imageUrl:l}=e.launcher,s=t?e.texts.launcherBlockedLabel:e.texts.launcherLabel,a=Math.round(Math.min(r,i)/2),c={display:"flex",alignItems:"center",justifyContent:"center",width:r,height:i,padding:0,border:"none",cursor:"pointer",opacity:t?.7:1};return je("button",l?{type:"button","aria-label":s,title:s,onClick:o,style:{...c,background:"none"},children:je("img",{src:l,alt:"",width:r,height:i,style:{display:"block",objectFit:"contain"}})}:{type:"button","aria-label":s,title:s,onClick:o,style:{...c,borderRadius:"50%",backgroundColor:e.launcher.background??n.accent,color:e.launcher.iconColor??n.onAccent,boxShadow:Ft},children:je("svg",{width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[je("path",{d:At.bell}),t&&je("path",{d:"M4 4l16 16"})]})})}function Ut({config:e,permission:t,open:n,mode:o="live",colorScheme:r="auto",busy:i,onAccept:l,onDecline:s,onLauncherClick:a}){const c=P(e,It(r,M(e))),u="live"===o,_=u?"fixed":"absolute",d=n&&e.prompt.enabled,p=W(e,t);return d||p?je(ue,{children:[u&&je("style",{children:"\n@keyframes pw-subw-fade { from { opacity: 0; } }\n@keyframes pw-subw-drop { from { opacity: 0; translate: 0 -16px; } }\n@keyframes pw-subw-rise { from { opacity: 0; translate: 0 16px; } }\n"}),d&&e.prompt.overlay&&je("div",{style:{position:_,inset:0,zIndex:e.zIndex,backgroundColor:"rgba(16, 24, 40, 0.5)",animation:u?"pw-subw-fade 0.2s ease-out backwards":void 0,pointerEvents:"auto"},onClick:s}),d&&je("div",{style:Tt(e,_,u),children:je(jt,{config:e,variant:L(t),colors:c,busy:i,onAccept:l,onDecline:s})}),p&&je("div",{style:{position:_,zIndex:e.zIndex,pointerEvents:"auto",...Ht(e.launcher.position,e.launcher.offset)},children:je(Dt,{config:e,blocked:"denied"===t,colors:c,onClick:a})})]}):null}const Ot="keyValue",Nt="messages",Lt="inboxMessages";function Wt(e,t){return function(n){n.objectStoreNames.contains(e)||t(n)}}const Rt=[Wt(Ot,function(e){e.createObjectStore(Ot,{keyPath:"key"})}),Wt("log",function(e){const t=e.createObjectStore("log",{keyPath:"id",autoIncrement:!0});t.createIndex("environment","environment",{unique:!1}),t.createIndex("date","date",{unique:!1}),t.createIndex("type","type",{unique:!1})}),Wt(Nt,function(e){e.createObjectStore(Nt,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}),Wt(Lt,function(e){const t="status",n=e.createObjectStore(Lt,{keyPath:"inbox_id",autoIncrement:!1});n.createIndex(t,t,{unique:!1,multiEntry:!0}),n.createIndex("rt","rt",{unique:!1,multiEntry:!0})})];class Bt{get all(){return Rt}}class Vt{constructor(e,t=new Bt){this.db=e,this.migrationsBuilder=t}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.all)}applyMigrationsPack(e){e.forEach(e=>{e(this.db)})}}function $t(e,t){console.info("onversionchange",t),e.close()}let qt;function Gt(e){return(qt||(qt=new Promise((e,t)=>{const n=indexedDB.open("PUSHWOOSH_SDK_STORE",7);n.onsuccess=n=>{const o=n.target.result;o.onversionchange=$t.bind(null,o,t),e(o)},n.onerror=()=>t(n.error),n.onupgradeneeded=e=>{const n=e.target.result;n.onversionchange=$t.bind(null,n,t),new Vt(n).applyMigrations()}})),qt).then(t=>new Promise((n,o)=>e(t,n,o)))}class Zt{_add(e){return Gt((t,n,o)=>{const r=t.transaction([this.name],"readwrite").objectStore(this.name).add(e);r.onsuccess=()=>{n(e)},r.onerror=()=>{o(r.error)}}).then(e=>this.getAll().then(t=>{if(Array.isArray(t)){const n=t.map(e=>e.id).sort((e,t)=>e==t?0:e<t?1:-1);if(n.length>this.maxItems)return Promise.all(n.slice(this.maxItems).map(e=>this.delete(e))).then(()=>e)}return e}))}delete(e){return Gt((t,n,o)=>{const r=t.transaction([this.name],"readwrite").objectStore(this.name).delete(e);r.onsuccess=()=>{n(r.result)},r.onerror=()=>{o(r.error)}})}getAll(){return Gt((e,t,n)=>{const o=[],r=e.transaction(this.name).objectStore(this.name).openCursor();r.onsuccess=e=>{const n=e.target.result;n?(n.value&&o.push(n.value),n.continue()):t(o)},r.onerror=()=>{n(r.error)}})}}Kt=Ot;var Kt;const Xt=new class extends Zt{constructor(){super(...arguments),this.name="log",this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(e,t,n){const o={type:e,environment:this.environment,message:`${t}`,date:new Date};return t instanceof Error&&(o.stack=t.stack),n&&(o.additional=n),this._add(o)}},Jt=(new class extends Zt{constructor(){super(...arguments),this.name=Nt,this.maxItems=25}add(e){return this._add({...e,date:new Date})}},{error:1,info:2,debug:3});let Qt=3;const Yt={setLevel(e){Jt[e]||(e="error"),Qt=Jt[e]},write(e,t,n){return"error"===e?this.error(t):this.info(t),Xt.add(e,t,n)}};Object.keys(Jt).forEach(e=>{const t=Jt[e];Yt[e]=(...n)=>{t<=Qt&&(console.groupCollapsed(e),console.info("",...n),console.trace("trace"),console.groupEnd())}});const en="Pushwoosh subscription widget:";class tn{constructor(e){this.permission="unsupported",this.open=!1,this.busy=!1,this.container=null,this.autoShowTimer=null,this.pw=e,this.config=function(e){const t=p,n=z(e),o=z(n.prompt),r=z(n.launcher),i=z(n.display),l=d,s=T(o.layout,c,t.prompt.layout),f=a[s],h=T(i.trigger,_,t.display.trigger),m=D(o.iconUrl),y=D(r.imageUrl),v=F({colors:n.colors}),b=H({dark:n.dark},v),g=!0===o.enabled,w=!0===r.enabled;return{enable:g||w,prompt:{enabled:g,layout:s,position:T(o.position,f,f[0]),...m?{iconUrl:m}:{},borderRadius:E(o.borderRadius,l.borderRadius,t.prompt.borderRadius),overlay:"modal"===s||!0===o.overlay},launcher:{enabled:w,position:T(r.position,u,t.launcher.position),offset:E(r.offset,l.offset,t.launcher.offset),width:E(r.width,l.launcherSize,t.launcher.width),height:E(r.height,l.launcherSize,t.launcher.height),...y?{imageUrl:y}:{},...U("background",r.background),...U("iconColor",r.iconColor)},display:{trigger:h,delay:E(i.delay,l.delay,t.display.delay),cappingCount:E(i.cappingCount,l.cappingCount,t.display.cappingCount),cappingInterval:E(i.cappingInterval,l.cappingInterval,t.display.cappingInterval)},texts:O(z(n.texts)),colors:v,...b?{dark:b}:{},fontFamily:j(n.fontFamily,t.fontFamily),zIndex:E(n.zIndex,l.zIndex,t.zIndex)}}(e.initParams.subscriptionWidget),this.accept=this.accept.bind(this),this.decline=this.decline.bind(this),this.toggle=this.toggle.bind(this),this.launcherClick=this.launcherClick.bind(this),e.moduleRegistry.subscriptionWidget=this}async run(){const{pw:e,config:t}=this;t.enable&&e.isPushAvailable()&&(this.permission=await this.readPermission(),this.mount(),this.listenSubscriptionChanges(),await this.scheduleAutoShow())}show(){this.container&&this.config.prompt.enabled&&N(this.permission)&&!this.open&&(this.open=!0,this.render(),this.pw.dispatchEvent("show-subscription-widget",{}))}hide(){this.open&&(this.open=!1,this.busy=!1,this.render(),this.pw.dispatchEvent("hide-subscription-widget",{}))}toggle(e){e??!this.open?this.show():this.hide()}isVisible(){return this.open}async readPermission(){const e=this.pw.driver?.getPermission();return"denied"===e?"denied":await this.pw.isSubscribed()?"granted":"default"}mount(){const e=document.createElement("div");e.id="pushwoosh-subscription-widget",e.style.position="fixed",e.style.inset="0",e.style.zIndex=String(this.config.zIndex),e.style.pointerEvents="none",document.body.appendChild(e),this.container=document.createElement("div"),e.attachShadow({mode:"open"}).appendChild(this.container),this.render()}render(){this.container&&(this.open||W(this.config,this.permission)?((e,t)=>{Te(je(Ut,{...t,mode:"live"}),e)})(this.container,{config:this.config,permission:this.permission,open:this.open,busy:this.busy,onAccept:this.accept,onDecline:this.decline,onLauncherClick:this.launcherClick}):Te(null,this.container))}async scheduleAutoShow(){const e=await this.pw.data.getSubscriptionWidgetHistory();(function(e,t,n,o){const{trigger:r,cappingCount:i,cappingInterval:l}=e.display;return!(!e.prompt.enabled||"auto"!==r||"default"!==t||i>0&&n.shownCount>=i||!(null===n.lastShownAt||o-n.lastShownAt>=36e5*l))})(this.config,this.permission,e,Date.now())&&(this.autoShowTimer=setTimeout(async()=>{this.autoShowTimer=null,this.open||"default"!==this.permission||(this.show(),await this.pw.data.setSubscriptionWidgetHistory(function(e,t){return{shownCount:e.shownCount+1,lastShownAt:t}}(e,Date.now())))},1e3*this.config.display.delay))}launcherClick(){const e=(t=this.config,n=this.permission,t.prompt.enabled?"prompt":"default"===n?"subscribe":"none");var t,n;"prompt"===e?this.toggle():"subscribe"===e&&this.subscribeFromLauncher()}async subscribeFromLauncher(){try{await this.pw.subscribe()}catch(e){Yt.error(e,`${en} failed to subscribe`)}this.permission=await this.readPermission(),this.render()}async accept(){this.busy=!0,this.render();try{await this.pw.subscribe()}catch(e){Yt.error(e,`${en} failed to subscribe`)}if(this.permission=await this.readPermission(),"denied"===this.permission)return this.busy=!1,void this.render();this.hide()}decline(){this.hide()}listenSubscriptionChanges(){const e=async()=>{this.permission=await this.readPermission(),"granted"===this.permission&&(this.cancelAutoShow(),this.hide()),this.render()};this.pw.addEventHandler("subscribe",e),this.pw.addEventHandler("unsubscribe",e),this.pw.addEventHandler("permission-denied",e)}cancelAutoShow(){null!==this.autoShowTimer&&(clearTimeout(this.autoShowTimer),this.autoShowTimer=null)}}return t})());
2
2
  //# sourceMappingURL=widget-subscription.js.map