2025-11-30 21:54:10 +00:00
|
|
|
import { cssManager, colors } from './shared.js';
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
import {
|
|
|
|
|
DeesElement,
|
|
|
|
|
customElement,
|
|
|
|
|
html,
|
|
|
|
|
css,
|
|
|
|
|
type TemplateResult,
|
|
|
|
|
property,
|
|
|
|
|
} from '@design.estate/dees-element';
|
2025-01-09 00:43:01 +01:00
|
|
|
|
|
|
|
|
import * as csInterfaces from '@consent.software/interfaces';
|
|
|
|
|
import * as csWebclient from '@consent.software/webclient';
|
|
|
|
|
import { delayFor } from '@push.rocks/smartdelay';
|
|
|
|
|
|
2025-01-17 06:45:06 +01:00
|
|
|
declare global {
|
|
|
|
|
interface HTMLElementTagNameMap {
|
|
|
|
|
'consentsoftware-cookieconsent': ConsentsoftwareCookieconsent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-09 00:43:01 +01:00
|
|
|
@customElement('consentsoftware-cookieconsent')
|
2025-11-30 21:54:10 +00:00
|
|
|
export class ConsentsoftwareCookieconsent extends DeesElement {
|
2025-01-09 00:43:01 +01:00
|
|
|
public static demo = () => html`<consentsoftware-cookieconsent></consentsoftware-cookieconsent>`;
|
|
|
|
|
|
|
|
|
|
public csWebclientInstance = new csWebclient.CsWebclient();
|
|
|
|
|
public csWebclientRan = false;
|
|
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
public static styles = [
|
|
|
|
|
cssManager.defaultStyles,
|
|
|
|
|
css`
|
|
|
|
|
:host {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
user-select: none;
|
|
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.pageOverlay {
|
|
|
|
|
position: fixed;
|
|
|
|
|
inset: 0;
|
|
|
|
|
display: grid;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
z-index: 1000;
|
|
|
|
|
background: rgba(0, 0, 0, 0);
|
|
|
|
|
backdrop-filter: blur(0px);
|
|
|
|
|
transition: all 0.2s ease-out;
|
|
|
|
|
}
|
2025-01-20 17:59:50 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.pageOverlay.shake {
|
|
|
|
|
background: rgba(0, 0, 0, 0.6) !important;
|
|
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-01-22 07:34:06 +01:00
|
|
|
.modalBox {
|
2025-11-30 21:54:10 +00:00
|
|
|
display: block;
|
|
|
|
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
|
|
|
|
background: ${cssManager.bdTheme(colors.light.background, colors.dark.background)};
|
|
|
|
|
box-shadow:
|
|
|
|
|
0 0 0 1px ${cssManager.bdTheme(colors.light.border, colors.dark.border)},
|
|
|
|
|
0 16px 70px ${cssManager.bdTheme('rgba(0, 0, 0, 0.15)', 'rgba(0, 0, 0, 0.35)')};
|
|
|
|
|
position: relative;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
max-width: 520px;
|
|
|
|
|
min-width: 320px;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
will-change: transform;
|
|
|
|
|
transition: all 0.2s ease-out;
|
|
|
|
|
transform: scale(0.96);
|
|
|
|
|
opacity: 0;
|
2025-01-22 07:34:06 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
@media (max-width: 560px) {
|
|
|
|
|
.modalBox {
|
|
|
|
|
max-width: 100%;
|
|
|
|
|
min-width: 100%;
|
|
|
|
|
height: 100vh;
|
|
|
|
|
border-radius: 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-20 17:59:50 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.modalBox.shake {
|
|
|
|
|
animation: shake 120ms 2 linear;
|
|
|
|
|
}
|
2025-01-20 17:59:50 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
@keyframes shake {
|
|
|
|
|
0% { transform: translateX(3px); }
|
|
|
|
|
50% { transform: translateX(-3px); }
|
|
|
|
|
100% { transform: translateX(0); }
|
|
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
:host([show='false']) { display: none; }
|
|
|
|
|
:host([show='true']) { display: block; }
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.content {
|
|
|
|
|
margin: auto;
|
|
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.text-container {
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
line-height: 1.5;
|
|
|
|
|
color: ${cssManager.bdTheme(colors.light.mutedForeground, colors.dark.mutedForeground)};
|
|
|
|
|
}
|
2025-11-30 21:43:36 +00:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.text-container a {
|
|
|
|
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
|
|
|
|
text-decoration: underline;
|
|
|
|
|
text-underline-offset: 2px;
|
|
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.text-container a:hover {
|
|
|
|
|
opacity: 0.8;
|
|
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-01-22 07:34:06 +01:00
|
|
|
.button-container {
|
2025-11-30 21:54:10 +00:00
|
|
|
padding: 12px 16px 16px;
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(3, 1fr);
|
|
|
|
|
gap: 8px;
|
2025-01-22 07:34:06 +01:00
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
@media (max-width: 560px) {
|
|
|
|
|
.button-container {
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.consent-button {
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
background: ${cssManager.bdTheme(colors.light.secondary, colors.dark.secondary)};
|
|
|
|
|
border: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
|
|
|
|
padding: 8px 16px;
|
|
|
|
|
font-size: 0.85em;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
text-align: center;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transition: all 0.15s ease;
|
|
|
|
|
color: ${cssManager.bdTheme(colors.light.secondaryForeground, colors.dark.secondaryForeground)};
|
|
|
|
|
}
|
2025-11-30 21:43:36 +00:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.consent-button:hover {
|
|
|
|
|
background: ${cssManager.bdTheme(colors.light.accent, colors.dark.accent)};
|
|
|
|
|
border-color: ${cssManager.bdTheme(colors.light.ring, colors.dark.ring)};
|
|
|
|
|
}
|
2025-11-30 21:43:36 +00:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.consent-button:last-child {
|
|
|
|
|
background: ${cssManager.bdTheme(colors.light.primary, colors.dark.primary)};
|
|
|
|
|
color: ${cssManager.bdTheme(colors.light.primaryForeground, colors.dark.primaryForeground)};
|
|
|
|
|
border-color: ${cssManager.bdTheme(colors.light.primary, colors.dark.primary)};
|
|
|
|
|
}
|
2025-01-22 07:34:06 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.consent-button:last-child:hover {
|
|
|
|
|
opacity: 0.9;
|
|
|
|
|
}
|
2025-01-22 07:34:06 +01:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.info-container {
|
|
|
|
|
text-align: center;
|
|
|
|
|
padding: 10px 16px;
|
|
|
|
|
background: ${cssManager.bdTheme(colors.light.muted, colors.dark.muted)};
|
|
|
|
|
border-top: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
|
|
|
|
font-size: 0.75em;
|
|
|
|
|
color: ${cssManager.bdTheme(colors.light.mutedForeground, colors.dark.mutedForeground)};
|
|
|
|
|
}
|
2025-11-30 21:43:36 +00:00
|
|
|
|
2025-11-30 21:54:10 +00:00
|
|
|
.info-container a {
|
|
|
|
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.info-container a:hover {
|
|
|
|
|
text-decoration: underline;
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
];
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-01-09 00:43:01 +01:00
|
|
|
constructor() {
|
|
|
|
|
super();
|
2025-01-22 07:34:06 +01:00
|
|
|
// Initially hide the consent banner until needed
|
2025-01-13 22:20:19 +01:00
|
|
|
this.setAttribute('show', 'false');
|
2025-01-09 00:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public render(): TemplateResult {
|
|
|
|
|
return html`
|
2025-01-20 17:59:50 +01:00
|
|
|
<div class="pageOverlay" @click=${this.pageOverlayClick}>
|
2025-01-13 22:20:19 +01:00
|
|
|
<div class="modalBox">
|
|
|
|
|
<div class="content">
|
|
|
|
|
<consentsoftware-header></consentsoftware-header>
|
|
|
|
|
<consentsoftware-tabs></consentsoftware-tabs>
|
2025-11-30 21:43:36 +00:00
|
|
|
<div class="text-container">
|
2025-01-13 22:20:19 +01:00
|
|
|
<div class="toptext">
|
2025-11-30 21:43:36 +00:00
|
|
|
We use cookies to enhance your experience. Review our
|
2025-01-13 22:20:19 +01:00
|
|
|
<a href="https://lossless.gmbh/cookie" target="_blank">cookie policy</a>
|
2025-11-30 21:43:36 +00:00
|
|
|
and select your preferences.
|
2025-01-13 22:20:19 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<consentsoftware-mainselection></consentsoftware-mainselection>
|
|
|
|
|
<div class="button-container">
|
|
|
|
|
<div
|
|
|
|
|
class="consent-button"
|
2025-01-17 19:21:20 +01:00
|
|
|
@click=${(event: MouseEvent) =>
|
|
|
|
|
this.handleConsentButtonClick(event, ['functional'])}
|
2025-01-13 22:20:19 +01:00
|
|
|
>
|
|
|
|
|
Deny
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
class="consent-button"
|
2025-01-17 19:21:20 +01:00
|
|
|
@click=${(event: MouseEvent) =>
|
|
|
|
|
this.handleConsentButtonClick(event, ['functional', 'analytics'])}
|
2025-01-13 22:20:19 +01:00
|
|
|
>
|
|
|
|
|
Accept selection
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
class="consent-button"
|
|
|
|
|
@click=${(event: MouseEvent) =>
|
2025-01-17 19:21:20 +01:00
|
|
|
this.handleConsentButtonClick(event, ['functional', 'analytics', 'marketing'])}
|
2025-01-13 22:20:19 +01:00
|
|
|
>
|
|
|
|
|
Accept all cookies
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="info-container">
|
|
|
|
|
consent management powered by
|
|
|
|
|
<a href="https://consent.software">consent.software</a>
|
|
|
|
|
</div>
|
2025-01-09 00:43:01 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 22:20:19 +01:00
|
|
|
/**
|
2025-01-22 07:34:06 +01:00
|
|
|
* Lifecycle method called when the element is connected to the DOM.
|
2025-11-30 21:54:10 +00:00
|
|
|
* Displays the consent banner if no cookie levels are set.
|
2025-01-13 22:20:19 +01:00
|
|
|
*/
|
2025-01-09 00:43:01 +01:00
|
|
|
public async connectedCallback() {
|
2025-11-30 21:54:10 +00:00
|
|
|
await super.connectedCallback();
|
2025-01-13 22:20:19 +01:00
|
|
|
|
2025-01-09 00:43:01 +01:00
|
|
|
const cookieLevel = await this.csWebclientInstance.getCookieLevels();
|
2025-01-13 22:20:19 +01:00
|
|
|
if (!cookieLevel) {
|
2025-01-22 07:34:06 +01:00
|
|
|
// Show consent banner if cookie levels haven't been set yet
|
2025-01-14 03:08:00 +01:00
|
|
|
this.setAttribute('show', 'true');
|
|
|
|
|
requestAnimationFrame(async () => {
|
2025-11-30 21:54:10 +00:00
|
|
|
await this.updateComplete;
|
2025-01-14 03:08:00 +01:00
|
|
|
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
|
|
|
|
|
if (pageOverlay) {
|
2025-11-30 21:43:36 +00:00
|
|
|
// Apply subtle backdrop blur when modal appears
|
|
|
|
|
pageOverlay.style.background = 'rgba(0,0,0, 0.6)';
|
|
|
|
|
pageOverlay.style.backdropFilter = 'blur(4px)';
|
2025-01-14 03:08:00 +01:00
|
|
|
}
|
|
|
|
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
|
|
|
|
if (modalBox) {
|
2025-01-22 07:34:06 +01:00
|
|
|
// Animate modal box appearance
|
2025-01-14 03:08:00 +01:00
|
|
|
modalBox.style.transform = `scale(1)`;
|
|
|
|
|
modalBox.style.opacity = '1';
|
|
|
|
|
}
|
2025-01-09 00:43:01 +01:00
|
|
|
});
|
|
|
|
|
} else {
|
2025-01-22 07:34:06 +01:00
|
|
|
// Hide banner if cookie levels are already set
|
2025-01-09 00:43:01 +01:00
|
|
|
this.setAttribute('show', 'false');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 07:34:06 +01:00
|
|
|
public async firstUpdated() {
|
2025-11-30 21:54:10 +00:00
|
|
|
// Run consent scripts if levels are already set
|
2025-01-09 00:43:01 +01:00
|
|
|
const acceptedCookieLevels = await this.csWebclientInstance.getCookieLevels();
|
|
|
|
|
if (!this.csWebclientRan && acceptedCookieLevels) {
|
|
|
|
|
this.csWebclientRan = true;
|
|
|
|
|
await this.csWebclientInstance.getAndRunConsentTuples();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 22:20:19 +01:00
|
|
|
/**
|
2025-01-22 07:34:06 +01:00
|
|
|
* Handles consent button clicks, sets cookie levels, and hides the banner.
|
2025-01-13 22:20:19 +01:00
|
|
|
*/
|
2025-01-17 19:21:20 +01:00
|
|
|
private async handleConsentButtonClick(
|
|
|
|
|
event: MouseEvent,
|
|
|
|
|
levelsArg: csInterfaces.TCookieLevel[]
|
|
|
|
|
) {
|
2025-01-09 00:43:01 +01:00
|
|
|
console.log(`Set level to ${levelsArg}`);
|
2025-01-17 19:21:20 +01:00
|
|
|
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
|
|
|
|
|
if (pageOverlay) {
|
2025-11-30 21:43:36 +00:00
|
|
|
pageOverlay.style.background = 'rgba(0,0,0, 0)';
|
2025-01-17 19:21:20 +01:00
|
|
|
pageOverlay.style.backdropFilter = 'blur(0px)';
|
|
|
|
|
}
|
|
|
|
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
|
|
|
|
if (modalBox) {
|
2025-01-22 07:34:06 +01:00
|
|
|
// Scale down and fade out modal box before hiding
|
2025-01-17 19:21:20 +01:00
|
|
|
modalBox.style.transform = `scale(0.95)`;
|
|
|
|
|
modalBox.style.opacity = '0';
|
|
|
|
|
}
|
2025-01-22 07:34:06 +01:00
|
|
|
// Save user consent preferences
|
2025-01-09 00:43:01 +01:00
|
|
|
await this.csWebclientInstance.setCookieLevels(levelsArg);
|
|
|
|
|
await delayFor(300);
|
2025-01-22 07:34:06 +01:00
|
|
|
this.setAttribute('show', 'false'); // Hide the consent banner
|
2025-11-30 21:54:10 +00:00
|
|
|
|
|
|
|
|
// Run consent scripts
|
|
|
|
|
if (!this.csWebclientRan) {
|
|
|
|
|
this.csWebclientRan = true;
|
|
|
|
|
await this.csWebclientInstance.getAndRunConsentTuples();
|
|
|
|
|
}
|
2025-01-09 00:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-22 07:34:06 +01:00
|
|
|
/**
|
|
|
|
|
* Handles clicks on the page overlay. If clicked outside the modal,
|
|
|
|
|
* triggers a shake animation as feedback.
|
|
|
|
|
*/
|
2025-01-20 17:59:50 +01:00
|
|
|
private async pageOverlayClick(e: MouseEvent) {
|
|
|
|
|
if (e.target === e.currentTarget) {
|
|
|
|
|
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
|
|
|
|
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
|
|
|
|
if (pageOverlay && modalBox) {
|
|
|
|
|
pageOverlay.classList.add('shake');
|
|
|
|
|
modalBox.classList.add('shake');
|
2025-01-20 18:04:47 +01:00
|
|
|
await delayFor(2000);
|
2025-01-20 17:59:50 +01:00
|
|
|
pageOverlay.classList.remove('shake');
|
|
|
|
|
modalBox.classList.remove('shake');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-09 00:43:01 +01:00
|
|
|
}
|