@nent/core
Version:
4 lines • 2.71 kB
JavaScript
/*!
* NENT 2022
*/
import{r as t,d as s,h as i,H as n,a as e}from"./index-916ca544.js";import{a,e as r}from"./index-f7016b94.js";import{a as o,r as c}from"./factory-acbf0d3d.js";import{D as h}from"./interfaces-4b724211.js";import{D as u}from"./interfaces-8c5cd1b8.js";import"./index-4bfabbbd.js";import"./values-ddfac998.js";import"./promises-584c4ece.js";import"./logging-5a93c8af.js";function d(t,s){if(!s)return"";const i=`; ${t}`;return!0===s?i:`${i}=${s}`}function f(t){return t.replace(/%3B/g,";")}function l(t){return t.replace(/;/g,"%3B")}class m{constructor(t,s,i){this.document=t,this.eventBus=s,this.name=i}async get(t){return function(t,s){return function(t){return function(t){const s={},i=t?t.split("; "):[];for(const t of i){const i=t.split("="),n=i.slice(1).join("=");s[f(i[0]).replace(/%3D/g,"=")]=f(n)}return s}(t.cookie)}(t)[s]}(this.document,t)||null}async set(t,s){await this.get(t)!=s&&(function(t,s,i){t.cookie=function(t,s,i){return`${l(t).replace(/=/g,"%3D")}=${l(s)}${function(t){if("number"==typeof t.expires){const s=new Date;s.setMilliseconds(s.getMilliseconds()+864e5*t.expires),t.expires=s}return d("Expires",t.expires?t.expires.toUTCString():"")+d("Domain",t.domain)+d("Path",t.path)+d("Secure",t.secure)+d("SameSite",t.sameSite)}(i)}`}(s,i,Object.assign({path:"/"},{sameSite:"strict"}))}(this.document,t,s),this.eventBus.emit(u.DataChanged,{provider:this.name}))}}const p=class{constructor(i){t(this,i),this.didConsent=s(this,"didConsent",6),this.consentKey="consent",this.hide=!1,this.skipConsent=!1,this.name="cookie"}async registerProvider(){o(this.name,this.provider),this.actionSubscription=a.on(this.name,(async t=>{if(t.command==h.SetData){const{data:s}=t;await Promise.all(Object.keys(t.data).map((t=>this.provider.set(t,s[t]))))}})),await this.provider.set(this.consentKey,(!0).toString()),this.didConsent.emit({consented:!0}),this.hide=!0}async componentWillLoad(){if(this.provider=new m(this.el.ownerDocument,r,this.name),this.skipConsent)return this.registerProvider(),void(this.hide=!0);const t=await this.provider.get(this.consentKey);null!=t&&(this.hide=!0,"true"==t&&this.registerProvider())}async handleConsentResponse(t,s){t.preventDefault(),s?await this.registerProvider():this.hide=!0}disconnectedCallback(){var t;c(this.name),null===(t=this.actionSubscription)||void 0===t||t.call(this)}render(){return i(n,{hidden:this.hide},i("slot",null),i("a",{id:"accept",onClick:async t=>await this.handleConsentResponse(t,!0)},i("slot",{name:"accept"},"Accept")),i("a",{id:"reject",onClick:async t=>await this.handleConsentResponse(t,!1)},i("slot",{name:"reject"},"Reject")))}get el(){return e(this)}};p.style=":host {display:block;}";export{p as n_data_cookie}