@smartgenie/cookie-consent 0.0.0-stage → 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 (92) hide show
  1. package/LICENSE +73 -0
  2. package/README.md +292 -2
  3. package/dist/blocking/attribute-blocker.d.ts +18 -0
  4. package/dist/blocking/gtm-consent-mode.d.ts +19 -0
  5. package/dist/blocking/uet-consent.d.ts +9 -0
  6. package/dist/capsules/banner-experiment.d.ts +2 -0
  7. package/dist/capsules/banner-experiment.js +1 -0
  8. package/dist/capsules/country-banners.d.ts +2 -0
  9. package/dist/capsules/country-banners.js +1 -0
  10. package/dist/capsules/loader.d.ts +8 -0
  11. package/dist/capsules/subdomain-consent.d.ts +5 -0
  12. package/dist/capsules/subdomain-consent.js +1 -0
  13. package/dist/config/schema.d.ts +19 -0
  14. package/dist/config/validator.d.ts +8 -0
  15. package/dist/core/consent-log.d.ts +14 -0
  16. package/dist/core/consent-manager.d.ts +13 -0
  17. package/dist/core/consent-stats.d.ts +13 -0
  18. package/dist/core/events.d.ts +5 -0
  19. package/dist/core/gpc.d.ts +5 -0
  20. package/dist/core/storage.d.ts +9 -0
  21. package/dist/geo/detector.d.ts +3 -0
  22. package/dist/i18n/langs/ar.d.ts +1 -0
  23. package/dist/i18n/langs/cs.d.ts +1 -0
  24. package/dist/i18n/langs/da.d.ts +1 -0
  25. package/dist/i18n/langs/de.d.ts +1 -0
  26. package/dist/i18n/langs/es.d.ts +1 -0
  27. package/dist/i18n/langs/fr.d.ts +1 -0
  28. package/dist/i18n/langs/hi.d.ts +1 -0
  29. package/dist/i18n/langs/it.d.ts +1 -0
  30. package/dist/i18n/langs/ja.d.ts +1 -0
  31. package/dist/i18n/langs/ko.d.ts +1 -0
  32. package/dist/i18n/langs/nl.d.ts +1 -0
  33. package/dist/i18n/langs/no.d.ts +1 -0
  34. package/dist/i18n/langs/pl.d.ts +1 -0
  35. package/dist/i18n/langs/pt.d.ts +1 -0
  36. package/dist/i18n/langs/ro.d.ts +1 -0
  37. package/dist/i18n/langs/ru.d.ts +1 -0
  38. package/dist/i18n/langs/sv.d.ts +1 -0
  39. package/dist/i18n/langs/tr.d.ts +1 -0
  40. package/dist/i18n/langs/zh.d.ts +1 -0
  41. package/dist/i18n/loader.d.ts +11 -0
  42. package/dist/i18n/remote.d.ts +23 -0
  43. package/dist/i18n/translations.d.ts +14 -0
  44. package/dist/index.d.ts +10 -0
  45. package/dist/lang/ar.json +1 -0
  46. package/dist/lang/cs.json +1 -0
  47. package/dist/lang/da.json +1 -0
  48. package/dist/lang/de.json +1 -0
  49. package/dist/lang/es.json +1 -0
  50. package/dist/lang/fr.json +1 -0
  51. package/dist/lang/hi.json +1 -0
  52. package/dist/lang/it.json +1 -0
  53. package/dist/lang/ja.json +1 -0
  54. package/dist/lang/ko.json +1 -0
  55. package/dist/lang/nl.json +1 -0
  56. package/dist/lang/no.json +1 -0
  57. package/dist/lang/pl.json +1 -0
  58. package/dist/lang/pt.json +1 -0
  59. package/dist/lang/ro.json +1 -0
  60. package/dist/lang/ru.json +1 -0
  61. package/dist/lang/sv.json +1 -0
  62. package/dist/lang/tr.json +1 -0
  63. package/dist/lang/zh.json +1 -0
  64. package/dist/react/SmartConsent.d.ts +14 -0
  65. package/dist/react/SmartConsent.js +2260 -0
  66. package/dist/react/SmartConsent.js.map +1 -0
  67. package/dist/regulations/loader.d.ts +3 -0
  68. package/dist/regulations/reasoner.d.ts +6 -0
  69. package/dist/regulations/schema.d.ts +8 -0
  70. package/dist/site/consent-records.d.ts +26 -0
  71. package/dist/site/settings.d.ts +48 -0
  72. package/dist/smartconsent.es.js +3063 -0
  73. package/dist/smartconsent.es.js.map +1 -0
  74. package/dist/smartconsent.js +3962 -0
  75. package/dist/smartconsent.js.map +1 -0
  76. package/dist/smartconsent.min.js +534 -0
  77. package/dist/smartconsent.min.js.map +1 -0
  78. package/dist/types.d.ts +377 -0
  79. package/dist/ui/a11y.d.ts +4 -0
  80. package/dist/ui/attribution-guard.d.ts +3 -0
  81. package/dist/ui/badge.d.ts +7 -0
  82. package/dist/ui/banner.d.ts +10 -0
  83. package/dist/ui/cookie-policy.d.ts +8 -0
  84. package/dist/ui/cookie-table.d.ts +7 -0
  85. package/dist/ui/credit.d.ts +15 -0
  86. package/dist/ui/embed-placeholder.d.ts +7 -0
  87. package/dist/ui/opt-out-notice.d.ts +7 -0
  88. package/dist/ui/styles.d.ts +3 -0
  89. package/dist/webhook.d.ts +5 -0
  90. package/package.json +100 -4
  91. package/templates/privacy-policy-template.md +135 -0
  92. package/templates/vanilla.html +116 -0
