react-lgpd-consent 0.1.5 → 0.1.7

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/dist/index.cjs CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,43 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- ConsentGate: () => ConsentGate,
34
- ConsentProvider: () => ConsentProvider,
35
- CookieBanner: () => CookieBanner,
36
- PreferencesModal: () => PreferencesModal,
37
- defaultConsentTheme: () => defaultConsentTheme,
38
- loadConditionalScript: () => loadConditionalScript,
39
- loadScript: () => loadScript,
40
- useConsent: () => useConsent,
41
- useConsentTexts: () => useConsentTexts
42
- });
43
- module.exports = __toCommonJS(index_exports);
44
-
45
- // src/components/CookieBanner.tsx
46
- var import_Button = __toESM(require("@mui/material/Button"), 1);
47
- var import_Box = __toESM(require("@mui/material/Box"), 1);
48
- var import_Link = __toESM(require("@mui/material/Link"), 1);
49
- var import_Paper = __toESM(require("@mui/material/Paper"), 1);
50
- var import_Snackbar = __toESM(require("@mui/material/Snackbar"), 1);
51
- var import_Stack = __toESM(require("@mui/material/Stack"), 1);
52
- var import_Typography = __toESM(require("@mui/material/Typography"), 1);
53
-
54
- // src/context/ConsentContext.tsx
55
- var React = __toESM(require("react"), 1);
56
- var import_styles2 = require("@mui/material/styles");
57
-
58
33
  // src/utils/cookieUtils.ts
