react-lgpd-consent 0.1.4 → 0.1.6

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,180 @@ 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, setPreference, closePreferences, isModalOpen } = useConsent();
160
+ const texts = useConsentTexts();
161
+ const open = DialogProps2?.open ?? isModalOpen ?? false;
162
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
163
+ import_Dialog.default,
164
+ {
165
+ "aria-labelledby": "cookie-pref-title",
166
+ open,
167
+ onClose: closePreferences,
168
+ ...DialogProps2,
169
+ children: [
170
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DialogTitle.default, { id: "cookie-pref-title", children: texts.modalTitle }),
171
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_DialogContent.default, { dividers: true, children: [
172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Typography.default, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
173
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_FormGroup.default, { children: [
174
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
175
+ import_FormControlLabel.default,
176
+ {
177
+ control: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
178
+ import_Switch.default,
179
+ {
180
+ checked: preferences.analytics,
181
+ onChange: (e) => setPreference("analytics", e.target.checked)
182
+ }
183
+ ),
184
+ label: "Cookies Anal\xEDticos (medem uso do site)"
185
+ }
186
+ ),
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: preferences.marketing,
194
+ onChange: (e) => setPreference("marketing", e.target.checked)
195
+ }
196
+ ),
197
+ label: "Cookies de Marketing/Publicidade"
198
+ }
199
+ ),
200
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
201
+ import_FormControlLabel.default,
202
+ {
203
+ control: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Switch.default, { checked: true, disabled: true }),
204
+ label: texts.necessaryAlwaysOn
205
+ }
206
+ )
207
+ ] })
208
+ ] }),
209
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DialogActions.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.default, { variant: "contained", onClick: closePreferences, children: texts.save }) })
210
+ ]
160
211
  }
212
+ );
213
+ }
214
+ var import_Button, import_Dialog, import_DialogActions, import_DialogContent, import_DialogTitle, import_FormControlLabel, import_FormGroup, import_Switch, import_Typography, import_jsx_runtime;
215
+ var init_PreferencesModal = __esm({
216
+ "src/components/PreferencesModal.tsx"() {
217
+ "use strict";
218
+ import_Button = __toESM(require("@mui/material/Button"), 1);
219
+ import_Dialog = __toESM(require("@mui/material/Dialog"), 1);
220
+ import_DialogActions = __toESM(require("@mui/material/DialogActions"), 1);
221
+ import_DialogContent = __toESM(require("@mui/material/DialogContent"), 1);
222
+ import_DialogTitle = __toESM(require("@mui/material/DialogTitle"), 1);
223
+ import_FormControlLabel = __toESM(require("@mui/material/FormControlLabel"), 1);
224
+ import_FormGroup = __toESM(require("@mui/material/FormGroup"), 1);
225
+ import_Switch = __toESM(require("@mui/material/Switch"), 1);
226
+ import_Typography = __toESM(require("@mui/material/Typography"), 1);
227
+ init_useConsent();
228
+ import_jsx_runtime = require("react/jsx-runtime");
161
229
  }
162
230
  });
163
231
 
164
232
  // 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
233
  function reducer(state, action) {
182
234
  switch (action.type) {
183
235
  case "ACCEPT_ALL":
@@ -217,13 +269,13 @@ function reducer(state, action) {
217
269
  return state;
218
270
  }
219
271
  }
220
- var StateCtx = React.createContext(null);
221
- var ActionsCtx = React.createContext(null);
222
- var TextsCtx = React.createContext(DEFAULT_TEXTS);
223
272
  function ConsentProvider({
224
273
  initialState,
225
274
  texts: textsProp,
226
275
  theme,
276
+ PreferencesModalComponent,
277
+ preferencesModalProps = {},
278
+ disableAutomaticModal = false,
227
279
  onConsentGiven,
228
280
  onPreferencesSaved,
229
281
  cookie: cookieOpts,
@@ -281,6 +333,7 @@ function ConsentProvider({
281
333
  return {
282
334
  consented: !!state.consented,
283
335
  preferences: state.preferences,
336
+ isModalOpen: state.isModalOpen,
284
337
  acceptAll,
285
338
  rejectAll,
286
339
  setPreference,
@@ -289,7 +342,10 @@ function ConsentProvider({
289
342
  resetConsent
290
343
  };
291
344
  }, [state, cookie]);
292
- 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 }) }) }) });
345
+ 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: [
346
+ children,
347
+ !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, {}) })
348
+ ] }) }) }) });
293
349
  }
