@nortic/citronkaka-ui 0.1.3 → 0.2.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/dist/{index-kuQRzOso.js → index-BcL_GpLr.js} +55 -47
- package/dist/index-CQ8BXiGX.js +7474 -0
- package/dist/index.js +1 -1
- package/package.json +26 -26
- package/dist/index-cvXsz_Ej.js +0 -7904
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function
|
|
1
|
+
function h() {
|
|
2
2
|
return location.hostname.split(".").slice(-2).join(".");
|
|
3
3
|
}
|
|
4
|
-
const
|
|
5
|
-
domain:
|
|
4
|
+
const m = {
|
|
5
|
+
domain: h(),
|
|
6
6
|
defaultModel: {
|
|
7
7
|
useraction: !1,
|
|
8
8
|
value: { necessary: !0, functional: !1, analytics: !1, marketing: !1 }
|
|
@@ -10,15 +10,12 @@ const h = {
|
|
|
10
10
|
persistentKey: "nortic_cookie_consent",
|
|
11
11
|
persistentExpirationDays: 365,
|
|
12
12
|
categories: ["necessary", "functional", "analytics", "marketing"],
|
|
13
|
-
services: [
|
|
14
|
-
{ name: "Translations", category: "functional", scripts: [], cookies: [/^i18n_redirected/] },
|
|
15
|
-
{ name: "Color mode", category: "functional", scripts: [], cookies: [/^color-mode/] }
|
|
16
|
-
]
|
|
13
|
+
services: []
|
|
17
14
|
};
|
|
18
|
-
class
|
|
15
|
+
class u {
|
|
19
16
|
static createCookieString(e, t, o = {}) {
|
|
20
|
-
const { expires:
|
|
21
|
-
return `${e}=${a}${
|
|
17
|
+
const { expires: s, path: i = "/", sameSite: n = "Strict", domain: c } = o, a = encodeURIComponent(t), d = s ? `; expires=${s.toUTCString()}` : "", p = c ? `; domain=${c}` : "";
|
|
18
|
+
return `${e}=${a}${d}; path=${i}; SameSite=${n}${p}`;
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
21
|
* Sets a cookie with the specified options.
|
|
@@ -27,9 +24,9 @@ class d {
|
|
|
27
24
|
* @param days Number of days until the cookie expires.
|
|
28
25
|
* @param domain Optional domain for the cookie.
|
|
29
26
|
*/
|
|
30
|
-
static set(e, t, o,
|
|
31
|
-
const i = typeof t == "string" ? t : JSON.stringify(t),
|
|
32
|
-
document.cookie = this.createCookieString(e, i, { expires:
|
|
27
|
+
static set(e, t, o, s) {
|
|
28
|
+
const i = typeof t == "string" ? t : JSON.stringify(t), n = new Date(Date.now() + o * 24 * 60 * 60 * 1e3);
|
|
29
|
+
document.cookie = this.createCookieString(e, i, { expires: n, domain: s });
|
|
33
30
|
}
|
|
34
31
|
/**
|
|
35
32
|
* Retrieves the value of a cookie by name.
|
|
@@ -59,24 +56,24 @@ class d {
|
|
|
59
56
|
});
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
|
-
class
|
|
59
|
+
class f {
|
|
63
60
|
/**
|
|
64
61
|
* Cleans up cookies based on a list of blacklist patterns.
|
|
65
62
|
* @param blacklist An array of RegExp patterns for cookies to delete.
|
|
66
63
|
*/
|
|
67
|
-
static run(e, t =
|
|
68
|
-
function o(
|
|
64
|
+
static run(e, t = u) {
|
|
65
|
+
function o(s) {
|
|
69
66
|
document.cookie.split(";").forEach((i) => {
|
|
70
|
-
const
|
|
71
|
-
|
|
67
|
+
const n = i.split("=")[0].trim();
|
|
68
|
+
s.test(n) && (t.delete(n), console.warn(`Removed cookie: ${n}`));
|
|
72
69
|
});
|
|
73
70
|
}
|
|
74
|
-
e.forEach((
|
|
75
|
-
o(
|
|
71
|
+
e.forEach((s) => {
|
|
72
|
+
o(s);
|
|
76
73
|
});
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
|
-
class
|
|
76
|
+
class k {
|
|
80
77
|
/**
|
|
81
78
|
* Starts the cookie interception process to block cookies based on a blacklist.
|
|
82
79
|
* @param blacklist An array of RegExp patterns for cookie names to block.
|
|
@@ -103,9 +100,9 @@ class f {
|
|
|
103
100
|
* @param cookieString The cookie string to be set.
|
|
104
101
|
*/
|
|
105
102
|
set(o) {
|
|
106
|
-
var
|
|
107
|
-
const i = o.split("=")[0].trim(),
|
|
108
|
-
|
|
103
|
+
var s;
|
|
104
|
+
const i = o.split("=")[0].trim(), n = o.match(/expires=([^;]+)/i);
|
|
105
|
+
n && new Date(n[1]).getTime() < Date.now() || !e.some((c) => c.test(i)) ? (s = t.set) == null || s.call(document, o) : console.warn(`Blocked cookie: ${i}`);
|
|
109
106
|
}
|
|
110
107
|
});
|
|
111
108
|
}
|
|
@@ -135,18 +132,18 @@ class l {
|
|
|
135
132
|
static interceptScriptCreation(e) {
|
|
136
133
|
const t = document.createElement.bind(document);
|
|
137
134
|
document.createElement = function(o) {
|
|
138
|
-
const
|
|
135
|
+
const s = t(o);
|
|
139
136
|
if (o.toLowerCase() === "script") {
|
|
140
|
-
const i =
|
|
137
|
+
const i = s, n = Object.getOwnPropertyDescriptor(
|
|
141
138
|
HTMLScriptElement.prototype,
|
|
142
139
|
"src"
|
|
143
140
|
);
|
|
144
|
-
|
|
141
|
+
n && Object.defineProperty(i, "src", {
|
|
145
142
|
configurable: !0,
|
|
146
143
|
enumerable: !0,
|
|
147
144
|
get() {
|
|
148
145
|
var c;
|
|
149
|
-
return (c =
|
|
146
|
+
return (c = n.get) == null ? void 0 : c.call(i);
|
|
150
147
|
},
|
|
151
148
|
set(c) {
|
|
152
149
|
var a;
|
|
@@ -154,11 +151,11 @@ class l {
|
|
|
154
151
|
console.warn(`Blocked script: ${c}`), i.type = "javascript/blocked";
|
|
155
152
|
return;
|
|
156
153
|
}
|
|
157
|
-
(a =
|
|
154
|
+
(a = n.set) == null || a.call(i, c);
|
|
158
155
|
}
|
|
159
156
|
});
|
|
160
157
|
}
|
|
161
|
-
return
|
|
158
|
+
return s;
|
|
162
159
|
};
|
|
163
160
|
}
|
|
164
161
|
/**
|
|
@@ -169,15 +166,15 @@ class l {
|
|
|
169
166
|
static observeDynamicScripts(e) {
|
|
170
167
|
new MutationObserver((t) => {
|
|
171
168
|
t.forEach(({ addedNodes: o }) => {
|
|
172
|
-
o.forEach((
|
|
173
|
-
if (
|
|
174
|
-
const i =
|
|
169
|
+
o.forEach((s) => {
|
|
170
|
+
if (s.nodeType === Node.ELEMENT_NODE && s.tagName === "SCRIPT") {
|
|
171
|
+
const i = s;
|
|
175
172
|
if (i.src && this.shouldBlockScript(e, i.src)) {
|
|
176
173
|
console.warn(`Blocked dynamically added script: ${i.src}`), i.type = "javascript/blocked";
|
|
177
|
-
const
|
|
178
|
-
i.getAttribute("type") === "javascript/blocked" && (c.preventDefault(), console.warn(`Prevented execution of blocked script: ${i.src}`)), i.removeEventListener("beforescriptexecute",
|
|
174
|
+
const n = (c) => {
|
|
175
|
+
i.getAttribute("type") === "javascript/blocked" && (c.preventDefault(), console.warn(`Prevented execution of blocked script: ${i.src}`)), i.removeEventListener("beforescriptexecute", n);
|
|
179
176
|
};
|
|
180
|
-
i.addEventListener("beforescriptexecute",
|
|
177
|
+
i.addEventListener("beforescriptexecute", n);
|
|
181
178
|
}
|
|
182
179
|
}
|
|
183
180
|
});
|
|
@@ -188,9 +185,20 @@ class l {
|
|
|
188
185
|
});
|
|
189
186
|
}
|
|
190
187
|
}
|
|
191
|
-
class
|
|
192
|
-
constructor(e =
|
|
193
|
-
this.config = e, this.listeners = t, this.persistentService = o, this.cookieCleaner =
|
|
188
|
+
class g {
|
|
189
|
+
constructor(e = m, t = { update: [] }, o = u, s = f, i = k, n = l) {
|
|
190
|
+
this.config = e, this.listeners = t, this.persistentService = o, this.cookieCleaner = s, this.cookieInterceptor = i, this.scriptInterceptor = n, s.run(this.blacklist.cookies), i.run(this.blacklist.cookies), n.run(this.blacklist.scripts);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Initializes the CookieConsent instance with the provided configuration.
|
|
194
|
+
* This method merges the provided configuration with the default configuration
|
|
195
|
+
* and re-runs the cookie and script cleaning/interception processes based on the updated configuration.
|
|
196
|
+
*
|
|
197
|
+
* @param config - A partial configuration object to override the default configuration.
|
|
198
|
+
* This allows customization of the cookie consent behavior.
|
|
199
|
+
*/
|
|
200
|
+
init(e = {}) {
|
|
201
|
+
this.config = { ...this.config, ...e }, this.cookieCleaner.run(this.blacklist.cookies), this.cookieInterceptor.run(this.blacklist.cookies), this.scriptInterceptor.run(this.blacklist.scripts);
|
|
194
202
|
}
|
|
195
203
|
/**
|
|
196
204
|
* Retrieves the current cookie consent model from persistent storage.
|
|
@@ -244,8 +252,8 @@ class y {
|
|
|
244
252
|
get blacklist() {
|
|
245
253
|
return this.config.services.reduce((e, t) => {
|
|
246
254
|
if (this.model.value[t.category] === !1) {
|
|
247
|
-
const { cookies: o, scripts:
|
|
248
|
-
e.cookies = e.cookies.concat(o), e.scripts = e.scripts.concat(
|
|
255
|
+
const { cookies: o, scripts: s } = t;
|
|
256
|
+
e.cookies = e.cookies.concat(o), e.scripts = e.scripts.concat(s);
|
|
249
257
|
}
|
|
250
258
|
return e;
|
|
251
259
|
}, { cookies: [], scripts: [] });
|
|
@@ -265,10 +273,10 @@ class y {
|
|
|
265
273
|
return o.necessary === !0 && typeof o.functional == "boolean" && typeof o.analytics == "boolean" && typeof o.marketing == "boolean";
|
|
266
274
|
}
|
|
267
275
|
}
|
|
268
|
-
window.Citronkaka = window.Citronkaka || new
|
|
269
|
-
const
|
|
276
|
+
window.Citronkaka = window.Citronkaka || new g();
|
|
277
|
+
const y = window.Citronkaka;
|
|
270
278
|
class v {
|
|
271
|
-
constructor(e = null, t =
|
|
279
|
+
constructor(e = null, t = y) {
|
|
272
280
|
this.ui = e, this.service = t, this.init();
|
|
273
281
|
}
|
|
274
282
|
/**
|
|
@@ -284,7 +292,7 @@ class v {
|
|
|
284
292
|
*/
|
|
285
293
|
async loadUI() {
|
|
286
294
|
try {
|
|
287
|
-
const { NorticCookieConsentDialog: e } = await import("./index-
|
|
295
|
+
const { NorticCookieConsentDialog: e } = await import("./index-CQ8BXiGX.js");
|
|
288
296
|
window.customElements.get("nortic-cookie-consent-dialog") || window.customElements.define("nortic-cookie-consent-dialog", e), this.ui = document.createElement("nortic-cookie-consent-dialog"), this.ui.setAttribute("data-testid", "cookie-consent"), document.body.appendChild(this.ui);
|
|
289
297
|
} catch (e) {
|
|
290
298
|
console.error("Failed to load the cookie consent dialog:", e);
|
|
@@ -299,6 +307,6 @@ class v {
|
|
|
299
307
|
}
|
|
300
308
|
const b = new v();
|
|
301
309
|
export {
|
|
302
|
-
|
|
303
|
-
|
|
310
|
+
b as i,
|
|
311
|
+
y
|
|
304
312
|
};
|