@hagicode/hagilight-core 0.20.1-dev.196.1.d67f4e4 → 0.20.1-dev.199.1.c17b214

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.
@@ -5,6 +5,7 @@
5
5
  import { resolveConsentCopy } from './consent-copy/index.js';
6
6
  import { consentDetails } from './consent-details.js';
7
7
  import { CONSENT_CONFIG_ID, DEFAULT_POLICY_VERSION } from './consent.js';
8
+ import { isAssignedCountryCode } from './consent-region.js';
8
9
  import { DEFAULT_LOCALE, SITE_LOCALE_CODES } from './root-transit-locale.js';
9
10
  export const CONSENT_PROVIDERS = ['googleAnalytics', 'posthog', 'fiftyOneLa'];
10
11
  /** Brand names stay as written in every locale. */
@@ -34,6 +35,65 @@ export function validatePrivacyUrl(value) {
34
35
  return trimmed;
35
36
  throw new TypeError('analytics.consent.privacyUrl must be an absolute http(s) URL or a site-relative path starting with "/".');
36
37
  }
38
+ const HOOK_NAME = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/u;
39
+ const REGIONAL_ONLY_OPTIONS = ['countryCode', 'regionHook', 'settingsEntry', 'sessionReplay'];
40
+ /** Throws a TypeError that names the option unless it is `default` or a non-empty list of assigned upper-case codes. */
41
+ export function validateRegions(value) {
42
+ if (value === 'default')
43
+ return 'default';
44
+ if (Array.isArray(value) && value.length > 0 && value.every((code) => isAssignedCountryCode(code)))
45
+ return [...value];
46
+ throw new TypeError('analytics.consent.regions must be "default" or a non-empty list of upper-case ISO 3166-1 alpha-2 country codes.');
47
+ }
48
+ /** Throws a TypeError that names the option unless the value is one assigned upper-case ISO 3166-1 alpha-2 code. */
49
+ export function validateCountryCode(value) {
50
+ if (!isAssignedCountryCode(value)) {
51
+ throw new TypeError('analytics.consent.countryCode must be one upper-case ISO 3166-1 alpha-2 country code, such as "DE".');
52
+ }
53
+ return value;
54
+ }
55
+ /** Throws a TypeError that names the option unless the value is the name of a function on `window`, not code. */
56
+ export function validateHookName(value) {
57
+ if (typeof value !== 'string' || !HOOK_NAME.test(value)) {
58
+ throw new TypeError('analytics.consent.regionHook must be the name of a function defined on window, such as "siteRegion".');
59
+ }
60
+ return value;
61
+ }
62
+ /** Throws a TypeError that names the option unless it is `requiredOnly` or `always`. */
63
+ export function validateSettingsEntry(value) {
64
+ if (value === 'requiredOnly' || value === 'always')
65
+ return value;
66
+ throw new TypeError('analytics.consent.settingsEntry must be "requiredOnly" or "always".');
67
+ }
68
+ /** Throws a TypeError that names the option unless it is `optIn`, `projectDefault` or `off`. */
69
+ export function validateSessionReplay(value) {
70
+ if (value === 'optIn' || value === 'projectDefault' || value === 'off')
71
+ return value;
72
+ throw new TypeError('analytics.consent.sessionReplay must be "optIn", "projectDefault" or "off".');
73
+ }
74
+ /**
75
+ * Validates the regional options of `analytics.consent` for every integration. Returns `undefined` when no regional option
76
+ * is set, so a global site stays exactly as it was. A regional-only option without `regions` throws, and so does `regions`
77
+ * with consent disabled, because either would silently widen or hide a compliance setting.
78
+ */
79
+ export function resolveRegionalOptions(input, enabled = true) {
80
+ const given = (key) => input?.[key] !== undefined;
81
+ if (!given('regions') && !REGIONAL_ONLY_OPTIONS.some((key) => given(key)))
82
+ return undefined;
83
+ if (!given('regions')) {
84
+ const key = REGIONAL_ONLY_OPTIONS.find((option) => given(option));
85
+ throw new TypeError(`analytics.consent.${key} needs analytics.consent.regions: regions is required when a regional option is set.`);
86
+ }
87
+ if (enabled === false)
88
+ throw new TypeError('analytics.consent.regions cannot be set while analytics.consent.enabled is false.');
89
+ return {
90
+ regions: validateRegions(input?.regions),
91
+ ...(given('countryCode') ? { countryCode: validateCountryCode(input?.countryCode) } : {}),
92
+ ...(given('regionHook') ? { regionHook: validateHookName(input?.regionHook) } : {}),
93
+ settingsEntry: given('settingsEntry') ? validateSettingsEntry(input?.settingsEntry) : 'requiredOnly',
94
+ sessionReplay: given('sessionReplay') ? validateSessionReplay(input?.sessionReplay) : 'optIn',
95
+ };
96
+ }
37
97
  /** Throws a TypeError that names the option when the policy version is not 1 to 32 safe characters. */