294
350
  function useConsentStateInternal() {
295
351
  const ctx = React.useContext(StateCtx);
@@ -307,6 +363,40 @@ function useConsentTextsInternal() {
307
363
  const ctx = React.useContext(TextsCtx);
308
364
  return ctx;
309
365
  }
366
+ var React, import_styles2, import_jsx_runtime2, PreferencesModal2, DEFAULT_PREFERENCES, DEFAULT_TEXTS, StateCtx, ActionsCtx, TextsCtx;
367
+ var init_ConsentContext = __esm({
368
+ "src/context/ConsentContext.tsx"() {
369
+ "use strict";
370
+ React = __toESM(require("react"), 1);
371
+ import_styles2 = require("@mui/material/styles");
372
+ init_cookieUtils();
373
+ init_theme();
374
+ import_jsx_runtime2 = require("react/jsx-runtime");
375
+ PreferencesModal2 = React.lazy(
376
+ () => Promise.resolve().then(() => (init_PreferencesModal(), PreferencesModal_exports)).then((m) => ({
377
+ default: m.PreferencesModal
378
+ }))
379
+ );
380
+ DEFAULT_PREFERENCES = {
381
+ analytics: false,
382
+ marketing: false
383
+ };
384
+ DEFAULT_TEXTS = {
385
+ bannerMessage: "Utilizamos cookies para melhorar sua experi\xEAncia.",
386
+ acceptAll: "Aceitar todos",
387
+ declineAll: "Recusar",
388
+ preferences: "Prefer\xEAncias",
389
+ policyLink: "Saiba mais",
390
+ modalTitle: "Prefer\xEAncias de Cookies",
391
+ modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
392
+ save: "Salvar prefer\xEAncias",
393
+ necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)"
394
+ };
395
+ StateCtx = React.createContext(null);
396
+ ActionsCtx = React.createContext(null);
397
+ TextsCtx = React.createContext(DEFAULT_TEXTS);
398
+ }
399
+ });
310
400
 
311
401
  // src/hooks/useConsent.ts
