@abtasty/popin-simple 1.5.6 → 1.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/main.js +1 -1
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- !function(){"use strict";const e=()=>Object.prototype.hasOwnProperty.call(window,"ABTastyEditor"),t=()=>{const e=!!document.getElementById("ABTastyPreviewBar"),t=location.href.includes("ab_project=preview");return e||t},i=()=>!e()&&(t()||!!window.ABTasty.getTestsOnPage()[TEST_ID]),n=()=>window.ABTasty&&!0===window.ABTasty.consentReady,s=(e,t)=>{const i=()=>{try{return document.querySelector(e)}catch(e){return null}};let n=i();const s=[document.body||document.documentElement,{childList:!0,subtree:!0,attributes:!0}],r=()=>a.disconnect(),o=()=>a.observe(...s),a=new MutationObserver(()=>(n=i(),n&&!r()&&t(n)));return n?setTimeout(()=>t(n),0):o(),{selector:e,clear:r,observe:o}};function r(e,t){return t(e)||!e.parentElement?e:r(e.parentElement,t)}const o=t=>{e()||(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation())},a=(e,t)=>[...document.querySelectorAll(t)].some(i=>i.isSameNode(e)||!!e.closest(t)),c="remove",l="rebuild",h="update",d=()=>{const{type:e}=DATA;return`${PACKAGE.replace("@abtasty/","")}${e?`_${e}`:""}`},u=()=>{const e=d();return`${e.charAt(0).toUpperCase()}${e.slice(1)}`.split("-").join(" ")},g=()=>`${PLUGIN_ID.split("-")[0]}_${TEST_ID}`,m=i=>{if((()=>{if(e()||t())return!1;const i=ABTasty.getTestsOnPage()[TEST_ID];return!!i&&Object.keys(i.targetings.qaParameters).length>0})()){const e=u();window.console.log(`%c${e} - QA Mode for campaign ${TEST_ID}\n${i}`,"background-color: rgba(0, 127, 145, 1); color: rgba(247, 247, 247, 1)")}},p=e=>{const t={promise:null,resolve:null,reject:null,name:e};return t.promise=new Promise((e,i)=>{t.resolve=e,t.reject=i}),t};class v{constructor(){this.targets=[],this.existingTargets=[],this.inViewportTargets=[],this.visibilityObserver=this.startVisibilityObserver(),this.mutationObserver=this.startMutationObserver(),this.mouseOverEvent=this.mouseOverHandler()}intersectionHandler(e){e.forEach(e=>{e.isIntersecting?(this.existingTargets.forEach(t=>{t.element.isSameNode(e.target)&&(this.inViewportTargets.push(t),this.mouseOverEvent.start())}),this.checkElements()):this.inViewportTargets=this.inViewportTargets.filter(t=>!t.element.isSameNode(e.target)||(this.mouseOverEvent.clear(),!1))})}startVisibilityObserver(){return new IntersectionObserver(this.intersectionHandler.bind(this),{root:null,rootMargin:"0px",threshold:0})}startMutationObserver(){const e=this.mutationObserver||new MutationObserver(this.checkElements.bind(this));return document.body&&e.observe(document.body,{attributes:!0,childList:!0,subtree:!0}),e}onMouseOver({target:e,path:t}){const i=this.inViewportTargets.find(({element:i,selector:n})=>{if(i.isSameNode(e))return!0;const s=[...e.querySelectorAll(n)];if(s.length&&s.includes(i))return!0;if(t.includes(i))return!0;const r=[...e.parentElement.children],o=r.findIndex(t=>t.isSameNode(e)),a=r.filter((e,t)=>t>o);if(a.length){if(a.includes(i))return!0;if(a.some(e=>[...e.querySelectorAll(n)].includes(i)))return!0}return!1});if(i&&this.isElementVisible(i.element)){const{selector:e,element:t,uniqueId:n}=i,s=this.targets.find(t=>t.selector===e&&t.uniqueId===n);s&&s.resolve(t),this.clear(e,n)}}mouseOverHandler(){const e=["mouseover",e=>setTimeout(()=>this.onMouseOver(e),50),!0];return{start:()=>document.addEventListener(...e),clear:()=>document.removeEventListener(...e)}}isElementVisible(e){return this.isElementTopmost(e)&&this.isElementOpaque(e)}isElementOpaque(e){return"HTML"===r(e,e=>"0"===window.getComputedStyle(e).opacity).nodeName}isElementTopmost(e){const t=e.getBoundingClientRect(),i=[[t.left,t.top],[t.right,t.top],[t.left,t.bottom],[t.right,t.bottom],[t.left+t.width/2,t.top],[t.left+t.width/2,t.bottom],[t.left,t.height/2],[t.right,t.height/2],[t.left+t.left/2,t.height/2]];let n=!1,s=0;for(;!n&&s<i.length;){const t=document.elementFromPoint(...i[s]);n=e===t||e.contains(t),s+=1}return n}checkElements(){this.targets.forEach(({selector:e,uniqueId:t})=>{const i=document.querySelector(e);i&&!this.existingTargets.find(i=>i.element.matches(e)&&i.uniqueId===t)&&(this.existingTargets.push({element:i,selector:e,uniqueId:t}),this.visibilityObserver.observe(i))}),this.existingTargets=this.existingTargets.filter(({selector:e,element:t})=>!!document.querySelector(e)||(t&&this.visibilityObserver.unobserve(t),!1)),this.inViewportTargets=this.inViewportTargets.filter(({selector:e,element:t,uniqueId:i})=>{if(t.matches(e)&&this.isElementVisible(t)){const n=this.targets.find(t=>t.selector===e&&t.uniqueId===i);return n&&n.resolve(t),this.clear(e,i),!1}return!0})}watch(e,t,i){this.targets.push({selector:e,resolve:t,uniqueId:i});const n=()=>{this.startMutationObserver(),this.checkElements()};document.body?n():s("body",n)}clear(e,t){[this.targets,this.existingTargets,this.inViewportTargets]=[this.targets,this.existingTargets,this.inViewportTargets].map(i=>i.filter(({selector:i,uniqueId:n})=>i!==e&&n!==t));const i=document.querySelector(e);i&&this.visibilityObserver.unobserve(i),0===this.targets.length&&this.mutationObserver.disconnect(),0===this.inViewportTargets.length&&this.mouseOverEvent.clear()}}class y{constructor({triggerEvent:e,triggerSelector:t,triggerDelay:i}){this.event=e,this.selector=t&&t.length?t:"body",this.delay=1e3*i,this.elementsSelectors=[],this.eventsListeners=[],this.timeouts=[],this.intervals=[],this.observers=[],this.promises=[],this.visibilityObservers=[],this.elementsWaiters=[],this.socialProofStore={}}async onElementVisible({promise:e,resolve:t}){const i=p(`${this.event}DomReady`);this.promises.push(i);const n=await this.onPageLoad(i),s=await async function(){let e;return e=await("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype||new Promise((e,t)=>{const i=window.document.getElementsByTagName("script")[0],n=window.document.createElement("script");n.src="https://polyfill.io/v3/polyfill.min.js?flags=gated&features=IntersectionObserver",i.parentNode.insertBefore(n,i),n.onload=e,n.onerror=t})),e}(),r=new v;if(this.visibilityObservers.push(r),s&&n){const e=g();r.watch(this.selector,t,e)}return e}onPageLoad({promise:e,resolve:t}){const i=()=>"complete"===document.readyState;if(!i()){const n=["readystatechange",({isTrusted:e})=>e&&i()&&t(!0),{passive:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}return t(!0),e}onClick({promise:e,resolve:t}){const i=document.createElement("style");i.type="text/css",i.id=`Click_${g()}`,i.innerHTML=`${this.selector} {\n\t\t\tcursor: pointer !important;\n\t\t\tpointer-events: all !important;\n\t\t}`,document.head.appendChild(i),this.elementsSelectors.push(`#${i.id}`);const n=["click",({isTrusted:e,target:i})=>e&&a(i,this.selector)&&t(!0),{passive:!0,capture:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}onHover({promise:e,resolve:t}){const i=["mouseenter",({isTrusted:e,target:i})=>e&&a(i,this.selector)&&t(!0),{passive:!0,capture:!0}];return this.eventsListeners.push([document.documentElement,...i]),document.documentElement.addEventListener(...i),e}onExitIntent({promise:e,resolve:t}){const i=["mouseleave",({isTrusted:e,clientY:i})=>{e&&i<=0&&t(!0)},{passive:!0}],n=s("body",e=>{this.eventsListeners.push([e,...i]),e.addEventListener(...i),this.elementsWaiters=this.elementsWaiters.filter(e=>e!==n)});return this.elementsWaiters.push(n),e}onReengage({promise:e,resolve:t}){const i=this.delay;let n=i;const s=[({isTrusted:e})=>{e&&(n=i)},{passive:!0}];["click","mousemove","scroll","keypress"].forEach(e=>{this.eventsListeners.push([document,e,...s]),document.addEventListener(e,...s)});const r=setInterval(()=>{n<=0?t(!0):n-=100},100);return this.intervals.push(r),e}onCustomTrigger({promise:e,resolve:t}){const{triggerEventCustomScript:i}=DATA;return new Function(`return new Promise(async resolve => {${i}})`)().then(e=>e&&t(!0)),e}onScrollUp({promise:e,resolve:t}){let i=0;const n=["scroll",({isTrusted:e})=>{e&&(window.pageYOffset<i?t(!0):i=window.pageYOffset)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}onScrollPercentReached({promise:e,resolve:t}){const{triggerEventScrollPercent:i}=DATA,n=["scroll",({isTrusted:e})=>{if(!e)return;const n=(()=>{const{documentElement:e,body:t}=document,i=e.scrollTop||t.scrollTop,n=e.scrollHeight||t.scrollHeight;return Math.trunc(i/(n-e.clientHeight)*100,10)})();i<n&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}checkSocialProofConditions(e,t,i,n){const s=(()=>{let e;return window.ABTasty||window.ABTASTY_S?(window.ABTASTY_S&&window.ABTASTY_S.USER&&window.ABTASTY_S.USER.accountIdentifier&&window.ABTASTY_S.USER.accountIdentifier.length?e=window.ABTASTY_S.USER.accountIdentifier:window.ABTasty&&window.ABTasty.getAccountSettings&&"function"==typeof window.ABTasty.getAccountSettings?e=window.ABTasty.getAccountSettings().identifier:window.ABTasty&&window.ABTasty.accountSettings&&(e=window.ABTasty.accountSettings.identifier),e):e})(),{viewInterval:r,spNoTrim:o}=DATA;if(this.socialProofStore.hasOwnProperty(e))i(this.socialProofStore[e])?n(`${this.socialProofStore[e][r]}`):n(!1);else if(e&&s){const a=t=>(this.socialProofStore[e]=t,n(!!i(t)&&`${t[r]}`));fetch(`https://api-social-proof.abtasty.com/clients/${s}/metrics/${t}?key=${e}${o?"&noTrim=true":""}`).then(e=>e.ok&&e.json()).then(a).catch(()=>m("Failed to fetch datas from server."))}else n(!1)}getSocialProofPurchases({promise:e,resolve:t}){const i=window.ABTastyProductKey,{viewInterval:n,triggerSocialProofMinPurchases:s}=DATA;return i||(m("Not able to find ABTastyProductKey, impossible to call the API, read documentation for more informations:\n\t\t\t\thttps://abtasty.elevio.help/en/articles/190-social-proof-prerequisites"),t(!1)),this.checkSocialProofConditions(i,"i",e=>{if(void 0===n||void 0===s)return!1;const t=void 0!==e[n]&&e[n]>=s;return t||m(`Widget will not be shown, product has been purchased ${e[n]} times while ${s} are required`),t},t),e}getSocialProofPageViews({promise:e,resolve:t}){const{viewInterval:i,triggerSocialProofMinPageViews:n,spNoTrim:s}=DATA,r=encodeURIComponent(s?window.location.href.replace(window.location.origin,""):`${window.location.pathname}`);return this.checkSocialProofConditions(r,"pv",e=>{if(void 0===i||void 0===n)return!1;const t=void 0!==e[i]&&e[i]>=n;return t||m(`Widget will not be shown, page has been seen ${e[i]} times while ${n} are required`),t},t),e}onConsent({promise:e,resolve:t}){if(!n()){const i=["abtasty_consentValid",()=>t(!0)];return this.eventsListeners.push(i),window.addEventListener(...i),e}return t(!0),e}onTrackingSent({promise:e,resolve:t}){const{triggerEventTrackingSent:i}=DATA;let n=localStorage.getItem("ABTastyData");const s=()=>JSON.parse(n).ActionTracking.find(({name:e})=>e===i),r=["storage",()=>{n=localStorage.getItem("ABTastyData"),s()&&t(!0)},{passive:!0,capture:!0}];return n&&s()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onMinPagesViewed({promise:e,resolve:t}){const{triggerEventMinPagesViewed:i}=DATA;let n=localStorage.getItem("ABTastyData");const s=()=>i<=(n?JSON.parse(n).VisitedPages.length:0),r=["storage",()=>{n=localStorage.getItem("ABTastyData"),s()&&t(!0)},{passive:!0,capture:!0}];return n&&s()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onRageClick({promise:e,resolve:t}){const{triggerEventRageClickQuantity:i,triggerEventRageClickDelay:n}=DATA;let s=0,r=!1;const o=["click",({isTrusted:e})=>{e&&(s+=1,s>=i&&t(!0),r||(r=!0,setTimeout(()=>{s=0,r=!1},n)))},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...o]),document.addEventListener(...o),e}clear(){if(this.elementsSelectors.length&&(this.elementsSelectors.forEach(e=>{document.querySelector(e)&&document.querySelector(e).remove()}),this.elementsSelectors=[]),this.eventsListeners.length&&(this.eventsListeners.forEach(e=>{const[t,...i]=e;t&&i.length>1&&t.removeEventListener(...i)}),this.eventsListeners=[]),this.timeouts.length&&(this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts=[]),this.intervals.length&&(this.intervals.forEach(e=>clearInterval(e)),this.intervals=[]),this.observers.length&&(this.observers.forEach(e=>e.disconnect()),this.observers=[]),this.visibilityObservers.length){const e=g();this.visibilityObservers.forEach(t=>t.clear(this.selector,e)),this.visibilityObservers=[]}return this.promises.length&&(this.promises.forEach(e=>e.resolve(!1)),this.promises=[]),this.elementsWaiters.length&&(this.elementsWaiters.forEach(e=>e.clear()),this.elementsWaiters=[]),this}async isTriggered(){this.clear();const e=p(this.event);this.promises.push(e);const t={consent:()=>this.onConsent(e),direct:()=>!0,pageLoad:()=>this.onPageLoad(e),click:()=>this.onClick(e),exitIntent:()=>this.onExitIntent(e),reengage:()=>this.onReengage(e),elementVisible:()=>this.onElementVisible(e),script:()=>this.onCustomTrigger(e),hover:()=>this.onHover(e),scrollUp:()=>this.onScrollUp(e),scrollPercent:()=>this.onScrollPercentReached(e),rageClick:()=>this.onRageClick(e),minPagesViewed:()=>this.onMinPagesViewed(e),trackingSent:()=>this.onTrackingSent(e),socialProofPurchases:()=>this.getSocialProofPurchases(e),socialProofPageViews:()=>this.getSocialProofPageViews(e)},i=!Object.prototype.hasOwnProperty.call(t,this.event)||await t[this.event]();return this.clear(),"reengage"!==this.event&&this.delay?i&&await(async()=>{const e=p(`${this.event}Delay`);return this.promises.push(e),setTimeout(()=>{e.resolve(!0),this.clear()},this.delay),e.promise})():i}}const f="display",b="closing",w="validation",$="ABTastyWidgets",S=`${$}Temporary`;class T{constructor({displayRecurrence:e,closingRecurrence:t,validationRecurrence:i},n){this.displayRecurrence=parseFloat(e),this.closingRecurrence=parseFloat(t),this.validationRecurrence=parseFloat(i),this.onSetCallback=n,this.widgetName=d(),this.uniqueId=g(),this.recurrenceKey=`${this.widgetName}_${this.uniqueId}`,this.isListeningStorageEvent=this.listenStorageEvent(),this.pendingRecurrence=!1,this.pendingRecurrenceValue={}}onStorage({key:e}){const t=localStorage.getItem(S),i=sessionStorage.getItem($);"ABTastyData"===e&&!t&&i&&localStorage.setItem(S,i)}listenStorageEvent(){return this.isListeningStorageEvent||window.addEventListener("storage",this.onStorage.bind(this)),!0}getGivenRecurrenceStorageParsed(e){try{const t=e.getItem($);return JSON.parse(t)}catch(t){return e.removeItem($),!1}}getSessionRecurrenceStorageParsed(){return this.getGivenRecurrenceStorageParsed(window.sessionStorage)}getLocalRecurrenceStorageParsed(){return this.getGivenRecurrenceStorageParsed(window.localStorage)}removeGivenStorage(e,t){const{[this.recurrenceKey]:i,...n}=t;return Object.entries(n).length?(e.setItem($,JSON.stringify(n)),n):(e.removeItem($),!1)}removeSessionRecurrenceStorage(){const e=this.getSessionRecurrenceStorageParsed();return!!e&&this.removeGivenStorage(window.sessionStorage,e)}removeLocalRecurrenceStorage(){const e=this.getLocalRecurrenceStorageParsed();return!!e&&this.removeGivenStorage(window.localStorage,e)}getSessionRecurrence(){const e=this.getSessionRecurrenceStorageParsed();return!!e&&e[this.recurrenceKey]}getLocalRecurrence(){const e=this.getLocalRecurrenceStorageParsed();return!!e&&e[this.recurrenceKey]}getCurrentRecurrence(){if(this.pendingRecurrence)return this.pendingRecurrenceValue;const e=this.getSessionRecurrence(),t=this.getLocalRecurrence();return e||t||{type:!1}}isOver(){const e=localStorage.getItem(S),t=!(!e||!e.includes(this.recurrenceKey))||this.getSessionRecurrence();e&&(sessionStorage.setItem($,e),localStorage.removeItem(S));const i=this.getLocalRecurrence(),n=(i?parseFloat(i.stamp):0)<(new Date).getTime();return n&&this.removeLocalRecurrenceStorage(),!this.pendingRecurrence&&n&&!this.getLocalRecurrence()&&!t}setRecurrence(e,i){0!==e&&(window.removeEventListener("storage",this.onStorage.bind(this)),this.isListeningStorageEvent=!1);const s=this.getTypeOfStorage(e);if(t()||!s&&"object"!=typeof s)return!1;const{storageString:r,storageMethod:o}=s,a=this.getStamp(e),c={type:i,stamp:a},{type:l}=this.getCurrentRecurrence(),h=async()=>{if(!n()){this.pendingRecurrence=!0,this.pendingRecurrenceValue=c;const e=new y({triggerEvent:"consent"});await e.isTriggered(),this.pendingRecurrence=!1,this.pendingRecurrenceValue={}}const e=this.getSessionRecurrence(),t=this.getLocalRecurrence();let i;"session"===r?e?i=this.removeSessionRecurrenceStorage():(this.removeLocalRecurrenceStorage(),i=this.getSessionRecurrenceStorageParsed()):"local"===r&&(t?i=this.removeLocalRecurrenceStorage():(this.removeSessionRecurrenceStorage(),i=this.getLocalRecurrenceStorageParsed()));const s=i?{[this.recurrenceKey]:c,...i}:{[this.recurrenceKey]:c};o.setItem($,JSON.stringify(s)),this.onSetCallback&&"function"==typeof this.onSetCallback&&this.onSetCallback()};if(!o)return!1;if(l&&i!==w)if(i===b&&l!==w)h();else{if(i!==f||l===w||l===b)return!1;h()}else h();return a}setDisplayRecurrence(){const e=f;this.setRecurrence(this.displayRecurrence,e)}setClosingRecurrence(){const e=b;this.setRecurrence(this.closingRecurrence,e)}setValidationRecurrence(){const e=w;this.setRecurrence(this.validationRecurrence,e)}getStamp(e){return(new Date).getTime()+864e5*e}getTypeOfStorage(e){return!(isNaN(e)||e<0||0!==e&&!e)&&(e>0?{storageString:"local",storageMethod:window.localStorage}:0===e&&{storageString:"session",storageMethod:window.sessionStorage})}}class C{constructor(e,t,i,n){this.recurrence=e,this.isWidgetApplied=t,this.callback=i,this.shouldUpdate=n,this.observer=new MutationObserver(this.observerHandler.bind(this)),this.eventListenerParams=["abtasty_resetActionTracking",this.eventHandler.bind(this),{passive:!0}],this.elementsWaiters=[]}recurrenceIsDone(){return!this.recurrence||this.recurrence.isOver()}decisionHandler(e){const t=i(),{type:n}=this.recurrence?this.recurrence.getCurrentRecurrence():{type:!1};let s;const r=this.isWidgetApplied(),o=(()=>{const t=this.recurrenceIsDone();return e&&"display"===n||t})(),a=!r&&t&&o,d=r&&(!t||!o),u=!r&&!t;return this.shouldUpdate&&!e&&t&&o?s=h:a?s=l:(d||u)&&(s=c),"string"==typeof s&&(this.clearWatcher(),this.callback(s,e),this.watch()),this}eventHandler(){let e=i();return[250,500].forEach(t=>{setTimeout(()=>{const n=i();return 500===t&&n===e?this:(e=n,this.decisionHandler(!1))},t)}),this}observerHandler(e){return e.some(e=>["removedNodes","addedNodes"].some(t=>e[t]&&e[t].length))?this.decisionHandler(!0):this}watch(){if(e())return this;this.clearWatcher(),document.addEventListener(...this.eventListenerParams);const t=()=>{const e=[document.body,{childList:!0,subtree:!0}];this.observer.observe(...e)};return document.body?t():(()=>{const e=s("body",()=>{t(),this.elementsWaiters=this.elementsWaiters.filter(t=>t!==e)});this.elementsWaiters.push(e)})(),this}clearWatcher(){return document.removeEventListener(...this.eventListenerParams),this.elementsWaiters.length&&(this.elementsWaiters.forEach(e=>e.clear()),this.elementsWaiters=[]),this.observer.disconnect(),this}}const E=/.+\/([^.]+)\.(otf|ttf)$/,A=["socialProofPurchases","socialProofPageViews"];class P{constructor(){this.children=void 0,this.uniqueId=g(),this.widgetName=d(),this.prettyName=u(),this.recurrenceParams=(()=>{const{displayRecurrence:t,closingRecurrence:i,validationRecurrence:n}=DATA;if(e()||!t&&!i&&!n)return!1;const s={everytime:()=>-1,session:()=>0,once:()=>395,day:e=>DATA[`${e}_day`],week:e=>7*DATA[`${e}_week`],month:e=>30.5*DATA[`${e}_month`]},r={};return t&&(r.displayRecurrence=s[t]("displayRecurrence")),i&&(r.closingRecurrence=s[i]("closingRecurrence")),n&&(r.validationRecurrence=s[n]("validationRecurrence")),r})(),this.triggerParams=(()=>{let{triggerEvent:t}=DATA;const{triggerEventClick:i,triggerEventHover:n,triggerEventReengageDelay:s,socialProofContentType:r,triggerEventElementVisible:o,triggerEventDelay:a}=DATA;if(e()||!t&&!r)return!1;const c={click:()=>i,hover:()=>n,elementVisible:()=>o},l=Object.prototype.hasOwnProperty.call(c,t)?c[t]():"body",h="reengage"===t?s:a;return r&&(t=1===r?"socialProofPurchases":"socialProofPageViews"),{triggerEvent:t,triggerSelector:l,triggerDelay:h}})(),this.recurrence=!!this.recurrenceParams&&new T(this.recurrenceParams,this.clearGivenClearables.bind(this)),this.trigger=!!this.triggerParams&&new y(this.triggerParams),this.shouldUpdate=!!this.triggerParams&&A.includes(this.triggerParams.triggerEvent),this.pageWatcher=new C(this.recurrence,this.isWidgetApplied.bind(this),this.onPageChange.bind(this),this.shouldUpdate),this.hasOncePerPageTrigger=(()=>{const{isOncePerPageTrigger:e,triggerEvent:t}=DATA;return!t||!["click","hover","scrollUp","script"].includes(t)||e})(),this.basicClassName=`ab_widget_container_${this.widgetName}`,this.widgetContainerId=`${this.basicClassName}_${this.uniqueId}`,this.contentClassName=`${this.basicClassName}_content`,this.overlayClassName=`${this.basicClassName}_overlay`,this.closeButtonClassName=`${this.basicClassName}_close_button`,this.hideClassName=`ab_hide_${this.uniqueId}`,this.domElement=this.getDom(),this.hasBeenShown=!1,this.closedByUser=!1,this.eventsListeners=[],this.timeouts=[],this.intervals=[],this.observers=[],this.promises=[],this.elementsWaiters=[]}clearGivenClearables(){this.eventsListeners.length&&(this.eventsListeners.forEach(e=>document.removeEventListener(...e)),this.eventsListeners=[]),this.timeouts.length&&(this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts=[]),this.intervals.length&&(this.intervals.forEach(e=>clearInterval(e)),this.intervals=[]),this.observers.length&&(this.observers.forEach(e=>e.disconnect()),this.observers=[]),this.promises.length&&(this.promises.forEach(e=>e.resolve(!1)),this.promises=[]),this.elementsWaiters.length&&(this.elementsWaiters.forEach(e=>e.clear()),this.elementsWaiters=[])}isWidgetApplied(){return this.domElement&&this.domElement.isConnected}removeOldDomElement(){const e=document.getElementById(this.widgetContainerId);return e&&e.remove(),this}async insert(){if(this.isWidgetApplied())return!1;const e=new Promise(e=>{const t=s("head",t=>{this.elementsWaiters=this.elementsWaiters.filter(({selector:e})=>"head"!==e),e(t.appendChild(this.styleElement))});this.elementsWaiters.push(t)}),t=new Promise(e=>{const{elementReferrer:t="body",referrerInsertType:i="beforeend"}="free"===DATA.layout?DATA:{},n=s(t,n=>{this.elementsWaiters=this.elementsWaiters.filter(e=>e.selector!==t),this.removeOldDomElement(),e(n.insertAdjacentElement(i,this.domElement))});this.elementsWaiters.push(n)});return Promise.all([t,e]).then(()=>this)}remove(){return this.pageWatcher.clearWatcher(),[this.domElement,this.styleElement].forEach(e=>e&&e.isConnected&&e.remove()),this.hasOncePerPageTrigger?this.pageWatcher.watch():e()||this.init().then(({response:e})=>e?this.show():this),this}show(){return e()||this.hasBeenShown&&this.hasOncePerPageTrigger||window.ABTastyEvent(`${this.prettyName} displayed`,null,TEST_ID),this.closedByUser=!1,setTimeout(()=>this.domElement.classList.remove(this.hideClassName),50),this.recurrence&&this.recurrence.setDisplayRecurrence(),this.hasBeenShown=!0,this.pageWatcher.watch(),this}hide(t=!0){return!e()&&this.hasBeenShown&&t&&window.ABTastyEvent(`${this.prettyName} closed`,null,TEST_ID),t&&(this.closedByUser=!0),this.domElement.classList.add(this.hideClassName),this}async init(t){const n=e(),s=i(),r=this.trigger&&this.trigger.promises.length,o=!this.recurrence||this.recurrence.isOver();if(!n&&!s||r||!o)return{container:this,response:!1};this.pageWatcher.watch();const a=n||!this.trigger||this.trigger&&await this.trigger.isTriggered(),c={container:this,response:a};return a?(await this.insert(),this.addCloseEvent(),n||t||this.hasBeenShown||void 0===this.children||"function"!=typeof this.children.refreshContent||this.children.refreshContent(a),c):c}onPageChange(e,t){let i=!1;const n=()=>this.init().then(({response:e})=>{i=e,e?this.show("onPageChange - relaunch"):this.hide(!1)});t||(this.hasBeenShown=!1,this.trigger&&this.trigger.clear());const s=this.isWidgetApplied(),r={[c]:()=>s?this.remove():this.pageWatcher.watch(),[l]:()=>{this.hasBeenShown?this.closedByUser?this.pageWatcher.watch():!s&&i&&this.insert().then(e=>e.show()).catch(this.pageWatcher.watch):n()},[h]:n};"function"==typeof r[e]&&r[e]()}addCloseEvent(...t){const{closeButton:i,overlay:n,overlayClickable:s,layout:r,animationDuration:a=1e3}=DATA,c=[];if(void 0!==n&&!0!==n||!0!==s||"popin"!==r||c.push(`.${this.overlayClassName}`),void 0!==i&&i&&c.push(`.${this.closeButtonClassName}`),!c.length)return this;const l=this.domElement.querySelectorAll(c.join(", "));if(!l.length)return this;const h=["click",e=>{o(e),this.recurrence&&this.recurrence.setClosingRecurrence(),this.hide(!0),setTimeout(()=>this.remove(),1.05*a)},{once:!0,capture:!0}];return t.push(...l),t.forEach(t=>{e()&&(t.dataset.abtastyActionnable="true"),t.removeEventListener(...h),t.addEventListener(...h)}),this}getDom(){const{closeButton:e,layout:t,overlay:i=!0}=DATA,n=document.createElement("div");return n.className=`${this.basicClassName} ${this.hideClassName}`,n.id=this.widgetContainerId,n.innerHTML=`\n\t\t\t${"popin"===t&&!0===i?`<div class="${this.overlayClassName}"></div>`:""}\n\t\t\t<div class="${this.contentClassName}">\n\t\t\t${e?`<button class="${this.closeButtonClassName}"><svg viewBox="0 0 16 16">\n\t<defs><path id="prefix__a" d="M12 4.991L11.009 4 8 7.009 4.991 4 4 4.991 7.009 8 4 11.009 4.991 12 8 8.991 11.009 12 12 11.009 8.991 8z"></path></defs>\n\t<g><use xlink:href="#prefix__a"></use></g>\n</svg></button>`:""}\n\t\t\t</div>`,n}loadFont(e,t){if(!e||"inherit"===e)return;const i=document.createElement("style"),n=t.match(E)?t.match(E)[1]:"";i.innerHTML=`@font-face { font-family: '${e}_${n}'; src: url('${t}'); font-display: swap; }`,document.head.appendChild(i)}getStyleTag(t="",i=DATA){const{noStyles:n,layout:s}=i,{backgroundColor:r,isBackgroundImage:o,backgroundImage:a,backgroundSize:c,backgroundPosition:l,backgroundRepeat:h,borderColor:d,borderRadius:u,borderWidth:g,textColor:m,textAlign:p,fontName:v,fontStyle:y,fontSize:f,isTitle:b,titleTextAlign:w,titleTextColor:$,titleFontName:S,titleFontStyle:T,titleFontSize:C,overlay:A,overlayColor:P,dropShadow:x,dropShadowColor:I,dropShadowBlur:k,containerMargin:N,containerPadding:R,closeButton:L,closeButtonPosition:B,closeButtonSize:_,closeButtonBorderRadius:D,closeButtonBorderWidth:O,closeButtonBorderColor:W,closeButtonColor:V,closeButtonBackgroundColor:j,buttonsAlign:q,buttonsBorderWidth:H,buttonsBorderColor:M,buttonsBorderRadius:U,buttonsBackgroundColor:F,buttonsTextColor:z,buttonsFontName:G,buttonsFontStyle:K,buttonsFontSize:Y,secondLink:J,secondLinkBorderWidth:Q,secondLinkBorderColor:X,secondLinkBorderRadius:Z,secondLinkBackgroundColor:ee,secondLinkTextColor:te,secondLinkFontName:ie,secondLinkFontStyle:ne,secondLinkFontSize:se,animation:re,animationDuration:oe,animationBehaviour:ae,animationSlideDirection:ce}=n?{}:i,le=document.createElement("style");le.type="text/css",e()&&le.setAttribute("abtasty-script-added","true"),this.loadFont(v,y),this.loadFont(S,T),this.loadFont(G,K),this.loadFont(ie,ne);const he=`background: ${["string"==typeof r?r:"rgba(255, 255, 255, 1)",o&&"string"==typeof a&&a.length?`url(${a})`:"",o&&"string"==typeof l&&"100% 100%"!==c?l:"0 0",o&&"string"==typeof c?`/ ${c}`:"/ auto",o&&h&&!["cover","100% 100%"].includes(c)?"repeat":"no-repeat"].join(" ").trim()};`,de="number"==typeof g&&g>0,ue=`border: ${[de?`${g}px`:"unset",de?"solid":"",de&&"string"==typeof d&&d.length?d:""].join(" ").trim()};`,ge=void 0!==u?`border-radius: ${u}px;`:"",me=void 0!==m?`color: ${m}; fill: ${m}; -webkit-text-fill-color: ${m};`:"",pe=void 0!==p?`text-align: ${p};`:"",ve=v&&"inherit"!==v?`font-family:${v}_${y.match(E)?y.match(E)[1]:""};`:y||"",ye=f?`font-size: ${f}px;`:"",fe=void 0!==x&&x?`box-shadow: 0 5px ${k}px 0 ${I};`:"",be=N instanceof Array&&1===N.length&&N[0],we=be?`margin: ${be.top}px ${be.right}px ${be.bottom}px ${be.left}px;`:"",$e=be?`margin: calc(${be.top}px * 0.5) calc(${be.right}px * 0.5) calc(${be.bottom}px * 0.5) calc(${be.left}px * 0.5);`:"",Se=R instanceof Array&&1===R.length&&R[0],Te=Se?`padding: ${Se.top}px ${Se.right}px ${Se.bottom}px ${Se.left}px;`:"",Ce=Se?`padding: calc(${Se.top}px * 0.5) calc(${Se.right}px * 0.5) calc(${Se.bottom}px * 0.5) calc(${Se.left}px * 0.5);`:"",Ee=void 0!==H&&H?`border-width: ${H}px; border-style: solid;`:"",Ae=[M,H].every(e=>void 0!==e)&&H?`border-color: ${M};`:"",Pe=void 0!==U?`border-radius: ${U}px;`:"",xe=void 0!==F?`background-color: ${F};`:"",Ie=void 0!==z?`color: ${z}; fill: ${z}; -webkit-text-fill-color: ${z};`:"",ke=G&&"inherit"!==G?`font-family:${G}_${K.match(E)?K.match(E)[1]:""};`:K||"",Ne=Y?`font-size: ${Y}px;`:"",Re=void 0!==Q&&Q?`border-width: ${Q}px; border-style: solid;`:"",Le=[X,Q].every(e=>void 0!==e)&&Q?`border-color: ${X};`:"",Be=void 0!==Z?`border-radius: ${Z}px;`:"",_e=void 0!==ee?`background-color: ${ee};`:"",De=void 0!==te?`color: ${te}; fill: ${te}; -webkit-text-fill-color: ${te};`:"",Oe=ie&&"inherit"!==ie?`font-family:${ie}_${ne.match(E)?ne.match(E)[1]:""};`:ne||"",We=se?`font-size: ${se}px;`:"",Ve="popin"!==s||void 0!==A&&!0!==A?"":[`#${this.widgetContainerId} .${this.overlayClassName} {`,`background-color: ${void 0!==P?P:"rgba(0, 0, 0, 0.6)"};`,"}"].join(""),je="number"==typeof _?_:16,qe=je/2,He=n||void 0!==L&&L?[`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} {`,"position: absolute;",("out"===B?`bottom: calc(100% + ${qe}px)`:`top: ${qe}px`)+";",`right: ${qe}px;`,"width: auto;","height: auto;","background: none;","border: none;","cursor: pointer;","outline: none;","padding: 0;","margin: 0;","line-height: 0;","z-index: 9;","number"==typeof D?`border-radius: ${D}px;`:"","number"==typeof O&&O>0?`border: ${O}px solid ${void 0!==W?W:"rgba(57, 57, 57, 1)"};`:"","string"==typeof j?`background-color: ${j};`:"","}",`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} svg {`,"pointer-events: none;",`width: ${je}px;`,`height: ${je}px;`,"string"==typeof V?`fill: ${V};`:"","}"].join(""):"",Me=b&&"string"==typeof $?[`#${this.widgetContainerId} .${this.contentClassName} > * h1, `,`#${this.widgetContainerId} .${this.contentClassName} > * h2, `,`#${this.widgetContainerId} .${this.contentClassName} > * h3, `,`#${this.widgetContainerId} .${this.contentClassName} > * h4, `,`#${this.widgetContainerId} .${this.contentClassName} > * h5, `,`#${this.widgetContainerId} .${this.contentClassName} > * h6 {`,`color: ${$}; fill: ${$}; -webkit-text-fill-color: ${$};`,void 0!==w?`text-align: ${w};`:"",S&&"inherit"!==S?`font-family:${S}_${T.match(E)?T.match(E)[1]:""};`:T||"",C?`font-size: ${C}px;`:"","}"].join(""):"";let Ue="";if("string"==typeof re){const t=(oe/1e3).toFixed(2),i=["top","bottom"].includes(ce),n=Number(i),s=[(["top","left"].includes(ce)?"-":"")+"100vmax",this.translateValues?this.translateValues[n]:"0"];i&&s.reverse(),Ue={none:[],fade:[`#${this.widgetContainerId} {`,`transition: opacity ${t}s ${ae};`,"}"],slide:[`.${this.hideClassName} .${this.overlayClassName} {`,"opacity: 0 !important;","}",`#${this.widgetContainerId} .${this.overlayClassName} {`,`transition: opacity ${t}s ${ae};`,"}",`.${this.hideClassName} .${this.contentClassName} {`,`transform: translate(${s.join(", ")}) !important;`,"}",`#${this.widgetContainerId} .${this.contentClassName} {`,`transition: transform ${t}s ${ae};`,"}"]}[e()&&!ABTASTY_S.WIDGETS.animationChanged?"none":re].join("")}const Fe=[`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,`margin-${"fill"===q?"top":"left"}: 8px;`,Re,Le,Be,_e,De,Oe,We,"}",`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,De,Oe,We,"}"];return le.textContent=[`.${this.hideClassName} {`,"opacity: 0 !important;","pointer-events: none;","}",`#${this.widgetContainerId} {`,"opacity: 1;","}",`#${this.widgetContainerId} .${this.contentClassName} {`,he,ge,ue,me,pe,fe,we,ve,ye,"}",`#${this.widgetContainerId} .${this.contentClassName} p {`,me,pe,ve,ye,"}",`#${this.widgetContainerId} .${this.contentClassName} > * {`,"display: block;","line-height: 1;","text-indent: unset;",Te,ve,ye,"}",`#${this.widgetContainerId} .${this.contentClassName} a {`,"text-decoration: underline;","}",`#${this.widgetContainerId} .${this.contentClassName} div.buttons_container a, `,`#${this.widgetContainerId} .${this.contentClassName} button {`,"text-decoration: none;","box-sizing: border-box;","display: inline-block;",Ee,Ae,Pe,xe,Ie,ke,Ne,"}",`#${this.widgetContainerId} .${this.contentClassName} div.buttons_container a *, `,`#${this.widgetContainerId} .${this.contentClassName} button:not(class*="close_button") * {`,Ie,ke,Ne,"}",...J?Fe:[],"@media screen and (max-width: 579px) {",`#${this.widgetContainerId} .${this.contentClassName} {`,$e,"}",`#${this.widgetContainerId} .${this.contentClassName} > * {`,Ce,"}","}",Ve,He,Me,Ue,`${t}`].join(""),le}}const x=["top: 0;","top: 50%;","bottom: 0;"],I=["left: 0;","left: 50%;","right: 0;"],k=e=>1===e?"-50%":0,N=()=>{if(Array.isArray(DATA.popinPosition)){const{popinPosition:[{x:e,y:t}]}=DATA,i=`translate(${k(t)}, ${k(e)});`;return`${x[e]}${I[t]}transform: ${i}`}return"left: 50%;top: 50%;transform: translate(-50%, -50%);"},R=()=>"autoWidth"in DATA&&!0===DATA.autoWidth,L=()=>{if(R())return"width: auto; height: auto; min-width: fit-content;";const{popinPercentWidth:e,popinPixelsWidth:t,widthUnit:i,autoHeight:n,popinPercentHeight:s,popinPixelsHeight:r,heightUnit:o}=DATA;return`width: ${"px"===i?t:e}${i};height: ${n?"auto":`${"px"===o?r:s}${o}`};`};function B(e){return B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},B(e)}var _,D,O,W=function(){function t(e){var i=e.parentContainer;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this.parentContainer=i,this.className="popinsimple_container_".concat(i.uniqueId),this.contentElement=this.getContentElement(),this.styleElement=this.getStyleElement()}var i,n;return i=t,n=[{key:"remove",value:function(){var e=this,t=DATA.animationDuration;setTimeout(function(){return e.parentContainer.remove()},1.05*t)}},{key:"addCloseEvent",value:function(t){var i=this;t&&t.addEventListener("click",function(t){o(t),e()||i.parentContainer.recurrence.setClosingRecurrence(),i.parentContainer.hide(),i.remove()},{capture:!0,passive:!1})}},{key:"addRedirectionEvent",value:function(t){var i=this;!e()&&t&&t.addEventListener("click",function(){var t=DATA,n=t.autoHide,s=t.timeHide;n&&setTimeout(function(){i.parentContainer.hide(),i.remove()},1e3*s),e()||i.parentContainer.recurrence.setValidationRecurrence()},{capture:!0,passive:!0})}},{key:"buttonBuilder",value:function(e,t,i,n){var s=arguments.length>4&&void 0!==arguments[4]&&arguments[4],r=document.createElement("a");return s&&(r.className="second_link"),r.innerHTML="<span>".concat(e,"</span>"),r.href="button"===t?i:"#","button"===t?(r.target=n?"_blank":"_self",this.addRedirectionEvent(r)):(r.dataset.abtastyActionnable="true",this.addCloseEvent(r)),r}},{key:"getButtons",value:function(){var e=this,t=function(t,i,n,s){var r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=document.createElement("a");return r&&(o.className="second_link"),o.innerHTML="<span>".concat(t,"</span>"),o.href="button"===i?n:"#","button"===i?(o.target=s?"_blank":"_self",e.addRedirectionEvent(o)):(o.dataset.abtastyActionnable="true",e.addCloseEvent(o)),o},i=DATA,n=i.linkType,s=i.buttonText,r=i.redirectionUrl,o=i.openInNewTab,a=i.secondLink,c=i.secondLinkText,l=i.secondLinkType,h=i.secondLinkURL,d=i.secondLinkOpenInNewTab,u=[t(s,n,r,o)];if(a){var g=t(c,l,h,d,a);u.push(g)}return u}},{key:"insertIn",value:function(e,t){return document.head.insertAdjacentElement("beforeend",this.styleElement),e.insertAdjacentElement(t,this.contentElement),e}},{key:"getContentElement",value:function(){var e=DATA,t=e.linkType,i=e.buttonText,n=e.redirectionUrl,s=e.isTitle,r=e.title,o=e.textContent,a=e.openInNewTab,c=document.createElement(t&&t.includes("widget")?"a":"div");c.className=this.className,"widget"===t?(c.href=n,c.target=a?"_blank":"_self",this.addRedirectionEvent(c)):"widgetClose"===t&&(c.href="#",c.dataset.abtastyActionnable="true",this.addCloseEvent(c));var l=document.createElement("div");if(l.className="popin_text_container",l.innerHTML="".concat(s?'<h2 class="popin_simple_title">'.concat(r,"</h2>"):"",'<p class="popin_simple_text">').concat(o,"</p>"),[t,i].every(function(e){return"string"==typeof e})&&t.includes("button")&&i.length){var h=this.getButtons(),d=document.createElement("div");d.className="buttons_container",h.forEach(function(e){return d.appendChild(e)}),l.appendChild(d)}return c.appendChild(l),c}},{key:"getStyleElement",value:function(){var t=document.createElement("style");t.type="text/css",e()&&t.setAttribute("abtasty-script-added","true");var i=DATA,n=i.linkType,s=i.buttonsAlign,r="#".concat(this.parentContainer.widgetContainerId," .").concat(this.parentContainer.contentClassName),o=void 0!==s&&"fill"!==s?"text-align: ".concat(s,";"):"",a=["".concat(r," .buttons_container {"),"display: inline-block;","width: 100%;",o,"}","".concat(r," .buttons_container a {"),"margin: 25px 0 0 0;","padding: 10px 22px;","max-width: 100%;","width: ".concat("fill"===s?"100%":"auto",";"),"text-align: center;","}"].join(""),c=["".concat(r," .popin_simple_title {"),"margin: 0 0 25px 0;","display: inline-block;","width: 100%;","}","".concat(r," .popin_text_container {"),"line-height: 1;","white-space: pre-line;","display: inline-block;","vertical-align: middle;","width: 100%;","}","".concat(r," .popin_text_container p {"),"margin: 0;","}"];return n&&n.includes("button")&&c.push(a),t.textContent=c.join(""),t}}],n&&function(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(s=function(e){if("object"!==B(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!==B(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key),"symbol"===B(s)?s:String(s)),n)}var s}(i.prototype,n),Object.defineProperty(i,"prototype",{writable:!1}),t}();D=new W({parentContainer:_=new class extends P{constructor(){super(),this.translateValues=Object.values(DATA.popinPosition[0]).map(e=>k(e)),this.stringStyles=this.getStyles(),this.styleElement=this.getStyleTag(this.stringStyles)}getStyles(){const{zindex:e,zindexCustom:t,overlay:i,widthUnit:n}=DATA;return[`#${this.widgetContainerId} {`,"position: fixed;","top: 0;","left: 0;","width: 100%;","height: 100%;",`z-index: ${"custom"===e?t:e};`,"background: none;","pointer-events: "+(!1===i?"none":"all"),"}",`#${this.widgetContainerId} .${this.overlayClassName} {`,"position: absolute;","z-index: -1;","top: 0;","left: 0;","width: 100%;","height: 100%;","}",`#${this.widgetContainerId} .${this.contentClassName} {`,"position: absolute;",N(),L(),"pointer-events: all","}",`${R()?"":[`#${this.widgetContainerId} .${this.contentClassName} > div {`,"height: 100%;","overflow: auto;","box-sizing: border-box;","}"].join("")}`,`${!R()&&["px","em"].includes(n)?["@media screen and (max-width: 579px) {",`#${this.widgetContainerId} .${this.contentClassName} {`,"max-width: 94vw;","}","}"].join(""):""}`].join("")}}}),O=_.domElement.querySelector(".".concat(_.contentClassName)),_.children=D,D.insertIn(O,"beforeend"),_.init().then(function(e){e.response&&_.show()})}();
1
+ !function(){"use strict";const e=()=>Object.prototype.hasOwnProperty.call(window,"ABTastyEditor"),t=()=>{const e=!!document.getElementById("ABTastyPreviewBar"),t=location.href.includes("ab_project=preview");return e||t},i=e=>new Function(`try {\n\t\t${e}\n\t} catch (error) {\n\t\treturn null;\n\t}`)(),n=()=>encodeURIComponent(DATA.spNoTrim?window.location.href.replace(window.location.origin,""):`${window.location.pathname}`),s=()=>!e()&&(t()||!!window.ABTasty.getTestsOnPage()[TEST_ID]),r=()=>window.ABTasty&&!0===window.ABTasty.consentReady,o=(e,t)=>{const i=()=>{try{return document.querySelector(e)}catch(e){return null}};let n=i();const s=[document.body||document.documentElement,{childList:!0,subtree:!0,attributes:!0}],r=()=>a.disconnect(),o=()=>a.observe(...s),a=new MutationObserver(()=>(n=i(),n&&!r()&&t(n)));return n?setTimeout(()=>t(n),0):o(),{selector:e,clear:r,observe:o}};function a(e,t){return t(e)||!e.parentElement?e:a(e.parentElement,t)}const c=t=>{e()||(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation())},l=(e,t)=>[...document.querySelectorAll(t)].some(i=>i.isSameNode(e)||!!e.closest(t)),h="remove",d="rebuild",u="update",g=()=>{const{type:e}=DATA;return`${PACKAGE.replace("@abtasty/","")}${e?`_${e}`:""}`},m=()=>{const e=g();return`${e.charAt(0).toUpperCase()}${e.slice(1)}`.split("-").join(" ")},p=()=>`${PLUGIN_ID.split("-")[0]}_${TEST_ID}`,v=i=>{if((()=>{if(e()||t())return!1;const i=ABTasty.getTestsOnPage()[TEST_ID];return!!i&&Object.keys(i.targetings.qaParameters).length>0})()){const e=m();window.console.log(`%c${e} - QA Mode for campaign ${TEST_ID}\n${i}`,"background-color: rgba(0, 127, 145, 1); color: rgba(247, 247, 247, 1)")}},y=e=>{const t={promise:null,resolve:null,reject:null,name:e};return t.promise=new Promise((e,i)=>{t.resolve=e,t.reject=i}),t};class f{constructor(){this.targets=[],this.existingTargets=[],this.inViewportTargets=[],this.visibilityObserver=this.startVisibilityObserver(),this.mutationObserver=this.startMutationObserver(),this.mouseOverEvent=this.mouseOverHandler()}intersectionHandler(e){e.forEach(e=>{e.isIntersecting?(this.existingTargets.forEach(t=>{t.element.isSameNode(e.target)&&(this.inViewportTargets.push(t),this.mouseOverEvent.start())}),this.checkElements()):this.inViewportTargets=this.inViewportTargets.filter(t=>!t.element.isSameNode(e.target)||(this.mouseOverEvent.clear(),!1))})}startVisibilityObserver(){return new IntersectionObserver(this.intersectionHandler.bind(this),{root:null,rootMargin:"0px",threshold:0})}startMutationObserver(){const e=this.mutationObserver||new MutationObserver(this.checkElements.bind(this));return document.body&&e.observe(document.body,{attributes:!0,childList:!0,subtree:!0}),e}onMouseOver({target:e,path:t}){const i=this.inViewportTargets.find(({element:i,selector:n})=>{if(i.isSameNode(e))return!0;const s=[...e.querySelectorAll(n)];if(s.length&&s.includes(i))return!0;if(t.includes(i))return!0;const r=[...e.parentElement.children],o=r.findIndex(t=>t.isSameNode(e)),a=r.filter((e,t)=>t>o);if(a.length){if(a.includes(i))return!0;if(a.some(e=>[...e.querySelectorAll(n)].includes(i)))return!0}return!1});if(i&&this.isElementVisible(i.element)){const{selector:e,element:t,uniqueId:n}=i,s=this.targets.find(t=>t.selector===e&&t.uniqueId===n);s&&s.resolve(t),this.clear(e,n)}}mouseOverHandler(){const e=["mouseover",e=>{const t=e.composedPath(),{target:i}=e;setTimeout(()=>this.onMouseOver({target:i,path:t}),50)},!0];return{start:()=>document.addEventListener(...e),clear:()=>document.removeEventListener(...e)}}isElementVisible(e){return this.isElementTopmost(e)&&this.isElementOpaque(e)}isElementOpaque(e){return"HTML"===a(e,e=>"0"===window.getComputedStyle(e).opacity).nodeName}isElementTopmost(e){const t=e.getBoundingClientRect(),i=[[t.left,t.top],[t.right,t.top],[t.left,t.bottom],[t.right,t.bottom],[t.left+t.width/2,t.top],[t.left+t.width/2,t.bottom],[t.left,t.height/2],[t.right,t.height/2],[t.left+t.left/2,t.height/2]];let n=!1,s=0;for(;!n&&s<i.length;){const t=document.elementFromPoint(...i[s]);n=e===t||e.contains(t),s+=1}return n}checkElements(){this.targets.forEach(({selector:e,uniqueId:t})=>{const i=document.querySelector(e);i&&!this.existingTargets.find(i=>i.element.matches(e)&&i.uniqueId===t)&&(this.existingTargets.push({element:i,selector:e,uniqueId:t}),this.visibilityObserver.observe(i))}),this.existingTargets=this.existingTargets.filter(({selector:e,element:t})=>!!document.querySelector(e)||(t&&this.visibilityObserver.unobserve(t),!1)),this.inViewportTargets=this.inViewportTargets.filter(({selector:e,element:t,uniqueId:i})=>{if(t.matches(e)&&this.isElementVisible(t)){const n=this.targets.find(t=>t.selector===e&&t.uniqueId===i);return n&&n.resolve(t),this.clear(e,i),!1}return!0})}watch(e,t,i){this.targets.push({selector:e,resolve:t,uniqueId:i});const n=()=>{this.startMutationObserver(),this.checkElements()};document.body?n():o("body",n)}clear(e,t){[this.targets,this.existingTargets,this.inViewportTargets]=[this.targets,this.existingTargets,this.inViewportTargets].map(i=>i.filter(({selector:i,uniqueId:n})=>i!==e&&n!==t));const i=document.querySelector(e);i&&this.visibilityObserver.unobserve(i),0===this.targets.length&&this.mutationObserver.disconnect(),0===this.inViewportTargets.length&&this.mouseOverEvent.clear()}}class b{constructor({triggerEvent:e,triggerSelector:t,triggerDelay:i}){this.event=e,this.selector=t&&t.length?t:"body",this.delay=1e3*i,this.elementsSelectors=[],this.eventsListeners=[],this.timeouts=[],this.intervals=[],this.observers=[],this.promises=[],this.visibilityObservers=[],this.elementsWaiters=[],this.socialProofStore={}}async onElementVisible({promise:e,resolve:t}){const i=y(`${this.event}DomReady`);this.promises.push(i);const n=await this.onPageLoad(i),s=await async function(){let e;return e=await("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype||new Promise((e,t)=>{const i=window.document.getElementsByTagName("script")[0],n=window.document.createElement("script");n.src="https://polyfill.io/v3/polyfill.min.js?flags=gated&features=IntersectionObserver",i.parentNode.insertBefore(n,i),n.onload=e,n.onerror=t})),e}(),r=new f;if(this.visibilityObservers.push(r),s&&n){const e=p();r.watch(this.selector,t,e)}return e}onPageLoad({promise:e,resolve:t}){const i=()=>"complete"===document.readyState;if(!i()){const n=["readystatechange",({isTrusted:e})=>e&&i()&&t(!0),{passive:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}return t(!0),e}onClick({promise:e,resolve:t}){const i=document.createElement("style");i.type="text/css",i.id=`Click_${p()}`,i.innerHTML=`${this.selector} {\n\t\t\tcursor: pointer !important;\n\t\t\tpointer-events: all !important;\n\t\t}`,document.head.appendChild(i),this.elementsSelectors.push(`#${i.id}`);const n=["click",({isTrusted:e,target:i})=>e&&l(i,this.selector)&&t(!0),{passive:!0,capture:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}onHover({promise:e,resolve:t}){const i=["mouseenter",({isTrusted:e,target:i})=>e&&l(i,this.selector)&&t(!0),{passive:!0,capture:!0}];return this.eventsListeners.push([document.documentElement,...i]),document.documentElement.addEventListener(...i),e}onExitIntent({promise:e,resolve:t}){const i=["mouseleave",({isTrusted:e,clientY:i})=>{e&&i<=0&&t(!0)},{passive:!0}],n=o("body",e=>{this.eventsListeners.push([e,...i]),e.addEventListener(...i),this.elementsWaiters=this.elementsWaiters.filter(e=>e!==n)});return this.elementsWaiters.push(n),e}onReengage({promise:e,resolve:t}){const i=this.delay;let n=i;const s=[({isTrusted:e})=>{e&&(n=i)},{passive:!0}];["click","mousemove","scroll","keypress"].forEach(e=>{this.eventsListeners.push([document,e,...s]),document.addEventListener(e,...s)});const r=setInterval(()=>{n<=0?t(!0):n-=100},100);return this.intervals.push(r),e}onCustomTrigger({promise:e,resolve:t}){const{triggerEventCustomScript:i}=DATA;return new Function(`return new Promise(async resolve => {${i}})`)().then(e=>e&&t(!0)),e}onScrollUp({promise:e,resolve:t}){let i=0;const n=["scroll",({isTrusted:e})=>{e&&(window.pageYOffset<i?t(!0):i=window.pageYOffset)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}onScrollPercentReached({promise:e,resolve:t}){const{triggerEventScrollPercent:i}=DATA,n=["scroll",({isTrusted:e})=>{if(!e)return;const n=(()=>{const{documentElement:e,body:t}=document,i=e.scrollTop||t.scrollTop,n=e.scrollHeight||t.scrollHeight;return Math.trunc(i/(n-e.clientHeight)*100,10)})();i<n&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...n]),document.addEventListener(...n),e}checkSocialProofConditions(e,t,i,n){const s=(()=>{let e;return window.ABTasty||window.ABTASTY_S?(window.ABTASTY_S&&window.ABTASTY_S.USER&&window.ABTASTY_S.USER.accountIdentifier&&window.ABTASTY_S.USER.accountIdentifier.length?e=window.ABTASTY_S.USER.accountIdentifier:window.ABTasty&&window.ABTasty.getAccountSettings&&"function"==typeof window.ABTasty.getAccountSettings?e=window.ABTasty.getAccountSettings().identifier:window.ABTasty&&window.ABTasty.accountSettings&&(e=window.ABTasty.accountSettings.identifier),e):e})(),{viewInterval:r,spNoTrim:o}=DATA;if(this.socialProofStore.hasOwnProperty(e))i(this.socialProofStore[e])?n(`${this.socialProofStore[e][r]}`):n(!1);else if(e&&s){const a=t=>(this.socialProofStore[e]=t,n(!!i(t)&&`${t[r]}`));fetch(`https://api-social-proof.abtasty.com/clients/${s}/metrics/${t}?key=${e}${o?"&noTrim=true":""}`).then(e=>e.ok&&e.json()).then(a).catch(()=>v("Failed to fetch datas from server."))}else n(!1)}getSocialProofDatas({promise:e,resolve:t},s,r=!1){const{productKey:o,keyType:a}=(()=>{const{socialProofContentType:e,productKeyProvider:t,pathToProductKey:s,customJSProductKey:r,productSKU:o}=DATA;if(2===e)return{productKey:n(),keyType:"url"};{let a=null,c="sku";switch(t){case"ABTastyProductKey":a=window.ABTastyProductKey;break;case"pathToProductKey":a=i(`return ${s};`);break;case"customJSProductKey":a=i(r);break;case"productSKU":a=o}return a||3!==e||(a=n(),c="url"),{productKey:a,keyType:c}}})(),{viewInterval:c,triggerSocialProofMinVisitors:l,triggerSocialProofMinPurchases:h,triggerSocialProofMinPageViews:d}=DATA,u={pv:d,i:h,"v-pv":l}[s];return[typeof c,typeof u].includes("undefined")&&t(!1),r&&!o&&(v("Not able to find ABTastyProductKey, impossible to call the API, read documentation for more informations:\n\t\t\t\thttps://abtasty.elevio.help/en/articles/190-social-proof-prerequisites"),t(!1)),this.checkSocialProofConditions(o,"v-pv"===s&&"sku"===a?"v-i":s,e=>{const t=void 0!==e[c]&&e[c]>=u;return t||v(`Widget will not be shown, Social Proof API returned ${e[c]} while ${u} are required`),t},t),e}onConsent({promise:e,resolve:t}){if(!r()){const i=["abtasty_consentValid",()=>t(!0)];return this.eventsListeners.push(i),window.addEventListener(...i),e}return t(!0),e}onTrackingSent({promise:e,resolve:t}){const{triggerEventTrackingSent:i}=DATA;let n=localStorage.getItem("ABTastyData");const s=()=>JSON.parse(n).ActionTracking.find(({name:e})=>e===i),r=["storage",()=>{n=localStorage.getItem("ABTastyData"),s()&&t(!0)},{passive:!0,capture:!0}];return n&&s()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onMinPagesViewed({promise:e,resolve:t}){const{triggerEventMinPagesViewed:i}=DATA;let n=localStorage.getItem("ABTastyData");const s=()=>i<=(n?JSON.parse(n).VisitedPages.length:0),r=["storage",()=>{n=localStorage.getItem("ABTastyData"),s()&&t(!0)},{passive:!0,capture:!0}];return n&&s()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onRageClick({promise:e,resolve:t}){const{triggerEventRageClickQuantity:i,triggerEventRageClickDelay:n}=DATA;let s=0,r=!1;const o=["click",({isTrusted:e})=>{if(e&&(s+=1,s>=i&&t(!0),!r)){r=!0;const e=setTimeout(()=>{s=0,r=!1},n);this.timeouts.push(e)}},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...o]),document.addEventListener(...o),e}clear(e){if(top.console.log("clear",{from:e}),this.elementsSelectors.length&&(this.elementsSelectors.forEach(e=>{document.querySelector(e)&&document.querySelector(e).remove()}),this.elementsSelectors=[]),this.eventsListeners.length&&(this.eventsListeners.forEach(e=>{const[t,...i]=e;t&&i.length>1&&t.removeEventListener(...i)}),this.eventsListeners=[]),this.timeouts.length&&(this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts=[]),this.intervals.length&&(this.intervals.forEach(e=>clearInterval(e)),this.intervals=[]),this.observers.length&&(this.observers.forEach(e=>e.disconnect()),this.observers=[]),this.visibilityObservers.length){const e=p();this.visibilityObservers.forEach(t=>t.clear(this.selector,e)),this.visibilityObservers=[]}return this.promises.length&&(this.promises.forEach(e=>e.resolve(!1)),this.promises=[]),this.elementsWaiters.length&&(this.elementsWaiters.forEach(e=>e.clear()),this.elementsWaiters=[]),this}async isTriggered(){this.clear("isTriggered"),top.console.log("isTriggered",{event:this.event});const e=y(this.event);this.promises.push(e);const t={consent:()=>this.onConsent(e),direct:()=>!0,pageLoad:()=>this.onPageLoad(e),click:()=>this.onClick(e),exitIntent:()=>this.onExitIntent(e),reengage:()=>this.onReengage(e),elementVisible:()=>this.onElementVisible(e),script:()=>this.onCustomTrigger(e),hover:()=>this.onHover(e),scrollUp:()=>this.onScrollUp(e),scrollPercent:()=>this.onScrollPercentReached(e),rageClick:()=>this.onRageClick(e),minPagesViewed:()=>this.onMinPagesViewed(e),trackingSent:()=>this.onTrackingSent(e),socialProofPurchases:()=>this.getSocialProofDatas(e,"i",!0),socialProofPageViews:()=>this.getSocialProofDatas(e,"pv"),socialProofVisitors:()=>this.getSocialProofDatas(e,"v-pv")},i=!Object.prototype.hasOwnProperty.call(t,this.event)||await t[this.event]();return i&&this.clear("isTriggered 2"),"reengage"!==this.event&&this.delay?i&&await(async()=>{const e=y(`${this.event}Delay`);this.promises.push(e);const t=setTimeout(()=>{e.resolve(!0),this.clear("waitDelay")},this.delay);return this.timeouts.push(t),e.promise})():i}}const w="display",$="closing",S="validation",T="ABTastyWidgets",C=`${T}Temporary`;class E{constructor({displayRecurrence:e,closingRecurrence:t,validationRecurrence:i},n){this.displayRecurrence=parseFloat(e),this.closingRecurrence=parseFloat(t),this.validationRecurrence=parseFloat(i),this.onSetCallback=n,this.widgetName=g(),this.uniqueId=p(),this.recurrenceKey=`${this.widgetName}_${this.uniqueId}`,this.isListeningStorageEvent=this.listenStorageEvent(),this.pendingRecurrence=!1,this.pendingRecurrenceValue={}}onStorage({key:e}){const t=localStorage.getItem(C),i=sessionStorage.getItem(T);"ABTastyData"===e&&!t&&i&&localStorage.setItem(C,i)}listenStorageEvent(){return this.isListeningStorageEvent||window.addEventListener("storage",this.onStorage.bind(this)),!0}getGivenRecurrenceStorageParsed(e){try{const t=e.getItem(T);return JSON.parse(t)}catch(t){return e.removeItem(T),!1}}getSessionRecurrenceStorageParsed(){return this.getGivenRecurrenceStorageParsed(window.sessionStorage)}getLocalRecurrenceStorageParsed(){return this.getGivenRecurrenceStorageParsed(window.localStorage)}removeGivenStorage(e,t){const{[this.recurrenceKey]:i,...n}=t;return Object.entries(n).length?(e.setItem(T,JSON.stringify(n)),n):(e.removeItem(T),!1)}removeSessionRecurrenceStorage(){const e=this.getSessionRecurrenceStorageParsed();return!!e&&this.removeGivenStorage(window.sessionStorage,e)}removeLocalRecurrenceStorage(){const e=this.getLocalRecurrenceStorageParsed();return!!e&&this.removeGivenStorage(window.localStorage,e)}getSessionRecurrence(){const e=this.getSessionRecurrenceStorageParsed();return!!e&&e[this.recurrenceKey]}getLocalRecurrence(){const e=this.getLocalRecurrenceStorageParsed();return!!e&&e[this.recurrenceKey]}getCurrentRecurrence(){if(this.pendingRecurrence)return this.pendingRecurrenceValue;const e=this.getSessionRecurrence(),t=this.getLocalRecurrence();return e||t||{type:!1}}isOver(){const e=localStorage.getItem(C),t=!(!e||!e.includes(this.recurrenceKey))||this.getSessionRecurrence();e&&(sessionStorage.setItem(T,e),localStorage.removeItem(C));const i=this.getLocalRecurrence(),n=(i?parseFloat(i.stamp):0)<(new Date).getTime();return n&&this.removeLocalRecurrenceStorage(),!this.pendingRecurrence&&n&&!this.getLocalRecurrence()&&!t}setRecurrence(e,i){0!==e&&(window.removeEventListener("storage",this.onStorage.bind(this)),this.isListeningStorageEvent=!1);const n=this.getTypeOfStorage(e);if(t()||!n&&"object"!=typeof n)return!1;const{storageString:s,storageMethod:o}=n,a=this.getStamp(e),c={type:i,stamp:a},{type:l}=this.getCurrentRecurrence(),h=async()=>{if(!r()){this.pendingRecurrence=!0,this.pendingRecurrenceValue=c;const e=new b({triggerEvent:"consent"});await e.isTriggered(),this.pendingRecurrence=!1,this.pendingRecurrenceValue={}}const e=this.getSessionRecurrence(),t=this.getLocalRecurrence();let i;"session"===s?e?i=this.removeSessionRecurrenceStorage():(this.removeLocalRecurrenceStorage(),i=this.getSessionRecurrenceStorageParsed()):"local"===s&&(t?i=this.removeLocalRecurrenceStorage():(this.removeSessionRecurrenceStorage(),i=this.getLocalRecurrenceStorageParsed()));const n=i?{[this.recurrenceKey]:c,...i}:{[this.recurrenceKey]:c};o.setItem(T,JSON.stringify(n)),this.onSetCallback&&"function"==typeof this.onSetCallback&&this.onSetCallback()};if(!o)return!1;if(l&&i!==S)if(i===$&&l!==S)h();else{if(i!==w||l===S||l===$)return!1;h()}else h();return a}setDisplayRecurrence(){const e=w;this.setRecurrence(this.displayRecurrence,e)}setClosingRecurrence(){const e=$;this.setRecurrence(this.closingRecurrence,e)}setValidationRecurrence(){const e=S;this.setRecurrence(this.validationRecurrence,e)}getStamp(e){return(new Date).getTime()+864e5*e}getTypeOfStorage(e){return!(isNaN(e)||e<0||0!==e&&!e)&&(e>0?{storageString:"local",storageMethod:window.localStorage}:0===e&&{storageString:"session",storageMethod:window.sessionStorage})}}class A{constructor(e,t,i,n){this.recurrence=e,this.isWidgetApplied=t,this.callback=i,this.shouldUpdate=n,this.observer=new MutationObserver(this.observerHandler.bind(this)),this.eventListenerParams=["abtasty_resetActionTracking",this.eventHandler.bind(this),{passive:!0}],this.elementsWaiters=[]}recurrenceIsDone(){return!this.recurrence||this.recurrence.isOver()}decisionHandler(e){const t=s(),{type:i}=this.recurrence?this.recurrence.getCurrentRecurrence():{type:!1};let n;const r=this.isWidgetApplied(),o=(()=>{const t=this.recurrenceIsDone();return e&&"display"===i||t})(),a=!r&&t&&o,c=r&&(!t||!o),l=!r&&!t;return this.shouldUpdate&&!e&&t&&o?n=u:a?n=d:(c||l)&&(n=h),"string"==typeof n&&(this.clearWatcher(),this.callback(n,e),this.watch()),this}eventHandler(){let e=s();return[250,500].forEach(t=>{setTimeout(()=>{const i=s();return 500===t&&i===e?this:(e=i,this.decisionHandler(!1))},t)}),this}observerHandler(e){return e.some(e=>["removedNodes","addedNodes"].some(t=>e[t]&&e[t].length))?this.decisionHandler(!0):this}watch(){if(e())return this;this.clearWatcher(),document.addEventListener(...this.eventListenerParams);const t=()=>{const e=[document.body,{childList:!0,subtree:!0}];this.observer.observe(...e)};return document.body?t():(()=>{const e=o("body",()=>{t(),this.elementsWaiters=this.elementsWaiters.filter(t=>t!==e)});this.elementsWaiters.push(e)})(),this}clearWatcher(){return document.removeEventListener(...this.eventListenerParams),this.elementsWaiters.length&&(this.elementsWaiters.forEach(e=>e.clear()),this.elementsWaiters=[]),this.observer.disconnect(),this}}const P=/.+\/([^.]+)\.(otf|ttf)$/,x=["socialProofPurchases","socialProofPageViews","socialProofVisitors"];class k{constructor(){this.children=void 0,this.uniqueId=p(),this.widgetName=g(),this.prettyName=m(),this.recurrenceParams=(()=>{const{displayRecurrence:t,closingRecurrence:i,validationRecurrence:n}=DATA;if(e()||!t&&!i&&!n)return!1;const s={everytime:()=>-1,session:()=>0,once:()=>395,day:e=>DATA[`${e}_day`],week:e=>7*DATA[`${e}_week`],month:e=>30.5*DATA[`${e}_month`]},r={};return t&&(r.displayRecurrence=s[t]("displayRecurrence")),i&&(r.closingRecurrence=s[i]("closingRecurrence")),n&&(r.validationRecurrence=s[n]("validationRecurrence")),r})(),this.triggerParams=(()=>{let{triggerEvent:t}=DATA;const{triggerEventClick:i,triggerEventHover:n,triggerEventReengageDelay:s,socialProofContentType:r,triggerEventElementVisible:o,triggerEventDelay:a}=DATA;if(e()||!t&&!r)return!1;const c={click:()=>i,hover:()=>n,elementVisible:()=>o},l=Object.prototype.hasOwnProperty.call(c,t)?c[t]():"body",h="reengage"===t?s:a;return r&&(t=[,"socialProofPurchases","socialProofPageViews","socialProofVisitors"][r]),{triggerEvent:t,triggerSelector:l,triggerDelay:h}})(),this.recurrence=!!this.recurrenceParams&&new E(this.recurrenceParams,this.clearGivenClearables.bind(this)),this.trigger=!!this.triggerParams&&new b(this.triggerParams),this.shouldUpdate=!!this.triggerParams&&x.includes(this.triggerParams.triggerEvent),this.pageWatcher=new A(this.recurrence,this.isWidgetApplied.bind(this),this.onPageChange.bind(this),this.shouldUpdate),this.hasOncePerPageTrigger=(()=>{const{isOncePerPageTrigger:e,triggerEvent:t}=DATA;return!t||!["click","hover","scrollUp","script"].includes(t)||e})(),this.basicClassName=`ab_widget_container_${this.widgetName}`,this.widgetContainerId=`${this.basicClassName}_${this.uniqueId}`,this.contentClassName=`${this.basicClassName}_content`,this.overlayClassName=`${this.basicClassName}_overlay`,this.closeButtonClassName=`${this.basicClassName}_close_button`,this.hideClassName=`ab_hide_${this.uniqueId}`,this.domElement=this.getDom(),this.hasBeenShown=!1,this.closedByUser=!1,this.eventsListeners=[],this.timeouts=[],this.intervals=[],this.observers=[],this.promises=[],this.elementsWaiters=[]}clearGivenClearables(){this.eventsListeners.length&&(this.eventsListeners.forEach(e=>document.removeEventListener(...e)),this.eventsListeners=[]),this.timeouts.length&&(this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts=[]),this.intervals.length&&(this.intervals.forEach(e=>clearInterval(e)),this.intervals=[]),this.observers.length&&(this.observers.forEach(e=>e.disconnect()),this.observers=[]),this.promises.length&&(this.promises.forEach(e=>e.resolve(!1)),this.promises=[]),this.elementsWaiters.length&&(this.elementsWaiters.forEach(e=>e.clear()),this.elementsWaiters=[])}isWidgetApplied(){return this.domElement&&this.domElement.isConnected}removeOldDomElement(){const e=document.getElementById(this.widgetContainerId);return e&&e.remove(),this}async insert(){if(this.isWidgetApplied())return!1;const e=new Promise(e=>{const t=o("head",t=>{this.elementsWaiters=this.elementsWaiters.filter(({selector:e})=>"head"!==e),e(t.appendChild(this.styleElement))});this.elementsWaiters.push(t)}),t=new Promise(e=>{const{elementReferrer:t="body",referrerInsertType:i="beforeend"}="free"===DATA.layout?DATA:{},n=o(t,n=>{this.elementsWaiters=this.elementsWaiters.filter(e=>e.selector!==t),this.removeOldDomElement(),e(n.insertAdjacentElement(i,this.domElement))});this.elementsWaiters.push(n)});return Promise.all([t,e]).then(()=>this)}remove(){return this.pageWatcher.clearWatcher(),[this.domElement,this.styleElement].forEach(e=>e&&e.isConnected&&e.remove()),this.hasOncePerPageTrigger?this.pageWatcher.watch():e()||this.init().then(({response:e})=>e?this.show():this),this}show(){return e()||this.hasBeenShown&&this.hasOncePerPageTrigger||window.ABTastyEvent(`${this.prettyName} displayed`,null,TEST_ID),this.closedByUser=!1,setTimeout(()=>this.domElement.classList.remove(this.hideClassName),50),this.recurrence&&this.recurrence.setDisplayRecurrence(),this.hasBeenShown=!0,this.pageWatcher.watch(),this}hide(t=!0){return!e()&&this.hasBeenShown&&t&&window.ABTastyEvent(`${this.prettyName} closed`,null,TEST_ID),t&&(this.closedByUser=!0),this.domElement.classList.add(this.hideClassName),this}async init(t){const i=e(),n=s(),r=this.trigger&&this.trigger.promises.length,o=!this.recurrence||this.recurrence.isOver();if(!i&&!n||r||!o)return{container:this,response:!1};this.pageWatcher.watch();const a=i||!this.trigger||this.trigger&&await this.trigger.isTriggered(),c={container:this,response:a};return a?(await this.insert(),this.addCloseEvent(),i||t||this.hasBeenShown||void 0===this.children||"function"!=typeof this.children.refreshContent||this.children.refreshContent(a),c):c}onPageChange(e,t){let i=!1;const n=()=>this.init().then(({response:e})=>{i=e,e?this.show("onPageChange - relaunch"):this.hide(!1)});t||(this.hasBeenShown=!1,this.trigger&&this.trigger.clear("onPageChange"));const s=this.isWidgetApplied(),r={[h]:()=>s?this.remove():this.pageWatcher.watch(),[d]:()=>{this.hasBeenShown?this.closedByUser?this.pageWatcher.watch():!s&&i&&this.insert().then(e=>e.show()).catch(this.pageWatcher.watch):n()},[u]:n};"function"==typeof r[e]&&r[e]()}addCloseEvent(...t){const{closeButton:i,overlay:n,overlayClickable:s,layout:r,animationDuration:o=1e3}=DATA,a=[];if(void 0!==n&&!0!==n||!0!==s||"popin"!==r||a.push(`.${this.overlayClassName}`),void 0!==i&&i&&a.push(`.${this.closeButtonClassName}`),!a.length)return this;const l=this.domElement.querySelectorAll(a.join(", "));if(!l.length)return this;const h=["click",e=>{c(e),this.recurrence&&this.recurrence.setClosingRecurrence(),this.hide(!0),setTimeout(()=>this.remove(),1.05*o)},{once:!0,capture:!0}];return t.push(...l),t.forEach(t=>{e()&&(t.dataset.abtastyActionnable="true"),t.removeEventListener(...h),t.addEventListener(...h)}),this}getDom(){const{closeButton:e,layout:t,overlay:i=!0}=DATA,n=document.createElement("div");return n.className=`${this.basicClassName} ${this.hideClassName}`,n.id=this.widgetContainerId,n.innerHTML=`\n\t\t\t${"popin"===t&&!0===i?`<div class="${this.overlayClassName}"></div>`:""}\n\t\t\t<div class="${this.contentClassName}">\n\t\t\t${e?`<button class="${this.closeButtonClassName}"><svg viewBox="0 0 16 16">\n\t<defs><path id="prefix__a" d="M12 4.991L11.009 4 8 7.009 4.991 4 4 4.991 7.009 8 4 11.009 4.991 12 8 8.991 11.009 12 12 11.009 8.991 8z"></path></defs>\n\t<g><use xlink:href="#prefix__a"></use></g>\n</svg></button>`:""}\n\t\t\t</div>`,n}loadFont(e,t){if(!e||"inherit"===e)return;const i=document.createElement("style"),n=t.match(P)?t.match(P)[1]:"";i.innerHTML=`@font-face { font-family: '${e}_${n}'; src: url('${t}'); font-display: swap; }`,document.head.appendChild(i)}getStyleTag(t="",i=DATA){const{noStyles:n,layout:s}=i,{backgroundColor:r,isBackgroundImage:o,backgroundImage:a,backgroundSize:c,backgroundPosition:l,backgroundRepeat:h,borderColor:d,borderRadius:u,borderWidth:g,textColor:m,textAlign:p,fontName:v,fontStyle:y,fontSize:f,isTitle:b,titleTextAlign:w,titleTextColor:$,titleFontName:S,titleFontStyle:T,titleFontSize:C,overlay:E,overlayColor:A,dropShadow:x,dropShadowColor:k,dropShadowBlur:I,containerMargin:N,containerPadding:R,closeButton:L,closeButtonPosition:B,closeButtonSize:_,closeButtonBorderRadius:D,closeButtonBorderWidth:O,closeButtonBorderColor:W,closeButtonColor:V,closeButtonBackgroundColor:j,buttonsAlign:q,buttonsBorderWidth:H,buttonsBorderColor:M,buttonsBorderRadius:U,buttonsBackgroundColor:F,buttonsTextColor:K,buttonsFontName:z,buttonsFontStyle:G,buttonsFontSize:Y,secondLink:J,secondLinkBorderWidth:Q,secondLinkBorderColor:X,secondLinkBorderRadius:Z,secondLinkBackgroundColor:ee,secondLinkTextColor:te,secondLinkFontName:ie,secondLinkFontStyle:ne,secondLinkFontSize:se,animation:re,animationDuration:oe,animationBehaviour:ae,animationSlideDirection:ce}=n?{}:i,le=document.createElement("style");le.type="text/css",e()&&le.setAttribute("abtasty-script-added","true"),this.loadFont(v,y),this.loadFont(S,T),this.loadFont(z,G),this.loadFont(ie,ne);const he=`background: ${["string"==typeof r?r:"rgba(255, 255, 255, 1)",o&&"string"==typeof a&&a.length?`url(${a})`:"",o&&"string"==typeof l&&"100% 100%"!==c?l:"0 0",o&&"string"==typeof c?`/ ${c}`:"/ auto",o&&h&&!["cover","100% 100%"].includes(c)?"repeat":"no-repeat"].join(" ").trim()};`,de="number"==typeof g&&g>0,ue=`border: ${[de?`${g}px`:"unset",de?"solid":"",de&&"string"==typeof d&&d.length?d:""].join(" ").trim()};`,ge=void 0!==u?`border-radius: ${u}px;`:"",me=void 0!==m?`color: ${m}; fill: ${m}; -webkit-text-fill-color: ${m};`:"",pe=void 0!==p?`text-align: ${p};`:"",ve=v&&"inherit"!==v?`font-family:${v}_${y.match(P)?y.match(P)[1]:""};`:y||"",ye=f?`font-size: ${f}px;`:"",fe=void 0!==x&&x?`box-shadow: 0 5px ${I}px 0 ${k};`:"",be=N instanceof Array&&1===N.length&&N[0],we=be?`margin: ${be.top}px ${be.right}px ${be.bottom}px ${be.left}px;`:"",$e=be?`margin: calc(${be.top}px * 0.5) calc(${be.right}px * 0.5) calc(${be.bottom}px * 0.5) calc(${be.left}px * 0.5);`:"",Se=R instanceof Array&&1===R.length&&R[0],Te=Se?`padding: ${Se.top}px ${Se.right}px ${Se.bottom}px ${Se.left}px;`:"",Ce=Se?`padding: calc(${Se.top}px * 0.5) calc(${Se.right}px * 0.5) calc(${Se.bottom}px * 0.5) calc(${Se.left}px * 0.5);`:"",Ee=void 0!==H&&H?`border-width: ${H}px; border-style: solid;`:"",Ae=[M,H].every(e=>void 0!==e)&&H?`border-color: ${M};`:"",Pe=void 0!==U?`border-radius: ${U}px;`:"",xe=void 0!==F?`background-color: ${F};`:"",ke=void 0!==K?`color: ${K}; fill: ${K}; -webkit-text-fill-color: ${K};`:"",Ie=z&&"inherit"!==z?`font-family:${z}_${G.match(P)?G.match(P)[1]:""};`:G||"",Ne=Y?`font-size: ${Y}px;`:"",Re=void 0!==Q&&Q?`border-width: ${Q}px; border-style: solid;`:"",Le=[X,Q].every(e=>void 0!==e)&&Q?`border-color: ${X};`:"",Be=void 0!==Z?`border-radius: ${Z}px;`:"",_e=void 0!==ee?`background-color: ${ee};`:"",De=void 0!==te?`color: ${te}; fill: ${te}; -webkit-text-fill-color: ${te};`:"",Oe=ie&&"inherit"!==ie?`font-family:${ie}_${ne.match(P)?ne.match(P)[1]:""};`:ne||"",We=se?`font-size: ${se}px;`:"",Ve="popin"!==s||void 0!==E&&!0!==E?"":[`#${this.widgetContainerId} .${this.overlayClassName} {`,`background-color: ${void 0!==A?A:"rgba(0, 0, 0, 0.6)"};`,"}"].join(""),je="number"==typeof _?_:16,qe=je/2,He=n||void 0!==L&&L?[`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} {`,"position: absolute;",("out"===B?`bottom: calc(100% + ${qe}px)`:`top: ${qe}px`)+";",`right: ${qe}px;`,"width: auto;","height: auto;","background: none;","border: none;","cursor: pointer;","outline: none;","padding: 0;","margin: 0;","line-height: 0;","z-index: 9;","number"==typeof D?`border-radius: ${D}px;`:"","number"==typeof O&&O>0?`border: ${O}px solid ${void 0!==W?W:"rgba(57, 57, 57, 1)"};`:"","string"==typeof j?`background-color: ${j};`:"","}",`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} svg {`,"pointer-events: none;",`width: ${je}px;`,`height: ${je}px;`,"string"==typeof V?`fill: ${V};`:"","}"].join(""):"",Me=b&&"string"==typeof $?[`#${this.widgetContainerId} .${this.contentClassName} > * h1, `,`#${this.widgetContainerId} .${this.contentClassName} > * h2, `,`#${this.widgetContainerId} .${this.contentClassName} > * h3, `,`#${this.widgetContainerId} .${this.contentClassName} > * h4, `,`#${this.widgetContainerId} .${this.contentClassName} > * h5, `,`#${this.widgetContainerId} .${this.contentClassName} > * h6 {`,`color: ${$}; fill: ${$}; -webkit-text-fill-color: ${$};`,void 0!==w?`text-align: ${w};`:"",S&&"inherit"!==S?`font-family:${S}_${T.match(P)?T.match(P)[1]:""};`:T||"",C?`font-size: ${C}px;`:"","}"].join(""):"";let Ue="";if("string"==typeof re){const t=(oe/1e3).toFixed(2),i=["top","bottom"].includes(ce),n=Number(i),s=[(["top","left"].includes(ce)?"-":"")+"100vmax",this.translateValues?this.translateValues[n]:"0"];i&&s.reverse(),Ue={none:[],fade:[`#${this.widgetContainerId} {`,`transition: opacity ${t}s ${ae};`,"}"],slide:[`.${this.hideClassName} .${this.overlayClassName} {`,"opacity: 0 !important;","}",`#${this.widgetContainerId} .${this.overlayClassName} {`,`transition: opacity ${t}s ${ae};`,"}",`.${this.hideClassName} .${this.contentClassName} {`,`transform: translate(${s.join(", ")}) !important;`,"}",`#${this.widgetContainerId} .${this.contentClassName} {`,`transition: transform ${t}s ${ae};`,"}"]}[e()&&!ABTASTY_S.WIDGETS.animationChanged?"none":re].join("")}const Fe=[`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,`margin-${"fill"===q?"top":"left"}: 8px;`,Re,Le,Be,_e,De,Oe,We,"}",`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,De,Oe,We,"}"];return le.textContent=[`.${this.hideClassName} {`,"opacity: 0 !important;","pointer-events: none;","}",`#${this.widgetContainerId} {`,"opacity: 1;","}",`#${this.widgetContainerId} .${this.contentClassName} {`,he,ge,ue,me,pe,fe,we,ve,ye,"}",`#${this.widgetContainerId} .${this.contentClassName} p {`,me,pe,ve,ye,"}",`#${this.widgetContainerId} .${this.contentClassName} > * {`,"display: block;","line-height: 1;","text-indent: unset;",Te,ve,ye,"}",`#${this.widgetContainerId} .${this.contentClassName} a {`,"text-decoration: underline;","}",`#${this.widgetContainerId} .${this.contentClassName} div.buttons_container a, `,`#${this.widgetContainerId} .${this.contentClassName} button {`,"text-decoration: none;","box-sizing: border-box;","display: inline-block;",Ee,Ae,Pe,xe,ke,Ie,Ne,"}",`#${this.widgetContainerId} .${this.contentClassName} div.buttons_container a *, `,`#${this.widgetContainerId} .${this.contentClassName} button:not(class*="close_button") * {`,ke,Ie,Ne,"}",...J?Fe:[],"@media screen and (max-width: 579px) {",`#${this.widgetContainerId} .${this.contentClassName} {`,$e,"}",`#${this.widgetContainerId} .${this.contentClassName} > * {`,Ce,"}","}",Ve,He,Me,Ue,`${t}`].join(""),le}}const I=["top: 0;","top: 50%;","bottom: 0;"],N=["left: 0;","left: 50%;","right: 0;"],R=e=>1===e?"-50%":0,L=()=>{if(Array.isArray(DATA.popinPosition)){const{popinPosition:[{x:e,y:t}]}=DATA,i=`translate(${R(t)}, ${R(e)});`;return`${I[e]}${N[t]}transform: ${i}`}return"left: 50%;top: 50%;transform: translate(-50%, -50%);"},B=()=>"autoWidth"in DATA&&!0===DATA.autoWidth,_=()=>{if(B())return"width: auto; height: auto; min-width: fit-content;";const{popinPercentWidth:e,popinPixelsWidth:t,widthUnit:i,autoHeight:n,popinPercentHeight:s,popinPixelsHeight:r,heightUnit:o}=DATA;return`width: ${"px"===i?t:e}${i};height: ${n?"auto":`${"px"===o?r:s}${o}`};`};function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}var O,W,V,j=function(){function t(e){var i=e.parentContainer;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this.parentContainer=i,this.className="popinsimple_container_".concat(i.uniqueId),this.contentElement=this.getContentElement(),this.styleElement=this.getStyleElement()}var i,n;return i=t,n=[{key:"remove",value:function(){var e=this,t=DATA.animationDuration;setTimeout(function(){return e.parentContainer.remove()},1.05*t)}},{key:"addCloseEvent",value:function(t){var i=this;t&&t.addEventListener("click",function(t){c(t),e()||i.parentContainer.recurrence.setClosingRecurrence(),i.parentContainer.hide(),i.remove()},{capture:!0,passive:!1})}},{key:"addRedirectionEvent",value:function(t){var i=this;!e()&&t&&t.addEventListener("click",function(){var t=DATA,n=t.autoHide,s=t.timeHide;n&&setTimeout(function(){i.parentContainer.hide(),i.remove()},1e3*s),e()||i.parentContainer.recurrence.setValidationRecurrence()},{capture:!0,passive:!0})}},{key:"buttonBuilder",value:function(e,t,i,n){var s=arguments.length>4&&void 0!==arguments[4]&&arguments[4],r=document.createElement("a");return s&&(r.className="second_link"),r.innerHTML="<span>".concat(e,"</span>"),r.href="button"===t?i:"#","button"===t?(r.target=n?"_blank":"_self",this.addRedirectionEvent(r)):(r.dataset.abtastyActionnable="true",this.addCloseEvent(r)),r}},{key:"getButtons",value:function(){var e=this,t=function(t,i,n,s){var r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=document.createElement("a");return r&&(o.className="second_link"),o.innerHTML="<span>".concat(t,"</span>"),o.href="button"===i?n:"#","button"===i?(o.target=s?"_blank":"_self",e.addRedirectionEvent(o)):(o.dataset.abtastyActionnable="true",e.addCloseEvent(o)),o},i=DATA,n=i.linkType,s=i.buttonText,r=i.redirectionUrl,o=i.openInNewTab,a=i.secondLink,c=i.secondLinkText,l=i.secondLinkType,h=i.secondLinkURL,d=i.secondLinkOpenInNewTab,u=[t(s,n,r,o)];if(a){var g=t(c,l,h,d,a);u.push(g)}return u}},{key:"insertIn",value:function(e,t){return document.head.insertAdjacentElement("beforeend",this.styleElement),e.insertAdjacentElement(t,this.contentElement),e}},{key:"getContentElement",value:function(){var e=DATA,t=e.linkType,i=e.buttonText,n=e.redirectionUrl,s=e.isTitle,r=e.title,o=e.textContent,a=e.openInNewTab,c=document.createElement(t&&t.includes("widget")?"a":"div");c.className=this.className,"widget"===t?(c.href=n,c.target=a?"_blank":"_self",this.addRedirectionEvent(c)):"widgetClose"===t&&(c.href="#",c.dataset.abtastyActionnable="true",this.addCloseEvent(c));var l=document.createElement("div");if(l.className="popin_text_container",l.innerHTML="".concat(s?'<h2 class="popin_simple_title">'.concat(r,"</h2>"):"",'<p class="popin_simple_text">').concat(o,"</p>"),[t,i].every(function(e){return"string"==typeof e})&&t.includes("button")&&i.length){var h=this.getButtons(),d=document.createElement("div");d.className="buttons_container",h.forEach(function(e){return d.appendChild(e)}),l.appendChild(d)}return c.appendChild(l),c}},{key:"getStyleElement",value:function(){var t=document.createElement("style");t.type="text/css",e()&&t.setAttribute("abtasty-script-added","true");var i=DATA,n=i.linkType,s=i.buttonsAlign,r="#".concat(this.parentContainer.widgetContainerId," .").concat(this.parentContainer.contentClassName),o=void 0!==s&&"fill"!==s?"text-align: ".concat(s,";"):"",a=["".concat(r," .buttons_container {"),"display: inline-block;","width: 100%;",o,"}","".concat(r," .buttons_container a {"),"margin: 25px 0 0 0;","padding: 10px 22px;","max-width: 100%;","width: ".concat("fill"===s?"100%":"auto",";"),"text-align: center;","}"].join(""),c=["".concat(r," .popin_simple_title {"),"margin: 0 0 25px 0;","display: inline-block;","width: 100%;","}","".concat(r," .popin_text_container {"),"line-height: 1;","white-space: pre-line;","display: inline-block;","vertical-align: middle;","width: 100%;","}","".concat(r," .popin_text_container p {"),"margin: 0;","}"];return n&&n.includes("button")&&c.push(a),t.textContent=c.join(""),t}}],n&&function(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(s=function(e){if("object"!==D(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!==D(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key),"symbol"===D(s)?s:String(s)),n)}var s}(i.prototype,n),Object.defineProperty(i,"prototype",{writable:!1}),t}();W=new j({parentContainer:O=new class extends k{constructor(){super(),this.translateValues=Object.values(DATA.popinPosition[0]).map(e=>R(e)),this.stringStyles=this.getStyles(),this.styleElement=this.getStyleTag(this.stringStyles)}getStyles(){const{zindex:e,zindexCustom:t,overlay:i,widthUnit:n}=DATA;return[`#${this.widgetContainerId} {`,"position: fixed;","top: 0;","left: 0;","width: 100%;","height: 100%;",`z-index: ${"custom"===e?t:e};`,"background: none;","pointer-events: "+(!1===i?"none":"all"),"}",`#${this.widgetContainerId} .${this.overlayClassName} {`,"position: absolute;","z-index: -1;","top: 0;","left: 0;","width: 100%;","height: 100%;","}",`#${this.widgetContainerId} .${this.contentClassName} {`,"position: absolute;",L(),_(),"pointer-events: all","}",`${B()?"":[`#${this.widgetContainerId} .${this.contentClassName} > div {`,"height: 100%;","overflow: auto;","box-sizing: border-box;","}"].join("")}`,`${!B()&&["px","em"].includes(n)?["@media screen and (max-width: 579px) {",`#${this.widgetContainerId} .${this.contentClassName} {`,"max-width: 94vw;","}","}"].join(""):""}`].join("")}}}),V=O.domElement.querySelector(".".concat(O.contentClassName)),O.children=W,W.insertIn(V,"beforeend"),O.init().then(function(e){e.response&&O.show()})}();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@abtasty/popin-simple",
3
3
  "description": "A simple way to create a simple modal.",
4
- "version": "1.5.6",
4
+ "version": "1.5.7",
5
5
  "main": "dist/main.js",
6
6
  "form": "dist/form.js",
7
7
  "type": "module",