@abtasty/action-button 0.0.14 → 0.0.16-0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/form.js +1 -1
- package/dist/main.js +1 -1
- package/package.json +8 -5
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},s=e=>new Function(`try {\n\t\t${e}\n\t} catch (error) {\n\t\treturn null;\n\t}`)(),i=()=>encodeURIComponent(DATA.spNoTrim?window.location.href.replace(window.location.origin,""):`${window.location.pathname}`),n=()=>!e()&&(t()||!!window.ABTasty.getTestsOnPage()[TEST_ID]),r=()=>window.ABTasty&&!0===window.ABTasty.consentReady,o=(e,t)=>{const s=()=>{try{return document.querySelector(e)}catch(e){return null}};let i=s();const n=[document.querySelector("body")||document.documentElement,{childList:!0,subtree:!0,attributes:!0}],r=()=>a.disconnect(),o=()=>a.observe(...n),a=new MutationObserver(()=>(i=s(),i&&!r()&&t(i)));return i?setTimeout(()=>t(i),0):o(),{selector:e,clear:r,observe:o}};function a(e,t){return t(e)||!e.parentElement?e:a(e.parentElement,t)}const c=(e,t)=>[...document.querySelectorAll(t)].some(s=>s===e||!!e.closest(t)),l=(e,t)=>{let s=Date.now();return()=>{s+t-Date.now()<=0&&(e(),s=Date.now())}},h=()=>{const{type:e}=DATA;return`${PACKAGE.replace("@abtasty/","")}${e?`_${e}`:""}`},d=()=>{const e=h();return`${e.charAt(0).toUpperCase()}${e.slice(1)}`.split("-").join(" ")},u=()=>`${PLUGIN_ID.split("-")[0]}_${TEST_ID}`,g=s=>{const i=(()=>{if(e()||t())return!1;const s=ABTasty.getTestsOnPage()[TEST_ID];return!!s&&Object.keys(s.targetings.qaParameters).length>0})(),n=document.cookie.includes("abTastyDebug=")||!0===window.abTastyDebug;if(i||n){const e=d();window.console.log(`%c${e} - ${i?"QA":"Debug"} Mode for campaign ${TEST_ID} %c ${s}`,"background-color: #D6FF01; color: #3100be; padding: 3px 0 3px 10px; border-radius: 5px 0 0 5px; font-weight: bold;","background-color: #3100be; color: white; padding: 3px 10px 3px 0; border-radius: 0 5px 5px 0;")}},m=e=>{const t={promise:null,resolve:null,reject:null,name:e};return t.promise=new Promise((e,s)=>{t.resolve=e,t.reject=s}),t};class p{constructor(){this.targets=[],this.existingTargets=[],this.inViewportTargets=[],this.visibilityObserver=this.startVisibilityObserver(),this.mutationObserver=null,this.mouseOverEvent=this.mouseOverHandler(),this.scrollEvent=this.scrollEventHandler(),this.onTransitionEnd=this.transitionOverHandler()}transitionOverHandler(){const e=["transitionend",this.checkElements.bind(this),!0];return this.getEvents(e)}intersectionHandler(e){e.forEach(e=>{e.isIntersecting?(this.existingTargets.forEach(t=>{t.element.isSameNode(e.target)&&(this.inViewportTargets.push(t),this.mouseOverEvent.start(),this.scrollEvent.start(),this.onTransitionEnd.start())}),this.checkElements()):this.inViewportTargets=this.inViewportTargets.filter(t=>!t.element.isSameNode(e.target)||(this.mouseOverEvent.clear(),this.scrollEvent.clear(),this.onTransitionEnd.clear(),!1))})}startVisibilityObserver(){return new IntersectionObserver(this.intersectionHandler.bind(this),{root:null,rootMargin:"0px",threshold:0})}startMutationObserver(){this.mutationObserver??=new MutationObserver(this.checkElements.bind(this));const{clear:e}=o("body",t=>{e(),this.mutationObserver.observe(t,{attributes:!0,childList:!0,subtree:!0})});return this.mutationObserver}onMouseOver({target:e,path:t}){const s=this.inViewportTargets.find(({element:s,selector:i})=>{if(s.isSameNode(e))return!0;const n=[...e.querySelectorAll(i)];if(n.length&&n.includes(s))return!0;if(t.includes(s))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(s))return!0;if(a.some(e=>[...e.querySelectorAll(i)].includes(s)))return!0}return!1});if(s&&this.isElementVisible(s.element)){const{selector:e,element:t,uniqueId:i}=s,n=this.targets.find(t=>t.selector===e&&t.uniqueId===i);n&&n.resolve(t),this.clear(e,i)}}getEvents(e){return{start:()=>document.addEventListener(...e),clear:()=>document.removeEventListener(...e)}}mouseOverHandler(){const e=["ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0?"touchmove":"mouseover",e=>{const t=e.composedPath(),{target:s}=e;setTimeout(()=>this.onMouseOver({target:s,path:t}),50)},!0];return this.getEvents(e)}scrollEventHandler(){const e=["scroll",l(this.checkElements.bind(this),50),{passive:!0}];return this.getEvents(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(),s=[[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 i=!1,n=0;for(;!i&&n<s.length;){const t=document.elementFromPoint(...s[n]);i=e===t||e.contains(t),n+=1}return i}checkElements(){this.targets.forEach(({selector:e,uniqueId:t})=>{const s=document.querySelector(e);s&&!this.existingTargets.find(s=>s.element.matches(e)&&s.uniqueId===t)&&(this.existingTargets.push({element:s,selector:e,uniqueId:t}),this.visibilityObserver.observe(s))}),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:s})=>{if(t.matches(e)&&this.isElementVisible(t)){const i=this.targets.find(t=>t.selector===e&&t.uniqueId===s);return i&&i.resolve(t),this.clear(e,s),!1}return!0})}watch(e,t,s){this.targets.push({selector:e,resolve:t,uniqueId:s}),this.startMutationObserver(),this.checkElements()}clear(e,t){[this.targets,this.existingTargets,this.inViewportTargets]=[this.targets,this.existingTargets,this.inViewportTargets].map(s=>s.filter(({selector:s,uniqueId:i})=>s!==e&&i!==t));const s=document.querySelector(e);s&&this.visibilityObserver.unobserve(s),0===this.targets.length&&this.mutationObserver?.disconnect(),0===this.inViewportTargets.length&&(this.mouseOverEvent.clear(),this.scrollEvent.clear(),this.onTransitionEnd.clear())}}const v="remove",b="rebuild",y="update";class w{constructor({triggerEvent:e,triggerSelector:t,triggerDelay:s,triggerTarget:i}){this.event=e,this.selector=t&&t.length?t:"body",this.target=i,this.delay=1e3*s,this.elementsSelectors=[],this.eventsListeners=[],this.timeouts=[],this.intervals=[],this.promises=[],this.visibilityObservers=[],this.socialProofStore={}}async onElementVisible({promise:e,resolve:t}){const s=m(`${this.event}DomReady`);this.promises.push(s);const i=await this.onPageLoad(s),n=new p;if(this.visibilityObservers.push(n),i){const e=u();n.watch(this.selector,t,e)}return e}onPageLoad({promise:e,resolve:t}){const s=()=>"complete"===document.readyState;if(!s()){const i=["readystatechange",()=>s()&&t(!0),{passive:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}return t(!0),e}onClick({promise:e,resolve:t}){const s=document.createElement("style");s.type="text/css",s.id=`Click_${u()}`,s.innerHTML=`${this.selector} {\n\t\t\tcursor: pointer !important;\n\t\t\tpointer-events: all !important;\n\t\t}`,document.head.appendChild(s),this.elementsSelectors.push(`#${s.id}`);const i=["click",({isTrusted:e,target:s})=>{const i=s.isEqualNode(this.target)||c(s,this.selector);return e&&i&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}onHover({promise:e,resolve:t}){const s=["mouseenter",({isTrusted:e,target:s})=>{const i=this.target?s.isEqualNode(this.target):c(s,this.selector);return e&&i&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document.documentElement,...s]),document.documentElement.addEventListener(...s),e}onExitIntent({promise:e,resolve:t}){const s=["mouseleave",({isTrusted:e,clientY:s})=>{e&&s<=0&&t(!0)},{passive:!0}],{clear:i}=o("body",e=>{i(),this.eventsListeners.push([e,...s]),e.addEventListener(...s)});return e}onReengage({promise:e,resolve:t}){const s=this.delay;let i=s;const n=[({isTrusted:e})=>{e&&(i=s)},{passive:!0}];["click","mousemove","scroll","keypress"].forEach(e=>{this.eventsListeners.push([document,e,...n]),document.addEventListener(e,...n)});const r=setInterval(()=>{i<=0?t(!0):i-=100},100);return this.intervals.push(r),e}onCustomTrigger({promise:e,resolve:t}){const{triggerEventCustomScript:s}=DATA;return new Function(`return new Promise(async resolve => {${s}})`)().then(e=>e&&t(!0)),e}onScrollUp({promise:e,resolve:t}){let s=0;const i=["scroll",({isTrusted:e})=>{e&&(window.pageYOffset<s?t(!0):s=window.pageYOffset)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}onScrollPercentReached({promise:e,resolve:t}){const{triggerEventScrollPercent:s}=DATA,i=["scroll",({isTrusted:e})=>{if(!e)return;const i=(()=>{const{documentElement:e,body:t}=document,s=e.scrollTop||t.scrollTop,i=e.scrollHeight||t.scrollHeight;return Math.trunc(s/(i-e.clientHeight)*100,10)})();s<i&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}checkSocialProofConditions(e,t,s,i){const n=(()=>{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))s(this.socialProofStore[e])?i(`${this.socialProofStore[e][r]}`):i(!1);else if(e&&n){const a=t=>(this.socialProofStore[e]=t,i(!!s(t)&&`${t[r]}`));fetch(`https://api-social-proof.abtasty.com/clients/${n}/metrics/${t}?key=${e}${o?"&noTrim=true":""}`).then(e=>e.ok&&e.json()).then(a).catch(()=>g("Failed to fetch datas from server."))}else i(!1)}getSocialProofDatas({promise:e,resolve:t},n,r=!1){const{productKey:o,keyType:a}=(()=>{const{socialProofContentType:e,productKeyProvider:t,pathToProductKey:n,customJSProductKey:r,productSKU:o}=DATA;if(2===e)return{productKey:i(),keyType:"url"};{let a=null,c="sku";switch(t){case"ABTastyProductKey":a=window.ABTastyProductKey;break;case"pathToProductKey":a=s(`return ${n};`);break;case"customJSProductKey":a=s(r);break;case"productSKU":a=o}return a||3!==e||(a=i(),c="url"),{productKey:a,keyType:c}}})(),{viewInterval:c,triggerSocialProofMinVisitors:l,triggerSocialProofMinPurchases:h,triggerSocialProofMinPageViews:d}=DATA,u={pv:d,i:h,"v-pv":l}[n];return[typeof c,typeof u].includes("undefined")&&t(!1),r&&!o&&(g("Not able to find ABTastyProductKey, impossible to call the API, read documentation for more informations:\n\t\t\t\thttps://support.abtasty.com/hc/en-us/articles/4710919241628-Widgets-List#h_84c04344-c655-4e5e-b9ab-d26a798ad9b0"),t(!1)),this.checkSocialProofConditions(o,"v-pv"===n&&"sku"===a?"v-i":n,e=>{const t=void 0!==e[c]&&e[c]>=u;return t||g(`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 s=["abtasty_consentValid",()=>t(!0)];return this.eventsListeners.push(s),window.addEventListener(...s),e}return t(!0),e}onTrackingSent({promise:e,resolve:t}){const{triggerEventTrackingSent:s}=DATA;let i=localStorage.getItem("ABTastyData");const n=()=>JSON.parse(i).ActionTracking.find(({name:e})=>e===s),r=["storage",()=>{i=localStorage.getItem("ABTastyData"),n()&&t(!0)},{passive:!0,capture:!0}];return i&&n()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onMinPagesViewed({promise:e,resolve:t}){const{triggerEventMinPagesViewed:s}=DATA;let i=localStorage.getItem("ABTastyData");const n=()=>s<=(i?JSON.parse(i).VisitedPages.length:0),r=["storage",()=>{i=localStorage.getItem("ABTastyData"),n()&&t(!0)},{passive:!0,capture:!0}];return i&&n()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onRageClick({promise:e,resolve:t}){const{triggerEventRageClickQuantity:s,triggerEventRageClickDelay:i}=DATA;let n=0,r=!1;const o=["click",({isTrusted:e})=>{if(e&&(n+=1,n>=s&&t(!0),!r)){r=!0;const e=setTimeout(()=>{n=0,r=!1},i);this.timeouts.push(e)}},{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,...s]=e;t&&s.length>1&&t.removeEventListener(...s)}),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.visibilityObservers.length){const e=u();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}async isTriggered(){this.clear();const e=m(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")},s=!Object.prototype.hasOwnProperty.call(t,this.event)||await t[this.event]();return s&&this.clear(),"reengage"!==this.event&&this.delay?s&&await(async()=>{const e=m(`${this.event}Delay`);this.promises.push(e);const t=setTimeout(()=>{e.resolve(!0),this.clear()},this.delay);return this.timeouts.push(t),e.promise})():s}}const $="display",f="closing",S="validation",T="ABTastyWidgets",C=`${T}Temporary`;class E{constructor({displayRecurrence:e,closingRecurrence:t,validationRecurrence:s},i){this.displayRecurrence=parseFloat(e),this.closingRecurrence=parseFloat(t),this.validationRecurrence=parseFloat(s),this.onSetCallback=i,this.widgetName=h(),this.uniqueId=u(),this.recurrenceKey=`${this.widgetName}_${this.uniqueId}`,this.isListeningStorageEvent=this.listenStorageEvent(),this.pendingRecurrence=!1,this.pendingRecurrenceValue={}}onStorage({key:e}){const t=localStorage.getItem(C),s=sessionStorage.getItem(T);"ABTastyData"===e&&!t&&s&&localStorage.setItem(C,s)}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]:s,...i}=t;return Object.entries(i).length?(e.setItem(T,JSON.stringify(i)),i):(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 s=this.getLocalRecurrence(),i=(s?parseFloat(s.stamp):0)<(new Date).getTime();return i&&this.removeLocalRecurrenceStorage(),!this.pendingRecurrence&&i&&!this.getLocalRecurrence()&&!t}setRecurrence(e,s){0!==e&&(window.removeEventListener("storage",this.onStorage.bind(this)),this.isListeningStorageEvent=!1);const i=this.getTypeOfStorage(e);if(t()||!i&&"object"!=typeof i)return!1;const{storageString:n,storageMethod:o}=i,a=this.getStamp(e),c={type:s,stamp:a},{type:l}=this.getCurrentRecurrence(),h=async()=>{if(!r()){this.pendingRecurrence=!0,this.pendingRecurrenceValue=c;const e=new w({triggerEvent:"consent"});await e.isTriggered(),this.pendingRecurrence=!1,this.pendingRecurrenceValue={}}const e=this.getSessionRecurrence(),t=this.getLocalRecurrence();let s;"session"===n?e?s=this.removeSessionRecurrenceStorage():(this.removeLocalRecurrenceStorage(),s=this.getSessionRecurrenceStorageParsed()):"local"===n&&(t?s=this.removeLocalRecurrenceStorage():(this.removeSessionRecurrenceStorage(),s=this.getLocalRecurrenceStorageParsed()));const i=s?{[this.recurrenceKey]:c,...s}:{[this.recurrenceKey]:c};o.setItem(T,JSON.stringify(i)),this.onSetCallback&&"function"==typeof this.onSetCallback&&this.onSetCallback()};if(!o)return!1;if(l&&s!==S)if(s===f&&l!==S)h();else{if(s!==$||l===S||l===f)return!1;h()}else h();return a}setDisplayRecurrence(){const e=$;this.setRecurrence(this.displayRecurrence,e)}setClosingRecurrence(){const e=f;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,s){this.isWidgetApplied=e,this.callback=t,this.shouldUpdate=s,this.observer=new MutationObserver(this.observerHandler.bind(this)),this.tagRollbackEventParams=["abtasty_resetActionTracking",this.onTagRollback.bind(this)],this.onCampaignLaunchedEventParams=["abtasty_executedCampaign",this.onCampaignLaunched.bind(this)]}decisionHandler(){const e=this.isWidgetApplied()?this.shouldUpdate&&y:b;return e?(this.clearWatcher(),this.callback(e,!0),this.watch(),this):this}onCampaignLaunched({detail:{campaignId:e}}){e===TEST_ID&&(this.callback(b,!1),this.watch())}onTagRollback(){return this.clearWatcher(),this.callback(v,!1),window.addEventListener(...this.onCampaignLaunchedEventParams),this}observerHandler(e){return n()?e.some(e=>["removedNodes","addedNodes"].some(t=>e[t]&&e[t].length))?this.decisionHandler():this:this.callback(v,!1)}watch(){if(e())return this;this.clearWatcher(),window.removeEventListener(...this.onCampaignLaunchedEventParams),document.addEventListener(...this.tagRollbackEventParams);const{clear:t}=o("body",e=>{t(),this.observer.observe(e,{childList:!0,subtree:!0})});return this}clearWatcher(){return document.removeEventListener(...this.tagRollbackEventParams),this.observer.disconnect(),this}}const I=/.+\/([^.]+)\.(otf|ttf)$/,P=["socialProofPurchases","socialProofPageViews","socialProofVisitors"];class x{constructor(t,s){this.children=void 0,this.uniqueId=`${u()}${s?`_${s}`:""}`,this.widgetName=h(),this.prettyName=d(),this.recurrenceParams=(()=>{const{displayRecurrence:t,closingRecurrence:s,validationRecurrence:i}=DATA,n=!t&&!s&&!i;if(e()||n)return!1;const r={everytime:()=>-1,session:()=>0,once:()=>395,day:e=>DATA[`${e}_day`],week:e=>7*DATA[`${e}_week`],month:e=>30.5*DATA[`${e}_month`]},o={};return t&&(o.displayRecurrence=r[t]("displayRecurrence")),s&&(o.closingRecurrence=r[s]("closingRecurrence")),i&&(o.validationRecurrence=r[i]("validationRecurrence")),o})(),this.triggerParams=(t=>{let{triggerEvent:s}=DATA;const{triggerEventClick:i,triggerEventHover:n,triggerEventReengageDelay:r,socialProofContentType:o,triggerEventElementVisible:a,triggerEventDelay:c}=DATA;if(e()||!s&&!o)return!1;const l={click:()=>i,hover:()=>n,elementVisible:()=>a},h=Object.prototype.hasOwnProperty.call(l,s)?l[s]():"body",d="reengage"===s?r:c;return o&&(s=[,"socialProofPurchases","socialProofPageViews","socialProofVisitors"][o]),{triggerEvent:s,triggerSelector:h,triggerDelay:d,triggerTarget:t}})(t),this.recurrence=!!this.recurrenceParams&&new E(this.recurrenceParams,this.clearGivenClearables.bind(this)),this.trigger=!!this.triggerParams&&new w(this.triggerParams),this.shouldUpdate=!!this.triggerParams&&P.includes(this.triggerParams.triggerEvent),this.pageWatcher=new A(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.forEach(e=>document.removeEventListener(...e)),this.eventsListeners=[],this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts=[],this.intervals.forEach(e=>clearInterval(e)),this.intervals=[],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;document.head.appendChild(this.styleElement);const e=["free"];return"drawer"===DATA.layout&&DATA.customTarget&&e.push("drawer"),new Promise(t=>{const{elementReferrer:s="body",referrerInsertType:i="beforeend"}=e.includes(DATA.layout)?DATA:{},n=o(s,e=>{this.elementsWaiters=this.elementsWaiters.filter(e=>e.selector!==s),this.removeOldDomElement(),t(e.insertAdjacentElement(i,this.domElement))});this.elementsWaiters.push(n)}).then(()=>this)}remove(){return this.trigger&&this.trigger.clear(),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.pageWatcher.clearWatcher(),this.closedByUser=!0),this.domElement.classList.add(this.hideClassName),this}async init(t){const s=e(),i=n(),r=this.trigger&&this.trigger.promises.length,o=!this.recurrence||this.recurrence.isOver();if(!s&&!i||r||!o)return{container:this,response:!1};this.pageWatcher.watch();const a=s||!this.trigger||this.trigger&&await this.trigger.isTriggered(),c={container:this,response:a};return a?(await this.insert(),this.addCloseEvent(),s||t||this.hasBeenShown||void 0===this.children||"function"!=typeof this.children.refreshContent||this.children.refreshContent(a),c):c}onPageChange(e,t){const s=()=>this.init().then(({response:e})=>{e?this.show():this.hide(!1)});t||(this.hasBeenShown=!1,this.trigger&&this.trigger.clear());const i=this.isWidgetApplied(),n={[v]:()=>i?this.remove():this.pageWatcher.watch(),[b]:()=>{this.hasBeenShown?this.closedByUser?this.pageWatcher.watch():i||this.insert().then(e=>e.show()).catch(this.pageWatcher.watch):s()},[y]:s};"function"==typeof n[e]&&n[e]()}addCloseEvent(...t){const{closeButton:s,overlay:i,overlayClickable:n,layout:r,animationDuration:o=1e3}=DATA,a=[];if(void 0!==i&&!0!==i||!0!==n||"popin"!==r||a.push(`.${this.overlayClassName}`),void 0!==s&&s&&a.push(`.${this.closeButtonClassName}`),!a.length)return this;const c=this.domElement.querySelectorAll(a.join(", "));if(!c.length)return this;const l=["click",t=>{(t=>{e()||(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation())})(t),this.recurrence&&this.recurrence.setClosingRecurrence(),this.hide(!0),setTimeout(()=>this.remove(),1.05*o)},{once:!0,capture:!0}];return t.push(...c),t.forEach(t=>{e()&&(t.dataset.abtastyActionnable="true"),t.removeEventListener(...l),t.addEventListener(...l)}),this}getDom(){const{closeButton:e,layout:t,overlay:s=!0}=DATA,i=document.createElement("div");return i.className=`${this.basicClassName} ${this.hideClassName}`,i.id=this.widgetContainerId,i.innerHTML=`\n\t\t\t${"popin"===t&&!0===s?`<div class="${this.overlayClassName}"></div>`:""}\n\t\t\t<div class="${this.contentClassName}">\n\t\t\t${e?`<button class="${this.closeButtonClassName}" aria-label="Close dialog"><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>`,i}loadFont(e,t){if(!e||"inherit"===e||!/otf|ttf/g.test(t))return;const s=document.createElement("style"),i=t.match(I)?t.match(I)[1]:"";s.innerHTML=`@font-face { font-family: '${e}_${i}'; src: url('${t}'); font-display: swap; }`,document.head.appendChild(s)}getStyleTag(t="",s=DATA){const{noStyles:i,layout:n}=s,{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:b,fontSize:y,isTitle:w,titleTextAlign:$,titleTextColor:f,titleFontName:S,titleFontStyle:T,titleFontSize:C,overlay:E,overlayColor:A,dropShadow:P,dropShadowColor:x,dropShadowBlur:k,containerMargin:R,containerPadding:L,closeButton:N,closeButtonPosition:B,closeButtonSize:D,closeButtonBorderRadius:_,closeButtonBorderWidth:O,closeButtonBorderColor:V,closeButtonColor:q,closeButtonBackgroundColor:W,buttonsAlign:H,buttonsBorderWidth:j,buttonsBorderColor:F,buttonsBorderRadius:M,buttonsBackgroundColor:U,buttonsTextColor:K,buttonsFontName:z,buttonsFontStyle:Y,buttonsFontSize:G,secondLink:J,secondLinkBorderWidth:X,secondLinkBorderColor:Q,secondLinkBorderRadius:Z,secondLinkBackgroundColor:ee,secondLinkTextColor:te,secondLinkFontName:se,secondLinkFontStyle:ie,secondLinkFontSize:ne,animation:re,animationDuration:oe,animationBehaviour:ae,animationSlideDirection:ce}=i?{}:s,le=document.createElement("style");le.type="text/css",e()&&le.setAttribute("abtasty-script-added","true"),this.loadFont(v,b),this.loadFont(S,T),this.loadFont(z,Y),this.loadFont(se,ie);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}_${b.match(I)?b.match(I)[1]:""};`:b||"",be=y?`font-size: ${y}px;`:"",ye=void 0!==P&&P?`box-shadow: 0 5px ${k}px 0 ${x};`:"",we=R instanceof Array&&1===R.length&&R[0],$e=we?`margin: ${we.top}px ${we.right}px ${we.bottom}px ${we.left}px;`:"",fe=we?`margin: calc(${we.top}px * 0.5) calc(${we.right}px * 0.5) calc(${we.bottom}px * 0.5) calc(${we.left}px * 0.5);`:"",Se=L instanceof Array&&1===L.length&&L[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!==j&&j?`border-width: ${j}px; border-style: solid;`:"",Ae=[F,j].every(e=>void 0!==e)&&j?`border-color: ${F};`:"",Ie=void 0!==M?`border-radius: ${M}px;`:"",Pe=void 0!==U?`background-color: ${U};`:"",xe=void 0!==K?`color: ${K}; fill: ${K}; -webkit-text-fill-color: ${K};`:"",ke=z&&"inherit"!==z?`font-family:${z}_${Y.match(I)?Y.match(I)[1]:""};`:Y||"",Re=G?`font-size: ${G}px;`:"",Le="number"==typeof X?`border-width: ${X}px; border-style: solid;`:"",Ne=[Q,X].every(e=>void 0!==e)&&X?`border-color: ${Q};`:"",Be=void 0!==Z?`border-radius: ${Z}px;`:"",De=void 0!==ee?`background-color: ${ee};`:"",_e=void 0!==te?`color: ${te}; fill: ${te}; -webkit-text-fill-color: ${te};`:"",Oe=se&&"inherit"!==se?`font-family:${se}_${ie.match(I)?ie.match(I)[1]:""};`:ie||"",Ve=ne?`font-size: ${ne}px;`:"",qe="popin"!==n||void 0!==E&&!0!==E?"":[`#${this.widgetContainerId} .${this.overlayClassName} {`,`background-color: ${void 0!==A?A:"rgba(0, 0, 0, 0.6)"};`,"}"].join(""),We="number"==typeof D?D:16,He=We/2,je=i||void 0!==N&&N?[`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} {`,"position: absolute;",("out"===B?`bottom: calc(100% + ${He}px)`:`top: ${He}px`)+";",`right: ${He}px;`,"width: auto;","height: auto;","background: none;","border: none;","cursor: pointer;","padding: 0;","margin: 0;","line-height: 0;","z-index: 9;","number"==typeof _?`border-radius: ${_}px;`:"","number"==typeof O&&O>0?`border: ${O}px solid ${void 0!==V?V:"rgba(57, 57, 57, 1)"};`:"","string"==typeof W?`background-color: ${W};`:"","}",`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} svg {`,"pointer-events: none;",`width: ${We}px;`,`height: ${We}px;`,"string"==typeof q?`fill: ${q};`:"","}"].join(""):"",Fe=w&&"string"==typeof f?[`#${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: ${f}; fill: ${f}; -webkit-text-fill-color: ${f};`,void 0!==$?`text-align: ${$};`:"",S&&"inherit"!==S?`font-family:${S}_${T.match(I)?T.match(I)[1]:""};`:T||"",C?`font-size: ${C}px;`:"","}"].join(""):"";let Me="";if("string"==typeof re){const t=(oe/1e3).toFixed(2),s=["top","bottom"].includes(ce),i=Number(s),n=[(["top","left"].includes(ce)?"-":"")+"100vmax",this.translateValues?this.translateValues[i]:"0"];s&&n.reverse(),Me={none:[`.${this.hideClassName} {`,"opacity: 0 !important;","}"],fade:[`.${this.hideClassName} {`,"opacity: 0 !important;","}",`#${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(${n.join(", ")}) !important;`,"}",`#${this.widgetContainerId} .${this.contentClassName} {`,`transition: transform ${t}s ${ae};`,"}"]}[e()&&!ABTASTY_S.WIDGETS.animationChanged?"none":re].join("")}const Ue=[`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,`margin-${"fill"===H?"top":"left"}: 8px;`,Le,Ne,Be,De,_e,Oe,Ve,"}",`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,_e,Oe,Ve,"}"];return le.textContent=[`.${this.hideClassName} {`,"pointer-events: none;","}",`#${this.widgetContainerId} {`,"opacity: 1;","}",`#${this.widgetContainerId} .${this.contentClassName} {`,he,ge,ue,me,pe,ye,$e,ve,be,"}",`#${this.widgetContainerId} .${this.contentClassName} p {`,me,pe,ve,be,"}",`#${this.widgetContainerId} .${this.contentClassName} > * {`,"display: block;","line-height: 1;","text-indent: unset;",Te,ve,be,"}",`#${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,Ie,Pe,xe,ke,Re,"}",`#${this.widgetContainerId} .${this.contentClassName} div.buttons_container a *, `,`#${this.widgetContainerId} .${this.contentClassName} button:not(class*="close_button") * {`,xe,ke,Re,"}",...J?Ue:[],"@media screen and (max-width: 579px) {",`#${this.widgetContainerId} .${this.contentClassName} {`,fe,"}",`#${this.widgetContainerId} .${this.contentClassName} > * {`,Ce,"}","}",qe,je,Fe,Me,`${t}`].join(""),le}}class k extends x{constructor(e,t){super(e,t),this.stringStyles=this.getStyles(),this.styleElement=this.getStyleTag(this.stringStyles)}getStyles(){return[`#${this.widgetContainerId} {`,"width: auto;","height: auto;","margin: 0;","padding: 0;","background: none;","}",`#${this.widgetContainerId} .${this.contentClassName} {`,"position: relative;","}"].join("")}}const R={top:{top:0,left:50,translateX:-50,translateY:0},bottom:{top:100,left:50,translateX:-50,translateY:-100},left:{top:50,left:0,translateX:0,translateY:-50},right:{top:50,left:100,translateX:-100,translateY:-50}};class L{constructor(e){let{parentContainer:t}=e;this.parentContainer=t,this.className=`aciontButton_container_${t.uniqueId}`,this.domElement=this.getElement(),this.styleElement=this.getStyles()}insertIn(e,t){document.head.appendChild(this.styleElement),e.insertAdjacentElement(t,this.domElement)}remove(){const{animationDuration:e=1e3}=DATA;setTimeout(()=>this.parentContainer.remove(),1.05*e)}onClick(){const{autoHide:t,timeHide:s}=DATA;t&&(this.parentContainer.hide(),setTimeout(()=>{this.remove()},1e3*s)),e()||this.parentContainer.recurrence.setValidationRecurrence()}launchScript(e){const{customJS:t}=DATA,s={contentElement:this.contentElement,UTILS:{hideWidget:()=>this.parentContainer.hide(),removeWidget:()=>this.remove()},TEST_ID:TEST_ID,UNIQUE_ID:this.parentContainer.uniqueId,event:e},i=Object.keys(s),n=Object.values(s);return Function(...i,t)(...n)}getElement(){const{buttonText:t,hasButtonIcon:s,buttonIcon:i,buttonIconAlt:n,linkType:r,redirectionUrl:o,openInNewTab:a,trackerName:c}=DATA,l=document.createElement("div"),h=function(t,s,i,n){let r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=arguments.length>5?arguments[5]:void 0,a=arguments.length>6?arguments[6]:void 0;const c=document.createElement("a");return c.ariaLabel=t,c.innerHTML=`<span>${t}</span>${r?`<img src="${o}" alt="${a}">`:""}`,c.href="button"===s?i:"#","button"===s&&(c.target=n?"_blank":"_self"),e()&&(c.dataset.abtastyActionnable="true"),c}(t,r,o,a,s,i,n);return l.className="buttons_container",h.className=`action_button_${this.parentContainer.uniqueId}`,h.addEventListener("click",e=>{window.ABTastyEvent(c,null,TEST_ID),g(`Tracking "${c}" sent to campaign ${TEST_ID}`),"code"===r&&this.launchScript(e),this.onClick.bind(this)},{capture:!0,passive:!0}),l.appendChild(h),l}getStyles(){const{elementReferrer:t,positionType:s,buttonLayout:i,zindex:n,zindexCustom:r,hasButtonIcon:o,buttonsPadding:a,buttonsFontSize:c,enableButtonHoverStyles:l,buttonsBorderColorHover:h,buttonsBackgroundColorHover:d,buttonsTextColorHover:u,enableButtonHoverTransition:g}=DATA,m=document.createElement("style");e()&&m.setAttribute("abtasty-script-added","true");const p="fixed"===s,v=["left","right"].includes(i),b=`#${this.parentContainer.widgetContainerId} .${this.parentContainer.contentClassName}`,[{top:y,bottom:w,left:$,right:f}]=a,{top:S,left:T,translateX:C,translateY:E}=R[i],A=[`#${this.parentContainer.widgetContainerId} a,`,`#${this.parentContainer.widgetContainerId} span {`,"all: unset;","}",`${b} .action_button_${this.parentContainer.uniqueId} {`,"display: flex !important;","flex-direction: column;","align-items: center;","justify-content: center;",`padding: ${y}px ${f}px ${w}px ${$}px;`,"cursor: pointer;","pointer-events: all;","}",`${b} .action_button_${this.parentContainer.uniqueId} span {`,"width: auto;",p&&v?["writing-mode: vertical-rl;","text-orientation: sideways;"].join(""):"",p&&"right"===i?"transform: rotate(180deg);":"","}"];if(p){const e=document.body.matches(t);e||A.push(`${t} {`,"position: relative;","}"),A.push(`#${this.parentContainer.widgetContainerId} {`,`position: ${e?"fixed":"absolute"};`,`top: ${S}%;`,`left: ${T}%;`,`transform: translate(${C}%, ${E}%);`,`z-index: ${"custom"===n?r:n};`,"}")}return o&&A.push(`.action_button_${this.parentContainer.uniqueId} img {`,v?`transform: rotate(${i.includes("right")?"-":""}90deg);`:"",`min-width: ${2*c}px;`,`max-height: ${2*c}px;`,`margin-${v?"top":"left"}: ${c}px`,"}"),l&&A.push(`${b} .action_button_${this.parentContainer.uniqueId}:hover {`,`border-color: ${h};`,`background-color: ${d};`,`color: ${u}; fill: ${u}; -webkit-text-fill-color: ${u};`,g?"transition: all 0.5s ease;":"","}"),m.textContent=A.join(""),m}}!function(){g("Widget launch");const e=new k,t=e.domElement.querySelector(`.${e.contentClassName}`),s=new L({parentContainer:e});e.children=s,s.insertIn(t,"beforeend"),e.init(!0).then(t=>{let{response:s}=t;s&&e.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},n=e=>new Function(`try {\n\t\t${e}\n\t} catch (error) {\n\t\treturn null;\n\t}`)(),i=()=>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="remove",a="rebuild",c="update",l=()=>{const{type:e}=DATA;return`${PACKAGE.replace("@abtasty/","")}${e?`_${e}`:""}`},h=()=>{const e=l();return`${e.charAt(0).toUpperCase()}${e.slice(1)}`.split("-").join(" ")},d=()=>`${PLUGIN_ID.split("-")[0]}_${TEST_ID}`,u=n=>{const i=(()=>{if(e()||t())return!1;const n=ABTasty.getTestsOnPage()[TEST_ID];return!!n&&Object.keys(n.targetings.qaParameters).length>0})(),s=document.cookie.includes("abTastyDebug=")||!0===window.abTastyDebug;if(i||s){const e=h();window.console.log(`%c${e} - ${i?"QA":"Debug"} Mode for campaign ${TEST_ID} %c ${n}`,"background-color: #D6FF01; color: #3100be; padding: 3px 0 3px 10px; border-radius: 5px 0 0 5px; font-weight: bold;","background-color: #3100be; color: white; padding: 3px 10px 3px 0; border-radius: 0 5px 5px 0;")}},g=e=>{const t={promise:null,resolve:null,reject:null,name:e};return t.promise=new Promise((e,n)=>{t.resolve=e,t.reject=n}),t},m=(e,t)=>{const n=()=>{try{return document.querySelector(e)}catch(e){return null}};let i=n();const s=[document.querySelector("body")||document.documentElement,{childList:!0,subtree:!0,attributes:!0}],r=()=>a.disconnect(),o=()=>a.observe(...s),a=new MutationObserver(()=>(i=n(),i&&!r()&&t(i)));return i?setTimeout(()=>t(i),0):o(),{selector:e,clear:r,observe:o}};function p(e,t){return t(e)||!e.parentElement?e:p(e.parentElement,t)}const v=(e,t)=>[...document.querySelectorAll(t)].some(n=>n===e||!!e.closest(t)),y=(e,t)=>{let n=Date.now();return()=>{n+t-Date.now()<=0&&(e(),n=Date.now())}};class f{constructor(){this.targets=[],this.existingTargets=[],this.inViewportTargets=[],this.visibilityObserver=this.startVisibilityObserver(),this.mutationObserver=null,this.mouseOverEvent=this.mouseOverHandler(),this.scrollEvent=this.scrollEventHandler(),this.onTransitionEnd=this.transitionOverHandler()}transitionOverHandler(){const e=["transitionend",this.checkElements.bind(this),!0];return this.getEvents(e)}intersectionHandler(e){e.forEach(e=>{e.isIntersecting?(this.existingTargets.forEach(t=>{t.element.isSameNode(e.target)&&(this.inViewportTargets.push(t),this.mouseOverEvent.start(),this.scrollEvent.start(),this.onTransitionEnd.start())}),this.checkElements()):this.inViewportTargets=this.inViewportTargets.filter(t=>!t.element.isSameNode(e.target)||(this.mouseOverEvent.clear(),this.scrollEvent.clear(),this.onTransitionEnd.clear(),!1))})}startVisibilityObserver(){return new IntersectionObserver(this.intersectionHandler.bind(this),{root:null,rootMargin:"0px",threshold:0})}startMutationObserver(){this.mutationObserver??=new MutationObserver(this.checkElements.bind(this));const{clear:e}=m("body",t=>{e(),this.mutationObserver.observe(t,{attributes:!0,childList:!0,subtree:!0})});return this.mutationObserver}onMouseOver({target:e,path:t}){const n=this.inViewportTargets.find(({element:n,selector:i})=>{if(n.isSameNode(e))return!0;const s=[...e.querySelectorAll(i)];if(s.length&&s.includes(n))return!0;if(t.includes(n))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(n))return!0;if(a.some(e=>[...e.querySelectorAll(i)].includes(n)))return!0}return!1});if(n&&this.isElementVisible(n.element)){const{selector:e,element:t,uniqueId:i}=n,s=this.targets.find(t=>t.selector===e&&t.uniqueId===i);s&&s.resolve(t),this.clear(e,i)}}getEvents(e){return{start:()=>document.addEventListener(...e),clear:()=>document.removeEventListener(...e)}}mouseOverHandler(){const e=["ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0?"touchmove":"mouseover",e=>{const t=e.composedPath(),{target:n}=e;setTimeout(()=>this.onMouseOver({target:n,path:t}),50)},!0];return this.getEvents(e)}scrollEventHandler(){const e=["scroll",y(this.checkElements.bind(this),50),{passive:!0}];return this.getEvents(e)}isElementVisible(e){return this.isElementTopmost(e)&&this.isElementOpaque(e)}isElementOpaque(e){return"HTML"===p(e,e=>"0"===window.getComputedStyle(e).opacity).nodeName}isElementTopmost(e){const t=e.getBoundingClientRect(),n=[[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 i=!1,s=0;for(;!i&&s<n.length;){const t=document.elementFromPoint(...n[s]);i=e===t||e.contains(t),s+=1}return i}checkElements(){this.targets.forEach(({selector:e,uniqueId:t})=>{const n=document.querySelector(e);n&&!this.existingTargets.find(n=>n.element.matches(e)&&n.uniqueId===t)&&(this.existingTargets.push({element:n,selector:e,uniqueId:t}),this.visibilityObserver.observe(n))}),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:n})=>{if(t.matches(e)&&this.isElementVisible(t)){const i=this.targets.find(t=>t.selector===e&&t.uniqueId===n);return i&&i.resolve(t),this.clear(e,n),!1}return!0})}watch(e,t,n){this.targets.push({selector:e,resolve:t,uniqueId:n}),this.startMutationObserver(),this.checkElements()}clear(e,t){[this.targets,this.existingTargets,this.inViewportTargets]=[this.targets,this.existingTargets,this.inViewportTargets].map(n=>n.filter(({selector:n,uniqueId:i})=>n!==e&&i!==t));const n=document.querySelector(e);n&&this.visibilityObserver.unobserve(n),0===this.targets.length&&this.mutationObserver?.disconnect(),0===this.inViewportTargets.length&&(this.mouseOverEvent.clear(),this.scrollEvent.clear(),this.onTransitionEnd.clear())}}class b{constructor({triggerEvent:e,triggerSelector:t,triggerDelay:n,triggerTarget:i}){this.event=e,this.selector=t&&t.length?t:"body",this.target=i,this.delay=1e3*n,this.elementsSelectors=[],this.eventsListeners=[],this.timeouts=[],this.intervals=[],this.promises=[],this.visibilityObservers=[],this.socialProofStore={}}async onElementVisible({promise:e,resolve:t}){const n=g(`${this.event}DomReady`);this.promises.push(n);const i=await this.onPageLoad(n),s=new f;if(this.visibilityObservers.push(s),i){const e=d();s.watch(this.selector,t,e)}return e}onPageLoad({promise:e,resolve:t}){const n=()=>"complete"===document.readyState;if(!n()){const i=["readystatechange",()=>n()&&t(!0),{passive:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}return t(!0),e}onClick({promise:e,resolve:t}){const n=document.createElement("style");n.type="text/css",n.id=`Click_${d()}`,n.innerHTML=`${this.selector} {\n\t\t\tcursor: pointer !important;\n\t\t\tpointer-events: all !important;\n\t\t}`,document.head.appendChild(n),this.elementsSelectors.push(`#${n.id}`);const i=["click",({isTrusted:e,target:n})=>{const i=n.isEqualNode(this.target)||v(n,this.selector);return e&&i&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}onHover({promise:e,resolve:t}){const n=["mouseenter",({isTrusted:e,target:n})=>{const i=this.target?n.isEqualNode(this.target):v(n,this.selector);return e&&i&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document.documentElement,...n]),document.documentElement.addEventListener(...n),e}onExitIntent({promise:e,resolve:t}){const n=["mouseleave",({isTrusted:e,clientY:n})=>{e&&n<=0&&t(!0)},{passive:!0}],{clear:i}=m("body",e=>{i(),this.eventsListeners.push([e,...n]),e.addEventListener(...n)});return e}onReengage({promise:e,resolve:t}){const n=this.delay;let i=n;const s=[({isTrusted:e})=>{e&&(i=n)},{passive:!0}];["click","mousemove","scroll","keypress"].forEach(e=>{this.eventsListeners.push([document,e,...s]),document.addEventListener(e,...s)});const r=setInterval(()=>{i<=0?t(!0):i-=100},100);return this.intervals.push(r),e}onCustomTrigger({promise:e,resolve:t}){const{triggerEventCustomScript:n}=DATA;return new Function(`return new Promise(async resolve => {${n}})`)().then(e=>e&&t(!0)),e}onScrollUp({promise:e,resolve:t}){let n=0;const i=["scroll",({isTrusted:e})=>{e&&(window.pageYOffset<n?t(!0):n=window.pageYOffset)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}onScrollPercentReached({promise:e,resolve:t}){const{triggerEventScrollPercent:n}=DATA,i=["scroll",({isTrusted:e})=>{if(!e)return;const i=(()=>{const{documentElement:e,body:t}=document,n=e.scrollTop||t.scrollTop,i=e.scrollHeight||t.scrollHeight;return Math.trunc(n/(i-e.clientHeight)*100,10)})();n<i&&t(!0)},{passive:!0,capture:!0}];return this.eventsListeners.push([document,...i]),document.addEventListener(...i),e}checkSocialProofConditions(e,t,n,i){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))n(this.socialProofStore[e])?i(`${this.socialProofStore[e][r]}`):i(!1);else if(e&&s){const a=t=>(this.socialProofStore[e]=t,i(!!n(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(()=>u("Failed to fetch datas from server."))}else i(!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:i(),keyType:"url"};{let a=null,c="sku";switch(t){case"ABTastyProductKey":a=window.ABTastyProductKey;break;case"pathToProductKey":a=n(`return ${s};`);break;case"customJSProductKey":a=n(r);break;case"productSKU":a=o}return a||3!==e||(a=i(),c="url"),{productKey:a,keyType:c}}})(),{viewInterval:c,triggerSocialProofMinVisitors:l,triggerSocialProofMinPurchases:h,triggerSocialProofMinPageViews:d}=DATA,g={pv:d,i:h,"v-pv":l}[s];return[typeof c,typeof g].includes("undefined")&&t(!1),r&&!o&&(u("Not able to find ABTastyProductKey, impossible to call the API, read documentation for more informations:\n\t\t\t\thttps://support.abtasty.com/hc/en-us/articles/4710919241628-Widgets-List#h_84c04344-c655-4e5e-b9ab-d26a798ad9b0"),t(!1)),this.checkSocialProofConditions(o,"v-pv"===s&&"sku"===a?"v-i":s,e=>{const t=void 0!==e[c]&&e[c]>=g;return t||u(`Widget will not be shown, Social Proof API returned ${e[c]} while ${g} are required`),t},t),e}onConsent({promise:e,resolve:t}){if(!r()){const n=["abtasty_consentValid",()=>t(!0)];return this.eventsListeners.push(n),window.addEventListener(...n),e}return t(!0),e}onTrackingSent({promise:e,resolve:t}){const{triggerEventTrackingSent:n}=DATA;let i=localStorage.getItem("ABTastyData");const s=()=>JSON.parse(i).ActionTracking.find(({name:e})=>e===n),r=["storage",()=>{i=localStorage.getItem("ABTastyData"),s()&&t(!0)},{passive:!0,capture:!0}];return i&&s()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onMinPagesViewed({promise:e,resolve:t}){const{triggerEventMinPagesViewed:n}=DATA;let i=localStorage.getItem("ABTastyData");const s=()=>n<=(i?JSON.parse(i).VisitedPages.length:0),r=["storage",()=>{i=localStorage.getItem("ABTastyData"),s()&&t(!0)},{passive:!0,capture:!0}];return i&&s()?t(!0):(()=>{this.eventsListeners.push([window,...r]),window.addEventListener(...r)})(),e}onRageClick({promise:e,resolve:t}){const{triggerEventRageClickQuantity:n,triggerEventRageClickDelay:i}=DATA;let s=0,r=!1;const o=["click",({isTrusted:e})=>{if(e&&(s+=1,s>=n&&t(!0),!r)){r=!0;const e=setTimeout(()=>{s=0,r=!1},i);this.timeouts.push(e)}},{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,...n]=e;t&&n.length>1&&t.removeEventListener(...n)}),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.visibilityObservers.length){const e=d();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}async isTriggered(){this.clear();const e=g(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")},n=!Object.prototype.hasOwnProperty.call(t,this.event)||await t[this.event]();return n&&this.clear(),"reengage"!==this.event&&this.delay?n&&await(async()=>{const e=g(`${this.event}Delay`);this.promises.push(e);const t=setTimeout(()=>{e.resolve(!0),this.clear()},this.delay);return this.timeouts.push(t),e.promise})():n}}const w="display",S="closing",T="validation",$="ABTastyWidgets",C=`${$}Temporary`;class E{constructor({displayRecurrence:e,closingRecurrence:t,validationRecurrence:n},i){this.displayRecurrence=parseFloat(e),this.closingRecurrence=parseFloat(t),this.validationRecurrence=parseFloat(n),this.onSetCallback=i,this.widgetName=l(),this.uniqueId=d(),this.recurrenceKey=`${this.widgetName}_${this.uniqueId}`,this.isListeningStorageEvent=this.listenStorageEvent(),this.pendingRecurrence=!1,this.pendingRecurrenceValue={}}onStorage({key:e}){const t=localStorage.getItem(C),n=sessionStorage.getItem($);"ABTastyData"===e&&!t&&n&&localStorage.setItem(C,n)}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]:n,...i}=t;return Object.entries(i).length?(e.setItem($,JSON.stringify(i)),i):(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(C),t=!(!e||!e.includes(this.recurrenceKey))||this.getSessionRecurrence();e&&(sessionStorage.setItem($,e),localStorage.removeItem(C));const n=this.getLocalRecurrence(),i=(n?parseFloat(n.stamp):0)<(new Date).getTime();return i&&this.removeLocalRecurrenceStorage(),!this.pendingRecurrence&&i&&!this.getLocalRecurrence()&&!t}setRecurrence(e,n){0!==e&&(window.removeEventListener("storage",this.onStorage.bind(this)),this.isListeningStorageEvent=!1);const i=this.getTypeOfStorage(e);if(t()||!i&&"object"!=typeof i)return!1;const{storageString:s,storageMethod:o}=i,a=this.getStamp(e),c={type:n,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 n;"session"===s?e?n=this.removeSessionRecurrenceStorage():(this.removeLocalRecurrenceStorage(),n=this.getSessionRecurrenceStorageParsed()):"local"===s&&(t?n=this.removeLocalRecurrenceStorage():(this.removeSessionRecurrenceStorage(),n=this.getLocalRecurrenceStorageParsed()));const i=n?{[this.recurrenceKey]:c,...n}:{[this.recurrenceKey]:c};o.setItem($,JSON.stringify(i)),this.onSetCallback&&"function"==typeof this.onSetCallback&&this.onSetCallback()};if(!o)return!1;if(l&&n!==T)if(n===S&&l!==T)h();else{if(n!==w||l===T||l===S)return!1;h()}else h();return a}setDisplayRecurrence(){const e=w;this.setRecurrence(this.displayRecurrence,e)}setClosingRecurrence(){const e=S;this.setRecurrence(this.closingRecurrence,e)}setValidationRecurrence(){const e=T;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,n){this.isWidgetApplied=e,this.callback=t,this.shouldUpdate=n,this.observer=new MutationObserver(this.observerHandler.bind(this)),this.tagRollbackEventParams=["abtasty_resetActionTracking",this.onTagRollback.bind(this)],this.onCampaignLaunchedEventParams=["abtasty_executedCampaign",this.onCampaignLaunched.bind(this)]}decisionHandler(){const e=this.isWidgetApplied()?this.shouldUpdate&&c:a;return e?(this.clearWatcher(),this.callback(e,!0),this.watch(),this):this}onCampaignLaunched({detail:{campaignId:e}}){e===TEST_ID&&(this.callback(a,!1),this.watch())}onTagRollback(){return this.clearWatcher(),this.callback(o,!1),window.addEventListener(...this.onCampaignLaunchedEventParams),this}observerHandler(e){return s()?e.some(e=>["removedNodes","addedNodes"].some(t=>e[t]&&e[t].length))?this.decisionHandler():this:this.callback(o,!1)}watch(){if(e())return this;this.clearWatcher(),window.removeEventListener(...this.onCampaignLaunchedEventParams),document.addEventListener(...this.tagRollbackEventParams);const{clear:t}=m("body",e=>{t(),this.observer.observe(e,{childList:!0,subtree:!0})});return this}clearWatcher(){return document.removeEventListener(...this.tagRollbackEventParams),this.observer.disconnect(),this}}const I=/.+\/([^.]+)\.(otf|ttf)$/,P=["socialProofPurchases","socialProofPageViews","socialProofVisitors"];class k{constructor(t,n){this.children=void 0,this.uniqueId=`${d()}${n?`_${n}`:""}`,this.widgetName=l(),this.prettyName=h(),this.recurrenceParams=(()=>{const{displayRecurrence:t,closingRecurrence:n,validationRecurrence:i}=DATA,s=!t&&!n&&!i;if(e()||s)return!1;const r={everytime:()=>-1,session:()=>0,once:()=>395,day:e=>DATA[`${e}_day`],week:e=>7*DATA[`${e}_week`],month:e=>30.5*DATA[`${e}_month`]},o={};return t&&(o.displayRecurrence=r[t]("displayRecurrence")),n&&(o.closingRecurrence=r[n]("closingRecurrence")),i&&(o.validationRecurrence=r[i]("validationRecurrence")),o})(),this.triggerParams=(t=>{let{triggerEvent:n}=DATA;const{triggerEventClick:i,triggerEventHover:s,triggerEventReengageDelay:r,socialProofContentType:o,triggerEventElementVisible:a,triggerEventDelay:c}=DATA;if(e()||!n&&!o)return!1;const l={click:()=>i,hover:()=>s,elementVisible:()=>a},h=Object.prototype.hasOwnProperty.call(l,n)?l[n]():"body",d="reengage"===n?r:c;return o&&(n=[,"socialProofPurchases","socialProofPageViews","socialProofVisitors"][o]),{triggerEvent:n,triggerSelector:h,triggerDelay:d,triggerTarget:t}})(t),this.recurrence=!!this.recurrenceParams&&new E(this.recurrenceParams,this.clearGivenClearables.bind(this)),this.trigger=!!this.triggerParams&&new b(this.triggerParams),this.shouldUpdate=!!this.triggerParams&&P.includes(this.triggerParams.triggerEvent),this.pageWatcher=new A(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.forEach(e=>document.removeEventListener(...e)),this.eventsListeners=[],this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts=[],this.intervals.forEach(e=>clearInterval(e)),this.intervals=[],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;document.head.appendChild(this.styleElement);const e=["free"];return"drawer"===DATA.layout&&DATA.customTarget&&e.push("drawer"),new Promise(t=>{const{elementReferrer:n="body",referrerInsertType:i="beforeend"}=e.includes(DATA.layout)?DATA:{},s=m(n,e=>{this.elementsWaiters=this.elementsWaiters.filter(e=>e.selector!==n),this.removeOldDomElement(),t(e.insertAdjacentElement(i,this.domElement))});this.elementsWaiters.push(s)}).then(()=>this)}remove(){return this.trigger&&this.trigger.clear(),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.pageWatcher.clearWatcher(),this.closedByUser=!0),this.domElement.classList.add(this.hideClassName),this}async init(t){const n=e(),i=s(),r=this.trigger&&this.trigger.promises.length,o=!this.recurrence||this.recurrence.isOver();if(!n&&!i||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){const n=()=>this.init().then(({response:e})=>{e?this.show():this.hide(!1)});t||(this.hasBeenShown=!1,this.trigger&&this.trigger.clear());const i=this.isWidgetApplied(),s={[o]:()=>i?this.remove():this.pageWatcher.watch(),[a]:()=>{this.hasBeenShown?this.closedByUser?this.pageWatcher.watch():i||this.insert().then(e=>e.show()).catch(this.pageWatcher.watch):n()},[c]:n};"function"==typeof s[e]&&s[e]()}addCloseEvent(...t){const{closeButton:n,overlay:i,overlayClickable:s,layout:r,animationDuration:o=1e3}=DATA,a=[];if(void 0!==i&&!0!==i||!0!==s||"popin"!==r||a.push(`.${this.overlayClassName}`),void 0!==n&&n&&a.push(`.${this.closeButtonClassName}`),!a.length)return this;const c=this.domElement.querySelectorAll(a.join(", "));if(!c.length)return this;const l=["click",t=>{(t=>{e()||(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation())})(t),this.recurrence&&this.recurrence.setClosingRecurrence(),this.hide(!0),setTimeout(()=>this.remove(),1.05*o)},{once:!0,capture:!0}];return t.push(...c),t.forEach(t=>{e()&&(t.dataset.abtastyActionnable="true"),t.removeEventListener(...l),t.addEventListener(...l)}),this}getDom(){const{closeButton:e,layout:t,overlay:n=!0}=DATA,i=document.createElement("div");return i.className=`${this.basicClassName} ${this.hideClassName}`,i.id=this.widgetContainerId,["popin","banner"].includes(t)&&(i.role="dialog"),i.innerHTML=`\n\t\t\t${"popin"===t&&!0===n?`<div class="${this.overlayClassName}"></div>`:""}\n\t\t\t<div class="${this.contentClassName}">\n\t\t\t${e?`<button class="${this.closeButtonClassName}" aria-label="Close dialog"><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>`,i}loadFont(e,t){if(!e||"inherit"===e||!/otf|ttf/g.test(t))return;const n=document.createElement("style"),i=t.match(I)?t.match(I)[1]:"";n.innerHTML=`@font-face { font-family: '${e}_${i}'; src: url('${t}'); font-display: swap; }`,document.head.appendChild(n)}getStyleTag(t="",n=DATA){const{noStyles:i,layout:s}=n,{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:S,titleFontName:T,titleFontStyle:$,titleFontSize:C,overlay:E,overlayColor:A,dropShadow:P,dropShadowColor:k,dropShadowBlur:x,containerMargin:R,containerPadding:L,closeButton:N,closeButtonPosition:B,closeButtonSize:D,closeButtonBorderRadius:_,closeButtonBorderWidth:O,closeButtonBorderColor:V,closeButtonColor:q,closeButtonBackgroundColor:W,buttonsAlign:j,buttonsBorderWidth:H,buttonsBorderColor:M,buttonsBorderRadius:F,buttonsBackgroundColor:U,buttonsTextColor:K,buttonsFontName:z,buttonsFontStyle:Y,buttonsFontSize:G,secondLink:J,secondLinkBorderWidth:X,secondLinkBorderColor:Q,secondLinkBorderRadius:Z,secondLinkBackgroundColor:ee,secondLinkTextColor:te,secondLinkFontName:ne,secondLinkFontStyle:ie,secondLinkFontSize:se,animation:re,animationDuration:oe,animationBehaviour:ae,animationSlideDirection:ce}=i?{}:n,le=document.createElement("style");le.type="text/css",e()&&le.setAttribute("abtasty-script-added","true"),this.loadFont(v,y),this.loadFont(T,$),this.loadFont(z,Y),this.loadFont(ne,ie);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(I)?y.match(I)[1]:""};`:y||"",ye=f?`font-size: ${f}px;`:"",fe=void 0!==P&&P?`box-shadow: 0 5px ${x}px 0 ${k};`:"",be=R instanceof Array&&1===R.length&&R[0],we=be?`margin: ${be.top}px ${be.right}px ${be.bottom}px ${be.left}px;`:"",Se=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);`:"",Te=L instanceof Array&&1===L.length&&L[0],$e=Te?`padding: ${Te.top}px ${Te.right}px ${Te.bottom}px ${Te.left}px;`:"",Ce=Te?`padding: calc(${Te.top}px * 0.5) calc(${Te.right}px * 0.5) calc(${Te.bottom}px * 0.5) calc(${Te.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};`:"",Ie=void 0!==F?`border-radius: ${F}px;`:"",Pe=void 0!==U?`background-color: ${U};`:"",ke=void 0!==K?`color: ${K}; fill: ${K}; -webkit-text-fill-color: ${K};`:"",xe=z&&"inherit"!==z?`font-family:${z}_${Y.match(I)?Y.match(I)[1]:""};`:Y||"",Re=G?`font-size: ${G}px;`:"",Le="number"==typeof X?`border-width: ${X}px; border-style: solid;`:"",Ne=[Q,X].every(e=>void 0!==e)&&X?`border-color: ${Q};`:"",Be=void 0!==Z?`border-radius: ${Z}px;`:"",De=void 0!==ee?`background-color: ${ee};`:"",_e=void 0!==te?`color: ${te}; fill: ${te}; -webkit-text-fill-color: ${te};`:"",Oe=ne&&"inherit"!==ne?`font-family:${ne}_${ie.match(I)?ie.match(I)[1]:""};`:ie||"",Ve=se?`font-size: ${se}px;`:"",qe="popin"!==s||void 0!==E&&!0!==E?"":[`#${this.widgetContainerId} .${this.overlayClassName} {`,`background-color: ${void 0!==A?A:"rgba(0, 0, 0, 0.6)"};`,"}"].join(""),We="number"==typeof D?D:16,je=We/2,He=i||void 0!==N&&N?[`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} {`,"position: absolute;",("out"===B?`bottom: calc(100% + ${je}px)`:`top: ${je}px`)+";",`right: ${je}px;`,"width: auto;","height: auto;","background: none;","border: none;","cursor: pointer;","padding: 0;","margin: 0;","line-height: 0;","z-index: 9;","number"==typeof _?`border-radius: ${_}px;`:"","number"==typeof O&&O>0?`border: ${O}px solid ${void 0!==V?V:"rgba(57, 57, 57, 1)"};`:"","string"==typeof W?`background-color: ${W};`:"","}",`#${this.widgetContainerId} .${this.contentClassName} .${this.closeButtonClassName} svg {`,"pointer-events: none;",`width: ${We}px;`,`height: ${We}px;`,"string"==typeof q?`fill: ${q};`:"","}"].join(""):"",Me=b&&"string"==typeof S?[`#${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: ${S}; fill: ${S}; -webkit-text-fill-color: ${S};`,void 0!==w?`text-align: ${w};`:"",T&&"inherit"!==T?`font-family:${T}_${$.match(I)?$.match(I)[1]:""};`:$||"",C?`font-size: ${C}px;`:"","}"].join(""):"";let Fe="";if("string"==typeof re){const t=(oe/1e3).toFixed(2),n=["top","bottom"].includes(ce),i=Number(n),s=[(["top","left"].includes(ce)?"-":"")+"100vmax",this.translateValues?this.translateValues[i]:"0"];n&&s.reverse(),Fe={none:[`.${this.hideClassName} {`,"opacity: 0 !important;","}"],fade:[`.${this.hideClassName} {`,"opacity: 0 !important;","}",`#${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 Ue=[`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,`margin-${"fill"===j?"top":"left"}: 8px;`,Le,Ne,Be,De,_e,Oe,Ve,"}",`#${this.widgetContainerId} .${this.contentClassName} .buttons_container .second_link {`,_e,Oe,Ve,"}"];return le.textContent=[`.${this.hideClassName} {`,"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;",$e,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,Ie,Pe,ke,xe,Re,"}",`#${this.widgetContainerId} .${this.contentClassName} div.buttons_container a *, `,`#${this.widgetContainerId} .${this.contentClassName} button:not(class*="close_button") * {`,ke,xe,Re,"}",...J?Ue:[],"@media screen and (max-width: 579px) {",`#${this.widgetContainerId} .${this.contentClassName} {`,Se,"}",`#${this.widgetContainerId} .${this.contentClassName} > * {`,Ce,"}","}",qe,He,Me,Fe,`${t}`].join(""),le}}class x extends k{constructor(e,t){super(e,t),this.stringStyles=this.getStyles(),this.styleElement=this.getStyleTag(this.stringStyles)}getStyles(){return[`#${this.widgetContainerId} {`,"width: auto;","height: auto;","margin: 0;","padding: 0;","background: none;","}",`#${this.widgetContainerId} .${this.contentClassName} {`,"position: relative;","}"].join("")}}function R(e){return R="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},R(e)}function L(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}function N(e){var t=function(e){if("object"!=R(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=R(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==R(t)?t:t+""}var B={top:{top:0,left:50,translateX:-50,translateY:0},bottom:{top:100,left:50,translateX:-50,translateY:-100},left:{top:50,left:0,translateX:0,translateY:-50},right:{top:50,left:100,translateX:-100,translateY:-50}},D=function(){return t=function e(t){var n=t.parentContainer;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.parentContainer=n,this.className="aciontButton_container_".concat(n.uniqueId),this.domElement=this.getElement(),this.styleElement=this.getStyles()},n=[{key:"insertIn",value:function(e,t){document.head.appendChild(this.styleElement),e.insertAdjacentElement(t,this.domElement)}},{key:"remove",value:function(){var e=this,t=DATA.animationDuration;setTimeout(function(){return e.parentContainer.remove()},1.05*(void 0===t?1e3:t))}},{key:"onClick",value:function(){var t=this,n=DATA,i=n.autoHide,s=n.timeHide;i&&(this.parentContainer.hide(),setTimeout(function(){t.remove()},1e3*s)),e()||this.parentContainer.recurrence.setValidationRecurrence()}},{key:"launchScript",value:function(e){var t=this,n=DATA.customJS,i={contentElement:this.contentElement,UTILS:{hideWidget:function(){return t.parentContainer.hide()},removeWidget:function(){return t.remove()}},TEST_ID:TEST_ID,UNIQUE_ID:this.parentContainer.uniqueId,event:e},s=Object.keys(i),r=Object.values(i);return Function.apply(void 0,s.concat([n])).apply(void 0,r)}},{key:"getElement",value:function(){var t=this,n=DATA,i=n.buttonText,s=n.hasButtonIcon,r=n.buttonIcon,o=n.buttonIconAlt,a=n.linkType,c=n.redirectionUrl,l=n.openInNewTab,h=n.trackerName,d=document.createElement("div"),g=function(t,n,i,s){var r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=arguments.length>5?arguments[5]:void 0,a=arguments.length>6?arguments[6]:void 0,c="button"===n,l=document.createElement(c?"a":"button");return l.ariaLabel=t,l.innerHTML="<span>".concat(t,"</span>").concat(r?'<img src="'.concat(o,'" alt="').concat(a,'">'):""),c&&(l.href=i,l.target=s?"_blank":"_self"),e()&&(l.dataset.abtastyActionnable="true"),l}(i,a,c,l,s,r,o);return d.className="buttons_container",g.className="action_button_".concat(this.parentContainer.uniqueId),g.addEventListener("click",function(e){window.ABTastyEvent(h,null,TEST_ID),u('Tracking "'.concat(h,'" sent to campaign ').concat(TEST_ID)),"code"===a&&t.launchScript(e),t.onClick.bind(t)},{capture:!0,passive:!0}),d.appendChild(g),d}},{key:"getStyles",value:function(){var t=DATA,n=t.elementReferrer,i=t.positionType,s=t.buttonLayout,r=t.zindex,o=t.zindexCustom,a=t.hasButtonIcon,c=t.buttonsPadding,l=t.buttonsFontSize,h=t.enableButtonHoverStyles,d=t.buttonsBorderColorHover,u=t.buttonsBackgroundColorHover,g=t.buttonsTextColorHover,m=t.enableButtonHoverTransition,p=document.createElement("style");e()&&p.setAttribute("abtasty-script-added","true");var v,y="fixed"===i,f=["left","right"].includes(s),b="#".concat(this.parentContainer.widgetContainerId," .").concat(this.parentContainer.contentClassName),w=(v=c,function(e){if(Array.isArray(e))return e}(v)||function(e){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,i,s,r,o=[],a=!0,c=!1;try{for(s=(t=t.call(e)).next,!1;!(a=(n=s.call(t)).done)&&(o.push(n.value),1!==o.length);a=!0);}catch(e){c=!0,i=e}finally{try{if(!a&&null!=t.return&&(r=t.return(),Object(r)!==r))return}finally{if(c)throw i}}return o}}(v)||function(e){if(e){if("string"==typeof e)return L(e,1);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?L(e,1):void 0}}(v)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())[0],S=w.top,T=w.bottom,$=w.left,C=w.right,E=B[s],A=E.top,I=E.left,P=E.translateX,k=E.translateY,x=["#".concat(this.parentContainer.widgetContainerId," a,"),"#".concat(this.parentContainer.widgetContainerId," span {"),"all: unset;","}","".concat(b," .action_button_").concat(this.parentContainer.uniqueId," {"),"display: flex !important;","flex-direction: column;","align-items: center;","justify-content: center;","padding: ".concat(S,"px ").concat(C,"px ").concat(T,"px ").concat($,"px;"),"cursor: pointer;","pointer-events: all;","}","".concat(b," .action_button_").concat(this.parentContainer.uniqueId," span {"),"width: auto;",y&&f?["writing-mode: vertical-rl;","text-orientation: sideways;"].join(""):"",y&&"right"===s?"transform: rotate(180deg);":"","}"];if(y){var R=document.body.matches(n);R||x.push("".concat(n," {"),"position: relative;","}"),x.push("#".concat(this.parentContainer.widgetContainerId," {"),"position: ".concat(R?"fixed":"absolute",";"),"top: ".concat(A,"%;"),"left: ".concat(I,"%;"),"transform: translate(".concat(P,"%, ").concat(k,"%);"),"z-index: ".concat("custom"===r?o:r,";"),"}")}return a&&x.push(".action_button_".concat(this.parentContainer.uniqueId," img {"),f?"transform: rotate(".concat(s.includes("right")?"-":"","90deg);"):"","min-width: ".concat(2*l,"px;"),"max-height: ".concat(2*l,"px;"),"margin-".concat(f?"top":"left",": ").concat(l,"px"),"}"),h&&x.push("".concat(b," .action_button_").concat(this.parentContainer.uniqueId,":hover {"),"border-color: ".concat(d,";"),"background-color: ".concat(u,";"),"color: ".concat(g,"; fill: ").concat(g,"; -webkit-text-fill-color: ").concat(g,";"),m?"transition: all 0.5s ease;":"","}"),p.textContent=x.join(""),p}}],n&&function(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,N(i.key),i)}}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();!function(){u("Widget launch");var e=new x,t=e.domElement.querySelector(".".concat(e.contentClassName)),n=new D({parentContainer:e});e.children=n,n.insertIn(t,"beforeend"),e.init(!0).then(function(t){t.response&&e.show()})}()}();
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@abtasty/action-button",
|
3
3
|
"description": "Action Button Widget",
|
4
|
-
"version": "0.0.
|
4
|
+
"version": "0.0.16-0",
|
5
5
|
"form": "dist/form.js",
|
6
6
|
"main": "dist/main.js",
|
7
7
|
"type": "module",
|
@@ -26,18 +26,21 @@
|
|
26
26
|
"@babel/eslint-parser": "^7.23.10",
|
27
27
|
"@babel/plugin-proposal-object-rest-spread": "^7.18.6",
|
28
28
|
"@babel/preset-env": "^7.24.0",
|
29
|
+
"@rollup/plugin-alias": "5.1.0",
|
29
30
|
"@rollup/plugin-babel": "^6.0.3",
|
30
31
|
"@rollup/plugin-eslint": "^9.0.1",
|
31
32
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
32
33
|
"@rollup/plugin-terser": "^0.4.4",
|
33
34
|
"babel-plugin-minify-dead-code-elimination": "^0.5.2",
|
35
|
+
"caniuse-lite": "^1.0.30001434",
|
36
|
+
"cssnano": "^5.1.12",
|
34
37
|
"eslint": "^8.57.0",
|
35
38
|
"eslint-config-prettier": "^9.1.0",
|
36
39
|
"eslint-import-resolver-node": "^0.3.2",
|
37
40
|
"eslint-plugin-import": "^2.29.1",
|
38
|
-
"
|
39
|
-
|
40
|
-
|
41
|
-
"
|
41
|
+
"postcss": "^8.4.19",
|
42
|
+
"postcss-cssnext": "^3.1.1",
|
43
|
+
"rollup": "^4.12.0",
|
44
|
+
"rollup-plugin-postcss": "^4.0.2"
|
42
45
|
}
|
43
46
|
}
|