59
- var import_js_cookie = __toESM(require("js-cookie"), 1);
60
- var DEFAULT_COOKIE_OPTS = {
61
- name: "cookieConsent",
62
- maxAgeDays: 365,
63
- sameSite: "Lax",
64
- secure: true,
65
- path: "/"
66
- };
67
34
  function readConsentCookie(name = DEFAULT_COOKIE_OPTS.name) {
68
35
  if (typeof document === "undefined") return null;
69
36
  const raw = import_js_cookie.default.get(name);
@@ -89,95 +56,203 @@ function removeConsentCookie(opts) {
89
56
  const o = { ...DEFAULT_COOKIE_OPTS, ...opts };
90
57
  import_js_cookie.default.remove(o.name, { path: o.path });
91
58
  }
59
+ var import_js_cookie, DEFAULT_COOKIE_OPTS;
60
+ var init_cookieUtils = __esm({
61
+ "src/utils/cookieUtils.ts"() {
62
+ "use strict";
63
+ import_js_cookie = __toESM(require("js-cookie"), 1);
64
+ DEFAULT_COOKIE_OPTS = {
65
+ name: "cookieConsent",
66
+ maxAgeDays: 365,
67
+ sameSite: "Lax",
68
+ secure: true,
69
+ path: "/"
70
+ };
71
+ }
72
+ });
92
73
 
93
74
  // src/utils/theme.ts
94
- var import_styles = require("@mui/material/styles");
95
- var defaultConsentTheme = (0, import_styles.createTheme)({
96
- palette: {
97
- primary: {
98
- main: "#1976d2",
99
- // Azul institucional
100
- contrastText: "#ffffff"
101
- },
102
- secondary: {
103
- main: "#dc004e",
104
- // Rosa/vermelho para ações importantes
105
- contrastText: "#ffffff"
106
- },
107
- background: {
108
- default: "#fafafa",
109
- paper: "#ffffff"
110
- },
111
- text: {
112
- primary: "#333333",
113
- secondary: "#666666"
114
- },
115
- action: {
116
- hover: "rgba(25, 118, 210, 0.04)"
117
- }
118
- },
119
- typography: {
120
- fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
121
- body2: {
122
- fontSize: "0.875rem",
123
- lineHeight: 1.43
124
- },
125
- button: {
126
- fontWeight: 500,
127
- textTransform: "none"
128
- // Manter capitalização original
129
- }
130
- },
131
- components: {
132
- MuiButton: {
133
- styleOverrides: {
134
- root: {
135
- borderRadius: 8,
136
- paddingX: 16,
137
- paddingY: 8
75
+ var import_styles, defaultConsentTheme;
76
+ var init_theme = __esm({
77
+ "src/utils/theme.ts"() {
78
+ "use strict";
79
+ import_styles = require("@mui/material/styles");
80
+ defaultConsentTheme = (0, import_styles.createTheme)({
81
+ palette: {
82
+ primary: {
83
+ main: "#1976d2",
84
+ // Azul institucional
85
+ contrastText: "#ffffff"
138
86
  },
139
- contained: {
140
- boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
141
- "&:hover": {
142
- boxShadow: "0 4px 8px rgba(0,0,0,0.15)"
143
- }
87
+ secondary: {
88
+ main: "#dc004e",
89
+ // Rosa/vermelho para ações importantes
90
+ contrastText: "#ffffff"
91
+ },
92
+ background: {
93
+ default: "#fafafa",
94
+ paper: "#ffffff"
95
+ },
96
+ text: {
97
+ primary: "#333333",
98
+ secondary: "#666666"
99
+ },
100
+ action: {
101
+ hover: "rgba(25, 118, 210, 0.04)"
144
102
  }
145
- }
146
- },
147
- MuiPaper: {
148
- styleOverrides: {
149
- root: {
150
- borderRadius: 12
103
+ },
104
+ typography: {
105
+ fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
106
+ body2: {
107
+ fontSize: "0.875rem",
108
+ lineHeight: 1.43
109
+ },
110
+ button: {
111
+ fontWeight: 500,
112
+ textTransform: "none"
113
+ // Manter capitalização original
151
114
  }
152
- }
153
- },
154
- MuiDialog: {
155
- styleOverrides: {
156
- paper: {
157
- borderRadius: 16
115
+ },
116
+ components: {
117
+ MuiButton: {
118
+ styleOverrides: {
119
+ root: {
120
+ borderRadius: 8,
121
+ paddingX: 16,
122
+ paddingY: 8
123
+ },
124
+ contained: {
125
+ boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
126
+ "&:hover": {
127
+ boxShadow: "0 4px 8px rgba(0,0,0,0.15)"
128
+ }
129
+ }
130
+ }
131
+ },
132
+ MuiPaper: {
133
+ styleOverrides: {
134
+ root: {
135
+ borderRadius: 12
136
+ }
137
+ }
138
+ },
139
+ MuiDialog: {
140
+ styleOverrides: {
141
+ paper: {
142
+ borderRadius: 16
143
+ }
144
+ }
158
145
  }
159
146
  }
147
+ });
148
+ }
149
+ });
150
+
151
+ // src/components/PreferencesModal.tsx
152
+ var PreferencesModal_exports = {};
153
+ __export(PreferencesModal_exports, {
154
+ PreferencesModal: () => PreferencesModal
155
+ });
156
+ function PreferencesModal({
157
+ DialogProps: DialogProps2
158
+ }) {
159
+ const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
160
+ const texts = useConsentTexts();
161
+ const [tempPreferences, setTempPreferences] = (0, import_react.useState)(preferences);
162
+ (0, import_react.useEffect)(() => {
163
+ if (isModalOpen) {
164
+ setTempPreferences(preferences);
165
+ }
166
+ }, [isModalOpen, preferences]);
167
+ const open = DialogProps2?.open ?? isModalOpen ?? false;
168
+ const handleSave = () => {
169
+ setPreferences(tempPreferences);
170
+ };
171
+ const handleCancel = () => {
172
+ setTempPreferences(preferences);
173
+ closePreferences();
174
+ };
175
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
176
+ import_Dialog.default,
177
+ {
178
+ "aria-labelledby": "cookie-pref-title",
179
+ open,
180
+ onClose: handleCancel,
181
+ ...DialogProps2,
182
+ children: [
183
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DialogTitle.default, { id: "cookie-pref-title", children: texts.modalTitle }),
184
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_DialogContent.default, { dividers: true, children: [
185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Typography.default, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
186
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_FormGroup.default, { children: [
187
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
188
+ import_FormControlLabel.default,
189
+ {
190
+ control: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
191
+ import_Switch.default,
192
+ {
193
+ checked: tempPreferences.analytics,
194
+ onChange: (e) => setTempPreferences((prev) => ({
195
+ ...prev,
196
+ analytics: e.target.checked
197
+ }))
198
+ }
199
+ ),
200
+ label: "Cookies Anal\xEDticos (medem uso do site)"
201
+ }
202
+ ),
203
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
204
+ import_FormControlLabel.default,
205
+ {
206
+ control: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
207
+ import_Switch.default,
208
+ {
209
+ checked: tempPreferences.marketing,
210
+ onChange: (e) => setTempPreferences((prev) => ({
211
+ ...prev,
212
+ marketing: e.target.checked
213
+ }))
214
+ }
215
+ ),
216
+ label: "Cookies de Marketing/Publicidade"
217
+ }
218
+ ),
219
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
220
+ import_FormControlLabel.default,
221
+ {
222
+ control: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Switch.default, { checked: true, disabled: true }),
223
+ label: texts.necessaryAlwaysOn
224
+ }
225
+ )
226
+ ] })
227
+ ] }),
228
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_DialogActions.default, { children: [
229
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.default, { variant: "outlined", onClick: handleCancel, children: "Cancelar" }),
230
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.default, { variant: "contained", onClick: handleSave, children: texts.save })
231
+ ] })
232
+ ]
160
233
  }
