non-spooky-react-cookie 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/LICENSE +21 -0
- package/README.md +577 -0
- package/dist/index.cjs +856 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +137 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.js +837 -0
- package/dist/index.js.map +1 -0
- package/dist/resolve-texts-yAIbWOUX.d.cts +456 -0
- package/dist/resolve-texts-yAIbWOUX.d.ts +456 -0
- package/dist/server.cjs +26 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +28 -0
- package/dist/server.d.ts +28 -0
- package/dist/server.js +23 -0
- package/dist/server.js.map +1 -0
- package/dist/storage-Cqed-yMR.cjs +373 -0
- package/dist/storage-Cqed-yMR.cjs.map +1 -0
- package/dist/storage-WH-kuxkg.js +296 -0
- package/dist/storage-WH-kuxkg.js.map +1 -0
- package/dist/styles.css +624 -0
- package/package.json +119 -0
- package/server/README.md +25 -0
- package/server/package.json +5 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Makes every property of an object (and nested objects) optional.
|
|
5
|
+
* Used so users can override only the texts they care about.
|
|
6
|
+
*/
|
|
7
|
+
type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]; };
|
|
8
|
+
/**
|
|
9
|
+
* `DeepPartial` that also accepts `null` at every level. A CMS usually returns
|
|
10
|
+
* an empty field as `null` (Payload's generated types say `string | null`), and
|
|
11
|
+
* the merge treats `null` exactly like a missing key: the built-in text stays.
|
|
12
|
+
*/
|
|
13
|
+
type DeepPartialNullable<T> = { [K in keyof T]?: T[K] extends object ? DeepPartialNullable<T[K]> | null : T[K] | null; };
|
|
14
|
+
/** A single fine-grained entry inside a category, e.g. "Meta Pixel" inside Marketing. */
|
|
15
|
+
type PreferenceItem = {
|
|
16
|
+
/** Must be unique across all categories and items of the app. */
|
|
17
|
+
id: string;
|
|
18
|
+
/** Shown in the settings dialog. Can also come from `texts.categories[<categoryId>].items[<id>].title`. */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Shown under the item title. Can also come from `texts`. */
|
|
21
|
+
description?: string;
|
|
22
|
+
};
|
|
23
|
+
/** A group of optional technologies. May contain fine-grained `items`. */
|
|
24
|
+
type PreferenceCategory = {
|
|
25
|
+
/** Unique id, e.g. "necessary", "analytics", "marketing". */
|
|
26
|
+
id: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
/** Always accepted and cannot be switched off (e.g. "necessary"). */
|
|
30
|
+
required?: boolean;
|
|
31
|
+
/** Optional fine-grained entries inside this category. */
|
|
32
|
+
items?: PreferenceItem[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A single category inside `ConsentConfig.categories`.
|
|
36
|
+
* The key of the map is the category id (e.g. "analytics").
|
|
37
|
+
*/
|
|
38
|
+
type ConsentCategoryConfig = {
|
|
39
|
+
/** Always accepted and cannot be switched off (e.g. "necessary"). */
|
|
40
|
+
required?: boolean;
|
|
41
|
+
/** Display name, e.g. "Analytics". */
|
|
42
|
+
name?: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
/** Optional fine-grained entries, keyed by item id. */
|
|
45
|
+
items?: Record<string, ConsentItemConfig>;
|
|
46
|
+
};
|
|
47
|
+
type ConsentItemConfig = {
|
|
48
|
+
name?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Declares the consent categories your site uses.
|
|
53
|
+
* Example:
|
|
54
|
+
* ```ts
|
|
55
|
+
* const consentConfig: ConsentConfig = {
|
|
56
|
+
* categories: {
|
|
57
|
+
* necessary: { required: true },
|
|
58
|
+
* analytics: { name: "Analytics" },
|
|
59
|
+
* marketing: { name: "Marketing" },
|
|
60
|
+
* },
|
|
61
|
+
* };
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
type ConsentConfig = {
|
|
65
|
+
categories: Record<string, ConsentCategoryConfig>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A third-party script managed by the provider.
|
|
69
|
+
* The script is loaded only when `category` (a category id or an item id)
|
|
70
|
+
* is accepted, and unloaded when consent is withdrawn.
|
|
71
|
+
*
|
|
72
|
+
* The script id is the key in the `scripts` map (not a field here) — it is
|
|
73
|
+
* used as the `<script>` element id and for deduplication.
|
|
74
|
+
*/
|
|
75
|
+
type ConsentScript = {
|
|
76
|
+
/** Category id (or item id) that must be accepted before the script loads. */
|
|
77
|
+
category: string;
|
|
78
|
+
/** URL of the script. Omit for inline scripts (`children`). */
|
|
79
|
+
src?: string;
|
|
80
|
+
/** Inline script body. */
|
|
81
|
+
children?: string;
|
|
82
|
+
/** Extra attributes, e.g. `{ "data-foo": "bar" }`. */
|
|
83
|
+
attrs?: Record<string, string>;
|
|
84
|
+
/** Set `script.async`. Wins over `defer` when both are set. */
|
|
85
|
+
async?: boolean;
|
|
86
|
+
/** Set `script.defer`. Ignored when `async` is set. */
|
|
87
|
+
defer?: boolean;
|
|
88
|
+
/** Called after the script finished loading. */
|
|
89
|
+
onLoad?: () => void;
|
|
90
|
+
/** Called when the script failed to load. */
|
|
91
|
+
onError?: () => void;
|
|
92
|
+
/**
|
|
93
|
+
* Runs when consent is withdrawn and the script is removed.
|
|
94
|
+
* Use it to undo side effects (e.g. `delete window.fbq`).
|
|
95
|
+
*/
|
|
96
|
+
cleanup?: () => void;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The provider's `scripts` map: third-party scripts keyed by script id.
|
|
100
|
+
* Use this ready-made type instead of spelling out `Record<string, ConsentScript>`.
|
|
101
|
+
*/
|
|
102
|
+
type ConsentScripts = Record<string, ConsentScript>;
|
|
103
|
+
type ItemTexts = {
|
|
104
|
+
title?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
};
|
|
107
|
+
type CategoryTexts = {
|
|
108
|
+
title?: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
items?: Record<string, ItemTexts>;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* All UI strings of the library. Every field is typed, so when you
|
|
114
|
+
* extend or override texts you get full autocomplete and type safety.
|
|
115
|
+
*/
|
|
116
|
+
type Texts = {
|
|
117
|
+
banner: {
|
|
118
|
+
title: string;
|
|
119
|
+
description: string;
|
|
120
|
+
acceptAll: string;
|
|
121
|
+
rejectAll: string;
|
|
122
|
+
settings: string;
|
|
123
|
+
policyLink: string;
|
|
124
|
+
};
|
|
125
|
+
dialog: {
|
|
126
|
+
title: string;
|
|
127
|
+
description: string;
|
|
128
|
+
save: string;
|
|
129
|
+
close: string;
|
|
130
|
+
/**
|
|
131
|
+
* Label of the collapsible trigger that reveals a category's items, e.g.
|
|
132
|
+
* "Show services". The item count follows in parentheses: "Show services (2)".
|
|
133
|
+
*/
|
|
134
|
+
itemsLabel: string;
|
|
135
|
+
};
|
|
136
|
+
footerLink: string;
|
|
137
|
+
/** Per-category and per-item texts, keyed by their ids. */
|
|
138
|
+
categories: Record<string, CategoryTexts>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* The provider's `texts` prop: override any built-in string. Every field is
|
|
142
|
+
* optional, so you list only what you want to change, and `null` counts as
|
|
143
|
+
* not set. Every value is plain JSON, so it can come from a CMS or be passed
|
|
144
|
+
* from a React Server Component.
|
|
145
|
+
*/
|
|
146
|
+
type TextOverrides = DeepPartialNullable<Texts>;
|
|
147
|
+
/**
|
|
148
|
+
* Color palette. Provide any subset; everything else keeps the built-in look.
|
|
149
|
+
*
|
|
150
|
+
* Only five colors are true inputs: `primaryColor`, `primaryTextColor`,
|
|
151
|
+
* `accentColor`, `surfaceColor` and `textColor`. Every other color is derived
|
|
152
|
+
* from those with `color-mix()` unless you set it, so a dark surface with light
|
|
153
|
+
* text automatically gets matching muted text, borders, secondary buttons,
|
|
154
|
+
* hover states and switch tracks.
|
|
155
|
+
*/
|
|
156
|
+
type ThemePalette = {
|
|
157
|
+
/** Main action color (primary buttons, active switches). */
|
|
158
|
+
primaryColor?: string;
|
|
159
|
+
/** Text color on primary buttons. Also the switch thumb color when on. */
|
|
160
|
+
primaryTextColor?: string;
|
|
161
|
+
/** Primary button hover background. Derived from primary + primary text. */
|
|
162
|
+
primaryHoverColor?: string;
|
|
163
|
+
/** Secondary button background. Derived: same as `surfaceColor`. */
|
|
164
|
+
secondaryColor?: string;
|
|
165
|
+
/** Text color on secondary buttons. Derived: same as `textColor`. */
|
|
166
|
+
secondaryTextColor?: string;
|
|
167
|
+
/** Accent color (links, disclosure triggers). */
|
|
168
|
+
accentColor?: string;
|
|
169
|
+
/** Background of the banner and dialog. */
|
|
170
|
+
surfaceColor?: string;
|
|
171
|
+
/** Background of the required-category card and button hover states. Derived from surface + text. */
|
|
172
|
+
surfaceMutedColor?: string;
|
|
173
|
+
/** Main text color. */
|
|
174
|
+
textColor?: string;
|
|
175
|
+
/** Muted/secondary text color. Derived from text + surface. */
|
|
176
|
+
mutedTextColor?: string;
|
|
177
|
+
/** Border color. Derived from text + surface. */
|
|
178
|
+
borderColor?: string;
|
|
179
|
+
/** Focus ring color. Derived: same as `primaryColor`. */
|
|
180
|
+
ringColor?: string;
|
|
181
|
+
/** Switch track color when off. Derived from text + surface. */
|
|
182
|
+
switchOffColor?: string;
|
|
183
|
+
/** Switch thumb color for both states. Derived: `surfaceColor` when off, `primaryTextColor` when on. */
|
|
184
|
+
switchThumbColor?: string;
|
|
185
|
+
/** Dialog backdrop (dim layer behind the settings dialog). */
|
|
186
|
+
backdropColor?: string;
|
|
187
|
+
};
|
|
188
|
+
/** What is persisted (localStorage and/or cookie) and shared with `onDecision`. */
|
|
189
|
+
type PreferencesState = {
|
|
190
|
+
version: string;
|
|
191
|
+
updatedAt: string;
|
|
192
|
+
/** Flat map of accepted ids: categories and items. */
|
|
193
|
+
accepted: Record<string, boolean>;
|
|
194
|
+
};
|
|
195
|
+
/** Partial update of the accepted map. */
|
|
196
|
+
type PreferencesUpdate = {
|
|
197
|
+
accepted: Record<string, boolean>;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Built-in storage strategies:
|
|
201
|
+
* - `"localStorage"` (default) – per-origin, invisible to the server.
|
|
202
|
+
* - `"cookie"` – readable by the server (see `readPreferencesFromCookies`),
|
|
203
|
+
* can span subdomains via `cookieOptions.domain`.
|
|
204
|
+
* - `"both"` – writes to both; reads the cookie first, then localStorage.
|
|
205
|
+
*/
|
|
206
|
+
type StorageKind = "localStorage" | "cookie" | "both";
|
|
207
|
+
/**
|
|
208
|
+
* Storage strategy: a plain string store keyed by `storageKey`. The library
|
|
209
|
+
* handles JSON serialization and validation, so an adapter never sees the
|
|
210
|
+
* state shape. Pass your own to persist anywhere (sessionStorage, IndexedDB
|
|
211
|
+
* wrapper, in-memory for tests, ...).
|
|
212
|
+
*/
|
|
213
|
+
type PreferencesStorage = {
|
|
214
|
+
get(key: string): string | null;
|
|
215
|
+
set(key: string, value: string): void;
|
|
216
|
+
remove(key: string): void;
|
|
217
|
+
};
|
|
218
|
+
/** Cookie attributes used by the `"cookie"` and `"both"` strategies. */
|
|
219
|
+
type CookieStorageOptions = {
|
|
220
|
+
/** Lifetime in seconds. Default: 31536000 (365 days). */
|
|
221
|
+
maxAge?: number;
|
|
222
|
+
/** e.g. `".example.com"` to share the decision across subdomains. Default: current host. */
|
|
223
|
+
domain?: string;
|
|
224
|
+
/** Default: `"/"`. */
|
|
225
|
+
path?: string;
|
|
226
|
+
/** Default: `"lax"`. `"none"` forces `secure`. */
|
|
227
|
+
sameSite?: "lax" | "strict" | "none";
|
|
228
|
+
/** Default: `true` on https, `false` otherwise. */
|
|
229
|
+
secure?: boolean;
|
|
230
|
+
};
|
|
231
|
+
/** Button-like props shared by the default and custom Button components. */
|
|
232
|
+
type ButtonLikeProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
233
|
+
variant?: "primary" | "secondary" | "ghost";
|
|
234
|
+
};
|
|
235
|
+
/** Switch-like props shared by the default and custom Switch components. */
|
|
236
|
+
type SwitchLikeProps = {
|
|
237
|
+
checked: boolean;
|
|
238
|
+
disabled?: boolean;
|
|
239
|
+
onCheckedChange: (checked: boolean) => void;
|
|
240
|
+
"aria-label": string;
|
|
241
|
+
};
|
|
242
|
+
/** Props of the default Collapsible (a controlled or self-managed disclosure). */
|
|
243
|
+
type CollapsibleProps = {
|
|
244
|
+
children: React.ReactNode;
|
|
245
|
+
/** Number of entries inside, shown after the label, e.g. "(2)". */
|
|
246
|
+
count: number;
|
|
247
|
+
/** Localized trigger label, e.g. "Show services" / "Dienste anzeigen". */
|
|
248
|
+
label: string;
|
|
249
|
+
/** Controlled open state. Omit to let the component manage its own state. */
|
|
250
|
+
open?: boolean;
|
|
251
|
+
/** Fired when the disclosure is toggled (controlled mode). */
|
|
252
|
+
onOpenChange?: (open: boolean) => void;
|
|
253
|
+
/** Initial open state when uncontrolled. Default: `false`. */
|
|
254
|
+
defaultOpen?: boolean;
|
|
255
|
+
/** Extra classes for the trigger button. */
|
|
256
|
+
className?: string;
|
|
257
|
+
/** Extra classes for the revealed content region. */
|
|
258
|
+
contentClassName?: string;
|
|
259
|
+
};
|
|
260
|
+
/** Escape hatch: swap the default Button/Switch/Collapsible for your own components. */
|
|
261
|
+
type PreferenceComponents = {
|
|
262
|
+
Button?: React.ComponentType<ButtonLikeProps>;
|
|
263
|
+
Switch?: React.ComponentType<SwitchLikeProps>;
|
|
264
|
+
Collapsible?: React.ComponentType<CollapsibleProps>;
|
|
265
|
+
};
|
|
266
|
+
type CookieBannerConfigurationProviderProps = {
|
|
267
|
+
children: React.ReactNode;
|
|
268
|
+
/**
|
|
269
|
+
* Consent category configuration (object map, keyed by category id).
|
|
270
|
+
* Defaults to necessary/preferences/analytics/marketing.
|
|
271
|
+
*/
|
|
272
|
+
config?: ConsentConfig;
|
|
273
|
+
/**
|
|
274
|
+
* Third-party scripts managed by the provider, keyed by script id.
|
|
275
|
+
* Each loads only when its `category` is accepted and is removed (with
|
|
276
|
+
* `cleanup`) when consent is withdrawn.
|
|
277
|
+
*/
|
|
278
|
+
scripts?: ConsentScripts;
|
|
279
|
+
/**
|
|
280
|
+
* Language of the built-in texts: "en" (default), "de", or "pl". Region
|
|
281
|
+
* codes resolve to their base language ("pl-PL" -> "pl"); anything else
|
|
282
|
+
* falls back to English.
|
|
283
|
+
*/
|
|
284
|
+
language?: string;
|
|
285
|
+
/** Override or extend any built-in text. Fully typed. */
|
|
286
|
+
texts?: TextOverrides;
|
|
287
|
+
/**
|
|
288
|
+
* Color palette override. Applied to the banner, the dialog and the
|
|
289
|
+
* settings link in both light and dark mode (unless `darkTheme` overrides
|
|
290
|
+
* a color for dark mode).
|
|
291
|
+
*/
|
|
292
|
+
theme?: ThemePalette;
|
|
293
|
+
/**
|
|
294
|
+
* Colors that apply only under a `.dark` or `[data-theme="dark"]`
|
|
295
|
+
* ancestor. Any color not set here falls back to `theme`, then to the
|
|
296
|
+
* built-in dark palette.
|
|
297
|
+
*/
|
|
298
|
+
darkTheme?: ThemePalette;
|
|
299
|
+
/** Swap the default Button/Switch/Collapsible for your own components. */
|
|
300
|
+
components?: PreferenceComponents;
|
|
301
|
+
/** Storage key: the localStorage key and/or cookie name. Default: "non-spooky-react-cookie". */
|
|
302
|
+
storageKey?: string;
|
|
303
|
+
/**
|
|
304
|
+
* Where the decision is persisted: `"localStorage"` (default), `"cookie"`,
|
|
305
|
+
* `"both"`, or a custom `PreferencesStorage` adapter. A custom adapter must
|
|
306
|
+
* be a stable reference (module-level const or `useMemo`), not an inline
|
|
307
|
+
* object literal.
|
|
308
|
+
*/
|
|
309
|
+
storage?: StorageKind | PreferencesStorage;
|
|
310
|
+
/** Cookie attributes, used when `storage` is `"cookie"` or `"both"`. */
|
|
311
|
+
cookieOptions?: CookieStorageOptions;
|
|
312
|
+
/**
|
|
313
|
+
* Decision read on the server (see `readPreferencesFromCookies`). When
|
|
314
|
+
* given — even as `null` — the first render is already `loaded`, so server
|
|
315
|
+
* and client markup match and the banner does not flash. After mount the
|
|
316
|
+
* client storage is re-read and wins.
|
|
317
|
+
*/
|
|
318
|
+
initialPreferences?: PreferencesState | null;
|
|
319
|
+
/** Bump this to ask visitors again. Default: "1". */
|
|
320
|
+
version?: string;
|
|
321
|
+
/**
|
|
322
|
+
* Keep Google consent mode (`gtag("consent", ...)`) in sync with the
|
|
323
|
+
* `analytics` / `marketing` categories. Creates the `window.gtag` stub,
|
|
324
|
+
* so enable it only when you load Google tags. Default: `false`.
|
|
325
|
+
*/
|
|
326
|
+
googleConsentMode?: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Register `window.justDont()`: a global that rejects all optional
|
|
329
|
+
* categories (required ones stay on, the banner closes, managed scripts
|
|
330
|
+
* unload) — handy for console snippets and "I don't care about cookies"-
|
|
331
|
+
* style browser extensions. Client-only. Enabled by default; pass
|
|
332
|
+
* `false` to opt out. The last mounted provider owns the global.
|
|
333
|
+
*/
|
|
334
|
+
windowJustDont?: boolean;
|
|
335
|
+
/**
|
|
336
|
+
* Honor the browser's Global Privacy Control signal
|
|
337
|
+
* (`navigator.globalPrivacyControl === true`, sent as `Sec-GPC: 1`). When
|
|
338
|
+
* a visitor with the signal on has no stored decision for the current
|
|
339
|
+
* `version`, the provider behaves as if they clicked "Reject all": required
|
|
340
|
+
* categories stay on, optional ones stay off, the banner never shows and
|
|
341
|
+
* `onDecision` fires. The decision is not persisted, because the signal is
|
|
342
|
+
* live: turning it off brings the banner back. A decision the visitor
|
|
343
|
+
* already made on this site always wins over the signal, and they can
|
|
344
|
+
* still opt in through the settings dialog. Enabled by default; pass
|
|
345
|
+
* `false` to opt out.
|
|
346
|
+
*/
|
|
347
|
+
respectGlobalPrivacyControl?: boolean;
|
|
348
|
+
/** Called whenever the visitor makes or changes their choice. */
|
|
349
|
+
onDecision?: (state: PreferencesState) => void;
|
|
350
|
+
};
|
|
351
|
+
type CookieBannerContextValue = {
|
|
352
|
+
loaded: boolean;
|
|
353
|
+
hasDecision: boolean;
|
|
354
|
+
showBanner: boolean;
|
|
355
|
+
/**
|
|
356
|
+
* `true` when `respectGlobalPrivacyControl` is on and the browser sent an
|
|
357
|
+
* active Global Privacy Control signal for this page load. Use it to tell
|
|
358
|
+
* the visitor their browser setting was honored.
|
|
359
|
+
*/
|
|
360
|
+
globalPrivacyControl: boolean;
|
|
361
|
+
settingsOpen: boolean;
|
|
362
|
+
preferences: PreferencesState;
|
|
363
|
+
texts: Texts;
|
|
364
|
+
categories: PreferenceCategory[];
|
|
365
|
+
/** The `scripts` map the provider was given, keyed by script id. */
|
|
366
|
+
scripts: ConsentScripts;
|
|
367
|
+
theme: ThemePalette;
|
|
368
|
+
darkTheme: ThemePalette;
|
|
369
|
+
components: PreferenceComponents;
|
|
370
|
+
/**
|
|
371
|
+
* `theme` as inline CSS custom properties. Kept for custom elements that
|
|
372
|
+
* only need the light palette; prefer spreading `themeAttributes` so the
|
|
373
|
+
* element also picks up `darkTheme`.
|
|
374
|
+
*/
|
|
375
|
+
themeStyle: React.CSSProperties;
|
|
376
|
+
/**
|
|
377
|
+
* Marker attribute that scopes the provider's theme rules to an element.
|
|
378
|
+
* Spread it onto any element of your own that uses `--nsr-*` variables.
|
|
379
|
+
*/
|
|
380
|
+
themeAttributes: Record<`data-${string}`, string>;
|
|
381
|
+
acceptAll: () => void;
|
|
382
|
+
rejectAll: () => void;
|
|
383
|
+
savePreferences: (partial: PreferencesUpdate) => void;
|
|
384
|
+
resetPreferences: () => void;
|
|
385
|
+
openSettings: () => void;
|
|
386
|
+
closeSettings: () => void;
|
|
387
|
+
/** True when the category or item id is accepted. Items are independent of their parent category. */
|
|
388
|
+
isAllowed: (id: string) => boolean;
|
|
389
|
+
/** Resolves the display title/description for a category or item id. */
|
|
390
|
+
resolveLabel: (id: string, config?: {
|
|
391
|
+
title?: string;
|
|
392
|
+
description?: string;
|
|
393
|
+
}) => {
|
|
394
|
+
title: string;
|
|
395
|
+
description: string;
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
type CookieBannerProps = {
|
|
399
|
+
/** URL of your privacy policy page. */
|
|
400
|
+
policyUrl?: string;
|
|
401
|
+
/** Root element classes. */
|
|
402
|
+
className?: string;
|
|
403
|
+
/** Inner card classes. */
|
|
404
|
+
contentClassName?: string;
|
|
405
|
+
/** Title classes. */
|
|
406
|
+
titleClassName?: string;
|
|
407
|
+
/** Description classes. */
|
|
408
|
+
descriptionClassName?: string;
|
|
409
|
+
/** Button group classes. */
|
|
410
|
+
actionsClassName?: string;
|
|
411
|
+
/** Extra classes applied to every button. */
|
|
412
|
+
buttonClassName?: string;
|
|
413
|
+
/**
|
|
414
|
+
* Swap the default components for the banner and the dialog it renders.
|
|
415
|
+
* Wins over the provider's `components`; `dialogProps.components` wins
|
|
416
|
+
* over this for the dialog only.
|
|
417
|
+
*/
|
|
418
|
+
components?: PreferenceComponents;
|
|
419
|
+
/**
|
|
420
|
+
* Props forwarded to the settings dialog that `CookieBanner` renders for
|
|
421
|
+
* you (class names for its parts). Use this instead of rendering a second
|
|
422
|
+
* `CookieSettingsDialog`.
|
|
423
|
+
*/
|
|
424
|
+
dialogProps?: CookieSettingsDialogProps;
|
|
425
|
+
};
|
|
426
|
+
type CookieSettingsDialogProps = {
|
|
427
|
+
className?: string;
|
|
428
|
+
overlayClassName?: string;
|
|
429
|
+
contentClassName?: string;
|
|
430
|
+
headerClassName?: string;
|
|
431
|
+
bodyClassName?: string;
|
|
432
|
+
footerClassName?: string;
|
|
433
|
+
categoryCardClassName?: string;
|
|
434
|
+
itemClassName?: string;
|
|
435
|
+
buttonClassName?: string;
|
|
436
|
+
/** Swap the default components for this dialog. Wins over the provider's `components`. */
|
|
437
|
+
components?: PreferenceComponents;
|
|
438
|
+
};
|
|
439
|
+
type CookieSettingsLinkProps = React.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/resolve-texts.d.ts
|
|
442
|
+
/** The languages that ship with built-in texts. Anything else gets English. */
|
|
443
|
+
declare const BUILT_IN_LANGUAGES: readonly ["en", "de", "pl"];
|
|
444
|
+
type BuiltInLanguage = (typeof BUILT_IN_LANGUAGES)[number];
|
|
445
|
+
/**
|
|
446
|
+
* The built-in texts for a language code. Matching ignores case, and a
|
|
447
|
+
* region or script suffix falls back to the base language ("pl-PL" and
|
|
448
|
+
* "de_AT" resolve to "pl" and "de"). Unknown languages get English.
|
|
449
|
+
*
|
|
450
|
+
* The result is plain JSON, so it is safe to use on the server, e.g. as the
|
|
451
|
+
* default values of CMS fields.
|
|
452
|
+
*/
|
|
453
|
+
declare function getBuiltInTexts(language?: string): Texts;
|
|
454
|
+
//#endregion
|
|
455
|
+
export { Texts as A, PreferenceItem as C, StorageKind as D, PreferencesUpdate as E, SwitchLikeProps as O, PreferenceComponents as S, PreferencesStorage as T, CookieStorageOptions as _, CategoryTexts as a, ItemTexts as b, ConsentConfig as c, ConsentScripts as d, CookieBannerConfigurationProviderProps as f, CookieSettingsLinkProps as g, CookieSettingsDialogProps as h, ButtonLikeProps as i, ThemePalette as j, TextOverrides as k, ConsentItemConfig as l, CookieBannerProps as m, BuiltInLanguage as n, CollapsibleProps as o, CookieBannerContextValue as p, getBuiltInTexts as r, ConsentCategoryConfig as s, BUILT_IN_LANGUAGES as t, ConsentScript as u, DeepPartial as v, PreferencesState as w, PreferenceCategory as x, DeepPartialNullable as y };
|
|
456
|
+
//# sourceMappingURL=resolve-texts-yAIbWOUX.d.ts.map
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_storage = require("./storage-Cqed-yMR.cjs");
|
|
3
|
+
//#region src/storage/server.ts
|
|
4
|
+
/**
|
|
5
|
+
* Reads the visitor's decision on the server. Works only when the provider
|
|
6
|
+
* persists to a cookie (`storage="cookie"` or `"both"`). Pass the result to
|
|
7
|
+
* the provider's `initialPreferences` so the first render already matches.
|
|
8
|
+
*
|
|
9
|
+
* Pure: no `window`, no React — safe in server components, route handlers,
|
|
10
|
+
* and middleware.
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const initial = readPreferencesFromCookies(await cookies(), "my-site-cookies");
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function readPreferencesFromCookies(source, storageKey = require_storage.DEFAULT_STORAGE_KEY) {
|
|
17
|
+
if (source == null) return null;
|
|
18
|
+
const raw = typeof source === "string" ? require_storage.findCookie(source, storageKey) : source.get(storageKey)?.value;
|
|
19
|
+
return require_storage.parsePreferences(raw);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.BUILT_IN_LANGUAGES = require_storage.BUILT_IN_LANGUAGES;
|
|
23
|
+
exports.getBuiltInTexts = require_storage.getBuiltInTexts;
|
|
24
|
+
exports.readPreferencesFromCookies = readPreferencesFromCookies;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.cjs","names":["DEFAULT_STORAGE_KEY","findCookie","parsePreferences"],"sources":["../src/storage/server.ts"],"sourcesContent":["import type { PreferencesState } from \"../types\";\nimport { findCookie } from \"./adapters\";\nimport { DEFAULT_STORAGE_KEY, parsePreferences } from \"./index\";\n\n/**\n * Where to read the consent cookie from on the server: the raw `Cookie`\n * request header, or a cookie store with `get(name)` such as the one returned\n * by Next.js `await cookies()`.\n */\nexport type CookieSource =\n | string\n | null\n | undefined\n | { get(name: string): { value: string } | undefined };\n\n/**\n * Reads the visitor's decision on the server. Works only when the provider\n * persists to a cookie (`storage=\"cookie\"` or `\"both\"`). Pass the result to\n * the provider's `initialPreferences` so the first render already matches.\n *\n * Pure: no `window`, no React — safe in server components, route handlers,\n * and middleware.\n *\n * ```tsx\n * const initial = readPreferencesFromCookies(await cookies(), \"my-site-cookies\");\n * ```\n */\nexport function readPreferencesFromCookies(\n source: CookieSource,\n storageKey: string = DEFAULT_STORAGE_KEY,\n): PreferencesState | null {\n if (source == null) return null;\n\n const raw =\n typeof source === \"string\"\n ? findCookie(source, storageKey)\n : source.get(storageKey)?.value;\n\n return parsePreferences(raw);\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,SAAgB,2BACd,QACA,aAAqBA,gBAAAA,qBACI;CACzB,IAAI,UAAU,MAAM,OAAO;CAE3B,MAAM,MACJ,OAAO,WAAW,WACdC,gBAAAA,WAAW,QAAQ,UAAU,IAC7B,OAAO,IAAI,UAAU,CAAC,EAAE;CAE9B,OAAOC,gBAAAA,iBAAiB,GAAG;AAC7B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { A as Texts, k as TextOverrides, n as BuiltInLanguage, r as getBuiltInTexts, t as BUILT_IN_LANGUAGES, w as PreferencesState } from "./resolve-texts-yAIbWOUX.cjs";
|
|
2
|
+
//#region src/storage/server.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Where to read the consent cookie from on the server: the raw `Cookie`
|
|
5
|
+
* request header, or a cookie store with `get(name)` such as the one returned
|
|
6
|
+
* by Next.js `await cookies()`.
|
|
7
|
+
*/
|
|
8
|
+
type CookieSource = string | null | undefined | {
|
|
9
|
+
get(name: string): {
|
|
10
|
+
value: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Reads the visitor's decision on the server. Works only when the provider
|
|
15
|
+
* persists to a cookie (`storage="cookie"` or `"both"`). Pass the result to
|
|
16
|
+
* the provider's `initialPreferences` so the first render already matches.
|
|
17
|
+
*
|
|
18
|
+
* Pure: no `window`, no React — safe in server components, route handlers,
|
|
19
|
+
* and middleware.
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const initial = readPreferencesFromCookies(await cookies(), "my-site-cookies");
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function readPreferencesFromCookies(source: CookieSource, storageKey?: string): PreferencesState | null;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { BUILT_IN_LANGUAGES, type BuiltInLanguage, type CookieSource, type TextOverrides, type Texts, getBuiltInTexts };
|
|
28
|
+
//# sourceMappingURL=server.d.cts.map
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { A as Texts, k as TextOverrides, n as BuiltInLanguage, r as getBuiltInTexts, t as BUILT_IN_LANGUAGES, w as PreferencesState } from "./resolve-texts-yAIbWOUX.js";
|
|
2
|
+
//#region src/storage/server.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Where to read the consent cookie from on the server: the raw `Cookie`
|
|
5
|
+
* request header, or a cookie store with `get(name)` such as the one returned
|
|
6
|
+
* by Next.js `await cookies()`.
|
|
7
|
+
*/
|
|
8
|
+
type CookieSource = string | null | undefined | {
|
|
9
|
+
get(name: string): {
|
|
10
|
+
value: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Reads the visitor's decision on the server. Works only when the provider
|
|
15
|
+
* persists to a cookie (`storage="cookie"` or `"both"`). Pass the result to
|
|
16
|
+
* the provider's `initialPreferences` so the first render already matches.
|
|
17
|
+
*
|
|
18
|
+
* Pure: no `window`, no React — safe in server components, route handlers,
|
|
19
|
+
* and middleware.
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const initial = readPreferencesFromCookies(await cookies(), "my-site-cookies");
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function readPreferencesFromCookies(source: CookieSource, storageKey?: string): PreferencesState | null;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { BUILT_IN_LANGUAGES, type BuiltInLanguage, type CookieSource, type TextOverrides, type Texts, getBuiltInTexts };
|
|
28
|
+
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { c as findCookie, d as BUILT_IN_LANGUAGES, f as getBuiltInTexts, n as parsePreferences, t as DEFAULT_STORAGE_KEY } from "./storage-WH-kuxkg.js";
|
|
2
|
+
//#region src/storage/server.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reads the visitor's decision on the server. Works only when the provider
|
|
5
|
+
* persists to a cookie (`storage="cookie"` or `"both"`). Pass the result to
|
|
6
|
+
* the provider's `initialPreferences` so the first render already matches.
|
|
7
|
+
*
|
|
8
|
+
* Pure: no `window`, no React — safe in server components, route handlers,
|
|
9
|
+
* and middleware.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const initial = readPreferencesFromCookies(await cookies(), "my-site-cookies");
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function readPreferencesFromCookies(source, storageKey = DEFAULT_STORAGE_KEY) {
|
|
16
|
+
if (source == null) return null;
|
|
17
|
+
const raw = typeof source === "string" ? findCookie(source, storageKey) : source.get(storageKey)?.value;
|
|
18
|
+
return parsePreferences(raw);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { BUILT_IN_LANGUAGES, getBuiltInTexts, readPreferencesFromCookies };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../src/storage/server.ts"],"sourcesContent":["import type { PreferencesState } from \"../types\";\nimport { findCookie } from \"./adapters\";\nimport { DEFAULT_STORAGE_KEY, parsePreferences } from \"./index\";\n\n/**\n * Where to read the consent cookie from on the server: the raw `Cookie`\n * request header, or a cookie store with `get(name)` such as the one returned\n * by Next.js `await cookies()`.\n */\nexport type CookieSource =\n | string\n | null\n | undefined\n | { get(name: string): { value: string } | undefined };\n\n/**\n * Reads the visitor's decision on the server. Works only when the provider\n * persists to a cookie (`storage=\"cookie\"` or `\"both\"`). Pass the result to\n * the provider's `initialPreferences` so the first render already matches.\n *\n * Pure: no `window`, no React — safe in server components, route handlers,\n * and middleware.\n *\n * ```tsx\n * const initial = readPreferencesFromCookies(await cookies(), \"my-site-cookies\");\n * ```\n */\nexport function readPreferencesFromCookies(\n source: CookieSource,\n storageKey: string = DEFAULT_STORAGE_KEY,\n): PreferencesState | null {\n if (source == null) return null;\n\n const raw =\n typeof source === \"string\"\n ? findCookie(source, storageKey)\n : source.get(storageKey)?.value;\n\n return parsePreferences(raw);\n}\n"],"mappings":";;;;;;;;;;;;;;AA2BA,SAAgB,2BACd,QACA,aAAqB,qBACI;CACzB,IAAI,UAAU,MAAM,OAAO;CAE3B,MAAM,MACJ,OAAO,WAAW,WACd,WAAW,QAAQ,UAAU,IAC7B,OAAO,IAAI,UAAU,CAAC,EAAE;CAE9B,OAAO,iBAAiB,GAAG;AAC7B"}
|