38
98
  export function validatePolicyVersion(value) {
39
99
  if (value === undefined)
@@ -54,6 +114,7 @@ export function resolveConsentPopupOptions(options) {
54
114
  providers,
55
115
  privacyUrl: validatePrivacyUrl(options.privacyUrl),
56
116
  policyVersion: validatePolicyVersion(options.policyVersion),
117
+ ...(options.regional ? { regional: options.regional } : {}),
57
118
  };
58
119
  }
59
120
  export function escapeHtml(value) {
@@ -73,17 +134,32 @@ function storageList(entries) {
73
134
  */
74
135
  export function consentDescriptor(options) {
75
136
  const resolved = resolveConsentPopupOptions(options);
137
+ const regional = resolved.regional
138
+ ? {
139
+ mode: 'regional',
140
+ regions: resolved.regional.regions,
141
+ ...(resolved.regional.countryCode !== undefined ? { countryCode: resolved.regional.countryCode } : {}),
142
+ ...(resolved.regional.regionHook !== undefined ? { regionHook: resolved.regional.regionHook } : {}),
143
+ settingsEntry: resolved.regional.settingsEntry,
144
+ sessionReplay: resolved.regional.sessionReplay,
145
+ }
146
+ : {};
76
147
  const payload = {
77
148
  policyVersion: resolved.policyVersion,
78
149
  privacyUrl: resolved.privacyUrl ?? null,
79
150
  providers: resolved.providers,
80
151
  locale: resolved.locale,
152
+ ...regional,
81
153
  };
82
154
  return JSON.stringify(payload).replace(/</gu, '\\u003c');
83
155
  }
84
156
  /** The ID of the descriptor script, so the popup and the gate can read the same element. */
85
157
  export const CONSENT_DESCRIPTOR_ID = CONSENT_CONFIG_ID;
86
- /** The popup's HTML: a hidden, labelled, non-modal region with two equal actions and an expandable details section. */
158
+ /**
159
+ * The popup's HTML: a hidden, labelled, non-modal region with two equal actions and an expandable details section. A
160
+ * regional site with session replay opt-in also gets a hidden replay section, with equal Allow and Not now actions. A
161
+ * global site renders exactly the markup it always did.
162
+ */
87
163
  export function renderConsentMarkup(options) {
88
164
  const resolved = resolveConsentPopupOptions(options);
89
165
  const copy = resolveConsentCopy(resolved.locale);
@@ -92,8 +168,21 @@ export function renderConsentMarkup(options) {
92
168
  const privacy = resolved.privacyUrl
93
169
  ? `<p class="hagilight-consent__privacy"><a href="${escapeHtml(resolved.privacyUrl)}">${escapeHtml(copy.privacyLink)}</a></p>`
94
170
  : '';
95
- return [
96
- `<section class="hagilight-consent" data-hagilight-consent data-state="undecided" role="region" aria-labelledby="hagilight-consent-title" hidden>`,
171
+ const replayOptIn = resolved.regional?.sessionReplay === 'optIn';
172
+ const replay = replayOptIn
173
+ ? [
174
+ `<div class="hagilight-consent__replay" data-hagilight-consent-replay hidden>`,
175
+ `<h2 class="hagilight-consent__title" id="hagilight-consent-replay-title">${escapeHtml(copy.replayTitle)}</h2>`,
176
+ `<p class="hagilight-consent__intro">${escapeHtml(copy.replayBody)}</p>`,
177
+ `<div class="hagilight-consent__actions">`,
178
+ `<button type="button" class="hagilight-consent__button" data-consent-replay-allow>${escapeHtml(copy.replayAllow)}</button>`,
179
+ `<button type="button" class="hagilight-consent__button" data-consent-replay-decline>${escapeHtml(copy.replayDecline)}</button>`,
180
+ `</div>`,
181
+ privacy,
182
+ `</div>`,
183
+ ]
184
+ : [];
185
+ const body = [
97
186
  `<h2 class="hagilight-consent__title" id="hagilight-consent-title">${escapeHtml(copy.title)}</h2>`,
98
187
  `<p class="hagilight-consent__intro">${escapeHtml(copy.intro)}</p>`,
99
188
  `<p class="hagilight-consent__choice" data-consent-choice data-choice-granted="${escapeHtml(copy.choiceAccepted)}" data-choice-denied="${escapeHtml(copy.choiceRejected)}" data-choice-undecided="${escapeHtml(copy.choiceUndecided)}">${escapeHtml(copy.choiceLabel)}: <span data-consent-choice-value>${escapeHtml(copy.choiceUndecided)}</span></p>`,
@@ -108,6 +197,20 @@ export function renderConsentMarkup(options) {
108
197
  `<p class="hagilight-consent__withdraw">${escapeHtml(copy.withdraw)}</p>`,
109
198
  privacy,
110
199
  `</div>`,
200
+ ];
201
+ if (!replayOptIn) {
202
+ return [
203
+ `<section class="hagilight-consent" data-hagilight-consent data-state="undecided" role="region" aria-labelledby="hagilight-consent-title" hidden>`,
204
+ ...body,
205
+ `</section>`,
206
+ ].join('');
207
+ }
208
+ return [
209
+ `<section class="hagilight-consent" data-hagilight-consent data-state="undecided" role="region" aria-labelledby="hagilight-consent-title" hidden>`,
210
+ `<div class="hagilight-consent__main" data-consent-main>`,
211
+ ...body,
212
+ `</div>`,
213
+ ...replay,
111
214
  `</section>`,
112
215
  ].join('');
113
216
  }
@@ -1,6 +1,8 @@
1
+ import { type RegionSource } from './consent-region.js';
1
2
  export declare const CONSENT_CLEARANCE_PROPERTY = "--hagilight-consent-clearance";
2
3
  /**
3
4
  * Mounts the popup inside `root` (the `[data-hagilight-consent]` section). Returns a function that removes the listeners.
4
- * With no panel, or where the visitor already decided or consent is not required, the panel stays hidden.
5
+ * With no panel, or where the visitor already decided, the panel stays hidden. An undecided visitor sees it once the
6
+ * region decision is `required` or `unknown`, and never for `notRequired` or while the decision is pending.
5
7
  */
6
- export declare function mountConsentPopup(root?: ParentNode): () => void;
8
+ export declare function mountConsentPopup(root?: ParentNode, region?: RegionSource): () => void;
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * Browser wiring for the consent popup. `mountConsentPopup` reveals the markup from `consent-markup.ts` only for an
3
- * undecided visitor, connects Accept and Reject to `setConsent`, toggles the details, reflects the current choice when
3
+ * undecided visitor whose region decision is `required` or `unknown`. It stays hidden while the decision is pending and
4
+ * for `notRequired`. It connects Accept and Reject to `setConsent`, toggles the details, reflects the current choice when
4
5
  * `openConsentPreferences()` is called, and publishes the popup's height as `--hagilight-consent-clearance` on the root.
5
- * The details slide open and the panel fades out through the Web Animations API, and both snap under reduced motion.
6
- * It never moves or traps focus.
6
+ * A replay opt-in request (`openConsentPreferences('replay')`) shows the replay section instead. The details slide open
7
+ * and the panel fades out through the Web Animations API, and both snap under reduced motion. It never moves or traps focus.
7
8
  */
8
- import { CONSENT_PREFERENCES_EVENT, getConsent, isConsentRequired, openConsentPreferences, setConsent } from './consent.js';
9
+ import { currentRegionConfig, CONSENT_PREFERENCES_EVENT, getConsent, onConsentChange, openConsentPreferences, regionalBehavior, setConsent, } from './consent.js';
10
+ import { pageRegionSource, startRegionResolution } from './consent-region.js';
9
11
  export const CONSENT_CLEARANCE_PROPERTY = '--hagilight-consent-clearance';
10
12
  /** Space between the popup and the banner or footer it lifts. */
11
13
  const CLEARANCE_GAP_PX = 12;
@@ -35,13 +37,51 @@ function publishClearance(panel) {
35
37
  root.style.setProperty(CONSENT_CLEARANCE_PROPERTY, '0px');
36
38
  return;
37
39
  }
38
- const height = Math.ceil(panel.getBoundingClientRect().height);
40
+ // offsetHeight ignores transforms, so the entrance scale does not shrink the clearance the banner lifts by.
41
+ const height = panel.offsetHeight;
39
42
  root.style.setProperty(CONSENT_CLEARANCE_PROPERTY, `${height + CLEARANCE_GAP_PX}px`);
40
43
  }
41
44
  catch {
42
45
  // No layout (for example during static rendering): leave the property unchanged.
43
46
  }
44
47
  }
48
+ /**
49
+ * Reveals the footer's regional entries (`data-consent-entry`), which the footer renders hidden. The settings entry shows
50
+ * for `required` and `unknown` decisions, or always when the site asks for it. The replay entry shows only for a
51
+ * `notRequired` visitor with the opt-in option and no record. Pages without these markers are not touched.
52
+ */
53
+ function revealConsentEntries(region) {
54
+ const apply = () => {
55
+ const decision = region.current();
56
+ const behavior = regionalBehavior();
57
+ const undecided = getConsent().analytics === 'undecided';
58
+ const settingsVisible = behavior.settingsEntry === 'always' || decision === 'required' || decision === 'unknown';
59
+ const replayVisible = decision === 'notRequired' && behavior.sessionReplay === 'optIn' && undecided;
60
+ for (const entry of Array.from(document.querySelectorAll('[data-consent-entry]'))) {
61
+ const visible = entry.dataset.consentEntry === 'settings' ? settingsVisible
62
+ : entry.dataset.consentEntry === 'replay' ? replayVisible
63
+ : false;
64
+ entry.hidden = !visible;
65
+ }
66
+ };
67
+ apply();
68
+ const unsubscribeRegion = region.subscribe(apply);
69
+ const unsubscribeConsent = onConsentChange(apply);
70
+ // A client-side router can replace the footer between pages, so new entries are revealed as they appear.
71
+ let observer;
72
+ try {
73
+ observer = typeof MutationObserver === 'function' ? new MutationObserver(apply) : undefined;
74
+ observer?.observe(document.body, { childList: true, subtree: true });
75
+ }
76
+ catch {
77
+ observer = undefined;
78
+ }
79
+ return () => {
80
+ unsubscribeRegion();
81
+ unsubscribeConsent();
82
+ observer?.disconnect();
83
+ };
84
+ }
45
85
  /** Shows the current choice in the panel, using the copy carried on the choice line. */
46
86
  function reflectChoice(panel) {
47
87
  const decision = getConsent().analytics;
@@ -59,9 +99,10 @@ function reflectChoice(panel) {
59
99
  }
60
100
  /**
61
101
  * Mounts the popup inside `root` (the `[data-hagilight-consent]` section). Returns a function that removes the listeners.
62
- * With no panel, or where the visitor already decided or consent is not required, the panel stays hidden.
102
+ * With no panel, or where the visitor already decided, the panel stays hidden. An undecided visitor sees it once the
103
+ * region decision is `required` or `unknown`, and never for `notRequired` or while the decision is pending.
63
104
  */
64
- export function mountConsentPopup(root = document) {
105
+ export function mountConsentPopup(root = document, region = pageRegionSource()) {
65
106
  const panel = root.querySelector('[data-hagilight-consent]');
66
107
  if (!panel)
67
108
  return noop;
@@ -69,6 +110,13 @@ export function mountConsentPopup(root = document) {
69
110
  if (panel.dataset.consentMounted === 'true')
70
111
  return noop;
71
112
  panel.dataset.consentMounted = 'true';
113
+ // The decision is resolved once per document. A page that never started it gets it started here.
114
+ startRegionResolution(currentRegionConfig());
115
+ const stopRevealingEntries = revealConsentEntries(region);
116
+ const main = panel.querySelector('[data-consent-main]');
117
+ const replay = panel.querySelector('[data-hagilight-consent-replay]');
118
+ const replayAllow = panel.querySelector('[data-consent-replay-allow]');
119
+ const replayDecline = panel.querySelector('[data-consent-replay-decline]');
72
120
  // Move the popup to the end of the body. Site layouts can isolate their content (Starlight's main pane does), which
73
121
  // would trap a z-index of 45 inside that pane, under fixed side panels. In the root stacking context it stays on top.
74
122
  const host = panel.closest('.hagilight-consent-host') ?? panel;
@@ -109,12 +157,22 @@ export function mountConsentPopup(root = document) {
109
157
  leaving = undefined;
110
158
  });
111
159
  };
112
- const show = () => {
160
+ /** Shows the main choice, or the replay opt-in section when `mode` is `replay` and the site offers that section. */
161
+ const show = (mode = 'main') => {
113
162
  if (leaving) {
114
163
  leaving.cancel();
115
164
  leaving = undefined;
116
165
  }
117
166
  delete panel.dataset.leaving;
167
+ const replayMode = mode === 'replay' && replay !== null;
168
+ if (main)
169
+ main.hidden = replayMode;
170
+ if (replay)
171
+ replay.hidden = !replayMode;
172
+ if (replayMode)
173
+ panel.dataset.mode = 'replay';
174
+ else
175
+ delete panel.dataset.mode;
118
176
  reflectChoice(panel);
119
177
  panel.hidden = false;
120
178
  publishClearance(panel);
@@ -123,6 +181,9 @@ export function mountConsentPopup(root = document) {
123
181
  setConsent({ analytics });
124
182
  hide();
125
183
  };
184
+ /** Allow stores an explicit grant, which also turns replay on. Not now stores nothing and only closes the panel. */
185
+ const onReplayAllow = () => choose(true);
186
+ const onReplayDecline = () => hide();
126
187
  const onAccept = () => choose(true);
127
188
  const onReject = () => choose(false);
128
189
  const onToggle = () => {
@@ -166,16 +227,28 @@ export function mountConsentPopup(root = document) {
166
227
  section.style.overflow = '';
167
228
  });
168
229
  };
169
- const onPreferences = () => show();
170
- /** The footer's "Cookie settings" entries call `openConsentPreferences()`; the popup's own listener then shows the panel. */
230
+ const onPreferences = (event) => {
231
+ const detail = event.detail;
232
+ show(detail?.mode === 'replay' ? 'replay' : 'main');
233
+ };
234
+ /**
235
+ * The footer's entries call `openConsentPreferences()`. An entry marked `data-consent-mode="replay"` asks for the
236
+ * replay opt-in section; the popup's own listener then shows it.
237
+ */
171
238
  const onFooterEntry = (event) => {
172
239
  const target = event.target;
173
- if (target instanceof Element && target.closest('[data-consent-preferences]'))
174
- openConsentPreferences();
240
+ if (!(target instanceof Element))
241
+ return;
242
+ const entry = target.closest('[data-consent-preferences]');
243
+ if (!entry)
244
+ return;
245
+ openConsentPreferences(entry.dataset.consentMode === 'replay' ? 'replay' : undefined);
175
246
  };
176
247
  accept?.addEventListener('click', onAccept);
177
248
  reject?.addEventListener('click', onReject);
178
249
  toggle?.addEventListener('click', onToggle);
250
+ replayAllow?.addEventListener('click', onReplayAllow);
251
+ replayDecline?.addEventListener('click', onReplayDecline);
179
252
  document.addEventListener(CONSENT_PREFERENCES_EVENT, onPreferences);
180
253
  document.addEventListener('click', onFooterEntry);
181
254
  let observer;
@@ -186,16 +259,33 @@ export function mountConsentPopup(root = document) {
186
259
  catch {
187
260
  observer = undefined;
188
261
  }
189
- if (getConsent().analytics === 'undecided' && isConsentRequired())
190
- show();
191
- else
192
- hide();
262
+ /**
263
+ * An undecided visitor sees the popup once the region decision is `required` or `unknown`. A decided visitor never
264
+ * does. The decision arrives through `region`, and a deadline timeout resolves to `required`, so the popup is shown
265
+ * exactly once for those cases.
266
+ */
267
+ const applyDecision = () => {
268
+ if (getConsent().analytics !== 'undecided') {
269
+ hide();
270
+ return;
271
+ }
272
+ const decision = region.current();
273
+ if (decision === 'required' || decision === 'unknown')
274
+ show();
275
+ else
276
+ hide();
277
+ };
278
+ const unsubscribeRegion = region.subscribe(applyDecision);
193
279
  return () => {
194
280
  leaving?.cancel();
195
281
  sliding?.cancel();
282
+ unsubscribeRegion();
283
+ stopRevealingEntries();
196
284
  accept?.removeEventListener('click', onAccept);
197
285
  reject?.removeEventListener('click', onReject);
198
286
  toggle?.removeEventListener('click', onToggle);
287
+ replayAllow?.removeEventListener('click', onReplayAllow);
288
+ replayDecline?.removeEventListener('click', onReplayDecline);
199
289
  document.removeEventListener(CONSENT_PREFERENCES_EVENT, onPreferences);
200
290
  document.removeEventListener('click', onFooterEntry);
201
291
  observer?.disconnect();
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Region decision (`@hagicode/hagilight-core/consent-region`). It answers one question for the visitor: does this
3
+ * visitor need an analytics decision before providers start? The answer is one of `required`, `notRequired` or
4
+ * `unknown`. Every consumer treats `unknown` exactly like `required`, so a visitor whose location cannot be identified
5
+ * gets the consent popup and no provider.
6
+ *
7
+ * Sources are consulted in a fixed order: the site's `countryCode`, the site's `regionHook`, the same-origin
8
+ * `/cdn-cgi/trace` endpoint (only its `loc` line), and a coarse time-zone fallback. The whole resolution is bounded by
9
+ * a deadline that falls back to `required`. No visitor IP address leaves the page, and no location request goes to any
10
+ * host other than the page's own origin. The module never throws and never writes storage.
11
+ */
12
+ export type RegionDecision = 'required' | 'notRequired' | 'unknown';
13
+ /** `default` applies the built-in country set; an array replaces it entirely. Absent means regional behavior is off. */
14
+ export type RegionsOption = 'default' | readonly string[];
15
+ export interface RegionConfig {
16
+ regions?: RegionsOption;
17
+ /** An explicit ISO 3166-1 alpha-2 code. Present but invalid resolves to `unknown` without consulting other sources. */
18
+ countryCode?: string;
19
+ /** Resolved by name by the integration. A missing function yields `unknown` when it is called. */
20
+ regionHook?: () => unknown;
21
+ }
22
+ /** Test seams. The page supplies the defaults from `pageRegionEnvironment()`. */
23
+ export interface RegionEnvironment {
24
+ /** The page URL. Absent means there is no page, so a configured decision is `unknown`. */
25
+ href?: string;
26
+ fetch?: (input: string, init: RequestInit) => Promise<Response>;
27
+ /** Returns the time-zone identifier. A throw or a non-string is treated as unreadable. */
28
+ timeZone?: () => unknown;
29
+ traceTimeoutMs?: number;
30
+ deadlineMs?: number;
31
+ /** Where the once-per-document resolution is stored. The page uses `window`. */
32
+ holder?: RegionHolder;
33
+ }
34
+ export interface RegionHolder {
35
+ __hagilightRegion?: RegionShared;
36
+ }
37
+ interface RegionShared {
38
+ decision?: RegionDecision;
39
+ promise?: Promise<RegionDecision>;
40
+ listeners: Set<(decision: RegionDecision) => void>;
41
+ }
42
+ export interface RegionSource {
43
+ /** The decision, or `pending` until resolution completes. */
44
+ current(): RegionDecision | 'pending';
45
+ /** Calls `listener` once the decision exists, immediately when it already does. Returns an unsubscribe function. */
46
+ subscribe(listener: (decision: RegionDecision) => void): () => void;
47
+ }
48
+ export declare const TRACE_PATH = "/cdn-cgi/trace";
49
+ /** Abandons the trace request early so the time-zone fallback still runs before the deadline. */
50
+ export declare const TRACE_TIMEOUT_MS = 1200;
51
+ /** The trace body is read only this far. The real body is a few hundred bytes. */
52
+ export declare const TRACE_MAX_BYTES = 4096;
53
+ /** The whole resolution. A hung source leaves the decision at `required` when this passes. */
54
+ export declare const RESOLUTION_DEADLINE_MS = 1800;
55
+ /** The default consent-required set: EU27, EEA (IS, LI, NO), GB, CH and BR. A product configuration, not a legal finding. */
56
+ export declare const DEFAULT_REQUIRED_COUNTRIES: readonly string[];
57
+ /** True only for an upper-case, officially assigned ISO 3166-1 alpha-2 code. */
58
+ export declare function isAssignedCountryCode(value: unknown): value is string;
59
+ /** The country set a configuration selects. An absent or `default` option uses the built-in set. */
60
+ export declare function requiredCountrySet(regions: RegionsOption | undefined): ReadonlySet<string>;
61
+ /** Maps a valid country to `required` or `notRequired` under the selected set. */
62
+ export declare function decisionForCountry(country: string, set: ReadonlySet<string>): RegionDecision;
63
+ /**
64
+ * The time-zone fallback. Europe and the listed EU/EEA/Brazil/French-territory zones require consent. Other Americas,
65
+ * Asia, Australia and Pacific zones do not. Anything else, including UTC, an empty or missing identifier and an
66
+ * unreadable clock, is `unknown`, which requires consent.
67
+ */
68
+ export declare function classifyTimeZone(timeZone: unknown): RegionDecision;
69
+ /** Reads the `loc` line of a trace body. Only that line is used. The IP line is never returned. */
70
+ export declare function parseTraceCountry(body: string): string | undefined;
71
+ /**
72
+ * Adapts a custom hook result. A state is taken as it is, a boolean maps to `notRequired` for `false` and `required`
73
+ * for `true`, and anything else is `unknown`. A throw or a rejected promise is `unknown`.
74
+ */
75
+ export declare function adaptHookValue(value: unknown): RegionDecision;
76
+ /**
77
+ * Resolves one visitor's decision. Without a regional configuration or a hook the answer is `required` with no request and no time
78
+ * read. Without a page URL or `fetch`, a configured decision is `unknown`. Otherwise the sources run, bounded by the
79
+ * deadline, which resolves to `required`. A late source answer does not change the result. The function never rejects.
80
+ */
81
+ export declare function resolveRegionDecision(config: RegionConfig, env?: RegionEnvironment): Promise<RegionDecision>;
82
+ /** The page environment: the page URL, `window.fetch` and `window` as the once-per-document holder. Empty without a window. */
83
+ export declare function pageRegionEnvironment(): RegionEnvironment;
84
+ /**
85
+ * Starts the resolution at most once per document and returns its promise. Later calls, including from another bundle
86
+ * on the same page, share the first one. The decision is announced to listeners exactly once.
87
+ */
88
+ export declare function startRegionResolution(config: RegionConfig, env?: RegionEnvironment): Promise<RegionDecision>;
89
+ /** The decision, or `pending` until resolution completes or when it was never started. */
90
+ export declare function getRegionDecision(env?: RegionEnvironment): RegionDecision | 'pending';
91
+ /** Calls `listener` with the decision: now when it exists, otherwise once it resolves. Returns an unsubscribe function. */
92
+ export declare function onRegionDecision(listener: (decision: RegionDecision) => void, env?: RegionEnvironment): () => void;
93
+ /** The page-backed source the gate and the popup read. It has no state of its own. */
94
+ export declare function pageRegionSource(env?: RegionEnvironment): RegionSource;
95
+ export {};