234
+ );
235
+ }
236
+ var import_Button, import_Dialog, import_DialogActions, import_DialogContent, import_DialogTitle, import_FormControlLabel, import_FormGroup, import_Switch, import_Typography, import_react, import_jsx_runtime;
237
+ var init_PreferencesModal = __esm({
238
+ "src/components/PreferencesModal.tsx"() {
239
+ "use strict";
240
+ import_Button = __toESM(require("@mui/material/Button"), 1);
241
+ import_Dialog = __toESM(require("@mui/material/Dialog"), 1);
242
+ import_DialogActions = __toESM(require("@mui/material/DialogActions"), 1);
243
+ import_DialogContent = __toESM(require("@mui/material/DialogContent"), 1);
244
+ import_DialogTitle = __toESM(require("@mui/material/DialogTitle"), 1);
245
+ import_FormControlLabel = __toESM(require("@mui/material/FormControlLabel"), 1);
246
+ import_FormGroup = __toESM(require("@mui/material/FormGroup"), 1);
247
+ import_Switch = __toESM(require("@mui/material/Switch"), 1);
248
+ import_Typography = __toESM(require("@mui/material/Typography"), 1);
249
+ import_react = require("react");
250
+ init_useConsent();
251
+ import_jsx_runtime = require("react/jsx-runtime");
161
252
  }
162
253
  });
163
254
 
164
255
  // src/context/ConsentContext.tsx
165
- var import_jsx_runtime = require("react/jsx-runtime");
166
- var DEFAULT_PREFERENCES = {
167
- analytics: false,
168
- marketing: false
169
- };
170
- var DEFAULT_TEXTS = {
171
- bannerMessage: "Utilizamos cookies para melhorar sua experi\xEAncia.",
172
- acceptAll: "Aceitar todos",
173
- declineAll: "Recusar",
174
- preferences: "Prefer\xEAncias",
175
- policyLink: "Saiba mais",
176
- modalTitle: "Prefer\xEAncias de Cookies",
177
- modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
178
- save: "Salvar prefer\xEAncias",
179
- necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)"
180
- };
181
256
  function reducer(state, action) {
182
257
  switch (action.type) {
183
258
  case "ACCEPT_ALL":
@@ -200,6 +275,13 @@ function reducer(state, action) {
200
275
  [action.category]: action.value
201
276
  }
202
277
  };
278
+ case "SET_PREFERENCES":
279
+ return {
280
+ ...state,
281
+ consented: true,
282
+ preferences: action.preferences,
283
+ isModalOpen: false
284
+ };
203
285
  case "OPEN_MODAL":
204
286
  return { ...state, isModalOpen: true };
205
287
  case "CLOSE_MODAL":
@@ -217,13 +299,13 @@ function reducer(state, action) {
217
299
  return state;
218
300
  }
219
301
  }