@@ -0,0 +1,3962 @@
1
+ this.SmartConsent = function() {
2
+ "use strict";
3
+ const DEFAULT_CATEGORIES = [
4
+ {
5
+ id: "essential",
6
+ label: "Essential",
7
+ description: "Required for the website to function. Cannot be disabled.",
8
+ required: true
9
+ },
10
+ {
11
+ id: "analytics",
12
+ label: "Analytics",
13
+ description: "Help us understand how visitors interact with our website.",
14
+ required: false
15
+ },
16
+ {
17
+ id: "functional",
18
+ label: "Functional",
19
+ description: "Enable personalised features and remember your preferences.",
20
+ required: false
21
+ },
22
+ {
23
+ id: "marketing",
24
+ label: "Marketing",
25
+ description: "Used to deliver relevant advertisements and track campaign performance.",
26
+ required: false
27
+ }
28
+ ];
29
+ const DEFAULT_THEME = {
30
+ bg: "#FFFFFF",
31
+ surface: "#F4F6F8",
32
+ border: "#DCE1E7",
33
+ text: "#182230",
34
+ textMuted: "#526071",
35
+ accent: "#33465F",
36
+ accept: "#33465F",
37
+ reject: "#33465F",
38
+ toggleOn: "#33465F",
39
+ toggleOff: "#778496",
40
+ radius: "12px",
41
+ font: "system-ui, sans-serif"
42
+ };
43
+ const DEFAULT_TEXTS = {
44
+ heading: "Cookie Preferences",
45
+ description: "We use cookies to improve your experience.",
46
+ acceptAll: "Accept All",
47
+ rejectOptional: "Reject Optional",
48
+ managePreferences: "Manage Preferences",
49
+ essentialOnly: "Essential Only",
50
+ savePreferences: "Save Preferences",
51
+ poweredBy: "Powered by SmartGenie",
52
+ doNotSell: "Do Not Sell or Share My Personal Information",
53
+ cookieSettings: "Cookie settings",
54
+ dataRequest: "Your data rights",
55
+ policyCredit: "Cookie consent by SmartConsent from SmartGenie",
56
+ embedNotice: "This content is from {service}. Loading it may set cookies.",
57
+ embedLoad: "Load content"
58
+ };
59
+ const DEFAULT_SETTINGS_BASE = "https://smartconsentsettings.blob.core.windows.net/$web";
60
+ const DEFAULT_PACKS_BASE = "https://cdn.smartgenie.co.uk/v1/";
61
+ const DEFAULT_API_BASE = "https://api.smartgenie.co.uk";
62
+ const DEFAULT_CONFIG = {
63
+ version: 0,
64
+ categories: DEFAULT_CATEGORIES,
65
+ theme: DEFAULT_THEME,
66
+ position: "bottom",
67
+ badgePosition: "bottom-right",
68
+ showBadge: true,
69
+ attribution: true,
70
+ attributionUrl: "https://www.smartgenie.co.uk/smartconsent",
71
+ consentMode: true,
72
+ expiry: 13,
73
+ texts: DEFAULT_TEXTS,
74
+ dir: "ltr",
75
+ layout: "box",
76
+ boxPosition: "bottom-right",
77
+ cookies: []
78
+ };
79
+ const MIN_EXPIRY = 1;
80
+ const MAX_EXPIRY = 13;
81
+ function validateConfig(raw) {
82
+ if (raw === null || raw === void 0 || typeof raw !== "object") {
83
+ throw new Error("SmartConsent: config must be an object");
84
+ }
85
+ const input = raw;
86
+ if (input.version === void 0 || input.version === null) {
87
+ throw new Error("SmartConsent: config.version is required");
88
+ }
89
+ if (typeof input.version !== "number" || !Number.isFinite(input.version)) {
90
+ throw new Error("SmartConsent: config.version must be a finite number");
91
+ }
92
+ const config = {
93
+ ...DEFAULT_CONFIG,
94
+ version: input.version
95
+ };
96
+ if (Array.isArray(input.categories)) {
97
+ config.categories = input.categories;
98
+ }
99
+ if (input.theme !== void 0 && typeof input.theme === "object" && input.theme !== null) {
100
+ config.theme = { ...DEFAULT_CONFIG.theme, ...input.theme };
101
+ }
102
+ if (input.texts !== void 0 && typeof input.texts === "object" && input.texts !== null) {
103
+ config.texts = { ...DEFAULT_CONFIG.texts, ...input.texts };
104
+ }
105
+ if (input.position === "bottom" || input.position === "top") {
106
+ config.position = input.position;
107
+ }
108
+ if (input.badgePosition === "bottom-right" || input.badgePosition === "bottom-left") {
109
+ config.badgePosition = input.badgePosition;
110
+ }
111
+ if (typeof input.showBadge === "boolean") config.showBadge = input.showBadge;
112
+ if (typeof input.attribution === "boolean") config.attribution = input.attribution;
113
+ if (typeof input.consentMode === "boolean") config.consentMode = input.consentMode;
114
+ if (typeof input.attributionUrl === "string") config.attributionUrl = input.attributionUrl;
115
+ if (typeof input.webhookUrl === "string") config.webhookUrl = input.webhookUrl;
116
+ if (typeof input.expiry === "number" && Number.isFinite(input.expiry)) {
117
+ config.expiry = Math.max(MIN_EXPIRY, Math.min(MAX_EXPIRY, input.expiry));
118
+ }
119
+ if (typeof input.onConsent === "function") {
120
+ config.onConsent = input.onConsent;
121
+ }
122
+ if (typeof input.siteId === "string") config.siteId = input.siteId;
123
+ if (input.platform === "wordpress-plugin" || input.platform === "joomla-extension" || input.platform === "drupal-module") {
124
+ config.platform = input.platform;
125
+ config.attribution = input.attribution === true;
126
+ }
127
+ if (typeof input.recordsEndpoint === "string") config.recordsEndpoint = input.recordsEndpoint;
128
+ else if (input.recordsEndpoint !== void 0) console.warn("SmartConsent: recordsEndpoint ignored (it must be a string).");
129
+ if (typeof input.language === "string") config.language = input.language;
130
+ if (input.dir === "ltr" || input.dir === "rtl") config.dir = input.dir;
131
+ if (input.layout === "banner" || input.layout === "box" || input.layout === "popup") {
132
+ config.layout = input.layout;
133
+ }
134
+ if (input.boxPosition === "bottom-left" || input.boxPosition === "bottom-right") {
135
+ config.boxPosition = input.boxPosition;
136
+ }
137
+ if (Array.isArray(input.cookies)) {
138
+ const valid = [];
139
+ for (const raw2 of input.cookies) {
140
+ if (raw2 && typeof raw2 === "object") {
141
+ const c = raw2;
142
+ if (typeof c.name === "string" && typeof c.category === "string") {
143
+ valid.push({
144
+ name: c.name,
145
+ category: c.category,
146
+ ...typeof c.domain === "string" && { domain: c.domain },
147
+ ...typeof c.description === "string" && { description: c.description },
148
+ ...typeof c.duration === "string" && { duration: c.duration },
149
+ ...(c.party === "first" || c.party === "third") && { party: c.party }
150
+ });
151
+ } else {
152
+ console.warn("SmartConsent: Skipping invalid cookie declaration:", c);
153
+ }
154
+ }
155
+ }
156
+ config.cookies = valid;
157
+ }
158
+ if (input.logo && typeof input.logo === "object") {
159
+ const logo = input.logo;
160
+ if (typeof logo.src === "string" && typeof logo.alt === "string") {
161
+ config.logo = {
162
+ src: logo.src,
163
+ alt: logo.alt,
164
+ ...typeof logo.width === "number" && { width: logo.width },
165
+ ...typeof logo.height === "number" && { height: logo.height }
166
+ };
167
+ }
168
+ }
169
+ return config;
170
+ }
171
+ const STORAGE_KEY = "smartconsent_state";
172
+ function createStorage() {
173
+ function readRaw() {
174
+ try {
175
+ const raw = localStorage.getItem(STORAGE_KEY);
176
+ if (!raw) return null;
177
+ return JSON.parse(raw);
178
+ } catch {
179
+ return null;
180
+ }
181
+ }
182
+ return {
183
+ getConsent() {
184
+ return readRaw();
185
+ },
186
+ saveConsent(state) {
187
+ try {
188
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
189
+ } catch {
190
+ }
191
+ },
192
+ clearConsent() {
193
+ try {
194
+ localStorage.removeItem(STORAGE_KEY);
195
+ } catch {
196
+ }
197
+ },
198
+ isExpired() {
199
+ const state = readRaw();
200
+ if (!state || !state.expiresAt) return true;
201
+ return new Date(state.expiresAt).getTime() <= Date.now();
202
+ },
203
+ isVersionMatch(version2) {
204
+ const state = readRaw();
205
+ if (!state) return false;
206
+ return state.version === version2;
207
+ }
208
+ };
209
+ }
210
+ const EVENT_NAME = "smartconsent:update";
211
+ function dispatchConsent(event) {
212
+ window.dispatchEvent(new CustomEvent(EVENT_NAME, { detail: event }));
213
+ }
214
+ function onConsentChange(callback) {
215
+ const handler = (e) => {
216
+ callback(e.detail);
217
+ };
218
+ window.addEventListener(EVENT_NAME, handler);
219
+ return () => window.removeEventListener(EVENT_NAME, handler);
220
+ }
221
+ function createConsentManager(config) {
222
+ const storage = createStorage();
223
+ function getValidState() {
224
+ const state = storage.getConsent();
225
+ if (!state) return null;
226
+ if (storage.isExpired() || !storage.isVersionMatch(config.version)) {
227
+ storage.clearConsent();
228
+ return null;
229
+ }
230
+ return state;
231
+ }
232
+ function buildCategories(allTrue) {
233
+ const cats = {};
234
+ for (const cat of config.categories) {
235
+ cats[cat.id] = cat.required ? true : allTrue;
236
+ }
237
+ return cats;
238
+ }
239
+ function computeExpiresAt() {
240
+ const now = /* @__PURE__ */ new Date();
241
+ now.setMonth(now.getMonth() + config.expiry);
242
+ return now.toISOString();
243
+ }
244
+ function saveAndDispatch(categories, action) {
245
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
246
+ const state = {
247
+ version: config.version,
248
+ categories,
249
+ timestamp,
250
+ action,
251
+ expiresAt: computeExpiresAt()
252
+ };
253
+ storage.saveConsent(state);
254
+ const event = {
255
+ categories,
256
+ action,
257
+ timestamp,
258
+ version: config.version
259
+ };
260
+ dispatchConsent(event);
261
+ if (config.onConsent) {
262
+ config.onConsent(state);
263
+ }
264
+ }
265
+ return {
266
+ acceptAll() {
267
+ saveAndDispatch(buildCategories(true), "accept_all");
268
+ },
269
+ rejectOptional() {
270
+ saveAndDispatch(buildCategories(false), "reject_optional");
271
+ },
272
+ saveCustom(categories) {
273
+ const merged = {};
274
+ for (const cat of config.categories) {
275
+ if (cat.required) {
276
+ merged[cat.id] = true;
277
+ } else {
278
+ merged[cat.id] = categories[cat.id] ?? false;
279
+ }
280
+ }
281
+ saveAndDispatch(merged, "custom");
282
+ },
283
+ withdraw() {
284
+ saveAndDispatch(buildCategories(false), "withdraw");
285
+ },
286
+ reset() {
287
+ storage.clearConsent();
288
+ },
289
+ getState() {
290
+ return getValidState();
291
+ },
292
+ hasConsent(category) {
293
+ const state = getValidState();
294
+ if (!state) return false;
295
+ return state.categories[category] === true;
296
+ },
297
+ needsConsent() {
298
+ return getValidState() === null;
299
+ },
300
+ onConsentChange(cb) {
301
+ return onConsentChange(cb);
302
+ }
303
+ };
304
+ }
305
+ function applyGpc(manager, config, bannerConfig) {
306
+ const nav = typeof navigator !== "undefined" ? navigator : null;
307
+ const gpcEnabled = !!nav && (nav.globalPrivacyControl === true || nav.doNotTrack === "1");
308
+ const gpcApplies = gpcEnabled && bannerConfig.signals.gpc_auto_reject;
309
+ if (gpcApplies) {
310
+ const saved = manager.getState();
311
+ const optionalGranted = !!saved && config.categories.some((c) => !c.required && saved.categories[c.id] === true);
312
+ if (!saved || optionalGranted) manager.rejectOptional();
313
+ }
314
+ return gpcApplies;
315
+ }
316
+ const LOG_KEY = "smartconsent_log";
317
+ const MAX_RECORDS = 100;
318
+ function createConsentLog(options) {
319
+ function readLog() {
320
+ try {
321
+ const raw = localStorage.getItem(LOG_KEY);
322
+ if (!raw) return [];
323
+ return JSON.parse(raw);
324
+ } catch {
325
+ return [];
326
+ }
327
+ }
328
+ function writeLog(records) {
329
+ try {
330
+ localStorage.setItem(LOG_KEY, JSON.stringify(records));
331
+ } catch {
332
+ }
333
+ }
334
+ function generateId() {
335
+ try {
336
+ return crypto.randomUUID();
337
+ } catch {
338
+ return Date.now().toString(36) + Math.random().toString(36).slice(2);
339
+ }
340
+ }
341
+ return {
342
+ addRecord(action, categories) {
343
+ const record = {
344
+ id: generateId(),
345
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
346
+ action,
347
+ categories: { ...categories },
348
+ visitorHash: options.visitorHash,
349
+ version: options.version,
350
+ jurisdiction: options.jurisdiction
351
+ };
352
+ const log = readLog();
353
+ log.push(record);
354
+ writeLog(log.length > MAX_RECORDS ? log.slice(-MAX_RECORDS) : log);
355
+ return record;
356
+ },
357
+ getLog() {
358
+ return readLog();
359
+ },
360
+ getLatest() {
361
+ const log = readLog();
362
+ return log.length > 0 ? log[log.length - 1] : null;
363
+ },
364
+ clear() {
365
+ try {
366
+ localStorage.removeItem(LOG_KEY);
367
+ } catch {
368
+ }
369
+ }
370
+ };
371
+ }
372
+ async function computeVisitorHash() {
373
+ const s = [navigator.userAgent, screen.width, screen.height, (/* @__PURE__ */ new Date()).getTimezoneOffset(), navigator.language].join("|");
374
+ try {
375
+ const buf = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(s));
376
+ return Array.from(new Uint8Array(buf), (b) => b.toString(16).padStart(2, "0")).join("");
377
+ } catch {
378
+ let h = 2166136261;
379
+ for (let i = 0; i < s.length; i++) {
380
+ h ^= s.charCodeAt(i);
381
+ h = Math.imul(h, 16777619);
382
+ }
383
+ return (h >>> 0).toString(16).padStart(8, "0");
384
+ }
385
+ }
386
+ function createWebhook(config) {
387
+ return {
388
+ send(event, record) {
389
+ if (!config.webhookUrl) return;
390
+ const payload = {
391
+ action: event.action,
392
+ categories: event.categories,
393
+ version: event.version,
394
+ timestamp: event.timestamp,
395
+ pageUrl: window.location.href,
396
+ userAgent: navigator.userAgent,
397
+ ...record && {
398
+ recordId: record.id,
399
+ visitorHash: record.visitorHash,
400
+ jurisdiction: record.jurisdiction
401
+ }
402
+ };
403
+ try {
404
+ fetch(config.webhookUrl, {
405
+ method: "POST",
406
+ headers: { "Content-Type": "application/json" },
407
+ body: JSON.stringify(payload)
408
+ }).catch(() => {
409
+ });
410
+ } catch {
411
+ }
412
+ }
413
+ };
414
+ }
415
+ function mapCategoriesToConsent(categories) {
416
+ return {
417
+ analytics_storage: categories.analytics ? "granted" : "denied",
418
+ ad_storage: categories.marketing ? "granted" : "denied",
419
+ ad_user_data: categories.marketing ? "granted" : "denied",
420
+ ad_personalization: categories.marketing ? "granted" : "denied",
421
+ functionality_storage: categories.functional ? "granted" : "denied",
422
+ personalization_storage: categories.functional ? "granted" : "denied",
423
+ security_storage: "granted"
424
+ // always granted (essential)
425
+ };
426
+ }
427
+ function ensureGtag() {
428
+ if (!window.dataLayer) {
429
+ window.dataLayer = [];
430
+ }
431
+ if (!window.gtag) {
432
+ window.gtag = function(...args) {
433
+ window.dataLayer.push(args);
434
+ };
435
+ }
436
+ }
437
+ const DENIED = {
438
+ analytics_storage: "denied",
439
+ ad_storage: "denied",
440
+ ad_user_data: "denied",
441
+ ad_personalization: "denied",
442
+ functionality_storage: "denied",
443
+ personalization_storage: "denied",
444
+ security_storage: "granted"
445
+ };
446
+ function sendGtmDefaultDeny() {
447
+ ensureGtag();
448
+ window.gtag("consent", "default", { ...DENIED, wait_for_update: 500 });
449
+ }
450
+ function sendGtmDenyUpdate() {
451
+ ensureGtag();
452
+ window.gtag("consent", "update", { ...DENIED });
453
+ }
454
+ function createGTMConsentMode(config, manager) {
455
+ let unsubConsent = null;
456
+ return {
457
+ init(opts) {
458
+ if (!config.consentMode) return;
459
+ if (!(opts == null ? void 0 : opts.defaultSent)) sendGtmDefaultDeny();
460
+ ensureGtag();
461
+ unsubConsent = onConsentChange((event) => {
462
+ window.gtag("consent", "update", mapCategoriesToConsent(event.categories));
463
+ });
464
+ const existingState = manager.getState();
465
+ if (existingState) {
466
+ window.gtag("consent", "update", mapCategoriesToConsent(existingState.categories));
467
+ }
468
+ },
469
+ destroy() {
470
+ if (unsubConsent) {
471
+ unsubConsent();
472
+ unsubConsent = null;
473
+ }
474
+ }
475
+ };
476
+ }
477
+ function push(kind, granted) {
478
+ (window.uetq = window.uetq || []).push("consent", kind, { ad_storage: granted ? "granted" : "denied" });
479
+ }
480
+ function sendUetDefaultDeny() {
481
+ push("default", false);
482
+ }
483
+ function sendUetUpdate(marketing) {
484
+ push("update", marketing);
485
+ }
486
+ function size(attr, css) {
487
+ if (attr && /^\d+(\.\d+)?$/.test(attr.trim())) return attr.trim() + "px";
488
+ return (attr == null ? void 0 : attr.trim()) || css;
489
+ }
490
+ function createPlaceholder(frame, onLoad) {
491
+ const box = document.createElement("div");
492
+ box.setAttribute("data-smartconsent", "embed");
493
+ box.setAttribute("role", "region");
494
+ const w = size(frame.getAttribute("width"), frame.style.width);
495
+ const h = size(frame.getAttribute("height"), frame.style.height);
496
+ if (w) box.style.setProperty("--sc-embed-w", w);
497
+ if (h) box.style.setProperty("--sc-embed-h", h);
498
+ const text = document.createElement("p");
499
+ const button = document.createElement("button");
500
+ button.type = "button";
501
+ button.addEventListener("click", onLoad);
502
+ box.append(text, button);
503
+ return box;
504
+ }
505
+ function fillPlaceholder(box, service, t) {
506
+ const notice = t.embedNotice.split("{service}").join(service);
507
+ box.setAttribute("aria-label", notice);
508
+ box.firstChild.textContent = notice;
509
+ const button = box.lastChild;
510
+ button.textContent = t.embedLoad;
511
+ button.setAttribute("aria-label", `${t.embedLoad}: ${service}`);
512
+ }
513
+ const BLOCKED_MARKER = "data-smartconsent-blocked";
514
+ const nativeCreateElement$1 = document.createElement;
515
+ const OWN_CDN = "cdn.smartgenie.co.uk";
516
+ const WAIT = "";
517
+ const FREE = "\0";
518
+ const nativeAppendChild = Node.prototype.appendChild;
519
+ const nativeInsertBefore = Node.prototype.insertBefore;
520
+ const nativeReplaceChild = Node.prototype.replaceChild;
521
+ const nativeAppend = Element.prototype.append;
522
+ function createBlocker(initialManager) {
523
+ let manager = null;
524
+ let observer = null;
525
+ let unsubConsent = null;
526
+ const blockedScripts = [];
527
+ const heldFrames = [];
528
+ let texts = DEFAULT_TEXTS;
529
+ let loaded = /* @__PURE__ */ new WeakSet();
530
+ let rules;
531
+ let created = /* @__PURE__ */ new WeakSet();
532
+ function thirdParty(src) {
533
+ if (!src) return null;
534
+ try {
535
+ const u = new URL(src, location.href);
536
+ return /^https?:$/.test(u.protocol) && u.hostname !== location.hostname && u.hostname !== OWN_CDN ? u : null;
537
+ } catch {
538
+ return null;
539
+ }
540
+ }
541
+ function listed(u) {
542
+ if (!u) return null;
543
+ const host = u.hostname.toLowerCase();
544
+ const hostPath = (host + u.pathname).toLowerCase();
545
+ for (const [p, c] of rules || []) {
546
+ if (p.includes("/") ? hostPath.includes(p) : host === p || host.endsWith("." + p)) return c;
547
+ }
548
+ return null;
549
+ }
550
+ function autoCategory(src, waits) {
551
+ if (rules === void 0) return null;
552
+ const u = thirdParty(src);
553
+ if (!u) return null;
554
+ return rules ? listed(u) : waits ? WAIT : null;
555
+ }
556
+ function isCategoryConsented(category) {
557
+ return manager ? manager.hasConsent(category) : false;
558
+ }
559
+ function isManagedBlockedScript(script) {
560
+ return script.getAttribute(BLOCKED_MARKER) === "true";
561
+ }
562
+ function shouldManageScript(script) {
563
+ return script.type !== "text/plain" || isManagedBlockedScript(script);
564
+ }
565
+ function snapshotScript(script, category) {
566
+ const src = script.getAttribute("src") || script.getAttribute("data-original-src");
567
+ const content = script.textContent || null;
568
+ const attrs = [];
569
+ for (const attr of Array.from(script.attributes)) {
570
+ if (attr.name !== "type" && attr.name !== "src" && attr.name !== "data-original-src") {
571
+ attrs.push({ name: attr.name, value: attr.value });
572
+ }
573
+ }
574
+ return { node: script, src, content, category, attributes: attrs };
575
+ }
576
+ function upsertBlockedScript(blocked) {
577
+ const existingIndex = blockedScripts.findIndex((entry) => entry.node === blocked.node);
578
+ if (existingIndex >= 0) {
579
+ blockedScripts[existingIndex] = blocked;
580
+ return;
581
+ }
582
+ blockedScripts.push(blocked);
583
+ }
584
+ function blockScript(script, category) {
585
+ const blocked = snapshotScript(script, category);
586
+ upsertBlockedScript(blocked);
587
+ script.setAttribute(BLOCKED_MARKER, "true");
588
+ script.type = "text/plain";
589
+ if (blocked.src) {
590
+ script.setAttribute("data-original-src", blocked.src);
591
+ script.removeAttribute("src");
592
+ }
593
+ }
594
+ function activateScript(blocked) {
595
+ const newScript = document.createElement("script");
596
+ for (const attr of blocked.attributes) {
597
+ newScript.setAttribute(attr.name, attr.value);
598
+ }
599
+ newScript.removeAttribute("type");
600
+ newScript.removeAttribute(BLOCKED_MARKER);
601
+ if (blocked.src) {
602
+ newScript.src = blocked.src;
603
+ } else if (blocked.content) {
604
+ newScript.textContent = blocked.content;
605
+ }
606
+ if (blocked.node.parentNode) {
607
+ blocked.node.parentNode.replaceChild(newScript, blocked.node);
608
+ return;
609
+ }
610
+ const target = document.body || document.head || document.documentElement;
611
+ target.appendChild(newScript);
612
+ }
613
+ function maybeBlockScript(script, byCode = false) {
614
+ var _a;
615
+ const category = script.getAttribute("data-consent-category") ?? ((_a = blockedScripts.find((b) => b.node === script)) == null ? void 0 : _a.category) ?? autoCategory(script.getAttribute("src"), byCode || created.has(script) || script.hasAttribute("async"));
616
+ if (category === null || isCategoryConsented(category) || !shouldManageScript(script)) {
617
+ return;
618
+ }
619
+ blockScript(script, category);
620
+ }
621
+ function service(frame) {
622
+ var _a;
623
+ return (((_a = thirdParty(frame.getAttribute("data-original-src"))) == null ? void 0 : _a.hostname) ?? "").replace(/^www\./, "");
624
+ }
625
+ function showBox(held) {
626
+ const parent = held.node.parentNode;
627
+ if (held.category === WAIT || held.box || !parent) return;
628
+ held.box = createPlaceholder(held.node, () => {
629
+ heldFrames.splice(heldFrames.indexOf(held), 1);
630
+ loaded.add(held.node);
631
+ restoreFrame(held);
632
+ });
633
+ fillPlaceholder(held.box, service(held.node), texts);
634
+ nativeReplaceChild.call(parent, held.box, held.node);
635
+ }
636
+ function restoreFrame(held) {
637
+ const box = held.box;
638
+ held.box = void 0;
639
+ if (box == null ? void 0 : box.parentNode) nativeReplaceChild.call(box.parentNode, held.node, box);
640
+ const src = held.node.getAttribute("data-original-src");
641
+ held.node.removeAttribute("data-original-src");
642
+ if (src) held.node.setAttribute("src", src);
643
+ }
644
+ function maybeHoldFrame(frame) {
645
+ if (loaded.has(frame)) return;
646
+ const already = heldFrames.find((f) => f.node === frame);
647
+ if (already) return showBox(already);
648
+ const src = frame.getAttribute("src");
649
+ const category = autoCategory(src, true);
650
+ if (category === null || isCategoryConsented(category)) return;
651
+ frame.setAttribute("data-original-src", src);
652
+ frame.removeAttribute("src");
653
+ const held = { node: frame, category };
654
+ heldFrames.push(held);
655
+ showBox(held);
656
+ }
657
+ function check(el, byCode) {
658
+ if (el instanceof HTMLScriptElement) maybeBlockScript(el, byCode);
659
+ else if (el instanceof HTMLIFrameElement) maybeHoldFrame(el);
660
+ }
661
+ function interceptNode(node, byCode = true) {
662
+ if (node instanceof Element) check(node, byCode);
663
+ if (node instanceof Element || node instanceof DocumentFragment) {
664
+ for (const el of Array.from(node.querySelectorAll("script, iframe"))) check(el, byCode);
665
+ }
666
+ return node;
667
+ }
668
+ function scanStatic() {
669
+ for (const el of Array.from(document.querySelectorAll("script, iframe"))) check(el, false);
670
+ }
671
+ function activateInert(granted) {
672
+ var _a;
673
+ const plainScripts = document.querySelectorAll(
674
+ `script[type="text/plain"][data-consent-category]:not([${BLOCKED_MARKER}="true"])`
675
+ );
676
+ for (const script of plainScripts) {
677
+ try {
678
+ const category = script.getAttribute("data-consent-category");
679
+ if (!granted(category)) continue;
680
+ const src = script.getAttribute("data-original-src") || script.getAttribute("src");
681
+ const content = script.textContent;
682
+ const newScript = document.createElement("script");
683
+ for (const attr of Array.from(script.attributes)) {
684
+ if (attr.name !== "type" && attr.name !== "data-original-src") {
685
+ newScript.setAttribute(attr.name, attr.value);
686
+ }
687
+ }
688
+ if (src) newScript.src = src;
689
+ else if (content) newScript.textContent = content;
690
+ (_a = script.parentNode) == null ? void 0 : _a.replaceChild(newScript, script);
691
+ } catch {
692
+ }
693
+ }
694
+ }
695
+ function release(granted) {
696
+ const toActivate = [];
697
+ const remaining = [];
698
+ for (const frame of heldFrames.splice(0)) {
699
+ if (!granted(frame.category)) {
700
+ heldFrames.push(frame);
701
+ continue;
702
+ }
703
+ restoreFrame(frame);
704
+ }
705
+ for (const blocked of blockedScripts) {
706
+ if (granted(blocked.category)) {
707
+ toActivate.push(blocked);
708
+ } else {
709
+ remaining.push(blocked);
710
+ }
711
+ }
712
+ blockedScripts.length = 0;
713
+ blockedScripts.push(...remaining);
714
+ for (const script of toActivate) {
715
+ try {
716
+ activateScript(script);
717
+ } catch {
718
+ }
719
+ }
720
+ activateInert(granted);
721
+ }
722
+ function onConsentUpdate(event) {
723
+ release((category) => event.categories[category] === true);
724
+ }
725
+ function reconcile() {
726
+ release((category) => isCategoryConsented(category));
727
+ }
728
+ return {
729
+ init() {
730
+ scanStatic();
731
+ observer = new MutationObserver((mutations) => {
732
+ for (const mutation of mutations) {
733
+ for (const node of Array.from(mutation.addedNodes)) {
734
+ interceptNode(node, false);
735
+ }
736
+ }
737
+ if (manager) activateInert(isCategoryConsented);
738
+ });
739
+ observer.observe(document.documentElement, { childList: true, subtree: true });
740
+ document.createElement = function(tagName, options) {
741
+ const el = nativeCreateElement$1.call(document, tagName, options);
742
+ const tag = String(tagName).toLowerCase();
743
+ if (tag === "script" || tag === "iframe") {
744
+ created.add(el);
745
+ const originalSetAttribute = el.setAttribute.bind(el);
746
+ el.setAttribute = (name2, value) => {
747
+ originalSetAttribute(name2, value);
748
+ if (name2 === "data-consent-category" || name2 === "src") {
749
+ check(el, true);
750
+ }
751
+ };
752
+ const proto = tag === "script" ? HTMLScriptElement.prototype : HTMLIFrameElement.prototype;
753
+ const srcDescriptor = Object.getOwnPropertyDescriptor(proto, "src");
754
+ if ((srcDescriptor == null ? void 0 : srcDescriptor.get) && srcDescriptor.set) {
755
+ Object.defineProperty(el, "src", {
756
+ configurable: true,
757
+ enumerable: true,
758
+ get() {
759
+ return srcDescriptor.get.call(this);
760
+ },
761
+ set(value) {
762
+ srcDescriptor.set.call(this, value);
763
+ check(el, true);
764
+ }
765
+ });
766
+ }
767
+ }
768
+ return el;
769
+ };
770
+ Node.prototype.appendChild = function(child) {
771
+ return nativeAppendChild.call(this, interceptNode(child));
772
+ };
773
+ Node.prototype.insertBefore = function(newChild, refChild) {
774
+ return nativeInsertBefore.call(this, interceptNode(newChild), refChild);
775
+ };
776
+ Node.prototype.replaceChild = function(newChild, oldChild) {
777
+ return nativeReplaceChild.call(this, interceptNode(newChild), oldChild);
778
+ };
779
+ Element.prototype.append = function(...nodes) {
780
+ nativeAppend.apply(
781
+ this,
782
+ nodes.map((node) => typeof node === "string" ? node : interceptNode(node))
783
+ );
784
+ };
785
+ if (manager) {
786
+ unsubConsent = manager.onConsentChange(onConsentUpdate);
787
+ reconcile();
788
+ }
789
+ },
790
+ attach(m) {
791
+ const unsub = m.onConsentChange(onConsentUpdate);
792
+ unsubConsent = unsub;
793
+ manager = m;
794
+ reconcile();
795
+ },
796
+ setRules(list) {
797
+ const waiting = rules === null;
798
+ rules = list;
799
+ if (!waiting || !list) return;
800
+ for (const held of [...blockedScripts, ...heldFrames]) {
801
+ if (held.category !== WAIT) continue;
802
+ const src = "src" in held ? held.src : held.node.getAttribute("data-original-src");
803
+ held.category = listed(thirdParty(src)) ?? FREE;
804
+ }
805
+ release((category) => category === FREE || isCategoryConsented(category));
806
+ for (const held of heldFrames) showBox(held);
807
+ },
808
+ setTexts(t) {
809
+ texts = t;
810
+ for (const held of heldFrames) if (held.box) fillPlaceholder(held.box, service(held.node), t);
811
+ },
812
+ destroy() {
813
+ if (observer) {
814
+ observer.disconnect();
815
+ observer = null;
816
+ }
817
+ document.createElement = nativeCreateElement$1;
818
+ Node.prototype.appendChild = nativeAppendChild;
819
+ Node.prototype.insertBefore = nativeInsertBefore;
820
+ Node.prototype.replaceChild = nativeReplaceChild;
821
+ Element.prototype.append = nativeAppend;
822
+ if (unsubConsent) {
823
+ unsubConsent();
824
+ unsubConsent = null;
825
+ }
826
+ manager = null;
827
+ blockedScripts.length = 0;
828
+ for (const held of heldFrames) {
829
+ const box = held.box;
830
+ if (box == null ? void 0 : box.parentNode) nativeReplaceChild.call(box.parentNode, held.node, box);
831
+ }
832
+ heldFrames.length = 0;
833
+ loaded = /* @__PURE__ */ new WeakSet();
834
+ texts = DEFAULT_TEXTS;
835
+ rules = void 0;
836
+ created = /* @__PURE__ */ new WeakSet();
837
+ }
838
+ };
839
+ }
840
+ const STYLE_ID = "smartconsent-styles";
841
+ function injectStyles(theme) {
842
+ if (document.getElementById(STYLE_ID)) return;
843
+ const style = document.createElement("style");
844
+ style.id = STYLE_ID;
845
+ style.textContent = buildCSS(theme);
846
+ document.head.appendChild(style);
847
+ }
848
+ function buildCSS(t) {
849
+ return `
850
+ [data-smartconsent] {
851
+ --sc-bg: ${t.bg};
852
+ --sc-surface: ${t.surface};
853
+ --sc-border: ${t.border};
854
+ --sc-text: ${t.text};
855
+ --sc-text-muted: ${t.textMuted};
856
+ --sc-accent: ${t.accent};
857
+ --sc-accept: ${t.accept};
858
+ --sc-reject: ${t.reject};
859
+ --sc-toggle-on: ${t.toggleOn};
860
+ --sc-toggle-off: ${t.toggleOff};
861
+ --sc-radius: ${t.radius};
862
+ --sc-font: ${t.font};
863
+ }
864
+
865
+ [data-smartconsent] *,
866
+ [data-smartconsent] *::before,
867
+ [data-smartconsent] *::after {
868
+ box-sizing: border-box;
869
+ margin: 0;
870
+ padding: 0;
871
+ }
872
+
873
+ [data-smartconsent="backdrop"] {
874
+ position: fixed;
875
+ inset: 0;
876
+ background: rgba(0, 0, 0, 0.4);
877
+ z-index: 9998;
878
+ }
879
+
880
+ [data-smartconsent="banner"] {
881
+ position: fixed;
882
+ bottom: 0;
883
+ left: 0;
884
+ right: 0;
885
+ z-index: 9999;
886
+ background: var(--sc-bg);
887
+ color: var(--sc-text);
888
+ font-family: var(--sc-font);
889
+ font-size: 14px;
890
+ line-height: 1.5;
891
+ animation: sc-slide-up 0.3s ease-out;
892
+ }
893
+
894
+ [data-smartconsent="banner"][data-sc-position="top"] {
895
+ bottom: auto;
896
+ top: 0;
897
+ animation: sc-slide-down-in 0.3s ease-out;
898
+ }
899
+
900
+ [data-smartconsent="banner"] .sc-accent-line {
901
+ height: 2px;
902
+ background: linear-gradient(90deg, var(--sc-accent), var(--sc-accept));
903
+ }
904
+
905
+ [data-smartconsent="banner"] .sc-inner {
906
+ max-width: 960px;
907
+ margin: 0 auto;
908
+ padding: 16px 20px;
909
+ }
910
+
911
+ /* Compact state */
912
+ [data-smartconsent="banner"] .sc-compact {
913
+ display: flex;
914
+ align-items: center;
915
+ gap: 16px;
916
+ flex-wrap: wrap;
917
+ }
918
+
919
+ [data-smartconsent="banner"] .sc-compact-text {
920
+ flex: 1 1 300px;
921
+ color: var(--sc-text);
922
+ font-size: 14px;
923
+ }
924
+
925
+ [data-smartconsent="banner"] .sc-compact-actions {
926
+ display: flex;
927
+ align-items: center;
928
+ gap: 10px;
929
+ flex-wrap: wrap;
930
+ }
931
+
932
+ [data-smartconsent="banner"] .sc-compact-attribution {
933
+ flex: 1 1 100%;
934
+ margin-top: 6px;
935
+ font-size: 11px;
936
+ }
937
+
938
+ [data-smartconsent="banner"] .sc-compact-attribution a {
939
+ color: var(--sc-accent);
940
+ text-decoration: none;
941
+ font-weight: 500;
942
+ }
943
+
944
+ [data-smartconsent="banner"] .sc-compact-attribution a:hover {
945
+ text-decoration: underline;
946
+ }
947
+
948
+ /* Expanded state */
949
+ [data-smartconsent="banner"] .sc-expanded {
950
+ display: none;
951
+ }
952
+
953
+ [data-smartconsent="banner"] .sc-expanded.sc-active {
954
+ display: block;
955
+ }
956
+
957
+ [data-smartconsent="banner"] .sc-compact.sc-hidden {
958
+ display: none;
959
+ }
960
+
961
+ [data-smartconsent="banner"] .sc-header {
962
+ display: flex;
963
+ align-items: center;
964
+ gap: 12px;
965
+ margin-bottom: 8px;
966
+ }
967
+
968
+ [data-smartconsent="banner"] .sc-logo {
969
+ flex-shrink: 0;
970
+ max-height: 48px;
971
+ width: auto;
972
+ }
973
+
974
+ [data-smartconsent="banner"] .sc-header .sc-heading {
975
+ margin-bottom: 0;
976
+ }
977
+
978
+ [data-smartconsent="banner"] .sc-heading {
979
+ font-size: 18px;
980
+ font-weight: 600;
981
+ margin-bottom: 8px;
982
+ color: var(--sc-text);
983
+ }
984
+
985
+ [data-smartconsent="banner"] .sc-description {
986
+ color: var(--sc-text-muted);
987
+ margin-bottom: 16px;
988
+ font-size: 13px;
989
+ }
990
+
991
+ /* Category rows */
992
+ [data-smartconsent="banner"] .sc-categories {
993
+ margin-bottom: 16px;
994
+ }
995
+
996
+ [data-smartconsent="banner"] .sc-category {
997
+ display: flex;
998
+ align-items: center;
999
+ justify-content: space-between;
1000
+ padding: 12px;
1001
+ border-bottom: 1px solid var(--sc-border);
1002
+ }
1003
+
1004
+ [data-smartconsent="banner"] .sc-category:hover {
1005
+ background: var(--sc-surface);
1006
+ }
1007
+
1008
+ [data-smartconsent="banner"] .sc-category-info {
1009
+ flex: 1;
1010
+ margin-right: 12px;
1011
+ }
1012
+
1013
+ [data-smartconsent="banner"] .sc-category-label {
1014
+ font-size: 14px;
1015
+ font-weight: 500;
1016
+ color: var(--sc-text);
1017
+ }
1018
+
1019
+ [data-smartconsent="banner"] .sc-category-desc {
1020
+ font-size: 12px;
1021
+ color: var(--sc-text-muted);
1022
+ margin-top: 2px;
1023
+ }
1024
+
1025
+ /* Toggle switch */
1026
+ [data-smartconsent="banner"] .sc-toggle {
1027
+ position: relative;
1028
+ width: 44px;
1029
+ height: 24px;
1030
+ background: var(--sc-toggle-off);
1031
+ border-radius: 12px;
1032
+ border: none;
1033
+ cursor: pointer;
1034
+ transition: background 0.2s;
1035
+ flex-shrink: 0;
1036
+ }
1037
+
1038
+ [data-smartconsent="banner"] .sc-toggle[aria-checked="true"] {
1039
+ background: var(--sc-toggle-on);
1040
+ }
1041
+
1042
+ [data-smartconsent="banner"] .sc-toggle::after {
1043
+ content: '';
1044
+ position: absolute;
1045
+ top: 3px;
1046
+ left: 3px;
1047
+ width: 18px;
1048
+ height: 18px;
1049
+ background: white;
1050
+ border-radius: 50%;
1051
+ transition: left 0.2s;
1052
+ }
1053
+
1054
+ [data-smartconsent="banner"] .sc-toggle[aria-checked="true"]::after {
1055
+ left: 23px;
1056
+ }
1057
+
1058
+ [data-smartconsent="banner"] .sc-toggle:disabled {
1059
+ opacity: 0.5;
1060
+ cursor: not-allowed;
1061
+ }
1062
+
1063
+ /* Held embed placeholder (CR-035): the size of the iframe it stands in for */
1064
+ [data-smartconsent="embed"] {
1065
+ display: flex;
1066
+ flex-direction: column;
1067
+ align-items: center;
1068
+ justify-content: center;
1069
+ gap: 12px;
1070
+ width: var(--sc-embed-w, 100%);
1071
+ max-width: 100%;
1072
+ height: var(--sc-embed-h, auto);
1073
+ min-height: 150px;
1074
+ padding: 16px;
1075
+ background: var(--sc-surface);
1076
+ color: var(--sc-text);
1077
+ border: 1px solid var(--sc-border);
1078
+ border-radius: var(--sc-radius);
1079
+ font-family: var(--sc-font);
1080
+ font-size: 14px;
1081
+ line-height: 1.5;
1082
+ text-align: center;
1083
+ box-sizing: border-box;
1084
+ }
1085
+
1086
+ [data-smartconsent="embed"] button {
1087
+ padding: 8px 18px;
1088
+ border: none;
1089
+ border-radius: var(--sc-radius);
1090
+ background: var(--sc-accent);
1091
+ color: #fff;
1092
+ font: 500 13px var(--sc-font);
1093
+ cursor: pointer;
1094
+ }
1095
+
1096
+ [data-smartconsent="embed"] button:focus-visible {
1097
+ outline: 2px solid var(--sc-accent);
1098
+ outline-offset: 2px;
1099
+ }
1100
+
1101
+ /* Buttons */
1102
+ [data-smartconsent="banner"] .sc-btn {
1103
+ padding: 8px 18px;
1104
+ border: none;
1105
+ border-radius: var(--sc-radius);
1106
+ font-family: var(--sc-font);
1107
+ font-size: 13px;
1108
+ font-weight: 500;
1109
+ cursor: pointer;
1110
+ transition: opacity 0.2s;
1111
+ white-space: nowrap;
1112
+ }
1113
+
1114
+ [data-smartconsent="banner"] .sc-btn:hover {
1115
+ opacity: 0.85;
1116
+ }
1117
+
1118
+ [data-smartconsent="banner"] .sc-btn:focus-visible {
1119
+ outline: 2px solid var(--sc-accent);
1120
+ outline-offset: 2px;
1121
+ }
1122
+
1123
+ [data-smartconsent="banner"] .sc-btn-accept {
1124
+ background: var(--sc-accept);
1125
+ color: #fff;
1126
+ }
1127
+
1128
+ [data-smartconsent="banner"] .sc-btn-reject {
1129
+ background: var(--sc-reject);
1130
+ color: #fff;
1131
+ }
1132
+
1133
+ [data-smartconsent="banner"] .sc-btn-save {
1134
+ background: var(--sc-accent);
1135
+ color: #fff;
1136
+ }
1137
+
1138
+ [data-smartconsent="banner"] .sc-btn-essential {
1139
+ background: var(--sc-reject);
1140
+ color: #fff;
1141
+ }
1142
+
1143
+ [data-smartconsent="banner"] .sc-link {
1144
+ background: none;
1145
+ border: none;
1146
+ color: var(--sc-accent);
1147
+ font-family: var(--sc-font);
1148
+ font-size: 13px;
1149
+ cursor: pointer;
1150
+ text-decoration: underline;
1151
+ padding: 4px;
1152
+ }
1153
+
1154
+ [data-smartconsent="banner"] .sc-link:focus-visible {
1155
+ outline: 2px solid var(--sc-accent);
1156
+ outline-offset: 2px;
1157
+ }
1158
+
1159
+ /* Expanded actions */
1160
+ [data-smartconsent="banner"] .sc-expanded-actions {
1161
+ display: flex;
1162
+ gap: 10px;
1163
+ flex-wrap: wrap;
1164
+ margin-top: 16px;
1165
+ }
1166
+
1167
+ /* Attribution */
1168
+ [data-smartconsent="banner"] .sc-attribution {
1169
+ text-align: center;
1170
+ margin-top: 12px;
1171
+ padding-top: 12px;
1172
+ border-top: 1px solid var(--sc-border);
1173
+ }
1174
+
1175
+ [data-smartconsent="banner"] .sc-attribution a {
1176
+ color: var(--sc-text-muted);
1177
+ font-size: 11px;
1178
+ text-decoration: none;
1179
+ }
1180
+
1181
+ [data-smartconsent="banner"] .sc-attribution a:hover {
1182
+ color: var(--sc-accent);
1183
+ }
1184
+
1185
+ /* Badge */
1186
+ [data-smartconsent="badge"] {
1187
+ position: fixed;
1188
+ width: 40px;
1189
+ height: 40px;
1190
+ border-radius: 50%;
1191
+ background: var(--sc-accent);
1192
+ color: #fff;
1193
+ border: none;
1194
+ cursor: pointer;
1195
+ z-index: 9997;
1196
+ display: flex;
1197
+ align-items: center;
1198
+ justify-content: center;
1199
+ font-size: 20px;
1200
+ opacity: 0.7;
1201
+ transition: opacity 0.2s;
1202
+ font-family: var(--sc-font);
1203
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
1204
+ }
1205
+
1206
+ [data-smartconsent="badge"]:hover {
1207
+ opacity: 1;
1208
+ }
1209
+
1210
+ [data-smartconsent="badge"]:focus-visible {
1211
+ outline: 2px solid var(--sc-accent);
1212
+ outline-offset: 2px;
1213
+ opacity: 1;
1214
+ }
1215
+
1216
+ [data-smartconsent="badge"][data-sc-position="bottom-right"] {
1217
+ bottom: 16px;
1218
+ right: 16px;
1219
+ }
1220
+
1221
+ [data-smartconsent="badge"][data-sc-position="bottom-left"] {
1222
+ bottom: 16px;
1223
+ left: 16px;
1224
+ }
1225
+
1226
+ /* Layout: Box (FP-06) */
1227
+ [data-smartconsent="banner"][data-sc-layout="box"] {
1228
+ bottom: 16px;
1229
+ left: 16px;
1230
+ right: auto;
1231
+ width: 400px;
1232
+ max-width: calc(100vw - 32px);
1233
+ border-radius: var(--sc-radius);
1234
+ box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
1235
+ animation: sc-fade-in 0.3s ease-out;
1236
+ }
1237
+
1238
+ [data-smartconsent="banner"][data-sc-layout="box"][data-sc-box-position="bottom-right"] {
1239
+ left: auto;
1240
+ right: 16px;
1241
+ }
1242
+
1243
+ [data-smartconsent="banner"][data-sc-layout="box"] .sc-compact {
1244
+ flex-direction: column;
1245
+ align-items: stretch;
1246
+ }
1247
+
1248
+ /* In a column a flex basis is a height: the text and credit hug their content (BRIEF-280). */
1249
+ [data-smartconsent="banner"][data-sc-layout="box"] .sc-compact-text,
1250
+ [data-smartconsent="banner"][data-sc-layout="box"] .sc-compact-attribution {
1251
+ flex-basis: auto;
1252
+ }
1253
+
1254
+ [data-smartconsent="banner"][data-sc-layout="box"] .sc-compact-actions {
1255
+ justify-content: stretch;
1256
+ }
1257
+
1258
+ [data-smartconsent="banner"][data-sc-layout="box"] .sc-compact-actions .sc-btn {
1259
+ flex: 1;
1260
+ }
1261
+
1262
+ /* Layout: Popup (FP-06) */
1263
+ [data-smartconsent="banner"][data-sc-layout="popup"] {
1264
+ bottom: auto;
1265
+ left: 50%;
1266
+ right: auto;
1267
+ top: 50%;
1268
+ transform: translate(-50%, -50%);
1269
+ width: 520px;
1270
+ max-width: calc(100vw - 32px);
1271
+ max-height: calc(100vh - 32px);
1272
+ overflow-y: auto;
1273
+ border-radius: var(--sc-radius);
1274
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
1275
+ animation: sc-fade-in 0.3s ease-out;
1276
+ }
1277
+
1278
+ @keyframes sc-fade-in {
1279
+ from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
1280
+ to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
1281
+ }
1282
+
1283
+ [data-smartconsent="banner"][data-sc-layout="box"] + [data-smartconsent="backdrop"],
1284
+ [data-smartconsent="banner"][data-sc-layout="box"] ~ [data-smartconsent="backdrop"] {
1285
+ display: none;
1286
+ }
1287
+
1288
+ /* Animations */
1289
+ @keyframes sc-slide-up {
1290
+ from { transform: translateY(100%); }
1291
+ to { transform: translateY(0); }
1292
+ }
1293
+
1294
+ @keyframes sc-slide-down-in {
1295
+ from { transform: translateY(-100%); }
1296
+ to { transform: translateY(0); }
1297
+ }
1298
+
1299
+ /* Responsive */
1300
+ @media (max-width: 480px) {
1301
+ [data-smartconsent="banner"] .sc-compact {
1302
+ flex-direction: column;
1303
+ align-items: stretch;
1304
+ }
1305
+
1306
+ [data-smartconsent="banner"] .sc-compact-text,
1307
+ [data-smartconsent="banner"] .sc-compact-attribution {
1308
+ flex-basis: auto;
1309
+ }
1310
+
1311
+ [data-smartconsent="banner"] .sc-compact-actions {
1312
+ justify-content: stretch;
1313
+ }
1314
+
1315
+ [data-smartconsent="banner"] .sc-compact-attribution {
1316
+ text-align: center;
1317
+ }
1318
+
1319
+ [data-smartconsent="banner"] .sc-compact-actions .sc-btn {
1320
+ flex: 1;
1321
+ }
1322
+
1323
+ [data-smartconsent="banner"] .sc-expanded-actions {
1324
+ flex-direction: column;
1325
+ }
1326
+
1327
+ [data-smartconsent="banner"] .sc-expanded-actions .sc-btn {
1328
+ width: 100%;
1329
+ }
1330
+
1331
+ /* A full-width strip for every box position: the position attribute matches the bottom-right rule's weight, and
1332
+ width: auto with left and right at 0 fits the viewport exactly (the banner itself is not border-box) (BRIEF-280). */
1333
+ [data-smartconsent="banner"][data-sc-layout="box"],
1334
+ [data-smartconsent="banner"][data-sc-layout="box"][data-sc-box-position] {
1335
+ left: 0;
1336
+ right: 0;
1337
+ bottom: 0;
1338
+ width: auto;
1339
+ max-width: none;
1340
+ border-radius: 0;
1341
+ }
1342
+
1343
+ [data-smartconsent="banner"][data-sc-layout="popup"] {
1344
+ left: 0;
1345
+ right: 0;
1346
+ top: auto;
1347
+ bottom: 0;
1348
+ width: 100%;
1349
+ max-width: 100%;
1350
+ transform: none;
1351
+ border-radius: 0;
1352
+ animation: sc-slide-up 0.3s ease-out;
1353
+ }
1354
+ }
1355
+ `;
1356
+ }
1357
+ function trapFocus(container) {
1358
+ const focusableSelector = 'button:not([disabled]), [href], input:not([disabled]), [tabindex]:not([tabindex="-1"]), [role="switch"]:not([disabled])';
1359
+ function getFocusable() {
1360
+ return Array.from(container.querySelectorAll(focusableSelector));
1361
+ }
1362
+ function handleKeyDown(e) {
1363
+ if (e.key !== "Tab") return;
1364
+ const focusable2 = getFocusable();
1365
+ if (focusable2.length === 0) return;
1366
+ const first = focusable2[0];
1367
+ const last = focusable2[focusable2.length - 1];
1368
+ if (e.shiftKey) {
1369
+ if (document.activeElement === first) {
1370
+ e.preventDefault();
1371
+ last.focus();
1372
+ }
1373
+ } else {
1374
+ if (document.activeElement === last) {
1375
+ e.preventDefault();
1376
+ first.focus();
1377
+ }
1378
+ }
1379
+ }
1380
+ container.addEventListener("keydown", handleKeyDown);
1381
+ const focusable = getFocusable();
1382
+ if (focusable.length > 0) {
1383
+ focusable[0].focus();
1384
+ }
1385
+ return () => {
1386
+ container.removeEventListener("keydown", handleKeyDown);
1387
+ };
1388
+ }
1389
+ function announceToScreenReader(message) {
1390
+ const el = document.createElement("div");
1391
+ el.setAttribute("role", "status");
1392
+ el.setAttribute("aria-live", "polite");
1393
+ el.setAttribute("aria-atomic", "true");
1394
+ el.style.position = "absolute";
1395
+ el.style.width = "1px";
1396
+ el.style.height = "1px";
1397
+ el.style.overflow = "hidden";
1398
+ el.style.clip = "rect(0, 0, 0, 0)";
1399
+ el.style.whiteSpace = "nowrap";
1400
+ el.textContent = message;
1401
+ (document.body ?? document.documentElement).appendChild(el);
1402
+ setTimeout(() => {
1403
+ el.remove();
1404
+ }, 1e3);
1405
+ }
1406
+ const CREDIT_TRANSLATIONS = {
1407
+ ar: "مدعوم بواسطة SmartGenie",
1408
+ cs: "Zajišťuje SmartGenie",
1409
+ da: "Drevet af SmartGenie",
1410
+ de: "Bereitgestellt von SmartGenie",
1411
+ es: "Desarrollado por SmartGenie",
1412
+ fr: "Propulsé par SmartGenie",
1413
+ hi: "SmartGenie द्वारा संचालित",
1414
+ it: "Offerto da SmartGenie",
1415
+ ja: "SmartGenie提供",
1416
+ ko: "SmartGenie 제공",
1417
+ nl: "Mogelijk gemaakt door SmartGenie",
1418
+ no: "Drevet av SmartGenie",
1419
+ pl: "Dostarczone przez SmartGenie",
1420
+ pt: "Fornecido por SmartGenie",
1421
+ ro: "Furnizat de SmartGenie",
1422
+ ru: "Работает на SmartGenie",
1423
+ sv: "Drivs av SmartGenie",
1424
+ tr: "SmartGenie tarafından desteklenmektedir",
1425
+ zh: "由 SmartGenie 提供支持"
1426
+ };
1427
+ const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
1428
+ function safeHttpUrl(url) {
1429
+ if (typeof url !== "string") return null;
1430
+ try {
1431
+ const { protocol } = new URL(url);
1432
+ return protocol === "http:" || protocol === "https:" ? url : null;
1433
+ } catch {
1434
+ return null;
1435
+ }
1436
+ }
1437
+ const CREDIT_REL = "sponsored nofollow noopener";
1438
+ function creditHref(config) {
1439
+ const url = safeHttpUrl(config.attributionUrl);
1440
+ return url && config.attributionRef ? `https://www.smartgenie.co.uk/r/${encodeURIComponent(config.attributionRef)}` : url;
1441
+ }
1442
+ function creditText(config, key) {
1443
+ const text = config.texts[key];
1444
+ const fallback = DEFAULT_TEXTS[key];
1445
+ if (key === "policyCredit") return text === fallback ? text : fallback;
1446
+ if (text === fallback || Object.values(CREDIT_TRANSLATIONS).includes(text)) return text;
1447
+ const lang = config.language || (typeof navigator !== "undefined" ? navigator.language : "") || "en";
1448
+ const code = lang.split("-")[0].toLowerCase();
1449
+ return has(CREDIT_TRANSLATIONS, code) ? CREDIT_TRANSLATIONS[code] : fallback;
1450
+ }
1451
+ const CONTAINERS = [".sc-compact-attribution", ".sc-attribution"];
1452
+ const MAX_RESTORES = 5;
1453
+ const WINDOW_MS = 1e3;
1454
+ const HIDING = [
1455
+ ["display", (v) => v === "none"],
1456
+ ["visibility", (v) => v === "hidden"],
1457
+ ["opacity", (v) => v !== "" && parseFloat(v) === 0]
1458
+ ];
1459
+ function hidingProps(el) {
1460
+ return HIDING.filter(([prop, isHiding]) => isHiding(el.style.getPropertyValue(prop))).map(([prop]) => prop);
1461
+ }
1462
+ function guardAttribution(banner, config) {
1463
+ if (!config.attribution) return () => {
1464
+ };
1465
+ const parts = [];
1466
+ for (const selector of CONTAINERS) {
1467
+ const container = banner.querySelector(selector);
1468
+ const link = container == null ? void 0 : container.querySelector("a");
1469
+ const parent = container == null ? void 0 : container.parentElement;
1470
+ if (container && link && parent) parts.push({ container, parent, link });
1471
+ }
1472
+ if (parts.length === 0) return () => {
1473
+ };
1474
+ const expectedText = creditText(config, "poweredBy");
1475
+ const expectedHref = creditHref(config);
1476
+ const needsRepair = ({ container, parent, link }) => link.parentElement !== container || container.parentElement !== parent || link.getAttribute("href") !== expectedHref || CREDIT_REL.split(" ").some((t) => !link.relList.contains(t)) || link.textContent !== expectedText || hidingProps(link).length > 0 || hidingProps(container).length > 0;
1477
+ const repair = ({ container, parent, link }) => {
1478
+ if (container.parentElement !== parent) parent.appendChild(container);
1479
+ if (link.parentElement !== container) container.appendChild(link);
1480
+ if (link.getAttribute("href") !== expectedHref) {
1481
+ if (expectedHref === null) link.removeAttribute("href");
1482
+ else link.setAttribute("href", expectedHref);
1483
+ }
1484
+ link.relList.add(...CREDIT_REL.split(" "));
1485
+ if (link.textContent !== expectedText) link.textContent = expectedText;
1486
+ for (const el of [link, container]) {
1487
+ for (const prop of hidingProps(el)) el.style.removeProperty(prop);
1488
+ }
1489
+ };
1490
+ let restores = 0;
1491
+ let windowStart = 0;
1492
+ const observer = new MutationObserver(() => {
1493
+ const broken = parts.filter(needsRepair);
1494
+ if (broken.length === 0) return;
1495
+ const now = Date.now();
1496
+ if (now - windowStart >= WINDOW_MS) {
1497
+ windowStart = now;
1498
+ restores = 0;
1499
+ }
1500
+ if (restores >= MAX_RESTORES) {
1501
+ observer.disconnect();
1502
+ console.warn("SmartConsent: attribution link keeps being removed; guard stopped.");
1503
+ return;
1504
+ }
1505
+ restores++;
1506
+ broken.forEach(repair);
1507
+ });
1508
+ observer.observe(banner, {
1509
+ childList: true,
1510
+ subtree: true,
1511
+ attributes: true,
1512
+ attributeFilter: ["href", "rel", "style"],
1513
+ characterData: true
1514
+ });
1515
+ return () => observer.disconnect();
1516
+ }
1517
+ function appendDataRightsLink(box, config) {
1518
+ if (!config.dataRequestUrl) return;
1519
+ if (box.firstChild) box.appendChild(document.createTextNode(" · "));
1520
+ const a = document.createElement("a");
1521
+ a.className = "sc-data-rights";
1522
+ a.href = config.dataRequestUrl;
1523
+ a.target = "_blank";
1524
+ a.rel = "noopener";
1525
+ a.textContent = config.texts.dataRequest;
1526
+ box.appendChild(a);
1527
+ }
1528
+ function createBanner(manager, config) {
1529
+ let bannerEl = null;
1530
+ let backdropEl = null;
1531
+ let releaseFocus = null;
1532
+ let escHandler = null;
1533
+ let stopGuard = null;
1534
+ const localised = !!config.language && config.language !== "en";
1535
+ const dialogName = localised ? config.texts.heading : "Cookie consent";
1536
+ function getMountTarget() {
1537
+ return document.body ?? document.documentElement;
1538
+ }
1539
+ function doReject() {
1540
+ manager.rejectOptional();
1541
+ api.hide();
1542
+ }
1543
+ function buildBanner() {
1544
+ const banner = document.createElement("div");
1545
+ banner.setAttribute("data-smartconsent", "banner");
1546
+ banner.setAttribute("role", "dialog");
1547
+ banner.setAttribute("aria-modal", "true");
1548
+ banner.setAttribute("aria-label", dialogName);
1549
+ if (localised) banner.setAttribute("lang", config.language);
1550
+ if (config.position === "top") {
1551
+ banner.setAttribute("data-sc-position", "top");
1552
+ }
1553
+ if (config.dir === "rtl") {
1554
+ banner.setAttribute("dir", "rtl");
1555
+ }
1556
+ if (config.layout !== "banner") {
1557
+ banner.setAttribute("data-sc-layout", config.layout);
1558
+ }
1559
+ if (config.layout === "box") {
1560
+ banner.setAttribute("data-sc-box-position", config.boxPosition);
1561
+ }
1562
+ const accent = document.createElement("div");
1563
+ accent.className = "sc-accent-line";
1564
+ banner.appendChild(accent);
1565
+ const inner = document.createElement("div");
1566
+ inner.className = "sc-inner";
1567
+ const compact = document.createElement("div");
1568
+ compact.className = "sc-compact";
1569
+ const compactText = document.createElement("div");
1570
+ compactText.className = "sc-compact-text";
1571
+ compactText.textContent = config.texts.description;
1572
+ compact.appendChild(compactText);
1573
+ const compactActions = document.createElement("div");
1574
+ compactActions.className = "sc-compact-actions";
1575
+ const rejectBtn = createButton(config.texts.rejectOptional, "sc-btn sc-btn-reject", () => {
1576
+ doReject();
1577
+ });
1578
+ compactActions.appendChild(rejectBtn);
1579
+ const acceptBtnCompact = createButton(config.texts.acceptAll, "sc-btn sc-btn-accept", () => {
1580
+ manager.acceptAll();
1581
+ api.hide();
1582
+ });
1583
+ compactActions.appendChild(acceptBtnCompact);
1584
+ const manageLink = document.createElement("button");
1585
+ manageLink.className = "sc-link";
1586
+ manageLink.textContent = config.texts.managePreferences;
1587
+ manageLink.type = "button";
1588
+ manageLink.addEventListener("click", () => {
1589
+ compact.classList.add("sc-hidden");
1590
+ expanded.classList.add("sc-active");
1591
+ });
1592
+ compactActions.appendChild(manageLink);
1593
+ compact.appendChild(compactActions);
1594
+ if (config.attribution) {
1595
+ const compactAttribution = document.createElement("div");
1596
+ compactAttribution.className = "sc-compact-attribution";
1597
+ const compactLink = document.createElement("a");
1598
+ const compactHref = creditHref(config);
1599
+ if (compactHref) compactLink.href = compactHref;
1600
+ compactLink.target = "_blank";
1601
+ compactLink.rel = CREDIT_REL;
1602
+ compactLink.textContent = creditText(config, "poweredBy");
1603
+ compactAttribution.appendChild(compactLink);
1604
+ compact.appendChild(compactAttribution);
1605
+ }
1606
+ inner.appendChild(compact);
1607
+ const expanded = document.createElement("div");
1608
+ expanded.className = "sc-expanded";
1609
+ if (config.logo) {
1610
+ const header = document.createElement("div");
1611
+ header.className = "sc-header";
1612
+ const img = document.createElement("img");
1613
+ img.src = config.logo.src;
1614
+ img.alt = config.logo.alt;
1615
+ img.className = "sc-logo";
1616
+ if (config.logo.width) img.width = config.logo.width;
1617
+ if (config.logo.height) img.height = config.logo.height;
1618
+ img.style.maxHeight = "48px";
1619
+ header.appendChild(img);
1620
+ const heading = document.createElement("h2");
1621
+ heading.className = "sc-heading";
1622
+ heading.textContent = config.texts.heading;
1623
+ header.appendChild(heading);
1624
+ expanded.appendChild(header);
1625
+ } else {
1626
+ const heading = document.createElement("h2");
1627
+ heading.className = "sc-heading";
1628
+ heading.textContent = config.texts.heading;
1629
+ expanded.appendChild(heading);
1630
+ }
1631
+ const desc = document.createElement("p");
1632
+ desc.className = "sc-description";
1633
+ desc.textContent = config.texts.description;
1634
+ expanded.appendChild(desc);
1635
+ const savedState = manager.getState();
1636
+ const toggleStates = {};
1637
+ const categoriesDiv = document.createElement("div");
1638
+ categoriesDiv.className = "sc-categories";
1639
+ for (const cat of config.categories) {
1640
+ toggleStates[cat.id] = cat.required ? true : (savedState == null ? void 0 : savedState.categories[cat.id]) ?? false;
1641
+ const row = document.createElement("div");
1642
+ row.className = "sc-category";
1643
+ const info = document.createElement("div");
1644
+ info.className = "sc-category-info";
1645
+ const label = document.createElement("div");
1646
+ label.className = "sc-category-label";
1647
+ label.textContent = cat.label;
1648
+ info.appendChild(label);
1649
+ const catDesc = document.createElement("div");
1650
+ catDesc.className = "sc-category-desc";
1651
+ catDesc.textContent = cat.description;
1652
+ info.appendChild(catDesc);
1653
+ row.appendChild(info);
1654
+ const toggle = document.createElement("button");
1655
+ toggle.className = "sc-toggle";
1656
+ toggle.type = "button";
1657
+ toggle.setAttribute("role", "switch");
1658
+ toggle.setAttribute("aria-checked", String(toggleStates[cat.id]));
1659
+ toggle.setAttribute("aria-label", cat.label);
1660
+ if (cat.required) {
1661
+ toggle.disabled = true;
1662
+ } else {
1663
+ toggle.addEventListener("click", () => {
1664
+ const current = toggle.getAttribute("aria-checked") === "true";
1665
+ toggle.setAttribute("aria-checked", String(!current));
1666
+ toggleStates[cat.id] = !current;
1667
+ });
1668
+ }
1669
+ row.appendChild(toggle);
1670
+ categoriesDiv.appendChild(row);
1671
+ }
1672
+ expanded.appendChild(categoriesDiv);
1673
+ const expandedActions = document.createElement("div");
1674
+ expandedActions.className = "sc-expanded-actions";
1675
+ const essentialBtn = createButton(config.texts.essentialOnly, "sc-btn sc-btn-essential", () => {
1676
+ doReject();
1677
+ });
1678
+ expandedActions.appendChild(essentialBtn);
1679
+ const saveBtn = createButton(config.texts.savePreferences, "sc-btn sc-btn-save", () => {
1680
+ manager.saveCustom(toggleStates);
1681
+ api.hide();
1682
+ });
1683
+ expandedActions.appendChild(saveBtn);
1684
+ const acceptBtnExpanded = createButton(config.texts.acceptAll, "sc-btn sc-btn-accept", () => {
1685
+ manager.acceptAll();
1686
+ api.hide();
1687
+ });
1688
+ expandedActions.appendChild(acceptBtnExpanded);
1689
+ expanded.appendChild(expandedActions);
1690
+ if (config.attribution || config.dataRequestUrl) {
1691
+ const attribution = document.createElement("div");
1692
+ attribution.className = "sc-attribution";
1693
+ if (config.attribution) {
1694
+ const link = document.createElement("a");
1695
+ const href = creditHref(config);
1696
+ if (href) link.href = href;
1697
+ link.target = "_blank";
1698
+ link.rel = CREDIT_REL;
1699
+ link.textContent = creditText(config, "poweredBy");
1700
+ attribution.appendChild(link);
1701
+ }
1702
+ appendDataRightsLink(attribution, config);
1703
+ expanded.appendChild(attribution);
1704
+ }
1705
+ inner.appendChild(expanded);
1706
+ banner.appendChild(inner);
1707
+ return banner;
1708
+ }
1709
+ function createButton(text, className, onClick) {
1710
+ const btn = document.createElement("button");
1711
+ btn.type = "button";
1712
+ btn.className = className;
1713
+ btn.textContent = text;
1714
+ btn.addEventListener("click", onClick);
1715
+ return btn;
1716
+ }
1717
+ const api = {
1718
+ show() {
1719
+ if (bannerEl) return;
1720
+ if (config.layout !== "box") {
1721
+ backdropEl = document.createElement("div");
1722
+ backdropEl.setAttribute("data-smartconsent", "backdrop");
1723
+ backdropEl.addEventListener("click", doReject);
1724
+ getMountTarget().appendChild(backdropEl);
1725
+ }
1726
+ bannerEl = buildBanner();
1727
+ getMountTarget().appendChild(bannerEl);
1728
+ stopGuard = guardAttribution(bannerEl, config);
1729
+ releaseFocus = trapFocus(bannerEl);
1730
+ escHandler = (e) => {
1731
+ if (e.key === "Escape") {
1732
+ doReject();
1733
+ }
1734
+ };
1735
+ document.addEventListener("keydown", escHandler);
1736
+ announceToScreenReader(dialogName);
1737
+ },
1738
+ hide() {
1739
+ if (stopGuard) {
1740
+ stopGuard();
1741
+ stopGuard = null;
1742
+ }
1743
+ if (releaseFocus) {
1744
+ releaseFocus();
1745
+ releaseFocus = null;
1746
+ }
1747
+ if (escHandler) {
1748
+ document.removeEventListener("keydown", escHandler);
1749
+ escHandler = null;
1750
+ }
1751
+ if (bannerEl) {
1752
+ bannerEl.remove();
1753
+ bannerEl = null;
1754
+ }
1755
+ if (backdropEl) {
1756
+ backdropEl.remove();
1757
+ backdropEl = null;
1758
+ }
1759
+ },
1760
+ destroy() {
1761
+ api.hide();
1762
+ }
1763
+ };
1764
+ return api;
1765
+ }
1766
+ function createOptOutNotice(manager, config, openSettings) {
1767
+ let el = null;
1768
+ let stopGuard = () => {
1769
+ };
1770
+ const t = config.texts;
1771
+ const make = (tag, cls, text) => {
1772
+ const e = document.createElement(tag);
1773
+ e.className = cls;
1774
+ if (text) e.textContent = text;
1775
+ return e;
1776
+ };
1777
+ const link = (text, onClick) => {
1778
+ const b = make("button", "sc-link", text);
1779
+ b.type = "button";
1780
+ b.addEventListener("click", () => {
1781
+ api.hide();
1782
+ onClick();
1783
+ });
1784
+ return b;
1785
+ };
1786
+ const api = {
1787
+ show() {
1788
+ if (el) return;
1789
+ el = document.createElement("div");
1790
+ el.setAttribute("data-smartconsent", "banner");
1791
+ el.setAttribute("data-sc-notice", "");
1792
+ el.setAttribute("role", "region");
1793
+ el.setAttribute("aria-label", t.heading);
1794
+ if (config.position === "top") el.setAttribute("data-sc-position", "top");
1795
+ if (config.dir === "rtl") el.setAttribute("dir", "rtl");
1796
+ const compact = make("div", "sc-compact");
1797
+ compact.appendChild(make("div", "sc-compact-text", t.description));
1798
+ const actions = make("div", "sc-compact-actions");
1799
+ actions.appendChild(link(t.doNotSell, () => manager.rejectOptional()));
1800
+ actions.appendChild(link(t.cookieSettings, openSettings));
1801
+ compact.appendChild(actions);
1802
+ if (config.attribution || config.dataRequestUrl) {
1803
+ const box = make("div", "sc-compact-attribution");
1804
+ if (config.attribution) {
1805
+ const a = make("a", "", creditText(config, "poweredBy"));
1806
+ const href = creditHref(config);
1807
+ if (href) a.href = href;
1808
+ a.target = "_blank";
1809
+ a.rel = CREDIT_REL;
1810
+ box.appendChild(a);
1811
+ }
1812
+ appendDataRightsLink(box, config);
1813
+ compact.appendChild(box);
1814
+ }
1815
+ const inner = make("div", "sc-inner");
1816
+ inner.appendChild(compact);
1817
+ el.appendChild(inner);
1818
+ (document.body ?? document.documentElement).appendChild(el);
1819
+ stopGuard = guardAttribution(el, config);
1820
+ },
1821
+ hide() {
1822
+ stopGuard();
1823
+ el == null ? void 0 : el.remove();
1824
+ el = null;
1825
+ }
1826
+ };
1827
+ return api;
1828
+ }
1829
+ function createBadge(config, onOpen) {
1830
+ let badgeEl = null;
1831
+ function getMountTarget() {
1832
+ return document.body ?? document.documentElement;
1833
+ }
1834
+ function build() {
1835
+ const btn = document.createElement("button");
1836
+ btn.setAttribute("data-smartconsent", "badge");
1837
+ btn.setAttribute("data-sc-position", config.badgePosition);
1838
+ btn.setAttribute("aria-label", "Cookie preferences");
1839
+ btn.type = "button";
1840
+ btn.innerHTML = `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><circle cx="8" cy="9" r="1" fill="currentColor"/><circle cx="15" cy="11" r="1" fill="currentColor"/><circle cx="10" cy="15" r="1" fill="currentColor"/></svg>`;
1841
+ btn.addEventListener("click", onOpen);
1842
+ return btn;
1843
+ }
1844
+ const api = {
1845
+ show() {
1846
+ if (!config.showBadge) return;
1847
+ if (badgeEl) {
1848
+ badgeEl.style.display = "flex";
1849
+ return;
1850
+ }
1851
+ badgeEl = build();
1852
+ getMountTarget().appendChild(badgeEl);
1853
+ },
1854
+ hide() {
1855
+ if (badgeEl) {
1856
+ badgeEl.style.display = "none";
1857
+ }
1858
+ },
1859
+ destroy() {
1860
+ if (badgeEl) {
1861
+ badgeEl.remove();
1862
+ badgeEl = null;
1863
+ }
1864
+ }
1865
+ };
1866
+ return api;
1867
+ }
1868
+ function validateRegulation(data) {
1869
+ if (data === null || data === void 0 || typeof data !== "object") {
1870
+ throw new Error("Regulation: data must be an object");
1871
+ }
1872
+ const d = data;
1873
+ if (!d.id || typeof d.id !== "string") {
1874
+ throw new Error('Regulation: missing or invalid "id" (must be a non-empty string)');
1875
+ }
1876
+ if (!d.name || typeof d.name !== "string") {
1877
+ throw new Error(`Regulation [${d.id}]: missing or invalid "name"`);
1878
+ }
1879
+ if (d.consent_model !== "opt-in" && d.consent_model !== "opt-out") {
1880
+ throw new Error(
1881
+ `Regulation [${d.id}]: "consent_model" must be "opt-in" or "opt-out", got "${String(d.consent_model)}"`
1882
+ );
1883
+ }
1884
+ if (d.default_cookie_state !== "blocked" && d.default_cookie_state !== "allowed") {
1885
+ throw new Error(
1886
+ `Regulation [${d.id}]: "default_cookie_state" must be "blocked" or "allowed"`
1887
+ );
1888
+ }
1889
+ if (!d.jurisdiction || typeof d.jurisdiction !== "object") {
1890
+ throw new Error(`Regulation [${d.id}]: missing "jurisdiction" object`);
1891
+ }
1892
+ const j = d.jurisdiction;
1893
+ if (!Array.isArray(j.countries)) {
1894
+ throw new Error(`Regulation [${d.id}]: "jurisdiction.countries" must be an array`);
1895
+ }
1896
+ if (!d.banner_requirements || typeof d.banner_requirements !== "object") {
1897
+ throw new Error(`Regulation [${d.id}]: missing "banner_requirements" object`);
1898
+ }
1899
+ if (!d.consent_rules || typeof d.consent_rules !== "object") {
1900
+ throw new Error(`Regulation [${d.id}]: missing "consent_rules" object`);
1901
+ }
1902
+ if (!d.language || typeof d.language !== "object") {
1903
+ throw new Error(`Regulation [${d.id}]: missing "language" object`);
1904
+ }
1905
+ if (!d.signals || typeof d.signals !== "object") {
1906
+ throw new Error(`Regulation [${d.id}]: missing "signals" object`);
1907
+ }
1908
+ if (!d.children || typeof d.children !== "object") {
1909
+ throw new Error(`Regulation [${d.id}]: missing "children" object`);
1910
+ }
1911
+ if (!d.audit || typeof d.audit !== "object") {
1912
+ throw new Error(`Regulation [${d.id}]: missing "audit" object`);
1913
+ }
1914
+ return data;
1915
+ }
1916
+ const id$a = "uk-gdpr-pecr";
1917
+ const name$a = "UK GDPR & PECR";
1918
+ const consent_model$a = "opt-in";
1919
+ const default_cookie_state$a = "blocked";
1920
+ const version$a = "1.0";
1921
+ const last_updated$a = "2026-03-01";
1922
+ const sources$a = [
1923
+ "https://ico.org.uk/for-organisations/guide-to-pecr/cookies-and-similar-technologies/",
1924
+ "https://ico.org.uk/for-organisations/uk-gdpr-guidance-and-resources/"
1925
+ ];
1926
+ const jurisdiction$a = {
1927
+ countries: [
1928
+ "GB"
1929
+ ],
1930
+ states: null
1931
+ };
1932
+ const banner_requirements$a = {
1933
+ require_accept_button: true,
1934
+ require_reject_button: true,
1935
+ require_equal_prominence: true,
1936
+ require_customise_button: true,
1937
+ cookie_wall_permitted: false,
1938
+ require_granular_categories: true
1939
+ };
1940
+ const consent_rules$a = {
1941
+ expiry_days: 395,
1942
+ withdrawal_mechanism: "persistent badge",
1943
+ withdrawal_ease: "as easy as giving consent",
1944
+ re_consent_on_policy_change: true
1945
+ };
1946
+ const language$a = {
1947
+ mandatory_languages: [
1948
+ "en"
1949
+ ],
1950
+ auto_detect_browser_language: false
1951
+ };
1952
+ const signals$a = {
1953
+ honour_gpc: true,
1954
+ honour_dnt: true
1955
+ };
1956
+ const children$a = {
1957
+ age_threshold: 13,
1958
+ tracking_prohibited: false,
1959
+ parental_consent_required: true
1960
+ };
1961
+ const audit$a = {
1962
+ consent_log_required: true,
1963
+ retention_years: 6,
1964
+ proof_of_consent_required: true
1965
+ };
1966
+ const ukGdprPecr = {
1967
+ id: id$a,
1968
+ name: name$a,
1969
+ consent_model: consent_model$a,
1970
+ default_cookie_state: default_cookie_state$a,
1971
+ version: version$a,
1972
+ last_updated: last_updated$a,
1973
+ sources: sources$a,
1974
+ jurisdiction: jurisdiction$a,
1975
+ banner_requirements: banner_requirements$a,
1976
+ consent_rules: consent_rules$a,
1977
+ language: language$a,
1978
+ signals: signals$a,
1979
+ children: children$a,
1980
+ audit: audit$a
1981
+ };
1982
+ const id$9 = "eu-gdpr-eprivacy";
1983
+ const name$9 = "EU GDPR & ePrivacy Directive";
1984
+ const consent_model$9 = "opt-in";
1985
+ const default_cookie_state$9 = "blocked";
1986
+ const version$9 = "1.0";
1987
+ const last_updated$9 = "2026-03-01";
1988
+ const sources$9 = [
1989
+ "https://eur-lex.europa.eu/eli/reg/2016/679/oj",
1990
+ "https://eur-lex.europa.eu/eli/dir/2002/58/oj"
1991
+ ];
1992
+ const jurisdiction$9 = {
1993
+ countries: [
1994
+ "AT",
1995
+ "BE",
1996
+ "BG",
1997
+ "HR",
1998
+ "CY",
1999
+ "CZ",
2000
+ "DK",
2001
+ "EE",
2002
+ "FI",
2003
+ "FR",
2004
+ "DE",
2005
+ "GR",
2006
+ "HU",
2007
+ "IE",
2008
+ "IT",
2009
+ "LV",
2010
+ "LT",
2011
+ "LU",
2012
+ "MT",
2013
+ "NL",
2014
+ "PL",
2015
+ "PT",
2016
+ "RO",
2017
+ "SK",
2018
+ "SI",
2019
+ "ES",
2020
+ "SE",
2021
+ "IS",
2022
+ "LI",
2023
+ "NO"
2024
+ ],
2025
+ states: null
2026
+ };
2027
+ const banner_requirements$9 = {
2028
+ require_accept_button: true,
2029
+ require_reject_button: true,
2030
+ require_equal_prominence: true,
2031
+ require_customise_button: true,
2032
+ cookie_wall_permitted: false,
2033
+ require_granular_categories: true
2034
+ };
2035
+ const consent_rules$9 = {
2036
+ expiry_days: 365,
2037
+ withdrawal_mechanism: "persistent badge",
2038
+ withdrawal_ease: "as easy as giving consent",
2039
+ re_consent_on_policy_change: true
2040
+ };
2041
+ const language$9 = {
2042
+ mandatory_languages: [
2043
+ "en"
2044
+ ],
2045
+ auto_detect_browser_language: true
2046
+ };
2047
+ const signals$9 = {
2048
+ honour_gpc: true,
2049
+ honour_dnt: true
2050
+ };
2051
+ const children$9 = {
2052
+ age_threshold: 16,
2053
+ tracking_prohibited: false,
2054
+ parental_consent_required: true
2055
+ };
2056
+ const audit$9 = {
2057
+ consent_log_required: true,
2058
+ retention_years: 5,
2059
+ proof_of_consent_required: true
2060
+ };
2061
+ const euGdprEprivacy = {
2062
+ id: id$9,
2063
+ name: name$9,
2064
+ consent_model: consent_model$9,
2065
+ default_cookie_state: default_cookie_state$9,
2066
+ version: version$9,
2067
+ last_updated: last_updated$9,
2068
+ sources: sources$9,
2069
+ jurisdiction: jurisdiction$9,
2070
+ banner_requirements: banner_requirements$9,
2071
+ consent_rules: consent_rules$9,
2072
+ language: language$9,
2073
+ signals: signals$9,
2074
+ children: children$9,
2075
+ audit: audit$9
2076
+ };
2077
+ const id$8 = "dpdp-india";
2078
+ const name$8 = "Digital Personal Data Protection Act (India)";
2079
+ const consent_model$8 = "opt-in";
2080
+ const default_cookie_state$8 = "blocked";
2081
+ const version$8 = "1.0";
2082
+ const last_updated$8 = "2026-03-01";
2083
+ const sources$8 = [
2084
+ "https://www.meity.gov.in/content/digital-personal-data-protection-act-2023"
2085
+ ];
2086
+ const jurisdiction$8 = {
2087
+ countries: [
2088
+ "IN"
2089
+ ],
2090
+ states: null
2091
+ };
2092
+ const banner_requirements$8 = {
2093
+ require_accept_button: true,
2094
+ require_reject_button: true,
2095
+ require_equal_prominence: true,
2096
+ require_customise_button: true,
2097
+ cookie_wall_permitted: false,
2098
+ require_granular_categories: true
2099
+ };
2100
+ const consent_rules$8 = {
2101
+ expiry_days: 365,
2102
+ withdrawal_mechanism: "persistent badge",
2103
+ withdrawal_ease: "as easy as giving consent",
2104
+ re_consent_on_policy_change: true
2105
+ };
2106
+ const language$8 = {
2107
+ mandatory_languages: [
2108
+ "en",
2109
+ "hi",
2110
+ "bn",
2111
+ "te",
2112
+ "mr",
2113
+ "ta",
2114
+ "ur",
2115
+ "gu",
2116
+ "kn",
2117
+ "ml",
2118
+ "or",
2119
+ "pa",
2120
+ "as",
2121
+ "mai",
2122
+ "sa",
2123
+ "ne",
2124
+ "sd",
2125
+ "kok",
2126
+ "doi",
2127
+ "mni",
2128
+ "sat",
2129
+ "ks",
2130
+ "bo"
2131
+ ],
2132
+ auto_detect_browser_language: true
2133
+ };
2134
+ const signals$8 = {
2135
+ honour_gpc: true,
2136
+ honour_dnt: true
2137
+ };
2138
+ const children$8 = {
2139
+ age_threshold: 18,
2140
+ tracking_prohibited: true,
2141
+ parental_consent_required: true
2142
+ };
2143
+ const audit$8 = {
2144
+ consent_log_required: true,
2145
+ retention_years: null,
2146
+ proof_of_consent_required: true
2147
+ };
2148
+ const dpdpIndia = {
2149
+ id: id$8,
2150
+ name: name$8,
2151
+ consent_model: consent_model$8,
2152
+ default_cookie_state: default_cookie_state$8,
2153
+ version: version$8,
2154
+ last_updated: last_updated$8,
2155
+ sources: sources$8,
2156
+ jurisdiction: jurisdiction$8,
2157
+ banner_requirements: banner_requirements$8,
2158
+ consent_rules: consent_rules$8,
2159
+ language: language$8,
2160
+ signals: signals$8,
2161
+ children: children$8,
2162
+ audit: audit$8
2163
+ };
2164
+ const id$7 = "lgpd-brazil";
2165
+ const name$7 = "Lei Geral de Proteção de Dados (Brazil)";
2166
+ const consent_model$7 = "opt-in";
2167
+ const default_cookie_state$7 = "blocked";
2168
+ const version$7 = "1.0";
2169
+ const last_updated$7 = "2026-03-01";
2170
+ const sources$7 = [
2171
+ "https://www.planalto.gov.br/ccivil_03/_ato2015-2018/2018/lei/l13709.htm"
2172
+ ];
2173
+ const jurisdiction$7 = {
2174
+ countries: [
2175
+ "BR"
2176
+ ],
2177
+ states: null
2178
+ };
2179
+ const banner_requirements$7 = {
2180
+ require_accept_button: true,
2181
+ require_reject_button: true,
2182
+ require_equal_prominence: true,
2183
+ require_customise_button: true,
2184
+ cookie_wall_permitted: false,
2185
+ require_granular_categories: true
2186
+ };
2187
+ const consent_rules$7 = {
2188
+ expiry_days: 365,
2189
+ withdrawal_mechanism: "persistent badge",
2190
+ withdrawal_ease: "as easy as giving consent",
2191
+ re_consent_on_policy_change: true
2192
+ };
2193
+ const language$7 = {
2194
+ mandatory_languages: [
2195
+ "pt"
2196
+ ],
2197
+ auto_detect_browser_language: false
2198
+ };
2199
+ const signals$7 = {
2200
+ honour_gpc: true,
2201
+ honour_dnt: true
2202
+ };
2203
+ const children$7 = {
2204
+ age_threshold: 12,
2205
+ tracking_prohibited: false,
2206
+ parental_consent_required: true
2207
+ };
2208
+ const audit$7 = {
2209
+ consent_log_required: true,
2210
+ retention_years: null,
2211
+ proof_of_consent_required: true
2212
+ };
2213
+ const lgpdBrazil = {
2214
+ id: id$7,
2215
+ name: name$7,
2216
+ consent_model: consent_model$7,
2217
+ default_cookie_state: default_cookie_state$7,
2218
+ version: version$7,
2219
+ last_updated: last_updated$7,
2220
+ sources: sources$7,
2221
+ jurisdiction: jurisdiction$7,
2222
+ banner_requirements: banner_requirements$7,
2223
+ consent_rules: consent_rules$7,
2224
+ language: language$7,
2225
+ signals: signals$7,
2226
+ children: children$7,
2227
+ audit: audit$7
2228
+ };
2229
+ const id$6 = "popia-south-africa";
2230
+ const name$6 = "Protection of Personal Information Act (South Africa)";
2231
+ const consent_model$6 = "opt-in";
2232
+ const default_cookie_state$6 = "blocked";
2233
+ const version$6 = "1.0";
2234
+ const last_updated$6 = "2026-03-01";
2235
+ const sources$6 = [
2236
+ "https://popia.co.za/"
2237
+ ];
2238
+ const jurisdiction$6 = {
2239
+ countries: [
2240
+ "ZA"
2241
+ ],
2242
+ states: null
2243
+ };
2244
+ const banner_requirements$6 = {
2245
+ require_accept_button: true,
2246
+ require_reject_button: true,
2247
+ require_equal_prominence: true,
2248
+ require_customise_button: true,
2249
+ cookie_wall_permitted: false,
2250
+ require_granular_categories: true
2251
+ };
2252
+ const consent_rules$6 = {
2253
+ expiry_days: 365,
2254
+ withdrawal_mechanism: "persistent badge",
2255
+ withdrawal_ease: "as easy as giving consent",
2256
+ re_consent_on_policy_change: true
2257
+ };
2258
+ const language$6 = {
2259
+ mandatory_languages: [
2260
+ "en"
2261
+ ],
2262
+ auto_detect_browser_language: false
2263
+ };
2264
+ const signals$6 = {
2265
+ honour_gpc: true,
2266
+ honour_dnt: true
2267
+ };
2268
+ const children$6 = {
2269
+ age_threshold: 18,
2270
+ tracking_prohibited: false,
2271
+ parental_consent_required: true
2272
+ };
2273
+ const audit$6 = {
2274
+ consent_log_required: true,
2275
+ retention_years: null,
2276
+ proof_of_consent_required: true
2277
+ };
2278
+ const popiaSouthAfrica = {
2279
+ id: id$6,
2280
+ name: name$6,
2281
+ consent_model: consent_model$6,
2282
+ default_cookie_state: default_cookie_state$6,
2283
+ version: version$6,
2284
+ last_updated: last_updated$6,
2285
+ sources: sources$6,
2286
+ jurisdiction: jurisdiction$6,
2287
+ banner_requirements: banner_requirements$6,
2288
+ consent_rules: consent_rules$6,
2289
+ language: language$6,
2290
+ signals: signals$6,
2291
+ children: children$6,
2292
+ audit: audit$6
2293
+ };
2294
+ const id$5 = "pipeda-canada";
2295
+ const name$5 = "PIPEDA & Quebec Law 25 (Canada)";
2296
+ const consent_model$5 = "opt-in";
2297
+ const default_cookie_state$5 = "blocked";
2298
+ const version$5 = "1.0";
2299
+ const last_updated$5 = "2026-03-01";
2300
+ const sources$5 = [
2301
+ "https://www.priv.gc.ca/en/privacy-topics/privacy-laws-in-canada/the-personal-information-protection-and-electronic-documents-act-pipeda/"
2302
+ ];
2303
+ const jurisdiction$5 = {
2304
+ countries: [
2305
+ "CA"
2306
+ ],
2307
+ states: null
2308
+ };
2309
+ const banner_requirements$5 = {
2310
+ require_accept_button: true,
2311
+ require_reject_button: true,
2312
+ require_equal_prominence: true,
2313
+ require_customise_button: true,
2314
+ cookie_wall_permitted: false,
2315
+ require_granular_categories: true
2316
+ };
2317
+ const consent_rules$5 = {
2318
+ expiry_days: 365,
2319
+ withdrawal_mechanism: "persistent badge",
2320
+ withdrawal_ease: "as easy as giving consent",
2321
+ re_consent_on_policy_change: true
2322
+ };
2323
+ const language$5 = {
2324
+ mandatory_languages: [
2325
+ "en",
2326
+ "fr"
2327
+ ],
2328
+ auto_detect_browser_language: true
2329
+ };
2330
+ const signals$5 = {
2331
+ honour_gpc: true,
2332
+ honour_dnt: true
2333
+ };
2334
+ const children$5 = {
2335
+ age_threshold: 13,
2336
+ tracking_prohibited: false,
2337
+ parental_consent_required: true
2338
+ };
2339
+ const audit$5 = {
2340
+ consent_log_required: true,
2341
+ retention_years: null,
2342
+ proof_of_consent_required: true
2343
+ };
2344
+ const pipedaCanada = {
2345
+ id: id$5,
2346
+ name: name$5,
2347
+ consent_model: consent_model$5,
2348
+ default_cookie_state: default_cookie_state$5,
2349
+ version: version$5,
2350
+ last_updated: last_updated$5,
2351
+ sources: sources$5,
2352
+ jurisdiction: jurisdiction$5,
2353
+ banner_requirements: banner_requirements$5,
2354
+ consent_rules: consent_rules$5,
2355
+ language: language$5,
2356
+ signals: signals$5,
2357
+ children: children$5,
2358
+ audit: audit$5
2359
+ };
2360
+ const id$4 = "pdpa-singapore";
2361
+ const name$4 = "Personal Data Protection Act (Singapore)";
2362
+ const consent_model$4 = "opt-in";
2363
+ const default_cookie_state$4 = "blocked";
2364
+ const version$4 = "1.0";
2365
+ const last_updated$4 = "2026-03-01";
2366
+ const sources$4 = [
2367
+ "https://www.pdpc.gov.sg/overview-of-pdpa/the-legislation/personal-data-protection-act"
2368
+ ];
2369
+ const jurisdiction$4 = {
2370
+ countries: [
2371
+ "SG"
2372
+ ],
2373
+ states: null
2374
+ };
2375
+ const banner_requirements$4 = {
2376
+ require_accept_button: true,
2377
+ require_reject_button: true,
2378
+ require_equal_prominence: false,
2379
+ require_customise_button: false,
2380
+ cookie_wall_permitted: false,
2381
+ require_granular_categories: false
2382
+ };
2383
+ const consent_rules$4 = {
2384
+ expiry_days: 365,
2385
+ withdrawal_mechanism: "persistent badge",
2386
+ withdrawal_ease: "reasonable effort",
2387
+ re_consent_on_policy_change: true
2388
+ };
2389
+ const language$4 = {
2390
+ mandatory_languages: [
2391
+ "en"
2392
+ ],
2393
+ auto_detect_browser_language: false
2394
+ };
2395
+ const signals$4 = {
2396
+ honour_gpc: true,
2397
+ honour_dnt: true
2398
+ };
2399
+ const children$4 = {
2400
+ age_threshold: 13,
2401
+ tracking_prohibited: false,
2402
+ parental_consent_required: true
2403
+ };
2404
+ const audit$4 = {
2405
+ consent_log_required: true,
2406
+ retention_years: null,
2407
+ proof_of_consent_required: false
2408
+ };
2409
+ const pdpaSingapore = {
2410
+ id: id$4,
2411
+ name: name$4,
2412
+ consent_model: consent_model$4,
2413
+ default_cookie_state: default_cookie_state$4,
2414
+ version: version$4,
2415
+ last_updated: last_updated$4,
2416
+ sources: sources$4,
2417
+ jurisdiction: jurisdiction$4,
2418
+ banner_requirements: banner_requirements$4,
2419
+ consent_rules: consent_rules$4,
2420
+ language: language$4,
2421
+ signals: signals$4,
2422
+ children: children$4,
2423
+ audit: audit$4
2424
+ };
2425
+ const id$3 = "pdpa-thailand";
2426
+ const name$3 = "Personal Data Protection Act (Thailand)";
2427
+ const consent_model$3 = "opt-in";
2428
+ const default_cookie_state$3 = "blocked";
2429
+ const version$3 = "1.0";
2430
+ const last_updated$3 = "2026-03-01";
2431
+ const sources$3 = [
2432
+ "https://thaipdpa.com/"
2433
+ ];
2434
+ const jurisdiction$3 = {
2435
+ countries: [
2436
+ "TH"
2437
+ ],
2438
+ states: null
2439
+ };
2440
+ const banner_requirements$3 = {
2441
+ require_accept_button: true,
2442
+ require_reject_button: true,
2443
+ require_equal_prominence: true,
2444
+ require_customise_button: true,
2445
+ cookie_wall_permitted: false,
2446
+ require_granular_categories: true
2447
+ };
2448
+ const consent_rules$3 = {
2449
+ expiry_days: 365,
2450
+ withdrawal_mechanism: "persistent badge",
2451
+ withdrawal_ease: "as easy as giving consent",
2452
+ re_consent_on_policy_change: true
2453
+ };
2454
+ const language$3 = {
2455
+ mandatory_languages: [
2456
+ "th",
2457
+ "en"
2458
+ ],
2459
+ auto_detect_browser_language: true
2460
+ };
2461
+ const signals$3 = {
2462
+ honour_gpc: true,
2463
+ honour_dnt: true
2464
+ };
2465
+ const children$3 = {
2466
+ age_threshold: 10,
2467
+ tracking_prohibited: false,
2468
+ parental_consent_required: true
2469
+ };
2470
+ const audit$3 = {
2471
+ consent_log_required: true,
2472
+ retention_years: null,
2473
+ proof_of_consent_required: true
2474
+ };
2475
+ const pdpaThailand = {
2476
+ id: id$3,
2477
+ name: name$3,
2478
+ consent_model: consent_model$3,
2479
+ default_cookie_state: default_cookie_state$3,
2480
+ version: version$3,
2481
+ last_updated: last_updated$3,
2482
+ sources: sources$3,
2483
+ jurisdiction: jurisdiction$3,
2484
+ banner_requirements: banner_requirements$3,
2485
+ consent_rules: consent_rules$3,
2486
+ language: language$3,
2487
+ signals: signals$3,
2488
+ children: children$3,
2489
+ audit: audit$3
2490
+ };
2491
+ const id$2 = "ccpa-cpra";
2492
+ const name$2 = "CCPA / CPRA (California)";
2493
+ const consent_model$2 = "opt-out";
2494
+ const default_cookie_state$2 = "allowed";
2495
+ const version$2 = "1.0";
2496
+ const last_updated$2 = "2026-03-01";
2497
+ const sources$2 = [
2498
+ "https://oag.ca.gov/privacy/ccpa",
2499
+ "https://cppa.ca.gov/"
2500
+ ];
2501
+ const jurisdiction$2 = {
2502
+ countries: [
2503
+ "US"
2504
+ ],
2505
+ states: [
2506
+ "CA"
2507
+ ]
2508
+ };
2509
+ const banner_requirements$2 = {
2510
+ require_accept_button: false,
2511
+ require_reject_button: true,
2512
+ require_equal_prominence: false,
2513
+ require_customise_button: true,
2514
+ cookie_wall_permitted: false,
2515
+ require_granular_categories: true
2516
+ };
2517
+ const consent_rules$2 = {
2518
+ expiry_days: 365,
2519
+ withdrawal_mechanism: "do not sell link",
2520
+ withdrawal_ease: "clear and conspicuous link",
2521
+ re_consent_on_policy_change: false
2522
+ };
2523
+ const language$2 = {
2524
+ mandatory_languages: [
2525
+ "en"
2526
+ ],
2527
+ auto_detect_browser_language: false
2528
+ };
2529
+ const signals$2 = {
2530
+ honour_gpc: true,
2531
+ honour_dnt: true
2532
+ };
2533
+ const children$2 = {
2534
+ age_threshold: 16,
2535
+ tracking_prohibited: false,
2536
+ parental_consent_required: true
2537
+ };
2538
+ const audit$2 = {
2539
+ consent_log_required: true,
2540
+ retention_years: 2,
2541
+ proof_of_consent_required: false
2542
+ };
2543
+ const ccpaCpra = {
2544
+ id: id$2,
2545
+ name: name$2,
2546
+ consent_model: consent_model$2,
2547
+ default_cookie_state: default_cookie_state$2,
2548
+ version: version$2,
2549
+ last_updated: last_updated$2,
2550
+ sources: sources$2,
2551
+ jurisdiction: jurisdiction$2,
2552
+ banner_requirements: banner_requirements$2,
2553
+ consent_rules: consent_rules$2,
2554
+ language: language$2,
2555
+ signals: signals$2,
2556
+ children: children$2,
2557
+ audit: audit$2
2558
+ };
2559
+ const id$1 = "us-state-general";
2560
+ const name$1 = "US State Privacy Laws (General)";
2561
+ const consent_model$1 = "opt-out";
2562
+ const default_cookie_state$1 = "allowed";
2563
+ const version$1 = "1.0";
2564
+ const last_updated$1 = "2026-03-01";
2565
+ const sources$1 = [
2566
+ "https://iapp.org/resources/article/us-state-privacy-legislation-tracker/"
2567
+ ];
2568
+ const jurisdiction$1 = {
2569
+ countries: [
2570
+ "US"
2571
+ ],
2572
+ states: [
2573
+ "CO",
2574
+ "CT",
2575
+ "VA",
2576
+ "UT",
2577
+ "TX",
2578
+ "OR",
2579
+ "MT",
2580
+ "DE",
2581
+ "IA",
2582
+ "NH",
2583
+ "NJ",
2584
+ "TN",
2585
+ "IN",
2586
+ "KY",
2587
+ "NE",
2588
+ "MD",
2589
+ "MN"
2590
+ ]
2591
+ };
2592
+ const banner_requirements$1 = {
2593
+ require_accept_button: false,
2594
+ require_reject_button: true,
2595
+ require_equal_prominence: false,
2596
+ require_customise_button: true,
2597
+ cookie_wall_permitted: false,
2598
+ require_granular_categories: false
2599
+ };
2600
+ const consent_rules$1 = {
2601
+ expiry_days: 365,
2602
+ withdrawal_mechanism: "opt-out link",
2603
+ withdrawal_ease: "clear mechanism",
2604
+ re_consent_on_policy_change: false
2605
+ };
2606
+ const language$1 = {
2607
+ mandatory_languages: [
2608
+ "en"
2609
+ ],
2610
+ auto_detect_browser_language: false
2611
+ };
2612
+ const signals$1 = {
2613
+ honour_gpc: true,
2614
+ honour_dnt: true
2615
+ };
2616
+ const children$1 = {
2617
+ age_threshold: 13,
2618
+ tracking_prohibited: false,
2619
+ parental_consent_required: true
2620
+ };
2621
+ const audit$1 = {
2622
+ consent_log_required: false,
2623
+ retention_years: null,
2624
+ proof_of_consent_required: false
2625
+ };
2626
+ const usStateGeneral = {
2627
+ id: id$1,
2628
+ name: name$1,
2629
+ consent_model: consent_model$1,
2630
+ default_cookie_state: default_cookie_state$1,
2631
+ version: version$1,
2632
+ last_updated: last_updated$1,
2633
+ sources: sources$1,
2634
+ jurisdiction: jurisdiction$1,
2635
+ banner_requirements: banner_requirements$1,
2636
+ consent_rules: consent_rules$1,
2637
+ language: language$1,
2638
+ signals: signals$1,
2639
+ children: children$1,
2640
+ audit: audit$1
2641
+ };
2642
+ const id = "default-global";
2643
+ const name = "Default Global (GDPR-equivalent)";
2644
+ const consent_model = "opt-in";
2645
+ const default_cookie_state = "blocked";
2646
+ const version = "1.0";
2647
+ const last_updated = "2026-03-01";
2648
+ const sources = [];
2649
+ const jurisdiction = {
2650
+ countries: [],
2651
+ states: null
2652
+ };
2653
+ const banner_requirements = {
2654
+ require_accept_button: true,
2655
+ require_reject_button: true,
2656
+ require_equal_prominence: true,
2657
+ require_customise_button: true,
2658
+ cookie_wall_permitted: false,
2659
+ require_granular_categories: true
2660
+ };
2661
+ const consent_rules = {
2662
+ expiry_days: 365,
2663
+ withdrawal_mechanism: "persistent badge",
2664
+ withdrawal_ease: "as easy as giving consent",
2665
+ re_consent_on_policy_change: true
2666
+ };
2667
+ const language = {
2668
+ mandatory_languages: [
2669
+ "en"
2670
+ ],
2671
+ auto_detect_browser_language: true
2672
+ };
2673
+ const signals = {
2674
+ honour_gpc: true,
2675
+ honour_dnt: true
2676
+ };
2677
+ const children = {
2678
+ age_threshold: 16,
2679
+ tracking_prohibited: false,
2680
+ parental_consent_required: true
2681
+ };
2682
+ const audit = {
2683
+ consent_log_required: true,
2684
+ retention_years: null,
2685
+ proof_of_consent_required: true
2686
+ };
2687
+ const defaultGlobal = {
2688
+ id,
2689
+ name,
2690
+ consent_model,
2691
+ default_cookie_state,
2692
+ version,
2693
+ last_updated,
2694
+ sources,
2695
+ jurisdiction,
2696
+ banner_requirements,
2697
+ consent_rules,
2698
+ language,
2699
+ signals,
2700
+ children,
2701
+ audit
2702
+ };
2703
+ const RAW_REGULATIONS = [
2704
+ ukGdprPecr,
2705
+ euGdprEprivacy,
2706
+ dpdpIndia,
2707
+ lgpdBrazil,
2708
+ popiaSouthAfrica,
2709
+ pipedaCanada,
2710
+ pdpaSingapore,
2711
+ pdpaThailand,
2712
+ ccpaCpra,
2713
+ usStateGeneral,
2714
+ defaultGlobal
2715
+ ];
2716
+ function loadRegulations() {
2717
+ const validated = [];
2718
+ for (const raw of RAW_REGULATIONS) {
2719
+ try {
2720
+ validated.push(validateRegulation(raw));
2721
+ } catch (e) {
2722
+ console.warn(
2723
+ "SmartConsent: Skipping invalid regulation file.",
2724
+ e instanceof Error ? e.message : e
2725
+ );
2726
+ }
2727
+ }
2728
+ return validated;
2729
+ }
2730
+ function resolveRegulations(geo, regulations) {
2731
+ let matched = regulations.filter((reg) => {
2732
+ if (reg.jurisdiction.countries.length === 0) return false;
2733
+ const countryMatch = reg.jurisdiction.countries.includes(geo.country);
2734
+ if (!countryMatch) return false;
2735
+ if (reg.jurisdiction.states && reg.jurisdiction.states.length > 0 && geo.state) {
2736
+ return reg.jurisdiction.states.includes(geo.state);
2737
+ }
2738
+ if (reg.jurisdiction.states && reg.jurisdiction.states.length > 0 && !geo.state) {
2739
+ return false;
2740
+ }
2741
+ return true;
2742
+ });
2743
+ if (matched.length === 0) {
2744
+ const fallback = regulations.find((r) => r.id === "default-global");
2745
+ if (fallback) {
2746
+ matched = [fallback];
2747
+ }
2748
+ }
2749
+ return mergeRegulations(matched);
2750
+ }
2751
+ function mergeRegulations(regulations) {
2752
+ let mode = "opt-out";
2753
+ let acceptAll = false;
2754
+ let rejectAll = false;
2755
+ let customise = false;
2756
+ let equalProminence = false;
2757
+ let cookieWall = true;
2758
+ let expiryDays = Infinity;
2759
+ let gpcAutoReject = false;
2760
+ let withdrawalMechanism = "opt-out link";
2761
+ let reConsentOnVersionChange = false;
2762
+ const applicableRegulations = [];
2763
+ const regulationIds = [];
2764
+ for (const reg of regulations) {
2765
+ applicableRegulations.push(reg.name);
2766
+ regulationIds.push(reg.id);
2767
+ if (reg.consent_model === "opt-in") mode = "opt-in";
2768
+ if (reg.banner_requirements.require_accept_button) acceptAll = true;
2769
+ if (reg.banner_requirements.require_reject_button) rejectAll = true;
2770
+ if (reg.banner_requirements.require_customise_button) customise = true;
2771
+ if (reg.banner_requirements.require_equal_prominence) equalProminence = true;
2772
+ if (!reg.banner_requirements.cookie_wall_permitted) cookieWall = false;
2773
+ if (reg.consent_rules.expiry_days < expiryDays) {
2774
+ expiryDays = reg.consent_rules.expiry_days;
2775
+ }
2776
+ if (reg.signals.honour_gpc) gpcAutoReject = true;
2777
+ if (reg.consent_rules.withdrawal_mechanism === "persistent badge") {
2778
+ withdrawalMechanism = "persistent badge";
2779
+ }
2780
+ if (reg.consent_rules.re_consent_on_policy_change) reConsentOnVersionChange = true;
2781
+ }
2782
+ if (expiryDays === Infinity) expiryDays = 365;
2783
+ const categories = [...DEFAULT_CATEGORIES];
2784
+ return {
2785
+ mode,
2786
+ buttons: {
2787
+ accept_all: acceptAll,
2788
+ reject_all: rejectAll,
2789
+ customise,
2790
+ equal_prominence: equalProminence
2791
+ },
2792
+ categories,
2793
+ blocking: {
2794
+ mode: "block-first",
2795
+ unknown_scripts: mode === "opt-in" ? "blocked" : "allowed"
2796
+ },
2797
+ consent: {
2798
+ expiry_days: expiryDays,
2799
+ withdrawal_mechanism: withdrawalMechanism,
2800
+ re_consent_on_version_change: reConsentOnVersionChange
2801
+ },
2802
+ signals: {
2803
+ gpc_auto_reject: gpcAutoReject
2804
+ },
2805
+ cookie_wall: cookieWall,
2806
+ language: "en",
2807
+ applicable_regulations: applicableRegulations,
2808
+ regulation_ids: regulationIds
2809
+ };
2810
+ }
2811
+ const zones = {
2812
+ "Africa/Ceuta": "ES",
2813
+ "Africa/Johannesburg": "ZA",
2814
+ "America/Araguaina": "BR",
2815
+ "America/Atikokan": "CA",
2816
+ "America/Bahia": "BR",
2817
+ "America/Belem": "BR",
2818
+ "America/Blanc-Sablon": "CA",
2819
+ "America/Boa_Vista": "BR",
2820
+ "America/Boise": "US-VA",
2821
+ "America/Cambridge_Bay": "CA",
2822
+ "America/Campo_Grande": "BR",
2823
+ "America/Chicago": "US-VA",
2824
+ "America/Coral_Harbour": "CA",
2825
+ "America/Creston": "CA",
2826
+ "America/Cuiaba": "BR",
2827
+ "America/Dawson": "CA",
2828
+ "America/Dawson_Creek": "CA",
2829
+ "America/Denver": "US-VA",
2830
+ "America/Detroit": "US-VA",
2831
+ "America/Edmonton": "CA",
2832
+ "America/Eirunepe": "BR",
2833
+ "America/Fort_Nelson": "CA",
2834
+ "America/Fortaleza": "BR",
2835
+ "America/Glace_Bay": "CA",
2836
+ "America/Goose_Bay": "CA",
2837
+ "America/Halifax": "CA",
2838
+ "America/Indiana/Indianapolis": "US-VA",
2839
+ "America/Indianapolis": "US-VA",
2840
+ "America/Inuvik": "CA",
2841
+ "America/Iqaluit": "CA",
2842
+ "America/Kentucky/Louisville": "US-VA",
2843
+ "America/Los_Angeles": "US-CA",
2844
+ "America/Louisville": "US-VA",
2845
+ "America/Maceio": "BR",
2846
+ "America/Manaus": "BR",
2847
+ "America/Moncton": "CA",
2848
+ "America/New_York": "US-VA",
2849
+ "America/Noronha": "BR",
2850
+ "America/Porto_Velho": "BR",
2851
+ "America/Rankin_Inlet": "CA",
2852
+ "America/Recife": "BR",
2853
+ "America/Regina": "CA",
2854
+ "America/Rio_Branco": "BR",
2855
+ "America/Santarem": "BR",
2856
+ "America/Sao_Paulo": "BR",
2857
+ "America/St_Johns": "CA",
2858
+ "America/Swift_Current": "CA",
2859
+ "America/Toronto": "CA",
2860
+ "America/Vancouver": "CA",
2861
+ "America/Whitehorse": "CA",
2862
+ "America/Winnipeg": "CA",
2863
+ "America/Yellowknife": "CA",
2864
+ "Asia/Bangkok": "TH",
2865
+ "Asia/Calcutta": "IN",
2866
+ "Asia/Kolkata": "IN",
2867
+ "Asia/Nicosia": "CY",
2868
+ "Asia/Singapore": "SG",
2869
+ "Atlantic/Azores": "PT",
2870
+ "Atlantic/Canary": "ES",
2871
+ "Atlantic/Madeira": "PT",
2872
+ "Atlantic/Reykjavik": "IS",
2873
+ "Europe/Amsterdam": "NL",
2874
+ "Europe/Athens": "GR",
2875
+ "Europe/Belfast": "GB",
2876
+ "Europe/Berlin": "DE",
2877
+ "Europe/Bratislava": "SK",
2878
+ "Europe/Brussels": "BE",
2879
+ "Europe/Bucharest": "RO",
2880
+ "Europe/Budapest": "HU",
2881
+ "Europe/Busingen": "DE",
2882
+ "Europe/Copenhagen": "DK",
2883
+ "Europe/Dublin": "IE",
2884
+ "Europe/Helsinki": "FI",
2885
+ "Europe/Lisbon": "PT",
2886
+ "Europe/Ljubljana": "SI",
2887
+ "Europe/London": "GB",
2888
+ "Europe/Luxembourg": "LU",
2889
+ "Europe/Madrid": "ES",
2890
+ "Europe/Malta": "MT",
2891
+ "Europe/Nicosia": "CY",
2892
+ "Europe/Oslo": "NO",
2893
+ "Europe/Paris": "FR",
2894
+ "Europe/Prague": "CZ",
2895
+ "Europe/Riga": "LV",
2896
+ "Europe/Rome": "IT",
2897
+ "Europe/Sofia": "BG",
2898
+ "Europe/Stockholm": "SE",
2899
+ "Europe/Tallinn": "EE",
2900
+ "Europe/Vaduz": "LI",
2901
+ "Europe/Vienna": "AT",
2902
+ "Europe/Vilnius": "LT",
2903
+ "Europe/Warsaw": "PL",
2904
+ "Europe/Zagreb": "HR"
2905
+ };
2906
+ const shared = {
2907
+ "Europe/London": [
2908
+ "JE",
2909
+ "GG",
2910
+ "IM"
2911
+ ],
2912
+ "Europe/Paris": [
2913
+ "MC"
2914
+ ],
2915
+ "Europe/Rome": [
2916
+ "SM",
2917
+ "VA"
2918
+ ],
2919
+ "Asia/Bangkok": [
2920
+ "KH",
2921
+ "LA",
2922
+ "VN"
2923
+ ]
2924
+ };
2925
+ const timezoneData = {
2926
+ zones,
2927
+ shared
2928
+ };
2929
+ const CACHE_KEY = "smartconsent_geo";
2930
+ const CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
2931
+ const UNKNOWN_COUNTRY = "ZZ";
2932
+ const ZONES = timezoneData.zones;
2933
+ const SHARED = timezoneData.shared;
2934
+ function readCache() {
2935
+ try {
2936
+ const raw = sessionStorage.getItem(CACHE_KEY);
2937
+ if (!raw) return null;
2938
+ const cached = JSON.parse(raw);
2939
+ if (Date.now() - cached.timestamp > CACHE_TTL_MS) return null;
2940
+ return { country: cached.country, state: cached.state, source: "cache" };
2941
+ } catch {
2942
+ return null;
2943
+ }
2944
+ }
2945
+ function writeCache(country, state) {
2946
+ try {
2947
+ const entry = { country, state, timestamp: Date.now() };
2948
+ sessionStorage.setItem(CACHE_KEY, JSON.stringify(entry));
2949
+ } catch {
2950
+ }
2951
+ }
2952
+ function readZone() {
2953
+ try {
2954
+ return new Intl.DateTimeFormat().resolvedOptions().timeZone || null;
2955
+ } catch {
2956
+ return null;
2957
+ }
2958
+ }
2959
+ function languageRegion() {
2960
+ try {
2961
+ const m = /^[A-Za-z]{2,3}-(?:[A-Za-z]{4}-)?([A-Za-z]{2})\b/.exec(navigator.language || "");
2962
+ return m ? m[1].toUpperCase() : "";
2963
+ } catch {
2964
+ return "";
2965
+ }
2966
+ }
2967
+ async function detectGeo() {
2968
+ var _a;
2969
+ const cached = readCache();
2970
+ if (cached) return cached;
2971
+ const zone = readZone();
2972
+ if (!zone) return { country: UNKNOWN_COUNTRY, source: "fallback" };
2973
+ const code = ZONES[zone];
2974
+ if (!code) return { country: UNKNOWN_COUNTRY, source: "timezone" };
2975
+ if ((_a = SHARED[zone]) == null ? void 0 : _a.includes(languageRegion())) return { country: UNKNOWN_COUNTRY, source: "timezone" };
2976
+ const [country, state] = code.split("-");
2977
+ writeCache(country, state);
2978
+ return { country, state, source: "timezone" };
2979
+ }
2980
+ const registry = {};
2981
+ function registerLanguage(data) {
2982
+ registry[data.lang] = data;
2983
+ }
2984
+ function expandLanguage(code) {
2985
+ return registry[code] ?? registry[code.split("-")[0]] ?? null;
2986
+ }
2987
+ function hasLanguage(code) {
2988
+ const base = code.split("-")[0];
2989
+ return base === "en" || base in registry;
2990
+ }
2991
+ function getEnglish() {
2992
+ const categories = {};
2993
+ for (const cat of DEFAULT_CATEGORIES) {
2994
+ categories[cat.id] = { label: cat.label, description: cat.description };
2995
+ }
2996
+ return { lang: "en", dir: "ltr", texts: { ...DEFAULT_TEXTS }, categories };
2997
+ }
2998
+ function getLanguage(code) {
2999
+ const base = code.split("-")[0];
3000
+ if (base === "en") return getEnglish();
3001
+ return expandLanguage(code);
3002
+ }
3003
+ function detectLanguage(configOverride) {
3004
+ if (configOverride) {
3005
+ const base2 = configOverride.split("-")[0];
3006
+ if (base2 === "en" || hasLanguage(configOverride)) return base2;
3007
+ }
3008
+ const browser = typeof navigator !== "undefined" && navigator.language || "en";
3009
+ const base = browser.split("-")[0];
3010
+ if (base === "en" || hasLanguage(base)) return base;
3011
+ return "en";
3012
+ }
3013
+ const PACK_CODES = [
3014
+ "ar",
3015
+ "cs",
3016
+ "da",
3017
+ "de",
3018
+ "es",
3019
+ "fr",
3020
+ "hi",
3021
+ "it",
3022
+ "ja",
3023
+ "ko",
3024
+ "nl",
3025
+ "no",
3026
+ "pl",
3027
+ "pt",
3028
+ "ro",
3029
+ "ru",
3030
+ "sv",
3031
+ "tr",
3032
+ "zh"
3033
+ ];
3034
+ const TIMEOUT_MS$2 = 1500;
3035
+ const CACHE_PREFIX$1 = "smartconsent_lang_";
3036
+ const baseCode = (c) => typeof c === "string" ? c.split("-")[0].toLowerCase() : "";
3037
+ const isPack = (c) => PACK_CODES.includes(c);
3038
+ const usable = (c) => c === "en" || isPack(c);
3039
+ function packsBase() {
3040
+ const src = document.currentScript && document.currentScript.src;
3041
+ if (src && /^https?:\/\//.test(src)) {
3042
+ const path = src.split(/[?#]/)[0];
3043
+ return path.slice(0, path.lastIndexOf("/") + 1);
3044
+ }
3045
+ return DEFAULT_PACKS_BASE;
3046
+ }
3047
+ function pickSiteLanguage(input) {
3048
+ const b = input.settings.banner;
3049
+ const own = baseCode(b == null ? void 0 : b.language);
3050
+ const chain = () => {
3051
+ for (const c of [own, baseCode(input.pageLanguage), baseCode(input.htmlLang)]) if (usable(c)) return c;
3052
+ return "en";
3053
+ };
3054
+ const browser = baseCode(input.browserLang);
3055
+ if (Array.isArray(b == null ? void 0 : b.languages)) {
3056
+ const offered = [own, ...b.languages.map(baseCode)].filter(usable);
3057
+ return offered.includes(browser) ? browser : chain();
3058
+ }
3059
+ return isPack(browser) ? browser : chain();
3060
+ }
3061
+ const isStr = (v) => typeof v === "string";
3062
+ const REQUIRED_TEXTS = ["heading", "description", "acceptAll", "rejectOptional", "managePreferences", "essentialOnly", "savePreferences", "poweredBy"];
3063
+ function checkPack(code, v) {
3064
+ const p = v;
3065
+ if (!p || typeof p !== "object" || p.lang !== code || p.dir !== "ltr" && p.dir !== "rtl") return null;
3066
+ const rawTexts = p.texts;
3067
+ const rawCats = p.categories;
3068
+ if (!rawTexts || typeof rawTexts !== "object" || Array.isArray(rawTexts)) return null;
3069
+ if (!rawCats || typeof rawCats !== "object" || Array.isArray(rawCats)) return null;
3070
+ const texts = {};
3071
+ for (const k of REQUIRED_TEXTS) {
3072
+ if (!isStr(rawTexts[k])) return null;
3073
+ texts[k] = rawTexts[k];
3074
+ }
3075
+ for (const k of ["doNotSell", "cookieSettings", "embedNotice", "embedLoad", "dataRequest"]) if (isStr(rawTexts[k])) texts[k] = rawTexts[k];
3076
+ const categories = {};
3077
+ for (const { id: id2 } of DEFAULT_CATEGORIES) {
3078
+ const c = rawCats[id2];
3079
+ if (!c || !isStr(c.label) || !isStr(c.description)) return null;
3080
+ categories[id2] = { label: c.label, description: c.description };
3081
+ }
3082
+ return { lang: code, dir: p.dir, texts, categories };
3083
+ }
3084
+ async function loadPack(code, base) {
3085
+ const url = `${base}lang/${code}.json`;
3086
+ const key = CACHE_PREFIX$1 + url;
3087
+ try {
3088
+ const cached = checkPack(code, JSON.parse(sessionStorage.getItem(key) || "null"));
3089
+ if (cached) {
3090
+ registerLanguage(cached);
3091
+ return true;
3092
+ }
3093
+ } catch {
3094
+ }
3095
+ const controller = new AbortController();
3096
+ let timer;
3097
+ const timeout = new Promise((resolve) => {
3098
+ timer = setTimeout(() => {
3099
+ controller.abort();
3100
+ resolve(null);
3101
+ }, TIMEOUT_MS$2);
3102
+ });
3103
+ const download = (async () => {
3104
+ try {
3105
+ const res = await fetch(url, { signal: controller.signal, credentials: "omit" });
3106
+ if (!res.ok) return null;
3107
+ const pack = checkPack(code, await res.json());
3108
+ if (pack) {
3109
+ try {
3110
+ sessionStorage.setItem(key, JSON.stringify(pack));
3111
+ } catch {
3112
+ }
3113
+ }
3114
+ return pack;
3115
+ } catch {
3116
+ return null;
3117
+ }
3118
+ })();
3119
+ try {
3120
+ const pack = await Promise.race([download, timeout]);
3121
+ if (!pack) return false;
3122
+ registerLanguage(pack);
3123
+ return true;
3124
+ } finally {
3125
+ clearTimeout(timer);
3126
+ }
3127
+ }
3128
+ const scanned = /* @__PURE__ */ new WeakSet();
3129
+ function markScanned(c) {
3130
+ scanned.add(c);
3131
+ return c;
3132
+ }
3133
+ function buildCookieTableHTML(config) {
3134
+ const cookies = config.cookies;
3135
+ if (cookies.length === 0) {
3136
+ return '<p class="sc-table-empty">No cookies declared.</p>';
3137
+ }
3138
+ const grouped = groupByCategory(cookies, config);
3139
+ let html = '<div class="sc-cookie-table-wrap">';
3140
+ for (const [categoryLabel, entries] of grouped) {
3141
+ html += `<h3 class="sc-table-category">${esc$1(categoryLabel)}</h3>`;
3142
+ html += '<table class="sc-cookie-table"><thead><tr>';
3143
+ html += '<th scope="col">Cookie</th>';
3144
+ html += '<th scope="col">Duration</th>';
3145
+ html += '<th scope="col">Description</th>';
3146
+ html += '<th scope="col">Type</th>';
3147
+ html += "</tr></thead><tbody>";
3148
+ for (const c of entries) {
3149
+ html += "<tr>";
3150
+ html += `<td>${esc$1(c.name)}${c.domain ? ` <small>(${esc$1(c.domain)})</small>` : ""}</td>`;
3151
+ const found = scanned.has(c);
3152
+ html += `<td>${esc$1(c.duration ?? (found ? "" : "Session"))}</td>`;
3153
+ html += `<td>${esc$1(c.description ?? "")}</td>`;
3154
+ html += `<td>${esc$1(c.party === "third" ? "Third party" : c.party || !found ? "First party" : "")}</td>`;
3155
+ html += "</tr>";
3156
+ }
3157
+ html += "</tbody></table>";
3158
+ }
3159
+ html += "</div>";
3160
+ return html;
3161
+ }
3162
+ function renderCookieTable(selector, config) {
3163
+ const target = document.querySelector(selector);
3164
+ if (!target) {
3165
+ console.warn(`SmartConsent: Cookie table target "${selector}" not found.`);
3166
+ return;
3167
+ }
3168
+ target.innerHTML = buildCookieTableHTML(config);
3169
+ }
3170
+ function groupByCategory(cookies, config) {
3171
+ const catMap = /* @__PURE__ */ new Map();
3172
+ for (const c of cookies) {
3173
+ const key = c.category;
3174
+ if (!catMap.has(key)) catMap.set(key, []);
3175
+ catMap.get(key).push(c);
3176
+ }
3177
+ const labelMap = {};
3178
+ for (const cat of config.categories) {
3179
+ labelMap[cat.id] = cat.label;
3180
+ }
3181
+ const result = [];
3182
+ for (const [key, entries] of catMap) {
3183
+ result.push([labelMap[key] ?? key, entries]);
3184
+ }
3185
+ return result;
3186
+ }
3187
+ function esc$1(str) {
3188
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
3189
+ }
3190
+ function generateCookiePolicy(config, options) {
3191
+ const { siteName, siteUrl, contactEmail } = options;
3192
+ const date = (/* @__PURE__ */ new Date()).toLocaleDateString("en-GB", { day: "numeric", month: "long", year: "numeric" });
3193
+ const categoryDescriptions = config.categories.map((c) => `<li><strong>${esc(c.label)}</strong>: ${esc(c.description)}</li>`).join("\n");
3194
+ const cookieTable = config.cookies.length > 0 ? buildCookieTableHTML(config) : "<p>No specific cookies have been declared for this site.</p>";
3195
+ const creditWords = esc(creditText(config, "policyCredit"));
3196
+ const creditHref2 = safeHttpUrl(config.attributionUrl);
3197
+ const credit = config.attribution ? `
3198
+ <p class="sc-policy-credit">${creditHref2 ? `<a href="${esc(creditHref2)}">${creditWords}</a>` : creditWords}</p>` : "";
3199
+ const site = esc(siteUrl);
3200
+ const siteLink = safeHttpUrl(siteUrl) ? `<a href="${site}">${site}</a>` : site;
3201
+ return `<div class="sc-cookie-policy">
3202
+ <h1>Cookie Policy</h1>
3203
+ <p><em>Last updated: ${date}</em></p>
3204
+
3205
+ <h2>What are cookies?</h2>
3206
+ <p>Cookies are small text files placed on your device when you visit a website. They are widely used to make websites work efficiently and to provide information to site owners.</p>
3207
+
3208
+ <h2>How ${esc(siteName)} uses cookies</h2>
3209
+ <p>We use cookies on ${siteLink} for the following purposes:</p>
3210
+ <ul>
3211
+ ${categoryDescriptions}
3212
+ </ul>
3213
+
3214
+ <h2>Cookies we use</h2>
3215
+ ${cookieTable}
3216
+
3217
+ <h2>Managing your preferences</h2>
3218
+ <p>You can change your cookie preferences at any time by clicking the cookie settings icon on our website, or by clearing cookies in your browser settings.</p>
3219
+
3220
+ <h2>Contact</h2>
3221
+ <p>If you have questions about our use of cookies, please contact us at <a href="mailto:${esc(contactEmail)}">${esc(contactEmail)}</a>.</p>
3222
+
3223
+ <hr>
3224
+ <p class="sc-policy-disclaimer"><strong>Disclaimer:</strong> This cookie policy is a template generated by SmartConsent. It is not legal advice. Please consult a legal professional to ensure compliance with applicable regulations.</p>${credit}
3225
+ </div>`;
3226
+ }
3227
+ function renderCookiePolicy(selector, config, options) {
3228
+ const target = document.querySelector(selector);
3229
+ if (!target) {
3230
+ console.warn(`SmartConsent: Cookie policy target "${selector}" not found.`);
3231
+ return;
3232
+ }
3233
+ target.innerHTML = generateCookiePolicy(config, options);
3234
+ }
3235
+ function esc(str) {
3236
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
3237
+ }
3238
+ function computeConsentStats(log) {
3239
+ if (log.length === 0) {
3240
+ return {
3241
+ totalActions: 0,
3242
+ acceptAllRate: 0,
3243
+ rejectAllRate: 0,
3244
+ customRate: 0,
3245
+ categoryBreakdown: {},
3246
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
3247
+ };
3248
+ }
3249
+ let acceptCount = 0;
3250
+ let rejectCount = 0;
3251
+ let customCount = 0;
3252
+ const catBreakdown = {};
3253
+ for (const record of log) {
3254
+ if (record.action === "accept_all") acceptCount++;
3255
+ else if (record.action === "reject_optional") rejectCount++;
3256
+ else if (record.action === "custom") customCount++;
3257
+ for (const [cat, value] of Object.entries(record.categories)) {
3258
+ if (!catBreakdown[cat]) catBreakdown[cat] = { accepted: 0, rejected: 0 };
3259
+ if (value) catBreakdown[cat].accepted++;
3260
+ else catBreakdown[cat].rejected++;
3261
+ }
3262
+ }
3263
+ const total = log.length;
3264
+ return {
3265
+ totalActions: total,
3266
+ acceptAllRate: Math.round(acceptCount / total * 100),
3267
+ rejectAllRate: Math.round(rejectCount / total * 100),
3268
+ customRate: Math.round(customCount / total * 100),
3269
+ categoryBreakdown: catBreakdown,
3270
+ lastUpdated: log[log.length - 1].timestamp
3271
+ };
3272
+ }
3273
+ const ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
3274
+ const TIMEOUT_MS$1 = 1500;
3275
+ const CACHE_PREFIX = "smartconsent_site3_";
3276
+ const PREVIOUS_PREFIX = "smartconsent_site2_";
3277
+ const validId = (v) => typeof v === "string" && ID_PATTERN.test(v) ? v : null;
3278
+ function readSiteId(rawConfig) {
3279
+ const fromConfig = rawConfig && typeof rawConfig === "object" ? rawConfig.siteId : void 0;
3280
+ return validId(fromConfig) ?? tagSiteId();
3281
+ }
3282
+ const tagSiteId = () => {
3283
+ var _a;
3284
+ return validId((_a = document.querySelector('script[src*="smartconsent"][data-site-id]')) == null ? void 0 : _a.getAttribute("data-site-id"));
3285
+ };
3286
+ function isSettings(v) {
3287
+ const s = v;
3288
+ return !!s && s.version === 1 && (s.plan === "free" || s.plan === "pro" || s.plan === "enterprise") && (s.mode === "normal" || s.mode === "safe") && !!s.attribution && typeof s.attribution.required === "boolean";
3289
+ }
3290
+ async function loadSiteSettings(id2, base) {
3291
+ const key = CACHE_PREFIX + id2;
3292
+ let cached = null;
3293
+ for (const k of [key, PREVIOUS_PREFIX + id2]) {
3294
+ try {
3295
+ const c = JSON.parse(sessionStorage.getItem(k) || "null");
3296
+ if (isSettings(c)) {
3297
+ if (c.attribution.required) cached = { ...c, attribution: { required: true } };
3298
+ break;
3299
+ }
3300
+ } catch {
3301
+ }
3302
+ }
3303
+ const controller = new AbortController();
3304
+ let timer;
3305
+ const timeout = new Promise((resolve) => {
3306
+ timer = setTimeout(() => {
3307
+ controller.abort();
3308
+ resolve(null);
3309
+ }, TIMEOUT_MS$1);
3310
+ });
3311
+ const download = (async () => {
3312
+ try {
3313
+ const res = await fetch(`${base}/v1/sites/${id2}.json`, { signal: controller.signal, credentials: "omit" });
3314
+ if (!res.ok) return null;
3315
+ const body = await res.json();
3316
+ if (!isSettings(body)) return null;
3317
+ try {
3318
+ sessionStorage.setItem(key, JSON.stringify(body));
3319
+ sessionStorage.removeItem(PREVIOUS_PREFIX + id2);
3320
+ } catch {
3321
+ }
3322
+ return body;
3323
+ } catch {
3324
+ return null;
3325
+ }
3326
+ })();
3327
+ try {
3328
+ return await Promise.race([download, timeout]) ?? cached;
3329
+ } finally {
3330
+ clearTimeout(timer);
3331
+ }
3332
+ }
3333
+ const bareHost = (h) => h.toLowerCase().replace(/\.$/, "").replace(/^www\./, "");
3334
+ function applySiteSettings(config, settings, siteId) {
3335
+ if (config.attributionRef !== void 0) {
3336
+ config = { ...config };
3337
+ delete config.attributionRef;
3338
+ }
3339
+ const platform = config.platform === "wordpress-plugin" || config.platform === "joomla-extension" || config.platform === "drupal-module";
3340
+ if (platform && config.attribution !== true) config = { ...config, attribution: false };
3341
+ if (!settings) return config;
3342
+ const scanned2 = scannedCookies(settings);
3343
+ if (scanned2.length && config.cookies.length === 0) config = { ...config, cookies: scanned2 };
3344
+ if (platform && !config.attribution) return config;
3345
+ const a = settings.attribution;
3346
+ let force = settings.mode === "safe" || a.required;
3347
+ if (!force && settings.plan !== "enterprise") {
3348
+ const onRegisteredHost = typeof settings.host === "string" && bareHost(settings.host) === bareHost(location.hostname);
3349
+ force = !(onRegisteredHost && config.attribution === false);
3350
+ }
3351
+ if (!force) return config;
3352
+ const out = { ...config, attribution: true, attributionUrl: DEFAULT_CONFIG.attributionUrl };
3353
+ const tag = tagSiteId();
3354
+ const own = a.ref === siteId && (!tag || tag === siteId);
3355
+ if (a.ref && own && typeof a.host === "string" && bareHost(a.host) === bareHost(location.hostname)) {
3356
+ out.attributionRef = a.ref;
3357
+ }
3358
+ return out;
3359
+ }
3360
+ function scannedCookies(settings) {
3361
+ const list = settings.cookies;
3362
+ const out = [];
3363
+ if (!Array.isArray(list)) return out;
3364
+ for (const c of list) {
3365
+ if (!c || typeof c.name !== "string" || typeof c.category !== "string") continue;
3366
+ const entry = { name: c.name, category: c.category };
3367
+ const about = [c.provider, c.purpose].filter((v) => typeof v === "string" && v !== "");
3368
+ if (about.length) entry.description = about.join(": ");
3369
+ if (c.party === "first" || c.party === "third") entry.party = c.party;
3370
+ if (typeof c.duration === "string" && c.duration) entry.duration = c.duration;
3371
+ out.push(markScanned(entry));
3372
+ }
3373
+ return out;
3374
+ }
3375
+ const THEME_KEYS = ["bg", "surface", "border", "text", "textMuted", "accent", "accept", "reject", "toggleOn", "toggleOff", "radius", "font"];
3376
+ const TEXT_KEYS = ["heading", "description", "acceptAll", "rejectOptional", "managePreferences", "essentialOnly", "savePreferences"];
3377
+ function pickStrings(obj, keys) {
3378
+ const out = {};
3379
+ if (obj && typeof obj === "object") {
3380
+ for (const k of keys) {
3381
+ const v = obj[k];
3382
+ if (typeof v === "string") out[k] = v;
3383
+ }
3384
+ }
3385
+ return out;
3386
+ }
3387
+ function validLogo(v) {
3388
+ const l = v;
3389
+ if (!l || typeof l !== "object" || typeof l.src !== "string" || typeof l.alt !== "string") return null;
3390
+ return l.src.startsWith("https://") ? { src: l.src, alt: l.alt } : null;
3391
+ }
3392
+ function withoutLogo(config) {
3393
+ const rest = { ...config };
3394
+ delete rest.logo;
3395
+ return rest;
3396
+ }
3397
+ function applyBannerSettings(config, settings) {
3398
+ if (!settings) return config;
3399
+ const raw = settings.banner;
3400
+ const b = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : null;
3401
+ const paid = settings.plan === "pro" || settings.plan === "enterprise";
3402
+ const dropLogo = !paid && !!config.logo;
3403
+ if (!b) return dropLogo ? withoutLogo(config) : config;
3404
+ let out = { ...config };
3405
+ if (dropLogo) out = withoutLogo(out);
3406
+ const logo = paid ? validLogo(b.logo) : null;
3407
+ if (logo) out.logo = logo;
3408
+ return applyLook(out, b);
3409
+ }
3410
+ function applyLook(config, b) {
3411
+ const out = { ...config };
3412
+ if (b.layout === "banner" || b.layout === "box" || b.layout === "popup") out.layout = b.layout;
3413
+ if (b.position === "bottom" || b.position === "top") out.position = b.position;
3414
+ if (b.boxPosition === "bottom-left" || b.boxPosition === "bottom-right") out.boxPosition = b.boxPosition;
3415
+ out.theme = { ...config.theme, ...pickStrings(b.theme, THEME_KEYS) };
3416
+ out.texts = { ...config.texts, ...pickStrings(b.texts, TEXT_KEYS) };
3417
+ return out;
3418
+ }
3419
+ function applyRegionLook(config, capsule, ids, settings) {
3420
+ if (!settings || !capsule || capsule.v !== 1 || typeof capsule.apply !== "function") return config;
3421
+ let look;
3422
+ try {
3423
+ look = capsule.apply([...ids], settings.regions);
3424
+ } catch {
3425
+ return config;
3426
+ }
3427
+ return look && typeof look === "object" && !Array.isArray(look) ? applyLook(config, look) : config;
3428
+ }
3429
+ function drainQueue(api) {
3430
+ var _a;
3431
+ const call = (args) => {
3432
+ const [method, ...rest] = Array.from(args);
3433
+ const fn = api[method];
3434
+ if (typeof fn !== "function") {
3435
+ console.warn("SmartConsent: unknown method", method);
3436
+ return;
3437
+ }
3438
+ try {
3439
+ fn.apply(api, rest);
3440
+ } catch (e) {
3441
+ console.error("SmartConsent: queued call failed.", method, e);
3442
+ }
3443
+ };
3444
+ const queue = ((_a = window.smartconsent) == null ? void 0 : _a.q) || [];
3445
+ window.smartconsent = (...args) => call(args);
3446
+ for (let i = 0; i < queue.length; i++) call(queue[i]);
3447
+ }
3448
+ const BLOCK_PREFIX = "smartconsent_block_";
3449
+ const RULE = /^[a-z0-9._/-]{1,100}$/;
3450
+ function validRules(v) {
3451
+ if (!Array.isArray(v)) return null;
3452
+ return v.filter((r) => Array.isArray(r) && typeof r[0] === "string" && RULE.test(r[0]) && (r[1] === "analytics" || r[1] === "marketing")).slice(0, 300);
3453
+ }
3454
+ function cachedBlockRules(id2) {
3455
+ try {
3456
+ return validRules(JSON.parse(localStorage.getItem(BLOCK_PREFIX + id2) || "null"));
3457
+ } catch {
3458
+ return null;
3459
+ }
3460
+ }
3461
+ function storeBlockRules(id2, settings) {
3462
+ const rules = validRules(settings.block);
3463
+ try {
3464
+ if (rules) localStorage.setItem(BLOCK_PREFIX + id2, JSON.stringify(rules));
3465
+ else localStorage.removeItem(BLOCK_PREFIX + id2);
3466
+ } catch {
3467
+ }
3468
+ return rules ?? [];
3469
+ }
3470
+ const ID = /^[a-z0-9-]{1,32}$/;
3471
+ const TIMEOUT_MS = 1500;
3472
+ const nativeCreateElement = document.createElement;
3473
+ const loads = /* @__PURE__ */ new Map();
3474
+ function loadCapsule(id2, base, listed) {
3475
+ if (!ID.test(id2) || !Array.isArray(listed) || !listed.includes(id2)) return Promise.resolve(null);
3476
+ let p = loads.get(id2);
3477
+ if (!p) {
3478
+ p = new Promise((resolve) => {
3479
+ const s = nativeCreateElement.call(document, "script");
3480
+ const done = (ok) => {
3481
+ var _a;
3482
+ clearTimeout(timer);
3483
+ const cap = ok ? (_a = window.SmartConsentCapsules) == null ? void 0 : _a[id2] : null;
3484
+ resolve(cap && typeof cap === "object" ? cap : null);
3485
+ };
3486
+ const timer = setTimeout(() => done(false), TIMEOUT_MS);
3487
+ s.async = true;
3488
+ s.src = `${base}capsules/${id2}.js`;
3489
+ s.onload = () => done(true);
3490
+ s.onerror = () => done(false);
3491
+ document.head.appendChild(s);
3492
+ });
3493
+ loads.set(id2, p);
3494
+ }
3495
+ return p;
3496
+ }
3497
+ const ENGINE_VERSION = "1.0.0";
3498
+ const VID_KEY = "smartconsent_vid";
3499
+ function randomId() {
3500
+ try {
3501
+ return crypto.randomUUID();
3502
+ } catch {
3503
+ return Date.now().toString(36) + Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2);
3504
+ }
3505
+ }
3506
+ function readVisitorId() {
3507
+ try {
3508
+ return localStorage.getItem(VID_KEY);
3509
+ } catch {
3510
+ return null;
3511
+ }
3512
+ }
3513
+ function resolveRecordsEndpoint(raw) {
3514
+ if (typeof raw !== "string") return null;
3515
+ try {
3516
+ const path = raw.startsWith("/") && raw[1] !== "/" && raw[1] !== "\\";
3517
+ if (path || /^https?:\/\//i.test(raw)) {
3518
+ const url = new URL(raw, location.href);
3519
+ if (url.origin === location.origin && (url.protocol === "http:" || url.protocol === "https:")) return url.href;
3520
+ }
3521
+ } catch {
3522
+ }
3523
+ console.warn("SmartConsent: recordsEndpoint ignored (it must be on this site).");
3524
+ return null;
3525
+ }
3526
+ function readTagRecordsEndpoint() {
3527
+ var _a;
3528
+ return ((_a = document.querySelector('script[src*="smartconsent"][data-records-endpoint]')) == null ? void 0 : _a.getAttribute("data-records-endpoint")) ?? void 0;
3529
+ }
3530
+ function createConsentRecorder(options) {
3531
+ const { siteId, recordsUrl, config, language: language2, experiment } = options;
3532
+ let pageVid = null;
3533
+ let persisted = false;
3534
+ let booting = true;
3535
+ Promise.resolve().then(() => {
3536
+ booting = false;
3537
+ });
3538
+ function visitor() {
3539
+ if (pageVid) return;
3540
+ try {
3541
+ const saved = localStorage.getItem(VID_KEY);
3542
+ if (saved) {
3543
+ pageVid = saved;
3544
+ persisted = true;
3545
+ return;
3546
+ }
3547
+ } catch {
3548
+ }
3549
+ pageVid = randomId();
3550
+ try {
3551
+ localStorage.setItem(VID_KEY, pageVid);
3552
+ persisted = true;
3553
+ } catch {
3554
+ persisted = false;
3555
+ }
3556
+ }
3557
+ return {
3558
+ send(record) {
3559
+ try {
3560
+ visitor();
3561
+ const texts = config.texts;
3562
+ const labels = {};
3563
+ for (const c of config.categories) labels[c.id] = c.label;
3564
+ const payload = {
3565
+ site_id: siteId,
3566
+ consent_id: record.id,
3567
+ visitor_id: pageVid,
3568
+ visitor_id_persisted: persisted,
3569
+ timestamp: record.timestamp,
3570
+ action: record.action,
3571
+ categories: { ...record.categories },
3572
+ consent_version: record.version,
3573
+ jurisdiction: record.jurisdiction,
3574
+ gpc: booting && record.action === "reject_optional" && navigator.globalPrivacyControl === true,
3575
+ language: language2,
3576
+ wording: {
3577
+ heading: texts.heading,
3578
+ description: texts.description,
3579
+ acceptAll: texts.acceptAll,
3580
+ rejectOptional: texts.rejectOptional,
3581
+ managePreferences: texts.managePreferences,
3582
+ essentialOnly: texts.essentialOnly,
3583
+ savePreferences: texts.savePreferences,
3584
+ categories: labels
3585
+ },
3586
+ page_url: location.origin + location.pathname,
3587
+ engine_version: ENGINE_VERSION,
3588
+ ...experiment && { experiment: experiment.id, variant: experiment.variant, page: location.pathname.slice(0, 200) }
3589
+ };
3590
+ const url = recordsUrl;
3591
+ const body = JSON.stringify(payload);
3592
+ let queued = false;
3593
+ try {
3594
+ queued = typeof navigator.sendBeacon === "function" && navigator.sendBeacon(url, body);
3595
+ } catch {
3596
+ queued = false;
3597
+ }
3598
+ if (!queued) {
3599
+ fetch(url, { method: "POST", body, keepalive: true, mode: "no-cors", credentials: "omit" }).catch(() => {
3600
+ });
3601
+ }
3602
+ } catch {
3603
+ }
3604
+ }
3605
+ };
3606
+ }
3607
+ async function init() {
3608
+ const blocker = createBlocker();
3609
+ const siteId = readSiteId(window.SmartConsentConfig);
3610
+ const cachedRules = siteId ? cachedBlockRules(siteId) : null;
3611
+ if (siteId) blocker.setRules(cachedRules);
3612
+ blocker.init();
3613
+ const rawEarly = window.SmartConsentConfig;
3614
+ const consentModeOn = !(rawEarly && typeof rawEarly === "object" && rawEarly.consentMode === false);
3615
+ if (consentModeOn) {
3616
+ sendGtmDefaultDeny();
3617
+ sendUetDefaultDeny();
3618
+ }
3619
+ let unsubUet = null;
3620
+ try {
3621
+ const packBase = packsBase();
3622
+ const settingsP = siteId ? loadSiteSettings(siteId, DEFAULT_SETTINGS_BASE) : Promise.resolve(null);
3623
+ if (siteId) void settingsP.then((s) => blocker.setRules(s ? storeBlockRules(siteId, s) : cachedRules ?? []));
3624
+ const regulations = loadRegulations();
3625
+ const geo = await detectGeo();
3626
+ const bannerConfig = resolveRegulations(geo, regulations);
3627
+ const rawSiteConfig = window.SmartConsentConfig;
3628
+ const mergedRaw = buildMergedConfig(bannerConfig, rawSiteConfig);
3629
+ let config;
3630
+ try {
3631
+ config = validateConfig(mergedRaw);
3632
+ } catch (e) {
3633
+ console.error("SmartConsent: Invalid config.", e instanceof Error ? e.message : e);
3634
+ return createNoopAPI();
3635
+ }
3636
+ const siteSettings = await settingsP;
3637
+ config = applySiteSettings(config, siteSettings, siteId ?? void 0);
3638
+ delete config.dataRequestUrl;
3639
+ if (siteId && (siteSettings == null ? void 0 : siteSettings.requests) === true) {
3640
+ config = { ...config, dataRequestUrl: `${DEFAULT_API_BASE}/api/v1/privacy-request/${encodeURIComponent(siteId)}` };
3641
+ }
3642
+ const capsuleP = loadCapsule("country-banners", packBase, siteSettings == null ? void 0 : siteSettings.capsules);
3643
+ const shareDomain = sharedDomain(siteSettings);
3644
+ const shareP = shareDomain ? loadCapsule("subdomain-consent", packBase, siteSettings == null ? void 0 : siteSettings.capsules) : Promise.resolve(null);
3645
+ const test = siteSettings == null ? void 0 : siteSettings.experiment;
3646
+ const testOn = !!test && typeof test.id === "string" && !!test.b && typeof test.b === "object";
3647
+ const testP = testOn ? loadCapsule("banner-experiment", packBase, siteSettings == null ? void 0 : siteSettings.capsules) : Promise.resolve(null);
3648
+ const site = rawSiteConfig && typeof rawSiteConfig === "object" ? rawSiteConfig : {};
3649
+ let langCode;
3650
+ if (siteId && siteSettings) {
3651
+ langCode = pickSiteLanguage({
3652
+ pageLanguage: config.language,
3653
+ settings: siteSettings,
3654
+ htmlLang: document.documentElement.lang,
3655
+ browserLang: typeof navigator !== "undefined" ? navigator.language : void 0
3656
+ });
3657
+ if (!hasLanguage(langCode)) await loadPack(langCode, packBase);
3658
+ } else {
3659
+ langCode = detectLanguage(config.language);
3660
+ }
3661
+ const langData = getLanguage(langCode);
3662
+ if (langData) {
3663
+ config = { ...config, language: langData.lang };
3664
+ const userTexts = site.texts && typeof site.texts === "object" ? site.texts : {};
3665
+ config = {
3666
+ ...config,
3667
+ texts: { ...config.texts, ...langData.texts, ...userTexts },
3668
+ dir: langData.dir
3669
+ };
3670
+ if (site.categories === void 0) {
3671
+ config = {
3672
+ ...config,
3673
+ categories: config.categories.map((cat) => {
3674
+ const langCat = langData.categories[cat.id];
3675
+ return langCat ? { ...cat, label: langCat.label, description: langCat.description } : cat;
3676
+ })
3677
+ };
3678
+ }
3679
+ } else if (config.language && config.language !== "en") {
3680
+ config = { ...config, language: "en" };
3681
+ }
3682
+ if (site.translations && typeof site.translations === "object") {
3683
+ const overrides = site.translations;
3684
+ const textsRecord = config.texts;
3685
+ for (const [key, value] of Object.entries(overrides)) {
3686
+ if (typeof value !== "string") continue;
3687
+ if (key.startsWith("banner.")) {
3688
+ const textKey = key.slice(7);
3689
+ if (textKey in textsRecord) textsRecord[textKey] = value;
3690
+ } else if (key.startsWith("categories.")) {
3691
+ const parts = key.split(".");
3692
+ if (parts.length === 3) {
3693
+ const catId = parts[1];
3694
+ const field = parts[2];
3695
+ config = {
3696
+ ...config,
3697
+ categories: config.categories.map(
3698
+ (cat) => cat.id === catId ? { ...cat, ...field === "name" ? { label: value } : field === "description" ? { description: value } : {} } : cat
3699
+ )
3700
+ };
3701
+ }
3702
+ }
3703
+ }
3704
+ }
3705
+ config = applyBannerSettings(config, siteSettings);
3706
+ config = applyRegionLook(config, await capsuleP, bannerConfig.regulation_ids, siteSettings);
3707
+ const variant = pickVariant(await testP, test == null ? void 0 : test.id);
3708
+ if (variant === "b") {
3709
+ const reject = config.texts.rejectOptional;
3710
+ config = applyRegionLook(config, { v: 1, apply: () => test == null ? void 0 : test.b }, [], siteSettings);
3711
+ config.texts.rejectOptional = reject;
3712
+ }
3713
+ const regulationExpiryMonths = Math.ceil(bannerConfig.consent.expiry_days / 30);
3714
+ if (regulationExpiryMonths < config.expiry) {
3715
+ config = { ...config, expiry: Math.max(1, Math.min(13, regulationExpiryMonths)) };
3716
+ }
3717
+ const shareCap = await shareP;
3718
+ const share = (shareCap == null ? void 0 : shareCap.v) === 1 && typeof shareCap.read === "function" && typeof shareCap.write === "function" ? shareCap : null;
3719
+ const writeShared = (state) => {
3720
+ try {
3721
+ share == null ? void 0 : share.write(shareDomain, state);
3722
+ } catch {
3723
+ }
3724
+ };
3725
+ if (share) {
3726
+ try {
3727
+ restoreShared(share.read(shareDomain), config.version, writeShared);
3728
+ } catch {
3729
+ }
3730
+ }
3731
+ const manager = createConsentManager(config);
3732
+ if (share) manager.onConsentChange(() => writeShared(manager.getState()));
3733
+ let implied = bannerConfig.mode === "opt-out" && manager.needsConsent();
3734
+ let notice = null;
3735
+ const closeNotice = () => {
3736
+ notice == null ? void 0 : notice.hide();
3737
+ notice = null;
3738
+ };
3739
+ manager.onConsentChange(() => {
3740
+ implied = false;
3741
+ closeNotice();
3742
+ });
3743
+ const view = {
3744
+ ...manager,
3745
+ getState: () => manager.getState() ?? (implied ? { version: config.version, categories: Object.fromEntries(config.categories.map((c) => [c.id, true])), timestamp: "", action: "accept_all", expiresAt: "" } : null),
3746
+ hasConsent: (c) => {
3747
+ var _a;
3748
+ return ((_a = view.getState()) == null ? void 0 : _a.categories[c]) === true;
3749
+ }
3750
+ };
3751
+ const webhook = createWebhook(config);
3752
+ const gtm = createGTMConsentMode(config, view);
3753
+ const visitorHash = await computeVisitorHash();
3754
+ const jurisdiction2 = bannerConfig.applicable_regulations.join(", ") || "unknown";
3755
+ const consentLog = createConsentLog({
3756
+ visitorHash,
3757
+ jurisdiction: jurisdiction2,
3758
+ version: String(config.version)
3759
+ });
3760
+ const localRecords = resolveRecordsEndpoint(config.recordsEndpoint) ?? resolveRecordsEndpoint(readTagRecordsEndpoint());
3761
+ const recorder = siteId && (siteSettings || localRecords) ? createConsentRecorder({
3762
+ siteId,
3763
+ recordsUrl: localRecords ?? `${DEFAULT_API_BASE}/api/v1/consent-records`,
3764
+ config,
3765
+ language: langData ? langCode : "en",
3766
+ experiment: variant && test ? { id: test.id, variant } : null
3767
+ }) : null;
3768
+ manager.onConsentChange((event) => {
3769
+ const record = consentLog.addRecord(event.action, event.categories);
3770
+ webhook.send(event, record);
3771
+ recorder == null ? void 0 : recorder.send(record);
3772
+ });
3773
+ const gpcApplies = applyGpc(manager, config, bannerConfig);
3774
+ blocker.setTexts(config.texts);
3775
+ try {
3776
+ gtm.init({ defaultSent: consentModeOn });
3777
+ if (consentModeOn) {
3778
+ unsubUet = onConsentChange((e) => sendUetUpdate(!!e.categories.marketing));
3779
+ const saved = view.getState();
3780
+ if (saved) sendUetUpdate(!!saved.categories.marketing);
3781
+ }
3782
+ blocker.attach(view);
3783
+ } catch (e) {
3784
+ try {
3785
+ gtm.destroy();
3786
+ unsubUet == null ? void 0 : unsubUet();
3787
+ if (consentModeOn) {
3788
+ sendGtmDenyUpdate();
3789
+ sendUetUpdate(false);
3790
+ }
3791
+ } catch {
3792
+ }
3793
+ console.error("SmartConsent: Initialization error.", e instanceof Error ? e.message : e);
3794
+ return createNoopAPI();
3795
+ }
3796
+ injectStyles(config.theme);
3797
+ let banner = createBanner(view, config);
3798
+ const badge = createBadge(config, () => {
3799
+ badge.hide();
3800
+ banner = createBanner(view, config);
3801
+ banner.show();
3802
+ });
3803
+ manager.onConsentChange(() => {
3804
+ setTimeout(() => {
3805
+ if (!manager.needsConsent()) {
3806
+ badge.show();
3807
+ }
3808
+ }, 0);
3809
+ });
3810
+ if (gpcApplies) {
3811
+ badge.show();
3812
+ } else if (manager.needsConsent()) {
3813
+ if (implied) (notice = createOptOutNotice(manager, config, () => (banner = createBanner(view, config)).show())).show();
3814
+ else banner.show();
3815
+ } else {
3816
+ badge.show();
3817
+ }
3818
+ const api = {
3819
+ hasConsent(category) {
3820
+ return view.hasConsent(category);
3821
+ },
3822
+ getConsent() {
3823
+ return manager.getState();
3824
+ },
3825
+ getConsentLog() {
3826
+ return consentLog.getLog();
3827
+ },
3828
+ getLatestConsent() {
3829
+ return consentLog.getLatest();
3830
+ },
3831
+ getConsentStats() {
3832
+ return computeConsentStats(consentLog.getLog());
3833
+ },
3834
+ getCookies() {
3835
+ return config.cookies;
3836
+ },
3837
+ renderCookieTable(selector) {
3838
+ renderCookieTable(selector, config);
3839
+ },
3840
+ getCookieTableHTML() {
3841
+ return buildCookieTableHTML(config);
3842
+ },
3843
+ generateCookiePolicy(options) {
3844
+ return generateCookiePolicy(config, options);
3845
+ },
3846
+ renderCookiePolicy(selector, options) {
3847
+ renderCookiePolicy(selector, config, options);
3848
+ },
3849
+ show() {
3850
+ closeNotice();
3851
+ badge.hide();
3852
+ banner = createBanner(view, config);
3853
+ banner.show();
3854
+ },
3855
+ reset() {
3856
+ closeNotice();
3857
+ implied = false;
3858
+ banner.destroy();
3859
+ badge.destroy();
3860
+ manager.reset();
3861
+ if (share) writeShared(null);
3862
+ consentLog.clear();
3863
+ banner = createBanner(view, config);
3864
+ banner.show();
3865
+ }
3866
+ };
3867
+ return api;
3868
+ } catch (e) {
3869
+ console.error("SmartConsent: Initialization error.", e instanceof Error ? e.message : e);
3870
+ return createNoopAPI();
3871
+ }
3872
+ }
3873
+ function pickVariant(cap, id2) {
3874
+ if (!cap || cap.v !== 1 || typeof cap.pick !== "function" || !id2) return null;
3875
+ try {
3876
+ const v = cap.pick(readVisitorId(), id2);
3877
+ return v === "a" || v === "b" ? v : null;
3878
+ } catch {
3879
+ return null;
3880
+ }
3881
+ }
3882
+ function sharedDomain(settings) {
3883
+ var _a;
3884
+ const d = (_a = settings == null ? void 0 : settings.share) == null ? void 0 : _a.domain;
3885
+ if (typeof d !== "string" || !d) return null;
3886
+ const domain = d.toLowerCase();
3887
+ const host = location.hostname.toLowerCase();
3888
+ return host === domain || host.endsWith("." + domain) ? domain : null;
3889
+ }
3890
+ function restoreShared(cookie, version2, toCookie) {
3891
+ const live = (s) => !!s && s.version === version2 && Date.parse(s.expiresAt) > Date.now() && !!s.categories && typeof s.categories === "object";
3892
+ const storage = createStorage();
3893
+ const local = storage.getConsent();
3894
+ const cookieOk = live(cookie);
3895
+ if (cookieOk && (!live(local) || Date.parse(cookie.timestamp) > Date.parse(local.timestamp))) storage.saveConsent(cookie);
3896
+ else if (live(local) && (!cookieOk || Date.parse(local.timestamp) > Date.parse(cookie.timestamp))) toCookie(local);
3897
+ }
3898
+ function buildMergedConfig(banner, siteConfig) {
3899
+ const site = siteConfig && typeof siteConfig === "object" ? siteConfig : {};
3900
+ const version2 = typeof site.version === "number" ? site.version : 1;
3901
+ const regulationExpiryMonths = Math.max(1, Math.min(13, Math.ceil(banner.consent.expiry_days / 30)));
3902
+ const siteExpiry = typeof site.expiry === "number" ? site.expiry : regulationExpiryMonths;
3903
+ const expiry = Math.min(siteExpiry, regulationExpiryMonths);
3904
+ return {
3905
+ version: version2,
3906
+ expiry,
3907
+ // Site owner cosmetic overrides
3908
+ ...site.theme !== void 0 && { theme: site.theme },
3909
+ ...site.texts !== void 0 && { texts: site.texts },
3910
+ ...site.webhookUrl !== void 0 && { webhookUrl: site.webhookUrl },
3911
+ ...site.recordsEndpoint !== void 0 && { recordsEndpoint: site.recordsEndpoint },
3912
+ ...site.attribution !== void 0 && { attribution: site.attribution },
3913
+ ...site.platform !== void 0 && { platform: site.platform },
3914
+ ...site.attributionUrl !== void 0 && { attributionUrl: site.attributionUrl },
3915
+ ...site.showBadge !== void 0 && { showBadge: site.showBadge },
3916
+ ...site.badgePosition !== void 0 && { badgePosition: site.badgePosition },
3917
+ ...site.position !== void 0 && { position: site.position },
3918
+ ...site.onConsent !== void 0 && { onConsent: site.onConsent },
3919
+ // Categories from site owner if provided, else from regulation
3920
+ ...site.categories !== void 0 ? { categories: site.categories } : { categories: banner.categories },
3921
+ // consentMode from site owner if provided
3922
+ ...site.consentMode !== void 0 && { consentMode: site.consentMode },
3923
+ // language (FP-03: i18n)
3924
+ ...site.language !== void 0 && { language: site.language },
3925
+ // layout (FP-06)
3926
+ ...site.layout !== void 0 && { layout: site.layout },
3927
+ ...site.boxPosition !== void 0 && { boxPosition: site.boxPosition },
3928
+ // logo (FP-05)
3929
+ ...site.logo !== void 0 && { logo: site.logo },
3930
+ // cookies (FP-07)
3931
+ ...site.cookies !== void 0 && { cookies: site.cookies }
3932
+ };
3933
+ }
3934
+ function createNoopAPI() {
3935
+ return {
3936
+ hasConsent: () => false,
3937
+ getConsent: () => null,
3938
+ getConsentLog: () => [],
3939
+ getLatestConsent: () => null,
3940
+ getConsentStats: () => ({ totalActions: 0, acceptAllRate: 0, rejectAllRate: 0, customRate: 0, categoryBreakdown: {}, lastUpdated: "" }),
3941
+ getCookies: () => [],
3942
+ renderCookieTable: () => {
3943
+ },
3944
+ getCookieTableHTML: () => "",
3945
+ generateCookiePolicy: () => "",
3946
+ renderCookiePolicy: () => {
3947
+ },
3948
+ show: () => {
3949
+ },
3950
+ reset: () => {
3951
+ }
3952
+ };
3953
+ }
3954
+ const pending = init();
3955
+ window.SmartConsent = createNoopAPI();
3956
+ pending.then((api) => {
3957
+ window.SmartConsent = api;
3958
+ drainQueue(api);
3959
+ });
3960
+ return pending;
3961
+ }();
3962
+ //# sourceMappingURL=smartconsent.js.map