@freshjuice/zest 0.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/LICENSE +21 -0
- package/README.md +312 -0
- package/dist/zest.de.js +2621 -0
- package/dist/zest.de.js.map +1 -0
- package/dist/zest.de.min.js +1 -0
- package/dist/zest.en.js +2621 -0
- package/dist/zest.en.js.map +1 -0
- package/dist/zest.en.min.js +1 -0
- package/dist/zest.es.js +2621 -0
- package/dist/zest.es.js.map +1 -0
- package/dist/zest.es.min.js +1 -0
- package/dist/zest.esm.js +3104 -0
- package/dist/zest.esm.js.map +1 -0
- package/dist/zest.esm.min.js +1 -0
- package/dist/zest.fr.js +2621 -0
- package/dist/zest.fr.js.map +1 -0
- package/dist/zest.fr.min.js +1 -0
- package/dist/zest.it.js +2621 -0
- package/dist/zest.it.js.map +1 -0
- package/dist/zest.it.min.js +1 -0
- package/dist/zest.ja.js +2621 -0
- package/dist/zest.ja.js.map +1 -0
- package/dist/zest.ja.min.js +1 -0
- package/dist/zest.js +3109 -0
- package/dist/zest.js.map +1 -0
- package/dist/zest.min.js +1 -0
- package/dist/zest.nl.js +2621 -0
- package/dist/zest.nl.js.map +1 -0
- package/dist/zest.nl.min.js +1 -0
- package/dist/zest.pl.js +2621 -0
- package/dist/zest.pl.js.map +1 -0
- package/dist/zest.pl.min.js +1 -0
- package/dist/zest.pt.js +2621 -0
- package/dist/zest.pt.js.map +1 -0
- package/dist/zest.pt.min.js +1 -0
- package/dist/zest.ru.js +2621 -0
- package/dist/zest.ru.js.map +1 -0
- package/dist/zest.ru.min.js +1 -0
- package/dist/zest.uk.js +2621 -0
- package/dist/zest.uk.js.map +1 -0
- package/dist/zest.uk.min.js +1 -0
- package/dist/zest.zh.js +2621 -0
- package/dist/zest.zh.js.map +1 -0
- package/dist/zest.zh.min.js +1 -0
- package/locales/de.json +40 -0
- package/locales/en.json +40 -0
- package/locales/es.json +40 -0
- package/locales/fr.json +40 -0
- package/locales/it.json +40 -0
- package/locales/ja.json +40 -0
- package/locales/nl.json +40 -0
- package/locales/pl.json +40 -0
- package/locales/pt.json +40 -0
- package/locales/ru.json +40 -0
- package/locales/uk.json +40 -0
- package/locales/zh.json +40 -0
- package/package.json +63 -0
- package/zest.config.schema.json +256 -0
package/dist/zest.esm.js
ADDED
|
@@ -0,0 +1,3104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Matcher - Categorizes cookies and storage keys by pattern
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default patterns for each category
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_PATTERNS = {
|
|
9
|
+
essential: [
|
|
10
|
+
/^zest_/,
|
|
11
|
+
/^csrf/i,
|
|
12
|
+
/^xsrf/i,
|
|
13
|
+
/^session/i,
|
|
14
|
+
/^__host-/i,
|
|
15
|
+
/^__secure-/i
|
|
16
|
+
],
|
|
17
|
+
functional: [
|
|
18
|
+
/^lang/i,
|
|
19
|
+
/^locale/i,
|
|
20
|
+
/^theme/i,
|
|
21
|
+
/^preferences/i,
|
|
22
|
+
/^ui_/i
|
|
23
|
+
],
|
|
24
|
+
analytics: [
|
|
25
|
+
/^_ga/,
|
|
26
|
+
/^_gid/,
|
|
27
|
+
/^_gat/,
|
|
28
|
+
/^_utm/,
|
|
29
|
+
/^__utm/,
|
|
30
|
+
/^plausible/i,
|
|
31
|
+
/^_pk_/,
|
|
32
|
+
/^matomo/i,
|
|
33
|
+
/^_hj/,
|
|
34
|
+
/^ajs_/
|
|
35
|
+
],
|
|
36
|
+
marketing: [
|
|
37
|
+
/^_fbp/,
|
|
38
|
+
/^_fbc/,
|
|
39
|
+
/^_gcl/,
|
|
40
|
+
/^_ttp/,
|
|
41
|
+
/^ads/i,
|
|
42
|
+
/^doubleclick/i,
|
|
43
|
+
/^__gads/,
|
|
44
|
+
/^__gpi/,
|
|
45
|
+
/^_pin_/,
|
|
46
|
+
/^li_/
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
let patterns = { ...DEFAULT_PATTERNS };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Set custom patterns
|
|
54
|
+
*/
|
|
55
|
+
function setPatterns(customPatterns) {
|
|
56
|
+
patterns = { ...DEFAULT_PATTERNS };
|
|
57
|
+
for (const [category, regexList] of Object.entries(customPatterns)) {
|
|
58
|
+
if (Array.isArray(regexList)) {
|
|
59
|
+
patterns[category] = regexList.map(p =>
|
|
60
|
+
p instanceof RegExp ? p : new RegExp(p)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Determine category for a cookie/storage key name
|
|
68
|
+
* @param {string} name - Cookie or storage key name
|
|
69
|
+
* @returns {string} Category ID (defaults to 'marketing' for unknown)
|
|
70
|
+
*/
|
|
71
|
+
function getCategoryForName(name) {
|
|
72
|
+
for (const [category, regexList] of Object.entries(patterns)) {
|
|
73
|
+
if (regexList.some(regex => regex.test(name))) {
|
|
74
|
+
return category;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Unknown items default to marketing (strictest)
|
|
78
|
+
return 'marketing';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Parse cookie string to extract name
|
|
83
|
+
* @param {string} cookieString - Full cookie string (e.g., "name=value; path=/")
|
|
84
|
+
* @returns {string|null} Cookie name or null
|
|
85
|
+
*/
|
|
86
|
+
function parseCookieName(cookieString) {
|
|
87
|
+
const match = cookieString.match(/^([^=]+)/);
|
|
88
|
+
return match ? match[1].trim() : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Cookie Interceptor - Intercepts document.cookie operations
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
// Store original descriptor
|
|
97
|
+
let originalCookieDescriptor = null;
|
|
98
|
+
|
|
99
|
+
// Queue for blocked cookies
|
|
100
|
+
const cookieQueue = [];
|
|
101
|
+
|
|
102
|
+
// Reference to consent checker function
|
|
103
|
+
let checkConsent$3 = () => false;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Set the consent checker function
|
|
107
|
+
*/
|
|
108
|
+
function setConsentChecker$2(fn) {
|
|
109
|
+
checkConsent$3 = fn;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get the original cookie descriptor
|
|
114
|
+
*/
|
|
115
|
+
function getOriginalCookieDescriptor() {
|
|
116
|
+
return originalCookieDescriptor;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Replay queued cookies for allowed categories
|
|
121
|
+
*/
|
|
122
|
+
function replayCookies(allowedCategories) {
|
|
123
|
+
const remaining = [];
|
|
124
|
+
|
|
125
|
+
for (const item of cookieQueue) {
|
|
126
|
+
if (allowedCategories.includes(item.category)) {
|
|
127
|
+
// Set the cookie using original setter
|
|
128
|
+
if (originalCookieDescriptor?.set) {
|
|
129
|
+
originalCookieDescriptor.set.call(document, item.value);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
remaining.push(item);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
cookieQueue.length = 0;
|
|
137
|
+
cookieQueue.push(...remaining);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Start intercepting cookies
|
|
142
|
+
*/
|
|
143
|
+
function interceptCookies() {
|
|
144
|
+
// Store original
|
|
145
|
+
originalCookieDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie');
|
|
146
|
+
|
|
147
|
+
if (!originalCookieDescriptor) {
|
|
148
|
+
console.warn('[Zest] Could not get cookie descriptor');
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
Object.defineProperty(document, 'cookie', {
|
|
153
|
+
get() {
|
|
154
|
+
// Always allow reading
|
|
155
|
+
return originalCookieDescriptor.get.call(document);
|
|
156
|
+
},
|
|
157
|
+
set(value) {
|
|
158
|
+
const name = parseCookieName(value);
|
|
159
|
+
if (!name) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const category = getCategoryForName(name);
|
|
164
|
+
|
|
165
|
+
if (checkConsent$3(category)) {
|
|
166
|
+
// Consent given - set cookie
|
|
167
|
+
originalCookieDescriptor.set.call(document, value);
|
|
168
|
+
} else {
|
|
169
|
+
// No consent - queue for later
|
|
170
|
+
cookieQueue.push({
|
|
171
|
+
value,
|
|
172
|
+
name,
|
|
173
|
+
category,
|
|
174
|
+
timestamp: Date.now()
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
configurable: true
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Storage Interceptor - Intercepts localStorage and sessionStorage operations
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
// Store originals
|
|
190
|
+
let originalLocalStorage = null;
|
|
191
|
+
let originalSessionStorage = null;
|
|
192
|
+
|
|
193
|
+
// Queues for blocked operations
|
|
194
|
+
const localStorageQueue = [];
|
|
195
|
+
const sessionStorageQueue = [];
|
|
196
|
+
|
|
197
|
+
// Reference to consent checker function
|
|
198
|
+
let checkConsent$2 = () => false;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Set the consent checker function
|
|
202
|
+
*/
|
|
203
|
+
function setConsentChecker$1(fn) {
|
|
204
|
+
checkConsent$2 = fn;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Create a proxy for storage API
|
|
209
|
+
*/
|
|
210
|
+
function createStorageProxy(storage, queue, storageName) {
|
|
211
|
+
return new Proxy(storage, {
|
|
212
|
+
get(target, prop) {
|
|
213
|
+
if (prop === 'setItem') {
|
|
214
|
+
return (key, value) => {
|
|
215
|
+
const category = getCategoryForName(key);
|
|
216
|
+
|
|
217
|
+
if (checkConsent$2(category)) {
|
|
218
|
+
target.setItem(key, value);
|
|
219
|
+
} else {
|
|
220
|
+
queue.push({
|
|
221
|
+
key,
|
|
222
|
+
value,
|
|
223
|
+
category,
|
|
224
|
+
timestamp: Date.now()
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Allow all other operations
|
|
231
|
+
const val = target[prop];
|
|
232
|
+
return typeof val === 'function' ? val.bind(target) : val;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Replay queued storage operations for allowed categories
|
|
239
|
+
*/
|
|
240
|
+
function replayStorage(allowedCategories) {
|
|
241
|
+
// Replay localStorage
|
|
242
|
+
const remainingLocal = [];
|
|
243
|
+
for (const item of localStorageQueue) {
|
|
244
|
+
if (allowedCategories.includes(item.category)) {
|
|
245
|
+
originalLocalStorage?.setItem(item.key, item.value);
|
|
246
|
+
} else {
|
|
247
|
+
remainingLocal.push(item);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
localStorageQueue.length = 0;
|
|
251
|
+
localStorageQueue.push(...remainingLocal);
|
|
252
|
+
|
|
253
|
+
// Replay sessionStorage
|
|
254
|
+
const remainingSession = [];
|
|
255
|
+
for (const item of sessionStorageQueue) {
|
|
256
|
+
if (allowedCategories.includes(item.category)) {
|
|
257
|
+
originalSessionStorage?.setItem(item.key, item.value);
|
|
258
|
+
} else {
|
|
259
|
+
remainingSession.push(item);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
sessionStorageQueue.length = 0;
|
|
263
|
+
sessionStorageQueue.push(...remainingSession);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Start intercepting storage APIs
|
|
268
|
+
*/
|
|
269
|
+
function interceptStorage() {
|
|
270
|
+
try {
|
|
271
|
+
originalLocalStorage = window.localStorage;
|
|
272
|
+
originalSessionStorage = window.sessionStorage;
|
|
273
|
+
|
|
274
|
+
Object.defineProperty(window, 'localStorage', {
|
|
275
|
+
value: createStorageProxy(originalLocalStorage, localStorageQueue, 'localStorage'),
|
|
276
|
+
configurable: true,
|
|
277
|
+
writable: false
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
Object.defineProperty(window, 'sessionStorage', {
|
|
281
|
+
value: createStorageProxy(originalSessionStorage, sessionStorageQueue, 'sessionStorage'),
|
|
282
|
+
configurable: true,
|
|
283
|
+
writable: false
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
return true;
|
|
287
|
+
} catch (e) {
|
|
288
|
+
console.warn('[Zest] Could not intercept storage APIs:', e);
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Known Trackers - Lists of known tracking script domains by category
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Safe mode - Major, well-known trackers only
|
|
299
|
+
*/
|
|
300
|
+
const SAFE_TRACKERS = {
|
|
301
|
+
analytics: [
|
|
302
|
+
'google-analytics.com',
|
|
303
|
+
'www.google-analytics.com',
|
|
304
|
+
'analytics.google.com',
|
|
305
|
+
'googletagmanager.com',
|
|
306
|
+
'www.googletagmanager.com',
|
|
307
|
+
'plausible.io',
|
|
308
|
+
'cloudflareinsights.com',
|
|
309
|
+
'static.cloudflareinsights.com'
|
|
310
|
+
],
|
|
311
|
+
marketing: [
|
|
312
|
+
'connect.facebook.net',
|
|
313
|
+
'www.facebook.com/tr',
|
|
314
|
+
'ads.google.com',
|
|
315
|
+
'www.googleadservices.com',
|
|
316
|
+
'googleads.g.doubleclick.net',
|
|
317
|
+
'pagead2.googlesyndication.com'
|
|
318
|
+
]
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Strict mode - Extended list including less common trackers
|
|
323
|
+
*/
|
|
324
|
+
const STRICT_TRACKERS = {
|
|
325
|
+
analytics: [
|
|
326
|
+
...SAFE_TRACKERS.analytics,
|
|
327
|
+
'analytics.tiktok.com',
|
|
328
|
+
'matomo.', // partial match
|
|
329
|
+
'hotjar.com',
|
|
330
|
+
'static.hotjar.com',
|
|
331
|
+
'script.hotjar.com',
|
|
332
|
+
'clarity.ms',
|
|
333
|
+
'www.clarity.ms',
|
|
334
|
+
'heapanalytics.com',
|
|
335
|
+
'cdn.heapanalytics.com',
|
|
336
|
+
'mixpanel.com',
|
|
337
|
+
'cdn.mxpnl.com',
|
|
338
|
+
'segment.com',
|
|
339
|
+
'cdn.segment.com',
|
|
340
|
+
'api.segment.io',
|
|
341
|
+
'fullstory.com',
|
|
342
|
+
'rs.fullstory.com',
|
|
343
|
+
'amplitude.com',
|
|
344
|
+
'cdn.amplitude.com',
|
|
345
|
+
'mouseflow.com',
|
|
346
|
+
'cdn.mouseflow.com',
|
|
347
|
+
'luckyorange.com',
|
|
348
|
+
'cdn.luckyorange.net',
|
|
349
|
+
'crazyegg.com',
|
|
350
|
+
'script.crazyegg.com'
|
|
351
|
+
],
|
|
352
|
+
marketing: [
|
|
353
|
+
...SAFE_TRACKERS.marketing,
|
|
354
|
+
'snap.licdn.com',
|
|
355
|
+
'px.ads.linkedin.com',
|
|
356
|
+
'ads.linkedin.com',
|
|
357
|
+
'analytics.twitter.com',
|
|
358
|
+
'static.ads-twitter.com',
|
|
359
|
+
't.co',
|
|
360
|
+
'analytics.tiktok.com',
|
|
361
|
+
'ads.tiktok.com',
|
|
362
|
+
'sc-static.net', // Snapchat
|
|
363
|
+
'tr.snapchat.com',
|
|
364
|
+
'ct.pinterest.com',
|
|
365
|
+
'pintrk.com',
|
|
366
|
+
's.pinimg.com',
|
|
367
|
+
'widgets.pinterest.com',
|
|
368
|
+
'bat.bing.com',
|
|
369
|
+
'ads.yahoo.com',
|
|
370
|
+
'sp.analytics.yahoo.com',
|
|
371
|
+
'amazon-adsystem.com',
|
|
372
|
+
'z-na.amazon-adsystem.com',
|
|
373
|
+
'criteo.com',
|
|
374
|
+
'static.criteo.net',
|
|
375
|
+
'dis.criteo.com',
|
|
376
|
+
'taboola.com',
|
|
377
|
+
'cdn.taboola.com',
|
|
378
|
+
'trc.taboola.com',
|
|
379
|
+
'outbrain.com',
|
|
380
|
+
'widgets.outbrain.com',
|
|
381
|
+
'adroll.com',
|
|
382
|
+
's.adroll.com'
|
|
383
|
+
],
|
|
384
|
+
functional: [
|
|
385
|
+
'cdn.onesignal.com',
|
|
386
|
+
'onesignal.com',
|
|
387
|
+
'pusher.com',
|
|
388
|
+
'js.pusher.com',
|
|
389
|
+
'intercom.io',
|
|
390
|
+
'widget.intercom.io',
|
|
391
|
+
'js.intercomcdn.com',
|
|
392
|
+
'crisp.chat',
|
|
393
|
+
'client.crisp.chat',
|
|
394
|
+
'cdn.livechatinc.com',
|
|
395
|
+
'livechatinc.com',
|
|
396
|
+
'tawk.to',
|
|
397
|
+
'embed.tawk.to',
|
|
398
|
+
'zendesk.com',
|
|
399
|
+
'static.zdassets.com'
|
|
400
|
+
]
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Check if a URL matches any tracker in the list
|
|
405
|
+
*/
|
|
406
|
+
function matchesTrackerList(url, trackerList) {
|
|
407
|
+
try {
|
|
408
|
+
const urlObj = new URL(url);
|
|
409
|
+
const hostname = urlObj.hostname.toLowerCase();
|
|
410
|
+
const fullUrl = url.toLowerCase();
|
|
411
|
+
|
|
412
|
+
for (const domain of trackerList) {
|
|
413
|
+
// Support partial matches (e.g., "matomo." matches "analytics.matomo.cloud")
|
|
414
|
+
if (domain.endsWith('.')) {
|
|
415
|
+
if (hostname.includes(domain.slice(0, -1))) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
} else if (hostname === domain || hostname.endsWith('.' + domain)) {
|
|
419
|
+
return true;
|
|
420
|
+
} else if (fullUrl.includes(domain)) {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
} catch (e) {
|
|
425
|
+
// Invalid URL
|
|
426
|
+
}
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Get category for a script URL based on tracker lists
|
|
432
|
+
*/
|
|
433
|
+
function getCategoryForScript(url, mode = 'safe') {
|
|
434
|
+
const trackers = mode === 'strict' ? STRICT_TRACKERS : SAFE_TRACKERS;
|
|
435
|
+
|
|
436
|
+
for (const [category, domains] of Object.entries(trackers)) {
|
|
437
|
+
if (matchesTrackerList(url, domains)) {
|
|
438
|
+
return category;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Check if URL is third-party (different domain)
|
|
447
|
+
*/
|
|
448
|
+
function isThirdParty(url) {
|
|
449
|
+
try {
|
|
450
|
+
const scriptHost = new URL(url).hostname;
|
|
451
|
+
const pageHost = window.location.hostname;
|
|
452
|
+
|
|
453
|
+
// Remove www. for comparison
|
|
454
|
+
const normalizeHost = (h) => h.replace(/^www\./, '');
|
|
455
|
+
|
|
456
|
+
return normalizeHost(scriptHost) !== normalizeHost(pageHost);
|
|
457
|
+
} catch (e) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Script Blocker - Blocks and manages consent-gated scripts
|
|
464
|
+
*
|
|
465
|
+
* Modes:
|
|
466
|
+
* - manual: Only blocks scripts with data-consent-category attribute
|
|
467
|
+
* - safe: Manual + known major trackers (Google, Facebook, etc.)
|
|
468
|
+
* - strict: Safe + extended tracker list (Hotjar, Mixpanel, etc.)
|
|
469
|
+
* - doomsday: Block ALL third-party scripts
|
|
470
|
+
*/
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
// Queue for blocked scripts
|
|
474
|
+
const scriptQueue = [];
|
|
475
|
+
|
|
476
|
+
// MutationObserver instance
|
|
477
|
+
let observer = null;
|
|
478
|
+
|
|
479
|
+
// Current blocking mode
|
|
480
|
+
let blockingMode = 'safe';
|
|
481
|
+
|
|
482
|
+
// Custom blocked domains (user-defined)
|
|
483
|
+
let customBlockedDomains = [];
|
|
484
|
+
|
|
485
|
+
// Reference to consent checker function
|
|
486
|
+
let checkConsent$1 = () => false;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Set the consent checker function
|
|
490
|
+
*/
|
|
491
|
+
function setConsentChecker(fn) {
|
|
492
|
+
checkConsent$1 = fn;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Check if script URL matches custom blocked domains
|
|
497
|
+
*/
|
|
498
|
+
function matchesCustomDomains(url) {
|
|
499
|
+
if (!url || customBlockedDomains.length === 0) return null;
|
|
500
|
+
|
|
501
|
+
try {
|
|
502
|
+
const hostname = new URL(url).hostname.toLowerCase();
|
|
503
|
+
|
|
504
|
+
for (const entry of customBlockedDomains) {
|
|
505
|
+
const domain = typeof entry === 'string' ? entry : entry.domain;
|
|
506
|
+
const category = typeof entry === 'string' ? 'marketing' : (entry.category || 'marketing');
|
|
507
|
+
|
|
508
|
+
if (hostname === domain || hostname.endsWith('.' + domain)) {
|
|
509
|
+
return category;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
} catch (e) {
|
|
513
|
+
// Invalid URL
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Determine if a script should be blocked and get its category
|
|
521
|
+
*/
|
|
522
|
+
function getScriptBlockCategory(script) {
|
|
523
|
+
// 1. Check for explicit data-consent-category attribute (always respected)
|
|
524
|
+
const explicitCategory = script.getAttribute('data-consent-category');
|
|
525
|
+
if (explicitCategory) {
|
|
526
|
+
return explicitCategory;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// 2. Skip if script has data-zest-allow attribute
|
|
530
|
+
if (script.hasAttribute('data-zest-allow')) {
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const src = script.src;
|
|
535
|
+
|
|
536
|
+
// No src = inline script, only block if explicitly tagged
|
|
537
|
+
if (!src) {
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// 3. Check custom blocked domains
|
|
542
|
+
const customCategory = matchesCustomDomains(src);
|
|
543
|
+
if (customCategory) {
|
|
544
|
+
return customCategory;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// 4. Mode-based blocking
|
|
548
|
+
switch (blockingMode) {
|
|
549
|
+
case 'manual':
|
|
550
|
+
// Only explicit tags, already checked above
|
|
551
|
+
return null;
|
|
552
|
+
|
|
553
|
+
case 'safe':
|
|
554
|
+
case 'strict':
|
|
555
|
+
// Check against known tracker lists
|
|
556
|
+
return getCategoryForScript(src, blockingMode);
|
|
557
|
+
|
|
558
|
+
case 'doomsday':
|
|
559
|
+
// Block all third-party scripts
|
|
560
|
+
if (isThirdParty(src)) {
|
|
561
|
+
// Try to categorize, default to marketing
|
|
562
|
+
return getCategoryForScript(src, 'strict') || 'marketing';
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
|
|
566
|
+
default:
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Block a script element
|
|
573
|
+
*/
|
|
574
|
+
function blockScript(script) {
|
|
575
|
+
// Skip already processed scripts
|
|
576
|
+
if (script.hasAttribute('data-zest-processed')) {
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const category = getScriptBlockCategory(script);
|
|
581
|
+
|
|
582
|
+
if (!category) {
|
|
583
|
+
script.setAttribute('data-zest-processed', 'allowed');
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (checkConsent$1(category)) {
|
|
588
|
+
// Consent already given - allow script
|
|
589
|
+
script.setAttribute('data-zest-processed', 'allowed');
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// Store script info for later execution
|
|
594
|
+
const scriptInfo = {
|
|
595
|
+
category,
|
|
596
|
+
src: script.src,
|
|
597
|
+
inline: script.textContent,
|
|
598
|
+
type: script.type,
|
|
599
|
+
async: script.async,
|
|
600
|
+
defer: script.defer,
|
|
601
|
+
timestamp: Date.now()
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
// Mark as processed
|
|
605
|
+
script.setAttribute('data-zest-processed', 'blocked');
|
|
606
|
+
script.setAttribute('data-consent-category', category);
|
|
607
|
+
|
|
608
|
+
// Disable the script
|
|
609
|
+
script.type = 'text/plain';
|
|
610
|
+
|
|
611
|
+
// If it has a src, also remove it to prevent loading
|
|
612
|
+
if (script.src) {
|
|
613
|
+
script.setAttribute('data-blocked-src', script.src);
|
|
614
|
+
script.removeAttribute('src');
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
scriptQueue.push(scriptInfo);
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Execute a queued script
|
|
623
|
+
*/
|
|
624
|
+
function executeScript(scriptInfo) {
|
|
625
|
+
const script = document.createElement('script');
|
|
626
|
+
|
|
627
|
+
if (scriptInfo.src) {
|
|
628
|
+
script.src = scriptInfo.src;
|
|
629
|
+
} else if (scriptInfo.inline) {
|
|
630
|
+
script.textContent = scriptInfo.inline;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (scriptInfo.async) script.async = true;
|
|
634
|
+
if (scriptInfo.defer) script.defer = true;
|
|
635
|
+
|
|
636
|
+
script.setAttribute('data-zest-processed', 'executed');
|
|
637
|
+
script.setAttribute('data-consent-executed', 'true');
|
|
638
|
+
|
|
639
|
+
document.head.appendChild(script);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Replay queued scripts for allowed categories
|
|
644
|
+
*/
|
|
645
|
+
function replayScripts(allowedCategories) {
|
|
646
|
+
const remaining = [];
|
|
647
|
+
|
|
648
|
+
for (const scriptInfo of scriptQueue) {
|
|
649
|
+
if (allowedCategories.includes(scriptInfo.category)) {
|
|
650
|
+
executeScript(scriptInfo);
|
|
651
|
+
} else {
|
|
652
|
+
remaining.push(scriptInfo);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
scriptQueue.length = 0;
|
|
657
|
+
scriptQueue.push(...remaining);
|
|
658
|
+
|
|
659
|
+
// Also re-enable any blocked scripts in the DOM
|
|
660
|
+
const blockedScripts = document.querySelectorAll('script[data-zest-processed="blocked"]');
|
|
661
|
+
blockedScripts.forEach(script => {
|
|
662
|
+
const category = script.getAttribute('data-consent-category');
|
|
663
|
+
if (allowedCategories.includes(category)) {
|
|
664
|
+
// Clone and replace to execute
|
|
665
|
+
const newScript = document.createElement('script');
|
|
666
|
+
|
|
667
|
+
const blockedSrc = script.getAttribute('data-blocked-src');
|
|
668
|
+
if (blockedSrc) {
|
|
669
|
+
newScript.src = blockedSrc;
|
|
670
|
+
} else {
|
|
671
|
+
newScript.textContent = script.textContent;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (script.async) newScript.async = true;
|
|
675
|
+
if (script.defer) newScript.defer = true;
|
|
676
|
+
|
|
677
|
+
newScript.setAttribute('data-zest-processed', 'executed');
|
|
678
|
+
newScript.setAttribute('data-consent-executed', 'true');
|
|
679
|
+
script.parentNode?.replaceChild(newScript, script);
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Process existing scripts in the DOM
|
|
686
|
+
*/
|
|
687
|
+
function processExistingScripts() {
|
|
688
|
+
const scripts = document.querySelectorAll('script:not([data-zest-processed])');
|
|
689
|
+
scripts.forEach(blockScript);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Handle mutations (new scripts added to DOM)
|
|
694
|
+
*/
|
|
695
|
+
function handleMutations(mutations) {
|
|
696
|
+
for (const mutation of mutations) {
|
|
697
|
+
for (const node of mutation.addedNodes) {
|
|
698
|
+
if (node.nodeName === 'SCRIPT' && !node.hasAttribute('data-zest-processed')) {
|
|
699
|
+
blockScript(node);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// Check child scripts
|
|
703
|
+
if (node.querySelectorAll) {
|
|
704
|
+
const scripts = node.querySelectorAll('script:not([data-zest-processed])');
|
|
705
|
+
scripts.forEach(blockScript);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Start observing for new scripts
|
|
713
|
+
*/
|
|
714
|
+
function startScriptBlocking(mode = 'safe', customDomains = []) {
|
|
715
|
+
blockingMode = mode;
|
|
716
|
+
customBlockedDomains = customDomains;
|
|
717
|
+
|
|
718
|
+
// Process existing scripts
|
|
719
|
+
processExistingScripts();
|
|
720
|
+
|
|
721
|
+
// Watch for new scripts
|
|
722
|
+
observer = new MutationObserver(handleMutations);
|
|
723
|
+
|
|
724
|
+
observer.observe(document.documentElement, {
|
|
725
|
+
childList: true,
|
|
726
|
+
subtree: true
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
return true;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Default consent categories
|
|
734
|
+
*/
|
|
735
|
+
const DEFAULT_CATEGORIES = {
|
|
736
|
+
essential: {
|
|
737
|
+
id: 'essential',
|
|
738
|
+
label: 'Essential',
|
|
739
|
+
description: 'Required for the website to function properly. Cannot be disabled.',
|
|
740
|
+
required: true,
|
|
741
|
+
default: true
|
|
742
|
+
},
|
|
743
|
+
functional: {
|
|
744
|
+
id: 'functional',
|
|
745
|
+
label: 'Functional',
|
|
746
|
+
description: 'Enable personalized features like language preferences and themes.',
|
|
747
|
+
required: false,
|
|
748
|
+
default: false
|
|
749
|
+
},
|
|
750
|
+
analytics: {
|
|
751
|
+
id: 'analytics',
|
|
752
|
+
label: 'Analytics',
|
|
753
|
+
description: 'Help us understand how visitors interact with our website.',
|
|
754
|
+
required: false,
|
|
755
|
+
default: false
|
|
756
|
+
},
|
|
757
|
+
marketing: {
|
|
758
|
+
id: 'marketing',
|
|
759
|
+
label: 'Marketing',
|
|
760
|
+
description: 'Used to deliver relevant advertisements and track campaign performance.',
|
|
761
|
+
required: false,
|
|
762
|
+
default: false
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Default consent state
|
|
768
|
+
*/
|
|
769
|
+
function getDefaultConsent() {
|
|
770
|
+
return {
|
|
771
|
+
essential: true,
|
|
772
|
+
functional: false,
|
|
773
|
+
analytics: false,
|
|
774
|
+
marketing: false
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Get all category IDs
|
|
780
|
+
*/
|
|
781
|
+
function getCategoryIds() {
|
|
782
|
+
return Object.keys(DEFAULT_CATEGORIES);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Do Not Track (DNT) Detection
|
|
787
|
+
*
|
|
788
|
+
* Detects browser DNT/GPC signals for privacy compliance
|
|
789
|
+
*/
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Check if Do Not Track is enabled
|
|
793
|
+
* Checks both DNT header and Global Privacy Control (GPC)
|
|
794
|
+
*/
|
|
795
|
+
function isDoNotTrackEnabled() {
|
|
796
|
+
if (typeof navigator === 'undefined') {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// Check DNT (Do Not Track)
|
|
801
|
+
// Values: "1" = enabled, "0" = disabled, null/undefined = not set
|
|
802
|
+
const dnt = navigator.doNotTrack ||
|
|
803
|
+
window.doNotTrack ||
|
|
804
|
+
navigator.msDoNotTrack;
|
|
805
|
+
|
|
806
|
+
if (dnt === '1' || dnt === 'yes' || dnt === true) {
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
// Check GPC (Global Privacy Control) - newer standard
|
|
811
|
+
// https://globalprivacycontrol.org/
|
|
812
|
+
if (navigator.globalPrivacyControl === true) {
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Get DNT signal details for logging/debugging
|
|
821
|
+
*/
|
|
822
|
+
function getDNTDetails() {
|
|
823
|
+
if (typeof navigator === 'undefined') {
|
|
824
|
+
return { enabled: false, source: null };
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
const dnt = navigator.doNotTrack ||
|
|
828
|
+
window.doNotTrack ||
|
|
829
|
+
navigator.msDoNotTrack;
|
|
830
|
+
|
|
831
|
+
if (dnt === '1' || dnt === 'yes' || dnt === true) {
|
|
832
|
+
return { enabled: true, source: 'dnt' };
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (navigator.globalPrivacyControl === true) {
|
|
836
|
+
return { enabled: true, source: 'gpc' };
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
return { enabled: false, source: null };
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Built-in translations for Zest
|
|
844
|
+
* Language is auto-detected from <html lang=""> or navigator.language
|
|
845
|
+
*/
|
|
846
|
+
|
|
847
|
+
const translations = {
|
|
848
|
+
en: {
|
|
849
|
+
labels: {
|
|
850
|
+
banner: {
|
|
851
|
+
title: 'We value your privacy',
|
|
852
|
+
description: 'We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.',
|
|
853
|
+
acceptAll: 'Accept All',
|
|
854
|
+
rejectAll: 'Reject All',
|
|
855
|
+
settings: 'Settings'
|
|
856
|
+
},
|
|
857
|
+
modal: {
|
|
858
|
+
title: 'Privacy Settings',
|
|
859
|
+
description: 'Manage your cookie preferences. You can enable or disable different types of cookies below.',
|
|
860
|
+
save: 'Save Preferences',
|
|
861
|
+
acceptAll: 'Accept All',
|
|
862
|
+
rejectAll: 'Reject All'
|
|
863
|
+
},
|
|
864
|
+
widget: {
|
|
865
|
+
label: 'Cookie Settings'
|
|
866
|
+
}
|
|
867
|
+
},
|
|
868
|
+
categories: {
|
|
869
|
+
essential: {
|
|
870
|
+
label: 'Essential',
|
|
871
|
+
description: 'Required for the website to function properly. Cannot be disabled.'
|
|
872
|
+
},
|
|
873
|
+
functional: {
|
|
874
|
+
label: 'Functional',
|
|
875
|
+
description: 'Enable personalized features like language preferences and themes.'
|
|
876
|
+
},
|
|
877
|
+
analytics: {
|
|
878
|
+
label: 'Analytics',
|
|
879
|
+
description: 'Help us understand how visitors interact with our website.'
|
|
880
|
+
},
|
|
881
|
+
marketing: {
|
|
882
|
+
label: 'Marketing',
|
|
883
|
+
description: 'Used to deliver relevant advertisements and track campaign performance.'
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
},
|
|
887
|
+
|
|
888
|
+
de: {
|
|
889
|
+
labels: {
|
|
890
|
+
banner: {
|
|
891
|
+
title: 'Wir respektieren Ihre Privatsphäre',
|
|
892
|
+
description: 'Wir verwenden Cookies, um Ihr Surferlebnis zu verbessern, personalisierte Inhalte bereitzustellen und unseren Datenverkehr zu analysieren. Mit einem Klick auf „Alle akzeptieren" stimmen Sie der Verwendung von Cookies zu.',
|
|
893
|
+
acceptAll: 'Alle akzeptieren',
|
|
894
|
+
rejectAll: 'Alle ablehnen',
|
|
895
|
+
settings: 'Einstellungen'
|
|
896
|
+
},
|
|
897
|
+
modal: {
|
|
898
|
+
title: 'Datenschutzeinstellungen',
|
|
899
|
+
description: 'Verwalten Sie Ihre Cookie-Einstellungen. Sie können verschiedene Arten von Cookies unten aktivieren oder deaktivieren.',
|
|
900
|
+
save: 'Einstellungen speichern',
|
|
901
|
+
acceptAll: 'Alle akzeptieren',
|
|
902
|
+
rejectAll: 'Alle ablehnen'
|
|
903
|
+
},
|
|
904
|
+
widget: {
|
|
905
|
+
label: 'Cookie-Einstellungen'
|
|
906
|
+
}
|
|
907
|
+
},
|
|
908
|
+
categories: {
|
|
909
|
+
essential: {
|
|
910
|
+
label: 'Notwendig',
|
|
911
|
+
description: 'Erforderlich für die ordnungsgemäße Funktion der Website. Können nicht deaktiviert werden.'
|
|
912
|
+
},
|
|
913
|
+
functional: {
|
|
914
|
+
label: 'Funktional',
|
|
915
|
+
description: 'Ermöglichen personalisierte Funktionen wie Spracheinstellungen und Designs.'
|
|
916
|
+
},
|
|
917
|
+
analytics: {
|
|
918
|
+
label: 'Analytisch',
|
|
919
|
+
description: 'Helfen uns zu verstehen, wie Besucher mit unserer Website interagieren.'
|
|
920
|
+
},
|
|
921
|
+
marketing: {
|
|
922
|
+
label: 'Marketing',
|
|
923
|
+
description: 'Werden verwendet, um relevante Werbung anzuzeigen und die Kampagnenleistung zu messen.'
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
},
|
|
927
|
+
|
|
928
|
+
es: {
|
|
929
|
+
labels: {
|
|
930
|
+
banner: {
|
|
931
|
+
title: 'Valoramos tu privacidad',
|
|
932
|
+
description: 'Utilizamos cookies para mejorar tu experiencia de navegación, ofrecer contenido personalizado y analizar nuestro tráfico. Al hacer clic en "Aceptar todo", consientes el uso de cookies.',
|
|
933
|
+
acceptAll: 'Aceptar todo',
|
|
934
|
+
rejectAll: 'Rechazar todo',
|
|
935
|
+
settings: 'Configuración'
|
|
936
|
+
},
|
|
937
|
+
modal: {
|
|
938
|
+
title: 'Configuración de privacidad',
|
|
939
|
+
description: 'Gestiona tus preferencias de cookies. Puedes activar o desactivar diferentes tipos de cookies a continuación.',
|
|
940
|
+
save: 'Guardar preferencias',
|
|
941
|
+
acceptAll: 'Aceptar todo',
|
|
942
|
+
rejectAll: 'Rechazar todo'
|
|
943
|
+
},
|
|
944
|
+
widget: {
|
|
945
|
+
label: 'Configuración de cookies'
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
categories: {
|
|
949
|
+
essential: {
|
|
950
|
+
label: 'Esenciales',
|
|
951
|
+
description: 'Necesarias para el funcionamiento del sitio web. No se pueden desactivar.'
|
|
952
|
+
},
|
|
953
|
+
functional: {
|
|
954
|
+
label: 'Funcionales',
|
|
955
|
+
description: 'Permiten funciones personalizadas como preferencias de idioma y temas.'
|
|
956
|
+
},
|
|
957
|
+
analytics: {
|
|
958
|
+
label: 'Analíticas',
|
|
959
|
+
description: 'Nos ayudan a entender cómo los visitantes interactúan con nuestro sitio web.'
|
|
960
|
+
},
|
|
961
|
+
marketing: {
|
|
962
|
+
label: 'Marketing',
|
|
963
|
+
description: 'Se utilizan para mostrar anuncios relevantes y medir el rendimiento de las campañas.'
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
},
|
|
967
|
+
|
|
968
|
+
fr: {
|
|
969
|
+
labels: {
|
|
970
|
+
banner: {
|
|
971
|
+
title: 'Nous respectons votre vie privée',
|
|
972
|
+
description: 'Nous utilisons des cookies pour améliorer votre expérience de navigation, proposer du contenu personnalisé et analyser notre trafic. En cliquant sur « Tout accepter », vous consentez à l\'utilisation de cookies.',
|
|
973
|
+
acceptAll: 'Tout accepter',
|
|
974
|
+
rejectAll: 'Tout refuser',
|
|
975
|
+
settings: 'Paramètres'
|
|
976
|
+
},
|
|
977
|
+
modal: {
|
|
978
|
+
title: 'Paramètres de confidentialité',
|
|
979
|
+
description: 'Gérez vos préférences en matière de cookies. Vous pouvez activer ou désactiver différents types de cookies ci-dessous.',
|
|
980
|
+
save: 'Enregistrer les préférences',
|
|
981
|
+
acceptAll: 'Tout accepter',
|
|
982
|
+
rejectAll: 'Tout refuser'
|
|
983
|
+
},
|
|
984
|
+
widget: {
|
|
985
|
+
label: 'Paramètres des cookies'
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
categories: {
|
|
989
|
+
essential: {
|
|
990
|
+
label: 'Essentiels',
|
|
991
|
+
description: 'Nécessaires au bon fonctionnement du site. Ne peuvent pas être désactivés.'
|
|
992
|
+
},
|
|
993
|
+
functional: {
|
|
994
|
+
label: 'Fonctionnels',
|
|
995
|
+
description: 'Permettent des fonctionnalités personnalisées comme les préférences de langue et de thème.'
|
|
996
|
+
},
|
|
997
|
+
analytics: {
|
|
998
|
+
label: 'Analytiques',
|
|
999
|
+
description: 'Nous aident à comprendre comment les visiteurs interagissent avec notre site.'
|
|
1000
|
+
},
|
|
1001
|
+
marketing: {
|
|
1002
|
+
label: 'Marketing',
|
|
1003
|
+
description: 'Utilisés pour afficher des publicités pertinentes et mesurer les performances des campagnes.'
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
},
|
|
1007
|
+
|
|
1008
|
+
it: {
|
|
1009
|
+
labels: {
|
|
1010
|
+
banner: {
|
|
1011
|
+
title: 'Rispettiamo la tua privacy',
|
|
1012
|
+
description: 'Utilizziamo i cookie per migliorare la tua esperienza di navigazione, fornire contenuti personalizzati e analizzare il nostro traffico. Cliccando su "Accetta tutto", acconsenti all\'uso dei cookie.',
|
|
1013
|
+
acceptAll: 'Accetta tutto',
|
|
1014
|
+
rejectAll: 'Rifiuta tutto',
|
|
1015
|
+
settings: 'Impostazioni'
|
|
1016
|
+
},
|
|
1017
|
+
modal: {
|
|
1018
|
+
title: 'Impostazioni privacy',
|
|
1019
|
+
description: 'Gestisci le tue preferenze sui cookie. Puoi attivare o disattivare diversi tipi di cookie qui sotto.',
|
|
1020
|
+
save: 'Salva preferenze',
|
|
1021
|
+
acceptAll: 'Accetta tutto',
|
|
1022
|
+
rejectAll: 'Rifiuta tutto'
|
|
1023
|
+
},
|
|
1024
|
+
widget: {
|
|
1025
|
+
label: 'Impostazioni cookie'
|
|
1026
|
+
}
|
|
1027
|
+
},
|
|
1028
|
+
categories: {
|
|
1029
|
+
essential: {
|
|
1030
|
+
label: 'Essenziali',
|
|
1031
|
+
description: 'Necessari per il corretto funzionamento del sito. Non possono essere disattivati.'
|
|
1032
|
+
},
|
|
1033
|
+
functional: {
|
|
1034
|
+
label: 'Funzionali',
|
|
1035
|
+
description: 'Abilitano funzionalità personalizzate come preferenze di lingua e tema.'
|
|
1036
|
+
},
|
|
1037
|
+
analytics: {
|
|
1038
|
+
label: 'Analitici',
|
|
1039
|
+
description: 'Ci aiutano a capire come i visitatori interagiscono con il nostro sito.'
|
|
1040
|
+
},
|
|
1041
|
+
marketing: {
|
|
1042
|
+
label: 'Marketing',
|
|
1043
|
+
description: 'Utilizzati per mostrare annunci pertinenti e misurare le prestazioni delle campagne.'
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
},
|
|
1047
|
+
|
|
1048
|
+
pt: {
|
|
1049
|
+
labels: {
|
|
1050
|
+
banner: {
|
|
1051
|
+
title: 'Valorizamos sua privacidade',
|
|
1052
|
+
description: 'Usamos cookies para melhorar sua experiência de navegação, fornecer conteúdo personalizado e analisar nosso tráfego. Ao clicar em "Aceitar tudo", você consente com o uso de cookies.',
|
|
1053
|
+
acceptAll: 'Aceitar tudo',
|
|
1054
|
+
rejectAll: 'Rejeitar tudo',
|
|
1055
|
+
settings: 'Configurações'
|
|
1056
|
+
},
|
|
1057
|
+
modal: {
|
|
1058
|
+
title: 'Configurações de privacidade',
|
|
1059
|
+
description: 'Gerencie suas preferências de cookies. Você pode ativar ou desativar diferentes tipos de cookies abaixo.',
|
|
1060
|
+
save: 'Salvar preferências',
|
|
1061
|
+
acceptAll: 'Aceitar tudo',
|
|
1062
|
+
rejectAll: 'Rejeitar tudo'
|
|
1063
|
+
},
|
|
1064
|
+
widget: {
|
|
1065
|
+
label: 'Configurações de cookies'
|
|
1066
|
+
}
|
|
1067
|
+
},
|
|
1068
|
+
categories: {
|
|
1069
|
+
essential: {
|
|
1070
|
+
label: 'Essenciais',
|
|
1071
|
+
description: 'Necessários para o funcionamento do site. Não podem ser desativados.'
|
|
1072
|
+
},
|
|
1073
|
+
functional: {
|
|
1074
|
+
label: 'Funcionais',
|
|
1075
|
+
description: 'Permitem recursos personalizados como preferências de idioma e tema.'
|
|
1076
|
+
},
|
|
1077
|
+
analytics: {
|
|
1078
|
+
label: 'Analíticos',
|
|
1079
|
+
description: 'Nos ajudam a entender como os visitantes interagem com nosso site.'
|
|
1080
|
+
},
|
|
1081
|
+
marketing: {
|
|
1082
|
+
label: 'Marketing',
|
|
1083
|
+
description: 'Usados para exibir anúncios relevantes e medir o desempenho de campanhas.'
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
|
|
1088
|
+
nl: {
|
|
1089
|
+
labels: {
|
|
1090
|
+
banner: {
|
|
1091
|
+
title: 'Wij respecteren uw privacy',
|
|
1092
|
+
description: 'Wij gebruiken cookies om uw browse-ervaring te verbeteren, gepersonaliseerde inhoud aan te bieden en ons verkeer te analyseren. Door op "Alles accepteren" te klikken, stemt u in met het gebruik van cookies.',
|
|
1093
|
+
acceptAll: 'Alles accepteren',
|
|
1094
|
+
rejectAll: 'Alles weigeren',
|
|
1095
|
+
settings: 'Instellingen'
|
|
1096
|
+
},
|
|
1097
|
+
modal: {
|
|
1098
|
+
title: 'Privacy-instellingen',
|
|
1099
|
+
description: 'Beheer uw cookievoorkeuren. U kunt hieronder verschillende soorten cookies in- of uitschakelen.',
|
|
1100
|
+
save: 'Voorkeuren opslaan',
|
|
1101
|
+
acceptAll: 'Alles accepteren',
|
|
1102
|
+
rejectAll: 'Alles weigeren'
|
|
1103
|
+
},
|
|
1104
|
+
widget: {
|
|
1105
|
+
label: 'Cookie-instellingen'
|
|
1106
|
+
}
|
|
1107
|
+
},
|
|
1108
|
+
categories: {
|
|
1109
|
+
essential: {
|
|
1110
|
+
label: 'Essentieel',
|
|
1111
|
+
description: 'Noodzakelijk voor de goede werking van de website. Kunnen niet worden uitgeschakeld.'
|
|
1112
|
+
},
|
|
1113
|
+
functional: {
|
|
1114
|
+
label: 'Functioneel',
|
|
1115
|
+
description: 'Maken gepersonaliseerde functies mogelijk zoals taal- en themavoorkeuren.'
|
|
1116
|
+
},
|
|
1117
|
+
analytics: {
|
|
1118
|
+
label: 'Analytisch',
|
|
1119
|
+
description: 'Helpen ons te begrijpen hoe bezoekers onze website gebruiken.'
|
|
1120
|
+
},
|
|
1121
|
+
marketing: {
|
|
1122
|
+
label: 'Marketing',
|
|
1123
|
+
description: 'Worden gebruikt om relevante advertenties te tonen en campagneprestaties te meten.'
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
|
|
1128
|
+
pl: {
|
|
1129
|
+
labels: {
|
|
1130
|
+
banner: {
|
|
1131
|
+
title: 'Szanujemy Twoją prywatność',
|
|
1132
|
+
description: 'Używamy plików cookie, aby poprawić Twoje wrażenia z przeglądania, dostarczać spersonalizowane treści i analizować nasz ruch. Klikając „Zaakceptuj wszystko", wyrażasz zgodę na używanie plików cookie.',
|
|
1133
|
+
acceptAll: 'Zaakceptuj wszystko',
|
|
1134
|
+
rejectAll: 'Odrzuć wszystko',
|
|
1135
|
+
settings: 'Ustawienia'
|
|
1136
|
+
},
|
|
1137
|
+
modal: {
|
|
1138
|
+
title: 'Ustawienia prywatności',
|
|
1139
|
+
description: 'Zarządzaj swoimi preferencjami dotyczącymi plików cookie. Możesz włączyć lub wyłączyć różne typy plików cookie poniżej.',
|
|
1140
|
+
save: 'Zapisz preferencje',
|
|
1141
|
+
acceptAll: 'Zaakceptuj wszystko',
|
|
1142
|
+
rejectAll: 'Odrzuć wszystko'
|
|
1143
|
+
},
|
|
1144
|
+
widget: {
|
|
1145
|
+
label: 'Ustawienia plików cookie'
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
categories: {
|
|
1149
|
+
essential: {
|
|
1150
|
+
label: 'Niezbędne',
|
|
1151
|
+
description: 'Wymagane do prawidłowego działania strony. Nie można ich wyłączyć.'
|
|
1152
|
+
},
|
|
1153
|
+
functional: {
|
|
1154
|
+
label: 'Funkcjonalne',
|
|
1155
|
+
description: 'Umożliwiają spersonalizowane funkcje, takie jak preferencje językowe i motywy.'
|
|
1156
|
+
},
|
|
1157
|
+
analytics: {
|
|
1158
|
+
label: 'Analityczne',
|
|
1159
|
+
description: 'Pomagają nam zrozumieć, jak odwiedzający korzystają z naszej strony.'
|
|
1160
|
+
},
|
|
1161
|
+
marketing: {
|
|
1162
|
+
label: 'Marketingowe',
|
|
1163
|
+
description: 'Służą do wyświetlania odpowiednich reklam i mierzenia skuteczności kampanii.'
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
|
|
1168
|
+
uk: {
|
|
1169
|
+
labels: {
|
|
1170
|
+
banner: {
|
|
1171
|
+
title: 'Ми цінуємо вашу конфіденційність',
|
|
1172
|
+
description: 'Ми використовуємо файли cookie для покращення вашого досвіду перегляду, надання персоналізованого контенту та аналізу нашого трафіку. Натискаючи «Прийняти все», ви погоджуєтесь на використання файлів cookie.',
|
|
1173
|
+
acceptAll: 'Прийняти все',
|
|
1174
|
+
rejectAll: 'Відхилити все',
|
|
1175
|
+
settings: 'Налаштування'
|
|
1176
|
+
},
|
|
1177
|
+
modal: {
|
|
1178
|
+
title: 'Налаштування конфіденційності',
|
|
1179
|
+
description: 'Керуйте своїми налаштуваннями файлів cookie. Ви можете ввімкнути або вимкнути різні типи файлів cookie нижче.',
|
|
1180
|
+
save: 'Зберегти налаштування',
|
|
1181
|
+
acceptAll: 'Прийняти все',
|
|
1182
|
+
rejectAll: 'Відхилити все'
|
|
1183
|
+
},
|
|
1184
|
+
widget: {
|
|
1185
|
+
label: 'Налаштування cookie'
|
|
1186
|
+
}
|
|
1187
|
+
},
|
|
1188
|
+
categories: {
|
|
1189
|
+
essential: {
|
|
1190
|
+
label: 'Необхідні',
|
|
1191
|
+
description: 'Потрібні для правильної роботи сайту. Не можуть бути вимкнені.'
|
|
1192
|
+
},
|
|
1193
|
+
functional: {
|
|
1194
|
+
label: 'Функціональні',
|
|
1195
|
+
description: 'Дозволяють персоналізовані функції, такі як мовні налаштування та теми.'
|
|
1196
|
+
},
|
|
1197
|
+
analytics: {
|
|
1198
|
+
label: 'Аналітичні',
|
|
1199
|
+
description: 'Допомагають нам зрозуміти, як відвідувачі взаємодіють з нашим сайтом.'
|
|
1200
|
+
},
|
|
1201
|
+
marketing: {
|
|
1202
|
+
label: 'Маркетингові',
|
|
1203
|
+
description: 'Використовуються для показу релевантної реклами та вимірювання ефективності кампаній.'
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
|
|
1208
|
+
ru: {
|
|
1209
|
+
labels: {
|
|
1210
|
+
banner: {
|
|
1211
|
+
title: 'Мы ценим вашу конфиденциальность',
|
|
1212
|
+
description: 'Мы используем файлы cookie для улучшения вашего опыта просмотра, предоставления персонализированного контента и анализа нашего трафика. Нажимая «Принять все», вы соглашаетесь на использование файлов cookie.',
|
|
1213
|
+
acceptAll: 'Принять все',
|
|
1214
|
+
rejectAll: 'Отклонить все',
|
|
1215
|
+
settings: 'Настройки'
|
|
1216
|
+
},
|
|
1217
|
+
modal: {
|
|
1218
|
+
title: 'Настройки конфиденциальности',
|
|
1219
|
+
description: 'Управляйте своими настройками файлов cookie. Вы можете включить или отключить различные типы файлов cookie ниже.',
|
|
1220
|
+
save: 'Сохранить настройки',
|
|
1221
|
+
acceptAll: 'Принять все',
|
|
1222
|
+
rejectAll: 'Отклонить все'
|
|
1223
|
+
},
|
|
1224
|
+
widget: {
|
|
1225
|
+
label: 'Настройки cookie'
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
1228
|
+
categories: {
|
|
1229
|
+
essential: {
|
|
1230
|
+
label: 'Необходимые',
|
|
1231
|
+
description: 'Требуются для правильной работы сайта. Не могут быть отключены.'
|
|
1232
|
+
},
|
|
1233
|
+
functional: {
|
|
1234
|
+
label: 'Функциональные',
|
|
1235
|
+
description: 'Позволяют использовать персонализированные функции, такие как языковые настройки и темы.'
|
|
1236
|
+
},
|
|
1237
|
+
analytics: {
|
|
1238
|
+
label: 'Аналитические',
|
|
1239
|
+
description: 'Помогают нам понять, как посетители взаимодействуют с нашим сайтом.'
|
|
1240
|
+
},
|
|
1241
|
+
marketing: {
|
|
1242
|
+
label: 'Маркетинговые',
|
|
1243
|
+
description: 'Используются для показа релевантной рекламы и измерения эффективности кампаний.'
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
},
|
|
1247
|
+
|
|
1248
|
+
ja: {
|
|
1249
|
+
labels: {
|
|
1250
|
+
banner: {
|
|
1251
|
+
title: 'プライバシーを尊重します',
|
|
1252
|
+
description: '当サイトでは、ブラウジング体験の向上、パーソナライズされたコンテンツの提供、トラフィックの分析のためにCookieを使用しています。「すべて同意」をクリックすると、Cookieの使用に同意したことになります。',
|
|
1253
|
+
acceptAll: 'すべて同意',
|
|
1254
|
+
rejectAll: 'すべて拒否',
|
|
1255
|
+
settings: '設定'
|
|
1256
|
+
},
|
|
1257
|
+
modal: {
|
|
1258
|
+
title: 'プライバシー設定',
|
|
1259
|
+
description: 'Cookieの設定を管理できます。以下で各種Cookieを有効または無効にできます。',
|
|
1260
|
+
save: '設定を保存',
|
|
1261
|
+
acceptAll: 'すべて同意',
|
|
1262
|
+
rejectAll: 'すべて拒否'
|
|
1263
|
+
},
|
|
1264
|
+
widget: {
|
|
1265
|
+
label: 'Cookie設定'
|
|
1266
|
+
}
|
|
1267
|
+
},
|
|
1268
|
+
categories: {
|
|
1269
|
+
essential: {
|
|
1270
|
+
label: '必須',
|
|
1271
|
+
description: 'サイトの正常な動作に必要です。無効にすることはできません。'
|
|
1272
|
+
},
|
|
1273
|
+
functional: {
|
|
1274
|
+
label: '機能性',
|
|
1275
|
+
description: '言語設定やテーマなどのパーソナライズ機能を有効にします。'
|
|
1276
|
+
},
|
|
1277
|
+
analytics: {
|
|
1278
|
+
label: '分析',
|
|
1279
|
+
description: '訪問者がサイトをどのように利用しているかを理解するのに役立ちます。'
|
|
1280
|
+
},
|
|
1281
|
+
marketing: {
|
|
1282
|
+
label: 'マーケティング',
|
|
1283
|
+
description: '関連性の高い広告を表示し、キャンペーンの効果を測定するために使用されます。'
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
|
|
1288
|
+
zh: {
|
|
1289
|
+
labels: {
|
|
1290
|
+
banner: {
|
|
1291
|
+
title: '我们重视您的隐私',
|
|
1292
|
+
description: '我们使用Cookie来改善您的浏览体验、提供个性化内容并分析我们的流量。点击"全部接受"即表示您同意我们使用Cookie。',
|
|
1293
|
+
acceptAll: '全部接受',
|
|
1294
|
+
rejectAll: '全部拒绝',
|
|
1295
|
+
settings: '设置'
|
|
1296
|
+
},
|
|
1297
|
+
modal: {
|
|
1298
|
+
title: '隐私设置',
|
|
1299
|
+
description: '管理您的Cookie偏好设置。您可以在下方启用或禁用不同类型的Cookie。',
|
|
1300
|
+
save: '保存设置',
|
|
1301
|
+
acceptAll: '全部接受',
|
|
1302
|
+
rejectAll: '全部拒绝'
|
|
1303
|
+
},
|
|
1304
|
+
widget: {
|
|
1305
|
+
label: 'Cookie设置'
|
|
1306
|
+
}
|
|
1307
|
+
},
|
|
1308
|
+
categories: {
|
|
1309
|
+
essential: {
|
|
1310
|
+
label: '必要',
|
|
1311
|
+
description: '网站正常运行所必需的。无法禁用。'
|
|
1312
|
+
},
|
|
1313
|
+
functional: {
|
|
1314
|
+
label: '功能性',
|
|
1315
|
+
description: '启用个性化功能,如语言偏好和主题设置。'
|
|
1316
|
+
},
|
|
1317
|
+
analytics: {
|
|
1318
|
+
label: '分析',
|
|
1319
|
+
description: '帮助我们了解访问者如何与网站互动。'
|
|
1320
|
+
},
|
|
1321
|
+
marketing: {
|
|
1322
|
+
label: '营销',
|
|
1323
|
+
description: '用于展示相关广告并衡量营销活动效果。'
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
/**
|
|
1330
|
+
* Detect language from various sources
|
|
1331
|
+
* Priority: config.lang > <html lang=""> > navigator.language > 'en'
|
|
1332
|
+
*/
|
|
1333
|
+
function detectLanguage(configLang) {
|
|
1334
|
+
// 1. Explicit config
|
|
1335
|
+
if (configLang && configLang !== 'auto') {
|
|
1336
|
+
return normalizeLanguage(configLang);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// 2. HTML lang attribute
|
|
1340
|
+
const htmlLang = document.documentElement.lang;
|
|
1341
|
+
if (htmlLang) {
|
|
1342
|
+
const normalized = normalizeLanguage(htmlLang);
|
|
1343
|
+
if (translations[normalized]) {
|
|
1344
|
+
return normalized;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
// 3. Browser language
|
|
1349
|
+
if (typeof navigator !== 'undefined' && navigator.language) {
|
|
1350
|
+
const normalized = normalizeLanguage(navigator.language);
|
|
1351
|
+
if (translations[normalized]) {
|
|
1352
|
+
return normalized;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// 4. Default to English
|
|
1357
|
+
return 'en';
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* Normalize language code (e.g., 'en-US' -> 'en', 'es_MX' -> 'es')
|
|
1362
|
+
*/
|
|
1363
|
+
function normalizeLanguage(lang) {
|
|
1364
|
+
if (!lang) return 'en';
|
|
1365
|
+
|
|
1366
|
+
// ISO 639-1 language codes are always 2 characters
|
|
1367
|
+
const base = lang.slice(0, 2).toLowerCase();
|
|
1368
|
+
|
|
1369
|
+
// Check if we support it
|
|
1370
|
+
if (translations[base]) {
|
|
1371
|
+
return base;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
return 'en';
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
/**
|
|
1378
|
+
* Get translation for a language
|
|
1379
|
+
*/
|
|
1380
|
+
function getTranslation(lang) {
|
|
1381
|
+
return translations[lang] || translations.en;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
/**
|
|
1385
|
+
* Default configuration values
|
|
1386
|
+
*/
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
const DEFAULTS = {
|
|
1390
|
+
// Language: 'auto' | 'en' | 'de' | 'es' | 'fr' | 'it' | 'pt' | 'nl' | 'pl' | 'uk' | 'ru' | 'ja' | 'zh'
|
|
1391
|
+
lang: 'auto',
|
|
1392
|
+
|
|
1393
|
+
// UI positioning
|
|
1394
|
+
position: 'bottom', // 'bottom' | 'bottom-left' | 'bottom-right' | 'top'
|
|
1395
|
+
|
|
1396
|
+
// Theming
|
|
1397
|
+
theme: 'auto', // 'light' | 'dark' | 'auto'
|
|
1398
|
+
accentColor: '#0071e3',
|
|
1399
|
+
|
|
1400
|
+
// Categories
|
|
1401
|
+
categories: DEFAULT_CATEGORIES,
|
|
1402
|
+
|
|
1403
|
+
// UI Labels
|
|
1404
|
+
labels: {
|
|
1405
|
+
banner: {
|
|
1406
|
+
title: 'We value your privacy',
|
|
1407
|
+
description: 'We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.',
|
|
1408
|
+
acceptAll: 'Accept All',
|
|
1409
|
+
rejectAll: 'Reject All',
|
|
1410
|
+
settings: 'Settings'
|
|
1411
|
+
},
|
|
1412
|
+
modal: {
|
|
1413
|
+
title: 'Privacy Settings',
|
|
1414
|
+
description: 'Manage your cookie preferences. You can enable or disable different types of cookies below.',
|
|
1415
|
+
save: 'Save Preferences',
|
|
1416
|
+
acceptAll: 'Accept All',
|
|
1417
|
+
rejectAll: 'Reject All'
|
|
1418
|
+
},
|
|
1419
|
+
widget: {
|
|
1420
|
+
label: 'Cookie Settings'
|
|
1421
|
+
}
|
|
1422
|
+
},
|
|
1423
|
+
|
|
1424
|
+
// Behavior
|
|
1425
|
+
autoInit: true,
|
|
1426
|
+
showWidget: true,
|
|
1427
|
+
expiration: 365,
|
|
1428
|
+
|
|
1429
|
+
// Do Not Track / Global Privacy Control
|
|
1430
|
+
// respectDNT: true = respect DNT/GPC signals
|
|
1431
|
+
// dntBehavior: 'reject' | 'preselect' | 'ignore'
|
|
1432
|
+
// - 'reject': auto-reject non-essential, don't show banner
|
|
1433
|
+
// - 'preselect': show banner with non-essential unchecked (same as normal)
|
|
1434
|
+
// - 'ignore': ignore DNT completely
|
|
1435
|
+
respectDNT: true,
|
|
1436
|
+
dntBehavior: 'reject',
|
|
1437
|
+
|
|
1438
|
+
// Custom styles to inject into Shadow DOM
|
|
1439
|
+
customStyles: '',
|
|
1440
|
+
|
|
1441
|
+
// Blocking mode: 'manual' | 'safe' | 'strict' | 'doomsday'
|
|
1442
|
+
mode: 'safe',
|
|
1443
|
+
|
|
1444
|
+
// Custom domains to block (in addition to mode-based blocking)
|
|
1445
|
+
blockedDomains: [], // days
|
|
1446
|
+
|
|
1447
|
+
// Links
|
|
1448
|
+
policyUrl: null,
|
|
1449
|
+
imprintUrl: null,
|
|
1450
|
+
|
|
1451
|
+
// Callbacks
|
|
1452
|
+
callbacks: {
|
|
1453
|
+
onAccept: null,
|
|
1454
|
+
onReject: null,
|
|
1455
|
+
onChange: null,
|
|
1456
|
+
onReady: null
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* Merge user config with defaults (deep merge)
|
|
1462
|
+
*/
|
|
1463
|
+
function mergeConfig(userConfig) {
|
|
1464
|
+
const config = { ...DEFAULTS };
|
|
1465
|
+
|
|
1466
|
+
if (!userConfig) {
|
|
1467
|
+
userConfig = {};
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// Simple properties
|
|
1471
|
+
const simpleKeys = ['lang', 'position', 'theme', 'accentColor', 'autoInit', 'showWidget', 'expiration', 'policyUrl', 'imprintUrl', 'customStyles', 'mode', 'blockedDomains', 'respectDNT', 'dntBehavior'];
|
|
1472
|
+
for (const key of simpleKeys) {
|
|
1473
|
+
if (userConfig[key] !== undefined) {
|
|
1474
|
+
config[key] = userConfig[key];
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// Detect language and get translations
|
|
1479
|
+
const detectedLang = detectLanguage(config.lang);
|
|
1480
|
+
config.lang = detectedLang;
|
|
1481
|
+
const translation = getTranslation(detectedLang);
|
|
1482
|
+
|
|
1483
|
+
// Deep merge labels (translation < user config)
|
|
1484
|
+
const translationLabels = translation.labels || {};
|
|
1485
|
+
const userLabels = userConfig.labels || {};
|
|
1486
|
+
config.labels = {
|
|
1487
|
+
banner: {
|
|
1488
|
+
...DEFAULTS.labels.banner,
|
|
1489
|
+
...translationLabels.banner,
|
|
1490
|
+
...userLabels.banner
|
|
1491
|
+
},
|
|
1492
|
+
modal: {
|
|
1493
|
+
...DEFAULTS.labels.modal,
|
|
1494
|
+
...translationLabels.modal,
|
|
1495
|
+
...userLabels.modal
|
|
1496
|
+
},
|
|
1497
|
+
widget: {
|
|
1498
|
+
...DEFAULTS.labels.widget,
|
|
1499
|
+
...translationLabels.widget,
|
|
1500
|
+
...userLabels.widget
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
// Deep merge categories (translation < user config)
|
|
1505
|
+
const translationCategories = translation.categories || {};
|
|
1506
|
+
const userCategories = userConfig.categories || {};
|
|
1507
|
+
config.categories = { ...DEFAULTS.categories };
|
|
1508
|
+
for (const key of Object.keys(DEFAULTS.categories)) {
|
|
1509
|
+
config.categories[key] = {
|
|
1510
|
+
...DEFAULTS.categories[key],
|
|
1511
|
+
...translationCategories[key],
|
|
1512
|
+
...userCategories[key]
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// Merge callbacks
|
|
1517
|
+
if (userConfig.callbacks) {
|
|
1518
|
+
config.callbacks = { ...DEFAULTS.callbacks, ...userConfig.callbacks };
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
// Patterns (for pattern matcher)
|
|
1522
|
+
if (userConfig.patterns) {
|
|
1523
|
+
config.patterns = userConfig.patterns;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
return config;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Configuration Parser - Reads config from various sources
|
|
1531
|
+
*/
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Parse data attributes from script tag
|
|
1536
|
+
*/
|
|
1537
|
+
function parseDataAttributes() {
|
|
1538
|
+
// Find the Zest script tag
|
|
1539
|
+
const script = document.currentScript ||
|
|
1540
|
+
document.querySelector('script[data-zest]') ||
|
|
1541
|
+
document.querySelector('script[src*="zest"]');
|
|
1542
|
+
|
|
1543
|
+
if (!script) {
|
|
1544
|
+
return {};
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
const config = {};
|
|
1548
|
+
|
|
1549
|
+
// Position
|
|
1550
|
+
const position = script.getAttribute('data-position');
|
|
1551
|
+
if (position) config.position = position;
|
|
1552
|
+
|
|
1553
|
+
// Theme
|
|
1554
|
+
const theme = script.getAttribute('data-theme');
|
|
1555
|
+
if (theme) config.theme = theme;
|
|
1556
|
+
|
|
1557
|
+
// Accent color
|
|
1558
|
+
const accent = script.getAttribute('data-accent') || script.getAttribute('data-accent-color');
|
|
1559
|
+
if (accent) config.accentColor = accent;
|
|
1560
|
+
|
|
1561
|
+
// Policy URL
|
|
1562
|
+
const policyUrl = script.getAttribute('data-policy-url') || script.getAttribute('data-privacy-url');
|
|
1563
|
+
if (policyUrl) config.policyUrl = policyUrl;
|
|
1564
|
+
|
|
1565
|
+
// Imprint URL
|
|
1566
|
+
const imprintUrl = script.getAttribute('data-imprint-url');
|
|
1567
|
+
if (imprintUrl) config.imprintUrl = imprintUrl;
|
|
1568
|
+
|
|
1569
|
+
// Show widget
|
|
1570
|
+
const showWidget = script.getAttribute('data-show-widget');
|
|
1571
|
+
if (showWidget !== null) config.showWidget = showWidget !== 'false';
|
|
1572
|
+
|
|
1573
|
+
// Auto init
|
|
1574
|
+
const autoInit = script.getAttribute('data-auto-init');
|
|
1575
|
+
if (autoInit !== null) config.autoInit = autoInit !== 'false';
|
|
1576
|
+
|
|
1577
|
+
// Expiration
|
|
1578
|
+
const expiration = script.getAttribute('data-expiration');
|
|
1579
|
+
if (expiration) config.expiration = parseInt(expiration, 10);
|
|
1580
|
+
|
|
1581
|
+
return config;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
/**
|
|
1585
|
+
* Parse window.ZestConfig object
|
|
1586
|
+
*/
|
|
1587
|
+
function parseWindowConfig() {
|
|
1588
|
+
if (typeof window !== 'undefined' && window.ZestConfig) {
|
|
1589
|
+
return window.ZestConfig;
|
|
1590
|
+
}
|
|
1591
|
+
return {};
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
/**
|
|
1595
|
+
* Get final merged configuration
|
|
1596
|
+
* Priority: data attributes > window.ZestConfig > defaults
|
|
1597
|
+
*/
|
|
1598
|
+
function getConfig() {
|
|
1599
|
+
const windowConfig = parseWindowConfig();
|
|
1600
|
+
const dataConfig = parseDataAttributes();
|
|
1601
|
+
|
|
1602
|
+
// Merge: defaults < windowConfig < dataConfig
|
|
1603
|
+
return mergeConfig({
|
|
1604
|
+
...windowConfig,
|
|
1605
|
+
...dataConfig
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* Update configuration at runtime
|
|
1611
|
+
*/
|
|
1612
|
+
let currentConfig = null;
|
|
1613
|
+
|
|
1614
|
+
function setConfig(config) {
|
|
1615
|
+
currentConfig = mergeConfig(config);
|
|
1616
|
+
return currentConfig;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
function getCurrentConfig() {
|
|
1620
|
+
if (!currentConfig) {
|
|
1621
|
+
currentConfig = getConfig();
|
|
1622
|
+
}
|
|
1623
|
+
return currentConfig;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
/**
|
|
1627
|
+
* Consent Store - Manages consent state persistence
|
|
1628
|
+
*/
|
|
1629
|
+
|
|
1630
|
+
|
|
1631
|
+
const COOKIE_NAME = 'zest_consent';
|
|
1632
|
+
const CONSENT_VERSION = '1.0';
|
|
1633
|
+
|
|
1634
|
+
// Current consent state
|
|
1635
|
+
let consent = null;
|
|
1636
|
+
|
|
1637
|
+
/**
|
|
1638
|
+
* Get the original cookie setter (bypasses interception)
|
|
1639
|
+
*/
|
|
1640
|
+
function setRawCookie(value) {
|
|
1641
|
+
const descriptor = getOriginalCookieDescriptor();
|
|
1642
|
+
if (descriptor?.set) {
|
|
1643
|
+
descriptor.set.call(document, value);
|
|
1644
|
+
} else {
|
|
1645
|
+
// Fallback if interceptor not initialized yet
|
|
1646
|
+
document.cookie = value;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
/**
|
|
1651
|
+
* Get the original cookie getter
|
|
1652
|
+
*/
|
|
1653
|
+
function getRawCookie() {
|
|
1654
|
+
const descriptor = getOriginalCookieDescriptor();
|
|
1655
|
+
if (descriptor?.get) {
|
|
1656
|
+
return descriptor.get.call(document);
|
|
1657
|
+
}
|
|
1658
|
+
return document.cookie;
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* Load consent from cookie
|
|
1663
|
+
*/
|
|
1664
|
+
function loadConsent() {
|
|
1665
|
+
try {
|
|
1666
|
+
const cookies = getRawCookie();
|
|
1667
|
+
const match = cookies.match(new RegExp(`${COOKIE_NAME}=([^;]+)`));
|
|
1668
|
+
|
|
1669
|
+
if (match) {
|
|
1670
|
+
const data = JSON.parse(decodeURIComponent(match[1]));
|
|
1671
|
+
consent = data.categories || getDefaultConsent();
|
|
1672
|
+
return { ...consent };
|
|
1673
|
+
}
|
|
1674
|
+
} catch (e) {
|
|
1675
|
+
// Invalid or missing cookie
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
consent = getDefaultConsent();
|
|
1679
|
+
return { ...consent };
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* Save consent to cookie
|
|
1684
|
+
*/
|
|
1685
|
+
function saveConsent(expirationDays = 365) {
|
|
1686
|
+
if (!consent) {
|
|
1687
|
+
consent = getDefaultConsent();
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
const data = {
|
|
1691
|
+
version: CONSENT_VERSION,
|
|
1692
|
+
timestamp: Date.now(),
|
|
1693
|
+
categories: consent
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
const expires = new Date(Date.now() + expirationDays * 24 * 60 * 60 * 1000).toUTCString();
|
|
1697
|
+
const cookieValue = `${COOKIE_NAME}=${encodeURIComponent(JSON.stringify(data))}; expires=${expires}; path=/; SameSite=Lax`;
|
|
1698
|
+
|
|
1699
|
+
setRawCookie(cookieValue);
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
/**
|
|
1703
|
+
* Get current consent state
|
|
1704
|
+
*/
|
|
1705
|
+
function getConsent() {
|
|
1706
|
+
if (!consent) {
|
|
1707
|
+
consent = loadConsent();
|
|
1708
|
+
}
|
|
1709
|
+
return { ...consent };
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
/**
|
|
1713
|
+
* Update consent state
|
|
1714
|
+
*/
|
|
1715
|
+
function updateConsent(newConsent, expirationDays = 365) {
|
|
1716
|
+
const previous = consent ? { ...consent } : getDefaultConsent();
|
|
1717
|
+
|
|
1718
|
+
consent = {
|
|
1719
|
+
essential: true, // Always true
|
|
1720
|
+
functional: !!newConsent.functional,
|
|
1721
|
+
analytics: !!newConsent.analytics,
|
|
1722
|
+
marketing: !!newConsent.marketing
|
|
1723
|
+
};
|
|
1724
|
+
|
|
1725
|
+
saveConsent(expirationDays);
|
|
1726
|
+
|
|
1727
|
+
return { current: { ...consent }, previous };
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
/**
|
|
1731
|
+
* Check if specific category is allowed
|
|
1732
|
+
*/
|
|
1733
|
+
function hasConsent(category) {
|
|
1734
|
+
if (!consent) {
|
|
1735
|
+
consent = loadConsent();
|
|
1736
|
+
}
|
|
1737
|
+
return consent[category] === true;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
/**
|
|
1741
|
+
* Accept all categories
|
|
1742
|
+
*/
|
|
1743
|
+
function acceptAll(expirationDays = 365) {
|
|
1744
|
+
return updateConsent({
|
|
1745
|
+
functional: true,
|
|
1746
|
+
analytics: true,
|
|
1747
|
+
marketing: true
|
|
1748
|
+
}, expirationDays);
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* Reject all (except essential)
|
|
1753
|
+
*/
|
|
1754
|
+
function rejectAll(expirationDays = 365) {
|
|
1755
|
+
return updateConsent({
|
|
1756
|
+
functional: false,
|
|
1757
|
+
analytics: false,
|
|
1758
|
+
marketing: false
|
|
1759
|
+
}, expirationDays);
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* Reset consent (clear cookie)
|
|
1764
|
+
*/
|
|
1765
|
+
function resetConsent() {
|
|
1766
|
+
setRawCookie(`${COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`);
|
|
1767
|
+
consent = null;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
/**
|
|
1771
|
+
* Check if consent has been given (any decision made)
|
|
1772
|
+
*/
|
|
1773
|
+
function hasConsentDecision() {
|
|
1774
|
+
try {
|
|
1775
|
+
const cookies = getRawCookie();
|
|
1776
|
+
return cookies.includes(COOKIE_NAME);
|
|
1777
|
+
} catch (e) {
|
|
1778
|
+
return false;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
/**
|
|
1783
|
+
* Get consent proof for compliance
|
|
1784
|
+
*/
|
|
1785
|
+
function getConsentProof() {
|
|
1786
|
+
try {
|
|
1787
|
+
const cookies = getRawCookie();
|
|
1788
|
+
const match = cookies.match(new RegExp(`${COOKIE_NAME}=([^;]+)`));
|
|
1789
|
+
|
|
1790
|
+
if (match) {
|
|
1791
|
+
return JSON.parse(decodeURIComponent(match[1]));
|
|
1792
|
+
}
|
|
1793
|
+
} catch (e) {
|
|
1794
|
+
// Invalid cookie
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
return null;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* Events - Custom event dispatching for consent changes
|
|
1802
|
+
*/
|
|
1803
|
+
|
|
1804
|
+
// Event names
|
|
1805
|
+
const EVENTS = {
|
|
1806
|
+
READY: 'zest:ready',
|
|
1807
|
+
CONSENT: 'zest:consent',
|
|
1808
|
+
REJECT: 'zest:reject',
|
|
1809
|
+
CHANGE: 'zest:change',
|
|
1810
|
+
SHOW: 'zest:show',
|
|
1811
|
+
HIDE: 'zest:hide'
|
|
1812
|
+
};
|
|
1813
|
+
|
|
1814
|
+
/**
|
|
1815
|
+
* Dispatch a custom event
|
|
1816
|
+
*/
|
|
1817
|
+
function emit(eventName, detail = {}) {
|
|
1818
|
+
const event = new CustomEvent(eventName, {
|
|
1819
|
+
detail,
|
|
1820
|
+
bubbles: true,
|
|
1821
|
+
cancelable: true
|
|
1822
|
+
});
|
|
1823
|
+
|
|
1824
|
+
document.dispatchEvent(event);
|
|
1825
|
+
return event;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
/**
|
|
1829
|
+
* Emit ready event
|
|
1830
|
+
*/
|
|
1831
|
+
function emitReady(consent) {
|
|
1832
|
+
return emit(EVENTS.READY, { consent });
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* Emit consent event (user accepted)
|
|
1837
|
+
*/
|
|
1838
|
+
function emitConsent(consent, previous) {
|
|
1839
|
+
return emit(EVENTS.CONSENT, { consent, previous });
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
/**
|
|
1843
|
+
* Emit reject event (user rejected all)
|
|
1844
|
+
*/
|
|
1845
|
+
function emitReject(consent) {
|
|
1846
|
+
return emit(EVENTS.REJECT, { consent });
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
/**
|
|
1850
|
+
* Emit change event (any consent change)
|
|
1851
|
+
*/
|
|
1852
|
+
function emitChange(consent, previous) {
|
|
1853
|
+
return emit(EVENTS.CHANGE, { consent, previous });
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
/**
|
|
1857
|
+
* Emit show event (banner/modal shown)
|
|
1858
|
+
*/
|
|
1859
|
+
function emitShow(type = 'banner') {
|
|
1860
|
+
return emit(EVENTS.SHOW, { type });
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* Emit hide event (banner/modal hidden)
|
|
1865
|
+
*/
|
|
1866
|
+
function emitHide(type = 'banner') {
|
|
1867
|
+
return emit(EVENTS.HIDE, { type });
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
/**
|
|
1871
|
+
* Styles - Shadow DOM encapsulated CSS with theming
|
|
1872
|
+
*/
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Generate CSS with custom properties
|
|
1876
|
+
*/
|
|
1877
|
+
function generateStyles(config) {
|
|
1878
|
+
const accentColor = config.accentColor || '#4F46E5';
|
|
1879
|
+
|
|
1880
|
+
return `
|
|
1881
|
+
:host {
|
|
1882
|
+
--zest-accent: ${accentColor};
|
|
1883
|
+
--zest-accent-hover: ${adjustColor(accentColor, -15)};
|
|
1884
|
+
--zest-bg: #ffffff;
|
|
1885
|
+
--zest-bg-secondary: #f3f4f6;
|
|
1886
|
+
--zest-text: #1f2937;
|
|
1887
|
+
--zest-text-secondary: #6b7280;
|
|
1888
|
+
--zest-border: #e5e7eb;
|
|
1889
|
+
--zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
|
|
1890
|
+
--zest-radius: 12px;
|
|
1891
|
+
--zest-radius-sm: 8px;
|
|
1892
|
+
--zest-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
1893
|
+
|
|
1894
|
+
font-family: var(--zest-font);
|
|
1895
|
+
font-size: 14px;
|
|
1896
|
+
line-height: 1.5;
|
|
1897
|
+
color: var(--zest-text);
|
|
1898
|
+
box-sizing: border-box;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
:host([data-theme="dark"]) {
|
|
1902
|
+
--zest-bg: #1f2937;
|
|
1903
|
+
--zest-bg-secondary: #374151;
|
|
1904
|
+
--zest-text: #f9fafb;
|
|
1905
|
+
--zest-text-secondary: #9ca3af;
|
|
1906
|
+
--zest-border: #4b5563;
|
|
1907
|
+
--zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
@media (prefers-color-scheme: dark) {
|
|
1911
|
+
:host([data-theme="auto"]) {
|
|
1912
|
+
--zest-bg: #1f2937;
|
|
1913
|
+
--zest-bg-secondary: #374151;
|
|
1914
|
+
--zest-text: #f9fafb;
|
|
1915
|
+
--zest-text-secondary: #9ca3af;
|
|
1916
|
+
--zest-border: #4b5563;
|
|
1917
|
+
--zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
*, *::before, *::after {
|
|
1922
|
+
box-sizing: border-box;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
/* Banner */
|
|
1926
|
+
.zest-banner {
|
|
1927
|
+
position: fixed;
|
|
1928
|
+
z-index: 999999;
|
|
1929
|
+
max-width: 480px;
|
|
1930
|
+
padding: 20px;
|
|
1931
|
+
background: var(--zest-bg);
|
|
1932
|
+
border-radius: var(--zest-radius);
|
|
1933
|
+
box-shadow: var(--zest-shadow);
|
|
1934
|
+
animation: zest-slide-in 0.3s ease-out;
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
.zest-banner--bottom {
|
|
1938
|
+
bottom: 20px;
|
|
1939
|
+
left: 50%;
|
|
1940
|
+
transform: translateX(-50%);
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
.zest-banner--bottom-left {
|
|
1944
|
+
bottom: 20px;
|
|
1945
|
+
left: 20px;
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
.zest-banner--bottom-right {
|
|
1949
|
+
bottom: 20px;
|
|
1950
|
+
right: 20px;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
.zest-banner--top {
|
|
1954
|
+
top: 20px;
|
|
1955
|
+
left: 50%;
|
|
1956
|
+
transform: translateX(-50%);
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
@keyframes zest-slide-in {
|
|
1960
|
+
from {
|
|
1961
|
+
opacity: 0;
|
|
1962
|
+
transform: translateX(-50%) translateY(20px);
|
|
1963
|
+
}
|
|
1964
|
+
to {
|
|
1965
|
+
opacity: 1;
|
|
1966
|
+
transform: translateX(-50%) translateY(0);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
.zest-banner--bottom-left {
|
|
1971
|
+
animation-name: zest-slide-in-left;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
@keyframes zest-slide-in-left {
|
|
1975
|
+
from {
|
|
1976
|
+
opacity: 0;
|
|
1977
|
+
transform: translateY(20px);
|
|
1978
|
+
}
|
|
1979
|
+
to {
|
|
1980
|
+
opacity: 1;
|
|
1981
|
+
transform: translateY(0);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
.zest-banner--bottom-right {
|
|
1986
|
+
animation-name: zest-slide-in-right;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
@keyframes zest-slide-in-right {
|
|
1990
|
+
from {
|
|
1991
|
+
opacity: 0;
|
|
1992
|
+
transform: translateY(20px);
|
|
1993
|
+
}
|
|
1994
|
+
to {
|
|
1995
|
+
opacity: 1;
|
|
1996
|
+
transform: translateY(0);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2001
|
+
.zest-banner,
|
|
2002
|
+
.zest-modal {
|
|
2003
|
+
animation: none;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
.zest-banner__title {
|
|
2008
|
+
margin: 0 0 8px 0;
|
|
2009
|
+
font-size: 16px;
|
|
2010
|
+
font-weight: 600;
|
|
2011
|
+
color: var(--zest-text);
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
.zest-banner__description {
|
|
2015
|
+
margin: 0 0 16px 0;
|
|
2016
|
+
font-size: 14px;
|
|
2017
|
+
color: var(--zest-text-secondary);
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
.zest-banner__buttons {
|
|
2021
|
+
display: flex;
|
|
2022
|
+
flex-wrap: wrap;
|
|
2023
|
+
gap: 8px;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
/* Buttons */
|
|
2027
|
+
.zest-btn {
|
|
2028
|
+
display: inline-flex;
|
|
2029
|
+
align-items: center;
|
|
2030
|
+
justify-content: center;
|
|
2031
|
+
padding: 10px 16px;
|
|
2032
|
+
font-size: 14px;
|
|
2033
|
+
font-weight: 500;
|
|
2034
|
+
font-family: inherit;
|
|
2035
|
+
border: none;
|
|
2036
|
+
border-radius: var(--zest-radius-sm);
|
|
2037
|
+
cursor: pointer;
|
|
2038
|
+
transition: background-color 0.15s ease, transform 0.1s ease;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
.zest-btn:hover {
|
|
2042
|
+
transform: translateY(-1px);
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
.zest-btn:active {
|
|
2046
|
+
transform: translateY(0);
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
.zest-btn:focus-visible {
|
|
2050
|
+
outline: 2px solid var(--zest-accent);
|
|
2051
|
+
outline-offset: 2px;
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
.zest-btn--primary {
|
|
2055
|
+
background: var(--zest-accent);
|
|
2056
|
+
color: #ffffff;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
.zest-btn--primary:hover {
|
|
2060
|
+
background: var(--zest-accent-hover);
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
.zest-btn--secondary {
|
|
2064
|
+
background: var(--zest-bg-secondary);
|
|
2065
|
+
color: var(--zest-text);
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
.zest-btn--secondary:hover {
|
|
2069
|
+
background: var(--zest-border);
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
.zest-btn--ghost {
|
|
2073
|
+
background: transparent;
|
|
2074
|
+
color: var(--zest-text-secondary);
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
.zest-btn--ghost:hover {
|
|
2078
|
+
background: var(--zest-bg-secondary);
|
|
2079
|
+
color: var(--zest-text);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
/* Modal */
|
|
2083
|
+
.zest-modal-overlay {
|
|
2084
|
+
position: fixed;
|
|
2085
|
+
inset: 0;
|
|
2086
|
+
z-index: 999998;
|
|
2087
|
+
display: flex;
|
|
2088
|
+
align-items: center;
|
|
2089
|
+
justify-content: center;
|
|
2090
|
+
padding: 20px;
|
|
2091
|
+
background: rgba(0, 0, 0, 0.5);
|
|
2092
|
+
animation: zest-fade-in 0.2s ease-out;
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
@keyframes zest-fade-in {
|
|
2096
|
+
from { opacity: 0; }
|
|
2097
|
+
to { opacity: 1; }
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
.zest-modal {
|
|
2101
|
+
width: 100%;
|
|
2102
|
+
max-width: 500px;
|
|
2103
|
+
max-height: 90vh;
|
|
2104
|
+
overflow-y: auto;
|
|
2105
|
+
background: var(--zest-bg);
|
|
2106
|
+
border-radius: var(--zest-radius);
|
|
2107
|
+
box-shadow: var(--zest-shadow);
|
|
2108
|
+
animation: zest-modal-in 0.3s ease-out;
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
@keyframes zest-modal-in {
|
|
2112
|
+
from {
|
|
2113
|
+
opacity: 0;
|
|
2114
|
+
transform: scale(0.95);
|
|
2115
|
+
}
|
|
2116
|
+
to {
|
|
2117
|
+
opacity: 1;
|
|
2118
|
+
transform: scale(1);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
.zest-modal__header {
|
|
2123
|
+
padding: 20px 20px 0;
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
.zest-modal__title {
|
|
2127
|
+
margin: 0 0 8px 0;
|
|
2128
|
+
font-size: 18px;
|
|
2129
|
+
font-weight: 600;
|
|
2130
|
+
color: var(--zest-text);
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
.zest-modal__description {
|
|
2134
|
+
margin: 0;
|
|
2135
|
+
font-size: 14px;
|
|
2136
|
+
color: var(--zest-text-secondary);
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
.zest-modal__body {
|
|
2140
|
+
padding: 20px;
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
.zest-modal__footer {
|
|
2144
|
+
display: flex;
|
|
2145
|
+
flex-wrap: wrap;
|
|
2146
|
+
gap: 8px;
|
|
2147
|
+
padding: 0 20px 20px;
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
/* Categories */
|
|
2151
|
+
.zest-category {
|
|
2152
|
+
padding: 16px;
|
|
2153
|
+
margin-bottom: 12px;
|
|
2154
|
+
background: var(--zest-bg-secondary);
|
|
2155
|
+
border-radius: var(--zest-radius-sm);
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
.zest-category:last-child {
|
|
2159
|
+
margin-bottom: 0;
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
.zest-category__header {
|
|
2163
|
+
display: flex;
|
|
2164
|
+
align-items: center;
|
|
2165
|
+
justify-content: space-between;
|
|
2166
|
+
gap: 12px;
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
.zest-category__info {
|
|
2170
|
+
flex: 1;
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
.zest-category__label {
|
|
2174
|
+
display: block;
|
|
2175
|
+
font-size: 14px;
|
|
2176
|
+
font-weight: 600;
|
|
2177
|
+
color: var(--zest-text);
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
.zest-category__description {
|
|
2181
|
+
margin: 4px 0 0;
|
|
2182
|
+
font-size: 13px;
|
|
2183
|
+
color: var(--zest-text-secondary);
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
/* Toggle Switch */
|
|
2187
|
+
.zest-toggle {
|
|
2188
|
+
position: relative;
|
|
2189
|
+
width: 44px;
|
|
2190
|
+
height: 24px;
|
|
2191
|
+
flex-shrink: 0;
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
.zest-toggle__input {
|
|
2195
|
+
position: absolute;
|
|
2196
|
+
opacity: 0;
|
|
2197
|
+
width: 100%;
|
|
2198
|
+
height: 100%;
|
|
2199
|
+
cursor: pointer;
|
|
2200
|
+
margin: 0;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
.zest-toggle__input:disabled {
|
|
2204
|
+
cursor: not-allowed;
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
.zest-toggle__slider {
|
|
2208
|
+
position: absolute;
|
|
2209
|
+
inset: 0;
|
|
2210
|
+
background: var(--zest-border);
|
|
2211
|
+
border-radius: 12px;
|
|
2212
|
+
transition: background-color 0.2s ease;
|
|
2213
|
+
pointer-events: none;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
.zest-toggle__slider::before {
|
|
2217
|
+
content: '';
|
|
2218
|
+
position: absolute;
|
|
2219
|
+
top: 2px;
|
|
2220
|
+
left: 2px;
|
|
2221
|
+
width: 20px;
|
|
2222
|
+
height: 20px;
|
|
2223
|
+
background: #ffffff;
|
|
2224
|
+
border-radius: 50%;
|
|
2225
|
+
transition: transform 0.2s ease;
|
|
2226
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
.zest-toggle__input:checked + .zest-toggle__slider {
|
|
2230
|
+
background: var(--zest-accent);
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
.zest-toggle__input:checked + .zest-toggle__slider::before {
|
|
2234
|
+
transform: translateX(20px);
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
.zest-toggle__input:focus-visible + .zest-toggle__slider {
|
|
2238
|
+
outline: 2px solid var(--zest-accent);
|
|
2239
|
+
outline-offset: 2px;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
.zest-toggle__input:disabled + .zest-toggle__slider {
|
|
2243
|
+
opacity: 0.6;
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
/* Widget */
|
|
2247
|
+
.zest-widget {
|
|
2248
|
+
position: fixed;
|
|
2249
|
+
z-index: 999997;
|
|
2250
|
+
bottom: 20px;
|
|
2251
|
+
left: 20px;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
.zest-widget__btn {
|
|
2255
|
+
display: flex;
|
|
2256
|
+
align-items: center;
|
|
2257
|
+
justify-content: center;
|
|
2258
|
+
width: 48px;
|
|
2259
|
+
height: 48px;
|
|
2260
|
+
padding: 0;
|
|
2261
|
+
background: var(--zest-bg);
|
|
2262
|
+
border: 1px solid var(--zest-border);
|
|
2263
|
+
border-radius: 50%;
|
|
2264
|
+
box-shadow: var(--zest-shadow);
|
|
2265
|
+
cursor: pointer;
|
|
2266
|
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
.zest-widget__btn:hover {
|
|
2270
|
+
transform: scale(1.05);
|
|
2271
|
+
box-shadow: 0 12px 28px -5px rgba(0, 0, 0, 0.15);
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
.zest-widget__btn:focus-visible {
|
|
2275
|
+
outline: 2px solid var(--zest-accent);
|
|
2276
|
+
outline-offset: 2px;
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
.zest-widget__icon {
|
|
2280
|
+
width: 24px;
|
|
2281
|
+
height: 24px;
|
|
2282
|
+
fill: var(--zest-text);
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
/* Link */
|
|
2286
|
+
.zest-link {
|
|
2287
|
+
color: var(--zest-accent);
|
|
2288
|
+
text-decoration: none;
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
.zest-link:hover {
|
|
2292
|
+
text-decoration: underline;
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
/* Mobile */
|
|
2296
|
+
@media (max-width: 480px) {
|
|
2297
|
+
.zest-banner {
|
|
2298
|
+
left: 10px;
|
|
2299
|
+
right: 10px;
|
|
2300
|
+
max-width: none;
|
|
2301
|
+
transform: none;
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
.zest-banner--bottom,
|
|
2305
|
+
.zest-banner--bottom-left,
|
|
2306
|
+
.zest-banner--bottom-right {
|
|
2307
|
+
bottom: 10px;
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2310
|
+
.zest-banner--top {
|
|
2311
|
+
top: 10px;
|
|
2312
|
+
transform: none;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
@keyframes zest-slide-in {
|
|
2316
|
+
from {
|
|
2317
|
+
opacity: 0;
|
|
2318
|
+
transform: translateY(20px);
|
|
2319
|
+
}
|
|
2320
|
+
to {
|
|
2321
|
+
opacity: 1;
|
|
2322
|
+
transform: translateY(0);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
.zest-banner__buttons {
|
|
2327
|
+
flex-direction: column;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
.zest-btn {
|
|
2331
|
+
width: 100%;
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
.zest-modal-overlay {
|
|
2335
|
+
padding: 10px;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
.zest-widget {
|
|
2339
|
+
bottom: 10px;
|
|
2340
|
+
left: 10px;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
/* Hidden utility */
|
|
2345
|
+
.zest-hidden {
|
|
2346
|
+
display: none !important;
|
|
2347
|
+
}
|
|
2348
|
+
${config.customStyles || ''}
|
|
2349
|
+
`;
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
/**
|
|
2353
|
+
* Adjust color brightness
|
|
2354
|
+
*/
|
|
2355
|
+
function adjustColor(hex, percent) {
|
|
2356
|
+
const num = parseInt(hex.replace('#', ''), 16);
|
|
2357
|
+
const amt = Math.round(2.55 * percent);
|
|
2358
|
+
const R = Math.min(255, Math.max(0, (num >> 16) + amt));
|
|
2359
|
+
const G = Math.min(255, Math.max(0, ((num >> 8) & 0x00ff) + amt));
|
|
2360
|
+
const B = Math.min(255, Math.max(0, (num & 0x0000ff) + amt));
|
|
2361
|
+
return '#' + (0x1000000 + R * 0x10000 + G * 0x100 + B).toString(16).slice(1);
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
/**
|
|
2365
|
+
* Cookie icon SVG
|
|
2366
|
+
*/
|
|
2367
|
+
const COOKIE_ICON = `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10c0-.728-.078-1.437-.225-2.12a1 1 0 0 0-1.482-.63 3 3 0 0 1-4.086-3.72 1 1 0 0 0-.793-1.263A10.05 10.05 0 0 0 12 2zm0 2c.178 0 .354.006.528.017a5 5 0 0 0 5.955 5.955c.011.174.017.35.017.528 0 4.418-3.582 8-8 8s-8-3.582-8-8 3.582-8 8-8zm-4 6a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm5 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"/></svg>`;
|
|
2368
|
+
|
|
2369
|
+
/**
|
|
2370
|
+
* Banner - Main consent banner component
|
|
2371
|
+
*/
|
|
2372
|
+
|
|
2373
|
+
|
|
2374
|
+
let bannerElement = null;
|
|
2375
|
+
let shadowRoot$2 = null;
|
|
2376
|
+
|
|
2377
|
+
/**
|
|
2378
|
+
* Create the banner HTML
|
|
2379
|
+
*/
|
|
2380
|
+
function createBannerHTML(config) {
|
|
2381
|
+
const labels = config.labels.banner;
|
|
2382
|
+
const position = config.position || 'bottom';
|
|
2383
|
+
|
|
2384
|
+
return `
|
|
2385
|
+
<div class="zest-banner zest-banner--${position}" role="dialog" aria-modal="false" aria-label="${labels.title}">
|
|
2386
|
+
<h2 class="zest-banner__title">${labels.title}</h2>
|
|
2387
|
+
<p class="zest-banner__description">${labels.description}</p>
|
|
2388
|
+
<div class="zest-banner__buttons">
|
|
2389
|
+
<button type="button" class="zest-btn zest-btn--primary" data-action="accept-all">
|
|
2390
|
+
${labels.acceptAll}
|
|
2391
|
+
</button>
|
|
2392
|
+
<button type="button" class="zest-btn zest-btn--secondary" data-action="reject-all">
|
|
2393
|
+
${labels.rejectAll}
|
|
2394
|
+
</button>
|
|
2395
|
+
<button type="button" class="zest-btn zest-btn--ghost" data-action="settings">
|
|
2396
|
+
${labels.settings}
|
|
2397
|
+
</button>
|
|
2398
|
+
</div>
|
|
2399
|
+
</div>
|
|
2400
|
+
`;
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
/**
|
|
2404
|
+
* Create and mount the banner
|
|
2405
|
+
*/
|
|
2406
|
+
function createBanner(callbacks = {}) {
|
|
2407
|
+
if (bannerElement) {
|
|
2408
|
+
return bannerElement;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
const config = getCurrentConfig();
|
|
2412
|
+
|
|
2413
|
+
// Create host element
|
|
2414
|
+
bannerElement = document.createElement('zest-banner');
|
|
2415
|
+
bannerElement.setAttribute('data-theme', config.theme || 'light');
|
|
2416
|
+
|
|
2417
|
+
// Create shadow root
|
|
2418
|
+
shadowRoot$2 = bannerElement.attachShadow({ mode: 'open' });
|
|
2419
|
+
|
|
2420
|
+
// Add styles
|
|
2421
|
+
const styleEl = document.createElement('style');
|
|
2422
|
+
styleEl.textContent = generateStyles(config);
|
|
2423
|
+
shadowRoot$2.appendChild(styleEl);
|
|
2424
|
+
|
|
2425
|
+
// Add banner HTML
|
|
2426
|
+
const container = document.createElement('div');
|
|
2427
|
+
container.innerHTML = createBannerHTML(config);
|
|
2428
|
+
shadowRoot$2.appendChild(container.firstElementChild);
|
|
2429
|
+
|
|
2430
|
+
// Add event listeners
|
|
2431
|
+
const banner = shadowRoot$2.querySelector('.zest-banner');
|
|
2432
|
+
|
|
2433
|
+
banner.addEventListener('click', (e) => {
|
|
2434
|
+
const action = e.target.dataset.action;
|
|
2435
|
+
if (!action) return;
|
|
2436
|
+
|
|
2437
|
+
switch (action) {
|
|
2438
|
+
case 'accept-all':
|
|
2439
|
+
callbacks.onAcceptAll?.();
|
|
2440
|
+
break;
|
|
2441
|
+
case 'reject-all':
|
|
2442
|
+
callbacks.onRejectAll?.();
|
|
2443
|
+
break;
|
|
2444
|
+
case 'settings':
|
|
2445
|
+
callbacks.onSettings?.();
|
|
2446
|
+
break;
|
|
2447
|
+
}
|
|
2448
|
+
});
|
|
2449
|
+
|
|
2450
|
+
// Keyboard handling
|
|
2451
|
+
banner.addEventListener('keydown', (e) => {
|
|
2452
|
+
if (e.key === 'Escape') {
|
|
2453
|
+
callbacks.onSettings?.();
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2456
|
+
|
|
2457
|
+
// Mount to document
|
|
2458
|
+
document.body.appendChild(bannerElement);
|
|
2459
|
+
|
|
2460
|
+
// Focus first button for accessibility
|
|
2461
|
+
requestAnimationFrame(() => {
|
|
2462
|
+
const firstButton = shadowRoot$2.querySelector('button');
|
|
2463
|
+
firstButton?.focus();
|
|
2464
|
+
});
|
|
2465
|
+
|
|
2466
|
+
return bannerElement;
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
/**
|
|
2470
|
+
* Show the banner
|
|
2471
|
+
*/
|
|
2472
|
+
function showBanner(callbacks = {}) {
|
|
2473
|
+
if (!bannerElement) {
|
|
2474
|
+
createBanner(callbacks);
|
|
2475
|
+
} else {
|
|
2476
|
+
bannerElement.classList.remove('zest-hidden');
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
/**
|
|
2481
|
+
* Hide the banner
|
|
2482
|
+
*/
|
|
2483
|
+
function hideBanner() {
|
|
2484
|
+
if (bannerElement) {
|
|
2485
|
+
bannerElement.remove();
|
|
2486
|
+
bannerElement = null;
|
|
2487
|
+
shadowRoot$2 = null;
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* Modal - Settings modal component for category toggles
|
|
2493
|
+
*/
|
|
2494
|
+
|
|
2495
|
+
|
|
2496
|
+
let modalElement = null;
|
|
2497
|
+
let shadowRoot$1 = null;
|
|
2498
|
+
let currentSelections = {};
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* Create category toggle HTML
|
|
2502
|
+
*/
|
|
2503
|
+
function createCategoryHTML(category, isChecked, isRequired) {
|
|
2504
|
+
const disabled = isRequired ? 'disabled' : '';
|
|
2505
|
+
const checked = isChecked ? 'checked' : '';
|
|
2506
|
+
|
|
2507
|
+
return `
|
|
2508
|
+
<div class="zest-category">
|
|
2509
|
+
<div class="zest-category__header">
|
|
2510
|
+
<div class="zest-category__info">
|
|
2511
|
+
<span class="zest-category__label">${category.label}</span>
|
|
2512
|
+
<p class="zest-category__description">${category.description}</p>
|
|
2513
|
+
</div>
|
|
2514
|
+
<label class="zest-toggle">
|
|
2515
|
+
<input
|
|
2516
|
+
type="checkbox"
|
|
2517
|
+
class="zest-toggle__input"
|
|
2518
|
+
data-category="${category.id}"
|
|
2519
|
+
${checked}
|
|
2520
|
+
${disabled}
|
|
2521
|
+
aria-label="${category.label}"
|
|
2522
|
+
>
|
|
2523
|
+
<span class="zest-toggle__slider"></span>
|
|
2524
|
+
</label>
|
|
2525
|
+
</div>
|
|
2526
|
+
</div>
|
|
2527
|
+
`;
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
/**
|
|
2531
|
+
* Create the modal HTML
|
|
2532
|
+
*/
|
|
2533
|
+
function createModalHTML(config, consent) {
|
|
2534
|
+
const labels = config.labels.modal;
|
|
2535
|
+
const categories = config.categories || DEFAULT_CATEGORIES;
|
|
2536
|
+
|
|
2537
|
+
const categoriesHTML = Object.values(categories)
|
|
2538
|
+
.map(cat => createCategoryHTML(
|
|
2539
|
+
cat,
|
|
2540
|
+
consent[cat.id] ?? cat.default,
|
|
2541
|
+
cat.required
|
|
2542
|
+
))
|
|
2543
|
+
.join('');
|
|
2544
|
+
|
|
2545
|
+
const policyLink = config.policyUrl
|
|
2546
|
+
? `<a href="${config.policyUrl}" class="zest-link" target="_blank" rel="noopener">Privacy Policy</a>`
|
|
2547
|
+
: '';
|
|
2548
|
+
|
|
2549
|
+
return `
|
|
2550
|
+
<div class="zest-modal-overlay" role="dialog" aria-modal="true" aria-label="${labels.title}">
|
|
2551
|
+
<div class="zest-modal">
|
|
2552
|
+
<div class="zest-modal__header">
|
|
2553
|
+
<h2 class="zest-modal__title">${labels.title}</h2>
|
|
2554
|
+
<p class="zest-modal__description">${labels.description} ${policyLink}</p>
|
|
2555
|
+
</div>
|
|
2556
|
+
<div class="zest-modal__body">
|
|
2557
|
+
${categoriesHTML}
|
|
2558
|
+
</div>
|
|
2559
|
+
<div class="zest-modal__footer">
|
|
2560
|
+
<button type="button" class="zest-btn zest-btn--primary" data-action="save">
|
|
2561
|
+
${labels.save}
|
|
2562
|
+
</button>
|
|
2563
|
+
<button type="button" class="zest-btn zest-btn--secondary" data-action="accept-all">
|
|
2564
|
+
${labels.acceptAll}
|
|
2565
|
+
</button>
|
|
2566
|
+
<button type="button" class="zest-btn zest-btn--ghost" data-action="reject-all">
|
|
2567
|
+
${labels.rejectAll}
|
|
2568
|
+
</button>
|
|
2569
|
+
</div>
|
|
2570
|
+
</div>
|
|
2571
|
+
</div>
|
|
2572
|
+
`;
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
/**
|
|
2576
|
+
* Get current selections from toggles
|
|
2577
|
+
*/
|
|
2578
|
+
function getSelections() {
|
|
2579
|
+
if (!shadowRoot$1) return currentSelections;
|
|
2580
|
+
|
|
2581
|
+
const toggles = shadowRoot$1.querySelectorAll('.zest-toggle__input');
|
|
2582
|
+
const selections = { essential: true };
|
|
2583
|
+
|
|
2584
|
+
toggles.forEach(toggle => {
|
|
2585
|
+
const category = toggle.dataset.category;
|
|
2586
|
+
if (category && category !== 'essential') {
|
|
2587
|
+
selections[category] = toggle.checked;
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
|
|
2591
|
+
return selections;
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
/**
|
|
2595
|
+
* Create and show the modal
|
|
2596
|
+
*/
|
|
2597
|
+
function showModal(consent = {}, callbacks = {}) {
|
|
2598
|
+
if (modalElement) {
|
|
2599
|
+
return modalElement;
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
const config = getCurrentConfig();
|
|
2603
|
+
currentSelections = { ...consent };
|
|
2604
|
+
|
|
2605
|
+
// Create host element
|
|
2606
|
+
modalElement = document.createElement('zest-modal');
|
|
2607
|
+
modalElement.setAttribute('data-theme', config.theme || 'light');
|
|
2608
|
+
|
|
2609
|
+
// Create shadow root
|
|
2610
|
+
shadowRoot$1 = modalElement.attachShadow({ mode: 'open' });
|
|
2611
|
+
|
|
2612
|
+
// Add styles
|
|
2613
|
+
const styleEl = document.createElement('style');
|
|
2614
|
+
styleEl.textContent = generateStyles(config);
|
|
2615
|
+
shadowRoot$1.appendChild(styleEl);
|
|
2616
|
+
|
|
2617
|
+
// Add modal HTML
|
|
2618
|
+
const container = document.createElement('div');
|
|
2619
|
+
container.innerHTML = createModalHTML(config, consent);
|
|
2620
|
+
shadowRoot$1.appendChild(container.firstElementChild);
|
|
2621
|
+
|
|
2622
|
+
// Add event listeners
|
|
2623
|
+
const modal = shadowRoot$1.querySelector('.zest-modal-overlay');
|
|
2624
|
+
|
|
2625
|
+
// Button clicks
|
|
2626
|
+
modal.addEventListener('click', (e) => {
|
|
2627
|
+
const action = e.target.dataset.action;
|
|
2628
|
+
if (!action) {
|
|
2629
|
+
// Click on overlay background to close
|
|
2630
|
+
if (e.target === modal) {
|
|
2631
|
+
callbacks.onClose?.();
|
|
2632
|
+
}
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
switch (action) {
|
|
2637
|
+
case 'save':
|
|
2638
|
+
callbacks.onSave?.(getSelections());
|
|
2639
|
+
break;
|
|
2640
|
+
case 'accept-all':
|
|
2641
|
+
callbacks.onAcceptAll?.();
|
|
2642
|
+
break;
|
|
2643
|
+
case 'reject-all':
|
|
2644
|
+
callbacks.onRejectAll?.();
|
|
2645
|
+
break;
|
|
2646
|
+
}
|
|
2647
|
+
});
|
|
2648
|
+
|
|
2649
|
+
// Keyboard handling
|
|
2650
|
+
modal.addEventListener('keydown', (e) => {
|
|
2651
|
+
if (e.key === 'Escape') {
|
|
2652
|
+
callbacks.onClose?.();
|
|
2653
|
+
}
|
|
2654
|
+
});
|
|
2655
|
+
|
|
2656
|
+
// Track toggle changes
|
|
2657
|
+
shadowRoot$1.querySelectorAll('.zest-toggle__input').forEach(toggle => {
|
|
2658
|
+
toggle.addEventListener('change', () => {
|
|
2659
|
+
currentSelections = getSelections();
|
|
2660
|
+
});
|
|
2661
|
+
});
|
|
2662
|
+
|
|
2663
|
+
// Mount to document
|
|
2664
|
+
document.body.appendChild(modalElement);
|
|
2665
|
+
|
|
2666
|
+
// Trap focus
|
|
2667
|
+
requestAnimationFrame(() => {
|
|
2668
|
+
const firstButton = shadowRoot$1.querySelector('button');
|
|
2669
|
+
firstButton?.focus();
|
|
2670
|
+
});
|
|
2671
|
+
|
|
2672
|
+
return modalElement;
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
/**
|
|
2676
|
+
* Hide the modal
|
|
2677
|
+
*/
|
|
2678
|
+
function hideModal() {
|
|
2679
|
+
if (modalElement) {
|
|
2680
|
+
modalElement.remove();
|
|
2681
|
+
modalElement = null;
|
|
2682
|
+
shadowRoot$1 = null;
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Widget - Minimal floating button to reopen settings
|
|
2688
|
+
*/
|
|
2689
|
+
|
|
2690
|
+
|
|
2691
|
+
let widgetElement = null;
|
|
2692
|
+
let shadowRoot = null;
|
|
2693
|
+
|
|
2694
|
+
/**
|
|
2695
|
+
* Create the widget HTML
|
|
2696
|
+
*/
|
|
2697
|
+
function createWidgetHTML(config) {
|
|
2698
|
+
const labels = config.labels.widget;
|
|
2699
|
+
|
|
2700
|
+
return `
|
|
2701
|
+
<div class="zest-widget">
|
|
2702
|
+
<button type="button" class="zest-widget__btn" aria-label="${labels.label}" title="${labels.label}">
|
|
2703
|
+
<span class="zest-widget__icon">${COOKIE_ICON}</span>
|
|
2704
|
+
</button>
|
|
2705
|
+
</div>
|
|
2706
|
+
`;
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
/**
|
|
2710
|
+
* Create and mount the widget
|
|
2711
|
+
*/
|
|
2712
|
+
function createWidget(callbacks = {}) {
|
|
2713
|
+
if (widgetElement) {
|
|
2714
|
+
return widgetElement;
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
const config = getCurrentConfig();
|
|
2718
|
+
|
|
2719
|
+
// Create host element
|
|
2720
|
+
widgetElement = document.createElement('zest-widget');
|
|
2721
|
+
widgetElement.setAttribute('data-theme', config.theme || 'light');
|
|
2722
|
+
|
|
2723
|
+
// Create shadow root
|
|
2724
|
+
shadowRoot = widgetElement.attachShadow({ mode: 'open' });
|
|
2725
|
+
|
|
2726
|
+
// Add styles
|
|
2727
|
+
const styleEl = document.createElement('style');
|
|
2728
|
+
styleEl.textContent = generateStyles(config);
|
|
2729
|
+
shadowRoot.appendChild(styleEl);
|
|
2730
|
+
|
|
2731
|
+
// Add widget HTML
|
|
2732
|
+
const container = document.createElement('div');
|
|
2733
|
+
container.innerHTML = createWidgetHTML(config);
|
|
2734
|
+
shadowRoot.appendChild(container.firstElementChild);
|
|
2735
|
+
|
|
2736
|
+
// Add event listener
|
|
2737
|
+
const button = shadowRoot.querySelector('.zest-widget__btn');
|
|
2738
|
+
button.addEventListener('click', () => {
|
|
2739
|
+
callbacks.onClick?.();
|
|
2740
|
+
});
|
|
2741
|
+
|
|
2742
|
+
// Mount to document
|
|
2743
|
+
document.body.appendChild(widgetElement);
|
|
2744
|
+
|
|
2745
|
+
return widgetElement;
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
/**
|
|
2749
|
+
* Show the widget
|
|
2750
|
+
*/
|
|
2751
|
+
function showWidget(callbacks = {}) {
|
|
2752
|
+
if (!widgetElement) {
|
|
2753
|
+
createWidget(callbacks);
|
|
2754
|
+
} else {
|
|
2755
|
+
widgetElement.style.display = '';
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
|
|
2759
|
+
/**
|
|
2760
|
+
* Hide the widget
|
|
2761
|
+
*/
|
|
2762
|
+
function hideWidget() {
|
|
2763
|
+
if (widgetElement) {
|
|
2764
|
+
widgetElement.style.display = 'none';
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
/**
|
|
2769
|
+
* Remove the widget completely
|
|
2770
|
+
*/
|
|
2771
|
+
function removeWidget() {
|
|
2772
|
+
if (widgetElement) {
|
|
2773
|
+
widgetElement.remove();
|
|
2774
|
+
widgetElement = null;
|
|
2775
|
+
shadowRoot = null;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
/**
|
|
2780
|
+
* Zest - Lightweight Cookie Consent Toolkit
|
|
2781
|
+
* Main entry point
|
|
2782
|
+
*/
|
|
2783
|
+
|
|
2784
|
+
|
|
2785
|
+
// State
|
|
2786
|
+
let initialized = false;
|
|
2787
|
+
let config = null;
|
|
2788
|
+
|
|
2789
|
+
/**
|
|
2790
|
+
* Consent checker function shared across interceptors
|
|
2791
|
+
*/
|
|
2792
|
+
function checkConsent(category) {
|
|
2793
|
+
return hasConsent(category);
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
/**
|
|
2797
|
+
* Replay all queued items for newly allowed categories
|
|
2798
|
+
*/
|
|
2799
|
+
function replayAll(allowedCategories) {
|
|
2800
|
+
replayCookies(allowedCategories);
|
|
2801
|
+
replayStorage(allowedCategories);
|
|
2802
|
+
replayScripts(allowedCategories);
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
/**
|
|
2806
|
+
* Handle accept all
|
|
2807
|
+
*/
|
|
2808
|
+
function handleAcceptAll() {
|
|
2809
|
+
const result = acceptAll(config.expiration);
|
|
2810
|
+
const categories = getCategoryIds();
|
|
2811
|
+
|
|
2812
|
+
hideBanner();
|
|
2813
|
+
hideModal();
|
|
2814
|
+
|
|
2815
|
+
replayAll(categories);
|
|
2816
|
+
|
|
2817
|
+
if (config.showWidget) {
|
|
2818
|
+
showWidget({ onClick: handleShowSettings });
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
emitConsent(result.current, result.previous);
|
|
2822
|
+
emitChange(result.current, result.previous);
|
|
2823
|
+
config.callbacks?.onAccept?.(result.current);
|
|
2824
|
+
config.callbacks?.onChange?.(result.current);
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
/**
|
|
2828
|
+
* Handle reject all
|
|
2829
|
+
*/
|
|
2830
|
+
function handleRejectAll() {
|
|
2831
|
+
const result = rejectAll(config.expiration);
|
|
2832
|
+
|
|
2833
|
+
hideBanner();
|
|
2834
|
+
hideModal();
|
|
2835
|
+
|
|
2836
|
+
if (config.showWidget) {
|
|
2837
|
+
showWidget({ onClick: handleShowSettings });
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
emitReject(result.current);
|
|
2841
|
+
emitChange(result.current, result.previous);
|
|
2842
|
+
config.callbacks?.onReject?.();
|
|
2843
|
+
config.callbacks?.onChange?.(result.current);
|
|
2844
|
+
}
|
|
2845
|
+
|
|
2846
|
+
/**
|
|
2847
|
+
* Handle save preferences from modal
|
|
2848
|
+
*/
|
|
2849
|
+
function handleSavePreferences(selections) {
|
|
2850
|
+
const result = updateConsent(selections, config.expiration);
|
|
2851
|
+
|
|
2852
|
+
// Find newly allowed categories
|
|
2853
|
+
const newlyAllowed = Object.keys(result.current).filter(
|
|
2854
|
+
cat => result.current[cat] && !result.previous[cat]
|
|
2855
|
+
);
|
|
2856
|
+
|
|
2857
|
+
if (newlyAllowed.length > 0) {
|
|
2858
|
+
replayAll(newlyAllowed);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
hideModal();
|
|
2862
|
+
|
|
2863
|
+
if (config.showWidget) {
|
|
2864
|
+
showWidget({ onClick: handleShowSettings });
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
// Determine if this was acceptance or rejection based on selections
|
|
2868
|
+
const hasNonEssential = Object.entries(selections)
|
|
2869
|
+
.some(([cat, val]) => cat !== 'essential' && val);
|
|
2870
|
+
|
|
2871
|
+
if (hasNonEssential) {
|
|
2872
|
+
emitConsent(result.current, result.previous);
|
|
2873
|
+
} else {
|
|
2874
|
+
emitReject(result.current);
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
emitChange(result.current, result.previous);
|
|
2878
|
+
config.callbacks?.onChange?.(result.current);
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
/**
|
|
2882
|
+
* Handle show settings
|
|
2883
|
+
*/
|
|
2884
|
+
function handleShowSettings() {
|
|
2885
|
+
hideBanner();
|
|
2886
|
+
hideWidget();
|
|
2887
|
+
|
|
2888
|
+
showModal(getConsent(), {
|
|
2889
|
+
onSave: handleSavePreferences,
|
|
2890
|
+
onAcceptAll: handleAcceptAll,
|
|
2891
|
+
onRejectAll: handleRejectAll,
|
|
2892
|
+
onClose: handleCloseModal
|
|
2893
|
+
});
|
|
2894
|
+
|
|
2895
|
+
emitShow('modal');
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
/**
|
|
2899
|
+
* Handle close modal
|
|
2900
|
+
*/
|
|
2901
|
+
function handleCloseModal() {
|
|
2902
|
+
hideModal();
|
|
2903
|
+
emitHide('modal');
|
|
2904
|
+
|
|
2905
|
+
// Show widget if consent was already given
|
|
2906
|
+
if (hasConsentDecision() && config.showWidget) {
|
|
2907
|
+
showWidget({ onClick: handleShowSettings });
|
|
2908
|
+
} else {
|
|
2909
|
+
// Show banner again if no decision made
|
|
2910
|
+
showBanner({
|
|
2911
|
+
onAcceptAll: handleAcceptAll,
|
|
2912
|
+
onRejectAll: handleRejectAll,
|
|
2913
|
+
onSettings: handleShowSettings
|
|
2914
|
+
});
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
/**
|
|
2919
|
+
* Initialize Zest
|
|
2920
|
+
*/
|
|
2921
|
+
function init(userConfig = {}) {
|
|
2922
|
+
if (initialized) {
|
|
2923
|
+
console.warn('[Zest] Already initialized');
|
|
2924
|
+
return Zest;
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// Merge config
|
|
2928
|
+
config = setConfig(userConfig);
|
|
2929
|
+
|
|
2930
|
+
// Set patterns if provided
|
|
2931
|
+
if (config.patterns) {
|
|
2932
|
+
setPatterns(config.patterns);
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
// Set up consent checkers
|
|
2936
|
+
setConsentChecker$2(checkConsent);
|
|
2937
|
+
setConsentChecker$1(checkConsent);
|
|
2938
|
+
setConsentChecker(checkConsent);
|
|
2939
|
+
|
|
2940
|
+
// Start interception
|
|
2941
|
+
interceptCookies();
|
|
2942
|
+
interceptStorage();
|
|
2943
|
+
startScriptBlocking(config.mode, config.blockedDomains);
|
|
2944
|
+
|
|
2945
|
+
// Load saved consent
|
|
2946
|
+
const consent = loadConsent();
|
|
2947
|
+
|
|
2948
|
+
initialized = true;
|
|
2949
|
+
|
|
2950
|
+
// Check Do Not Track / Global Privacy Control
|
|
2951
|
+
const dntEnabled = isDoNotTrackEnabled();
|
|
2952
|
+
let dntApplied = false;
|
|
2953
|
+
|
|
2954
|
+
if (dntEnabled && config.respectDNT && config.dntBehavior !== 'ignore') {
|
|
2955
|
+
if (config.dntBehavior === 'reject' && !hasConsentDecision()) {
|
|
2956
|
+
// Auto-reject non-essential cookies silently
|
|
2957
|
+
const result = rejectAll(config.expiration);
|
|
2958
|
+
dntApplied = true;
|
|
2959
|
+
|
|
2960
|
+
// Emit events
|
|
2961
|
+
emitReject(result.current);
|
|
2962
|
+
emitChange(result.current, result.previous);
|
|
2963
|
+
config.callbacks?.onReject?.();
|
|
2964
|
+
config.callbacks?.onChange?.(result.current);
|
|
2965
|
+
}
|
|
2966
|
+
// 'preselect' behavior is handled by default (banner shows with defaults off)
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
// Emit ready event
|
|
2970
|
+
emitReady(consent);
|
|
2971
|
+
config.callbacks?.onReady?.(consent);
|
|
2972
|
+
|
|
2973
|
+
// Show UI based on consent state
|
|
2974
|
+
if (!hasConsentDecision() && !dntApplied) {
|
|
2975
|
+
// No consent decision yet - show banner
|
|
2976
|
+
showBanner({
|
|
2977
|
+
onAcceptAll: handleAcceptAll,
|
|
2978
|
+
onRejectAll: handleRejectAll,
|
|
2979
|
+
onSettings: handleShowSettings
|
|
2980
|
+
});
|
|
2981
|
+
emitShow('banner');
|
|
2982
|
+
} else {
|
|
2983
|
+
// Consent already given (or DNT auto-rejected) - show widget for reopening settings
|
|
2984
|
+
if (config.showWidget) {
|
|
2985
|
+
showWidget({ onClick: handleShowSettings });
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
return Zest;
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
/**
|
|
2993
|
+
* Public API
|
|
2994
|
+
*/
|
|
2995
|
+
const Zest = {
|
|
2996
|
+
// Initialization
|
|
2997
|
+
init,
|
|
2998
|
+
|
|
2999
|
+
// Banner control
|
|
3000
|
+
show() {
|
|
3001
|
+
if (!initialized) {
|
|
3002
|
+
console.warn('[Zest] Not initialized. Call Zest.init() first.');
|
|
3003
|
+
return;
|
|
3004
|
+
}
|
|
3005
|
+
hideModal();
|
|
3006
|
+
hideWidget();
|
|
3007
|
+
showBanner({
|
|
3008
|
+
onAcceptAll: handleAcceptAll,
|
|
3009
|
+
onRejectAll: handleRejectAll,
|
|
3010
|
+
onSettings: handleShowSettings
|
|
3011
|
+
});
|
|
3012
|
+
emitShow('banner');
|
|
3013
|
+
},
|
|
3014
|
+
|
|
3015
|
+
hide() {
|
|
3016
|
+
hideBanner();
|
|
3017
|
+
emitHide('banner');
|
|
3018
|
+
},
|
|
3019
|
+
|
|
3020
|
+
// Settings modal
|
|
3021
|
+
showSettings() {
|
|
3022
|
+
if (!initialized) {
|
|
3023
|
+
console.warn('[Zest] Not initialized. Call Zest.init() first.');
|
|
3024
|
+
return;
|
|
3025
|
+
}
|
|
3026
|
+
handleShowSettings();
|
|
3027
|
+
},
|
|
3028
|
+
|
|
3029
|
+
hideSettings() {
|
|
3030
|
+
hideModal();
|
|
3031
|
+
emitHide('modal');
|
|
3032
|
+
},
|
|
3033
|
+
|
|
3034
|
+
// Consent management
|
|
3035
|
+
getConsent,
|
|
3036
|
+
hasConsent,
|
|
3037
|
+
hasConsentDecision,
|
|
3038
|
+
getConsentProof,
|
|
3039
|
+
|
|
3040
|
+
// DNT detection
|
|
3041
|
+
isDoNotTrackEnabled,
|
|
3042
|
+
getDNTDetails,
|
|
3043
|
+
|
|
3044
|
+
// Accept/Reject programmatically
|
|
3045
|
+
acceptAll() {
|
|
3046
|
+
if (!initialized) {
|
|
3047
|
+
console.warn('[Zest] Not initialized. Call Zest.init() first.');
|
|
3048
|
+
return;
|
|
3049
|
+
}
|
|
3050
|
+
handleAcceptAll();
|
|
3051
|
+
},
|
|
3052
|
+
|
|
3053
|
+
rejectAll() {
|
|
3054
|
+
if (!initialized) {
|
|
3055
|
+
console.warn('[Zest] Not initialized. Call Zest.init() first.');
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
handleRejectAll();
|
|
3059
|
+
},
|
|
3060
|
+
|
|
3061
|
+
// Reset and show banner again
|
|
3062
|
+
reset() {
|
|
3063
|
+
resetConsent();
|
|
3064
|
+
hideModal();
|
|
3065
|
+
removeWidget();
|
|
3066
|
+
|
|
3067
|
+
if (initialized) {
|
|
3068
|
+
showBanner({
|
|
3069
|
+
onAcceptAll: handleAcceptAll,
|
|
3070
|
+
onRejectAll: handleRejectAll,
|
|
3071
|
+
onSettings: handleShowSettings
|
|
3072
|
+
});
|
|
3073
|
+
emitShow('banner');
|
|
3074
|
+
}
|
|
3075
|
+
},
|
|
3076
|
+
|
|
3077
|
+
// Config
|
|
3078
|
+
getConfig: getCurrentConfig,
|
|
3079
|
+
|
|
3080
|
+
// Events
|
|
3081
|
+
EVENTS
|
|
3082
|
+
};
|
|
3083
|
+
|
|
3084
|
+
// Auto-init if config present
|
|
3085
|
+
if (typeof window !== 'undefined') {
|
|
3086
|
+
// Make Zest available globally
|
|
3087
|
+
window.Zest = Zest;
|
|
3088
|
+
|
|
3089
|
+
const autoInit = () => {
|
|
3090
|
+
const cfg = getConfig();
|
|
3091
|
+
if (cfg.autoInit !== false) {
|
|
3092
|
+
init(window.ZestConfig);
|
|
3093
|
+
}
|
|
3094
|
+
};
|
|
3095
|
+
|
|
3096
|
+
if (document.readyState === 'loading') {
|
|
3097
|
+
document.addEventListener('DOMContentLoaded', autoInit);
|
|
3098
|
+
} else {
|
|
3099
|
+
autoInit();
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
export { Zest as default };
|
|
3104
|
+
//# sourceMappingURL=zest.esm.js.map
|