@usercentrics/cmp-browser-sdk
Version:
Usercentrics CMP Browser SDK
2 lines (1 loc) • 3.58 kB
JavaScript
import{S as e,C as t,a,D as i,F as s,b as n,W as o,c as r,A as c,_ as l,d as u,G as p,e as d,f as C,g,h as v,i as A,L as f}from"./index-a467e104.js";import m from"./DefaultData-b709c3f8.js";var O=function(t){return!(!t||!t.length||t[2]!==e.ACCEPT)},w=function(e){var t=e&&e.data&&e.data.__uspapiCall;t&&window[o](t.command,t.version,function(a,i){!e.source||e.source instanceof MessagePort||e.source instanceof ServiceWorker||e.source.postMessage({__uspapiReturn:{callId:t.callId,returnValue:a,success:i}},"*")})},P=function(){function P(a,l,u,d){var C,m,S,h,D,N,k,E,x;(g(this,P),k=v(this,P,[l,u]),A(k,"iabAgreementExists",void 0),A(k,"isActive",void 0),A(k,"isExplicitConsented",void 0),A(k,"isOptedOut",void 0),A(k,"explicitDeny",!1),A(k,"explicitNotice",void 0),A(k,"region",void 0),A(k,"reshowAfterDays",void 0),A(k,"showOnPageLoad",void 0),A(k,"framework",void 0),A(k,"legalFramework",void 0),k.iabAgreementExists=(null===(C=a.ccpa)||void 0===C?void 0:C.iabAgreementExists)||!1,k.isActive=a.framework?["CCPA","UCPA","CTDPA","VCDPA","CPRA","CPA","MSPL"].includes(a.framework):null!==(m=null===(S=a.ccpa)||void 0===S?void 0:S.isActive)&&void 0!==m&&m,k.region=(null===(h=a.ccpa)||void 0===h?void 0:h.region)||f.US_CA_ONLY,k.reshowAfterDays=(null===(D=a.ccpa)||void 0===D?void 0:D.reshowAfterDays)||365,k.showOnPageLoad=(null===(N=a.ccpa)||void 0===N?void 0:N.showOnPageLoad)||!1,k.isOptedOut=!!navigator.globalPrivacyControl,k.isExplicitConsented=d,k.framework=a.framework||"ccpa",k.legalFramework=k.getLegalFramework(k.framework),n.getCcpaString()!==i)?(k.explicitNotice=!(!(x=n.getCcpaString())||!x.length||x[1]!==e.ACCEPT),!d&&k.isOptedOut?(k.explicitDeny=!0,k.setCcpaStorage(k.isOptedOut,k.explicitNotice?e.ACCEPT:e.UNKNOWN)):(k.isOptedOut=O(n.getCcpaString()),null===(E=p.getInstance())||void 0===E||E.setSectionString(n.getCcpaString(),k.legalFramework))):(k.setCcpaStorage(k.isOptedOut,e.UNKNOWN),k.explicitNotice=!1);return function(){if(!Object.prototype.hasOwnProperty.call(window.frames,s)){var e=document.createElement("iframe");e.style.display="none",e.name=s,document.body.appendChild(e)}}(),window[o]=function(e,a,i){switch("function"!=typeof i&&console.warn(r.API_INVALID_CALLBACK),a!==t&&i({uspString:null,version:null},!1),e){case c.GET_USP_DATA:i({uspString:n.getCcpaString(),version:t},!0);break;case o:i(null,!0);break;default:console.warn(r.API_INVALID_COMMAND,e),i(null,!1)}},window.addEventListener("message",w,!1),k}return l(P,m),u(P,[{key:"getIsOptedOut",value:function(){return this.isOptedOut}},{key:"getLegalFramework",value:function(e){switch(e){case"UCPA":return"usut";case"CTDPA":return"usct";case"VCDPA":return"usva";case"CPRA":return"usca";case"CPA":return"usco";default:return"uspv1"}}},{key:"getExplicitNotice",value:function(){return this.explicitNotice}},{key:"setCcpaStorage",value:function(s){var o,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.ACCEPT;this.setIsOptedOut(s),s?n.setCcpaTimeStamp():n.clearCcpaData(),r===e.ACCEPT?this.explicitNotice=!0:this.explicitNotice=!1;var c=function(s,n,o){var r="".concat(t).concat(n).concat(s?e.ACCEPT:e.DENY).concat(o?e.ACCEPT:e.UNKNOWN);return a.test(r)||(r=i),r}(s,r,this.iabAgreementExists);null===(o=p.getInstance())||void 0===o||o.setSectionString(c,this.legalFramework),d.isCrossDomainAvailable()&&d.setCrossDomainCcpaData({ccpaString:c,timestamp:n.getCcpaTimeStamp()}).catch(function(){console.warn(C.CROSS_DOMAIN_SET_DATA_FAILURE)}),n.setCcpaString(c)}},{key:"setIsOptedOut",value:function(e){var t="boolean"==typeof e?e:O(e);this.isOptedOut=t}}])}();export{P as default};