@usercentrics/cmp-browser-sdk
Version:
Usercentrics CMP Browser SDK
2 lines (1 loc) • 29.2 kB
JavaScript
import{r as e,t,u as s,w as n,$ as i,x as r,y as o,z as a,B as c,_ as u,H as d,I as l,J as h,K as p,M as v,N as f,O as g,P as m,Q as I,R as C,T as E,f as b,h as V,p as S,U as y,V as A,X as T,Y as M,Z as D,a0 as L,a1 as w,a2 as P,a3 as _,b as k,a4 as R,a5 as O,a6 as N,a7 as F,a8 as U,G,q as Q,a9 as x,l as B,n as j,aa as H,ab as W,ac as q,ad as z,ae as X,af as J,ag as K,ah as Y,ai as Z,i as $,aj as ee,ak as te,al as se}from"./index-c3735125.js";import ne from"./DefaultData-982e0079.js";var ie,re;function oe(e,t){return Object.keys(t).forEach(function(s){"default"===s||"__esModule"===s||Object.prototype.hasOwnProperty.call(e,s)||Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[s]}})}),e}function ae(e,t,s,n){Object.defineProperty(e,t,{get:s,set:n,enumerable:!0,configurable:!0})}var ce={},ue={};ae(ue,"TCFCommand",function(){return de});var de=function(e){return e.PING="ping",e.GET_TC_DATA="getTCData",e.GET_IN_APP_TC_DATA="getInAppTCData",e.GET_VENDOR_LIST="getVendorList",e.ADD_EVENT_LISTENER="addEventListener",e.REMOVE_EVENT_LISTENER="removeEventListener",e}({});oe(ce,ue),oe(ce,{});var le={},he={};ae(he,"InAppTCData",function(){return De});var pe={};ae(pe,"TCData",function(){return Me});ae({},"CmpApiModel",function(){return ye});var ve={},fe={};ae(fe,"CmpStatus",function(){return ge});var ge=function(e){return e.STUB="stub",e.LOADING="loading",e.LOADED="loaded",e.ERROR="error",e}({}),me={};ae(me,"DisplayStatus",function(){return Ie});var Ie=function(e){return e.VISIBLE="visible",e.HIDDEN="hidden",e.DISABLED="disabled",e}({}),Ce={};ae(Ce,"EventStatus",function(){return Ee});var Ee=function(e){return e.TC_LOADED="tcloaded",e.CMP_UI_SHOWN="cmpuishown",e.USER_ACTION_COMPLETE="useractioncomplete",e}({});oe(ve,fe),oe(ve,me),oe(ve,Ce);var be=function(){return t(function e(t,n,i,r){s(this,e),this.success=!0,Object.assign(this,{callback:t,listenerId:i,param:n,next:r});try{this.respond()}catch(o){this.invokeCallback(null)}},[{key:"invokeCallback",value:function(e){var t=null!==e;"function"==typeof this.next?this.callback(this.next,e,t):this.callback(e,t)}}])}(),Ve=function(){function n(){return s(this,n),c(this,n,arguments)}return e(n,be),t(n,[{key:"respond",value:function(){this.throwIfParamInvalid(),this.invokeCallback(new Me(this.param,this.listenerId))}},{key:"throwIfParamInvalid",value:function(){if(!(void 0===this.param||Array.isArray(this.param)&&this.param.every(Number.isInteger)))throw new Error("Invalid Parameter")}}])}(),Se=function(){return t(function e(){s(this,e),this.eventQueue=new Map,this.queueNumber=0},[{key:"add",value:function(e){return this.eventQueue.set(this.queueNumber,e),this.queueNumber++}},{key:"remove",value:function(e){return this.eventQueue.delete(e)}},{key:"exec",value:function(){this.eventQueue.forEach(function(e,t){new Ve(e.callback,e.param,t,e.next)})}},{key:"clear",value:function(){this.queueNumber=0,this.eventQueue.clear()}},{key:"size",get:function(){return this.eventQueue.size}}])}(),ye=function(){return t(function e(){s(this,e)},null,[{key:"reset",value:function(){delete this.cmpId,delete this.cmpVersion,delete this.eventStatus,delete this.gdprApplies,delete this.tcModel,delete this.tcString,delete this.tcfPolicyVersion,this.enableAdvertiserConsentMode=!1,this.addtlConsent="",this.cmpStatus=ge.LOADING,this.disabled=!1,this.displayStatus=Ie.HIDDEN,this.eventQueue.clear()}}])}();(ie=ye).apiVersion="2",ie.eventQueue=new Se,ie.cmpStatus=ge.LOADING,ie.disabled=!1,ie.displayStatus=Ie.HIDDEN,ie.enableAdvertiserConsentMode=!1,ie.addtlConsent="";var Ae={};ae(Ae,"Response",function(){return Te});var Te=t(function e(){s(this,e),this.cmpId=ye.cmpId,this.cmpVersion=ye.cmpVersion,this.gdprApplies=ye.gdprApplies,this.tcfPolicyVersion=ye.tcfPolicyVersion}),Me=function(){function i(e,t){var n;if(s(this,i),(n=c(this,i)).eventStatus=ye.eventStatus,n.cmpStatus=ye.cmpStatus,n.listenerId=t,ye.gdprApplies){var r=ye.tcModel;n.tcString=ye.tcString,n.addtlConsent=r.addtlConsent,n.enableAdvertiserConsentMode=r.enableAdvertiserConsentMode,n.isServiceSpecific=r.isServiceSpecific,n.useNonStandardTexts=r.useNonStandardTexts,n.purposeOneTreatment=r.purposeOneTreatment,n.publisherCC=r.publisherCountryCode,n.outOfBand={allowedVendors:n.createVectorField(r.vendorsAllowed,e),disclosedVendors:n.createVectorField(r.vendorsDisclosed,e)},n.purpose={consents:n.createVectorField(r.purposeConsents),legitimateInterests:n.createVectorField(r.purposeLegitimateInterests)},n.vendor={consents:n.createVectorField(r.vendorConsents,e),legitimateInterests:n.createVectorField(r.vendorLegitimateInterests,e)},n.specialFeatureOptins=n.createVectorField(r.specialFeatureOptins),n.publisher={consents:n.createVectorField(r.publisherConsents),legitimateInterests:n.createVectorField(r.publisherLegitimateInterests),customPurpose:{consents:n.createVectorField(r.publisherCustomConsents),legitimateInterests:n.createVectorField(r.publisherCustomLegitimateInterests)},restrictions:n.createRestrictions(r.publisherRestrictions)}}return n}return e(i,Te),t(i,[{key:"createRestrictions",value:function(e){var t={};if(e.numRestrictions>0)for(var s=e.getMaxVendorId(),n=function(){var s=i.toString();e.getRestrictions(i).forEach(function(e){var n=e.purposeId.toString();t[n]||(t[n]={}),t[n][s]=e.restrictionType})},i=1;i<=s;i++)n();return t}},{key:"createVectorField",value:function(e,t){return t?t.reduce(function(t,s){return t[String(s)]=e.has(Number(s)),t},{}):n(e).reduce(function(e,t){return e[t[0].toString(10)]=t[1],e},{})}}])}(),De=function(){function i(e){var t;return s(this,i),delete(t=c(this,i,[e])).outOfBand,t}return e(i,Me),t(i,[{key:"createVectorField",value:function(e){return n(e).reduce(function(e,t){return e+=t[1]?"1":"0"},"")}},{key:"createRestrictions",value:function(e){var t={};if(e.numRestrictions>0){var s=e.getMaxVendorId();e.getRestrictions().forEach(function(e){t[e.purposeId.toString()]="_".repeat(s)});for(var n=function(s){var n=s+1;e.getRestrictions(n).forEach(function(e){var n=e.restrictionType.toString(),i=e.purposeId.toString(),r=t[i].substr(0,s),o=t[i].substr(s+1);t[i]=r+n+o})},i=0;i<s;i++)n(i)}return t}}])}(),Le={};ae(Le,"Ping",function(){return we});var we=function(){function n(){var e;return s(this,n),(e=c(this,n)).cmpLoaded=!0,e.cmpStatus=ye.cmpStatus,e.displayStatus=ye.displayStatus,e.apiVersion=String(ye.apiVersion),ye.tcModel&&ye.tcModel.vendorListVersion&&(e.gvlVersion=+ye.tcModel.vendorListVersion),e}return e(n,Te),t(n)}();oe(le,he),oe(le,Le),oe(le,Ae),oe(le,pe);ae({},"CmpApi",function(){return ze});var Pe,_e,ke,Re,Oe,Ne,Fe=function(){function n(){return s(this,n),c(this,n,arguments)}return e(n,be),t(n,[{key:"respond",value:function(){this.invokeCallback(new we)}}])}(),Ue=function(){function n(){return s(this,n),c(this,n,arguments)}return e(n,Ve),t(n,[{key:"respond",value:function(){this.throwIfParamInvalid(),this.invokeCallback(new De(this.param))}}])}(),Ge=function(){function n(){return s(this,n),c(this,n,arguments)}return e(n,be),t(n,[{key:"respond",value:function(){var e,t=this,s=ye.tcModel,n=s.vendorListVersion;void 0===this.param&&(this.param=n),(e=this.param===n&&s.gvl?s.gvl:new i(this.param)).readyPromise.then(function(){t.invokeCallback(e.getJson())})}}])}(),Qe=function(){function n(){return s(this,n),c(this,n,arguments)}return e(n,Ve),t(n,[{key:"respond",value:function(){this.listenerId=ye.eventQueue.add({callback:this.callback,param:this.param,next:this.next}),r(n,"respond",this,3)([])}}])}(),xe=function(){function n(){return s(this,n),c(this,n,arguments)}return e(n,be),t(n,[{key:"respond",value:function(){this.invokeCallback(ye.eventQueue.remove(this.param))}}])}(),Be=t(function e(){s(this,e)});re=Be,Pe=de.PING,_e=de.GET_TC_DATA,ke=de.GET_IN_APP_TC_DATA,Re=de.GET_VENDOR_LIST,Oe=de.ADD_EVENT_LISTENER,Ne=de.REMOVE_EVENT_LISTENER,re[Pe]=Fe,re[_e]=Ve,re[ke]=Ue,re[Re]=Ge,re[Oe]=Qe,re[Ne]=xe;var je=function(){function n(){var e;s(this,n);for(var t=arguments.length,i=new Array(t),r=0;r<t;r++)i[r]=arguments[r];return(e=c(this,n,[].concat(i))).cmpStatus=ge.ERROR,e}return e(n,Te),t(n)}(),He=function(){return t(function e(){s(this,e)},null,[{key:"has",value:function(e){return"string"==typeof e&&(e=Number(e)),this.set_.has(e)}}])}();He.set_=new Set([0,2,void 0,null]);var We="__tcfapi",qe=function(){return t(function e(t){if(s(this,e),t){var n=de.ADD_EVENT_LISTENER;if(null!=t&&t[n])throw new Error("Built-In Custom Commmand for ".concat(n," not allowed: Use ").concat(de.GET_TC_DATA," instead"));if(n=de.REMOVE_EVENT_LISTENER,null!=t&&t[n])throw new Error("Built-In Custom Commmand for ".concat(n," not allowed"));null!=t&&t[de.GET_TC_DATA]&&(t[de.ADD_EVENT_LISTENER]=t[de.GET_TC_DATA],t[de.REMOVE_EVENT_LISTENER]=t[de.GET_TC_DATA]),this.customCommands=t}try{this.callQueue=window[We]()||[]}catch(i){this.callQueue=[]}finally{window[We]=this.apiCall.bind(this),this.purgeQueuedCalls()}},[{key:"apiCall",value:function(e,t,s){for(var n,i=arguments.length,r=new Array(i>3?i-3:0),o=3;o<i;o++)r[o-3]=arguments[o];if("string"!=typeof e)s(null,!1);else if(He.has(t)){if("function"!=typeof s)throw new Error("invalid callback function");ye.disabled?s(new je,!1):this.isCustomCommand(e)||this.isBuiltInCommand(e)?this.isCustomCommand(e)&&!this.isBuiltInCommand(e)?(n=this.customCommands)[e].apply(n,[s].concat(r)):e===de.PING?this.isCustomCommand(e)?new Be[e](this.customCommands[e],r[0],null,s):new Be[e](s,r[0]):void 0===ye.tcModel?this.callQueue.push([e,t,s].concat(r)):this.isCustomCommand(e)&&this.isBuiltInCommand(e)?new Be[e](this.customCommands[e],r[0],null,s):new Be[e](s,r[0]):s(null,!1)}else s(null,!1)}},{key:"purgeQueuedCalls",value:function(){var e=this.callQueue;this.callQueue=[],e.forEach(function(e){var t;(t=window)[We].apply(t,n(e))})}},{key:"isCustomCommand",value:function(e){return this.customCommands&&"function"==typeof this.customCommands[e]}},{key:"isBuiltInCommand",value:function(e){return void 0!==Be[e]}}])}(),ze=function(){return t(function e(t,n){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3?arguments[3]:void 0;s(this,e),this.numUpdates=0,this.throwIfInvalidInt(t,"cmpId",2),this.throwIfInvalidInt(n,"cmpVersion",0),ye.cmpId=t,ye.cmpVersion=n,ye.tcfPolicyVersion=4,this.isServiceSpecific=!!i,this.callResponder=new qe(r)},[{key:"throwIfInvalidInt",value:function(e,t,s){if(!("number"==typeof e&&Number.isInteger(e)&&e>=s))throw new Error("Invalid ".concat(t,": ").concat(e))}},{key:"update",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=arguments.length>2?arguments[2]:void 0;if(ye.disabled)throw new Error("CmpApi Disabled");ye.cmpStatus=ge.LOADED,t?(ye.displayStatus=Ie.VISIBLE,ye.eventStatus=Ee.CMP_UI_SHOWN):void 0===ye.tcModel?(ye.displayStatus=Ie.DISABLED,ye.eventStatus=Ee.TC_LOADED):(ye.displayStatus=Ie.HIDDEN,ye.eventStatus=Ee.USER_ACTION_COMPLETE),ye.gdprApplies=null!==e,ye.gdprApplies?(""===e?(ye.tcModel=new o,ye.tcModel.cmpId=ye.cmpId,ye.tcModel.cmpVersion=ye.cmpVersion):ye.tcModel=a.decode(e),ye.tcModel.addtlConsent=s||"",ye.tcModel.enableAdvertiserConsentMode=ye.enableAdvertiserConsentMode,ye.tcModel.isServiceSpecific=this.isServiceSpecific,ye.tcfPolicyVersion=Number(ye.tcModel.policyVersion),ye.tcString=e):ye.tcModel=null,0===this.numUpdates?this.callResponder.purgeQueuedCalls():ye.eventQueue.exec(),this.numUpdates++}},{key:"disable",value:function(){ye.disabled=!0,ye.cmpStatus=ge.ERROR}}])}(),Xe=function(e){function t(t,s,n,i,r,o,a,c){var u=e.call(this,n,r)||this;u.gcmEnabled=!1,u.policyVersion=5,u.locationInstance=d.getInstance(),u.botInstance=l.getInstance(),u.previousStorage=null,u.selectedVendorsIncludeNonDisclosed=!1,u.cmpApi={},u.tcModel=null,u.tcfData=null,u.vendors=[];var b=t.tcf2,V=b.acmV2Enabled,S=b.advertiserConsentModeEnabled,y=b.atpPurposes,A=b.changedPurposes,T=b.cmpId,M=b.cmpVersion,D=b.consensuDomain,L=b.consensuScriptPath,w=b.dataRetentionPeriodLabel,P=b.disabledSpecialFeatures,_=b.firstLayerHideToggles,k=b.gdprApplies,R=b.hideLegitimateInterestToggles,O=b.publisherCountryCode,N=b.purposeOneTreatment,F=b.secondLayerHideToggles,U=b.selectedStacks,G=b.selectedVendorIds,Q=b.selectedATPIds,x=b.tcfv2HistoryDisabled,B=b.vendorIdsOutsideEUList,j=b.version,H=t.googleConsentMode;return u.acmData={isEnabled:!0===V,vendorIds:V&&Q||[],vendorsPurposes:V&&y?h(y):[]},u.advertiserConsentModeEnabled=S,u.gcmEnabled=!0===H,u.changedPurposes=p(A),u.cmpId=T||5,u.cmpVersion=M||v(),u.policyVersion="2.0"===j||"2.1"===j?2:5,u.consensuScriptPath=f(L),u.consensuSubdomain=g(D),u.dataRetentionLabel=w,u.disabledSpecialFeatures=P||[],u.gdprApplies=m(k,!1),u.hideLegitimateInterestToggles=R,u.isAnalyticsEnabled=!0===t.consentAnalytics,u.isApiV2Enabled=!0===t.consentAPIv2,u.isConsentXDeviceEnabled=!0===t.consentXDevice,u.publisherCountryCode=O||"DE",u.purposeOneTreatment=m(N,!1),u.resurfaceOptions=I(s),u.stackIds=U||[],u.tcfv2HistoryDisabled=x,u.useGranularChoice=C(_,F),u.vendorIds=G||[],u.vendorIdsOutsideEUList=B||[],u.selectedLanguage=E(o),u.enableDeprecatedV1ConsentSaving=c,u.cmpApi=new ze(u.cmpId,u.cmpVersion,!0),u.dataTransferSettings=i,u.excludeAcceptAllVendors=a,u}return u(t,e),t.prototype.updateControllerId=function(e){this.dataTransferSettings.controllerId=e},t.prototype.applySpecialCasesForVendors=function(){var e=this;this.tcModel&&Object.values(this.vendors).forEach(function(t){var s=t.id;if(e.tcModel){var n=e.tcModel.gvl.vendors[s];(n&&0===n.purposes.length&&0===n.legIntPurposes.length&&n.specialPurposes.length>0||n&&n.purposes.length>0&&0===n.legIntPurposes.length&&n.specialPurposes.length>0)&&e.tcModel.vendorLegitimateInterests.set(s)}})},t.prototype.acceptAllDisclosed=function(e){var t,s;return b(this,void 0,void 0,function(){var n,i,r,o=this;return V(this,function(a){switch(a.label){case 0:return(n=this.tcModel)?(this.acmData.isEnabled&&this.acmData.vendors&&(this.acmData.vendors=this.acmData.vendors.map(function(e){return S(S({},e),{consent:{status:!0}})})),i=[],r=[],this.getVendors().forEach(function(e){var t=e.id,s=e.legitimateInterestPurposes,a=e.purposes,c=e.specialPurposes,u=-1===o.excludeAcceptAllVendors.indexOf(t);a.length?(u&&n.vendorConsents.set(t),i=i.concat(a.map(function(e){return e.id}))):u&&n.vendorConsents.unset(t),s.length||c.length&&0===s.length&&0===a.length?(u&&n.vendorLegitimateInterests.set(t),r=r.concat(s.map(function(e){return e.id}))):u&&n.vendorLegitimateInterests.unset(t)}),n.purposeConsents.set(y(i)),n.publisherConsents.set(y(i)),n.purposeLegitimateInterests.set(y(r)),n.publisherLegitimateInterests.set(y(r)),this.hideLegitimateInterestToggles&&(n.unsetAllVendorLegitimateInterests(),n.unsetAllPurposeLegitimateInterests()),this.applySpecialCasesForVendors(),n.specialFeatureOptins.set(A(null===(s=null===(t=this.tcModel)||void 0===t?void 0:t.gvl)||void 0===s?void 0:s.stacks,this.getVendors(),this.disabledSpecialFeatures,this.stackIds)),this.tcModel=n,[4,this.updateTCString(e)]):[2];case 1:return a.sent(),[2]}})})},t.prototype.areAllPurposesAccepted=function(){var e,t;return T(this.tcModel,null===(e=this.tcModel)||void 0===e?void 0:e.gvl.stacks,null===(t=this.tcModel)||void 0===t?void 0:t.gvl.purposes,this.vendors,this.disabledSpecialFeatures,this.stackIds,this.purposeOneTreatment,this.useGranularChoice,this.hideLegitimateInterestToggles).every(function(e){var t=!0,s=!0;return e.showConsentToggle&&null!==e.consent&&(t=e.consent),e.showLegitimateInterestToggle&&null!==e.legitimateInterestConsent&&(s=e.legitimateInterestConsent),t&&s})},t.prototype.areAllVendorsAccepted=function(){return this.getVendors().every(function(e){var t=!0,s=!0;return e.showConsentToggle&&null!==e.consent&&(t=e.consent),e.showLegitimateInterestConsentToggle&&null!==e.legitimateInterestConsent&&(s=e.legitimateInterestConsent),t&&s})},t.prototype.changeLanguage=function(e,t){var s;return b(this,void 0,void 0,function(){var n,i,r=this;return V(this,function(o){switch(o.label){case 0:return n=E(e),[4,this.resetGVLWithLanguage("en"===n?"".concat(n,"-v2"):n)];case 1:return o.sent(),t&&(this.dataRetentionLabel=t.dataRetentionPeriodLabel,t.acmV2Enabled&&t.atpPurposes&&(this.acmData.vendorsPurposes=h(t.atpPurposes),i=null===(s=this.acmData.vendors)||void 0===s?void 0:s.map(function(e){return S(S({},e),{purposes:r.acmData.vendorsPurposes})}),this.acmData.vendors=i)),this.tcModel&&this.tcModel.gvl.narrowVendorsTo(this.vendorIds),this.resetTcfData(),[2]}})})},t.prototype.denyAllDisclosed=function(e){return b(this,void 0,void 0,function(){var t;return V(this,function(s){switch(s.label){case 0:return this.tcModel?(this.acmData.isEnabled&&this.acmData.vendors&&(this.acmData.vendors=this.acmData.vendors.map(function(e){return S(S({},e),{consent:{status:!1}})})),this.tcModel.unsetAllVendorConsents(),this.tcModel.unsetAllVendorLegitimateInterests(),this.applySpecialCasesForVendors(),t=M(this.tcModel.gvl.stacks,this.getVendors(),this.disabledSpecialFeatures,this.stackIds,this.purposeOneTreatment),this.tcModel.purposeConsents.unset(t),this.tcModel.purposeLegitimateInterests.unset(t),this.tcModel.specialFeatureOptins.unset(A(this.tcModel.gvl.stacks,this.getVendors(),this.disabledSpecialFeatures,this.stackIds)),this.tcModel.publisherConsents.unset(t),this.tcModel.publisherLegitimateInterests.unset(t),[4,this.updateTCString(e)]):[2];case 1:return s.sent(),[2]}})})},t.prototype.getSelectedVendorsIncludeNonDisclosed=function(){return this.selectedVendorsIncludeNonDisclosed},t.prototype.getTcModel=function(){return this.tcModel},t.prototype.getTCFData=function(){var e,t,s,n,i,r,o,a,c;return this.tcfData||(this.tcfData={acmVendors:this.getAcmVendors(),features:D(this.getVendors(),null===(t=null===(e=this.tcModel)||void 0===e?void 0:e.gvl)||void 0===t?void 0:t.features),purposes:T(this.tcModel,null===(s=this.tcModel)||void 0===s?void 0:s.gvl.stacks,null===(n=this.tcModel)||void 0===n?void 0:n.gvl.purposes,this.getVendors(),this.disabledSpecialFeatures,this.stackIds,this.purposeOneTreatment,this.useGranularChoice,this.hideLegitimateInterestToggles),specialFeatures:L(this.tcModel,null===(i=this.tcModel)||void 0===i?void 0:i.gvl,this.getVendors(),this.disabledSpecialFeatures,this.stackIds,this.useGranularChoice),specialPurposes:w(null===(o=null===(r=this.tcModel)||void 0===r?void 0:r.gvl)||void 0===o?void 0:o.specialPurposes,this.getVendors()),stacks:P(null===(c=null===(a=this.tcModel)||void 0===a?void 0:a.gvl)||void 0===c?void 0:c.stacks,this.disabledSpecialFeatures,this.stackIds),vendors:this.getVendors()}),this.tcfData},t.prototype.getGdprApplies=function(){return b(this,void 0,void 0,function(){return V(this,function(e){switch(e.label){case 0:return this.gdprApplies?[4,this.locationInstance.getIsUserInEU()]:[2,!0];case 1:return[2,e.sent()]}})})},t.prototype.getACString=function(){var e;if(this.acmData.isEnabled&&(null===(e=this.acmData.vendors)||void 0===e?void 0:e.length)){var t=this.acmData.vendors.reduce(function(e,t){var s=e.consentedAcmVendorIds,n=e.disclosedAcmVendorIds;return t.consent.status?s.push(t.id):n.push(t.id),{consentedAcmVendorIds:s,disclosedAcmVendorIds:n}},{consentedAcmVendorIds:[],disclosedAcmVendorIds:[]}),s=t.consentedAcmVendorIds,n=t.disclosedAcmVendorIds;return"2~".concat(s.join("."),"~dv.").concat(n.join("."))}return""},t.prototype.getTCString=function(e){return this.tcModel?a.encode(this.tcModel,e):""},t.prototype.getTCFDisclosedVendorsSegmentString=function(){return this.getTCString({segments:[_.VENDORS_DISCLOSED]})},t.prototype.init=function(e){return b(this,void 0,void 0,function(){var t,s;return V(this,function(n){switch(n.label){case 0:return this.previousStorage=k.fetchTCFData(),t=k.fetchTCString()||"",s=k.fetchACString()||"",[4,this.initTCModel({acString:s,tcString:t},e)];case 1:return n.sent(),this.botInstance.isRobot()&&this.acceptAllDisclosed(1),[2]}})})},t.prototype.setUIAsClosed=function(){return b(this,void 0,void 0,function(){return V(this,function(e){return[2,this.cmpApiUpdate(k.fetchTCString(),!1,k.fetchACString())]})})},t.prototype.setUIAsOpen=function(){return b(this,void 0,void 0,function(){return V(this,function(e){return[2,this.cmpApiUpdate(k.fetchTCString(),!0,k.fetchACString())]})})},t.prototype.shouldResurfaceUI=function(){var e=this.resurfaceOptions;return this.policyVersion>=4&&e.onATPListChanged&&R(this.previousStorage,this.getAcmVendors())||e.onVendorAdded&&O(this.previousStorage,this.getVendors())||e.onPurposeChanged&&N(this.previousStorage,this.getVendors())||e.onPeriodEnded&&F(this.previousStorage)},t.prototype.updateChoices=function(e,t){return b(this,void 0,void 0,function(){var s=this;return V(this,function(n){switch(n.label){case 0:return e.purposes?[4,this.savePurposes(e.purposes)]:[3,2];case 1:n.sent(),n.label=2;case 2:return e.specialFeatures?[4,this.saveSpecialFeatures(e.specialFeatures)]:[3,4];case 3:n.sent(),n.label=4;case 4:return e.vendors?[4,this.saveVendors(e.vendors)]:[3,6];case 5:n.sent(),n.label=6;case 6:return this.tcModel&&this.hideLegitimateInterestToggles&&(this.tcModel.unsetAllVendorLegitimateInterests(),this.tcModel.unsetAllPurposeLegitimateInterests()),this.applySpecialCasesForVendors(),e.acmVendors&&this.acmData.isEnabled&&this.acmData.vendors&&e.acmVendors.forEach(function(e){var t,n=null===(t=s.acmData.vendors)||void 0===t?void 0:t.find(function(t){return t.id===e.id});n&&(n.consent.status=e.consent)}),e.purposes||e.specialFeatures||e.vendors||e.acmVendors?[4,this.updateTCString(t)]:[3,8];case 7:n.sent(),n.label=8;case 8:return[2]}})})},t.prototype.resetTcf=function(){this.cmpApi={},this.selectedVendorsIncludeNonDisclosed=!1,this.tcModel={},this.tcfData=null,this.vendors=[]},t.prototype.applyPurposeRestrictions=function(e,t){var s=this;e.forEach(function(e){var n,i=new U(e,t);null===(n=s.tcModel)||void 0===n||n.publisherRestrictions.restrictPurposeToLegalBasis(i)})},t.prototype.cmpApiUpdate=function(e,t,s){return void 0===s&&(s=""),b(this,void 0,void 0,function(){var n;return V(this,function(i){switch(i.label){case 0:return null==(n=G.getInstance())||n.setSectionString(e,"tcfeuv2"),[4,this.getGdprApplies()];case 1:return i.sent()?this.cmpApi.update(e,t,s):this.cmpApi.update(null),[2]}})})},t.prototype.getVendors=function(){return Q(this.vendors)||this.setVendors(),this.vendors},t.prototype.initTCModel=function(e,t){var s,n,r=e.tcString,c=e.acString;return b(this,void 0,void 0,function(){var e,u,d,l,h,p,v,f,g,m,I,C,b,S,y,A,T,M,D,L,w,P=this;return V(this,function(V){switch(V.label){case 0:if(!this.acmData.isEnabled||!this.acmData.vendorIds.length||this.acmData.vendors)return[3,2];if(e=[],c)try{e=c.split("~")[1].split(".").map(function(e){return parseInt(e,10)})}catch(_){}return[4,$.getInstance().fetchAcmVendors().then(function(t){var s=[];P.acmData.vendorIds.forEach(function(n){if(t.providers[n]){var i=j(t.providers[n],2),r=i[0],o=i[1];s.push({consent:{status:e.some(function(e){return e===n})},id:n,name:r,privacyPolicyUrl:o,purposes:P.acmData.vendorsPurposes})}}),P.acmData.vendors=s})];case 1:V.sent(),V.label=2;case 2:return this.isPolicyVersion2()?(i.baseUrl=t?W:q,i.languageFilename=z,i.latestFilename=X):(i.baseUrl=t?J:K,i.languageFilename=Y,i.latestFilename=Z),[4,$.getInstance().fetchVendorsList("".concat(i.baseUrl).concat(i.latestFilename),this.changedPurposes.notAllowedPurposes)];case 3:if(u=V.sent(),d=new i(u),this.tcModel=new o(d),this.tcModel.cmpId=this.cmpId,this.tcModel.cmpVersion=this.cmpVersion,this.tcModel.isServiceSpecific=!0,this.tcModel.publisherCountryCode=this.publisherCountryCode,this.tcModel.purposeOneTreatment=this.purposeOneTreatment,this.gcmEnabled&&(l=void 0===this.advertiserConsentModeEnabled||this.advertiserConsentModeEnabled,h=void 0!==window.advertiserConsentMode?window.advertiserConsentMode:l,this.setEnableAdvertiserConsentMode(h)),this.acmData.isEnabled&&this.setAddtlConsent(c||""),r)try{if(p=this.tcModel.gvl,v=this.tcModel.publisherRestrictions,f=a.decode(r,this.tcModel),parseInt(f.policyVersion.toString(),10)>2){for(this.tcModel=f,this.isPolicyVersion2()||this.tcModel.purposeLegitimateInterests.unset([1,3,4,5,6]),g=this.tcModel.purposeConsents.values(),m=this.tcModel.purposeConsents.size,b=0;b<=m-1;b+=1)S=g.next().value,p.purposes[S]||null===(s=this.tcModel)||void 0===s||s.purposeConsents.unset(S);for(I=this.tcModel.purposeLegitimateInterests.values(),C=this.tcModel.purposeLegitimateInterests.size,b=0;b<=C-1;b+=1)S=I.next().value,p.purposes[S]||null===(n=this.tcModel)||void 0===n||n.purposeLegitimateInterests.unset(S);this.tcModel=Object.assign(this.tcModel,{gvl:p,publisherRestrictions:v}),null==(y=G.getInstance())||y.setSectionString(r,"tcfeuv2")}}catch(k){console.warn(H.INIT_TCF_ERROR,k)}if(null===this.tcModel)throw new Error(H.TC_MODEL_UNDEFINED);if(!this.selectedLanguage)throw new Error(H.SELECTED_LANGUAGE_UNDEFINED);return[4,this.tcModel.gvl.readyPromise.catch(function(e){console.warn(H.RESET_GVL_FAILURE,e)})];case 4:return V.sent(),this.tcModel.gvl.narrowVendorsTo(this.vendorIds),A=B([],j(this.tcModel.gvl.vendorIds),!1),T=E(this.selectedLanguage),[4,this.resetGVLWithLanguage("en"===T?"".concat(T,"-v2"):T)];case 5:return V.sent(),M=this.changedPurposes,D=M.purposes,L=M.legitimateInterestPurposes,w=M.notAllowedPurposes,this.applyPurposeRestrictions(D,x.REQUIRE_CONSENT),this.applyPurposeRestrictions(L,x.REQUIRE_LI),this.applyPurposeRestrictions(w,x.NOT_ALLOWED),this.setSelectedVendorsIncludeNonDisclosed(A),[2]}})})},t.prototype.setEnableAdvertiserConsentMode=function(e){this.tcModel&&(this.tcModel.enableAdvertiserConsentMode=e),ye.enableAdvertiserConsentMode=e},t.prototype.setAddtlConsent=function(e){this.tcModel&&(this.tcModel.addtlConsent=e),ye.addtlConsent=e},t.prototype.resetGVLWithLanguage=function(e){var t,s;return b(this,void 0,void 0,function(){var n;return V(this,function(i){return n=E(e),[2,null===(s=null===(t=this.tcModel)||void 0===t?void 0:t.gvl)||void 0===s?void 0:s.changeLanguage(n).catch(function(e){console.warn(H.RESET_GVL_FAILURE,e)})]})})},t.prototype.resetTcfData=function(){this.setVendors(),this.tcfData=null},t.prototype.setSelectedVendorsIncludeNonDisclosed=function(e){var t=k.fetchTCFVendorsDisclosedObject();e.some(function(e){return!ee(e,t)})&&(this.selectedVendorsIncludeNonDisclosed=!0)},t.prototype.savePurposes=function(e){return b(this,void 0,void 0,function(){var t;return V(this,function(s){return(t=this.tcModel)?(e.forEach(function(e){e.consent?(t.purposeConsents.set(e.id),t.publisherConsents.set(e.id)):(t.purposeConsents.unset(e.id),t.publisherConsents.unset(e.id)),e.legitimateInterestConsent?(t.purposeLegitimateInterests.set(e.id),t.publisherLegitimateInterests.set(e.id)):(t.purposeLegitimateInterests.unset(e.id),t.publisherLegitimateInterests.unset(e.id))}),[2]):[2]})})},t.prototype.saveSpecialFeatures=function(e){return b(this,void 0,void 0,function(){var t;return V(this,function(s){return(t=this.tcModel)?(e.forEach(function(e){e.consent?t.specialFeatureOptins.set(e.id):t.specialFeatureOptins.unset(e.id)}),[2]):[2]})})},t.prototype.saveVendors=function(e){return b(this,void 0,void 0,function(){var t;return V(this,function(s){return(t=this.tcModel)?(e.forEach(function(e){e.consent?t.vendorConsents.set(e.id):t.vendorConsents.unset(e.id),e.legitimateInterestConsent?t.vendorLegitimateInterests.set(e.id):t.vendorLegitimateInterests.unset(e.id)}),[2]):[2]})})},t.prototype.setVendors=function(){this.vendors=te(this.tcModel,this.disabledSpecialFeatures,this.useGranularChoice,this.hideLegitimateInterestToggles,this.purposeOneTreatment,this.vendorIdsOutsideEUList,this.dataRetentionLabel)},t.prototype.getTcfData=function(){return{acString:this.getACString(),tcString:this.getTCString(),timestamp:Date.now(),vendors:se(this.getVendors())}},t.prototype.injectTCString=function(e){return b(this,void 0,void 0,function(){var t,s;return V(this,function(n){switch(n.label){case 0:return t=a.decode(e),this.isPolicyVersion2()||t.purposeLegitimateInterests.unset([1,3,4,5,6]),this.tcModel&&t.lastUpdated>=this.tcModel.lastUpdated?(s=this.getTcfData(),k.saveTCFData(S(S({},s),{tcString:e})),[4,this.saveTCFData(s)]):[3,2];case 1:return n.sent(),[2,!0];case 2:return[2,!1]}})})},t.prototype.isPolicyVersion2=function(){return 2===this.policyVersion},t.prototype.saveTCFData=function(e){return b(this,void 0,void 0,function(){return V(this,function(t){return[2,$.getInstance().saveTCFConsents(this.dataTransferSettings,e,"onTcfStringChange","explicit",this.isApiV2Enabled?{isAnalyticsEnabled:this.isAnalyticsEnabled,isConsentAPIv2Enabled:this.isConsentXDeviceEnabled}:null,this.enableDeprecatedV1ConsentSaving)]})})},t.prototype.updateTCString=function(e){return b(this,void 0,void 0,function(){var t;return V(this,function(s){switch(s.label){case 0:return this.tcModel&&(this.isPolicyVersion2()||this.tcModel.purposeLegitimateInterests.unset([1,3,4,5,6]),this.tcModel.consentScreen=e,this.tcModel.updated()),t=this.getTcfData(),k.saveTCFData(t),[4,this.cmpApiUpdate(t.tcString,!1,t.acString)];case 1:return s.sent(),this.resetTcfData(),this.botInstance.isRobot()?[3,3]:[4,this.saveTCFData(t)];case 2:s.sent(),s.label=3;case 3:return[2]}})})},t.prototype.getVendorsCount=function(){return(this.getVendors().length||0)+this.getAcmVendorsCount()},t.prototype.getAcmVendors=function(){return this.acmData.vendors||[]},t.prototype.getAcmVendorsCount=function(){return this.getAcmVendors().length||0},t}(ne);export{Xe as default};