"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var s={key:"CookieController",ids:{details:"cookie-details",alert:"cookie-alert"},attributes:{details:"data-cookie-details",alert:"data-cookie-alert",cookieCategory:"data-cookie-category",action:{attribute:"data-cookie-action",value:{dismiss:"dismiss",accept:"accept",reject:"reject",details:"details",save:"save"}}}};var I=()=>({details:document.querySelector(`[${s.attributes.details}]`),alert:document.querySelector(`[${s.attributes.alert}]`),categoryCheckboxes:document.querySelectorAll(`input[type="checkbox"][${s.attributes.cookieCategory}]`),actionDismiss:document.querySelectorAll(`[${s.attributes.action.attribute}="${s.attributes.action.value.dismiss}"]`),actionAccept:document.querySelectorAll(`[${s.attributes.action.attribute}="${s.attributes.action.value.accept}"]`),actionReject:document.querySelectorAll(`[${s.attributes.action.attribute}="${s.attributes.action.value.reject}"]`),actionDetails:document.querySelectorAll(`[${s.attributes.action.attribute}="${s.attributes.action.value.details}"]`),actionSave:document.querySelectorAll(`[${s.attributes.action.attribute}="${s.attributes.action.value.save}"]`)}),m=I;var q=()=>typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,o=>{let r=Math.random()*16|0;return(o==="x"?r:r&3|8).toString(16)}),u=q;var L={state:{uuid:"",interacted:!1,categories:{}},options:{essentialCookies:!1,categoryCookies:{},onConsentChange:null,version:null,storage:{path:"/",sameSite:"Strict",secure:window.location.protocol==="https:"}},abortController:new AbortController,elements:null},e=L;var N=()=>{let o={};if(_optionalChain([e, 'access', _2 => _2.elements, 'optionalAccess', _3 => _3.categoryCheckboxes]))for(let r=0;r _4.elements, 'access', _5 => _5.categoryCheckboxes, 'access', _6 => _6[r], 'optionalAccess', _7 => _7.getAttribute, 'call', _8 => _8(s.attributes.cookieCategory)]);o[a]=!1}try{let i=_optionalChain([document, 'access', _9 => _9.cookie, 'access', _10 => _10.split, 'call', _11 => _11(";"), 'access', _12 => _12.find, 'call', _13 => _13(a=>a.trim().startsWith(`${s.key}=`)), 'optionalAccess', _14 => _14.split, 'call', _15 => _15("="), 'access', _16 => _16[1]]);return i?JSON.parse(i):{uuid:"",version:_optionalChain([e, 'access', _17 => _17.options, 'access', _18 => _18.version, 'optionalAccess', _19 => _19.current])||void 0,interacted:!1,categories:o}}catch (e2){return{uuid:"",version:_optionalChain([e, 'access', _20 => _20.options, 'access', _21 => _21.version, 'optionalAccess', _22 => _22.current])||void 0,interacted:!1,categories:o}}},p=N;var O=(o,r)=>{o==="warn"&&console.warn(`[Cookie Controller] ${r}`)},f=O;var M=o=>{o.uuid||(o.uuid=t.generateUUID());let r=JSON.stringify(o);document.cookie=t.formatCookieString(s.key,r,e.options.storage),e.state=o},g=M;var R=o=>{if(o==="static"){_optionalChain([e, 'access', _23 => _23.elements, 'optionalAccess', _24 => _24.details, 'optionalAccess', _25 => _25.hasAttribute, 'call', _26 => _26("id")])||_optionalChain([e, 'access', _27 => _27.elements, 'optionalAccess', _28 => _28.details, 'optionalAccess', _29 => _29.setAttribute, 'call', _30 => _30("id",s.ids.details)]),_optionalChain([e, 'access', _31 => _31.elements, 'optionalAccess', _32 => _32.alert, 'optionalAccess', _33 => _33.hasAttribute, 'call', _34 => _34("id")])||_optionalChain([e, 'access', _35 => _35.elements, 'optionalAccess', _36 => _36.alert, 'optionalAccess', _37 => _37.setAttribute, 'call', _38 => _38("id",s.ids.alert)]);let r=_optionalChain([e, 'access', _39 => _39.elements, 'optionalAccess', _40 => _40.details, 'optionalAccess', _41 => _41.getAttribute, 'call', _42 => _42("id")]);if(_optionalChain([e, 'access', _43 => _43.elements, 'optionalAccess', _44 => _44.details, 'optionalAccess', _45 => _45.setAttribute, 'call', _46 => _46("role","dialog")]),_optionalChain([e, 'access', _47 => _47.elements, 'optionalAccess', _48 => _48.details, 'optionalAccess', _49 => _49.setAttribute, 'call', _50 => _50("aria-modal","true")]),_optionalChain([e, 'access', _51 => _51.elements, 'optionalAccess', _52 => _52.alert, 'optionalAccess', _53 => _53.setAttribute, 'call', _54 => _54("aria-live","polite")]),_optionalChain([e, 'access', _55 => _55.elements, 'optionalAccess', _56 => _56.alert, 'optionalAccess', _57 => _57.setAttribute, 'call', _58 => _58("role","alert")]),_optionalChain([e, 'access', _59 => _59.elements, 'optionalAccess', _60 => _60.actionDetails]))for(let i=0;i _61.setAttribute, 'call', _62 => _62("aria-controls",r)]),_optionalChain([a, 'optionalAccess', _63 => _63.setAttribute, 'call', _64 => _64("aria-haspopup","dialog")])}}if(o==="dynamic"){let r=t.detailsState.get();if(_optionalChain([e, 'access', _65 => _65.elements, 'optionalAccess', _66 => _66.details, 'optionalAccess', _67 => _67.setAttribute, 'call', _68 => _68("aria-hidden",r?"false":"true")]),_optionalChain([e, 'access', _69 => _69.elements, 'optionalAccess', _70 => _70.alert, 'optionalAccess', _71 => _71.setAttribute, 'call', _72 => _72("aria-hidden",r?"true":"false")]),_optionalChain([e, 'access', _73 => _73.elements, 'optionalAccess', _74 => _74.actionDetails]))for(let i=0;i _75.elements, 'access', _76 => _76.actionDetails, 'access', _77 => _77[i], 'optionalAccess', _78 => _78.setAttribute, 'call', _79 => _79("aria-expanded",r?"true":"false")])}},d=R;var T=o=>{_optionalChain([e, 'access', _80 => _80.elements, 'optionalAccess', _81 => _81.alert, 'optionalAccess', _82 => _82.setAttribute, 'call', _83 => _83(s.attributes.alert,o?"true":"false")]),t.setAttributes("dynamic")},H=()=>_optionalChain([e, 'access', _84 => _84.elements, 'optionalAccess', _85 => _85.alert, 'optionalAccess', _86 => _86.getAttribute, 'call', _87 => _87(s.attributes.alert)])==="true",C={get:H,set:T};var J=o=>{t.alertState.get()&&t.alertState.set(!1),_optionalChain([e, 'access', _88 => _88.elements, 'optionalAccess', _89 => _89.details, 'optionalAccess', _90 => _90.setAttribute, 'call', _91 => _91(s.attributes.details,o?"true":"false")]),t.setAttributes("dynamic")},V=()=>_optionalChain([e, 'access', _92 => _92.elements, 'optionalAccess', _93 => _93.details, 'optionalAccess', _94 => _94.getAttribute, 'call', _95 => _95(s.attributes.details)])==="true",b={get:V,set:J};var P=(o,r)=>{if(e.options.onConsentChange){let i=Object.entries(e.state.categories).map(([a,l])=>({category:a,consented:l,cookies:_nullishCoalesce(e.options.categoryCookies[a], () => ([]))}));e.options.essentialCookies&&i.push({category:"essential",consented:!0,cookies:_nullishCoalesce(e.options.categoryCookies.essential, () => ([]))}),e.options.onConsentChange({type:o,uuid:e.state.uuid,version:e.state.version,categories:i,changed:r})}},k=P;var W=o=>{let r=o.target,i=r.getAttribute(s.attributes.cookieCategory);if(!i)return;let a=r.checked;e.state.categories[i]=a,t.setCookieState(e.state),t.onConsentChange("change",{category:i,consented:a,cookies:_nullishCoalesce(e.options.categoryCookies[i], () => ([]))})},x=W;var z=(o="accept")=>{if(_optionalChain([e, 'access', _96 => _96.elements, 'optionalAccess', _97 => _97.categoryCheckboxes]))for(let r=0;rt.rejectAccept("reject"),S=B;var F=()=>t.rejectAccept("accept"),h=F;var G=()=>{t.detailsState.set(!1),t.alertState.set(!1),e.state.interacted=!0,t.setCookieState(e.state)},v=G;var K=()=>{if(_optionalChain([e, 'access', _98 => _98.elements, 'optionalAccess', _99 => _99.categoryCheckboxes]))for(let o=0;o (!1))}t.detailsState.set(!t.detailsState.get()),e.state.interacted=!0,t.setCookieState(e.state)},A=K;var Q=()=>{if(_optionalChain([e, 'access', _100 => _100.elements, 'optionalAccess', _101 => _101.categoryCheckboxes]))for(let o=0;o{let{signal:o}=e.abortController,r=(i,a,l)=>{for(let c=0;c _102[c], 'optionalAccess', _103 => _103.addEventListener, 'call', _104 => _104(a,l,{signal:o})])};_optionalChain([e, 'access', _105 => _105.elements, 'optionalAccess', _106 => _106.actionDismiss])&&r(e.elements.actionDismiss,"click",t.dismiss),_optionalChain([e, 'access', _107 => _107.elements, 'optionalAccess', _108 => _108.actionAccept])&&r(e.elements.actionAccept,"click",t.accept),_optionalChain([e, 'access', _109 => _109.elements, 'optionalAccess', _110 => _110.actionReject])&&r(e.elements.actionReject,"click",t.reject),_optionalChain([e, 'access', _111 => _111.elements, 'optionalAccess', _112 => _112.actionDetails])&&r(e.elements.actionDetails,"click",t.toggleDetails),_optionalChain([e, 'access', _113 => _113.elements, 'optionalAccess', _114 => _114.actionSave])&&r(e.elements.actionSave,"click",t.save),_optionalChain([e, 'access', _115 => _115.elements, 'optionalAccess', _116 => _116.categoryCheckboxes])&&r(e.elements.categoryCheckboxes,"change",t.onCategoryChange)},j=X;var Y=o=>{if(e.options={essentialCookies:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _117 => _117.essentialCookies]), () => (!1)),categoryCookies:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _118 => _118.categoryCookies]), () => ({})),onConsentChange:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _119 => _119.onConsentChange]), () => (null)),version:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _120 => _120.version]), () => (null)),storage:{path:"/",sameSite:"Strict",secure:window.location.protocol==="https:",..._optionalChain([o, 'optionalAccess', _121 => _121.storage])}},e.elements=t.getElements(),e.abortController=new AbortController,!e.elements.details){t.log("warn","No details element has been found.");return}if(!e.elements.alert){t.log("warn","No alert element has been found.");return}e.state=t.getCookieState(),t.setAttributes("static"),t.setAttributes("dynamic"),e.state.interacted||t.alertState.set(!0),t.registerEvents(),e.state.version&&_optionalChain([e, 'access', _122 => _122.options, 'access', _123 => _123.version, 'optionalAccess', _124 => _124.current])&&(e.state.version!==e.options.version.current&&_optionalChain([e, 'access', _125 => _125.options, 'access', _126 => _126.version, 'access', _127 => _127.onNewVersion, 'optionalCall', _128 => _128(e.state.version,e.options.version.current)]),e.state.version=e.options.version.current,t.setCookieState(e.state)),t.onConsentChange("onload")},$=Y;var Z=()=>{e.abortController.abort()},E=Z;var _=o=>e.state.categories[o],w=_;var ee=(o,r,i)=>{let a=[`${o}=${r}`];if(i.path&&a.push(`path=${i.path}`),i.domain&&a.push(`domain=${i.domain}`),i.sameSite&&a.push(`SameSite=${i.sameSite}`),i.secure&&a.push("Secure"),i.expires){let l=i.expires instanceof Date?i.expires:new Date(Date.now()+i.expires*24*60*60*1e3);a.push(`expires=${l.toUTCString()}`)}return a.join(";")},U=ee;var te={getElements:m,generateUUID:u,getCookieState:p,log:f,setCookieState:g,setAttributes:d,alertState:C,detailsState:b,onConsentChange:k,onCategoryChange:x,rejectAccept:y,accept:h,reject:S,dismiss:v,toggleDetails:A,save:D,registerEvents:j,initialise:$,destroy:E,getCookieConsent:w,formatCookieString:U},t=te;var oo={init:t.initialise,destroy:t.destroy,getCookieConsent:t.getCookieConsent,accept:t.accept,reject:t.reject,dismiss:t.dismiss,toggleDetails:t.toggleDetails,save:t.save};exports.default = oo; //# sourceMappingURL=index.cjs.map