220
- var StateCtx = React.createContext(null);
221
- var ActionsCtx = React.createContext(null);
222
- var TextsCtx = React.createContext(DEFAULT_TEXTS);
223
302
  function ConsentProvider({
224
303
  initialState,
225
304
  texts: textsProp,
226
305
  theme,
306
+ PreferencesModalComponent,
307
+ preferencesModalProps = {},
308
+ disableAutomaticModal = false,
227
309
  onConsentGiven,
228
310
  onPreferencesSaved,
229
311
  cookie: cookieOpts,
@@ -272,6 +354,7 @@ function ConsentProvider({
272
354
  const acceptAll = () => dispatch({ type: "ACCEPT_ALL" });
273
355
  const rejectAll = () => dispatch({ type: "REJECT_ALL" });
274
356
  const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
357
+ const setPreferences = (preferences) => dispatch({ type: "SET_PREFERENCES", preferences });
275
358
  const openPreferences = () => dispatch({ type: "OPEN_MODAL" });
276
359
  const closePreferences = () => dispatch({ type: "CLOSE_MODAL" });
277
360
  const resetConsent = () => {
@@ -285,12 +368,16 @@ function ConsentProvider({
285
368
  acceptAll,
286
369
  rejectAll,
287
370
  setPreference,
371
+ setPreferences,
288
372
  openPreferences,
289
373
  closePreferences,
290
374
  resetConsent
291
375
  };
292
376
  }, [state, cookie]);
293
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles2.ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StateCtx.Provider, { value: state, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextsCtx.Provider, { value: texts, children }) }) }) });
377
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_styles2.ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StateCtx.Provider, { value: state, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(TextsCtx.Provider, { value: texts, children: [
378
+ children,
379
+ !disableAutomaticModal && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(React.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PreferencesModalComponent, { ...preferencesModalProps }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PreferencesModal2, {}) })
380
+ ] }) }) }) });
294
381
  }
295
382
  function useConsentStateInternal() {
296
383
  const ctx = React.useContext(StateCtx);
@@ -308,6 +395,40 @@ function useConsentTextsInternal() {
308
395
  const ctx = React.useContext(TextsCtx);
309
396
  return ctx;
310
397
  }
398
+ var React, import_styles2, import_jsx_runtime2, PreferencesModal2, DEFAULT_PREFERENCES, DEFAULT_TEXTS, StateCtx, ActionsCtx, TextsCtx;
399
+ var init_ConsentContext = __esm({
400
+ "src/context/ConsentContext.tsx"() {
401
+ "use strict";
402
+ React = __toESM(require("react"), 1);
403
+ import_styles2 = require("@mui/material/styles");
404
+ init_cookieUtils();
405
+ init_theme();
406
+ import_jsx_runtime2 = require("react/jsx-runtime");
407
+ PreferencesModal2 = React.lazy(
408
+ () => Promise.resolve().then(() => (init_PreferencesModal(), PreferencesModal_exports)).then((m) => ({
409
+ default: m.PreferencesModal
410
+ }))
411
+ );
412
+ DEFAULT_PREFERENCES = {
413
+ analytics: false,
414
+ marketing: false
415
+ };
416
+ DEFAULT_TEXTS = {
417
+ bannerMessage: "Utilizamos cookies para melhorar sua experi\xEAncia.",
418
+ acceptAll: "Aceitar todos",
419
+ declineAll: "Recusar",
420
+ preferences: "Prefer\xEAncias",
421
+ policyLink: "Saiba mais",
422
+ modalTitle: "Prefer\xEAncias de Cookies",
423
+ modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
424
+ save: "Salvar prefer\xEAncias",
425
+ necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)"
426
+ };
427
+ StateCtx = React.createContext(null);
428
+ ActionsCtx = React.createContext(null);
429
+ TextsCtx = React.createContext(DEFAULT_TEXTS);
430
+ }
431
+ });
311
432
 