312
402
  function useConsent() {
@@ -327,9 +417,37 @@ function useConsent() {
327
417
  function useConsentTexts() {
328
418
  return useConsentTextsInternal();
329
419
  }
420
+ var init_useConsent = __esm({
421
+ "src/hooks/useConsent.ts"() {
422
+ "use strict";
423
+ init_ConsentContext();
424
+ }
425
+ });
426
+
427
+ // src/index.ts
428
+ var index_exports = {};
429
+ __export(index_exports, {
430
+ ConsentGate: () => ConsentGate,
431
+ ConsentProvider: () => ConsentProvider,
432
+ CookieBanner: () => CookieBanner,
433
+ PreferencesModal: () => PreferencesModal,
434
+ defaultConsentTheme: () => defaultConsentTheme,
435
+ loadScript: () => loadScript,
436
+ useConsent: () => useConsent,
437
+ useConsentTexts: () => useConsentTexts
438
+ });
439
+ module.exports = __toCommonJS(index_exports);
330
440
 
331
441
  // src/components/CookieBanner.tsx
332
- var import_jsx_runtime2 = require("react/jsx-runtime");
442
+ var import_Button2 = __toESM(require("@mui/material/Button"), 1);
443
+ var import_Box = __toESM(require("@mui/material/Box"), 1);
444
+ var import_Link = __toESM(require("@mui/material/Link"), 1);
445
+ var import_Paper = __toESM(require("@mui/material/Paper"), 1);
446
+ var import_Snackbar = __toESM(require("@mui/material/Snackbar"), 1);
447
+ var import_Stack = __toESM(require("@mui/material/Stack"), 1);
448
+ var import_Typography2 = __toESM(require("@mui/material/Typography"), 1);
449
+ init_useConsent();
450
+ var import_jsx_runtime3 = require("react/jsx-runtime");
333
451
  function CookieBanner({
334
452
  policyLinkUrl,
335
453
  debug,
@@ -342,17 +460,17 @@ function CookieBanner({
342
460
  const texts = useConsentTexts();
343
461
  const open = debug ? true : !consented;
344
462
  if (!open) return null;
345
- const bannerContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
463
+ const bannerContent = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
346
464
  import_Paper.default,
347
465
  {
348
466
  elevation: 3,
349
467
  sx: { p: 2, maxWidth: 720, mx: "auto" },
350
468
  ...PaperProps,
351
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_Stack.default, { spacing: 1, children: [
352
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_Typography.default, { variant: "body2", children: [
469
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_Stack.default, { spacing: 1, children: [
470
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_Typography2.default, { variant: "body2", children: [
353
471
  texts.bannerMessage,
354
472
  " ",
355
- policyLinkUrl && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
473
+ policyLinkUrl && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
356
474
  import_Link.default,
357
475
  {
358
476
  href: policyLinkUrl,
@@ -363,16 +481,16 @@ function CookieBanner({
363
481
  }
364
482
  )
365
483
  ] }),
366
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
484
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
367
485
  import_Stack.default,
368
486
  {
369
487
  direction: { xs: "column", sm: "row" },
370
488
  spacing: 1,
371
489
  justifyContent: "flex-end",
372
490
  children: [
373
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_Button.default, { variant: "outlined", onClick: rejectAll, children: texts.declineAll }),
374
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_Button.default, { variant: "contained", onClick: acceptAll, children: texts.acceptAll }),
375
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_Button.default, { variant: "text", onClick: openPreferences, children: texts.preferences })
491
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Button2.default, { variant: "outlined", onClick: rejectAll, children: texts.declineAll }),
492
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Button2.default, { variant: "contained", onClick: acceptAll, children: texts.acceptAll }),
493
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Button2.default, { variant: "text", onClick: openPreferences, children: texts.preferences })
376
494
  ]
377
495
  }
378
496
  )
@@ -380,28 +498,40 @@ function CookieBanner({
380
498
  }
381
499
  );
382
500
  if (blocking) {
383
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
384
- import_Box.default,
385
- {
386
- sx: {
387
- position: "fixed",
388
- top: 0,
389
- left: 0,
390
- right: 0,
391
- bottom: 0,
392
- backgroundColor: "rgba(0, 0, 0, 0.5)",
393
- display: "flex",
394
- alignItems: "center",
395
- justifyContent: "center",
396
- zIndex: 1300,
397
- // Above MUI Modal
398
- p: 2
399
- },
400
- children: bannerContent
401
- }
402
- );
501
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
502
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
503
+ import_Box.default,
504
+ {
505
+ sx: {
506
+ position: "fixed",
507
+ top: 0,
508
+ left: 0,
509
+ right: 0,
510
+ bottom: 0,
511
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
512
+ zIndex: 1299
513
+ // Abaixo do banner mas acima do conteúdo
514
+ }
515
+ }
516
+ ),
517
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
518
+ import_Box.default,
519
+ {
520
+ sx: {
521
+ position: "fixed",
522
+ bottom: 0,
523
+ left: 0,
524
+ right: 0,
525
+ zIndex: 1300,
526
+ // Acima do overlay
527
+ p: 2
528
+ },
529
+ children: bannerContent
530
+ }
531
+ )
532
+ ] });
403
533
  }
404
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
534
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
405
535
  import_Snackbar.default,
