@solvenza/cookies-compliance 1.0.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.
Files changed (43) hide show
  1. package/README.md +245 -0
  2. package/bin/audit-cli.js +25 -0
  3. package/bin/init-cli.js +126 -0
  4. package/dist/chunk-DDAAVRWG.js +25 -0
  5. package/dist/chunk-DDAAVRWG.js.map +1 -0
  6. package/dist/chunk-LIWFUVWY.js +1858 -0
  7. package/dist/chunk-LIWFUVWY.js.map +1 -0
  8. package/dist/consent-engine-BvsH_wqV.d.cts +191 -0
  9. package/dist/consent-engine-BvsH_wqV.d.ts +191 -0
  10. package/dist/consent.esm.cjs +2051 -0
  11. package/dist/consent.esm.cjs.map +1 -0
  12. package/dist/consent.esm.d.cts +146 -0
  13. package/dist/consent.esm.d.ts +146 -0
  14. package/dist/consent.esm.js +184 -0
  15. package/dist/consent.esm.js.map +1 -0
  16. package/dist/consent.min.js +589 -0
  17. package/dist/consent.min.js.map +1 -0
  18. package/dist/wrappers/angular.cjs +1867 -0
  19. package/dist/wrappers/angular.cjs.map +1 -0
  20. package/dist/wrappers/angular.d.cts +20 -0
  21. package/dist/wrappers/angular.d.ts +20 -0
  22. package/dist/wrappers/angular.js +42 -0
  23. package/dist/wrappers/angular.js.map +1 -0
  24. package/dist/wrappers/next.cjs +1840 -0
  25. package/dist/wrappers/next.cjs.map +1 -0
  26. package/dist/wrappers/next.d.cts +3 -0
  27. package/dist/wrappers/next.d.ts +3 -0
  28. package/dist/wrappers/next.js +15 -0
  29. package/dist/wrappers/next.js.map +1 -0
  30. package/dist/wrappers/react.cjs +1882 -0
  31. package/dist/wrappers/react.cjs.map +1 -0
  32. package/dist/wrappers/react.d.cts +4 -0
  33. package/dist/wrappers/react.d.ts +4 -0
  34. package/dist/wrappers/react.js +56 -0
  35. package/dist/wrappers/react.js.map +1 -0
  36. package/dist/wrappers/wordpress.cjs +64 -0
  37. package/dist/wrappers/wordpress.cjs.map +1 -0
  38. package/dist/wrappers/wordpress.d.cts +10 -0
  39. package/dist/wrappers/wordpress.d.ts +10 -0
  40. package/dist/wrappers/wordpress.js +41 -0
  41. package/dist/wrappers/wordpress.js.map +1 -0
  42. package/package.json +85 -0
  43. package/schema.json +165 -0