312
433
  // src/hooks/useConsent.ts
313
434
  function useConsent() {
@@ -320,6 +441,7 @@ function useConsent() {
320
441
  acceptAll: actions.acceptAll,
321
442
  rejectAll: actions.rejectAll,
322
443
  setPreference: actions.setPreference,
444
+ setPreferences: actions.setPreferences,
323
445
  openPreferences: actions.openPreferences,
324
446
  closePreferences: actions.closePreferences,
325
447
  resetConsent: actions.resetConsent
@@ -328,9 +450,37 @@ function useConsent() {
328
450
  function useConsentTexts() {
329
451
  return useConsentTextsInternal();
330
452
  }
453
+ var init_useConsent = __esm({
454
+ "src/hooks/useConsent.ts"() {
455
+ "use strict";
456
+ init_ConsentContext();
457
+ }
458
+ });
459
+
460
+ // src/index.ts
461
+ var index_exports = {};
462
+ __export(index_exports, {
463
+ ConsentGate: () => ConsentGate,
464
+ ConsentProvider: () => ConsentProvider,
465
+ CookieBanner: () => CookieBanner,
466
+ PreferencesModal: () => PreferencesModal,
467
+ defaultConsentTheme: () => defaultConsentTheme,
468
+ loadScript: () => loadScript,
469
+ useConsent: () => useConsent,
470
+ useConsentTexts: () => useConsentTexts
471
+ });
472
+ module.exports = __toCommonJS(index_exports);
331
473
 
332
474
  // src/components/CookieBanner.tsx
333
- var import_jsx_runtime2 = require("react/jsx-runtime");
475
+ var import_Button2 = __toESM(require("@mui/material/Button"), 1);
476
+ var import_Box = __toESM(require("@mui/material/Box"), 1);
477
+ var import_Link = __toESM(require("@mui/material/Link"), 1);
478
+ var import_Paper = __toESM(require("@mui/material/Paper"), 1);
479
+ var import_Snackbar = __toESM(require("@mui/material/Snackbar"), 1);
480
+ var import_Stack = __toESM(require("@mui/material/Stack"), 1);
481
+ var import_Typography2 = __toESM(require("@mui/material/Typography"), 1);
482
+ init_useConsent();
483
+ var import_jsx_runtime3 = require("react/jsx-runtime");
334
484
  function CookieBanner({
335
485
  policyLinkUrl,
336
486
  debug,
@@ -343,17 +493,17 @@ function CookieBanner({
343
493
  const texts = useConsentTexts();
344
494
  const open = debug ? true : !consented;
345
495
  if (!open) return null;
346
- const bannerContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
496
+ const bannerContent = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
347
497
  import_Paper.default,
348
498
  {
349
499
  elevation: 3,
350
500
  sx: { p: 2, maxWidth: 720, mx: "auto" },
351
501
  ...PaperProps,
352
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_Stack.default, { spacing: 1, children: [
353
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_Typography.default, { variant: "body2", children: [
502
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_Stack.default, { spacing: 1, children: [
503
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_Typography2.default, { variant: "body2", children: [
354
504
  texts.bannerMessage,
355
505
  " ",
356
- policyLinkUrl && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
506
+ policyLinkUrl && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
357
507
  import_Link.default,
358
508
  {
359
509
  href: policyLinkUrl,
@@ -364,16 +514,16 @@ function CookieBanner({
364
514
  }
365
515
  )
366
516
  ] }),
367
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
517
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
368
518
  import_Stack.default,
369
519
  {
370
520
  direction: { xs: "column", sm: "row" },
371
521
  spacing: 1,
372
522
  justifyContent: "flex-end",
373
523
  children: [
374
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_Button.default, { variant: "outlined", onClick: rejectAll, children: texts.declineAll }),
375
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_Button.default, { variant: "contained", onClick: acceptAll, children: texts.acceptAll }),
376
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_Button.default, { variant: "text", onClick: openPreferences, children: texts.preferences })
524
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Button2.default, { variant: "outlined", onClick: rejectAll, children: texts.declineAll }),
525
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Button2.default, { variant: "contained", onClick: acceptAll, children: texts.acceptAll }),
526
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Button2.default, { variant: "text", onClick: openPreferences, children: texts.preferences })
377
527
  ]
378
528
  }
379
529
  )
@@ -381,8 +531,8 @@ function CookieBanner({
381
531
  }
382
532
  );
383
533
  if (blocking) {
384
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
385
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
534
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
535
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
386
536
  import_Box.default,
387
537
  {
388
538
  sx: {
@@ -397,7 +547,7 @@ function CookieBanner({
397
547
  }
398
548
  }
399
549
  ),
400
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
550
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
401
551
  import_Box.default,
402
552
  {
403
553
  sx: {
@@ -414,7 +564,7 @@ function CookieBanner({
414
564
  )
415
565
  ] });
416
566
  }
417
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
567
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
418
568
  import_Snackbar.default,
419
569
  {
420
570
  open,
@@ -425,77 +575,13 @@ function CookieBanner({
425
575
  );
426
576
  }
427
577
 
428
- // src/components/PreferencesModal.tsx
429
- var import_Button2 = __toESM(require("@mui/material/Button"), 1);
430
- var import_Dialog = __toESM(require("@mui/material/Dialog"), 1);
431
- var import_DialogActions = __toESM(require("@mui/material/DialogActions"), 1);
432
- var import_DialogContent = __toESM(require("@mui/material/DialogContent"), 1);
433
- var import_DialogTitle = __toESM(require("@mui/material/DialogTitle"), 1);
434
- var import_FormControlLabel = __toESM(require("@mui/material/FormControlLabel"), 1);
435
- var import_FormGroup = __toESM(require("@mui/material/FormGroup"), 1);
436
- var import_Switch = __toESM(require("@mui/material/Switch"), 1);
437
- var import_Typography2 = __toESM(require("@mui/material/Typography"), 1);
438
- var import_jsx_runtime3 = require("react/jsx-runtime");
439
- function PreferencesModal({
440
- DialogProps: DialogProps2
441
- }) {
442
- const { preferences, setPreference, closePreferences, isModalOpen } = useConsent();
443
- const texts = useConsentTexts();
444
- const open = DialogProps2?.open ?? isModalOpen ?? false;
445
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
446
- import_Dialog.default,
447
- {
448
- "aria-labelledby": "cookie-pref-title",
449
- open,
450
- onClose: closePreferences,
451
- ...DialogProps2,
452
- children: [
453
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_DialogTitle.default, { id: "cookie-pref-title", children: texts.modalTitle }),
454
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_DialogContent.default, { dividers: true, children: [
455
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Typography2.default, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
456
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_FormGroup.default, { children: [
457
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
458
- import_FormControlLabel.default,
459
- {
460
- control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
461
- import_Switch.default,
462
- {
463
- checked: preferences.analytics,
464
- onChange: (e) => setPreference("analytics", e.target.checked)
465
- }
466
- ),
467
- label: "Cookies Anal\xEDticos (medem uso do site)"
468
- }
469
- ),
470
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
471
- import_FormControlLabel.default,
472
- {
473
- control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
474
- import_Switch.default,
475
- {
476
- checked: preferences.marketing,
477
- onChange: (e) => setPreference("marketing", e.target.checked)
478
- }
479
- ),
480
- label: "Cookies de Marketing/Publicidade"
481
- }
482
- ),
483
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
484
- import_FormControlLabel.default,
485
- {
486
- control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Switch.default, { checked: true, disabled: true }),
487
- label: texts.necessaryAlwaysOn
488
- }
489
- )
490
- ] })
491
- ] }),
492
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_DialogActions.default, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Button2.default, { variant: "contained", onClick: closePreferences, children: texts.save }) })
493
- ]
494
- }
495
- );
496
- }
578
+ // src/index.ts
579
+ init_PreferencesModal();
580
+ init_ConsentContext();
581
+ init_useConsent();
497
582
 
