cookiecraft 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).CookieCraft={})}(this,function(t){"use strict";class n{save(t){try{localStorage.setItem(n.STORAGE_KEY,JSON.stringify(t))}catch(t){}}load(){try{const t=localStorage.getItem(n.STORAGE_KEY);if(!t)return null;const e=JSON.parse(t);if(!this.validateSchema(e)){const t=this.migrate(e);return t?(this.save(t),t):null}return e}catch(t){return null}}clear(){try{localStorage.removeItem(n.STORAGE_KEY)}catch(t){}}isExpired(t){const n=new Date(t.expiresAt);return!!isNaN(n.getTime())||n<new Date}validateSchema(t){return t&&"number"==typeof t.version&&"string"==typeof t.timestamp&&"object"==typeof t.categories&&"string"==typeof t.expiresAt}migrate(t){if(!t||"object"!=typeof t)return null;const e=t;if(e.categories&&"object"==typeof e.categories){const t=new Date,i=new Date(t);i.setMonth(i.getMonth()+n.EXPIRY_MONTHS);const s=e.categories,o={necessary:!0===s.necessary,analytics:!0===s.analytics,marketing:!0===s.marketing};return"preferences"in s&&(o.preferences=!0===s.preferences),{version:"number"==typeof e.version?e.version:1,timestamp:"string"==typeof e.timestamp?e.timestamp:t.toISOString(),categories:o,expiresAt:"string"==typeof e.expiresAt?e.expiresAt:i.toISOString()}}return null}}n.STORAGE_KEY="cookiecraft_consent",n.EXPIRY_MONTHS=13;class e{constructor(t){this.consent=null,this.config=t}validateConsent(t){if(!t.necessary)return!1;if(this.config.categories&&Object.keys(this.config.categories).length>0)for(const n of Object.keys(t))if(!(n in this.config.categories))return!1;for(const n of Object.keys(t))t[n]=!0===t[n];return!0}updateConsent(t){if(!this.validateConsent(t))throw Error("Invalid consent categories");return this.consent=this.createConsentRecord(t),this.consent}needsConsent(){return null===this.consent}needsUpdate(t){return t.version<this.config.revision}getCurrentConsent(){return this.consent}createConsentRecord(t){const e=new Date,i=new Date(e);return i.setMonth(i.getMonth()+n.EXPIRY_MONTHS),{version:this.config.revision,timestamp:e.toISOString(),categories:Object.assign({},t),expiresAt:i.toISOString()}}}class i{constructor(){this.events=new Map}on(t,n){this.events.has(t)||this.events.set(t,new Set),this.events.get(t).add(n)}off(t,n){this.events.has(t)&&this.events.get(t).delete(n)}emit(t,n){this.events.has(t)&&this.events.get(t).forEach(t=>{try{t(n)}catch(t){}})}clear(){this.events.clear()}clearEvent(t){this.events.delete(t)}}class s{constructor(t,n){this.observer=null,this.blockedScripts=new Map,this.currentConsent=null,this.categoryManager=t,this.eventEmitter=n}init(){this.blockExistingScripts(),this.observeDOM()}block(){this.currentConsent=null,this.blockedScripts.clear(),this.blockExistingScripts()}unblock(t){this.currentConsent=t;const n=[];this.blockedScripts.forEach((e,i)=>{const s=this.categoryManager.getCategoryForScript(e);s&&this.categoryManager.isAllowed(s,t)&&(this.reactivateScript(e),n.push(i))}),n.forEach(t=>this.blockedScripts.delete(t))}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null)}blockExistingScripts(){document.querySelectorAll("script[data-cookieconsent]").forEach(t=>{t instanceof HTMLScriptElement&&this.processScript(t)})}observeDOM(){this.observer=new MutationObserver(t=>{t.forEach(t=>{t.addedNodes.forEach(t=>{t instanceof HTMLScriptElement&&t.hasAttribute("data-cookieconsent")&&this.processScript(t)})})}),this.observer.observe(document.documentElement,{childList:!0,subtree:!0})}processScript(t){const n=this.categoryManager.getCategoryForScript(t);if(n&&!(this.currentConsent&&this.categoryManager.isAllowed(n,this.currentConsent)||"text/plain"===t.type)){const n=this.generateScriptId(t);if(this.blockedScripts.has(n))return;t.setAttribute("data-original-type",t.type||"text/javascript"),t.type="text/plain",this.blockedScripts.set(n,t)}}reactivateScript(t){const n=document.createElement("script");Array.from(t.attributes).forEach(t=>{"type"!==t.name&&"data-original-type"!==t.name&&n.setAttribute(t.name,t.value)});const e=t.getAttribute("data-original-type")||"text/javascript";n.type=e,t.src?n.src=t.src:n.textContent=t.textContent,t.parentNode&&(t.parentNode.insertBefore(n,t),t.parentNode.removeChild(t)),this.eventEmitter.emit("script:activated",{category:t.getAttribute("data-cookieconsent"),src:t.src||"inline"})}generateScriptId(t){if(t.src)return"src:"+t.src;const n=t.textContent||"",e=t.getAttribute("data-cookieconsent")||"",i=t.getAttribute("data-cc-id");if(i)return i;const s=`inline:${e}:${this.simpleHash(n)}`;return t.setAttribute("data-cc-id",s),s}simpleHash(t){let n=0;for(let e=0;e<t.length;e++)n=(n<<5)-n+t.charCodeAt(e),n|=0;return n.toString(36)}}class o{constructor(){this.categories=new Map,this.initializeDefaultPatterns()}registerCategory(t,n){this.categories.set(t,n)}getCategoryForScript(t){const n=t.getAttribute("data-cookieconsent");if(n)return n;const e=t.src;if(!e)return null;for(const[t,n]of this.categories)if(n.some(t=>e.includes(t)))return t;return null}isAllowed(t,n){return!0===n[t]}initializeDefaultPatterns(){this.categories.set("analytics",["google-analytics.com","analytics.google.com","plausible.io","matomo.org","hotjar.com","mixpanel.com","segment.com","amplitude.com"]),this.categories.set("marketing",["googletagmanager.com","facebook.net","facebook.com/tr","connect.facebook.net","doubleclick.net","ads.google.com","linkedin.com/analytics","twitter.com/i/adsct","pinterest.com/ct","adroll.com","taboola.com","outbrain.com","tiktok.com"]),this.categories.set("necessary",[])}}const c={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},a=/[&<>"'`]/g;function r(t){return t.replace(a,t=>c[t]||t)}function l(t){const n=t.trim();return n.startsWith("https://")||n.startsWith("http://")||n.startsWith("/")||n.startsWith("./")?r(n):""}function h(t){const n=t.trim();return/^#[0-9a-fA-F]{3,8}$/.test(n)||/^rgba?\(\s*[\d\s,./%]+\)$/.test(n)||/^hsla?\(\s*[\d\s,./%deg]+\)$/.test(n)||/^[a-zA-Z]+$/.test(n)&&!["inherit","initial","unset","revert","revert-layer"].includes(n.toLowerCase())?n:""}function d(t){const n=t.trim();if(/^#[0-9a-fA-F]{6}$/.test(n))return n;if(/^#[0-9a-fA-F]{3}$/.test(n)){const t=n[1],e=n[2],i=n[3];return`#${t}${t}${e}${e}${i}${i}`}return/^#[0-9a-fA-F]{8}$/.test(n)?n.substring(0,7):null}function u(t){if(!t)return"";const n=d(t);if(!n)return`--cc-primary: ${t};`;const e=function(t){const n=d(t);if(!n)return t;const e=n.replace("#",""),i=parseInt(e.substring(0,2),16),s=parseInt(e.substring(2,4),16),o=parseInt(e.substring(4,6),16),c=t=>Math.max(0,Math.min(255,Math.round(t+-15*t/100))),a=t=>{const n=t.toString(16);return 1===n.length?"0"+n:n};return`#${a(c(i))}${a(c(s))}${a(c(o))}`}(n);return`--cc-primary: ${n}; --cc-primary-hover: ${e};`}class f{constructor(t,n){this.element=null,this.hideTimeout=null,this.previousActiveElement=null,this.config=t,this.eventEmitter=n}show(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const t=()=>{this.element||(this.previousActiveElement=document.activeElement,this.element=this.createDOM(),document.body.appendChild(this.element),this.attachListeners()),requestAnimationFrame(()=>{var t;null===(t=this.element)||void 0===t||t.classList.add("is-visible")}),this.config.disablePageInteraction&&(document.body.style.overflow="hidden",this.trapFocus())};document.body?t():document.addEventListener("DOMContentLoaded",t)}hide(){var t;null===(t=this.element)||void 0===t||t.classList.remove("is-visible"),this.config.disablePageInteraction&&(document.body.style.overflow=""),this.hideTimeout=setTimeout(()=>{this.destroy()},300)}destroy(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null),this.element&&(this.element.remove(),this.element=null),this.previousActiveElement&&document.contains(this.previousActiveElement)&&(this.previousActiveElement.focus(),this.previousActiveElement=null)}createDOM(){const t=this.config.translations||{},n=this.config.theme||"light",e=this.config.position||"bottom",i=this.config.layout||"bar",s=!1!==this.config.backdropBlur,o=this.config.disablePageInteraction,c=u(this.config.primaryColor?h(this.config.primaryColor):""),a=`\n <div\n class="cc-banner cc-banner--${r(e)} cc-banner--${r(i)} ${s?"cc-backdrop-blur":""}"\n role="${o?"dialog":"region"}"\n ${o?'aria-modal="true"':""}\n aria-label="Cookie consent"\n aria-live="polite"\n data-theme="${r(n)}"\n style="${c}"\n >\n <div class="cc-banner__container">\n <div class="cc-banner__content">\n <h2 class="cc-banner__title">\n ${r(t.title||"We use cookies")}\n </h2>\n <p class="cc-banner__description">\n ${this.getDescriptionHTML()}\n </p>\n </div>\n <div class="cc-banner__actions">\n <button\n class="cc-btn cc-btn--ghost"\n data-action="reject"\n aria-label="${r(t.rejectAll||"Essentials only")}"\n >\n ${r(t.rejectAll||"Essentials only")}\n </button>\n <button\n class="cc-btn cc-btn--tertiary"\n data-action="customize"\n aria-label="${r(t.customize||"Customize")}"\n >\n ${r(t.customize||"Customize")}\n </button>\n <button\n class="cc-btn cc-btn--accept"\n data-action="accept"\n aria-label="${r(t.acceptAll||"Accept all")}"\n >\n ${r(t.acceptAll||"Accept all")}\n </button>\n </div>\n </div>\n </div>\n `,l=document.createElement("div");return l.innerHTML=a.trim(),l.firstChild}attachListeners(){var t,n;null===(t=this.element)||void 0===t||t.addEventListener("click",t=>{const n=t.target.closest("[data-action]");if(n)switch(n.getAttribute("data-action")){case"accept":this.handleAcceptAll();break;case"reject":this.handleRejectAll();break;case"customize":this.handleCustomize()}}),null===(n=this.element)||void 0===n||n.addEventListener("keydown",t=>{"Escape"===t.key&&this.config.disablePageInteraction&&this.handleRejectAll()})}handleAcceptAll(){const t={necessary:!0,analytics:!0,marketing:!0};for(const n of Object.keys(this.config.categories))t[n]=!0;this.eventEmitter.emit("consent:accept",t),this.hide()}handleRejectAll(){const t={necessary:!0,analytics:!1,marketing:!1};for(const n of Object.keys(this.config.categories))"necessary"!==n&&(t[n]=!1);this.eventEmitter.emit("consent:reject",t),this.hide()}handleCustomize(){this.eventEmitter.emit("preferences:show"),this.hide()}trapFocus(){var t,n;const e=null===(t=this.element)||void 0===t?void 0:t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(!e||0===e.length)return;const i=e[0],s=e[e.length-1];null==i||i.focus(),null===(n=this.element)||void 0===n||n.addEventListener("keydown",t=>{"Tab"===t.key&&(t.shiftKey&&document.activeElement===i?(t.preventDefault(),s.focus()):t.shiftKey||document.activeElement!==s||(t.preventDefault(),i.focus()))})}getDescriptionHTML(){const t=this.config.translations||{},n=r(t.description||"We use cookies to improve your experience on our site. You can choose which cookies you accept.");if(t.privacyPolicyUrl){const e=l(t.privacyPolicyUrl);if(e)return`${n} <a href="${e}" target="_blank" rel="noopener noreferrer">${r(t.privacyPolicyLabel||"Privacy Policy")}</a>`}return n}}class p{constructor(t,n,e){this.element=null,this.previousActiveElement=null,this.config=t,this.eventEmitter=n,this.currentConsent=e}show(){const t=()=>{this.element||(this.previousActiveElement=document.activeElement,this.element=this.createDOM(),document.body.appendChild(this.element),this.attachListeners()),this.element.classList.add("is-visible"),this.trapFocus(),document.body.style.overflow="hidden"};document.body?t():document.addEventListener("DOMContentLoaded",t)}hide(){var t;null===(t=this.element)||void 0===t||t.classList.remove("is-visible"),document.body.style.overflow="",this.previousActiveElement&&document.contains(this.previousActiveElement)&&(this.previousActiveElement.focus(),this.previousActiveElement=null),setTimeout(()=>{this.destroy()},300)}destroy(){this.element&&(this.element.remove(),this.element=null)}createDOM(){const t=this.config.translations||{},n=this.config.theme||"light",e=this.config.preferencesPosition||"center",i=u(this.config.primaryColor?h(this.config.primaryColor):""),s=t.privacyPolicyUrl?(()=>{const n=l(t.privacyPolicyUrl);return n?`\n <a href="${n}" target="_blank" rel="noopener noreferrer" class="cc-privacy-link">\n <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>\n <polyline points="15 3 21 3 21 9"/>\n <line x1="10" y1="14" x2="21" y2="3"/>\n </svg>\n ${r(t.privacyPolicyLabel||"Privacy Policy")}\n </a>\n `:""})():"",o=`\n <div\n class="cc-modal cc-modal--${r(e)}"\n role="dialog"\n aria-modal="true"\n aria-labelledby="cc-modal-title"\n data-theme="${r(n)}"\n style="${i}"\n >\n <div class="cc-modal__overlay"></div>\n <div class="cc-modal__content">\n <div class="cc-modal__header">\n <h2 id="cc-modal-title">\n ${r(t.preferencesTitle||t.title||"Cookie Preferences")}\n </h2>\n </div>\n\n <div class="cc-modal__body">\n ${this.renderCategories()}\n </div>\n\n <div class="cc-modal__footer">\n <div class="cc-modal__footer-links">\n ${s}\n </div>\n <div class="cc-modal__footer-actions">\n <button\n class="cc-btn cc-btn--secondary"\n data-action="reject"\n >\n ${r(t.essentialsOnly||"Essentials only")}\n </button>\n <button\n class="cc-btn cc-btn--primary"\n data-action="save"\n >\n ${r(t.savePreferences||"Save preferences")}\n </button>\n </div>\n </div>\n </div>\n </div>\n `,c=document.createElement("div");return c.innerHTML=o.trim(),c.firstChild}renderCategories(){return Object.entries(this.config.categories).map(([t,n])=>{const e=!0===this.currentConsent[t],i=n.readOnly;return`\n <div class="cc-category">\n <div class="cc-category__header">\n <label class="cc-toggle ${i?"cc-toggle--disabled":""}">\n <input\n type="checkbox"\n data-category="${r(t)}"\n ${e?"checked":""}\n ${i?"disabled":""}\n aria-label="${r(n.label)} cookies"\n >\n <span class="cc-toggle__slider"></span>\n </label>\n <div class="cc-category__info">\n <h3>${r(n.label)}</h3>\n <p>${r(n.description)}</p>\n </div>\n </div>\n </div>\n `}).join("")}attachListeners(){var t;null===(t=this.element)||void 0===t||t.addEventListener("click",t=>{const n=t.target.closest("[data-action]");if(!n)return;const e=n.getAttribute("data-action");"save"===e?this.handleSave():"reject"===e&&this.handleRejectAll()})}handleSave(){var t;const n=null===(t=this.element)||void 0===t?void 0:t.querySelectorAll("input[data-category]"),e={necessary:!0,analytics:!1,marketing:!1};for(const t of Object.keys(this.config.categories))"necessary"!==t&&(e[t]=!1);null==n||n.forEach(t=>{if(t instanceof HTMLInputElement){const n=t.getAttribute("data-category");n&&(e[n]=t.checked)}}),this.eventEmitter.emit("consent:update",e),this.hide()}handleRejectAll(){const t={necessary:!0,analytics:!1,marketing:!1};for(const n of Object.keys(this.config.categories))"necessary"!==n&&(t[n]=!1);this.eventEmitter.emit("consent:reject",t),this.hide()}trapFocus(){var t,n;const e=null===(t=this.element)||void 0===t?void 0:t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(!e||0===e.length)return;const i=e[0],s=e[e.length-1];null==i||i.focus(),null===(n=this.element)||void 0===n||n.addEventListener("keydown",t=>{"Tab"===t.key&&(t.shiftKey&&document.activeElement===i?(t.preventDefault(),s.focus()):t.shiftKey||document.activeElement!==s||(t.preventDefault(),i.focus()))})}}class m{constructor(t,n){this.element=null,this.isVisible=!1,this.config=t,this.eventEmitter=n}show(){const t=()=>{this.element||(this.element=this.createDOM(),document.body.appendChild(this.element),this.attachListeners()),requestAnimationFrame(()=>{var t;null===(t=this.element)||void 0===t||t.classList.add("is-visible"),this.isVisible=!0})};document.body?t():document.addEventListener("DOMContentLoaded",t)}hide(){var t;null===(t=this.element)||void 0===t||t.classList.remove("is-visible"),this.isVisible=!1}destroy(){this.element&&(this.element.remove(),this.element=null),this.isVisible=!1}getIsVisible(){return this.isVisible}createDOM(){const t=this.config.translations||{},n=this.config.theme||"light",e=this.config.widgetPosition||"bottom-right",i=this.config.widgetStyle||"full",s=u(this.config.primaryColor?h(this.config.primaryColor):""),o=`\n <div\n class="cc-widget cc-widget--${r(e)} cc-widget--${r(i)}"\n role="button"\n aria-label="${r(t.cookieSettings||"Cookie settings")}"\n tabindex="0"\n data-theme="${r(n)}"\n style="${s}"\n >\n <svg class="cc-widget__icon" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">\n <defs>\n <path id="cc-ck-a" d="M6,9 C5.448,9 5,8.552 5,8 C5,7.448 5.448,7 6,7 C6.552,7 7,7.448 7,8 C7,8.552 6.552,9 6,9 Z M0.5,5 C0.776,5 1,5.224 1,5.5 C1,5.776 0.776,6 0.5,6 C0.224,6 0,5.776 0,5.5 C0,5.224 0.224,5 0.5,5 Z M1.5,0 C1.776,0 2,0.224 2,0.5 C2,0.776 1.776,1 1.5,1 C1.224,1 1,0.776 1,0.5 C1,0.224 1.224,0 1.5,0 Z"/>\n <path id="cc-ck-c" d="M16.899,14.984 C14.727,14.802 12.991,13.088 12.773,10.927 C10.117,10.808 8,8.617 8,5.932 C8,4.837 8.352,3.824 8.949,3 C5.027,3.515 2,6.87 2,10.932 C2,15.35 5.582,18.932 10,18.932 C12.939,18.932 15.509,17.346 16.899,14.984 Z M18.623,15.998 C16.839,19.029 13.583,20.932 10,20.932 C4.477,20.932 0,16.454 0,10.932 C0,5.897 3.74,1.666 8.689,1.017 C10.429,0.789 11.599,2.753 10.568,4.174 C10.2,4.682 10,5.289 10,5.932 C10,7.537 11.265,8.857 12.862,8.929 C13.854,8.973 14.663,9.738 14.763,10.726 C14.884,11.932 15.857,12.889 17.067,12.991 C18.535,13.114 19.37,14.729 18.623,15.998 Z M10,18 C8.343,18 7,16.657 7,15 C7,13.343 8.343,12 10,12 C11.657,12 13,13.343 13,15 C13,16.657 11.657,18 10,18 Z M10,16 C10.552,16 11,15.552 11,15 C11,14.448 10.552,14 10,14 C9.448,14 9,14.448 9,15 C9,15.552 9.448,16 10,16 Z M4.5,14 C3.672,14 3,13.328 3,12.5 C3,11.672 3.672,11 4.5,11 C5.328,11 6,11.672 6,12.5 C6,13.328 5.328,14 4.5,14 Z M4.5,12 C4.224,12 4,12.224 4,12.5 C4,12.776 4.224,13 4.5,13 C4.776,13 5,12.776 5,12.5 C5,12.224 4.776,12 4.5,12 Z M5.5,9 C4.672,9 4,8.328 4,7.5 C4,6.672 4.672,6 5.5,6 C6.328,6 7,6.672 7,7.5 C7,8.328 6.328,9 5.5,9 Z M5.5,7 C5.224,7 5,7.224 5,7.5 C5,7.776 5.224,8 5.5,8 C5.776,8 6,7.776 6,7.5 C6,7.224 5.776,7 5.5,7 Z"/>\n </defs>\n <g fill="currentColor" fill-rule="evenodd" transform="translate(3 1)">\n <g transform="translate(4 7)">\n <use href="#cc-ck-a"/>\n </g>\n <use href="#cc-ck-c"/>\n </g>\n </svg>\n <span class="cc-widget__text">\n ${r(t.cookies||"Cookies")}\n </span>\n </div>\n `,c=document.createElement("div");return c.innerHTML=o.trim(),c.firstChild}attachListeners(){var t,n;null===(t=this.element)||void 0===t||t.addEventListener("click",()=>{this.handleClick()}),null===(n=this.element)||void 0===n||n.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),this.handleClick())})}handleClick(){this.eventEmitter.emit("preferences:show")}}class v{constructor(t,n){this.dataLayerManager=t,this.config=n}setDefaultConsent(){var t;const n={ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied",functionality_storage:"denied",personalization_storage:"denied",security_storage:"granted"},e=null!==(t=this.config.gtmWaitForUpdate)&&void 0!==t?t:500;e>0&&(n.wait_for_update=e),this.dataLayerManager.pushConsent("default",n),this.config.gtmUrlPassthrough&&this.dataLayerManager.pushSet("url_passthrough",!0),this.config.gtmAdsDataRedaction&&this.dataLayerManager.pushSet("ads_data_redaction",!0)}updateConsent(t){const n=this.mapCategoriesToGTM(t);this.dataLayerManager.pushConsent("update",n)}mapCategoriesToGTM(t){const n=!("preferences"in this.config.categories)||!0===t.preferences;return{ad_storage:t.marketing?"granted":"denied",ad_user_data:t.marketing?"granted":"denied",ad_personalization:t.marketing?"granted":"denied",analytics_storage:t.analytics?"granted":"denied",functionality_storage:n?"granted":"denied",personalization_storage:n?"granted":"denied",security_storage:"granted"}}}class g{ensureGtag(){window.dataLayer=window.dataLayer||[],"function"!=typeof window.gtag&&(window.gtag=function(){window.dataLayer.push(arguments)})}pushConsent(t,n){this.ensureGtag(),window.gtag("consent",t,n)}pushSet(t,n){this.ensureGtag(),window.gtag("set",t,n)}}const b={analytics:[/^_ga/,/^_gid/,/^_gat/,/^_gcl/,/^_hj/,/^_pk_/,/^mp_/,/^ajs_/,/^amplitude/,/^plausible/],marketing:[/^_fbp/,/^_fbc/,/^fr$/,/^_pin_/,/^_tt_/,/^li_/,/^_uet/,/^IDE$/,/^test_cookie/,/^MUID$/,/^NID$/],preferences:[/^lang$/,/^locale$/,/^i18n/]};function y(t){const n=window.location.hostname,e=["/",window.location.pathname],i=["",n],s=n.split(".");s.length>2&&i.push("."+s.slice(-2).join(".")),i.push("."+n);for(const n of i)for(const i of e){const e=n?"; domain="+n:"";document.cookie=`${t}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${i}${e}`,document.cookie=`${t}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${i}${e}; secure`,document.cookie=`${t}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${i}${e}; samesite=lax`,document.cookie=`${t}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${i}${e}; samesite=none; secure`}}function w(t){const n=b[t];if(!n)return;const e=document.cookie.split(";").map(t=>t.trim().split("=")[0]).filter(Boolean);for(const t of e)n.some(n=>n.test(t))&&y(t)}function C(t){for(const[n,e]of Object.entries(t))e||"necessary"===n||w(n)}t.CookieConsent=class{constructor(t){if(this.banner=null,this.preferenceCenter=null,this.floatingWidget=null,this.gtmIntegration=null,this.hideTimeout=null,"undefined"==typeof window)return this.config=t,this.consentManager=null,this.storageManager=null,this.eventEmitter=null,void(this.scriptBlocker=null);this.config=this.validateConfig(t),this.consentManager=new e(this.config),this.storageManager=new n,this.eventEmitter=new i,this.scriptBlocker=new s(new o,this.eventEmitter),this.config.gtmConsentMode&&(this.gtmIntegration=new v(new g,this.config)),this.eventEmitter.on("consent:accept",t=>{var n,e;this.updateConsent(t),null===(e=(n=this.config).onAccept)||void 0===e||e.call(n,t)}),this.eventEmitter.on("consent:reject",t=>{var n,e;this.updateConsent(t),null===(e=(n=this.config).onReject)||void 0===e||e.call(n)}),this.eventEmitter.on("consent:update",t=>{var n,e;this.updateConsent(t),null===(e=(n=this.config).onChange)||void 0===e||e.call(n,t)}),this.eventEmitter.on("preferences:show",()=>{this.showPreferences()})}init(){if("undefined"==typeof window)return;this.scriptBlocker.init(),this.gtmIntegration&&this.gtmIntegration.setDefaultConsent();const t=this.storageManager.load();t&&!this.storageManager.isExpired(t)?this.consentManager.needsUpdate(t)?this.config.autoShow&&this.showBanner():(this.applyConsent(t.categories),this.gtmIntegration&&this.gtmIntegration.updateConsent(t.categories),this.eventEmitter.emit("consent:load",t),this.config.showWidget&&this.showFloatingWidget()):this.config.autoShow&&this.showBanner(),window.cookieConsent=this,this.eventEmitter.emit("consent:init")}show(){this.showBanner()}hide(){var t;null===(t=this.banner)||void 0===t||t.hide()}showPreferences(){var t;const n=(null===(t=this.storageManager.load())||void 0===t?void 0:t.categories)||{necessary:!0,analytics:!0,marketing:!0};for(const t of Object.keys(this.config.categories))t in n||(n[t]="necessary"===t);this.preferenceCenter&&this.preferenceCenter.destroy(),this.preferenceCenter=new p(this.config,this.eventEmitter,n),this.preferenceCenter.show()}updateConsent(t){const n=this.consentManager.updateConsent(t);this.storageManager.save(n),this.applyConsent(t),this.gtmIntegration&&this.gtmIntegration.updateConsent(t),this.config.showWidget&&setTimeout(()=>{this.showFloatingWidget()},400)}getConsent(){return this.storageManager.load()}reset(){var t,n;this.storageManager.clear(),this.scriptBlocker.block();const e={necessary:!0,analytics:!1,marketing:!1};for(const t of Object.keys(this.config.categories))"necessary"!==t&&(e[t]=!1);C(e),this.gtmIntegration&&this.gtmIntegration.updateConsent(e),null===(n=(t=this.config).onReject)||void 0===n||n.call(t),this.showBanner()}on(t,n){this.eventEmitter.on(t,n)}off(t,n){this.eventEmitter.off(t,n)}destroy(){var t,n,e,i;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null),null===(t=this.banner)||void 0===t||t.destroy(),this.banner=null,null===(n=this.preferenceCenter)||void 0===n||n.destroy(),this.preferenceCenter=null,null===(e=this.floatingWidget)||void 0===e||e.destroy(),this.floatingWidget=null,null===(i=this.scriptBlocker)||void 0===i||i.destroy(),this.eventEmitter.clear(),window.cookieConsent===this&&(window.cookieConsent=void 0)}showBanner(){this.banner||(this.banner=new f(this.config,this.eventEmitter)),this.banner.show(),this.eventEmitter.emit("consent:show")}showFloatingWidget(){this.floatingWidget||(this.floatingWidget=new m(this.config,this.eventEmitter)),this.floatingWidget.show()}applyConsent(t){this.scriptBlocker.unblock(t),C(t)}validateConfig(t){return Object.assign(Object.assign({},t),{categories:t.categories||{necessary:{enabled:!0,readOnly:!0,label:"Essential",description:"Required for the website to function properly."},analytics:{enabled:!0,readOnly:!1,label:"Analytics",description:"Help us understand how you use our site."},marketing:{enabled:!0,readOnly:!1,label:"Marketing",description:"Used to deliver relevant advertisements."}},mode:t.mode||"opt-in",autoShow:void 0===t.autoShow||t.autoShow,revision:t.revision||1,gtmConsentMode:t.gtmConsentMode||!1,disablePageInteraction:t.disablePageInteraction||!1,theme:t.theme||"light",position:t.position||"bottom-left",layout:t.layout||"box",backdropBlur:!1!==t.backdropBlur,animationStyle:t.animationStyle||"smooth",preferencesPosition:t.preferencesPosition||"center",showWidget:void 0===t.showWidget||t.showWidget,widgetPosition:t.widgetPosition||"bottom-left",widgetStyle:t.widgetStyle||"compact"})}}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CookieCraft={})}(this,function(e){"use strict";class t{save(e){try{localStorage.setItem(t.STORAGE_KEY,JSON.stringify(e))}catch(e){}}load(){try{const e=localStorage.getItem(t.STORAGE_KEY);if(!e)return null;const i=JSON.parse(e);if(!this.validateSchema(i)){const e=this.migrate(i);return e?(this.save(e),e):null}return i}catch(e){return null}}clear(){try{localStorage.removeItem(t.STORAGE_KEY)}catch(e){}}isExpired(e){const t=new Date(e.expiresAt);return!!isNaN(t.getTime())||t<new Date}validateSchema(e){return e&&"number"==typeof e.version&&"string"==typeof e.timestamp&&"object"==typeof e.categories&&"string"==typeof e.expiresAt}migrate(e){if(!e||"object"!=typeof e)return null;const i=e;if(i.categories&&"object"==typeof i.categories){const e=new Date,s=new Date(e);s.setMonth(s.getMonth()+t.EXPIRY_MONTHS);const n=i.categories,o={necessary:!0===n.necessary,analytics:!0===n.analytics,marketing:!0===n.marketing};return"preferences"in n&&(o.preferences=!0===n.preferences),{version:"number"==typeof i.version?i.version:1,timestamp:"string"==typeof i.timestamp?i.timestamp:e.toISOString(),categories:o,expiresAt:"string"==typeof i.expiresAt?i.expiresAt:s.toISOString()}}return null}}t.STORAGE_KEY="cookiecraft_consent",t.EXPIRY_MONTHS=13;class i{constructor(e){this.consent=null,this.config=e}validateConsent(e){if(!e.necessary)return!1;if(this.config.categories&&Object.keys(this.config.categories).length>0)for(const t of Object.keys(e))if(!(t in this.config.categories))return!1;for(const t of Object.keys(e))e[t]=!0===e[t];return!0}updateConsent(e){if(!this.validateConsent(e))throw Error("Invalid consent categories");return this.consent=this.createConsentRecord(e),this.consent}needsConsent(){return null===this.consent}needsUpdate(e){return e.version<this.config.revision}getCurrentConsent(){return this.consent}createConsentRecord(e){const i=new Date,s=new Date(i);return s.setMonth(s.getMonth()+t.EXPIRY_MONTHS),{version:this.config.revision,timestamp:i.toISOString(),categories:Object.assign({},e),expiresAt:s.toISOString()}}}class s{constructor(){this.events=new Map}on(e,t){this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t)}off(e,t){this.events.has(e)&&this.events.get(e).delete(t)}emit(e,t){this.events.has(e)&&this.events.get(e).forEach(e=>{try{e(t)}catch(e){}})}clear(){this.events.clear()}clearEvent(e){this.events.delete(e)}}class n{constructor(e,t){this.observer=null,this.blockedScripts=new Map,this.currentConsent=null,this.categoryManager=e,this.eventEmitter=t}init(){this.blockExistingScripts(),this.observeDOM()}block(){this.currentConsent=null,this.blockedScripts.clear(),this.blockExistingScripts()}unblock(e){this.currentConsent=e;const t=[];this.blockedScripts.forEach((i,s)=>{const n=this.categoryManager.getCategoryForScript(i);n&&this.categoryManager.isAllowed(n,e)&&(this.reactivateScript(i),t.push(s))}),t.forEach(e=>this.blockedScripts.delete(e))}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null)}blockExistingScripts(){document.querySelectorAll("script[data-cookieconsent]").forEach(e=>{e instanceof HTMLScriptElement&&this.processScript(e)})}observeDOM(){this.observer=new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e instanceof HTMLScriptElement&&e.hasAttribute("data-cookieconsent")&&this.processScript(e)})})}),this.observer.observe(document.documentElement,{childList:!0,subtree:!0})}processScript(e){const t=this.categoryManager.getCategoryForScript(e);if(t&&!(this.currentConsent&&this.categoryManager.isAllowed(t,this.currentConsent)||"text/plain"===e.type)){const t=this.generateScriptId(e);if(this.blockedScripts.has(t))return;e.setAttribute("data-original-type",e.type||"text/javascript"),e.type="text/plain",this.blockedScripts.set(t,e)}}reactivateScript(e){const t=document.createElement("script");Array.from(e.attributes).forEach(e=>{"type"!==e.name&&"data-original-type"!==e.name&&t.setAttribute(e.name,e.value)});const i=e.getAttribute("data-original-type")||"text/javascript";t.type=i,e.src?t.src=e.src:t.textContent=e.textContent,e.parentNode&&(e.parentNode.insertBefore(t,e),e.parentNode.removeChild(e)),this.eventEmitter.emit("script:activated",{category:e.getAttribute("data-cookieconsent"),src:e.src||"inline"})}generateScriptId(e){if(e.src)return"src:"+e.src;const t=e.textContent||"",i=e.getAttribute("data-cookieconsent")||"",s=e.getAttribute("data-cc-id");if(s)return s;const n=`inline:${i}:${this.simpleHash(t)}`;return e.setAttribute("data-cc-id",n),n}simpleHash(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i),t|=0;return t.toString(36)}}class o{constructor(){this.categories=new Map,this.initializeDefaultPatterns()}registerCategory(e,t){this.categories.set(e,t)}getCategoryForScript(e){const t=e.getAttribute("data-cookieconsent");if(t)return t;const i=e.src;if(!i)return null;for(const[e,t]of this.categories)if(t.some(e=>i.includes(e)))return e;return null}isAllowed(e,t){return!0===t[e]}initializeDefaultPatterns(){this.categories.set("analytics",["google-analytics.com","analytics.google.com","plausible.io","matomo.org","hotjar.com","mixpanel.com","segment.com","amplitude.com"]),this.categories.set("marketing",["googletagmanager.com","facebook.net","facebook.com/tr","connect.facebook.net","doubleclick.net","ads.google.com","linkedin.com/analytics","twitter.com/i/adsct","pinterest.com/ct","adroll.com","taboola.com","outbrain.com","tiktok.com"]),this.categories.set("necessary",[])}}const c={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},a=/[&<>"'`]/g;function r(e){return e.replace(a,e=>c[e]||e)}function l(e){const t=e.trim();return t.startsWith("https://")||t.startsWith("http://")||t.startsWith("/")||t.startsWith("./")?r(t):""}function h(e){const t=e.trim();return/^#[0-9a-fA-F]{3,8}$/.test(t)||/^rgba?\(\s*[\d\s,./%]+\)$/.test(t)||/^hsla?\(\s*[\d\s,./%deg]+\)$/.test(t)||/^[a-zA-Z]+$/.test(t)&&!["inherit","initial","unset","revert","revert-layer"].includes(t.toLowerCase())?t:""}function d(e){const t=e.trim();if(/^#[0-9a-fA-F]{6}$/.test(t))return t;if(/^#[0-9a-fA-F]{3}$/.test(t)){const e=t[1],i=t[2],s=t[3];return`#${e}${e}${i}${i}${s}${s}`}return/^#[0-9a-fA-F]{8}$/.test(t)?t.substring(0,7):null}function u(e){if(!e)return"";const t=d(e);if(!t)return`--cc-primary: ${e};`;const i=function(e){const t=d(e);if(!t)return e;const i=t.replace("#",""),s=parseInt(i.substring(0,2),16),n=parseInt(i.substring(2,4),16),o=parseInt(i.substring(4,6),16),c=e=>Math.max(0,Math.min(255,Math.round(e+-15*e/100))),a=e=>{const t=e.toString(16);return 1===t.length?"0"+t:t};return`#${a(c(s))}${a(c(n))}${a(c(o))}`}(t);return`--cc-primary: ${t}; --cc-primary-hover: ${i};`}class p{constructor(e,t){this.element=null,this.hideTimeout=null,this.previousActiveElement=null,this.config=e,this.eventEmitter=t}show(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const e=()=>{this.element||(this.previousActiveElement=document.activeElement,this.element=this.createDOM(),document.body.appendChild(this.element),this.attachListeners()),requestAnimationFrame(()=>{var e;null===(e=this.element)||void 0===e||e.classList.add("is-visible")}),this.config.disablePageInteraction&&(document.body.style.overflow="hidden",this.trapFocus())};document.body?e():document.addEventListener("DOMContentLoaded",e)}hide(){var e;null===(e=this.element)||void 0===e||e.classList.remove("is-visible"),this.config.disablePageInteraction&&(document.body.style.overflow=""),this.hideTimeout=setTimeout(()=>{this.destroy()},300)}destroy(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null),this.element&&(this.element.remove(),this.element=null),this.previousActiveElement&&document.contains(this.previousActiveElement)&&(this.previousActiveElement.focus(),this.previousActiveElement=null)}createDOM(){const e=this.config.translations||{},t=this.config.theme||"light",i=this.config.position||"bottom",s=this.config.layout||"bar",n=!1!==this.config.backdropBlur,o=this.config.disablePageInteraction,c=u(this.config.primaryColor?h(this.config.primaryColor):""),a=e.title?`<h2 class="cc-banner__title">${r(e.title)}</h2>`:"",l=this.getDescriptionHTML(),d=l?`<p class="cc-banner__description">${l}</p>`:"",p=`\n <div\n class="cc-banner cc-banner--${r(i)} cc-banner--${r(s)} ${n?"cc-backdrop-blur":""}"\n role="${o?"dialog":"region"}"\n ${o?'aria-modal="true"':""}\n aria-label="Cookie consent"\n aria-live="polite"\n data-theme="${r(t)}"\n style="${c}"\n >\n <div class="cc-banner__container">\n <div class="cc-banner__content">\n ${a}\n ${d}\n </div>\n <div class="cc-banner__actions">\n <button\n class="cc-btn cc-btn--accept"\n data-action="accept"\n aria-label="${r(e.acceptAll||"Accept all")}"\n >\n ${r(e.acceptAll||"Accept all")}\n </button>\n </div>\n </div>\n </div>\n `,f=document.createElement("div");return f.innerHTML=p.trim(),f.firstChild}attachListeners(){var e,t;null===(e=this.element)||void 0===e||e.addEventListener("click",e=>{const t=e.target.closest("[data-action]");if(t)switch(t.getAttribute("data-action")){case"accept":this.handleAcceptAll();break;case"reject":this.handleRejectAll();break;case"customize":this.handleCustomize()}}),null===(t=this.element)||void 0===t||t.addEventListener("keydown",e=>{"Escape"===e.key&&this.config.disablePageInteraction&&this.handleRejectAll()})}handleAcceptAll(){const e={necessary:!0,analytics:!0,marketing:!0};for(const t of Object.keys(this.config.categories))e[t]=!0;this.eventEmitter.emit("consent:accept",e),this.hide()}handleRejectAll(){const e={necessary:!0,analytics:!1,marketing:!1};for(const t of Object.keys(this.config.categories))"necessary"!==t&&(e[t]=!1);this.eventEmitter.emit("consent:reject",e),this.hide()}handleCustomize(){this.eventEmitter.emit("preferences:show"),this.hide()}trapFocus(){var e,t;const i=null===(e=this.element)||void 0===e?void 0:e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(!i||0===i.length)return;const s=i[0],n=i[i.length-1];null==s||s.focus(),null===(t=this.element)||void 0===t||t.addEventListener("keydown",e=>{"Tab"===e.key&&(e.shiftKey&&document.activeElement===s?(e.preventDefault(),n.focus()):e.shiftKey||document.activeElement!==n||(e.preventDefault(),s.focus()))})}getDescriptionHTML(){const e=this.config.translations||{};if(!e.description)return"";const t=r(e.description),i=r(e.customize||"Customize");let s=t;if(e.privacyPolicyUrl){const t=l(e.privacyPolicyUrl);t&&(s+=` <a href="${t}" target="_blank" rel="noopener noreferrer">${r(e.privacyPolicyLabel||"Privacy Policy")}</a>`)}return s+=` <span class="cc-banner__customize" data-action="customize">${i}</span>`,s}}class f{constructor(e,t,i){this.element=null,this.previousActiveElement=null,this.config=e,this.eventEmitter=t,this.currentConsent=i}show(){const e=()=>{this.element||(this.previousActiveElement=document.activeElement,this.element=this.createDOM(),document.body.appendChild(this.element),this.attachListeners()),this.element.classList.add("is-visible"),this.trapFocus(),document.body.style.overflow="hidden"};document.body?e():document.addEventListener("DOMContentLoaded",e)}hide(){var e;null===(e=this.element)||void 0===e||e.classList.remove("is-visible"),document.body.style.overflow="",this.previousActiveElement&&document.contains(this.previousActiveElement)&&(this.previousActiveElement.focus(),this.previousActiveElement=null),setTimeout(()=>{this.destroy()},300)}destroy(){this.element&&(this.element.remove(),this.element=null)}createDOM(){const e=this.config.translations||{},t=this.config.theme||"light",i=this.config.preferencesPosition||"center",s=u(this.config.primaryColor?h(this.config.primaryColor):""),n=e.privacyPolicyUrl?(()=>{const t=l(e.privacyPolicyUrl);return t?`\n <a href="${t}" target="_blank" rel="noopener noreferrer" class="cc-privacy-link">\n <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>\n <polyline points="15 3 21 3 21 9"/>\n <line x1="10" y1="14" x2="21" y2="3"/>\n </svg>\n ${r(e.privacyPolicyLabel||"Privacy Policy")}\n </a>\n `:""})():"",o=`\n <div\n class="cc-modal cc-modal--${r(i)}"\n role="dialog"\n aria-modal="true"\n aria-labelledby="cc-modal-title"\n data-theme="${r(t)}"\n style="${s}"\n >\n <div class="cc-modal__overlay"></div>\n <div class="cc-modal__content">\n <div class="cc-modal__header">\n <h2 id="cc-modal-title">\n ${r(e.preferencesTitle||e.title||"Cookie Preferences")}\n </h2>\n </div>\n\n <div class="cc-modal__body">\n ${this.renderCategories()}\n </div>\n\n <div class="cc-modal__footer">\n <div class="cc-modal__footer-links">\n ${n}\n </div>\n <div class="cc-modal__footer-actions">\n <button\n class="cc-btn cc-btn--secondary"\n data-action="reject"\n >\n ${r(e.essentialsOnly||"Essentials only")}\n </button>\n <button\n class="cc-btn cc-btn--primary"\n data-action="save"\n >\n ${r(e.savePreferences||"Save preferences")}\n </button>\n </div>\n </div>\n </div>\n </div>\n `,c=document.createElement("div");return c.innerHTML=o.trim(),c.firstChild}renderCategories(){return Object.entries(this.config.categories).map(([e,t])=>{const i=!0===this.currentConsent[e],s=t.readOnly;return`\n <div class="cc-category">\n <div class="cc-category__header">\n <label class="cc-toggle ${s?"cc-toggle--disabled":""}">\n <input\n type="checkbox"\n data-category="${r(e)}"\n ${i?"checked":""}\n ${s?"disabled":""}\n aria-label="${r(t.label)} cookies"\n >\n <span class="cc-toggle__slider"></span>\n </label>\n <div class="cc-category__info">\n <h3>${r(t.label)}</h3>\n <p>${r(t.description)}</p>\n </div>\n </div>\n </div>\n `}).join("")}attachListeners(){var e;null===(e=this.element)||void 0===e||e.addEventListener("click",e=>{const t=e.target.closest("[data-action]");if(!t)return;const i=t.getAttribute("data-action");"save"===i?this.handleSave():"reject"===i&&this.handleRejectAll()})}handleSave(){var e;const t=null===(e=this.element)||void 0===e?void 0:e.querySelectorAll("input[data-category]"),i={necessary:!0,analytics:!1,marketing:!1};for(const e of Object.keys(this.config.categories))"necessary"!==e&&(i[e]=!1);null==t||t.forEach(e=>{if(e instanceof HTMLInputElement){const t=e.getAttribute("data-category");t&&(i[t]=e.checked)}}),this.eventEmitter.emit("consent:update",i),this.hide()}handleRejectAll(){const e={necessary:!0,analytics:!1,marketing:!1};for(const t of Object.keys(this.config.categories))"necessary"!==t&&(e[t]=!1);this.eventEmitter.emit("consent:reject",e),this.hide()}trapFocus(){var e,t;const i=null===(e=this.element)||void 0===e?void 0:e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(!i||0===i.length)return;const s=i[0],n=i[i.length-1];null==s||s.focus(),null===(t=this.element)||void 0===t||t.addEventListener("keydown",e=>{"Tab"===e.key&&(e.shiftKey&&document.activeElement===s?(e.preventDefault(),n.focus()):e.shiftKey||document.activeElement!==n||(e.preventDefault(),s.focus()))})}}class v{constructor(e,t){this.element=null,this.isVisible=!1,this.config=e,this.eventEmitter=t}show(){const e=()=>{this.element||(this.element=this.createDOM(),document.body.appendChild(this.element),this.attachListeners()),requestAnimationFrame(()=>{var e;null===(e=this.element)||void 0===e||e.classList.add("is-visible"),this.isVisible=!0})};document.body?e():document.addEventListener("DOMContentLoaded",e)}hide(){var e;null===(e=this.element)||void 0===e||e.classList.remove("is-visible"),this.isVisible=!1}destroy(){this.element&&(this.element.remove(),this.element=null),this.isVisible=!1}getIsVisible(){return this.isVisible}createDOM(){const e=this.config.translations||{},t=this.config.theme||"light",i=this.config.widgetPosition||"bottom-right",s=this.config.widgetStyle||"full",n=u(this.config.primaryColor?h(this.config.primaryColor):""),o=`\n <div\n class="cc-widget cc-widget--${r(i)} cc-widget--${r(s)}"\n role="button"\n aria-label="${r(e.cookieSettings||"Cookie settings")}"\n tabindex="0"\n data-theme="${r(t)}"\n style="${n}"\n >\n <svg class="cc-widget__icon" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">\n <defs>\n <path id="cc-ck-a" d="M6,9 C5.448,9 5,8.552 5,8 C5,7.448 5.448,7 6,7 C6.552,7 7,7.448 7,8 C7,8.552 6.552,9 6,9 Z M0.5,5 C0.776,5 1,5.224 1,5.5 C1,5.776 0.776,6 0.5,6 C0.224,6 0,5.776 0,5.5 C0,5.224 0.224,5 0.5,5 Z M1.5,0 C1.776,0 2,0.224 2,0.5 C2,0.776 1.776,1 1.5,1 C1.224,1 1,0.776 1,0.5 C1,0.224 1.224,0 1.5,0 Z"/>\n <path id="cc-ck-c" d="M16.899,14.984 C14.727,14.802 12.991,13.088 12.773,10.927 C10.117,10.808 8,8.617 8,5.932 C8,4.837 8.352,3.824 8.949,3 C5.027,3.515 2,6.87 2,10.932 C2,15.35 5.582,18.932 10,18.932 C12.939,18.932 15.509,17.346 16.899,14.984 Z M18.623,15.998 C16.839,19.029 13.583,20.932 10,20.932 C4.477,20.932 0,16.454 0,10.932 C0,5.897 3.74,1.666 8.689,1.017 C10.429,0.789 11.599,2.753 10.568,4.174 C10.2,4.682 10,5.289 10,5.932 C10,7.537 11.265,8.857 12.862,8.929 C13.854,8.973 14.663,9.738 14.763,10.726 C14.884,11.932 15.857,12.889 17.067,12.991 C18.535,13.114 19.37,14.729 18.623,15.998 Z M10,18 C8.343,18 7,16.657 7,15 C7,13.343 8.343,12 10,12 C11.657,12 13,13.343 13,15 C13,16.657 11.657,18 10,18 Z M10,16 C10.552,16 11,15.552 11,15 C11,14.448 10.552,14 10,14 C9.448,14 9,14.448 9,15 C9,15.552 9.448,16 10,16 Z M4.5,14 C3.672,14 3,13.328 3,12.5 C3,11.672 3.672,11 4.5,11 C5.328,11 6,11.672 6,12.5 C6,13.328 5.328,14 4.5,14 Z M4.5,12 C4.224,12 4,12.224 4,12.5 C4,12.776 4.224,13 4.5,13 C4.776,13 5,12.776 5,12.5 C5,12.224 4.776,12 4.5,12 Z M5.5,9 C4.672,9 4,8.328 4,7.5 C4,6.672 4.672,6 5.5,6 C6.328,6 7,6.672 7,7.5 C7,8.328 6.328,9 5.5,9 Z M5.5,7 C5.224,7 5,7.224 5,7.5 C5,7.776 5.224,8 5.5,8 C5.776,8 6,7.776 6,7.5 C6,7.224 5.776,7 5.5,7 Z"/>\n </defs>\n <g fill="currentColor" fill-rule="evenodd" transform="translate(3 1)">\n <g transform="translate(4 7)">\n <use href="#cc-ck-a"/>\n </g>\n <use href="#cc-ck-c"/>\n </g>\n </svg>\n <span class="cc-widget__text">\n ${r(e.cookies||"Cookies")}\n </span>\n </div>\n `,c=document.createElement("div");return c.innerHTML=o.trim(),c.firstChild}attachListeners(){var e,t;null===(e=this.element)||void 0===e||e.addEventListener("click",()=>{this.handleClick()}),null===(t=this.element)||void 0===t||t.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),this.handleClick())})}handleClick(){this.eventEmitter.emit("preferences:show")}}class m{constructor(e,t){this.dataLayerManager=e,this.config=t}setDefaultConsent(){var e;const t={ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied",functionality_storage:"denied",personalization_storage:"denied",security_storage:"granted"},i=null!==(e=this.config.gtmWaitForUpdate)&&void 0!==e?e:500;i>0&&(t.wait_for_update=i),this.dataLayerManager.pushConsent("default",t),this.config.gtmUrlPassthrough&&this.dataLayerManager.pushSet("url_passthrough",!0),this.config.gtmAdsDataRedaction&&this.dataLayerManager.pushSet("ads_data_redaction",!0)}updateConsent(e){const t=this.mapCategoriesToGTM(e);this.dataLayerManager.pushConsent("update",t)}mapCategoriesToGTM(e){const t=!("preferences"in this.config.categories)||!0===e.preferences;return{ad_storage:e.marketing?"granted":"denied",ad_user_data:e.marketing?"granted":"denied",ad_personalization:e.marketing?"granted":"denied",analytics_storage:e.analytics?"granted":"denied",functionality_storage:t?"granted":"denied",personalization_storage:t?"granted":"denied",security_storage:"granted"}}}class g{ensureGtag(){window.dataLayer=window.dataLayer||[],"function"!=typeof window.gtag&&(window.gtag=function(){window.dataLayer.push(arguments)})}pushConsent(e,t){this.ensureGtag(),window.gtag("consent",e,t)}pushSet(e,t){this.ensureGtag(),window.gtag("set",e,t)}}const y={analytics:[/^_ga/,/^_gid/,/^_gat/,/^_gcl/,/^_hj/,/^_pk_/,/^mp_/,/^ajs_/,/^amplitude/,/^plausible/],marketing:[/^_fbp/,/^_fbc/,/^fr$/,/^_pin_/,/^_tt_/,/^li_/,/^_uet/,/^IDE$/,/^test_cookie/,/^MUID$/,/^NID$/],preferences:[/^lang$/,/^locale$/,/^i18n/]};function b(e){const t=window.location.hostname,i=["/",window.location.pathname],s=["",t],n=t.split(".");n.length>2&&s.push("."+n.slice(-2).join(".")),s.push("."+t);for(const t of s)for(const s of i){const i=t?"; domain="+t:"";document.cookie=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${s}${i}`,document.cookie=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${s}${i}; secure`,document.cookie=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${s}${i}; samesite=lax`,document.cookie=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${s}${i}; samesite=none; secure`}}function k(e){const t=y[e];if(!t)return;const i=document.cookie.split(";").map(e=>e.trim().split("=")[0]).filter(Boolean);for(const e of i)t.some(t=>t.test(e))&&b(e)}function C(e){for(const[t,i]of Object.entries(e))i||"necessary"===t||k(t)}const w={en:{title:"We use cookies",description:"We use cookies to improve your experience on our site. You can choose which cookies you accept.",acceptAll:"Accept all",rejectAll:"Essentials only",customize:"Manage preferences",savePreferences:"Save preferences",essentialsOnly:"Essentials only",preferencesTitle:"Cookie Preferences",cookieSettings:"Cookie settings",cookies:"Cookies",privacyPolicyLabel:"Privacy Policy"},fr:{title:"Nous utilisons des cookies",description:"Ce site utilise des cookies pour améliorer votre expérience de navigation. Vous pouvez choisir les cookies que vous acceptez.",acceptAll:"Tout accepter",rejectAll:"Essentiels uniquement",customize:"Gérer mes préférences",savePreferences:"Enregistrer",essentialsOnly:"Essentiels uniquement",preferencesTitle:"Préférences des cookies",cookieSettings:"Paramètres des cookies",cookies:"Cookies",privacyPolicyLabel:"Politique de confidentialité"},de:{title:"Wir verwenden Cookies",description:"Diese Website verwendet Cookies, um Ihr Erlebnis zu verbessern. Sie können wählen, welche Cookies Sie akzeptieren.",acceptAll:"Alle akzeptieren",rejectAll:"Nur essenzielle",customize:"Einstellungen verwalten",savePreferences:"Speichern",essentialsOnly:"Nur essenzielle",preferencesTitle:"Cookie-Einstellungen",cookieSettings:"Cookie-Einstellungen",cookies:"Cookies",privacyPolicyLabel:"Datenschutzrichtlinie"},es:{title:"Usamos cookies",description:"Este sitio utiliza cookies para mejorar su experiencia. Puede elegir qué cookies acepta.",acceptAll:"Aceptar todo",rejectAll:"Solo esenciales",customize:"Gestionar preferencias",savePreferences:"Guardar",essentialsOnly:"Solo esenciales",preferencesTitle:"Preferencias de cookies",cookieSettings:"Configuración de cookies",cookies:"Cookies",privacyPolicyLabel:"Política de privacidad"},it:{title:"Utilizziamo i cookie",description:"Questo sito utilizza i cookie per migliorare la tua esperienza. Puoi scegliere quali cookie accettare.",acceptAll:"Accetta tutti",rejectAll:"Solo essenziali",customize:"Gestisci preferenze",savePreferences:"Salva",essentialsOnly:"Solo essenziali",preferencesTitle:"Preferenze cookie",cookieSettings:"Impostazioni cookie",cookies:"Cookie",privacyPolicyLabel:"Informativa sulla privacy"},nl:{title:"Wij gebruiken cookies",description:"Deze site maakt gebruik van cookies om uw ervaring te verbeteren. U kunt kiezen welke cookies u accepteert.",acceptAll:"Alles accepteren",rejectAll:"Alleen essentieel",customize:"Voorkeuren beheren",savePreferences:"Opslaan",essentialsOnly:"Alleen essentieel",preferencesTitle:"Cookie-voorkeuren",cookieSettings:"Cookie-instellingen",cookies:"Cookies",privacyPolicyLabel:"Privacybeleid"},pt:{title:"Utilizamos cookies",description:"Este site utiliza cookies para melhorar a sua experiência. Pode escolher quais cookies aceita.",acceptAll:"Aceitar todos",rejectAll:"Apenas essenciais",customize:"Gerir preferências",savePreferences:"Guardar",essentialsOnly:"Apenas essenciais",preferencesTitle:"Preferências de cookies",cookieSettings:"Definições de cookies",cookies:"Cookies",privacyPolicyLabel:"Política de privacidade"}};e.CookieConsent=class{constructor(e){if(this.banner=null,this.preferenceCenter=null,this.floatingWidget=null,this.gtmIntegration=null,this.hideTimeout=null,"undefined"==typeof window)return this.config=e,this.consentManager=null,this.storageManager=null,this.eventEmitter=null,void(this.scriptBlocker=null);this.config=this.validateConfig(e),this.consentManager=new i(this.config),this.storageManager=new t,this.eventEmitter=new s,this.scriptBlocker=new n(new o,this.eventEmitter),this.config.gtmConsentMode&&(this.gtmIntegration=new m(new g,this.config)),this.eventEmitter.on("consent:accept",e=>{var t,i;this.updateConsent(e),null===(i=(t=this.config).onAccept)||void 0===i||i.call(t,e)}),this.eventEmitter.on("consent:reject",e=>{var t,i;this.updateConsent(e),null===(i=(t=this.config).onReject)||void 0===i||i.call(t)}),this.eventEmitter.on("consent:update",e=>{var t,i;this.updateConsent(e),null===(i=(t=this.config).onChange)||void 0===i||i.call(t,e)}),this.eventEmitter.on("preferences:show",()=>{this.showPreferences()})}init(){if("undefined"==typeof window)return;this.scriptBlocker.init(),this.gtmIntegration&&this.gtmIntegration.setDefaultConsent();const e=this.storageManager.load();e&&!this.storageManager.isExpired(e)?this.consentManager.needsUpdate(e)?this.config.autoShow&&this.showBanner():(this.applyConsent(e.categories),this.gtmIntegration&&this.gtmIntegration.updateConsent(e.categories),this.eventEmitter.emit("consent:load",e),this.config.showWidget&&this.showFloatingWidget()):this.config.autoShow&&this.showBanner(),window.cookieConsent=this,this.eventEmitter.emit("consent:init")}show(){this.showBanner()}hide(){var e;null===(e=this.banner)||void 0===e||e.hide()}showPreferences(){var e;const t=(null===(e=this.storageManager.load())||void 0===e?void 0:e.categories)||{necessary:!0,analytics:!0,marketing:!0};for(const e of Object.keys(this.config.categories))e in t||(t[e]="necessary"===e);this.preferenceCenter&&this.preferenceCenter.destroy(),this.preferenceCenter=new f(this.config,this.eventEmitter,t),this.preferenceCenter.show()}updateConsent(e){const t=this.consentManager.updateConsent(e);this.storageManager.save(t),this.applyConsent(e),this.gtmIntegration&&this.gtmIntegration.updateConsent(e),this.config.showWidget&&setTimeout(()=>{this.showFloatingWidget()},400)}getConsent(){return this.storageManager.load()}reset(){var e,t;this.storageManager.clear(),this.scriptBlocker.block();const i={necessary:!0,analytics:!1,marketing:!1};for(const e of Object.keys(this.config.categories))"necessary"!==e&&(i[e]=!1);C(i),this.gtmIntegration&&this.gtmIntegration.updateConsent(i),null===(t=(e=this.config).onReject)||void 0===t||t.call(e),this.showBanner()}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}destroy(){var e,t,i,s;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null),null===(e=this.banner)||void 0===e||e.destroy(),this.banner=null,null===(t=this.preferenceCenter)||void 0===t||t.destroy(),this.preferenceCenter=null,null===(i=this.floatingWidget)||void 0===i||i.destroy(),this.floatingWidget=null,null===(s=this.scriptBlocker)||void 0===s||s.destroy(),this.eventEmitter.clear(),window.cookieConsent===this&&(window.cookieConsent=void 0)}showBanner(){this.banner||(this.banner=new p(this.config,this.eventEmitter)),this.banner.show(),this.eventEmitter.emit("consent:show")}showFloatingWidget(){this.floatingWidget||(this.floatingWidget=new v(this.config,this.eventEmitter)),this.floatingWidget.show()}applyConsent(e){this.scriptBlocker.unblock(e),C(e)}validateConfig(e){var t;const i=(null===(t=e.language)||void 0===t?void 0:t.toLowerCase().split("-")[0])||"en",s=Object.assign(Object.assign({},w[i]||w.en),e.translations);return Object.assign(Object.assign({},e),{translations:s,categories:e.categories||{necessary:{enabled:!0,readOnly:!0,label:"Essential",description:"Required for the website to function properly."},analytics:{enabled:!0,readOnly:!1,label:"Analytics",description:"Help us understand how you use our site."},marketing:{enabled:!0,readOnly:!1,label:"Marketing",description:"Used to deliver relevant advertisements."}},mode:e.mode||"opt-in",autoShow:void 0===e.autoShow||e.autoShow,revision:e.revision||1,gtmConsentMode:e.gtmConsentMode||!1,disablePageInteraction:e.disablePageInteraction||!1,theme:e.theme||"light",position:e.position||"bottom-left",layout:e.layout||"box",backdropBlur:!1!==e.backdropBlur,animationStyle:e.animationStyle||"smooth",preferencesPosition:e.preferencesPosition||"center",showWidget:void 0===e.showWidget||e.showWidget,widgetPosition:e.widgetPosition||"bottom-left",widgetStyle:e.widgetStyle||"compact"})}}});
2
2
  //# sourceMappingURL=cookiecraft.min.js.map