@consenti/ui 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +548 -151
  2. package/dist/angular.d.cts +486 -111
  3. package/dist/angular.d.ts +486 -111
  4. package/dist/angular.js +1 -73
  5. package/dist/angular.js.map +1 -1
  6. package/dist/angular.mjs +1 -52
  7. package/dist/angular.mjs.map +1 -1
  8. package/dist/chunk-3EXCD24H.mjs +2 -0
  9. package/dist/{chunk-ARALKXMB.mjs.map → chunk-3EXCD24H.mjs.map} +1 -1
  10. package/dist/chunk-J4BKXUD6.mjs +2 -0
  11. package/dist/chunk-J4BKXUD6.mjs.map +1 -0
  12. package/dist/hmac-UKMRMKN6.mjs +2 -0
  13. package/dist/{hmac-N6H7F2K2.mjs.map → hmac-UKMRMKN6.mjs.map} +1 -1
  14. package/dist/http-AQVVUCX6.mjs +2 -0
  15. package/dist/index.css +1 -1
  16. package/dist/index.d.ts +806 -103
  17. package/dist/index.mjs +1 -2220
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/index.umd.js +1 -2304
  20. package/dist/index.umd.js.map +1 -1
  21. package/dist/profiles-OEZAKEWL.mjs +2 -0
  22. package/dist/profiles-OEZAKEWL.mjs.map +1 -0
  23. package/dist/react.d.cts +470 -89
  24. package/dist/react.d.ts +470 -89
  25. package/dist/react.js +1 -60
  26. package/dist/react.js.map +1 -1
  27. package/dist/react.mjs +1 -39
  28. package/dist/react.mjs.map +1 -1
  29. package/dist/testing.js +1 -94
  30. package/dist/testing.js.map +1 -1
  31. package/dist/testing.mjs +1 -73
  32. package/dist/testing.mjs.map +1 -1
  33. package/dist/vue.d.cts +473 -82
  34. package/dist/vue.d.ts +473 -82
  35. package/dist/vue.js +1 -72
  36. package/dist/vue.js.map +1 -1
  37. package/dist/vue.mjs +1 -51
  38. package/dist/vue.mjs.map +1 -1
  39. package/package.json +15 -6
  40. package/dist/chunk-ARALKXMB.mjs +0 -20
  41. package/dist/hmac-N6H7F2K2.mjs +0 -26
  42. package/dist/http-VHOGZ6ZJ.mjs +0 -7
  43. /package/dist/{http-VHOGZ6ZJ.mjs.map → http-AQVVUCX6.mjs.map} +0 -0
package/dist/vue.d.ts CHANGED
@@ -1,15 +1,117 @@
1
+ import * as vue from 'vue';
2
+
3
+ type NonEmptyArray<T> = [T, ...T[]];
4
+ /**
5
+ * Deep-partial with JSON Merge Patch (RFC 7396) delete semantics: any key may be
6
+ * set to `null` instead of its usual type to signal "delete this key" when the
7
+ * partial is applied with `deepMerge()` — `undefined`/omitted keeps the base
8
+ * value, `null` removes it. Only meaningful for object/map keys (e.g. removing
9
+ * a `CategoryMap`/`CookieMap` entry via `profileOverride`); array elements are
10
+ * merged positionally and don't support deletion this way.
11
+ */
12
+ type DeepPartial<T> = T extends Function ? T : T extends Array<infer InferredArrayType> ? Array<DeepPartial<InferredArrayType>> : T extends ReadonlyArray<infer InferredReadonlyArrayType> ? ReadonlyArray<DeepPartial<InferredReadonlyArrayType>> : T extends object ? {
13
+ [Key in keyof T]?: DeepPartial<T[Key]> | null;
14
+ } : T;
15
+
16
+ declare const COMPLIANCE_GROUP_IDS: readonly ["opt-in", "opt-out", "opt-out-strict", "opt-in-dpdpa", "opt-in-china", "opt-in-brazil", "general-privacy-consent", "notice-only"];
17
+ declare const COOKIE_PURPOSE_IDS: readonly ["necessary", "functional", "preferences", "analytics", "marketing"];
18
+
19
+ /**
20
+ * Compliance-related literal types, derived from the regulation/group ID data
21
+ * that lives in @consenti/utils (packages/utils/src/compliance.ts).
22
+ *
23
+ * This import is type-only and fully erased at compile time — @consenti/types
24
+ * has no runtime dependency on @consenti/utils. The actual data (COMPLIANCE_GROUPS,
25
+ * EMBEDDED_COMPLIANCE_MAP, COMPLIANCE_VALIDATION_RULES, GPC_OPTIONS, etc.) lives in
26
+ * @consenti/utils; import it from there.
27
+ *
28
+ * HOW TO ADD A NEW REGULATION OR COMPLIANCE GROUP: see the header comment in
29
+ * packages/utils/src/compliance.ts — these types auto-update from that data.
30
+ */
31
+
32
+ type ComplianceGroupId = typeof COMPLIANCE_GROUP_IDS[number];
33
+ /**
34
+ * `(string & {})` (rather than plain `string`) keeps IDE autocomplete for the
35
+ * known `ComplianceGroupId` literals while still allowing any other string —
36
+ * used to target a profile authored against a custom (non-built-in)
37
+ * `customComplianceGroup` instead of one of the 8 built-in groups.
38
+ */
39
+ type ComplianceType = 'auto' | ComplianceGroupId | (string & {}) | Symbol;
40
+
41
+ interface ComplianceMapData {
42
+ version: string;
43
+ countries: Record<string, CountryComplianceEntry>;
44
+ }
45
+ interface CountryComplianceEntry {
46
+ complianceGroup: ComplianceGroupId;
47
+ default: ComplianceGroupId;
48
+ description: string;
49
+ overriddenRegions?: Record<string, {
50
+ complianceGroup: ComplianceGroupId;
51
+ description: string;
52
+ }>;
53
+ }
54
+ interface ConsentDbRecord {
55
+ id: string;
56
+ tenantId: string;
57
+ visitorId: string;
58
+ profileId: string;
59
+ locale: string;
60
+ consentJson: ConsentValue;
61
+ gpcDetected: boolean;
62
+ source: 'banner' | 'api' | 'import';
63
+ ageVerified?: boolean;
64
+ parentalConsentToken?: string;
65
+ tcfString?: string;
66
+ /** HMAC-SHA256 signature over the record's core fields, hex-encoded. Only present when
67
+ * `consentSigningKey` is configured — opt-in tamper-evidence for server-stored records,
68
+ * independent of the widget's own cookie-signing (`core.cookieSigningKey`). */
69
+ signature?: string;
70
+ createdAt: string;
71
+ updatedAt: string;
72
+ }
73
+
1
74
  type ConsentStatus = 'granted' | 'denied' | 'objected';