406
536
  {
407
537
  open,
@@ -412,77 +542,13 @@ function CookieBanner({
412
542
  );
413
543
  }
414
544
 
415
- // src/components/PreferencesModal.tsx
416
- var import_Button2 = __toESM(require("@mui/material/Button"), 1);
417
- var import_Dialog = __toESM(require("@mui/material/Dialog"), 1);
418
- var import_DialogActions = __toESM(require("@mui/material/DialogActions"), 1);
419
- var import_DialogContent = __toESM(require("@mui/material/DialogContent"), 1);
420
- var import_DialogTitle = __toESM(require("@mui/material/DialogTitle"), 1);
421
- var import_FormControlLabel = __toESM(require("@mui/material/FormControlLabel"), 1);
422
- var import_FormGroup = __toESM(require("@mui/material/FormGroup"), 1);
423
- var import_Switch = __toESM(require("@mui/material/Switch"), 1);
424
- var import_Typography2 = __toESM(require("@mui/material/Typography"), 1);
425
- var import_jsx_runtime3 = require("react/jsx-runtime");
426
- function PreferencesModal({
427
- DialogProps: DialogProps2
428
- }) {
429
- const { preferences, setPreference, closePreferences, isModalOpen } = useConsent();
430
- const texts = useConsentTexts();
431
- const open = DialogProps2?.open ?? isModalOpen ?? false;
432
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
433
- import_Dialog.default,
434
- {
435
- "aria-labelledby": "cookie-pref-title",
436
- open,
437
- onClose: closePreferences,
438
- ...DialogProps2,
439
- children: [
440
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_DialogTitle.default, { id: "cookie-pref-title", children: texts.modalTitle }),
441
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_DialogContent.default, { dividers: true, children: [
442
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Typography2.default, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
443
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_FormGroup.default, { children: [
444
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
445
- import_FormControlLabel.default,
446
- {
447
- control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
448
- import_Switch.default,
449
- {
450
- checked: preferences.analytics,
451
- onChange: (e) => setPreference("analytics", e.target.checked)
452
- }
453
- ),
454
- label: "Cookies Anal\xEDticos (medem uso do site)"
455
- }
456
- ),
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.marketing,
464
- onChange: (e) => setPreference("marketing", e.target.checked)
465
- }
466
- ),
467
- label: "Cookies de Marketing/Publicidade"
468
- }
469
- ),
470
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
471
- import_FormControlLabel.default,
472
- {
473
- control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Switch.default, { checked: true, disabled: true }),
474
- label: texts.necessaryAlwaysOn
475
- }
476
- )
477
- ] })
478
- ] }),
479
- /* @__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 }) })
480
- ]
481
- }
482
- );
483
- }
545
+ // src/index.ts
546
+ init_PreferencesModal();
547
+ init_ConsentContext();
548
+ init_useConsent();
484
549
 
485
550
  // src/utils/ConsentGate.tsx
551
+ init_useConsent();
486
552
  var import_jsx_runtime4 = require("react/jsx-runtime");
487
553
  function ConsentGate(props) {
488
554
  const { preferences } = useConsent();
@@ -491,36 +557,44 @@ function ConsentGate(props) {
491
557
  }
492
558
 
493
559
  // src/utils/scriptLoader.ts
494
- function loadScript(id, src, attrs = {}) {
495
- if (typeof document === "undefined") return;
496
- if (document.getElementById(id)) return;
497
- const s = document.createElement("script");
498
- s.id = id;
499
- s.src = src;
500
- s.async = true;
501
- for (const [k, v] of Object.entries(attrs)) s.setAttribute(k, v);
502
- document.body.appendChild(s);
503
- }
504
- function loadConditionalScript(id, src, condition, attrs = {}, maxWaitMs = 5e3) {
560
+ function loadScript(id, src, category = null, attrs = {}) {
505
561
  if (typeof document === "undefined") return Promise.resolve();
506
562
  if (document.getElementById(id)) return Promise.resolve();
507
563
  return new Promise((resolve, reject) => {
508
- const startTime = Date.now();
509
- const checkCondition = () => {
510
- if (condition()) {
511
- loadScript(id, src, attrs);
512
- resolve();
513
- } else if (Date.now() - startTime > maxWaitMs) {
514
- reject(
515
- new Error(`Timeout waiting for consent condition for script ${id}`)
516
- );
517
- } else {
518
- setTimeout(checkCondition, 100);
564
+ const checkConsent = () => {
565
+ const consentCookie = document.cookie.split("; ").find((row) => row.startsWith("cookieConsent="))?.split("=")[1];
566
+ if (!consentCookie) {
567
+ setTimeout(checkConsent, 100);
568
+ return;
569
+ }
570
+ try {
571
+ const consent = JSON.parse(decodeURIComponent(consentCookie));
572
+ if (!consent.consented) {
573
+ setTimeout(checkConsent, 100);
574
+ return;
575
+ }
576
+ if (category && !consent.preferences[category]) {
577
+ reject(new Error(`Consent not given for ${category} scripts`));
578
+ return;
579
+ }
580
+ const s = document.createElement("script");
581
+ s.id = id;
582
+ s.src = src;
583
+ s.async = true;
584
+ for (const [k, v] of Object.entries(attrs)) s.setAttribute(k, v);
585
+ s.onload = () => resolve();
586
+ s.onerror = () => reject(new Error(`Failed to load script: ${src}`));
587
+ document.body.appendChild(s);
588
+ } catch {
589
+ setTimeout(checkConsent, 100);
519
590
  }
520
591
  };
521
- checkCondition();
592
+ checkConsent();
522
593
  });
523
594
  }
595
+
596
+ // src/index.ts
597
+ init_theme();
524
598
  // Annotate the CommonJS export names for ESM import in node:
525
599
  0 && (module.exports = {
526
600
  ConsentGate,
@@ -528,7 +602,6 @@ function loadConditionalScript(id, src, condition, attrs = {}, maxWaitMs = 5e3)
528
602
  CookieBanner,
529
603
  PreferencesModal,
530
604
  defaultConsentTheme,
531
- loadConditionalScript,
532
605
  loadScript,
533
606
  useConsent,
534
607
  useConsentTexts