@@ -0,0 +1,1858 @@
1
+ import {
2
+ __spreadValues
3
+ } from "./chunk-DDAAVRWG.js";
4
+
5
+ // src/core/config-validator.ts
6
+ var ConfigValidationError = class extends Error {
7
+ constructor(message) {
8
+ super(`[ConsentSDK Config Error] ${message}`);
9
+ this.name = "ConfigValidationError";
10
+ }
11
+ };
12
+ function validateConfig(config) {
13
+ if (!config) {
14
+ throw new ConfigValidationError("Configuration object is null or undefined.");
15
+ }
16
+ if (typeof config.schemaVersion !== "number" || config.schemaVersion < 1) {
17
+ throw new ConfigValidationError("Invalid or missing 'schemaVersion'. Expected integer >= 1.");
18
+ }
19
+ if (!config.policyVersion || typeof config.policyVersion !== "string") {
20
+ throw new ConfigValidationError("Invalid or missing 'policyVersion'. String required.");
21
+ }
22
+ if (!config.categories || typeof config.categories !== "object") {
23
+ throw new ConfigValidationError("Missing 'categories' map in configuration.");
24
+ }
25
+ const categoryKeys = Object.keys(config.categories);
26
+ if (categoryKeys.length === 0) {
27
+ throw new ConfigValidationError("At least one category must be defined in 'categories'.");
28
+ }
29
+ const necessaryCategory = config.categories["necessary"];
30
+ if (!necessaryCategory) {
31
+ throw new ConfigValidationError("Category 'necessary' must be defined.");
32
+ }
33
+ if (necessaryCategory.required !== true) {
34
+ throw new ConfigValidationError("Category 'necessary' must have 'required: true'.");
35
+ }
36
+ for (const [catId, catConfig] of Object.entries(config.categories)) {
37
+ if (catId !== "necessary" && !catConfig.required) {
38
+ if (catConfig.default === true) {
39
+ throw new ConfigValidationError(
40
+ `Legal violation (AEPD): Optional category '${catId}' cannot have default: true. All optional categories must be opt-in (default: false).`
41
+ );
42
+ }
43
+ }
44
+ }
45
+ if (config.services && typeof config.services === "object") {
46
+ for (const [serviceId, serviceConfig] of Object.entries(config.services)) {
47
+ if (!serviceConfig.category) {
48
+ throw new ConfigValidationError(
49
+ `Service '${serviceId}' missing 'category' reference.`
50
+ );
51
+ }
52
+ if (!config.categories[serviceConfig.category]) {
53
+ throw new ConfigValidationError(
54
+ `Service '${serviceId}' references non-existent category '${serviceConfig.category}'.`
55
+ );
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ // src/core/security.ts
62
+ function sha256Sync(ascii) {
63
+ let i, j;
64
+ let result = "";
65
+ const asciiLength = ascii.length * 8;
66
+ let hash = [
67
+ 1779033703,
68
+ 3144134277,
69
+ 1013904242,
70
+ 2773480762,
71
+ 1359893119,
72
+ 2600822924,
73
+ 528734635,
74
+ 1541459225
75
+ ];
76
+ const k = [
77
+ 1116352408,
78
+ 1899447441,
79
+ 3049323471,
80
+ 3921009573,
81
+ 961987163,
82
+ 1508970993,
83
+ 2453635748,
84
+ 2870763221,
85
+ 3624381080,
86
+ 310598401,
87
+ 607225278,
88
+ 1426881987,
89
+ 1925078388,
90
+ 2162078206,
91
+ 2614888103,
92
+ 3248222580,
93
+ 3835390401,
94
+ 4022224774,
95
+ 264347078,
96
+ 604807628,
97
+ 770255983,
98
+ 1249150122,
99
+ 1555081692,
100
+ 1996064986,
101
+ 2554220882,
102
+ 2821834349,
103
+ 2952996808,
104
+ 3210313671,
105
+ 3336571891,
106
+ 3584528711,
107
+ 113926993,
108
+ 338241895,
109
+ 666307205,
110
+ 773529912,
111
+ 1294757372,
112
+ 1396182291,
113
+ 1695183700,
114
+ 1986661051,
115
+ 2177026350,
116
+ 2456956037,
117
+ 2730485921,
118
+ 2820302411,
119
+ 3259730800,
120
+ 3345764771,
121
+ 3516065817,
122
+ 3600352804,
123
+ 4094571909,
124
+ 275423344,
125
+ 430227734,
126
+ 506948616,
127
+ 659060556,
128
+ 883997877,
129
+ 958139571,
130
+ 1322822218,
131
+ 1537002063,
132
+ 1747873779,
133
+ 1955562222,
134
+ 2024104815,
135
+ 2227730452,
136
+ 2361852424,
137
+ 2428436474,
138
+ 2756734187,
139
+ 3204031479,
140
+ 3329325298
141
+ ];
142
+ const blocks = [];
143
+ for (i = 0; i < ascii.length; i++) {
144
+ blocks[i >> 2] |= ascii.charCodeAt(i) << 24 - i % 4 * 8;
145
+ }
146
+ blocks[asciiLength >> 5] |= 128 << 24 - asciiLength % 32;
147
+ blocks[(asciiLength + 64 >> 9 << 4) + 15] = asciiLength;
148
+ for (i = 0; i < blocks.length; i += 16) {
149
+ const w = blocks.slice(i, i + 16);
150
+ const oldHash = [...hash];
151
+ for (j = 0; j < 64; j++) {
152
+ const w15 = w[j - 15], w2 = w[j - 2];
153
+ const s0 = (w15 >>> 7 | w15 << 25) ^ (w15 >>> 18 | w15 << 14) ^ w15 >>> 3;
154
+ const s1 = (w2 >>> 17 | w2 << 15) ^ (w2 >>> 19 | w2 << 13) ^ w2 >>> 10;
155
+ w[j] = j < 16 ? w[j] || 0 : w[j - 16] + s0 + w[j - 7] + s1 | 0;
156
+ const ch = hash[4] & hash[5] ^ ~hash[4] & hash[6];
157
+ const maj = hash[0] & hash[1] ^ hash[0] & hash[2] ^ hash[1] & hash[2];
158
+ const sig0 = (hash[0] >>> 2 | hash[0] << 30) ^ (hash[0] >>> 13 | hash[0] << 19) ^ (hash[0] >>> 22 | hash[0] << 10);
159
+ const sig1 = (hash[4] >>> 6 | hash[4] << 26) ^ (hash[4] >>> 11 | hash[4] << 21) ^ (hash[4] >>> 25 | hash[4] << 7);
160
+ const t1 = hash[7] + sig1 + ch + k[j] + (w[j] | 0);
161
+ const t2 = sig0 + maj;
162
+ hash[7] = hash[6];
163
+ hash[6] = hash[5];
164
+ hash[5] = hash[4];
165
+ hash[4] = hash[3] + t1 | 0;
166
+ hash[3] = hash[2];
167
+ hash[2] = hash[1];
168
+ hash[1] = hash[0];
169
+ hash[0] = t1 + t2 | 0;
170
+ }
171
+ for (j = 0; j < 8; j++) {
172
+ hash[j] = hash[j] + oldHash[j] | 0;
173
+ }
174
+ }
175
+ for (i = 0; i < 8; i++) {
176
+ for (j = 3; j >= 0; j--) {
177
+ const b = hash[i] >> j * 8 & 255;
178
+ result += (b < 16 ? "0" : "") + b.toString(16);
179
+ }
180
+ }
181
+ return result;
182
+ }
183
+ function computeReceiptSignature(payload, secretKey) {
184
+ if (secretKey) {
185
+ return sha256Sync(`${secretKey}:${payload}:${secretKey}`);
186
+ }
187
+ let hash = 2166136261;
188
+ for (let i = 0; i < payload.length; i++) {
189
+ hash ^= payload.charCodeAt(i);
190
+ hash = Math.imul(hash, 16777619);
191
+ }
192
+ return (hash >>> 0).toString(16);
193
+ }
194
+ function verifyReceiptIntegrity(payload, expectedSignature, secretKey) {
195
+ if (!expectedSignature) return false;
196
+ return computeReceiptSignature(payload, secretKey) === expectedSignature;
197
+ }
198
+ function sanitizeHtml(str) {
199
+ if (!str) return "";
200
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
201
+ }
202
+ function sanitizeUrl(url) {
203
+ if (!url) return "#";
204
+ const trimmed = url.trim().toLowerCase();
205
+ if (trimmed.startsWith("javascript:") || trimmed.startsWith("data:") || trimmed.startsWith("vbscript:")) {
206
+ return "#";
207
+ }
208
+ return url;
209
+ }
210
+
211
+ // src/core/receipt.ts
212
+ function generateUUID() {
213
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
214
+ return crypto.randomUUID();
215
+ }
216
+ return "xxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
217
+ const r = Math.random() * 16 | 0;
218
+ const v = c === "x" ? r : r & 3 | 8;
219
+ return v.toString(16);
220
+ });
221
+ }
222
+ function createReceipt(policyVersion, choices, source, existingReceipt, secretKey) {
223
+ const now = (/* @__PURE__ */ new Date()).toISOString();
224
+ const receiptId = (existingReceipt == null ? void 0 : existingReceipt.receiptId) || generateUUID();
225
+ const decidedAt = (existingReceipt == null ? void 0 : existingReceipt.decidedAt) || now;
226
+ const payloadToSign = `${receiptId}:${policyVersion}:${JSON.stringify(choices)}`;
227
+ const signature = computeReceiptSignature(payloadToSign, secretKey);
228
+ return {
229
+ schema: 1,
230
+ receiptId,
231
+ policyVersion,
232
+ decidedAt,
233
+ updatedAt: now,
234
+ source,
235
+ choices,
236
+ signature
237
+ };
238
+ }
239
+ function parseReceipt(jsonStr) {
240
+ try {
241
+ const data = JSON.parse(jsonStr);
242
+ if (typeof data === "object" && data !== null && typeof data.receiptId === "string" && typeof data.policyVersion === "string" && typeof data.choices === "object") {
243
+ return data;
244
+ }
245
+ return null;
246
+ } catch (e) {
247
+ return null;
248
+ }
249
+ }
250
+ function isReceiptExpired(receipt, maxAgeDays = 365) {
251
+ if (!receipt.updatedAt) return true;
252
+ const updated = new Date(receipt.updatedAt).getTime();
253
+ const now = Date.now();
254
+ const maxAgeMs = maxAgeDays * 86400 * 1e3;
255
+ return now - updated > maxAgeMs;
256
+ }
257
+
258
+ // src/storage/cookie-store.ts
259
+ var CookieStorageProvider = class {
260
+ get(key) {
261
+ return CookieStore.get(key);
262
+ }
263
+ set(key, value, options) {
264
+ CookieStore.set(key, value, options);
265
+ }
266
+ remove(key, path = "/") {
267
+ CookieStore.remove(key, path);
268
+ }
269
+ };
270
+ var CookieStore = class {
271
+ static get(name) {
272
+ if (typeof document === "undefined") return null;
273
+ const nameEQ = encodeURIComponent(name) + "=";
274
+ const ca = document.cookie.split(";");
275
+ for (let i = 0; i < ca.length; i++) {
276
+ let c = ca[i];
277
+ while (c.charAt(0) === " ") c = c.substring(1, c.length);
278
+ if (c.indexOf(nameEQ) === 0) {
279
+ return decodeURIComponent(c.substring(nameEQ.length, c.length));
280
+ }
281
+ }
282
+ return null;
283
+ }
284
+ static set(name, value, options = {}) {
285
+ var _a, _b;
286
+ if (typeof document === "undefined") return;
287
+ const path = options.path || "/";
288
+ const maxAgeDays = (_a = options.maxAgeDays) != null ? _a : 365;
289
+ const maxAgeSeconds = Math.floor(maxAgeDays * 86400);
290
+ const sameSite = options.sameSite || "Lax";
291
+ const isHttps = typeof window !== "undefined" && window.location.protocol === "https:";
292
+ const secure = (_b = options.secure) != null ? _b : isHttps;
293
+ let cookieStr = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; Path=${path}; Max-Age=${maxAgeSeconds}; SameSite=${sameSite}`;
294
+ if (secure) {
295
+ cookieStr += "; Secure";
296
+ }
297
+ document.cookie = cookieStr;
298
+ }
299
+ static remove(name, path = "/") {
300
+ if (typeof document === "undefined") return;
301
+ document.cookie = `${encodeURIComponent(name)}=; Path=${path}; Max-Age=0; SameSite=Lax`;
302
+ }
303
+ };
304
+
305
+ // src/storage/memory-store.ts
306
+ var _MemoryStorageProvider = class _MemoryStorageProvider {
307
+ get(key) {
308
+ var _a;
309
+ return (_a = _MemoryStorageProvider.store.get(key)) != null ? _a : null;
310
+ }
311
+ set(key, value) {
312
+ _MemoryStorageProvider.store.set(key, value);
313
+ }
314
+ remove(key) {
315
+ _MemoryStorageProvider.store.delete(key);
316
+ }
317
+ clear() {
318
+ _MemoryStorageProvider.store.clear();
319
+ }
320
+ };
321
+ _MemoryStorageProvider.store = /* @__PURE__ */ new Map();
322
+ var MemoryStorageProvider = _MemoryStorageProvider;
323
+ var MemoryStore = {
324
+ get: (name) => new MemoryStorageProvider().get(name),
325
+ set: (name, val) => new MemoryStorageProvider().set(name, val),
326
+ remove: (name) => new MemoryStorageProvider().remove(name),
327
+ clear: () => new MemoryStorageProvider().clear()
328
+ };
329
+
330
+ // src/blocker/script-gate.ts
331
+ var ScriptResourceBlocker = class {
332
+ constructor() {
333
+ this.type = "script";
334
+ }
335
+ process(isCategoryAllowed, isServiceAllowed) {
336
+ ScriptGate.scanAndActivate(isCategoryAllowed, isServiceAllowed);
337
+ }
338
+ };
339
+ var ScriptGate = class {
340
+ static scanAndActivate(isCategoryAllowed, isServiceAllowed, onServiceLoaded) {
341
+ var _a;
342
+ if (typeof document === "undefined") return;
343
+ const blockedScripts = Array.from(
344
+ document.querySelectorAll(
345
+ 'script[type="text/plain"][data-consent], script[type="text/plain"][data-service]'
346
+ )
347
+ );
348
+ for (const oldScript of blockedScripts) {
349
+ if (this.executedScripts.has(oldScript)) continue;
350
+ const category = oldScript.getAttribute("data-consent");
351
+ const serviceId = oldScript.getAttribute("data-service");
352
+ let isAllowed = false;
353
+ if (serviceId) {
354
+ isAllowed = isServiceAllowed(serviceId);
355
+ } else if (category) {
356
+ isAllowed = isCategoryAllowed(category);
357
+ }
358
+ if (!isAllowed) continue;
359
+ this.executedScripts.add(oldScript);
360
+ const newScript = document.createElement("script");
361
+ for (let i = 0; i < oldScript.attributes.length; i++) {
362
+ const attr = oldScript.attributes[i];
363
+ if (attr.name === "type") continue;
364
+ if (attr.name === "data-src") {
365
+ newScript.src = attr.value;
366
+ continue;
367
+ }
368
+ newScript.setAttribute(attr.name, attr.value);
369
+ }
370
+ newScript.type = "text/javascript";
371
+ if (!newScript.src && oldScript.textContent) {
372
+ newScript.textContent = oldScript.textContent;
373
+ }
374
+ (_a = oldScript.parentNode) == null ? void 0 : _a.replaceChild(newScript, oldScript);
375
+ if (serviceId || category) {
376
+ onServiceLoaded == null ? void 0 : onServiceLoaded(serviceId || category, category || "custom");
377
+ }
378
+ }
379
+ }
380
+ };
381
+ ScriptGate.executedScripts = /* @__PURE__ */ new Set();
382
+
383
+ // src/blocker/iframe-gate.ts
384
+ var IframeResourceBlocker = class {
385
+ constructor() {
386
+ this.type = "iframe";
387
+ }
388
+ process(isCategoryAllowed, isServiceAllowed) {
389
+ IframeGate.processIframes(isCategoryAllowed, isServiceAllowed);
390
+ }
391
+ };
392
+ var IframeGate = class {
393
+ static processIframes(isCategoryAllowed, isServiceAllowed, options = {}) {
394
+ if (typeof document === "undefined") return;
395
+ const iframes = Array.from(
396
+ document.querySelectorAll(
397
+ "iframe[data-consent], iframe[data-service]"
398
+ )
399
+ );
400
+ for (const iframe of iframes) {
401
+ const category = iframe.getAttribute("data-consent");
402
+ const serviceId = iframe.getAttribute("data-service");
403
+ let isAllowed = false;
404
+ if (serviceId) {
405
+ isAllowed = isServiceAllowed(serviceId);
406
+ } else if (category) {
407
+ isAllowed = isCategoryAllowed(category);
408
+ }
409
+ const originalSrc = iframe.getAttribute("data-src") || iframe.getAttribute("src");
410
+ if (!originalSrc) continue;
411
+ if (!iframe.getAttribute("data-src")) {
412
+ iframe.setAttribute("data-src", originalSrc);
413
+ }
414
+ if (isAllowed) {
415
+ this.unlockIframe(iframe, originalSrc);
416
+ } else {
417
+ this.lockIframe(
418
+ iframe,
419
+ category || "marketing",
420
+ serviceId || void 0,
421
+ options
422
+ );
423
+ }
424
+ }
425
+ }
426
+ static lockIframe(iframe, category, serviceId, options) {
427
+ var _a;
428
+ if (iframe.hasAttribute("src")) {
429
+ iframe.removeAttribute("src");
430
+ }
431
+ if (this.placeholders.has(iframe)) return;
432
+ const container = document.createElement("div");
433
+ container.className = "consent-iframe-placeholder";
434
+ container.style.cssText = `
435
+ width: ${iframe.width ? iframe.width.endsWith("%") || iframe.width.endsWith("px") ? iframe.width : iframe.width + "px" : "100%"};
436
+ height: ${iframe.height ? iframe.height.endsWith("%") || iframe.height.endsWith("px") ? iframe.height : iframe.height + "px" : "315px"};
437
+ min-height: 200px;
438
+ background: #0f172a;
439
+ color: #f8fafc;
440
+ display: flex;
441
+ flex-direction: column;
442
+ align-items: center;
443
+ justify-content: center;
444
+ text-align: center;
445
+ padding: 1.5rem;
446
+ border-radius: 8px;
447
+ box-sizing: border-box;
448
+ font-family: system-ui, -apple-system, sans-serif;
449
+ `;
450
+ const titleText = serviceId ? `Contenido de ${serviceId} bloqueado` : "Contenido externo bloqueado";
451
+ const bodyText = "Este contenido est\xE1 bloqueado hasta que autorices esta finalidad de privacidad.";
452
+ container.innerHTML = `
453
+ <div style="font-weight: 600; font-size: 1.1rem; margin-bottom: 0.5rem; color: #f8fafc;">
454
+ ${titleText}
455
+ </div>
456
+ <p style="font-size: 0.9rem; color: #94a3b8; margin: 0 0 1rem 0; max-width: 400px;">
457
+ ${bodyText}
458
+ </p>
459
+ <button type="button" class="consent-placeholder-allow-btn" style="
460
+ background: #2563eb;
461
+ color: #ffffff;
462
+ border: none;
463
+ padding: 0.6rem 1.2rem;
464
+ border-radius: 6px;
465
+ font-weight: 500;
466
+ cursor: pointer;
467
+ font-size: 0.9rem;
468
+ transition: background 0.2s ease;
469
+ ">
470
+ Permitir y mostrar contenido
471
+ </button>
472
+ `;
473
+ const button = container.querySelector(
474
+ ".consent-placeholder-allow-btn"
475
+ );
476
+ button == null ? void 0 : button.addEventListener("click", () => {
477
+ var _a2;
478
+ (_a2 = options.onAllowClick) == null ? void 0 : _a2.call(options, category, serviceId);
479
+ });
480
+ iframe.style.display = "none";
481
+ (_a = iframe.parentNode) == null ? void 0 : _a.insertBefore(container, iframe);
482
+ this.placeholders.set(iframe, container);
483
+ }
484
+ static unlockIframe(iframe, src) {
485
+ var _a;
486
+ if (iframe.getAttribute("src") !== src) {
487
+ iframe.setAttribute("src", src);
488
+ }
489
+ iframe.style.display = "";
490
+ const placeholder = this.placeholders.get(iframe);
491
+ if (placeholder) {
492
+ (_a = placeholder.parentNode) == null ? void 0 : _a.removeChild(placeholder);
493
+ this.placeholders.delete(iframe);
494
+ }
495
+ }
496
+ };
497
+ IframeGate.placeholders = /* @__PURE__ */ new Map();
498
+
499
+ // src/blocker/resource-gate.ts
500
+ var ImageResourceBlocker = class {
501
+ constructor() {
502
+ this.type = "image";
503
+ }
504
+ process(isCategoryAllowed, isServiceAllowed) {
505
+ ResourceGate.processImages(isCategoryAllowed, isServiceAllowed);
506
+ }
507
+ };
508
+ var ResourceGate = class {
509
+ static processImages(isCategoryAllowed, isServiceAllowed) {
510
+ if (typeof document === "undefined") return;
511
+ const images = Array.from(
512
+ document.querySelectorAll(
513
+ "img[data-consent], img[data-service]"
514
+ )
515
+ );
516
+ for (const img of images) {
517
+ const category = img.getAttribute("data-consent");
518
+ const serviceId = img.getAttribute("data-service");
519
+ let isAllowed = false;
520
+ if (serviceId) {
521
+ isAllowed = isServiceAllowed(serviceId);
522
+ } else if (category) {
523
+ isAllowed = isCategoryAllowed(category);
524
+ }
525
+ const originalSrc = img.getAttribute("data-src") || img.getAttribute("src");
526
+ if (!originalSrc) continue;
527
+ if (!img.getAttribute("data-src")) {
528
+ img.setAttribute("data-src", originalSrc);
529
+ }
530
+ if (isAllowed) {
531
+ if (img.getAttribute("src") !== originalSrc) {
532
+ img.setAttribute("src", originalSrc);
533
+ }
534
+ } else {
535
+ if (img.hasAttribute("src")) {
536
+ img.removeAttribute("src");
537
+ }
538
+ }
539
+ }
540
+ }
541
+ };
542
+
543
+ // src/services/google.ts
544
+ var GoogleConsentAdapter = class {
545
+ static initDefault(_configMap) {
546
+ if (typeof window === "undefined") return;
547
+ window.dataLayer = window.dataLayer || [];
548
+ if (!window.gtag) {
549
+ window.gtag = function() {
550
+ var _a;
551
+ (_a = window.dataLayer) == null ? void 0 : _a.push(arguments);
552
+ };
553
+ }
554
+ if (!this.initialized) {
555
+ window.gtag("consent", "default", {
556
+ analytics_storage: "denied",
557
+ ad_storage: "denied",
558
+ ad_user_data: "denied",
559
+ ad_personalization: "denied",
560
+ wait_for_update: 500
561
+ });
562
+ this.initialized = true;
563
+ }
564
+ }
565
+ static update(choices, configMap) {
566
+ if (typeof window === "undefined") return;
567
+ this.initDefault(configMap);
568
+ const analyticsCategory = (configMap == null ? void 0 : configMap.analytics_storage) || "analytics";
569
+ const marketingCategory = (configMap == null ? void 0 : configMap.ad_storage) || "marketing";
570
+ const isAnalyticsAllowed = choices[analyticsCategory] === true;
571
+ const isMarketingAllowed = choices[marketingCategory] === true;
572
+ window.gtag("consent", "update", {
573
+ analytics_storage: isAnalyticsAllowed ? "granted" : "denied",
574
+ ad_storage: isMarketingAllowed ? "granted" : "denied",
575
+ ad_user_data: isMarketingAllowed ? "granted" : "denied",
576
+ ad_personalization: isMarketingAllowed ? "granted" : "denied"
577
+ });
578
+ }
579
+ };
580
+ GoogleConsentAdapter.initialized = false;
581
+
582
+ // src/diagnostics/resource-scanner.ts
583
+ var ResourceScanner = class _ResourceScanner {
584
+ static runDiagnostic(_config, isConsentGiven) {
585
+ const thirdPartyScripts = [];
586
+ if (typeof document !== "undefined") {
587
+ const scripts = document.querySelectorAll("script[src]");
588
+ scripts.forEach((script) => {
589
+ const src = script.getAttribute("src");
590
+ if (src && (src.startsWith("http://") || src.startsWith("https://"))) {
591
+ thirdPartyScripts.push(src);
592
+ }
593
+ });
594
+ }
595
+ return {
596
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
597
+ unblockedThirdPartyScripts: isConsentGiven ? [] : thirdPartyScripts,
598
+ compliant: isConsentGiven || thirdPartyScripts.length === 0
599
+ };
600
+ }
601
+ scanThirdPartyResources() {
602
+ return _ResourceScanner.runDiagnostic({}, true).unblockedThirdPartyScripts;
603
+ }
604
+ };
605
+
606
+ // src/ui/policy-generator.ts
607
+ var PolicyGenerator = class {
608
+ static renderTable(config) {
609
+ let html = `
610
+ <div class="consent-policy-table-wrapper" style="margin: 1.5rem 0; font-family: system-ui, sans-serif;">
611
+ <table style="width: 100%; border-collapse: collapse; text-align: left; border: 1px solid #e2e8f0;">
612
+ <thead>
613
+ <tr style="background: #f8fafc; border-bottom: 2px solid #cbd5e1;">
614
+ <th style="padding: 0.75rem; border: 1px solid #e2e8f0;">Categor\xEDa / Servicio</th>
615
+ <th style="padding: 0.75rem; border: 1px solid #e2e8f0;">Proveedor</th>
616
+ <th style="padding: 0.75rem; border: 1px solid #e2e8f0;">Finalidad</th>
617
+ <th style="padding: 0.75rem; border: 1px solid #e2e8f0;">Requerida</th>
618
+ </tr>
619
+ </thead>
620
+ <tbody>
621
+ `;
622
+ for (const [catId, cat] of Object.entries(config.categories)) {
623
+ const isReq = cat.required ? "S\xED (T\xE9cnica)" : "No (Opcional)";
624
+ html += `
625
+ <tr style="background: #ffffff; font-weight: 600;">
626
+ <td style="padding: 0.75rem; border: 1px solid #e2e8f0;" colspan="3">${sanitizeHtml(cat.label)}</td>
627
+ <td style="padding: 0.75rem; border: 1px solid #e2e8f0;">${isReq}</td>
628
+ </tr>
629
+ `;
630
+ if (config.services) {
631
+ for (const [srvId, srv] of Object.entries(config.services)) {
632
+ if (srv.category === catId) {
633
+ html += `
634
+ <tr style="background: #f8fafc; font-size: 0.9rem;">
635
+ <td style="padding: 0.5rem 0.75rem 0.5rem 1.5rem; border: 1px solid #e2e8f0;">\u21B3 ${sanitizeHtml(srv.label || srvId)}</td>
636
+ <td style="padding: 0.5rem 0.75rem; border: 1px solid #e2e8f0;">${sanitizeHtml(srv.provider || "-")}</td>
637
+ <td style="padding: 0.5rem 0.75rem; border: 1px solid #e2e8f0;">${sanitizeHtml(cat.description || "-")}</td>
638
+ <td style="padding: 0.5rem 0.75rem; border: 1px solid #e2e8f0;">${isReq}</td>
639
+ </tr>
640
+ `;
641
+ }
642
+ }
643
+ }
644
+ }
645
+ html += `
646
+ </tbody>
647
+ </table>
648
+ </div>
649
+ `;
650
+ return html;
651
+ }
652
+ };
653
+
654
+ // src/core/state.ts
655
+ var StateManager = class {
656
+ constructor() {
657
+ this.state = {
658
+ initialized: false,
659
+ policyVersion: "",
660
+ locale: "es",
661
+ receipt: null,
662
+ choices: {}
663
+ };
664
+ this.config = null;
665
+ }
666
+ init(config, choices, receipt) {
667
+ var _a;
668
+ this.config = config;
669
+ this.state = {
670
+ initialized: true,
671
+ policyVersion: config.policyVersion,
672
+ locale: ((_a = config.locale) == null ? void 0 : _a.default) || "es",
673
+ receipt,
674
+ choices
675
+ };
676
+ }
677
+ getConfig() {
678
+ return this.config;
679
+ }
680
+ getState() {
681
+ return __spreadValues({}, this.state);
682
+ }
683
+ getChoices() {
684
+ return __spreadValues({}, this.state.choices);
685
+ }
686
+ getReceipt() {
687
+ return this.state.receipt;
688
+ }
689
+ hasCategory(category) {
690
+ return this.state.choices[category] === true;
691
+ }
692
+ hasService(serviceId) {
693
+ if (!this.config || !this.config.services) return false;
694
+ const service = this.config.services[serviceId];
695
+ if (!service) return false;
696
+ return this.hasCategory(service.category);
697
+ }
698
+ updateChoices(receipt) {
699
+ this.state.receipt = receipt;
700
+ this.state.choices = __spreadValues({}, receipt.choices);
701
+ }
702
+ clearChoices() {
703
+ if (!this.config) return;
704
+ const resetChoices = {};
705
+ for (const [catId, catConfig] of Object.entries(this.config.categories)) {
706
+ resetChoices[catId] = catConfig.required === true;
707
+ }
708
+ this.state.choices = resetChoices;
709
+ this.state.receipt = null;
710
+ }
711
+ };
712
+
713
+ // src/core/events.ts
714
+ var EventBus = class {
715
+ constructor() {
716
+ this.handlers = /* @__PURE__ */ new Map();
717
+ }
718
+ on(event, handler) {
719
+ if (!this.handlers.has(event)) {
720
+ this.handlers.set(event, /* @__PURE__ */ new Set());
721
+ }
722
+ const set = this.handlers.get(event);
723
+ set.add(handler);
724
+ return () => {
725
+ set.delete(handler);
726
+ };
727
+ }
728
+ emit(event, detail) {
729
+ const set = this.handlers.get(event);
730
+ if (!set) return;
731
+ for (const handler of set) {
732
+ try {
733
+ handler(detail);
734
+ } catch (err) {
735
+ console.error(`[ConsentSDK Event Error] Handler for '${event}' failed:`, err);
736
+ }
737
+ }
738
+ }
739
+ clear() {
740
+ this.handlers.clear();
741
+ }
742
+ };
743
+
744
+ // src/core/policy-engine.ts
745
+ function evaluatePolicy(config, receipt) {
746
+ var _a, _b, _c;
747
+ const defaultChoices = {};
748
+ for (const [catId, catConfig] of Object.entries(config.categories)) {
749
+ defaultChoices[catId] = catConfig.required === true;
750
+ }
751
+ if (!receipt) {
752
+ return {
753
+ isValid: false,
754
+ reason: "missing",
755
+ choices: defaultChoices
756
+ };
757
+ }
758
+ if (receipt.policyVersion !== config.policyVersion) {
759
+ return {
760
+ isValid: false,
761
+ reason: "policy_version_changed",
762
+ choices: defaultChoices
763
+ };
764
+ }
765
+ const maxAgeDays = (_b = (_a = config.consent) == null ? void 0 : _a.maxAgeDays) != null ? _b : 365;
766
+ if (isReceiptExpired(receipt, maxAgeDays)) {
767
+ return {
768
+ isValid: false,
769
+ reason: "expired",
770
+ choices: defaultChoices
771
+ };
772
+ }
773
+ if (receipt.signature) {
774
+ const payloadToSign = `${receipt.receiptId}:${receipt.policyVersion}:${JSON.stringify(receipt.choices)}`;
775
+ const expectedSignature = computeReceiptSignature(payloadToSign, (_c = config.security) == null ? void 0 : _c.secretKey);
776
+ if (receipt.signature !== expectedSignature) {
777
+ return {
778
+ isValid: false,
779
+ reason: "tampered",
780
+ choices: defaultChoices
781
+ };
782
+ }
783
+ }
784
+ const activeChoices = __spreadValues({}, defaultChoices);
785
+ for (const catId of Object.keys(config.categories)) {
786
+ if (catId === "necessary") {
787
+ activeChoices[catId] = true;
788
+ } else if (typeof receipt.choices[catId] === "boolean") {
789
+ activeChoices[catId] = receipt.choices[catId];
790
+ }
791
+ }
792
+ return {
793
+ isValid: true,
794
+ reason: "valid",
795
+ choices: activeChoices
796
+ };
797
+ }
798
+
799
+ // src/blocker/registry.ts
800
+ var BlockerRegistry = class {
801
+ constructor() {
802
+ this.observer = null;
803
+ }
804
+ init(isCategoryAllowed, isServiceAllowed, iframeOptions, onServiceLoaded) {
805
+ const runBlockers = () => {
806
+ ScriptGate.scanAndActivate(
807
+ isCategoryAllowed,
808
+ isServiceAllowed,
809
+ onServiceLoaded
810
+ );
811
+ IframeGate.processIframes(
812
+ isCategoryAllowed,
813
+ isServiceAllowed,
814
+ iframeOptions
815
+ );
816
+ ResourceGate.processImages(isCategoryAllowed, isServiceAllowed);
817
+ };
818
+ runBlockers();
819
+ if (typeof MutationObserver !== "undefined" && typeof document !== "undefined") {
820
+ this.observer = new MutationObserver(() => {
821
+ runBlockers();
822
+ });
823
+ this.observer.observe(document.documentElement || document.body, {
824
+ childList: true,
825
+ subtree: true
826
+ });
827
+ }
828
+ }
829
+ destroy() {
830
+ if (this.observer) {
831
+ this.observer.disconnect();
832
+ this.observer = null;
833
+ }
834
+ }
835
+ };
836
+
837
+ // src/services/custom.ts
838
+ var CustomServiceAdapter = class {
839
+ static createWhen(eventBus, isCategoryAllowed, isServiceAllowed) {
840
+ return function when(categoryOrService, callback) {
841
+ if (isCategoryAllowed(categoryOrService) || isServiceAllowed(categoryOrService)) {
842
+ try {
843
+ callback();
844
+ } catch (err) {
845
+ console.error(`[ConsentSDK when()] Callback execution failed:`, err);
846
+ }
847
+ }
848
+ return eventBus.on("consent:changed", ({ choices }) => {
849
+ if (choices[categoryOrService] === true || isServiceAllowed(categoryOrService)) {
850
+ try {
851
+ callback();
852
+ } catch (err) {
853
+ console.error(`[ConsentSDK when()] Callback execution failed:`, err);
854
+ }
855
+ }
856
+ });
857
+ };
858
+ }
859
+ };
860
+
861
+ // src/ui/styles.ts
862
+ function injectStyles(nonce) {
863
+ if (typeof document === "undefined") return;
864
+ const existing = document.getElementById("consent-sdk-styles");
865
+ if (existing) {
866
+ existing.remove();
867
+ }
868
+ const styleEl = document.createElement("style");
869
+ styleEl.id = "consent-sdk-styles";
870
+ if (nonce) {
871
+ styleEl.setAttribute("nonce", nonce);
872
+ }
873
+ styleEl.textContent = `
874
+ :root {
875
+ --consent-bg: #ffffff;
876
+ --consent-fg: #0f172a;
877
+ --consent-muted: #64748b;
878
+ --consent-divider: #f1f5f9;
879
+ --consent-border: #e2e8f0;
880
+ --consent-hover-bg: #f8fafc;
881
+ --consent-primary: #0f172a;
882
+ --consent-primary-hover: #1e293b;
883
+ --consent-primary-fg: #ffffff;
884
+ --consent-secondary: #f8fafc;
885
+ --consent-secondary-hover: #f1f5f9;
886
+ --consent-secondary-fg: #0f172a;
887
+ --consent-accent: #2563eb;
888
+ --consent-focus-ring: rgba(37, 99, 235, 0.3);
889
+ --consent-font: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
890
+ --consent-modal-shadow: 0 32px 64px -16px rgba(15, 23, 42, 0.2), 0 0 1px rgba(15, 23, 42, 0.12);
891
+ }
892
+
893
+ @media (prefers-color-scheme: dark) {
894
+ :root {
895
+ --consent-bg: #0f172a;
896
+ --consent-fg: #f8fafc;
897
+ --consent-muted: #94a3b8;
898
+ --consent-divider: #1e293b;
899
+ --consent-border: #334155;
900
+ --consent-hover-bg: #1e293b;
901
+ --consent-primary: #f8fafc;
902
+ --consent-primary-hover: #ffffff;
903
+ --consent-primary-fg: #0f172a;
904
+ --consent-secondary: #1e293b;
905
+ --consent-secondary-hover: #334155;
906
+ --consent-secondary-fg: #f8fafc;
907
+ --consent-modal-shadow: 0 32px 64px -16px rgba(0, 0, 0, 0.6), 0 0 1px rgba(255, 255, 255, 0.12);
908
+ }
909
+ }
910
+
911
+ @keyframes consentSlideUp {
912
+ from {
913
+ opacity: 0;
914
+ transform: translateY(16px) scale(0.985);
915
+ }
916
+ to {
917
+ opacity: 1;
918
+ transform: translateY(0) scale(1);
919
+ }
920
+ }
921
+
922
+ @keyframes consentFadeIn {
923
+ from { opacity: 0; }
924
+ to { opacity: 1; }
925
+ }
926
+
927
+ /* 1st Layer Banner - Clean & Seamless */
928
+ .consent-banner-wrapper {
929
+ position: fixed;
930
+ bottom: 1.25rem;
931
+ left: 1.25rem;
932
+ right: 1.25rem;
933
+ max-width: 1060px;
934
+ margin: 0 auto;
935
+ z-index: 2147483645;
936
+ background: var(--consent-bg);
937
+ color: var(--consent-fg);
938
+ border: 1px solid var(--consent-border);
939
+ border-radius: 20px;
940
+ box-shadow: var(--consent-modal-shadow);
941
+ padding: 1.5rem 1.75rem;
942
+ font-family: var(--consent-font);
943
+ font-size: 0.92rem;
944
+ line-height: 1.5;
945
+ animation: consentSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
946
+ box-sizing: border-box;
947
+ }
948
+
949
+ .consent-banner-container {
950
+ display: flex;
951
+ flex-direction: column;
952
+ gap: 1.25rem;
953
+ }
954
+
955
+ @media (min-width: 860px) {
956
+ .consent-banner-container {
957
+ flex-direction: row;
958
+ align-items: center;
959
+ justify-content: space-between;
960
+ }
961
+ }
962
+
963
+ .consent-banner-text {
964
+ flex: 1;
965
+ }
966
+
967
+ .consent-banner-title {
968
+ font-size: 1.1rem;
969
+ font-weight: 700;
970
+ letter-spacing: -0.015em;
971
+ margin: 0 0 0.35rem 0;
972
+ color: var(--consent-fg);
973
+ display: flex;
974
+ align-items: center;
975
+ gap: 0.5rem;
976
+ }
977
+
978
+ .consent-banner-title-icon {
979
+ display: inline-flex;
980
+ align-items: center;
981
+ justify-content: center;
982
+ width: 22px;
983
+ height: 22px;
984
+ border-radius: 6px;
985
+ background: rgba(37, 99, 235, 0.1);
986
+ color: var(--consent-accent);
987
+ }
988
+
989
+ .consent-banner-desc {
990
+ margin: 0;
991
+ color: var(--consent-muted);
992
+ font-size: 0.88rem;
993
+ max-width: 720px;
994
+ }
995
+
996
+ .consent-banner-links {
997
+ margin-top: 0.4rem;
998
+ }
999
+
1000
+ .consent-banner-links a {
1001
+ color: var(--consent-muted);
1002
+ font-size: 0.83rem;
1003
+ text-decoration: underline;
1004
+ text-underline-offset: 3px;
1005
+ font-weight: 500;
1006
+ margin-right: 1.2rem;
1007
+ transition: color 0.15s ease;
1008
+ }
1009
+
1010
+ .consent-banner-links a:hover {
1011
+ color: var(--consent-fg);
1012
+ }
1013
+
1014
+ /* Equal Visual Prominence CTAs */
1015
+ .consent-banner-actions {
1016
+ display: flex;
1017
+ flex-direction: column;
1018
+ gap: 0.5rem;
1019
+ width: 100%;
1020
+ }
1021
+
1022
+ @media (min-width: 640px) {
1023
+ .consent-banner-actions {
1024
+ flex-direction: row;
1025
+ width: auto;
1026
+ align-items: center;
1027
+ }
1028
+ }
1029
+
1030
+ .consent-btn {
1031
+ display: inline-flex;
1032
+ align-items: center;
1033
+ justify-content: center;
1034
+ padding: 0.6rem 1.2rem;
1035
+ font-size: 0.88rem;
1036
+ font-weight: 600;
1037
+ border-radius: 10px;
1038
+ border: 1px solid var(--consent-border);
1039
+ cursor: pointer;
1040
+ font-family: inherit;
1041
+ transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
1042
+ min-height: 42px;
1043
+ min-width: 110px;
1044
+ box-sizing: border-box;
1045
+ user-select: none;
1046
+ }
1047
+
1048
+ .consent-btn:hover {
1049
+ transform: translateY(-1px);
1050
+ }
1051
+
1052
+ .consent-btn:active {
1053
+ transform: translateY(0) scale(0.98);
1054
+ }
1055
+
1056
+ .consent-btn:focus-visible {
1057
+ outline: 3px solid var(--consent-focus-ring);
1058
+ outline-offset: 2px;
1059
+ }
1060
+
1061
+ .consent-btn-reject {
1062
+ background: var(--consent-secondary);
1063
+ color: var(--consent-secondary-fg);
1064
+ border-color: var(--consent-border);
1065
+ }
1066
+
1067
+ .consent-btn-reject:hover {
1068
+ background: var(--consent-secondary-hover);
1069
+ }
1070
+
1071
+ .consent-btn-configure {
1072
+ background: transparent;
1073
+ color: var(--consent-muted);
1074
+ border-color: transparent;
1075
+ }
1076
+
1077
+ .consent-btn-configure:hover {
1078
+ color: var(--consent-fg);
1079
+ background: var(--consent-secondary);
1080
+ }
1081
+
1082
+ .consent-btn-accept {
1083
+ background: var(--consent-primary);
1084
+ color: var(--consent-primary-fg);
1085
+ border-color: var(--consent-primary);
1086
+ }
1087
+
1088
+ .consent-btn-accept:hover {
1089
+ background: var(--consent-primary-hover);
1090
+ }
1091
+
1092
+ /* 2nd Layer Preference Modal - Ultra Clean Linear List Style */
1093
+ .consent-dialog-backdrop {
1094
+ position: fixed;
1095
+ top: 0;
1096
+ left: 0;
1097
+ width: 100vw;
1098
+ height: 100vh;
1099
+ background: rgba(15, 23, 42, 0.45);
1100
+ backdrop-filter: blur(8px);
1101
+ -webkit-backdrop-filter: blur(8px);
1102
+ z-index: 2147483646;
1103
+ display: flex;
1104
+ align-items: center;
1105
+ justify-content: center;
1106
+ padding: 1.25rem;
1107
+ box-sizing: border-box;
1108
+ animation: consentFadeIn 0.2s ease forwards;
1109
+ }
1110
+
1111
+ .consent-dialog {
1112
+ background: var(--consent-bg);
1113
+ color: var(--consent-fg);
1114
+ border: 1px solid var(--consent-border);
1115
+ border-radius: 20px;
1116
+ width: 100%;
1117
+ max-width: 600px;
1118
+ max-height: 85vh;
1119
+ display: flex;
1120
+ flex-direction: column;
1121
+ box-shadow: var(--consent-modal-shadow);
1122
+ font-family: var(--consent-font);
1123
+ overflow: hidden;
1124
+ animation: consentSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
1125
+ }
1126
+
1127
+ .consent-dialog-header {
1128
+ padding: 1.5rem 1.75rem 1.25rem 1.75rem;
1129
+ border-bottom: 1px solid var(--consent-divider);
1130
+ display: flex;
1131
+ justify-content: space-between;
1132
+ align-items: flex-start;
1133
+ }
1134
+
1135
+ .consent-dialog-title {
1136
+ font-size: 1.15rem;
1137
+ font-weight: 700;
1138
+ letter-spacing: -0.015em;
1139
+ margin: 0;
1140
+ }
1141
+
1142
+ .consent-dialog-close {
1143
+ background: transparent;
1144
+ border: none;
1145
+ color: var(--consent-muted);
1146
+ cursor: pointer;
1147
+ padding: 0.35rem;
1148
+ border-radius: 8px;
1149
+ display: flex;
1150
+ align-items: center;
1151
+ justify-content: center;
1152
+ transition: background 0.15s ease, color 0.15s ease;
1153
+ margin: -0.35rem -0.35rem 0 0;
1154
+ }
1155
+
1156
+ .consent-dialog-close:hover {
1157
+ background: var(--consent-secondary);
1158
+ color: var(--consent-fg);
1159
+ }
1160
+
1161
+ /* Seamless Category List Body (NO individual boxed divs) */
1162
+ .consent-dialog-body {
1163
+ padding: 0;
1164
+ overflow-y: auto;
1165
+ display: flex;
1166
+ flex-direction: column;
1167
+ }
1168
+
1169
+ .consent-category-row {
1170
+ padding: 1.25rem 1.75rem;
1171
+ border-bottom: 1px solid var(--consent-divider);
1172
+ transition: background 0.15s ease;
1173
+ }
1174
+
1175
+ .consent-category-row:last-child {
1176
+ border-bottom: none;
1177
+ }
1178
+
1179
+ .consent-category-row:hover {
1180
+ background: var(--consent-hover-bg);
1181
+ }
1182
+
1183
+ .consent-category-header {
1184
+ display: flex;
1185
+ justify-content: space-between;
1186
+ align-items: flex-start;
1187
+ gap: 1rem;
1188
+ }
1189
+
1190
+ .consent-category-name {
1191
+ font-weight: 600;
1192
+ font-size: 0.95rem;
1193
+ color: var(--consent-fg);
1194
+ }
1195
+
1196
+ .consent-category-desc {
1197
+ margin: 0.3rem 0 0 0;
1198
+ font-size: 0.85rem;
1199
+ color: var(--consent-muted);
1200
+ line-height: 1.45;
1201
+ }
1202
+
1203
+ /* Minimalist Badges */
1204
+ .consent-badge {
1205
+ display: inline-flex;
1206
+ align-items: center;
1207
+ padding: 0.15rem 0.5rem;
1208
+ border-radius: 6px;
1209
+ font-size: 0.7rem;
1210
+ font-weight: 600;
1211
+ letter-spacing: 0.01em;
1212
+ }
1213
+
1214
+ .consent-badge-required {
1215
+ background: rgba(16, 185, 129, 0.1);
1216
+ color: #059669;
1217
+ }
1218
+
1219
+ .consent-badge-optional {
1220
+ background: rgba(100, 116, 139, 0.08);
1221
+ color: var(--consent-muted);
1222
+ }
1223
+
1224
+ /* Inline Service Disclosure Button */
1225
+ .consent-toggle-services-btn {
1226
+ border: none;
1227
+ background: transparent;
1228
+ color: var(--consent-accent);
1229
+ font-size: 0.78rem;
1230
+ font-weight: 600;
1231
+ cursor: pointer;
1232
+ padding: 0.35rem 0 0 0;
1233
+ display: inline-flex;
1234
+ align-items: center;
1235
+ gap: 0.25rem;
1236
+ font-family: inherit;
1237
+ }
1238
+
1239
+ .consent-toggle-services-btn:hover {
1240
+ opacity: 0.85;
1241
+ }
1242
+
1243
+ /* Minimalist Toggle Switch */
1244
+ .consent-toggle {
1245
+ position: relative;
1246
+ display: inline-block;
1247
+ width: 40px;
1248
+ height: 22px;
1249
+ flex-shrink: 0;
1250
+ margin-top: 0.15rem;
1251
+ }
1252
+
1253
+ .consent-toggle input {
1254
+ opacity: 0;
1255
+ width: 0;
1256
+ height: 0;
1257
+ }
1258
+
1259
+ .consent-toggle-slider {
1260
+ position: absolute;
1261
+ cursor: pointer;
1262
+ top: 0; left: 0; right: 0; bottom: 0;
1263
+ background-color: #cbd5e1;
1264
+ transition: background-color 0.2s ease;
1265
+ border-radius: 22px;
1266
+ }
1267
+
1268
+ .consent-toggle-slider:before {
1269
+ position: absolute;
1270
+ content: "";
1271
+ height: 16px;
1272
+ width: 16px;
1273
+ left: 3px;
1274
+ bottom: 3px;
1275
+ background-color: white;
1276
+ transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
1277
+ border-radius: 50%;
1278
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
1279
+ }
1280
+
1281
+ .consent-toggle input:checked + .consent-toggle-slider {
1282
+ background-color: var(--consent-accent);
1283
+ }
1284
+
1285
+ .consent-toggle input:checked + .consent-toggle-slider:before {
1286
+ transform: translateX(18px);
1287
+ }
1288
+
1289
+ .consent-toggle input:disabled + .consent-toggle-slider {
1290
+ opacity: 0.45;
1291
+ cursor: not-allowed;
1292
+ }
1293
+
1294
+ /* Footer */
1295
+ .consent-dialog-footer {
1296
+ padding: 1.25rem 1.75rem;
1297
+ border-top: 1px solid var(--consent-divider);
1298
+ background: var(--consent-bg);
1299
+ display: flex;
1300
+ flex-direction: column;
1301
+ gap: 0.6rem;
1302
+ justify-content: space-between;
1303
+ align-items: center;
1304
+ }
1305
+
1306
+ @media (min-width: 520px) {
1307
+ .consent-dialog-footer {
1308
+ flex-direction: row;
1309
+ }
1310
+ }
1311
+ `;
1312
+ document.head.appendChild(styleEl);
1313
+ }
1314
+
1315
+ // src/ui/banner.ts
1316
+ var ConsentBanner = class {
1317
+ constructor() {
1318
+ this.element = null;
1319
+ }
1320
+ render(config, handlers) {
1321
+ var _a, _b, _c, _d, _e, _f, _g;
1322
+ if (typeof document === "undefined") return;
1323
+ this.remove();
1324
+ injectStyles((_a = config.csp) == null ? void 0 : _a.nonce);
1325
+ const bannerConfig = ((_b = config.ui) == null ? void 0 : _b.banner) || {};
1326
+ const titleText = sanitizeHtml(bannerConfig.title || "Tu privacidad, bajo tu control");
1327
+ const descText = sanitizeHtml(
1328
+ bannerConfig.description || "Usamos tecnolog\xEDas necesarias para el funcionamiento del sitio. Con tu permiso, tambi\xE9n podemos utilizar anal\xEDtica y marketing."
1329
+ );
1330
+ const acceptText = sanitizeHtml(bannerConfig.accept || "Aceptar todas");
1331
+ const rejectText = sanitizeHtml(bannerConfig.reject || "Rechazar todas");
1332
+ const configureText = sanitizeHtml(bannerConfig.configure || "Configurar");
1333
+ const privacyUrl = sanitizeUrl(((_c = config.policy) == null ? void 0 : _c.privacyUrl) || "/politica-privacidad");
1334
+ const cookiesUrl = sanitizeUrl(((_d = config.policy) == null ? void 0 : _d.cookiesUrl) || "/politica-cookies");
1335
+ const wrapper = document.createElement("div");
1336
+ wrapper.className = "consent-banner-wrapper";
1337
+ wrapper.setAttribute("role", "region");
1338
+ wrapper.setAttribute(
1339
+ "aria-label",
1340
+ "Gesti\xF3n de consentimiento de privacidad"
1341
+ );
1342
+ wrapper.innerHTML = `
1343
+ <div class="consent-banner-container">
1344
+ <div class="consent-banner-text">
1345
+ <h2 class="consent-banner-title">
1346
+ <span class="consent-banner-title-icon">
1347
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
1348
+ <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
1349
+ </svg>
1350
+ </span>
1351
+ ${titleText}
1352
+ </h2>
1353
+ <p class="consent-banner-desc">${descText}</p>
1354
+ <div class="consent-banner-links">
1355
+ <a href="${cookiesUrl}" target="_blank" rel="noopener">Pol\xEDtica de cookies</a>
1356
+ <a href="${privacyUrl}" target="_blank" rel="noopener">Pol\xEDtica de privacidad</a>
1357
+ </div>
1358
+ </div>
1359
+ <div class="consent-banner-actions">
1360
+ <button type="button" class="consent-btn consent-btn-reject" id="consent-btn-reject">
1361
+ ${rejectText}
1362
+ </button>
1363
+ <button type="button" class="consent-btn consent-btn-configure" id="consent-btn-configure">
1364
+ ${configureText}
1365
+ </button>
1366
+ <button type="button" class="consent-btn consent-btn-accept" id="consent-btn-accept">
1367
+ ${acceptText}
1368
+ </button>
1369
+ </div>
1370
+ </div>
1371
+ `;
1372
+ (_e = wrapper.querySelector("#consent-btn-reject")) == null ? void 0 : _e.addEventListener("click", () => {
1373
+ handlers.onRejectAll();
1374
+ this.remove();
1375
+ });
1376
+ (_f = wrapper.querySelector("#consent-btn-configure")) == null ? void 0 : _f.addEventListener("click", () => {
1377
+ handlers.onConfigure();
1378
+ });
1379
+ (_g = wrapper.querySelector("#consent-btn-accept")) == null ? void 0 : _g.addEventListener("click", () => {
1380
+ handlers.onAcceptAll();
1381
+ this.remove();
1382
+ });
1383
+ document.body.appendChild(wrapper);
1384
+ this.element = wrapper;
1385
+ }
1386
+ remove() {
1387
+ if (this.element && this.element.parentNode) {
1388
+ this.element.parentNode.removeChild(this.element);
1389
+ this.element = null;
1390
+ }
1391
+ }
1392
+ };
1393
+
1394
+ // src/ui/preferences.ts
1395
+ var PreferencesModal = class {
1396
+ constructor() {
1397
+ this.backdrop = null;
1398
+ this.lastFocusedElement = null;
1399
+ }
1400
+ render(config, currentChoices, handlers) {
1401
+ var _a, _b, _c, _d, _e, _f, _g;
1402
+ if (typeof document === "undefined") return;
1403
+ this.close();
1404
+ injectStyles((_a = config.csp) == null ? void 0 : _a.nonce);
1405
+ this.lastFocusedElement = document.activeElement;
1406
+ const prefConfig = ((_b = config.ui) == null ? void 0 : _b.preferences) || {};
1407
+ const modalTitle = sanitizeHtml(prefConfig.title || "Preferencias de privacidad");
1408
+ const saveText = sanitizeHtml(prefConfig.save || "Guardar selecci\xF3n");
1409
+ const acceptAllText = sanitizeHtml(prefConfig.acceptAll || "Permitir todas");
1410
+ const rejectAllText = sanitizeHtml(prefConfig.rejectAll || "Rechazar opcionales");
1411
+ const backdrop = document.createElement("div");
1412
+ backdrop.className = "consent-dialog-backdrop";
1413
+ const dialog = document.createElement("div");
1414
+ dialog.className = "consent-dialog";
1415
+ dialog.setAttribute("role", "dialog");
1416
+ dialog.setAttribute("aria-modal", "true");
1417
+ dialog.setAttribute("aria-labelledby", "consent-dialog-title-id");
1418
+ const header = document.createElement("div");
1419
+ header.className = "consent-dialog-header";
1420
+ header.innerHTML = `
1421
+ <div>
1422
+ <h2 class="consent-dialog-title" id="consent-dialog-title-id">${modalTitle}</h2>
1423
+ <p style="margin: 0.2rem 0 0 0; font-size: 0.84rem; color: var(--consent-muted); font-weight: 400;">
1424
+ Gestiona tus permisos de almacenamiento por finalidad (LSSI art. 22.2 &amp; RGPD).
1425
+ </p>
1426
+ </div>
1427
+ <button type="button" class="consent-dialog-close" aria-label="Cerrar ventana">
1428
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
1429
+ <line x1="18" y1="6" x2="6" y2="18"></line>
1430
+ <line x1="6" y1="6" x2="18" y2="18"></line>
1431
+ </svg>
1432
+ </button>
1433
+ `;
1434
+ const body = document.createElement("div");
1435
+ body.className = "consent-dialog-body";
1436
+ const categoryChoices = __spreadValues({}, currentChoices);
1437
+ for (const [catId, catConfig] of Object.entries(config.categories)) {
1438
+ const catRow = document.createElement("div");
1439
+ catRow.className = "consent-category-row";
1440
+ const isRequired = catConfig.required === true;
1441
+ const isChecked = isRequired ? true : (_c = categoryChoices[catId]) != null ? _c : false;
1442
+ const associatedServices = config.services ? Object.entries(config.services).filter(([_, srv]) => srv.category === catId) : [];
1443
+ let servicesHtml = "";
1444
+ if (associatedServices.length > 0) {
1445
+ servicesHtml = `
1446
+ <div class="consent-category-services" id="cat-services-${catId}" style="display: none; margin-top: 0.75rem; padding-top: 0.6rem; border-top: 1px dashed var(--consent-divider); font-size: 0.82rem;">
1447
+ <div style="font-weight: 600; color: var(--consent-muted); margin-bottom: 0.4rem; font-size: 0.75rem; letter-spacing: 0.02em;">
1448
+ Servicios incluidos (${associatedServices.length})
1449
+ </div>
1450
+ <div style="display: flex; flex-direction: column; gap: 0.3rem;">
1451
+ ${associatedServices.map(
1452
+ ([srvId, srv]) => `
1453
+ <div style="display: flex; justify-content: space-between; align-items: center; padding: 0.2rem 0;">
1454
+ <span style="font-weight: 500;">${sanitizeHtml(srv.label || srvId)}</span>
1455
+ <span style="color: var(--consent-muted); font-size: 0.78rem;">${sanitizeHtml(srv.provider || "Terceros")}</span>
1456
+ </div>
1457
+ `
1458
+ ).join("")}
1459
+ </div>
1460
+ </div>
1461
+ `;
1462
+ }
1463
+ catRow.innerHTML = `
1464
+ <div class="consent-category-header">
1465
+ <div style="flex: 1; padding-right: 1rem;">
1466
+ <div style="display: flex; align-items: center; gap: 0.4rem;">
1467
+ <span class="consent-category-name">${sanitizeHtml(catConfig.label)}</span>
1468
+ ${isRequired ? '<span class="consent-badge consent-badge-required">Requerida</span>' : '<span class="consent-badge consent-badge-optional">Opcional</span>'}
1469
+ </div>
1470
+ <p class="consent-category-desc">${sanitizeHtml(catConfig.description)}</p>
1471
+ ${associatedServices.length > 0 ? `<button type="button" class="consent-toggle-services-btn" data-target="cat-services-${catId}">
1472
+ Ver servicios (${associatedServices.length}) \u25BE
1473
+ </button>` : ""}
1474
+ </div>
1475
+ <label class="consent-toggle">
1476
+ <input type="checkbox" id="cat-toggle-${catId}" ${isChecked ? "checked" : ""} ${isRequired ? "disabled" : ""}>
1477
+ <span class="consent-toggle-slider"></span>
1478
+ </label>
1479
+ </div>
1480
+ ${servicesHtml}
1481
+ `;
1482
+ if (!isRequired) {
1483
+ const checkbox = catRow.querySelector(
1484
+ `#cat-toggle-${catId}`
1485
+ );
1486
+ checkbox == null ? void 0 : checkbox.addEventListener("change", (e) => {
1487
+ categoryChoices[catId] = e.target.checked;
1488
+ });
1489
+ }
1490
+ const toggleServicesBtn = catRow.querySelector(
1491
+ ".consent-toggle-services-btn"
1492
+ );
1493
+ if (toggleServicesBtn) {
1494
+ toggleServicesBtn.addEventListener("click", () => {
1495
+ const targetId = toggleServicesBtn.getAttribute("data-target");
1496
+ if (targetId) {
1497
+ const targetEl = catRow.querySelector(`#${targetId}`);
1498
+ if (targetEl) {
1499
+ const isHidden = targetEl.style.display === "none";
1500
+ targetEl.style.display = isHidden ? "block" : "none";
1501
+ toggleServicesBtn.textContent = isHidden ? `Ocultar servicios (${associatedServices.length}) \u25B4` : `Ver servicios (${associatedServices.length}) \u25BE`;
1502
+ }
1503
+ }
1504
+ });
1505
+ }
1506
+ body.appendChild(catRow);
1507
+ }
1508
+ const footer = document.createElement("div");
1509
+ footer.className = "consent-dialog-footer";
1510
+ footer.innerHTML = `
1511
+ <button type="button" class="consent-btn consent-btn-reject" id="consent-pref-reject">
1512
+ ${rejectAllText}
1513
+ </button>
1514
+ <div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
1515
+ <button type="button" class="consent-btn consent-btn-configure" id="consent-pref-accept">
1516
+ ${acceptAllText}
1517
+ </button>
1518
+ <button type="button" class="consent-btn consent-btn-accept" id="consent-pref-save">
1519
+ ${saveText}
1520
+ </button>
1521
+ </div>
1522
+ `;
1523
+ dialog.appendChild(header);
1524
+ dialog.appendChild(body);
1525
+ dialog.appendChild(footer);
1526
+ backdrop.appendChild(dialog);
1527
+ (_d = header.querySelector(".consent-dialog-close")) == null ? void 0 : _d.addEventListener("click", () => {
1528
+ handlers.onClose();
1529
+ this.close();
1530
+ });
1531
+ (_e = footer.querySelector("#consent-pref-reject")) == null ? void 0 : _e.addEventListener("click", () => {
1532
+ handlers.onRejectAll();
1533
+ this.close();
1534
+ });
1535
+ (_f = footer.querySelector("#consent-pref-accept")) == null ? void 0 : _f.addEventListener("click", () => {
1536
+ handlers.onAcceptAll();
1537
+ this.close();
1538
+ });
1539
+ (_g = footer.querySelector("#consent-pref-save")) == null ? void 0 : _g.addEventListener("click", () => {
1540
+ handlers.onSave(categoryChoices);
1541
+ this.close();
1542
+ });
1543
+ const handleKeyDown = (e) => {
1544
+ if (e.key === "Escape") {
1545
+ handlers.onClose();
1546
+ this.close();
1547
+ return;
1548
+ }
1549
+ if (e.key === "Tab") {
1550
+ const focusableElements = dialog.querySelectorAll(
1551
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
1552
+ );
1553
+ const firstElement = focusableElements[0];
1554
+ const lastElement = focusableElements[focusableElements.length - 1];
1555
+ if (e.shiftKey) {
1556
+ if (document.activeElement === firstElement) {
1557
+ lastElement == null ? void 0 : lastElement.focus();
1558
+ e.preventDefault();
1559
+ }
1560
+ } else {
1561
+ if (document.activeElement === lastElement) {
1562
+ firstElement == null ? void 0 : firstElement.focus();
1563
+ e.preventDefault();
1564
+ }
1565
+ }
1566
+ }
1567
+ };
1568
+ document.addEventListener("keydown", handleKeyDown);
1569
+ this._keyListener = handleKeyDown;
1570
+ document.body.appendChild(backdrop);
1571
+ this.backdrop = backdrop;
1572
+ const firstFocusable = dialog.querySelector("button");
1573
+ firstFocusable == null ? void 0 : firstFocusable.focus();
1574
+ }
1575
+ close() {
1576
+ if (this._keyListener) {
1577
+ document.removeEventListener("keydown", this._keyListener);
1578
+ delete this._keyListener;
1579
+ }
1580
+ if (this.backdrop && this.backdrop.parentNode) {
1581
+ this.backdrop.parentNode.removeChild(this.backdrop);
1582
+ this.backdrop = null;
1583
+ }
1584
+ if (this.lastFocusedElement && typeof this.lastFocusedElement.focus === "function") {
1585
+ this.lastFocusedElement.focus();
1586
+ this.lastFocusedElement = null;
1587
+ }
1588
+ }
1589
+ };
1590
+
1591
+ // src/core/consent-engine.ts
1592
+ var ConsentEngine = class {
1593
+ constructor() {
1594
+ this.stateManager = new StateManager();
1595
+ this.eventBus = new EventBus();
1596
+ this.blockerRegistry = new BlockerRegistry();
1597
+ this.banner = new ConsentBanner();
1598
+ this.preferencesModal = new PreferencesModal();
1599
+ this.initPromise = null;
1600
+ this.resolveReady = null;
1601
+ this.readyPromise = new Promise((resolve) => {
1602
+ this.resolveReady = resolve;
1603
+ });
1604
+ }
1605
+ async init(configInput) {
1606
+ if (this.initPromise) return this.initPromise;
1607
+ this.initPromise = (async () => {
1608
+ var _a, _b, _c;
1609
+ let config;
1610
+ if (typeof configInput === "string") {
1611
+ const response = await fetch(configInput);
1612
+ if (!response.ok) {
1613
+ throw new Error(
1614
+ `[ConsentSDK] Failed to fetch consent configuration from '${configInput}' (HTTP ${response.status})`
1615
+ );
1616
+ }
1617
+ config = await response.json();
1618
+ } else {
1619
+ config = configInput;
1620
+ }
1621
+ validateConfig(config);
1622
+ const cookieName = ((_a = config.storage) == null ? void 0 : _a.name) || "site_consent";
1623
+ const rawReceipt = ((_b = config.storage) == null ? void 0 : _b.type) === "memory" ? MemoryStore.get(cookieName) : CookieStore.get(cookieName);
1624
+ const savedReceipt = rawReceipt ? parseReceipt(rawReceipt) : null;
1625
+ const evalResult = evaluatePolicy(config, savedReceipt);
1626
+ const activeReceipt = evalResult.isValid ? savedReceipt : null;
1627
+ this.stateManager.init(config, evalResult.choices, activeReceipt);
1628
+ GoogleConsentAdapter.initDefault();
1629
+ if (evalResult.isValid) {
1630
+ GoogleConsentAdapter.update(evalResult.choices);
1631
+ }
1632
+ this.blockerRegistry.init(
1633
+ (cat) => this.has(cat),
1634
+ (srv) => this.hasService(srv),
1635
+ {
1636
+ onAllowClick: (category) => {
1637
+ const current = this.stateManager.getChoices();
1638
+ current[category] = true;
1639
+ this.setPreferences(current);
1640
+ }
1641
+ },
1642
+ (serviceId, category) => {
1643
+ this.eventBus.emit("service:loaded", { serviceId, category });
1644
+ }
1645
+ );
1646
+ this.setupGlobalRevocationTrigger();
1647
+ (_c = this.resolveReady) == null ? void 0 : _c.call(this);
1648
+ this.eventBus.emit("ready", { state: this.getConsent() });
1649
+ if (!evalResult.isValid) {
1650
+ this.showBanner();
1651
+ }
1652
+ })();
1653
+ return this.initPromise;
1654
+ }
1655
+ async ready() {
1656
+ return this.readyPromise;
1657
+ }
1658
+ getConsent() {
1659
+ return this.stateManager.getState();
1660
+ }
1661
+ has(category) {
1662
+ return this.stateManager.hasCategory(category);
1663
+ }
1664
+ hasService(serviceId) {
1665
+ return this.stateManager.hasService(serviceId);
1666
+ }
1667
+ acceptAll() {
1668
+ const config = this.stateManager.getConfig();
1669
+ if (!config) return;
1670
+ const choices = {};
1671
+ for (const catId of Object.keys(config.categories)) {
1672
+ choices[catId] = true;
1673
+ }
1674
+ this.saveChoices(choices, "banner");
1675
+ this.eventBus.emit("consent:accepted", {
1676
+ choices,
1677
+ receipt: this.getReceipt()
1678
+ });
1679
+ }
1680
+ rejectAll() {
1681
+ const config = this.stateManager.getConfig();
1682
+ if (!config) return;
1683
+ const choices = {};
1684
+ for (const [catId, catConfig] of Object.entries(config.categories)) {
1685
+ choices[catId] = catConfig.required === true;
1686
+ }
1687
+ this.saveChoices(choices, "banner");
1688
+ this.eventBus.emit("consent:rejected", {
1689
+ choices,
1690
+ receipt: this.getReceipt()
1691
+ });
1692
+ }
1693
+ setPreferences(choices) {
1694
+ const config = this.stateManager.getConfig();
1695
+ if (!config) return;
1696
+ const sanitizedChoices = __spreadValues({}, choices);
1697
+ sanitizedChoices["necessary"] = true;
1698
+ this.saveChoices(sanitizedChoices, "preferences");
1699
+ }
1700
+ openPreferences() {
1701
+ const config = this.stateManager.getConfig();
1702
+ if (!config) return;
1703
+ this.preferencesModal.render(config, this.stateManager.getChoices(), {
1704
+ onSave: (choices) => this.setPreferences(choices),
1705
+ onAcceptAll: () => this.acceptAll(),
1706
+ onRejectAll: () => this.rejectAll(),
1707
+ onClose: () => {
1708
+ this.eventBus.emit("preferences:closed", void 0);
1709
+ }
1710
+ });
1711
+ this.eventBus.emit("preferences:opened", void 0);
1712
+ }
1713
+ closePreferences() {
1714
+ this.preferencesModal.close();
1715
+ }
1716
+ withdraw() {
1717
+ var _a, _b;
1718
+ const previousChoices = this.stateManager.getChoices();
1719
+ const config = this.stateManager.getConfig();
1720
+ if (!config) return;
1721
+ const cookieName = ((_a = config.storage) == null ? void 0 : _a.name) || "site_consent";
1722
+ if (((_b = config.storage) == null ? void 0 : _b.type) === "memory") {
1723
+ MemoryStore.remove(cookieName);
1724
+ } else {
1725
+ CookieStore.remove(cookieName);
1726
+ }
1727
+ this.stateManager.clearChoices();
1728
+ GoogleConsentAdapter.update(this.stateManager.getChoices());
1729
+ this.eventBus.emit("consent:withdrawn", { previousChoices });
1730
+ this.showBanner();
1731
+ }
1732
+ when(categoryOrService, callback) {
1733
+ return CustomServiceAdapter.createWhen(
1734
+ this.eventBus,
1735
+ (cat) => this.has(cat),
1736
+ (srv) => this.hasService(srv)
1737
+ )(categoryOrService, callback);
1738
+ }
1739
+ on(event, handler) {
1740
+ return this.eventBus.on(event, handler);
1741
+ }
1742
+ getReceipt() {
1743
+ return this.stateManager.getReceipt();
1744
+ }
1745
+ rescan() {
1746
+ const config = this.stateManager.getConfig();
1747
+ if (!config) {
1748
+ throw new Error("[ConsentSDK] SDK not initialized.");
1749
+ }
1750
+ const isGiven = !!this.getReceipt();
1751
+ return ResourceScanner.runDiagnostic(config, isGiven);
1752
+ }
1753
+ mountPolicy(targetContainer) {
1754
+ const config = this.stateManager.getConfig();
1755
+ if (!config) {
1756
+ throw new Error("[ConsentSDK] SDK not initialized.");
1757
+ }
1758
+ const container = typeof targetContainer === "string" ? document.querySelector(targetContainer) : targetContainer;
1759
+ if (container) {
1760
+ container.innerHTML = PolicyGenerator.renderTable(config);
1761
+ }
1762
+ }
1763
+ saveChoices(choices, source) {
1764
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1765
+ const config = this.stateManager.getConfig();
1766
+ if (!config) return;
1767
+ const receipt = createReceipt(
1768
+ config.policyVersion,
1769
+ choices,
1770
+ source,
1771
+ this.stateManager.getReceipt(),
1772
+ (_a = config.security) == null ? void 0 : _a.secretKey
1773
+ );
1774
+ this.stateManager.updateChoices(receipt);
1775
+ const cookieName = ((_b = config.storage) == null ? void 0 : _b.name) || "site_consent";
1776
+ const receiptJson = JSON.stringify(receipt);
1777
+ if (((_c = config.storage) == null ? void 0 : _c.type) === "memory") {
1778
+ MemoryStore.set(cookieName, receiptJson);
1779
+ } else {
1780
+ CookieStore.set(cookieName, receiptJson, {
1781
+ path: ((_d = config.storage) == null ? void 0 : _d.path) || "/",
1782
+ maxAgeDays: (_f = (_e = config.consent) == null ? void 0 : _e.maxAgeDays) != null ? _f : 365,
1783
+ sameSite: ((_g = config.storage) == null ? void 0 : _g.sameSite) || "Lax",
1784
+ secure: (_h = config.storage) == null ? void 0 : _h.secure
1785
+ });
1786
+ }
1787
+ GoogleConsentAdapter.update(choices);
1788
+ this.blockerRegistry.init(
1789
+ (cat) => this.has(cat),
1790
+ (srv) => this.hasService(srv)
1791
+ );
1792
+ if (((_i = config.logging) == null ? void 0 : _i.enabled) && config.logging.endpoint) {
1793
+ try {
1794
+ fetch(config.logging.endpoint, {
1795
+ method: "POST",
1796
+ headers: { "Content-Type": "application/json" },
1797
+ body: receiptJson
1798
+ }).catch(() => {
1799
+ });
1800
+ } catch (e) {
1801
+ }
1802
+ }
1803
+ this.banner.remove();
1804
+ this.eventBus.emit("consent:changed", { choices, receipt });
1805
+ }
1806
+ showBanner() {
1807
+ const config = this.stateManager.getConfig();
1808
+ if (!config) return;
1809
+ this.banner.render(config, {
1810
+ onAcceptAll: () => this.acceptAll(),
1811
+ onRejectAll: () => this.rejectAll(),
1812
+ onConfigure: () => this.openPreferences()
1813
+ });
1814
+ this.eventBus.emit("banner:shown", void 0);
1815
+ }
1816
+ setupGlobalRevocationTrigger() {
1817
+ if (typeof document === "undefined") return;
1818
+ document.addEventListener("click", (e) => {
1819
+ const target = e.target;
1820
+ if (target == null ? void 0 : target.closest("[data-consent-open]")) {
1821
+ e.preventDefault();
1822
+ this.openPreferences();
1823
+ }
1824
+ });
1825
+ }
1826
+ };
1827
+ var globalScope = typeof window !== "undefined" ? window : globalThis;
1828
+ if (!globalScope.__ConsentSDK_Instance__) {
1829
+ globalScope.__ConsentSDK_Instance__ = new ConsentEngine();
1830
+ }
1831
+ var Consent = globalScope.__ConsentSDK_Instance__;
1832
+
1833
+ export {
1834
+ ConfigValidationError,
1835
+ validateConfig,
1836
+ computeReceiptSignature,
1837
+ verifyReceiptIntegrity,
1838
+ sanitizeHtml,
1839
+ createReceipt,
1840
+ parseReceipt,
1841
+ isReceiptExpired,
1842
+ CookieStorageProvider,
1843
+ CookieStore,
1844
+ MemoryStorageProvider,
1845
+ MemoryStore,
1846
+ ScriptResourceBlocker,
1847
+ ScriptGate,
1848
+ IframeResourceBlocker,
1849
+ IframeGate,
1850
+ ImageResourceBlocker,
1851
+ ResourceGate,
1852
+ GoogleConsentAdapter,
1853
+ ResourceScanner,
1854
+ PolicyGenerator,
1855
+ ConsentEngine,
1856
+ Consent
1857
+ };
1858
+ //# sourceMappingURL=chunk-LIWFUVWY.js.map