75
+ type ConsentAction = 'accept_all' | 'reject_all' | 'custom' | 'update';
2
76
  type ConsentValue = Record<string, ConsentStatus>;
77
+ /**
78
+ * Output format for getConsent(type).
79
+ * 'default' → raw ConsentValue (existing behaviour)
80
+ * 'google-gtm' → Google Consent Mode v2 keys + ads_data_redaction, url_passthrough
81
+ * 'category' → consent per CookiePurpose category
82
+ * 'adobe' → { analytics, target, manager, optimizer }
83
+ * 'meta' → { pixel, api, plugins, facebookLogin }
84
+ * 'microsoft-clarity' → { session, heatmaps, performance }
85
+ * 'twilio-segment' → { identify, page, track, group, alias }
86
+ */
87
+ type ConsentType = 'default' | 'google-gtm' | 'category' | 'adobe' | 'meta' | 'microsoft-clarity' | 'twilio-segment';
88
+ type GpcMode = 'ignore' | 'honor' | 'strict';
89
+ type LegalBasis = 'mandatory' | 'consent' | 'legitimate_interest';
90
+ type CookiePurpose = typeof COOKIE_PURPOSE_IDS[number];
91
+ /**
92
+ * A single consent parameter (tracker/cookie definition).
93
+ * Keyed by its own id inside `Record<string, Cookie>` — the map key IS the id,
94
+ * there is no `id` field on the value itself.
95
+ */
3
96
  interface Cookie {
4
- id: string;
5
- type?: 'consent' | 'legitimate_interest';
6
- mandatory?: boolean;
97
+ purpose?: CookiePurpose;
7
98
  listenGpc?: boolean;
8
- expiry?: number;
99
+ /**
100
+ * Pre-grant this parameter's default consent to 'granted' (instead of the
101
+ * compliance-group-driven default) when no stored decision exists yet.
102
+ * Only meaningful when the owning category's `legalBasis === 'consent'` —
103
+ * `mandatory`/`legitimate_interest` categories are already effectively
104
+ * pre-granted regardless of this flag. Never overrides an active GPC signal.
105
+ * Default: false.
106
+ */
107
+ preGrant?: boolean;
9
108
  tcfVendorId?: number;
10
109
  tcfPurposes?: number[];
110
+ tcfSpecialFeatures?: number[];
11
111
  cpraCategory?: 'sale' | 'sharing' | 'sensitive';
12
112
  }
113
+ /** `Cookie` keyed by its own id — the standard shape used everywhere a parameter list is passed around. */
114
+ type CookieMap = Record<string, Cookie>;
13
115
  type ButtonStyle = 'primary' | 'secondary' | 'text' | 'accent';
14
116
  type ButtonAction = 'submit' | 'manage' | 'close' | 'custom' | 'link';
