@naturalcycles/internal-web-lib 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/analyticsClient.js +19 -19
- package/bundle/analyticsClient.js.map +1 -1
- package/bundle/cookieMonster.js +863 -0
- package/bundle/cookieMonster.js.map +1 -0
- package/dist/analytics/analyticsClient.js +674 -804
- package/dist/analytics/index.js +2 -1
- package/dist/cookie-monster/components/setting-dropdown/setting-dropdown.component.d.ts +17 -0
- package/dist/cookie-monster/components/setting-dropdown/setting-dropdown.component.js +4 -0
- package/dist/cookie-monster/components/setting-dropdown/setting-dropdown2.component.js +129 -0
- package/dist/cookie-monster/components/themed-button/themed-button.component.d.ts +7 -0
- package/dist/cookie-monster/components/themed-button/themed-button.component.js +4 -0
- package/dist/cookie-monster/components/themed-button/themed-button2.component.js +30 -0
- package/dist/cookie-monster/consent/consent.service.d.ts +24 -0
- package/dist/cookie-monster/consent/consent.service.js +68 -0
- package/dist/cookie-monster/consent/consentLogStorage.service.d.ts +9 -0
- package/dist/cookie-monster/consent/consentLogStorage.service.js +38 -0
- package/dist/cookie-monster/const/cookieMonster.const.d.ts +4 -0
- package/dist/cookie-monster/const/cookieMonster.const.js +11 -0
- package/dist/cookie-monster/cookie-monster-element.d.ts +33 -0
- package/dist/cookie-monster/cookie-monster-element.js +121 -0
- package/dist/cookie-monster/cookieMonsterService.d.ts +19 -0
- package/dist/cookie-monster/cookieMonsterService.js +59 -0
- package/dist/cookie-monster/css/fonts.js +4 -0
- package/dist/cookie-monster/css/general.js +4 -0
- package/dist/cookie-monster/css/shared-sheets.d.ts +4 -0
- package/dist/cookie-monster/css/shared-sheets.js +14 -0
- package/dist/cookie-monster/icons/back.js +4 -0
- package/dist/cookie-monster/icons/chevron.js +4 -0
- package/dist/cookie-monster/index.d.ts +2 -0
- package/dist/cookie-monster/index.js +3 -0
- package/dist/cookie-monster/lang/da-DK.js +22 -0
- package/dist/cookie-monster/lang/de-DE.js +22 -0
- package/dist/cookie-monster/lang/en-GB.js +22 -0
- package/dist/cookie-monster/lang/en-US.js +22 -0
- package/dist/cookie-monster/lang/es-US.js +22 -0
- package/dist/cookie-monster/lang/fi-FI.js +22 -0
- package/dist/cookie-monster/lang/fr-FR.js +22 -0
- package/dist/cookie-monster/lang/it-IT.js +22 -0
- package/dist/cookie-monster/lang/no-NO.js +22 -0
- package/dist/cookie-monster/lang/pt-BR.js +22 -0
- package/dist/cookie-monster/lang/sv-SE.js +22 -0
- package/dist/cookie-monster/types/CookieMonster.types.d.ts +56 -0
- package/dist/cookie-monster/types/CookieMonster.types.js +34 -0
- package/dist/cookie-monster/utils/createButton.d.ts +1 -0
- package/dist/cookie-monster/utils/createButton.js +11 -0
- package/dist/cookie-monster/utils/getCookieMonsterEvent.d.ts +2 -0
- package/dist/cookie-monster/utils/getCookieMonsterEvent.js +10 -0
- package/dist/cookie-monster/utils/handleRootClick.d.ts +1 -0
- package/dist/cookie-monster/utils/handleRootClick.js +16 -0
- package/dist/cookie-monster/utils/linkify.d.ts +1 -0
- package/dist/cookie-monster/utils/linkify.js +9 -0
- package/dist/cookie-monster/utils/translationsService.d.ts +7 -0
- package/dist/cookie-monster/utils/translationsService.js +56 -0
- package/dist/cookie-monster/views/main.view.d.ts +24 -0
- package/dist/cookie-monster/views/main.view.js +115 -0
- package/dist/cookie-monster/views/settings.view.d.ts +18 -0
- package/dist/cookie-monster/views/settings.view.js +96 -0
- package/dist/cookie-monster/views/views.js +4 -0
- package/dist/index.js +2 -1
- package/dist/node_modules/.pnpm/@naturalcycles_ncuikit@1.14.0_react@19.3.0_undici@8.11.2/node_modules/@naturalcycles/ncuikit/dist/styles/_palette.js +4 -0
- package/package.json +15 -5
package/dist/analytics/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { AnalyticsClient, AnalyticsClientError, AnalyticsIdentity, getCookie, setCookie } from "./analyticsClient.js";
|
|
2
|
+
export { AnalyticsClient, AnalyticsClientError, AnalyticsIdentity, getCookie, setCookie };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class SettingDropdown extends HTMLElement {
|
|
2
|
+
private readonly root;
|
|
3
|
+
private readonly dropdown;
|
|
4
|
+
private readonly button;
|
|
5
|
+
private readonly content;
|
|
6
|
+
private readonly checkbox;
|
|
7
|
+
private readonly span;
|
|
8
|
+
private readonly icon;
|
|
9
|
+
private uid;
|
|
10
|
+
constructor();
|
|
11
|
+
connectedCallback(): void;
|
|
12
|
+
static get observedAttributes(): string[];
|
|
13
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
|
|
14
|
+
toggleDropdown(): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
isChecked(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/cookie-monster/components/setting-dropdown/setting-dropdown.component.css?inline
|
|
2
|
+
var setting_dropdown_component_default = ".CookieMonster__dropdown {\n padding: 16px 0;\n display: grid;\n grid-template-columns: max-content 1fr;\n align-items: center;\n border-bottom: 1px solid var(--color-ink-300);\n}\n\n:host(:last-of-type) .CookieMonster__dropdown {\n border-bottom: none;\n}\n\n.CookieMonster__icon {\n width: 24px;\n height: 24px;\n margin-right: 4px;\n}\n\n.CookieMonster__icon___expanded {\n transform: rotate(180deg);\n}\n\n.CookieMonster__dropdownHeading {\n color: var(--color-ink-1000);\n font-size: 16px;\n font-weight: 800;\n align-self: center;\n}\n\n.CookieMonster__dropdownContent {\n font-size: 14px;\n padding-top: 16px;\n grid-column: 1 / span 2;\n color: var(--color-ink-600);\n overflow-y: auto;\n}\n\n.CookieMonster__dropdownButton {\n background-color: transparent;\n border: none;\n display: flex;\n\n cursor: pointer;\n}\n\n.CookieMonster__dropdownLabel {\n font-size: 14px;\n color: var(--color-ink-600);\n justify-self: end;\n}\n\ninput[type='checkbox'] {\n appearance: none;\n -webkit-appearance: none;\n position: relative;\n width: 18px;\n height: 18px;\n justify-self: end;\n border: 2px solid var(--color-purple-500);\n border-radius: 2px;\n cursor: pointer;\n}\n\ninput[type='checkbox']:checked::after {\n content: '✓';\n position: absolute;\n color: white;\n font-size: 14px;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}\n\ninput[type='checkbox']:checked:not(:disabled) {\n background-color: var(--color-purple-500);\n border-color: var(--color-purple-500);\n}\n\ninput[type='checkbox']:checked:disabled {\n background-color: var(--color-ink-400);\n border-color: var(--color-ink-400);\n}\n\n.CookieMonster__alwaysOnGroup {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 8px;\n}\n\n::slotted(a) {\n color: var(--color-neue-blue-500);\n}\n";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { setting_dropdown_component_default as default };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createStyles, fontSheet, generalSheet, paletteSheet } from "../../css/shared-sheets.js";
|
|
2
|
+
import chevron_default from "../../icons/chevron.js";
|
|
3
|
+
import { CookieMonsterDropdownDetail } from "../../types/CookieMonster.types.js";
|
|
4
|
+
import { tr } from "../../utils/translationsService.js";
|
|
5
|
+
import setting_dropdown_component_default from "./setting-dropdown.component.js";
|
|
6
|
+
//#region src/cookie-monster/components/setting-dropdown/setting-dropdown.component.ts
|
|
7
|
+
var dropdownStyleSheet = createStyles(setting_dropdown_component_default);
|
|
8
|
+
var SettingDropdown = class extends HTMLElement {
|
|
9
|
+
root;
|
|
10
|
+
dropdown;
|
|
11
|
+
button;
|
|
12
|
+
content;
|
|
13
|
+
checkbox;
|
|
14
|
+
span;
|
|
15
|
+
icon;
|
|
16
|
+
uid = "";
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.root = this.attachShadow({ mode: "open" });
|
|
20
|
+
this.root.adoptedStyleSheets = [
|
|
21
|
+
paletteSheet,
|
|
22
|
+
generalSheet,
|
|
23
|
+
fontSheet,
|
|
24
|
+
dropdownStyleSheet
|
|
25
|
+
];
|
|
26
|
+
this.dropdown = document.createElement("div");
|
|
27
|
+
this.dropdown.classList.add("CookieMonster__dropdown");
|
|
28
|
+
const button = document.createElement("button");
|
|
29
|
+
button.setAttribute("uid", `cm-dropdown-btn-${this.uid}`);
|
|
30
|
+
button.classList.add("CookieMonster__dropdownButton");
|
|
31
|
+
button.setAttribute("aria-expanded", "false");
|
|
32
|
+
button.setAttribute("aria-controls", "content");
|
|
33
|
+
button.type = "button";
|
|
34
|
+
this.button = button;
|
|
35
|
+
const icon = document.createElement("img");
|
|
36
|
+
icon.src = chevron_default;
|
|
37
|
+
icon.alt = "";
|
|
38
|
+
icon.setAttribute("aria-hidden", "true");
|
|
39
|
+
icon.classList.add("CookieMonster__icon");
|
|
40
|
+
this.icon = icon;
|
|
41
|
+
const span = document.createElement("span");
|
|
42
|
+
span.id = "heading";
|
|
43
|
+
span.classList.add("CookieMonster__dropdownHeading");
|
|
44
|
+
this.span = span;
|
|
45
|
+
const checkbox = document.createElement("input");
|
|
46
|
+
checkbox.type = "checkbox";
|
|
47
|
+
this.checkbox = checkbox;
|
|
48
|
+
const content = document.createElement("div");
|
|
49
|
+
content.setAttribute("uid", `cm-dropdown-content-${this.uid}`);
|
|
50
|
+
content.id = "content";
|
|
51
|
+
content.classList.add("CookieMonster__dropdownContent");
|
|
52
|
+
content.setAttribute("role", "region");
|
|
53
|
+
content.setAttribute("aria-labelledby", "heading");
|
|
54
|
+
content.hidden = true;
|
|
55
|
+
content.innerHTML = `<slot></slot>`;
|
|
56
|
+
this.content = content;
|
|
57
|
+
button.append(icon, span);
|
|
58
|
+
this.dropdown.append(button, checkbox, content);
|
|
59
|
+
this.root.append(this.dropdown);
|
|
60
|
+
}
|
|
61
|
+
connectedCallback() {
|
|
62
|
+
this.button.addEventListener("click", () => {
|
|
63
|
+
this.toggleDropdown();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
static get observedAttributes() {
|
|
67
|
+
return [
|
|
68
|
+
"title",
|
|
69
|
+
"always-on",
|
|
70
|
+
"uid"
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
74
|
+
if (name === "uid") {
|
|
75
|
+
this.uid = newValue || "";
|
|
76
|
+
this.button.setAttribute("uid", `cm-dropdown-btn-${this.uid}`);
|
|
77
|
+
this.content.setAttribute("uid", `cm-dropdown-content-${this.uid}`);
|
|
78
|
+
this.dropdown.setAttribute("uid", `cm-dropdown-${this.uid}`);
|
|
79
|
+
this.checkbox.setAttribute("uid", `cm-dropdown-checkbox-${this.uid}`);
|
|
80
|
+
}
|
|
81
|
+
if (name === "title") {
|
|
82
|
+
const title = newValue || "";
|
|
83
|
+
this.span.textContent = title;
|
|
84
|
+
this.checkbox.setAttribute("name", title);
|
|
85
|
+
this.checkbox.setAttribute("aria-labelledby", "heading");
|
|
86
|
+
}
|
|
87
|
+
if (name === "always-on" && newValue !== null) {
|
|
88
|
+
this.checkbox.checked = true;
|
|
89
|
+
this.checkbox.disabled = true;
|
|
90
|
+
const alwaysOnLabel = document.createElement("p");
|
|
91
|
+
alwaysOnLabel.textContent = tr("dropdown-always-on-warning");
|
|
92
|
+
alwaysOnLabel.classList.add("CookieMonster__dropdownLabel");
|
|
93
|
+
const alwaysOnGroup = document.createElement("div");
|
|
94
|
+
alwaysOnGroup.classList.add("CookieMonster__alwaysOnGroup");
|
|
95
|
+
this.checkbox.replaceWith(alwaysOnGroup);
|
|
96
|
+
alwaysOnGroup.append(alwaysOnLabel, this.checkbox);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
toggleDropdown() {
|
|
100
|
+
this.content.hidden = !this.content.hidden;
|
|
101
|
+
const isExpanded = !this.content.hidden;
|
|
102
|
+
this.button.setAttribute("aria-expanded", isExpanded.toString());
|
|
103
|
+
this.icon.classList.toggle("CookieMonster__icon___expanded", isExpanded);
|
|
104
|
+
if (isExpanded) {
|
|
105
|
+
this.dispatchEvent(new CustomEvent(CookieMonsterDropdownDetail.DropdownOpen, {
|
|
106
|
+
bubbles: true,
|
|
107
|
+
composed: true
|
|
108
|
+
}));
|
|
109
|
+
requestAnimationFrame(() => {
|
|
110
|
+
this.content.scrollIntoView({
|
|
111
|
+
behavior: "smooth",
|
|
112
|
+
block: "nearest"
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
close() {
|
|
118
|
+
if (!this.content.hidden) {
|
|
119
|
+
this.content.hidden = true;
|
|
120
|
+
this.button.setAttribute("aria-expanded", "false");
|
|
121
|
+
this.icon.classList.remove("CookieMonster__icon___expanded");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
isChecked() {
|
|
125
|
+
return this.checkbox.checked;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { SettingDropdown };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/cookie-monster/components/themed-button/themed-button.component.css?inline
|
|
2
|
+
var themed_button_component_default = ".CookieMonster__button {\n font-size: 14px;\n font-style: normal;\n line-height: 100%;\n background-color: transparent;\n border: none;\n border-radius: 28px;\n padding: 8px 16px;\n text-align: center;\n white-space: nowrap;\n cursor: pointer;\n width: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 4px;\n}\n\n.CookieMonster__button___primary {\n border: 1px solid var(--color-purple-500);\n background-color: var(--color-purple-500);\n color: var(--color-white-1000);\n}\n\n.CookieMonster__button___secondary {\n border: 1px solid var(--color-purple-500);\n color: var(--color-purple-500);\n}\n";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { themed_button_component_default as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createStyles, fontSheet, generalSheet, paletteSheet } from "../../css/shared-sheets.js";
|
|
2
|
+
import themed_button_component_default from "./themed-button.component.js";
|
|
3
|
+
//#region src/cookie-monster/components/themed-button/themed-button.component.ts
|
|
4
|
+
var buttonStyleSheet = createStyles(themed_button_component_default);
|
|
5
|
+
var ThemedButton = class extends HTMLElement {
|
|
6
|
+
root;
|
|
7
|
+
button;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.root = this.attachShadow({ mode: "open" });
|
|
11
|
+
this.root.adoptedStyleSheets = [
|
|
12
|
+
paletteSheet,
|
|
13
|
+
generalSheet,
|
|
14
|
+
fontSheet,
|
|
15
|
+
buttonStyleSheet
|
|
16
|
+
];
|
|
17
|
+
this.button = document.createElement("button");
|
|
18
|
+
this.button.classList.add("CookieMonster__button");
|
|
19
|
+
this.button.innerHTML = `<slot></slot>`;
|
|
20
|
+
this.root.append(this.button);
|
|
21
|
+
}
|
|
22
|
+
static get observedAttributes() {
|
|
23
|
+
return ["theme"];
|
|
24
|
+
}
|
|
25
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
26
|
+
if (name === "theme") this.button.classList.add(`CookieMonster__button___${newValue}`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ThemedButton };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ConsentLogEntry, CookieMonsterConsent, RegisterCookieMonsterOptions } from '../types/CookieMonster.types.js';
|
|
2
|
+
declare class ConsentService {
|
|
3
|
+
private initialized;
|
|
4
|
+
private domain;
|
|
5
|
+
/**
|
|
6
|
+
* Supplies the CookieMonster package version to tag onto consent log entries. Injected by
|
|
7
|
+
* `cookieMonsterService.register()` rather than imported directly, to avoid a module cycle
|
|
8
|
+
* between this service and `cookieMonsterService.ts` (which depends on this service).
|
|
9
|
+
*/
|
|
10
|
+
private versionProvider;
|
|
11
|
+
setVersionProvider(provider: () => string | undefined): void;
|
|
12
|
+
initConsent(options?: RegisterCookieMonsterOptions): void;
|
|
13
|
+
/** Undoes initConsent(). */
|
|
14
|
+
teardownConsent(): void;
|
|
15
|
+
getConsent(): CookieMonsterConsent | undefined;
|
|
16
|
+
getConsentLog(): ConsentLogEntry[] | undefined;
|
|
17
|
+
/** Whether the visitor's browser is signaling GPC opt-out and no consent has been recorded yet. */
|
|
18
|
+
isGpcActive(): boolean;
|
|
19
|
+
private readonly handleClose;
|
|
20
|
+
private persistConsent;
|
|
21
|
+
private getBannerText;
|
|
22
|
+
}
|
|
23
|
+
export declare const consentService: ConsentService;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CookieMonsterEvent } from "../types/CookieMonster.types.js";
|
|
2
|
+
import { DEFAULT_OPT_OUT_CONSENT } from "../const/cookieMonster.const.js";
|
|
3
|
+
import { CookieMonsterElement } from "../cookie-monster-element.js";
|
|
4
|
+
import { consentLogStorageService } from "./consentLogStorage.service.js";
|
|
5
|
+
import { isServerSide } from "@naturalcycles/js-lib";
|
|
6
|
+
//#region src/cookie-monster/consent/consent.service.ts
|
|
7
|
+
var ConsentService = class {
|
|
8
|
+
initialized = false;
|
|
9
|
+
domain;
|
|
10
|
+
/**
|
|
11
|
+
* Supplies the CookieMonster package version to tag onto consent log entries. Injected by
|
|
12
|
+
* `cookieMonsterService.register()` rather than imported directly, to avoid a module cycle
|
|
13
|
+
* between this service and `cookieMonsterService.ts` (which depends on this service).
|
|
14
|
+
*/
|
|
15
|
+
versionProvider = () => void 0;
|
|
16
|
+
setVersionProvider(provider) {
|
|
17
|
+
this.versionProvider = provider;
|
|
18
|
+
}
|
|
19
|
+
initConsent(options) {
|
|
20
|
+
if (isServerSide() || this.initialized) return;
|
|
21
|
+
this.initialized = true;
|
|
22
|
+
this.domain = options?.domain;
|
|
23
|
+
if (this.isGpcActive()) this.persistConsent({ ...DEFAULT_OPT_OUT_CONSENT }, options?.domain, void 0);
|
|
24
|
+
globalThis.addEventListener(CookieMonsterEvent.cookieMonsterOnClose, this.handleClose);
|
|
25
|
+
if (!consentLogStorageService.readConsentCookie()) CookieMonsterElement.open({ language: options?.language });
|
|
26
|
+
}
|
|
27
|
+
/** Undoes initConsent(). */
|
|
28
|
+
teardownConsent() {
|
|
29
|
+
if (isServerSide()) return;
|
|
30
|
+
globalThis.removeEventListener(CookieMonsterEvent.cookieMonsterOnClose, this.handleClose);
|
|
31
|
+
this.initialized = false;
|
|
32
|
+
this.domain = void 0;
|
|
33
|
+
}
|
|
34
|
+
getConsent() {
|
|
35
|
+
if (isServerSide()) return void 0;
|
|
36
|
+
return consentLogStorageService.readConsentCookie();
|
|
37
|
+
}
|
|
38
|
+
getConsentLog() {
|
|
39
|
+
if (isServerSide()) return void 0;
|
|
40
|
+
const entries = consentLogStorageService.getConsentLogEntries();
|
|
41
|
+
return entries.length ? entries : void 0;
|
|
42
|
+
}
|
|
43
|
+
/** Whether the visitor's browser is signaling GPC opt-out and no consent has been recorded yet. */
|
|
44
|
+
isGpcActive() {
|
|
45
|
+
if (consentLogStorageService.readConsentCookie()) return false;
|
|
46
|
+
return navigator.globalPrivacyControl === true;
|
|
47
|
+
}
|
|
48
|
+
handleClose = (event) => {
|
|
49
|
+
const { consent } = event.detail;
|
|
50
|
+
this.persistConsent(consent, this.domain, this.getBannerText());
|
|
51
|
+
};
|
|
52
|
+
persistConsent(consent, domain, text) {
|
|
53
|
+
consentLogStorageService.writeConsentCookie(consent, domain);
|
|
54
|
+
const entry = {
|
|
55
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56
|
+
consent,
|
|
57
|
+
version: this.versionProvider(),
|
|
58
|
+
text
|
|
59
|
+
};
|
|
60
|
+
consentLogStorageService.addConsentLogEntry(entry);
|
|
61
|
+
}
|
|
62
|
+
getBannerText() {
|
|
63
|
+
return document.querySelector("cookie-monster")?.getBannerText();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var consentService = new ConsentService();
|
|
67
|
+
//#endregion
|
|
68
|
+
export { consentService };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConsentLogEntry, CookieMonsterConsent } from '../types/CookieMonster.types.js';
|
|
2
|
+
declare class ConsentLogStorageService {
|
|
3
|
+
readConsentCookie(): CookieMonsterConsent | undefined;
|
|
4
|
+
writeConsentCookie(consent: CookieMonsterConsent, domain?: string): void;
|
|
5
|
+
getConsentLogEntries(): ConsentLogEntry[];
|
|
6
|
+
addConsentLogEntry(entry: ConsentLogEntry): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const consentLogStorageService: ConsentLogStorageService;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { cookieService } from "@naturalcycles/shared";
|
|
2
|
+
//#region src/cookie-monster/consent/consentLogStorage.service.ts
|
|
3
|
+
var COOKIE_NAME = "CookieConsent";
|
|
4
|
+
var COOKIE_EXPIRATION_DAYS = 365;
|
|
5
|
+
var LOG_STORAGE_KEY = "CookieMonsterConsentLog";
|
|
6
|
+
var ConsentLogStorageService = class {
|
|
7
|
+
readConsentCookie() {
|
|
8
|
+
const raw = cookieService.getCookie(COOKIE_NAME);
|
|
9
|
+
if (!raw) return void 0;
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(raw);
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
writeConsentCookie(consent, domain) {
|
|
17
|
+
if (domain) cookieService.deleteCookie(COOKIE_NAME);
|
|
18
|
+
cookieService.setCookie(COOKIE_NAME, JSON.stringify(consent), COOKIE_EXPIRATION_DAYS, domain);
|
|
19
|
+
}
|
|
20
|
+
getConsentLogEntries() {
|
|
21
|
+
try {
|
|
22
|
+
const raw = localStorage.getItem(LOG_STORAGE_KEY);
|
|
23
|
+
if (!raw) return [];
|
|
24
|
+
return JSON.parse(raw);
|
|
25
|
+
} catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
addConsentLogEntry(entry) {
|
|
30
|
+
const entries = [...this.getConsentLogEntries(), entry].slice(-20);
|
|
31
|
+
try {
|
|
32
|
+
localStorage.setItem(LOG_STORAGE_KEY, JSON.stringify(entries));
|
|
33
|
+
} catch {}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var consentLogStorageService = new ConsentLogStorageService();
|
|
37
|
+
//#endregion
|
|
38
|
+
export { consentLogStorageService };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CookieMonsterEvent } from '../types/CookieMonster.types.js';
|
|
2
|
+
import type { CookieMonsterConsent } from '../types/CookieMonster.types.js';
|
|
3
|
+
export declare const DEMO_PAGE_TRACKING_ALL_EVENTS: CookieMonsterEvent[];
|
|
4
|
+
export declare const DEFAULT_OPT_OUT_CONSENT: CookieMonsterConsent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConsentSource, CookieMonsterEvent } from "../types/CookieMonster.types.js";
|
|
2
|
+
CookieMonsterEvent.cookieMonsterOnMount, CookieMonsterEvent.cookieMonsterOnDisplay, CookieMonsterEvent.cookieMonsterOnClose, CookieMonsterEvent.cookieMonsterOnSettingsViewed, CookieMonsterEvent.cookieMonsterOnBackToBanner;
|
|
3
|
+
var DEFAULT_OPT_OUT_CONSENT = {
|
|
4
|
+
necessary: true,
|
|
5
|
+
preferences: false,
|
|
6
|
+
statistics: false,
|
|
7
|
+
marketing: false,
|
|
8
|
+
source: ConsentSource.gpc
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DEFAULT_OPT_OUT_CONSENT };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import './views/main.view.js';
|
|
2
|
+
import { CookieMonsterView } from './types/CookieMonster.types.js';
|
|
3
|
+
export interface OpenCookieMonsterOptions {
|
|
4
|
+
/** Which view to show. Defaults to whatever view CookieMonster was last in. */
|
|
5
|
+
view?: CookieMonsterView;
|
|
6
|
+
language?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CookieMonsterElement extends HTMLElement {
|
|
9
|
+
private readonly root;
|
|
10
|
+
private readonly container;
|
|
11
|
+
private mainView;
|
|
12
|
+
private isScrollLocked;
|
|
13
|
+
private scrollY;
|
|
14
|
+
/**
|
|
15
|
+
* Creates and appends the element if needed, then shows it. Static so consent.service.ts can
|
|
16
|
+
* also call it without a module cycle through cookieMonsterService.ts.
|
|
17
|
+
*/
|
|
18
|
+
static open(options?: OpenCookieMonsterOptions): void;
|
|
19
|
+
static close(): void;
|
|
20
|
+
private static getOrCreate;
|
|
21
|
+
constructor();
|
|
22
|
+
connectedCallback(): void;
|
|
23
|
+
static get observedAttributes(): string[];
|
|
24
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
25
|
+
disconnectedCallback(): void;
|
|
26
|
+
showBanner(): void;
|
|
27
|
+
showSettings(): void;
|
|
28
|
+
getBannerText(): string | undefined;
|
|
29
|
+
private handleFinalDecision;
|
|
30
|
+
private lockScroll;
|
|
31
|
+
private unlockScroll;
|
|
32
|
+
private replaceMainView;
|
|
33
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createStyles, generalSheet, paletteSheet } from "./css/shared-sheets.js";
|
|
2
|
+
import { CookieMonsterEvent, CookieMonsterView } from "./types/CookieMonster.types.js";
|
|
3
|
+
import { setLanguage } from "./utils/translationsService.js";
|
|
4
|
+
import { getCookieMonsterEvent } from "./utils/getCookieMonsterEvent.js";
|
|
5
|
+
import views_default from "./views/views.js";
|
|
6
|
+
import { isServerSide } from "@naturalcycles/js-lib";
|
|
7
|
+
import { langService } from "@naturalcycles/shared";
|
|
8
|
+
//#region src/cookie-monster/cookie-monster-element.ts
|
|
9
|
+
var viewsStyleSheet = createStyles(views_default);
|
|
10
|
+
var CookieMonsterElement = class CookieMonsterElement extends HTMLElement {
|
|
11
|
+
root;
|
|
12
|
+
container;
|
|
13
|
+
mainView;
|
|
14
|
+
isScrollLocked = false;
|
|
15
|
+
scrollY = 0;
|
|
16
|
+
/**
|
|
17
|
+
* Creates and appends the element if needed, then shows it. Static so consent.service.ts can
|
|
18
|
+
* also call it without a module cycle through cookieMonsterService.ts.
|
|
19
|
+
*/
|
|
20
|
+
static open(options) {
|
|
21
|
+
if (isServerSide()) return;
|
|
22
|
+
const element = CookieMonsterElement.getOrCreate(options?.language);
|
|
23
|
+
if (options?.view === CookieMonsterView.settings) element.showSettings();
|
|
24
|
+
else if (options?.view === CookieMonsterView.banner) element.showBanner();
|
|
25
|
+
element.setAttribute("display", "true");
|
|
26
|
+
}
|
|
27
|
+
static close() {
|
|
28
|
+
if (isServerSide()) return;
|
|
29
|
+
document.querySelector("cookie-monster")?.setAttribute("display", "false");
|
|
30
|
+
}
|
|
31
|
+
static getOrCreate(language) {
|
|
32
|
+
let element = document.querySelector("cookie-monster");
|
|
33
|
+
element ||= document.createElement("cookie-monster");
|
|
34
|
+
if (language) element.setAttribute("language", language);
|
|
35
|
+
if (!element.isConnected) document.body.append(element);
|
|
36
|
+
return element;
|
|
37
|
+
}
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
setLanguage(this.getAttribute("language") || langService.LANG_DEFAULT);
|
|
41
|
+
this.root = this.attachShadow({ mode: "open" });
|
|
42
|
+
this.root.adoptedStyleSheets = [
|
|
43
|
+
paletteSheet,
|
|
44
|
+
generalSheet,
|
|
45
|
+
viewsStyleSheet
|
|
46
|
+
];
|
|
47
|
+
this.container = document.createElement("div");
|
|
48
|
+
this.container.id = "CookieMonster";
|
|
49
|
+
this.container.setAttribute("uid", "cookiemonster");
|
|
50
|
+
this.root.append(this.container);
|
|
51
|
+
this.mainView = document.createElement("main-view");
|
|
52
|
+
this.container.append(this.mainView);
|
|
53
|
+
}
|
|
54
|
+
connectedCallback() {
|
|
55
|
+
setLanguage(this.getAttribute("language") || langService.LANG_DEFAULT);
|
|
56
|
+
this.replaceMainView();
|
|
57
|
+
this.dispatchEvent(getCookieMonsterEvent(CookieMonsterEvent.cookieMonsterOnMount));
|
|
58
|
+
this.attributeChangedCallback("display", null, this.getAttribute("display"));
|
|
59
|
+
this.addEventListener(CookieMonsterEvent.cookieMonsterOnClose, this.handleFinalDecision);
|
|
60
|
+
}
|
|
61
|
+
static get observedAttributes() {
|
|
62
|
+
return ["display", "language"];
|
|
63
|
+
}
|
|
64
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
65
|
+
if (name === "display") {
|
|
66
|
+
const display = newValue !== null && newValue !== "false";
|
|
67
|
+
this.container.style.display = display ? "block" : "none";
|
|
68
|
+
if (display) this.lockScroll();
|
|
69
|
+
else this.unlockScroll();
|
|
70
|
+
this.dispatchEvent(getCookieMonsterEvent(CookieMonsterEvent.cookieMonsterOnDisplay, { display }));
|
|
71
|
+
}
|
|
72
|
+
if (name === "language") {
|
|
73
|
+
if (oldValue === newValue) return;
|
|
74
|
+
setLanguage(newValue || langService.LANG_DEFAULT);
|
|
75
|
+
this.replaceMainView();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
disconnectedCallback() {
|
|
79
|
+
this.removeEventListener(CookieMonsterEvent.cookieMonsterOnClose, this.handleFinalDecision);
|
|
80
|
+
this.unlockScroll();
|
|
81
|
+
}
|
|
82
|
+
showBanner() {
|
|
83
|
+
this.mainView.showBanner();
|
|
84
|
+
}
|
|
85
|
+
showSettings() {
|
|
86
|
+
this.mainView.showSettings();
|
|
87
|
+
}
|
|
88
|
+
getBannerText() {
|
|
89
|
+
return this.mainView.getBannerText();
|
|
90
|
+
}
|
|
91
|
+
handleFinalDecision() {
|
|
92
|
+
this.setAttribute("display", "false");
|
|
93
|
+
}
|
|
94
|
+
lockScroll() {
|
|
95
|
+
if (this.isScrollLocked) return;
|
|
96
|
+
this.isScrollLocked = true;
|
|
97
|
+
this.scrollY = globalThis.scrollY;
|
|
98
|
+
document.body.style.position = "fixed";
|
|
99
|
+
document.body.style.top = `-${this.scrollY}px`;
|
|
100
|
+
document.body.style.left = "0";
|
|
101
|
+
document.body.style.right = "0";
|
|
102
|
+
document.body.style.width = "100%";
|
|
103
|
+
}
|
|
104
|
+
unlockScroll() {
|
|
105
|
+
if (!this.isScrollLocked) return;
|
|
106
|
+
this.isScrollLocked = false;
|
|
107
|
+
document.body.style.position = "";
|
|
108
|
+
document.body.style.top = "";
|
|
109
|
+
document.body.style.left = "";
|
|
110
|
+
document.body.style.right = "";
|
|
111
|
+
document.body.style.width = "";
|
|
112
|
+
globalThis.scrollTo(0, this.scrollY);
|
|
113
|
+
}
|
|
114
|
+
replaceMainView() {
|
|
115
|
+
const newMainView = document.createElement("main-view");
|
|
116
|
+
this.mainView.replaceWith(newMainView);
|
|
117
|
+
this.mainView = newMainView;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
export { CookieMonsterElement };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { OpenCookieMonsterOptions } from './cookie-monster-element.js';
|
|
2
|
+
import type { ConsentLogEntry, CookieMonsterConsent, RegisterCookieMonsterOptions } from './types/CookieMonster.types.js';
|
|
3
|
+
export type { OpenCookieMonsterOptions } from './cookie-monster-element.js';
|
|
4
|
+
declare class CookieMonsterService {
|
|
5
|
+
register(options?: RegisterCookieMonsterOptions): void;
|
|
6
|
+
/**
|
|
7
|
+
* Undoes register. The custom elements stay defined, since the platform offers no way to
|
|
8
|
+
* undefine them.
|
|
9
|
+
*/
|
|
10
|
+
unregister(): void;
|
|
11
|
+
open(options?: OpenCookieMonsterOptions): void;
|
|
12
|
+
/** Opens CookieMonster directly into the settings view for the Cookie Policy page. */
|
|
13
|
+
openSettings(): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
getConsent(): CookieMonsterConsent | undefined;
|
|
16
|
+
getConsentLog(): ConsentLogEntry[] | undefined;
|
|
17
|
+
getCookieMonsterVersion(): string | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare const cookieMonsterService: CookieMonsterService;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { CookieMonsterView } from "./types/CookieMonster.types.js";
|
|
2
|
+
import { SettingDropdown } from "./components/setting-dropdown/setting-dropdown2.component.js";
|
|
3
|
+
import { ThemedButton } from "./components/themed-button/themed-button2.component.js";
|
|
4
|
+
import { SettingsViewElement } from "./views/settings.view.js";
|
|
5
|
+
import { MainViewElement } from "./views/main.view.js";
|
|
6
|
+
import { CookieMonsterElement } from "./cookie-monster-element.js";
|
|
7
|
+
import { consentService } from "./consent/consent.service.js";
|
|
8
|
+
//#region src/cookie-monster/cookieMonsterService.ts
|
|
9
|
+
var CookieMonsterService = class {
|
|
10
|
+
register(options) {
|
|
11
|
+
defineElementOnce("cookie-monster", CookieMonsterElement);
|
|
12
|
+
defineElementOnce("main-view", MainViewElement);
|
|
13
|
+
defineElementOnce("settings-view", SettingsViewElement);
|
|
14
|
+
defineElementOnce("setting-dropdown", SettingDropdown);
|
|
15
|
+
defineElementOnce("themed-button", ThemedButton);
|
|
16
|
+
consentService.setVersionProvider(getCookieMonsterVersion);
|
|
17
|
+
consentService.initConsent(options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Undoes register. The custom elements stay defined, since the platform offers no way to
|
|
21
|
+
* undefine them.
|
|
22
|
+
*/
|
|
23
|
+
unregister() {
|
|
24
|
+
consentService.teardownConsent();
|
|
25
|
+
}
|
|
26
|
+
open(options) {
|
|
27
|
+
CookieMonsterElement.open(options);
|
|
28
|
+
}
|
|
29
|
+
/** Opens CookieMonster directly into the settings view for the Cookie Policy page. */
|
|
30
|
+
openSettings() {
|
|
31
|
+
CookieMonsterElement.open({ view: CookieMonsterView.settings });
|
|
32
|
+
}
|
|
33
|
+
close() {
|
|
34
|
+
CookieMonsterElement.close();
|
|
35
|
+
}
|
|
36
|
+
getConsent() {
|
|
37
|
+
return consentService.getConsent();
|
|
38
|
+
}
|
|
39
|
+
getConsentLog() {
|
|
40
|
+
return consentService.getConsentLog();
|
|
41
|
+
}
|
|
42
|
+
getCookieMonsterVersion() {
|
|
43
|
+
return getCookieMonsterVersion();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* CookieMonster's own package version, used to tag consent log entries with the
|
|
48
|
+
* banner copy/behavior version the user saw.
|
|
49
|
+
*/
|
|
50
|
+
function getCookieMonsterVersion() {
|
|
51
|
+
return "1.0.0";
|
|
52
|
+
}
|
|
53
|
+
function defineElementOnce(name, element) {
|
|
54
|
+
if (!globalThis.customElements) return;
|
|
55
|
+
if (!globalThis.customElements.get(name)) globalThis.customElements.define(name, element);
|
|
56
|
+
}
|
|
57
|
+
var cookieMonsterService = new CookieMonsterService();
|
|
58
|
+
//#endregion
|
|
59
|
+
export { cookieMonsterService };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/cookie-monster/css/fonts.css?inline
|
|
2
|
+
var fonts_default = "@font-face {\n /* \n * The font family name is explicitly different compared to the same font family in other projects.\n * Having the same font family name as NCWeb/WebSignup caused rendering issues (font size being off).\n */\n font-family: 'Open Sauce One';\n font-display: swap;\n src: url('/fonts/opensauce/one/OpenSauceOne-Regular.woff2') format('woff2');\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: 'Open Sauce One';\n font-display: swap;\n src: url('/fonts/opensauce/one/OpenSauceOne-Medium.woff2') format('woff2');\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: 'Open Sauce One';\n font-display: swap;\n src: url('/fonts/opensauce/one/OpenSauceOne-Bold.woff2') format('woff2');\n font-weight: 600;\n font-style: normal;\n}\n\n@font-face {\n font-family: 'Open Sauce One';\n font-display: swap;\n src: url('/fonts/opensauce/one/OpenSauceOne-ExtraBold.woff2') format('woff2');\n font-weight: 800;\n font-style: normal;\n}\n";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { fonts_default as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _palette_default from "../../node_modules/.pnpm/@naturalcycles_ncuikit@1.14.0_react@19.3.0_undici@8.11.2/node_modules/@naturalcycles/ncuikit/dist/styles/_palette.js";
|
|
2
|
+
import fonts_default from "./fonts.js";
|
|
3
|
+
import general_default from "./general.js";
|
|
4
|
+
//#region src/cookie-monster/css/shared-sheets.ts
|
|
5
|
+
function createStyles(css) {
|
|
6
|
+
const sheet = new CSSStyleSheet();
|
|
7
|
+
sheet.replaceSync(css);
|
|
8
|
+
return sheet;
|
|
9
|
+
}
|
|
10
|
+
var paletteSheet = createStyles(_palette_default.replaceAll(":root", ":host"));
|
|
11
|
+
var generalSheet = createStyles(general_default);
|
|
12
|
+
var fontSheet = createStyles(fonts_default);
|
|
13
|
+
//#endregion
|
|
14
|
+
export { createStyles, fontSheet, generalSheet, paletteSheet };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/cookie-monster/icons/back.svg
|
|
2
|
+
var back_default = "data:image/svg+xml,%3csvg%20width='16'%20height='16'%20viewBox='0%200%2016%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M1.38381%208.25519C1.41634%208.33382%201.46457%208.40749%201.52849%208.4714L6.19515%2013.1381C6.4555%2013.3984%206.87761%2013.3984%207.13796%2013.1381C7.39831%2012.8777%207.39831%2012.4556%207.13796%2012.1953L3.60937%208.66666L13.9999%208.66667C14.3681%208.66667%2014.6666%208.36819%2014.6666%208C14.6666%207.63181%2014.3681%207.33333%2013.9999%207.33333L3.60937%207.33333L7.13796%203.80473C7.39831%203.54439%207.39831%203.12228%207.13796%202.86193C6.87761%202.60158%206.4555%202.60158%206.19515%202.86193L1.52849%207.52859C1.39988%207.6572%201.3348%207.82529%201.33325%207.99384'%20fill='%2372035D'/%3e%3cpath%20d='M1.38381%208.25519C1.35195%208.17837%201.33405%208.0943%201.33325%208.00615L1.38381%208.25519Z'%20fill='%2372035D'/%3e%3c/svg%3e";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { back_default as default };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/cookie-monster/icons/chevron.svg
|
|
2
|
+
var chevron_default = "data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M11.2929%2015.7071C11.6834%2016.0976%2012.3166%2016.0976%2012.7071%2015.7071L17.7071%2010.7071C18.0976%2010.3166%2018.0976%209.68342%2017.7071%209.29289C17.3166%208.90237%2016.6834%208.90237%2016.2929%209.29289L12%2013.5858L7.70711%209.29289C7.31658%208.90237%206.68342%208.90237%206.29289%209.29289C5.90237%209.68342%205.90237%2010.3166%206.29289%2010.7071L11.2929%2015.7071Z'%20fill='%231A1A1A'/%3e%3c/svg%3e";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { chevron_default as default };
|