498
583
  // src/utils/ConsentGate.tsx
584
+ init_useConsent();
499
585
  var import_jsx_runtime4 = require("react/jsx-runtime");
500
586
  function ConsentGate(props) {
501
587
  const { preferences } = useConsent();
@@ -504,36 +590,44 @@ function ConsentGate(props) {
504
590
  }
505
591
 
506
592
  // src/utils/scriptLoader.ts
507
- function loadScript(id, src, attrs = {}) {
508
- if (typeof document === "undefined") return;
509
- if (document.getElementById(id)) return;
510
- const s = document.createElement("script");
511
- s.id = id;
512
- s.src = src;
513
- s.async = true;
514
- for (const [k, v] of Object.entries(attrs)) s.setAttribute(k, v);
515
- document.body.appendChild(s);
516
- }
517
- function loadConditionalScript(id, src, condition, attrs = {}, maxWaitMs = 5e3) {
593
+ function loadScript(id, src, category = null, attrs = {}) {
518
594
  if (typeof document === "undefined") return Promise.resolve();
519
595
  if (document.getElementById(id)) return Promise.resolve();
520
596
  return new Promise((resolve, reject) => {
521
- const startTime = Date.now();
522
- const checkCondition = () => {
523
- if (condition()) {
524
- loadScript(id, src, attrs);
525
- resolve();
526
- } else if (Date.now() - startTime > maxWaitMs) {
527
- reject(
528
- new Error(`Timeout waiting for consent condition for script ${id}`)
529
- );
530
- } else {
531
- setTimeout(checkCondition, 100);
597
+ const checkConsent = () => {
598
+ const consentCookie = document.cookie.split("; ").find((row) => row.startsWith("cookieConsent="))?.split("=")[1];
599
+ if (!consentCookie) {
600
+ setTimeout(checkConsent, 100);
601
+ return;
602
+ }
603
+ try {
604
+ const consent = JSON.parse(decodeURIComponent(consentCookie));
605
+ if (!consent.consented || consent.isModalOpen) {
606
+ setTimeout(checkConsent, 100);
607
+ return;
608
+ }
609
+ if (category && !consent.preferences[category]) {
610
+ reject(new Error(`Consent not given for ${category} scripts`));
611
+ return;
612
+ }
613
+ const s = document.createElement("script");
614
+ s.id = id;
615
+ s.src = src;
616
+ s.async = true;
617
+ for (const [k, v] of Object.entries(attrs)) s.setAttribute(k, v);
618
+ s.onload = () => resolve();
619
+ s.onerror = () => reject(new Error(`Failed to load script: ${src}`));
620
+ document.body.appendChild(s);
621
+ } catch {
622
+ setTimeout(checkConsent, 100);
532
623
  }
533
624
  };
534
- checkCondition();
625
+ checkConsent();
535
626
  });
536
627
  }
628
+
629
+ // src/index.ts
630
+ init_theme();
537
631
  // Annotate the CommonJS export names for ESM import in node:
538
632
  0 && (module.exports = {
539
633
  ConsentGate,
@@ -541,7 +635,6 @@ function loadConditionalScript(id, src, condition, attrs = {}, maxWaitMs = 5e3)
541
635
  CookieBanner,
542
636
  PreferencesModal,
543
637
  defaultConsentTheme,
544
- loadConditionalScript,
545
638
  loadScript,
546
639
  useConsent,
547
640
  useConsentTexts