15
117
  interface Button {
@@ -19,6 +121,10 @@ interface Button {
19
121
  cookies?: string[] | '*' | '!';
20
122
  url?: string;
21
123
  }
124
+ /** `Button` keyed by its own id — e.g. `'accept-all'`. The map key IS the id, rendered as the DOM
125
+ * `id` (`consenti-btn-{id}`) so integrators can target specific buttons, and is what
126
+ * `profileOverride`'s `deepMerge` deletes by (`{ 'reject-optional': null }` removes one button). */
127
+ type ButtonMap = Record<string, Button>;
22
128
  interface MainBanner {
23
129
  position: 'top' | 'bottom' | 'middle' | 'left-bottom' | 'right-bottom';
24
130
  overlayOpacity?: number;
@@ -27,34 +133,45 @@ interface MainBanner {
27
133
  heading?: string;
28
134
  headingTag?: string;
29
135
  htmlText: string;
30
- buttons: Button[];
136
+ buttons: ButtonMap;
137
+ /** Stack buttons vertically below this viewport width in px. 0 or undefined = disabled. Default: 576. */
138
+ stackButtonsOnBreakpoint?: number;
139
+ /** Trap keyboard Tab focus within the consent root while this banner is visible. */
140
+ trapFocus?: boolean;
31
141
  }
32
142
  type GpcBanner = MainBanner;
143
+ /**
144
+ * A consent category — the single source of legal basis for every parameter
145
+ * it lists in `cookies`. Keyed by its own id inside `Record<string, Category>` —
146
+ * the map key IS the id, there is no `id` field on the value itself.
147
+ *
148
+ * A parameter must belong to exactly one category (enforced at authoring time,
149
+ * not by this type) — that relationship is what `getCookieLegalBasis`/
150
+ * `isMandatoryCookie` (`@consenti/utils`) resolve at runtime.
151
+ */
33
152
  interface Category {
34
- id: string;
35
153
  heading: string;
36
154
  headingTag?: string;
37
155
  htmlText: string;
38
- mandatory?: boolean;
39
- type?: 'consent' | 'legitimate_interest';
40
- legitimateInterest?: {
41
- enabled?: boolean;
42
- description?: string;
43
- };
156
+ legalBasis: LegalBasis;
157
+ /** Only meaningful when legalBasis === 'legitimate_interest' — the GDPR balancing-test justification shown to visitors. */
158
+ legitimateInterestDescription?: string;
159
+ /** IDs of the parameters (from the profile's `cookies` map) that belong to this category. */
44
160
  cookies: string[];
45
161
  }
46
- interface PreferenceModal {
162
+ /** `Category` keyed by its own id — the standard shape used everywhere a category list is passed around. */
163
+ type CategoryMap = Record<string, Category>;
164
+ interface PreferenceModal extends Omit<MainBanner, "position"> {
47
165
  position?: 'left' | 'right' | 'center';
48
- overlayOpacity?: number;
49
- showClose?: boolean;
50
- showLocaleSwitcher?: boolean;
51
- heading?: string;
52
- headingTag?: string;
53
166
  subheading?: string;
54
- htmlText?: string;
55
- buttons: Button[];
56
- categories: Category[];
167
+ categories: CategoryMap;
57
168
  persistent?: boolean;
169
+ /** Screen width in px below which the modal expands to full screen. Default: 576. Set to 0 to disable. */
170
+ mobileFullScreenBreakpoint?: number;
171
+ /** Label for the optional consent-receipt download checkbox (shown when `allowReceipt` is true). Falls back to a default when omitted. */
172
+ receiptLabel?: string;
173
+ /** Description shown beneath the consent-receipt checkbox. Falls back to a default when omitted. */
174
+ receiptDescription?: string;
58
175
  }
59
176
  interface DpdpaConfig {
60
177
  dataFiduciary: string;
@@ -62,17 +179,55 @@ interface DpdpaConfig {
62
179
  purposeDescription?: string;
63
180
  }
64
181
  interface ResolvedProfile {
65
- id: number;
66
- version: number;
182
+ id: string;
183
+ /** Incremented in place on every save of this profile. Absent for embedded/local profiles that have no server-side version counter. */
184
+ version?: number;
67
185
  defaultLocale: string;
68
186
  locales?: string[];
69
- cookies: Cookie[];
187
+ cookies: CookieMap;
188
+ /** Days until consent expires and the visitor is asked again (profile-wide). Default: 365. */
189
+ expiryDays?: number;
190
+ allowReceipt?: boolean;
70
191
  mainBanner: MainBanner;
71
192
  gpcBanner?: GpcBanner;
72
193
  preferenceModal: PreferenceModal;
73
194
  cookieSigningKey?: string;
74
195
  dpdpa?: DpdpaConfig;
75
196
  darkMode?: boolean;
197
+ gpcMode?: GpcMode;
198
+ complianceGroup?: ComplianceGroupId;
199
+ complianceConfig?: Record<string, string>;
200
+ /** Falls back to `true` (hidden) if neither the widget config nor the profile set it. */
201
+ hidePoweredBy?: boolean;
202
+ /** Show metadata footer strip (Consent ID, Date, Version, Privacy Settings link). */
203
+ showFooterMetadata?: boolean;
204
+ /** Apply WCAG 2.1 AA accessibility enhancements to the widget. */
205
+ enhanceAccessibility?: boolean;
206
+ }
207
+ type WidgetCountryResolverFn = () => Promise<{
208
+ country: string | null;
209
+ region: string | null;
210
+ confidence: number;
211
+ }>;
212
+ interface AgeGateWidgetConfig {
213
+ enabled: boolean;
214
+ minimumAge: number;
215
+ requireParentalConsent?: boolean;
216
+ }
217
+ /** Mirrors the server-side `TcfConfig` shape (`@consenti/api`) — `cmpId`/`cmpVersion` must match
218
+ * what the backend uses to encode `tcfString`, since both feed the same simplified TC string. */
219
+ interface TcfWidgetConfig {
220
+ enabled: boolean;
221
+ cmpId: number;
222
+ cmpVersion: number;
223
+ }
224
+ interface ComplianceWidgetConfig {
225
+ type?: ComplianceType;
226
+ geoDataProvider?: 'default' | WidgetCountryResolverFn;
227
+ autoComplianceMap?: 'default' | ComplianceMapData | 'auto';
228
+ complianceMapUrl?: string;
229
+ ageGate?: AgeGateWidgetConfig;
230
+ tcf?: TcfWidgetConfig;
76
231
  }
77
232
  interface GtmConfig {
78
233
  containerId?: string;
@@ -80,6 +235,7 @@ interface GtmConfig {
80
235
  dataLayer?: string;
81
236
  urlPassthrough?: boolean;
82
237
  adsDataRedaction?: boolean;
238
+ verbose?: boolean;
83
239
  }
84
240
  interface UtilsConfig {
85
241
  gtm?: GtmConfig;
@@ -88,6 +244,9 @@ interface ApiConfig {
88
244
  enabled?: boolean;
89
245
  baseUrl?: string;
90
246
  authToken?: string;
247
+ tenantId?: string;
248
+ complianceGroup?: ComplianceGroupId;
249
+ trustDomain?: boolean;
91
250
  }
92
251
  interface ThemeConfig {
93
252
  bgColor?: string;
@@ -109,35 +268,60 @@ interface ThemeConfig {
109
268
  accentTextColor?: string;
110
269
  }
111
270
  interface CoreConfig {
112
- profileId?: number;
113
- autoHonorGPC?: boolean | 'strict';
271
+ tenantId?: string;
114
272
  locale?: string;
273
+ /** Text direction for the banner/modal root. `'auto'` (default) derives it from `locale`
274
+ * (Arabic, Hebrew, Persian, Urdu, ... → `rtl`); set explicitly to override. */
275
+ dir?: 'ltr' | 'rtl' | 'auto';
115
276
  disableCssTemplate?: boolean;
116
- signCookies?: boolean;
117
277
  cookieSigningKey?: string;
118
278
  allowReceipt?: boolean;
119
279
  cookieDomains?: string;
120
280
  storage?: 'cookie' | 'localStorage';
121
281
  theme?: ThemeConfig;
122
- privacyPolicyUrl?: string;
123
- regulation?: 'gdpr' | 'ccpa' | 'cpra' | 'dpdpa' | 'uk-gdpr' | 'lgpd' | 'pipeda' | 'popia' | 'pdpa-th' | 'appi' | 'kvkk';
124
282
  userId?: string;
283
+ usePrebuiltProfiles?: 'all' | NonEmptyArray<ComplianceGroupId>;
284
+ cacheResolvedProfiles?: boolean;
285
+ console?: Array<'info' | 'log' | 'warning' | 'error'>;
125
286
  }
126
287
  interface ConsentiConfig {
127
- core: CoreConfig;
288
+ verbose?: boolean;
289
+ /** Optional — every field of `CoreConfig` is itself optional, so `new ConsentiSetup({})` and
290
+ * `new ConsentiSetup({ compliance: { type: 'opt-in' } })` (omitting `core` entirely) both work,
291
+ * matching the widget's own "Minimal config" documentation. */
292
+ core?: CoreConfig;
293
+ compliance?: ComplianceWidgetConfig;
128
294
  rootEl?: string | HTMLElement;
129
295
  darkMode?: boolean;
130
296
  autoInit?: boolean;
131
297
  api?: ApiConfig;
132
298
  utils?: UtilsConfig;
133
299
  plugins?: ConsentiPlugin[];
134
- profileOverride?: Partial<ResolvedProfile>;
300
+ profileOverride?: DeepPartial<ResolvedProfile>;
301
+ /** When true, suppresses the "Powered by Consenti" footer link in the banner and modal. */
302
+ hidePoweredBy?: boolean;
135
303
  }
304
+ type ConsentiEventName = 'bannerInitialized' | 'consenti:bannerInitialized' | 'bannerVisibility' | 'consenti:bannerVisibility' | 'modalVisibility' | 'consenti:modalVisibility' | 'consentBeingSubmitted' | 'consenti:consentBeingSubmitted' | 'consentSubmitted' | 'consenti:consentSubmitted' | 'parentalConsentRequired' | 'consenti:parentalConsentRequired';
136
305
  interface ConsentiWidgetAPI {
137
306
  hasConsent(): boolean;
138
307
  getConsent(): ConsentValue | null;
308
+ getConsent(type: ConsentType): Record<string, string> | null;
309
+ getConsent(type?: ConsentType): ConsentValue | Record<string, string> | null;
139
310
  getConsentDate(): Date | false;
140
311
  getGTMConsent(): Record<string, string> | null;
312
+ isCookieGranted(cookieId: string, requestValue?: boolean): boolean | ConsentStatus;
313
+ isCategoryGranted(categoryId: string, requestValue?: boolean): boolean | {
314
+ [cookieId: string]: ConsentStatus;
315
+ }[];
316
+ grantAll(onlyMandatory?: boolean): Promise<void>;
317
+ denyAll(includingMandatory?: boolean): Promise<void>;
318
+ on(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
319
+ off(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
320
+ version(): {
321
+ package: string;
322
+ profileVersion: string | null;
323
+ consentVersion: string | null;
324
+ };
141
325
  bannerVisibility(): 'main' | 'gpc' | false;
142
326
  modalVisibility(): 'preference' | false;
143
327
  getProfile(): ResolvedProfile | null;
@@ -145,13 +329,17 @@ interface ConsentiWidgetAPI {
145
329
  hideBanner(): void;
146
330
  showModal(triggerEl?: HTMLElement): void;
147
331
  hideModal(): void;
148
- submitConsent(consent: Partial<ConsentValue>): Promise<void>;
332
+ submitConsent(consent: Partial<ConsentValue>): Promise<ConsentDbRecord | void>;
149
333
  deleteConsent(): Promise<void>;
150
334
  reConsent(): Promise<void>;
151
335
  getRootElement(): HTMLElement | null;
152
336
  getBannerElement(): HTMLElement | null;
153
337
  getModalElement(): HTMLElement | null;
154
338
  switchLocale(locale: string): void;
339
+ setDarkMode(enable?: boolean): void;
340
+ setTheme(theme: Partial<ThemeConfig>): void;
341
+ setConfig(config: DeepPartial<ConsentiConfig>): void;
342
+ setProfile(override: DeepPartial<ResolvedProfile>): void;
155
343
  init(): Promise<void>;
156
344
  onReady(callback: () => void): void;
157
345
  destroy(): void;
@@ -165,6 +353,47 @@ declare abstract class ConsentiPlugin {
165
353
  onModalShow?(): void | Promise<void>;
166
354
  onModalHide?(): void | Promise<void>;
167
355
  }
356
+ interface BannerInitializedDetail {
357
+ profileId: string;
358
+ complianceGroup?: ComplianceType;
359
+ hasExistingConsent: boolean;
360
+ gpcDetected: boolean;
361
+ willShow: boolean;
362
+ }
363
+ interface BannerVisibilityDetail {
364
+ visible: boolean;
365
+ variant: 'main' | 'gpc';
366
+ action: boolean;
367
+ }
368
+ interface ModalVisibilityDetail {
369
+ visible: boolean;
370
+ action: boolean;
371
+ }
372
+ interface ConsentBeingSubmitted {
373
+ consentId: string;
374
+ visitorId: string;
375
+ profileId: string;
376
+ consentJson: ConsentValue;
377
+ consentAction: ConsentAction;
378
+ gpcDetected: boolean;
379
+ pageUrl: string;
380
+ timestamp: number;
381
+ fromBroadcast?: boolean;
382
+ }
383
+ interface ConsentSubmittedDetail extends ConsentBeingSubmitted {
384
+ apiResponse: ConsentDbRecord;
385
+ }
386
+ /** Dispatched when the age gate is declined and `requireParentalConsent` is set — see
387
+ * `AgeGateWidgetConfig`. A deny-all consent (mandatory cookies only) has already been
388
+ * submitted with `parentalConsentToken` attached; this event is the hook for the site
389
+ * owner to run their own out-of-band parental-consent verification. */
390
+ interface ParentalConsentRequiredDetail {
391
+ parentalConsentToken: string;
392
+ profileId: string;
393
+ visitorId: string;
394
+ timestamp: number;
395
+ }
396
+ type ConsentEvent = BannerInitializedDetail | BannerVisibilityDetail | ModalVisibilityDetail | ConsentBeingSubmitted | ConsentSubmittedDetail | ParentalConsentRequiredDetail;
168
397
 
169
398
  /**
170
399
  * Main entry point for the Consenti widget.
@@ -176,7 +405,7 @@ declare abstract class ConsentiPlugin {
176
405
  * @example
177
406
  * ```ts
178
407
  * const widget = new ConsentiSetup({
179
- * core: { profileId: 0 },
408
+ * compliance: { type: 'opt-in' },
180
409
  * })
181
410
  * await widget.ready
182
411
  * console.log(widget.hasConsent())
@@ -184,15 +413,30 @@ declare abstract class ConsentiPlugin {
184
413
  */
185
414
 
186
415
  declare class ConsentiSetup implements ConsentiWidgetAPI {
187
- private config;
188
416
  private initialized;
189
417
  private initializing;
190
418
  private profile;
419
+ private resolvedBase;
420
+ /** cookieId → Category lookup, rebuilt whenever `profile` changes. Avoids rescanning categories on every consent action. */
421
+ private categoryIndex;
422
+ /** Watchers created by the declarative `data-consenti-*` DOM scan — destroyed alongside the widget since they have no other owner. */
423
+ private scannedScripts;
191
424
  private consentStore;
425
+ /**
426
+ * Stable per-browser identifier. Created lazily the first time a consent decision actually
427
+ * happens (manual submit, GPC auto-response, or relaying a decision already made in another
428
+ * tab) — never minted before that, so an undecided visitor leaves nothing in storage. See
429
+ * `getOrCreateVisitorId()`.
430
+ */
431
+ private visitorId;
192
432
  private eventBus;
193
433
  private banner;
194
434
  private modal;
435
+ private ageGate;
195
436
  private renderer;
437
+ /** Set once the age gate (if enabled) resolves; threaded onto every `submitConsent` call thereafter. */
438
+ private _ageVerified;
439
+ private _parentalConsentToken;
196
440
  private broadcastChannel;
197
441
  private readyResolve;
198
442
  private readyPromise;
@@ -201,13 +445,23 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
201
445
  private lastSignature;
202
446
  /** Tracks which banner variant is currently visible, or null when hidden. */
203
447
  private _bannerVariant;
448
+ /** Tracks which banner variant is currently mounted in the DOM (persists when banner is hidden). */
449
+ private _bannerMounted;
450
+ /** Active focus trap keydown listener — removed when modal closes. */
451
+ private _focusTrapListener;
452
+ /** Maps original handler functions to their DOM-wrapped listeners for on/off bookkeeping. */
453
+ private _eventHandlers;
454
+ /** `core` defaulted to `{}` in the constructor below — every one of its own fields is
455
+ * optional, so this narrows back to non-optional for every other method in this class. */
456
+ private config;
204
457
  /**
205
458
  * Creates and initialises the consent widget.
206
459
  *
207
460
  * Construction is synchronous; the async `init()` is launched in the background.
208
461
  * Use `await widget.ready` or `widget.onReady(cb)` to run code after init completes.
209
462
  *
210
- * @param config - Widget configuration. See `ConsentiConfig` for all options.
463
+ * @param config - Widget configuration. See `ConsentiConfig` for all options. `core` may be
464
+ * omitted entirely — every one of its own fields is optional too.
211
465
  */
212
466
  constructor(config: ConsentiConfig);
213
467
  private profileId;
@@ -217,8 +471,53 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
217
471
  * to re-initialise the same instance.
218
472
  */
219
473
  init(): Promise<void>;
474
+ /**
475
+ * Everything after the "does consent already exist" check — GPC/CCPA/CPRA silent paths,
476
+ * then the normal opt-in banner. Extracted from `init()` so the age gate (when enabled and
477
+ * no consent exists yet) can defer this whole sequence until the visitor answers it via
478
+ * `resolveAgeGate()`, then resume here with `hasExisting` fixed at `false`.
479
+ */
480
+ private continueInit;
481
+ /** Mounts the age-gate prompt (`compliance.ageGate`) in place of the normal banner flow. */
482
+ private showAgeGate;
483
+ /**
484
+ * Handles the visitor's age-gate answer.
485
+ * - Confirmed → records `ageVerified: true` for all future `submitConsent` calls and
486
+ * resumes the normal init flow via `continueInit()`.
487
+ * - Declined, no parental consent required → immediately submits a deny-all consent
488
+ * (mandatory cookies still granted), mirroring the GPC-strict silent-write pattern.
489
+ * - Declined, parental consent required → same deny-all submission, plus a
490
+ * `parentalConsentToken` and a `consenti:parentalConsentRequired` event so the site
491
+ * owner can wire their own out-of-band verification flow (no email infra exists in
492
+ * this package to do that here).
493
+ */
494
+ private resolveAgeGate;
495
+ /**
496
+ * Marks the widget ready and runs the declarative DOM-scan for
497
+ * `data-consenti-consent-script`/`data-consenti-category-script` tags. Called from
498
+ * every exit path of `init()` so the scan always runs exactly once per init cycle,
499
+ * whether `init()` was triggered automatically (`autoInit !== false`) or explicitly
500
+ * by the caller (`autoInit: false`) — it never runs before the widget actually has
501
+ * a resolved profile to read consent from.
502
+ */
503
+ private finishInit;
504
+ /** Sets the `dir` attribute on the root element from `core.dir` (default `'auto'`, derived from `core.locale`). */
505
+ private applyDirection;
220
506
  /** Applies the `consenti-root--dark` class based on config or profile flag. */
221
507
  private applyDarkMode;
508
+ /** Applies `consenti--enhanced-a11y` class when `profile.enhanceAccessibility` is set. */
509
+ private applyAccessibility;
510
+ /** Builds and appends the metadata footer strip to a banner or modal container. */
511
+ private _appendMetaFooter;
512
+ /**
513
+ * Injects a `<style>` element into the root for `stackButtonsOnBreakpoint`.
514
+ * Called once per profile load; a new style replaces the previous one.
515
+ */
516
+ private applyStackButtonsBreakpoint;
517
+ /** Installs a keyboard focus trap on `container` while the modal is open. */
518
+ private _installFocusTrap;
519
+ /** Removes the active focus trap keyboard listener. */
520
+ private _removeFocusTrap;
222
521
  /**
223
522
  * Injects CSS custom property overrides supplied via `core.theme` into the
224
523
  * Consenti root element so they cascade down to all widget elements.
@@ -233,6 +532,8 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
233
532
  * @param invoke - Function that calls the desired hook method on a single plugin.
234
533
  */
235
534
  private callPluginHook;
535
+ private _buildGrantAllConsent;
536
+ private _buildDenyAllConsent;
236
537
  private buildHandlers;
237
538
  /**
238
539
  * Classifies a consent submission as `accept_all`, `reject_all`, `custom`, or `update`.
@@ -246,22 +547,23 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
246
547
  */
247
548
  hasConsent(): boolean;
248
549
  /**
249
- * Returns the stored consent map, or `null` if no consent has been saved.
250
- * Always returns `null` during SSR.
550
+ * Returns the stored consent map, optionally transformed for a specific vendor.
551
+ * Pass `type` to get a vendor-ready object instead of the raw Consenti format.
552
+ * Always returns `null` during SSR or when no consent has been saved.
553
+ *
554
+ * @param type - Vendor format: 'google-gtm', 'category', 'adobe', 'meta',
555
+ * 'microsoft-clarity', 'twilio-segment', or omit for raw format.
251
556
  */
252
557
  getConsent(): ConsentValue | null;
558
+ getConsent(type: ConsentType): Record<string, string> | null;
253
559
  /**
254
560
  * Returns the `Date` when consent was last saved, or `false` if no consent exists.
255
561
  * Always returns `false` during SSR.
256
562
  */
257
563
  getConsentDate(): Date | false;
258
564
  /**
259
- * Returns the consent map in Google Consent Mode v2 format, ready to pass to
260
- * `gtag('consent', 'update', ...)`. Returns `null` if no consent has been saved.
261
- *
262
- * Maps Consenti cookie IDs to the seven Google Consent Mode v2 parameters.
263
- * Cookies whose IDs exactly match a GCM v2 key are forwarded directly.
264
- * Non-GCM cookies are ignored by this method (they appear in `getConsent()` only).
565
+ * @deprecated Use `getConsent('google-gtm')` instead.
566
+ * Returns the consent map in Google Consent Mode v2 format.
265
567
  */
266
568
  getGTMConsent(): Record<string, string> | null;
267
569
  /**
@@ -273,7 +575,7 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
273
575
  * @param consent - Partial or full map of cookie ID → status.
274
576
  * @param gpcDerived - Internal flag set to `true` when called from the GPC strict path.
275
577
  */
276
- submitConsent(consent: Partial<ConsentValue>, gpcDerived?: boolean): Promise<void>;
578
+ submitConsent(consent: Partial<ConsentValue>, gpcDerived?: boolean, source?: number): Promise<ConsentDbRecord | void>;
277
579
  /**
278
580
  * Returns the currently visible banner variant, or `false` if no banner is shown.
279
581
  * Useful for programmatically checking state before calling `showBanner` / `hideBanner`.
@@ -381,6 +683,93 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
381
683
  * @param locale - BCP 47 locale code to switch to (e.g. `'fr'`, `'de-AT'`).
382
684
  */
383
685
  switchLocale(locale: string): void;
686
+ /**
687
+ * Returns `true` if the named cookie's consent is `'granted'`.
688
+ * When `requestValue` is `true`, returns the raw `ConsentStatus` string instead of a boolean,
689
+ * or `false` if the cookie is not in the consent map.
690
+ */
691
+ isCookieGranted(cookieId: string, requestValue?: boolean): boolean | 'granted' | 'denied' | 'objected';
692
+ /**
693
+ * Checks consent for all cookies belonging to the given category.
694
+ *
695
+ * With `requestValue = false` (default): returns `true` only when every cookie in the
696
+ * category is `'granted'`, `false` otherwise.
697
+ *
698
+ * With `requestValue = true`: returns an array of one-key records — one per cookie in the
699
+ * category — e.g. `[{ analytics: 'granted' }, { pixel: 'denied' }]`.
700
+ *
701
+ * Returns `false` / `[]` if the category is not found or the widget is not yet initialized.
702
+ */
703
+ isCategoryGranted(categoryId: string, requestValue?: boolean): boolean | {
704
+ [cookieId: string]: 'granted' | 'denied' | 'objected';
705
+ }[];
706
+ /**
707
+ * Programmatically accepts cookies and hides the banner.
708
+ *
709
+ * @param onlyMandatory - When `true`, only mandatory cookies are granted and all others
710
+ * are set to `'denied'`. Defaults to `false` (grant everything).
711
+ */
712
+ grantAll(onlyMandatory?: boolean): Promise<void>;
713
+ /**
714
+ * Programmatically denies cookies and hides the banner.
715
+ *
716
+ * @param includingMandatory - When `true`, mandatory cookies are also denied. Defaults to
717
+ * `false` (mandatory cookies remain `'granted'`). Passing `true`
718
+ * logs a warning — ensure this is intentional.
719
+ */
720
+ denyAll(includingMandatory?: boolean): Promise<void>;
721
+ /**
722
+ * Subscribes to a Consenti widget event. The `consenti:` prefix is optional —
723
+ * both `'consentSubmitted'` and `'consenti:consentSubmitted'` are accepted.
724
+ *
725
+ * The same handler reference must be passed to `off()` to unsubscribe.
726
+ *
727
+ * @example
728
+ * ```ts
729
+ * const handler = (data) => console.log(data)
730
+ * widget.on('consentSubmitted', handler)
731
+ * // later:
732
+ * widget.off('consentSubmitted', handler)
733
+ * ```
734
+ */
735
+ on(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
736
+ /**
737
+ * Removes a previously registered event handler. The same function reference passed to
738
+ * `on()` must be used here.
739
+ */
740
+ off(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
741
+ /**
742
+ * Returns the current version of the package and the active profile/consent versions.
743
+ * Useful for debugging and support diagnostics.
744
+ */
745
+ version(): {
746
+ package: string;
747
+ profileVersion: string;
748
+ consentVersion: string | null;
749
+ };
750
+ /**
751
+ * Toggles or sets dark mode at runtime without re-initialising the widget.
752
+ * When `enable` is omitted, the current dark mode state is toggled.
753
+ */
754
+ setDarkMode(enable?: boolean): void;
755
+ /**
756
+ * Applies partial theme token overrides at runtime, merging them into the current theme.
757
+ * CSS custom properties on the root element are updated immediately.
758
+ */
759
+ setTheme(theme: Partial<ThemeConfig>): void;
760
+ /**
761
+ * Deep-merges a partial config into the current widget config.
762
+ * Theme and dark mode side-effects are re-applied immediately.
763
+ * Changes to locale or profile require an explicit `switchLocale()` or `init()` call.
764
+ */
765
+ setConfig(config: DeepPartial<ConsentiConfig>): void;
766
+ /**
767
+ * Merges a partial profile override into the current profile and re-renders any visible UI.
768
+ * Does not make a network request — the resolved base profile from the last `init()` is reused.
769
+ *
770
+ * No-op before `init()` completes (while `resolvedBase` is null).
771
+ */
772
+ setProfile(override: DeepPartial<ResolvedProfile>): void;
384
773
  /**
385
774
  * Destroys the widget — removes all DOM elements, disconnects the BroadcastChannel,
386
775
  * and calls `destroy()` on all registered plugins.
@@ -390,34 +779,6 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
390
779
  destroy(): void;
391
780
  }
392
781
 
393
- /**
394
- * Vue 3 composable integration for `@consenti/ui`.
395
- *
396
- * Import from the `@consenti/ui/vue` subpath to keep this module
397
- * tree-shaken out of vanilla JS or React bundles.
398
- *
399
- * Intended for **Nuxt 3** and any Vue 3 project where you manage the `ConsentiSetup`
400
- * instance yourself (typically in a `.client.ts` plugin) and want `useConsent()`
401
- * to be reactive in components.
402
- *
403
- * @example
404
- * ```ts
405
- * // plugins/consenti.client.ts (Nuxt 3)
406
- * import { ConsentiSetup } from '@consenti/ui'
407
- * import { setConsentiWidget } from '@consenti/ui/vue'
408
- *
409
- * export default defineNuxtPlugin(() => {
410
- * const widget = new ConsentiSetup({ core: { profileId: 0 } })
411
- * setConsentiWidget(widget)
412
- * })
413
- *
414
- * // Any component
415
- * import { useConsent } from '@consenti/ui/vue'
416
- *
417
- * const { hasConsent, submitConsent } = useConsent()
418
- * ```
419
- */
420
-
421
782
  /**
422
783
  * Registers the active `ConsentiSetup` instance so `useConsent()` can read from it.
423
784
  * Call this once after creating your widget, typically in a `.client.ts` Nuxt plugin.
@@ -426,21 +787,51 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
426
787
  */
427
788
  declare function setConsentiWidget(widget: ConsentiSetup): void;
428
789
  /**
429
- * Vue 3 composable that exposes consent state and triggers reactivity on consent changes.
790
+ * Vue 3 composable that exposes consent state, banner/modal visibility, and widget actions.
430
791
  *
431
- * Listens to `consenti:consentSubmitted` on `window` via `onMounted` / `onUnmounted`
432
- * and increments a `ref(tick)` counter. Reactive getters read `tick.value` to register
433
- * a Vue dependency so components re-render when consent changes.
792
+ * State values (`hasConsent`, `consent`, `consentDate`, `bannerVisible`, `modalVisible`) are
793
+ * Vue `Ref`s — they are reactive in templates and `watch`/`computed` without calling `.value`
794
+ * in the template (Vue auto-unwraps top-level refs).
434
795
  *
435
- * Returns SSR-safe fallback values during Nuxt server render.
796
+ * Event listeners are registered in `onMounted` and removed in `onUnmounted`, so this
797
+ * composable is safe to call in components that render on the server (Nuxt SSR): the refs
798
+ * simply hold their initial values (`false` / `null`) during SSR and hydrate correctly.
436
799
  *
437
- * @returns An object with `hasConsent`, `getConsent`, `submitConsent`, and `getConsentDate`.
800
+ * @returns Reactive refs for consent state and plain functions for widget actions.
438
801
  */
439
802
  declare function useConsent(): {
440
- hasConsent: () => boolean;
441
- getConsent: () => ConsentValue | null;
442
- submitConsent: (_consent: Partial<ConsentValue>) => Promise<void>;
443
- getConsentDate: () => Date | false;
803
+ /** Reactive — `true` once the visitor has saved a valid consent record. */
804
+ hasConsent: vue.Ref<boolean, boolean>;
805
+ /** Reactive — the stored consent map (`Record<cookieId, status>`), or `null`. */
806
+ consent: vue.Ref<ConsentValue | null, ConsentValue | null>;
807
+ /** Reactive — `Date` of the last consent submission, or `false`. */
808
+ consentDate: vue.Ref<false | Date, false | Date>;
809
+ /** Reactive — `'main'`, `'gpc'`, or `false` (banner hidden). */
810
+ bannerVisible: vue.Ref<false | "main" | "gpc", false | "main" | "gpc">;
811
+ /** Reactive — `'preference'` or `false` (modal hidden). */
812
+ modalVisible: vue.Ref<false | "preference", false | "preference">;
813
+ /** Shows the consent banner. Pass `true` to force the GPC variant. */
814
+ showBanner: (gpc?: boolean) => void | undefined;
815
+ /** Hides the consent banner. */
816
+ hideBanner: () => void | undefined;
817
+ /** Opens the preference modal. */
818
+ showModal: () => void | undefined;
819
+ /** Closes the preference modal. */
820
+ hideModal: () => void | undefined;
821
+ /** Grants all non-mandatory cookies. Pass `true` to grant only mandatory ones and deny the rest. */
822
+ grantAll: (onlyMandatory?: boolean) => Promise<void>;
823
+ /** Denies all non-mandatory cookies. Pass `true` to deny mandatory ones too (use with care). */
824
+ denyAll: (includingMandatory?: boolean) => Promise<void>;
825
+ /** Saves the given partial consent map. */
826
+ submitConsent: (c: Partial<ConsentValue>) => Promise<void | ConsentDbRecord>;
827
+ /** Deletes the current consent record and re-shows the banner. */
828
+ reConsent: () => Promise<void>;
829
+ /** Returns `true` if the given cookie ID is `'granted'`. */
830
+ isCookieGranted: (id: string) => boolean;
831
+ /** Returns `true` if every cookie in the given category is `'granted'`. */
832
+ isCategoryGranted: (id: string) => boolean;
833
+ /** Switches the active locale and re-renders the banner and modal. */
834
+ switchLocale: (locale: string) => void | undefined;
444
835
  };
445
836
 
446
837
  export { setConsentiWidget, useConsent };