@iqworksai/consentiq-react 0.1.2 → 0.1.5
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/README.md +10 -10
- package/dist/index.d.mts +128 -18
- package/dist/index.d.ts +128 -18
- package/dist/index.js +569 -104
- package/dist/index.mjs +561 -100
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createContext, useContext, useEffect, useState, useCallback, useMemo } from "react";
|
|
3
3
|
|
|
4
4
|
// src/api-client.ts
|
|
5
|
-
var DEFAULT_API_URL = "https://
|
|
5
|
+
var DEFAULT_API_URL = "https://consent.iqworks.ai";
|
|
6
6
|
var ConsentIQApiClient = class {
|
|
7
7
|
constructor(propertyKey, apiUrl, debug = false) {
|
|
8
8
|
this.propertyKey = propertyKey;
|
|
@@ -133,6 +133,10 @@ var DEFAULT_CONSENT = {
|
|
|
133
133
|
social: false
|
|
134
134
|
};
|
|
135
135
|
var CONSENT_STORAGE_KEY = "consentiq_consent";
|
|
136
|
+
var RTL_LANGUAGES = /* @__PURE__ */ new Set(["ar", "he", "fa", "ur", "ps", "sd", "dv", "yi"]);
|
|
137
|
+
function isRtlLanguage(lang) {
|
|
138
|
+
return RTL_LANGUAGES.has(lang.split("-")[0].toLowerCase());
|
|
139
|
+
}
|
|
136
140
|
function ConsentIQProvider({
|
|
137
141
|
children,
|
|
138
142
|
propertyKey,
|
|
@@ -144,6 +148,7 @@ function ConsentIQProvider({
|
|
|
144
148
|
onClose,
|
|
145
149
|
autoShow = true,
|
|
146
150
|
language: preferredLanguage,
|
|
151
|
+
locale,
|
|
147
152
|
debug = false
|
|
148
153
|
}) {
|
|
149
154
|
const [config, setConfig] = useState(null);
|
|
@@ -155,7 +160,6 @@ function ConsentIQProvider({
|
|
|
155
160
|
const [language, setLanguage] = useState("en");
|
|
156
161
|
const [regulation, setRegulation] = useState(null);
|
|
157
162
|
const [subjectId, setSubjectId] = useState("");
|
|
158
|
-
const [hasExistingConsent, setHasExistingConsent] = useState(false);
|
|
159
163
|
const apiClient = useMemo(
|
|
160
164
|
() => new ConsentIQApiClient(propertyKey, apiUrl, debug),
|
|
161
165
|
[propertyKey, apiUrl, debug]
|
|
@@ -185,7 +189,7 @@ function ConsentIQProvider({
|
|
|
185
189
|
setSubjectId(sid);
|
|
186
190
|
const propertyConfig = await apiClient.getConfig();
|
|
187
191
|
setConfig(propertyConfig);
|
|
188
|
-
const detectedLang = preferredLanguage || detectLanguage(propertyConfig.property.supportedLanguages);
|
|
192
|
+
const detectedLang = preferredLanguage || locale || detectLanguage(propertyConfig.property.supportedLanguages);
|
|
189
193
|
setLanguage(detectedLang);
|
|
190
194
|
const country = detectCountry();
|
|
191
195
|
if (country && propertyConfig.geoRules) {
|
|
@@ -196,6 +200,7 @@ function ConsentIQProvider({
|
|
|
196
200
|
}
|
|
197
201
|
}
|
|
198
202
|
}
|
|
203
|
+
let foundExistingConsent = false;
|
|
199
204
|
if (sid) {
|
|
200
205
|
const existingConsent = await apiClient.getConsent(sid).catch(() => null);
|
|
201
206
|
if (existingConsent) {
|
|
@@ -203,18 +208,18 @@ function ConsentIQProvider({
|
|
|
203
208
|
if (existingConsent.marketingConsents) {
|
|
204
209
|
setMarketingConsent(existingConsent.marketingConsents);
|
|
205
210
|
}
|
|
206
|
-
setHasExistingConsent(true);
|
|
207
211
|
saveLocalConsent(existingConsent.cookieConsents);
|
|
212
|
+
foundExistingConsent = true;
|
|
208
213
|
} else {
|
|
209
214
|
const localConsent = loadLocalConsent();
|
|
210
215
|
if (localConsent) {
|
|
211
216
|
setConsent(localConsent);
|
|
212
|
-
|
|
217
|
+
foundExistingConsent = true;
|
|
213
218
|
}
|
|
214
219
|
}
|
|
215
220
|
}
|
|
216
221
|
setIsLoading(false);
|
|
217
|
-
if (autoShow && !
|
|
222
|
+
if (autoShow && !foundExistingConsent) {
|
|
218
223
|
setIsBannerVisible(true);
|
|
219
224
|
onOpen?.();
|
|
220
225
|
}
|
|
@@ -230,11 +235,8 @@ function ConsentIQProvider({
|
|
|
230
235
|
providedSubjectId,
|
|
231
236
|
autoGenerateSubjectId,
|
|
232
237
|
preferredLanguage,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
saveLocalConsent,
|
|
236
|
-
onOpen,
|
|
237
|
-
hasExistingConsent
|
|
238
|
+
locale,
|
|
239
|
+
autoShow
|
|
238
240
|
]);
|
|
239
241
|
const submitConsent = useCallback(
|
|
240
242
|
async (cookieConsents, marketingConsents) => {
|
|
@@ -282,10 +284,10 @@ function ConsentIQProvider({
|
|
|
282
284
|
allAccepted.social = true;
|
|
283
285
|
}
|
|
284
286
|
setConsent(allAccepted);
|
|
285
|
-
await submitConsent(allAccepted, marketingConsent);
|
|
286
287
|
setIsBannerVisible(false);
|
|
287
288
|
setIsPreferenceCenterVisible(false);
|
|
288
289
|
onClose?.();
|
|
290
|
+
void submitConsent(allAccepted, marketingConsent);
|
|
289
291
|
}, [config, marketingConsent, submitConsent, onClose]);
|
|
290
292
|
const rejectAll = useCallback(async () => {
|
|
291
293
|
const allRejected = {
|
|
@@ -297,10 +299,10 @@ function ConsentIQProvider({
|
|
|
297
299
|
social: false
|
|
298
300
|
};
|
|
299
301
|
setConsent(allRejected);
|
|
300
|
-
await submitConsent(allRejected, {});
|
|
301
302
|
setIsBannerVisible(false);
|
|
302
303
|
setIsPreferenceCenterVisible(false);
|
|
303
304
|
onClose?.();
|
|
305
|
+
void submitConsent(allRejected, {});
|
|
304
306
|
}, [submitConsent, onClose]);
|
|
305
307
|
const updateConsent = useCallback(
|
|
306
308
|
async (updates) => {
|
|
@@ -311,7 +313,7 @@ function ConsentIQProvider({
|
|
|
311
313
|
// Always enforce necessary
|
|
312
314
|
};
|
|
313
315
|
setConsent(newConsent);
|
|
314
|
-
|
|
316
|
+
void submitConsent(newConsent, marketingConsent);
|
|
315
317
|
},
|
|
316
318
|
[consent, marketingConsent, submitConsent]
|
|
317
319
|
);
|
|
@@ -319,10 +321,13 @@ function ConsentIQProvider({
|
|
|
319
321
|
async (updates) => {
|
|
320
322
|
const newMarketingConsent = { ...marketingConsent, ...updates };
|
|
321
323
|
setMarketingConsent(newMarketingConsent);
|
|
322
|
-
|
|
324
|
+
void submitConsent(consent, newMarketingConsent);
|
|
323
325
|
},
|
|
324
326
|
[consent, marketingConsent, submitConsent]
|
|
325
327
|
);
|
|
328
|
+
const changeLanguage = useCallback((lang) => {
|
|
329
|
+
setLanguage(lang);
|
|
330
|
+
}, []);
|
|
326
331
|
const showBanner = useCallback(() => {
|
|
327
332
|
setIsBannerVisible(true);
|
|
328
333
|
onOpen?.();
|
|
@@ -343,12 +348,12 @@ function ConsentIQProvider({
|
|
|
343
348
|
const resetConsent = useCallback(() => {
|
|
344
349
|
setConsent(DEFAULT_CONSENT);
|
|
345
350
|
setMarketingConsent({});
|
|
346
|
-
setHasExistingConsent(false);
|
|
347
351
|
if (typeof window !== "undefined") {
|
|
348
352
|
localStorage.removeItem(CONSENT_STORAGE_KEY);
|
|
349
353
|
localStorage.removeItem("consentiq_subject_id");
|
|
350
354
|
}
|
|
351
355
|
}, []);
|
|
356
|
+
const dir = isRtlLanguage(language) ? "rtl" : "ltr";
|
|
352
357
|
const contextValue = useMemo(
|
|
353
358
|
() => ({
|
|
354
359
|
consent,
|
|
@@ -358,6 +363,8 @@ function ConsentIQProvider({
|
|
|
358
363
|
isBannerVisible,
|
|
359
364
|
isPreferenceCenterVisible,
|
|
360
365
|
language,
|
|
366
|
+
changeLanguage,
|
|
367
|
+
dir,
|
|
361
368
|
regulation,
|
|
362
369
|
hasConsent,
|
|
363
370
|
hasMarketingConsent,
|
|
@@ -379,6 +386,8 @@ function ConsentIQProvider({
|
|
|
379
386
|
isBannerVisible,
|
|
380
387
|
isPreferenceCenterVisible,
|
|
381
388
|
language,
|
|
389
|
+
changeLanguage,
|
|
390
|
+
dir,
|
|
382
391
|
regulation,
|
|
383
392
|
hasConsent,
|
|
384
393
|
hasMarketingConsent,
|
|
@@ -414,14 +423,70 @@ function useConsentGate(category) {
|
|
|
414
423
|
};
|
|
415
424
|
}
|
|
416
425
|
|
|
426
|
+
// src/components/LanguageSelector.tsx
|
|
427
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
428
|
+
function languageLabel(code) {
|
|
429
|
+
try {
|
|
430
|
+
const display = new Intl.DisplayNames([code], { type: "language" });
|
|
431
|
+
const name = display.of(code);
|
|
432
|
+
if (name) {
|
|
433
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
434
|
+
}
|
|
435
|
+
} catch {
|
|
436
|
+
}
|
|
437
|
+
return code.toUpperCase();
|
|
438
|
+
}
|
|
439
|
+
function LanguageSelector({ className, style }) {
|
|
440
|
+
const { config, language, changeLanguage, dir } = useConsentIQ();
|
|
441
|
+
const languages = config?.property.supportedLanguages ?? [];
|
|
442
|
+
if (languages.length <= 1) {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
const caretSide = dir === "rtl" ? "left" : "right";
|
|
446
|
+
return /* @__PURE__ */ jsx2(
|
|
447
|
+
"select",
|
|
448
|
+
{
|
|
449
|
+
className,
|
|
450
|
+
value: language,
|
|
451
|
+
onChange: (e) => changeLanguage(e.target.value),
|
|
452
|
+
"aria-label": "Language",
|
|
453
|
+
style: {
|
|
454
|
+
appearance: "none",
|
|
455
|
+
WebkitAppearance: "none",
|
|
456
|
+
MozAppearance: "none",
|
|
457
|
+
backgroundColor: "rgba(127, 127, 127, 0.12)",
|
|
458
|
+
backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")`,
|
|
459
|
+
backgroundRepeat: "no-repeat",
|
|
460
|
+
backgroundPosition: `${caretSide} 0.45rem center`,
|
|
461
|
+
backgroundSize: "0.65rem",
|
|
462
|
+
border: "1px solid rgba(127, 127, 127, 0.3)",
|
|
463
|
+
borderRadius: "0.375rem",
|
|
464
|
+
color: "inherit",
|
|
465
|
+
fontFamily: "inherit",
|
|
466
|
+
fontSize: "0.75rem",
|
|
467
|
+
fontWeight: 500,
|
|
468
|
+
lineHeight: 1.2,
|
|
469
|
+
cursor: "pointer",
|
|
470
|
+
outline: "none",
|
|
471
|
+
paddingBlock: "0.3rem",
|
|
472
|
+
paddingInlineStart: "0.6rem",
|
|
473
|
+
paddingInlineEnd: "1.5rem",
|
|
474
|
+
...style
|
|
475
|
+
},
|
|
476
|
+
children: languages.map((code) => /* @__PURE__ */ jsx2("option", { value: code, style: { color: "#18181b" }, children: languageLabel(code) }, code))
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
417
481
|
// src/components/CookieBanner.tsx
|
|
418
|
-
import { Fragment, jsx as
|
|
482
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
419
483
|
function CookieBanner({ className, position, theme, style }) {
|
|
420
484
|
const {
|
|
421
485
|
config,
|
|
422
486
|
isBannerVisible,
|
|
423
487
|
isLoading,
|
|
424
488
|
language,
|
|
489
|
+
dir,
|
|
425
490
|
acceptAll,
|
|
426
491
|
rejectAll,
|
|
427
492
|
showPreferenceCenter
|
|
@@ -431,7 +496,8 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
431
496
|
}
|
|
432
497
|
const bannerConfig = config.banner;
|
|
433
498
|
const translations = config.translations[language] || config.translations[config.property.defaultLanguage] || {};
|
|
434
|
-
const
|
|
499
|
+
const requestedPosition = position || bannerConfig.position || "bottom";
|
|
500
|
+
const resolvedPosition = dir === "rtl" ? requestedPosition === "bottom-left" ? "bottom-right" : requestedPosition === "bottom-right" ? "bottom-left" : requestedPosition : requestedPosition;
|
|
435
501
|
const resolvedTheme = theme || bannerConfig.theme || "dark";
|
|
436
502
|
const effectiveTheme = resolvedTheme === "auto" ? typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : resolvedTheme;
|
|
437
503
|
const positionStyles = {
|
|
@@ -450,14 +516,14 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
450
516
|
}
|
|
451
517
|
};
|
|
452
518
|
const themeStyles = {
|
|
453
|
-
backgroundColor: effectiveTheme === "dark" ? "#
|
|
454
|
-
color: effectiveTheme === "dark" ? "#
|
|
519
|
+
backgroundColor: effectiveTheme === "dark" ? "#09090b" : "#ffffff",
|
|
520
|
+
color: effectiveTheme === "dark" ? "#f4f4f5" : "#27272a",
|
|
455
521
|
borderWidth: "1px",
|
|
456
522
|
borderStyle: "solid",
|
|
457
|
-
borderColor: effectiveTheme === "dark" ? "#
|
|
523
|
+
borderColor: effectiveTheme === "dark" ? "#3f3f46" : "#e4e4e7"
|
|
458
524
|
};
|
|
459
525
|
const buttonPrimaryStyle = {
|
|
460
|
-
backgroundColor: bannerConfig.primaryColor || "#
|
|
526
|
+
backgroundColor: bannerConfig.primaryColor || "#ff6a00",
|
|
461
527
|
color: "#ffffff",
|
|
462
528
|
padding: "0.5rem 1rem",
|
|
463
529
|
borderRadius: "0.5rem",
|
|
@@ -467,8 +533,8 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
467
533
|
fontSize: "0.875rem"
|
|
468
534
|
};
|
|
469
535
|
const buttonSecondaryStyle = {
|
|
470
|
-
backgroundColor: effectiveTheme === "dark" ? "#
|
|
471
|
-
color: effectiveTheme === "dark" ? "#
|
|
536
|
+
backgroundColor: effectiveTheme === "dark" ? "#52525b" : "#e4e4e7",
|
|
537
|
+
color: effectiveTheme === "dark" ? "#f4f4f5" : "#27272a",
|
|
472
538
|
padding: "0.5rem 1rem",
|
|
473
539
|
borderRadius: "0.5rem",
|
|
474
540
|
border: "none",
|
|
@@ -479,13 +545,13 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
479
545
|
const buttonLinkStyle = {
|
|
480
546
|
background: "none",
|
|
481
547
|
border: "none",
|
|
482
|
-
color: effectiveTheme === "dark" ? "#
|
|
548
|
+
color: effectiveTheme === "dark" ? "#a1a1aa" : "#71717a",
|
|
483
549
|
cursor: "pointer",
|
|
484
550
|
fontSize: "0.875rem",
|
|
485
551
|
padding: "0.5rem"
|
|
486
552
|
};
|
|
487
553
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
488
|
-
resolvedPosition === "center" && /* @__PURE__ */
|
|
554
|
+
resolvedPosition === "center" && /* @__PURE__ */ jsx3(
|
|
489
555
|
"div",
|
|
490
556
|
{
|
|
491
557
|
style: {
|
|
@@ -512,8 +578,9 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
512
578
|
role: "dialog",
|
|
513
579
|
"aria-label": "Cookie consent",
|
|
514
580
|
"aria-modal": resolvedPosition === "center",
|
|
581
|
+
dir,
|
|
515
582
|
children: [
|
|
516
|
-
bannerConfig.showLogo && bannerConfig.logoUrl && /* @__PURE__ */
|
|
583
|
+
bannerConfig.showLogo && bannerConfig.logoUrl && /* @__PURE__ */ jsx3(
|
|
517
584
|
"img",
|
|
518
585
|
{
|
|
519
586
|
src: bannerConfig.logoUrl,
|
|
@@ -521,7 +588,7 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
521
588
|
style: { height: "1.5rem", marginBottom: "0.75rem" }
|
|
522
589
|
}
|
|
523
590
|
),
|
|
524
|
-
translations.bannerTitle && /* @__PURE__ */
|
|
591
|
+
translations.bannerTitle && /* @__PURE__ */ jsx3(
|
|
525
592
|
"h2",
|
|
526
593
|
{
|
|
527
594
|
style: {
|
|
@@ -533,7 +600,7 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
533
600
|
children: translations.bannerTitle
|
|
534
601
|
}
|
|
535
602
|
),
|
|
536
|
-
/* @__PURE__ */
|
|
603
|
+
/* @__PURE__ */ jsx3(
|
|
537
604
|
"p",
|
|
538
605
|
{
|
|
539
606
|
style: {
|
|
@@ -555,7 +622,7 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
555
622
|
alignItems: "center"
|
|
556
623
|
},
|
|
557
624
|
children: [
|
|
558
|
-
/* @__PURE__ */
|
|
625
|
+
/* @__PURE__ */ jsx3(
|
|
559
626
|
"button",
|
|
560
627
|
{
|
|
561
628
|
onClick: acceptAll,
|
|
@@ -564,7 +631,7 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
564
631
|
children: translations.acceptAllText || "Accept All"
|
|
565
632
|
}
|
|
566
633
|
),
|
|
567
|
-
/* @__PURE__ */
|
|
634
|
+
/* @__PURE__ */ jsx3(
|
|
568
635
|
"button",
|
|
569
636
|
{
|
|
570
637
|
onClick: rejectAll,
|
|
@@ -573,7 +640,7 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
573
640
|
children: translations.rejectAllText || "Reject All"
|
|
574
641
|
}
|
|
575
642
|
),
|
|
576
|
-
/* @__PURE__ */
|
|
643
|
+
/* @__PURE__ */ jsx3(
|
|
577
644
|
"button",
|
|
578
645
|
{
|
|
579
646
|
onClick: showPreferenceCenter,
|
|
@@ -581,7 +648,8 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
581
648
|
type: "button",
|
|
582
649
|
children: translations.customizeText || "Customize"
|
|
583
650
|
}
|
|
584
|
-
)
|
|
651
|
+
),
|
|
652
|
+
/* @__PURE__ */ jsx3(LanguageSelector, { style: { marginInlineStart: "auto" } })
|
|
585
653
|
]
|
|
586
654
|
}
|
|
587
655
|
)
|
|
@@ -591,9 +659,91 @@ function CookieBanner({ className, position, theme, style }) {
|
|
|
591
659
|
] });
|
|
592
660
|
}
|
|
593
661
|
|
|
662
|
+
// src/components/ConsentTrigger.tsx
|
|
663
|
+
import { useState as useState2 } from "react";
|
|
664
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
665
|
+
function ConsentTrigger({
|
|
666
|
+
className,
|
|
667
|
+
position = "bottom-left",
|
|
668
|
+
theme,
|
|
669
|
+
style,
|
|
670
|
+
label = "Cookie preferences"
|
|
671
|
+
}) {
|
|
672
|
+
const { config, isLoading, isBannerVisible, isPreferenceCenterVisible, showPreferenceCenter, dir } = useConsentIQ();
|
|
673
|
+
const [hovered, setHovered] = useState2(false);
|
|
674
|
+
if (isLoading || isBannerVisible || isPreferenceCenterVisible) {
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
const bannerConfig = config?.banner;
|
|
678
|
+
const resolvedTheme = theme || bannerConfig?.theme || "dark";
|
|
679
|
+
const effectiveTheme = resolvedTheme === "auto" ? typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : resolvedTheme;
|
|
680
|
+
const accent = bannerConfig?.primaryColor || "#ff6a00";
|
|
681
|
+
const corner = dir === "rtl" ? position === "bottom-right" ? "bottom-left" : "bottom-right" : position;
|
|
682
|
+
const cornerStyles = corner === "bottom-right" ? { right: "1rem" } : { left: "1rem" };
|
|
683
|
+
return /* @__PURE__ */ jsx4(
|
|
684
|
+
"button",
|
|
685
|
+
{
|
|
686
|
+
type: "button",
|
|
687
|
+
className,
|
|
688
|
+
onClick: showPreferenceCenter,
|
|
689
|
+
onMouseEnter: () => setHovered(true),
|
|
690
|
+
onMouseLeave: () => setHovered(false),
|
|
691
|
+
onFocus: () => setHovered(true),
|
|
692
|
+
onBlur: () => setHovered(false),
|
|
693
|
+
"aria-label": label,
|
|
694
|
+
title: label,
|
|
695
|
+
style: {
|
|
696
|
+
position: "fixed",
|
|
697
|
+
bottom: "1rem",
|
|
698
|
+
...cornerStyles,
|
|
699
|
+
zIndex: 9997,
|
|
700
|
+
width: "3rem",
|
|
701
|
+
height: "3rem",
|
|
702
|
+
padding: 0,
|
|
703
|
+
borderRadius: "9999px",
|
|
704
|
+
display: "flex",
|
|
705
|
+
alignItems: "center",
|
|
706
|
+
justifyContent: "center",
|
|
707
|
+
cursor: "pointer",
|
|
708
|
+
backgroundColor: effectiveTheme === "dark" ? "#09090b" : "#ffffff",
|
|
709
|
+
color: accent,
|
|
710
|
+
borderWidth: "1px",
|
|
711
|
+
borderStyle: "solid",
|
|
712
|
+
borderColor: effectiveTheme === "dark" ? "#3f3f46" : "#e4e4e7",
|
|
713
|
+
boxShadow: hovered ? "0 6px 16px -2px rgba(0, 0, 0, 0.2)" : "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
|
|
714
|
+
transform: hovered ? "scale(1.05)" : "scale(1)",
|
|
715
|
+
transition: "transform 0.15s ease, box-shadow 0.15s ease",
|
|
716
|
+
...style
|
|
717
|
+
},
|
|
718
|
+
children: /* @__PURE__ */ jsxs2(
|
|
719
|
+
"svg",
|
|
720
|
+
{
|
|
721
|
+
width: "22",
|
|
722
|
+
height: "22",
|
|
723
|
+
viewBox: "0 0 24 24",
|
|
724
|
+
fill: "none",
|
|
725
|
+
stroke: "currentColor",
|
|
726
|
+
strokeWidth: "2",
|
|
727
|
+
strokeLinecap: "round",
|
|
728
|
+
strokeLinejoin: "round",
|
|
729
|
+
"aria-hidden": "true",
|
|
730
|
+
children: [
|
|
731
|
+
/* @__PURE__ */ jsx4("path", { d: "M12 2a10 10 0 1 0 10 10 4 4 0 0 1-5-5 4 4 0 0 1-5-5Z" }),
|
|
732
|
+
/* @__PURE__ */ jsx4("path", { d: "M8.5 8.5v.01" }),
|
|
733
|
+
/* @__PURE__ */ jsx4("path", { d: "M16 15.5v.01" }),
|
|
734
|
+
/* @__PURE__ */ jsx4("path", { d: "M12 12v.01" }),
|
|
735
|
+
/* @__PURE__ */ jsx4("path", { d: "M11 17v.01" }),
|
|
736
|
+
/* @__PURE__ */ jsx4("path", { d: "M7 14v.01" })
|
|
737
|
+
]
|
|
738
|
+
}
|
|
739
|
+
)
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
|
|
594
744
|
// src/components/PreferenceCenter.tsx
|
|
595
|
-
import { useState as
|
|
596
|
-
import { jsx as
|
|
745
|
+
import { useState as useState3, useEffect as useEffect2 } from "react";
|
|
746
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
597
747
|
function PreferenceCenter({ className, theme, style }) {
|
|
598
748
|
const {
|
|
599
749
|
config,
|
|
@@ -601,10 +751,11 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
601
751
|
isPreferenceCenterVisible,
|
|
602
752
|
isLoading,
|
|
603
753
|
language,
|
|
754
|
+
dir,
|
|
604
755
|
updateConsent,
|
|
605
756
|
hidePreferenceCenter
|
|
606
757
|
} = useConsentIQ();
|
|
607
|
-
const [localConsent, setLocalConsent] =
|
|
758
|
+
const [localConsent, setLocalConsent] = useState3(consent);
|
|
608
759
|
useEffect2(() => {
|
|
609
760
|
setLocalConsent(consent);
|
|
610
761
|
}, [consent]);
|
|
@@ -670,8 +821,8 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
670
821
|
};
|
|
671
822
|
const modalStyle = {
|
|
672
823
|
position: "relative",
|
|
673
|
-
backgroundColor: isDark ? "#
|
|
674
|
-
color: isDark ? "#
|
|
824
|
+
backgroundColor: isDark ? "#09090b" : "#ffffff",
|
|
825
|
+
color: isDark ? "#f4f4f5" : "#27272a",
|
|
675
826
|
borderRadius: "0.75rem",
|
|
676
827
|
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
|
|
677
828
|
maxWidth: "600px",
|
|
@@ -685,7 +836,7 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
685
836
|
};
|
|
686
837
|
const headerStyle = {
|
|
687
838
|
padding: "1rem 1.5rem",
|
|
688
|
-
borderBottom: `1px solid ${isDark ? "#
|
|
839
|
+
borderBottom: `1px solid ${isDark ? "#3f3f46" : "#e4e4e7"}`,
|
|
689
840
|
display: "flex",
|
|
690
841
|
justifyContent: "space-between",
|
|
691
842
|
alignItems: "center"
|
|
@@ -697,14 +848,14 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
697
848
|
};
|
|
698
849
|
const footerStyle = {
|
|
699
850
|
padding: "1rem 1.5rem",
|
|
700
|
-
borderTop: `1px solid ${isDark ? "#
|
|
851
|
+
borderTop: `1px solid ${isDark ? "#3f3f46" : "#e4e4e7"}`,
|
|
701
852
|
display: "flex",
|
|
702
853
|
gap: "0.5rem",
|
|
703
854
|
justifyContent: "flex-end"
|
|
704
855
|
};
|
|
705
856
|
const categoryStyle = {
|
|
706
857
|
padding: "1rem",
|
|
707
|
-
backgroundColor: isDark ? "#
|
|
858
|
+
backgroundColor: isDark ? "#18181b" : "#fafafa",
|
|
708
859
|
borderRadius: "0.5rem",
|
|
709
860
|
marginBottom: "0.75rem"
|
|
710
861
|
};
|
|
@@ -714,7 +865,7 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
714
865
|
justifyContent: "space-between"
|
|
715
866
|
};
|
|
716
867
|
const buttonPrimaryStyle = {
|
|
717
|
-
backgroundColor: bannerConfig.primaryColor || "#
|
|
868
|
+
backgroundColor: bannerConfig.primaryColor || "#ff6a00",
|
|
718
869
|
color: "#ffffff",
|
|
719
870
|
padding: "0.5rem 1rem",
|
|
720
871
|
borderRadius: "0.5rem",
|
|
@@ -724,8 +875,8 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
724
875
|
fontSize: "0.875rem"
|
|
725
876
|
};
|
|
726
877
|
const buttonSecondaryStyle = {
|
|
727
|
-
backgroundColor: isDark ? "#
|
|
728
|
-
color: isDark ? "#
|
|
878
|
+
backgroundColor: isDark ? "#52525b" : "#e4e4e7",
|
|
879
|
+
color: isDark ? "#f4f4f5" : "#27272a",
|
|
729
880
|
padding: "0.5rem 1rem",
|
|
730
881
|
borderRadius: "0.5rem",
|
|
731
882
|
border: "none",
|
|
@@ -736,47 +887,59 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
736
887
|
const buttonTextStyle = {
|
|
737
888
|
background: "none",
|
|
738
889
|
border: "none",
|
|
739
|
-
color:
|
|
890
|
+
color: bannerConfig.primaryColor || "#ff6a00",
|
|
740
891
|
cursor: "pointer",
|
|
741
892
|
fontSize: "0.875rem",
|
|
742
|
-
|
|
893
|
+
fontWeight: 500,
|
|
894
|
+
padding: 0,
|
|
895
|
+
textDecoration: "underline",
|
|
896
|
+
textUnderlineOffset: "2px"
|
|
743
897
|
};
|
|
744
|
-
return /* @__PURE__ */
|
|
745
|
-
/* @__PURE__ */
|
|
746
|
-
/* @__PURE__ */
|
|
747
|
-
/* @__PURE__ */
|
|
748
|
-
/* @__PURE__ */
|
|
749
|
-
/* @__PURE__ */
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
898
|
+
return /* @__PURE__ */ jsxs3("div", { style: containerStyle, className, children: [
|
|
899
|
+
/* @__PURE__ */ jsx5("div", { style: backdropStyle, onClick: hidePreferenceCenter }),
|
|
900
|
+
/* @__PURE__ */ jsxs3("div", { style: modalStyle, role: "dialog", "aria-modal": "true", "aria-label": "Cookie preferences", dir, children: [
|
|
901
|
+
/* @__PURE__ */ jsxs3("div", { style: headerStyle, children: [
|
|
902
|
+
/* @__PURE__ */ jsx5("h2", { style: { margin: 0, fontSize: "1.25rem", fontWeight: 600, lineHeight: 1 }, children: "Cookie Preferences" }),
|
|
903
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "0.875rem" }, children: [
|
|
904
|
+
/* @__PURE__ */ jsx5(LanguageSelector, {}),
|
|
905
|
+
/* @__PURE__ */ jsx5(
|
|
906
|
+
"button",
|
|
907
|
+
{
|
|
908
|
+
onClick: hidePreferenceCenter,
|
|
909
|
+
style: {
|
|
910
|
+
display: "flex",
|
|
911
|
+
alignItems: "center",
|
|
912
|
+
justifyContent: "center",
|
|
913
|
+
width: "1.75rem",
|
|
914
|
+
height: "1.75rem",
|
|
915
|
+
padding: 0,
|
|
916
|
+
background: "none",
|
|
917
|
+
border: "none",
|
|
918
|
+
fontSize: "1.5rem",
|
|
919
|
+
cursor: "pointer",
|
|
920
|
+
color: isDark ? "#a1a1aa" : "#71717a",
|
|
921
|
+
lineHeight: 1
|
|
922
|
+
},
|
|
923
|
+
"aria-label": "Close",
|
|
924
|
+
type: "button",
|
|
925
|
+
children: "\xD7"
|
|
926
|
+
}
|
|
927
|
+
)
|
|
928
|
+
] })
|
|
766
929
|
] }),
|
|
767
|
-
/* @__PURE__ */
|
|
768
|
-
/* @__PURE__ */
|
|
769
|
-
/* @__PURE__ */
|
|
770
|
-
/* @__PURE__ */
|
|
771
|
-
/* @__PURE__ */
|
|
930
|
+
/* @__PURE__ */ jsxs3("div", { style: bodyStyle, children: [
|
|
931
|
+
/* @__PURE__ */ jsx5("p", { style: { marginTop: 0, marginBottom: "1.5rem", opacity: 0.8, fontSize: "0.875rem" }, children: translations.bannerDescription || "Manage your cookie preferences. Some cookies are essential for the site to function properly." }),
|
|
932
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", gap: "1rem", marginBottom: "1.5rem" }, children: [
|
|
933
|
+
/* @__PURE__ */ jsx5("button", { onClick: handleAcceptAll, style: buttonTextStyle, type: "button", children: "Enable All" }),
|
|
934
|
+
/* @__PURE__ */ jsx5("button", { onClick: handleRejectAll, style: buttonTextStyle, type: "button", children: "Disable All" })
|
|
772
935
|
] }),
|
|
773
936
|
config.categories.filter((cat) => cat.enabled).map((category) => {
|
|
774
937
|
const categoryTranslation = translations.categories?.[category.code];
|
|
775
938
|
const isEnabled = localConsent[category.code] ?? category.defaultState;
|
|
776
|
-
return /* @__PURE__ */
|
|
777
|
-
/* @__PURE__ */
|
|
778
|
-
/* @__PURE__ */
|
|
779
|
-
/* @__PURE__ */
|
|
939
|
+
return /* @__PURE__ */ jsxs3("div", { style: categoryStyle, children: [
|
|
940
|
+
/* @__PURE__ */ jsxs3("div", { style: toggleContainerStyle, children: [
|
|
941
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "baseline", flexWrap: "wrap" }, children: [
|
|
942
|
+
/* @__PURE__ */ jsx5(
|
|
780
943
|
"h3",
|
|
781
944
|
{
|
|
782
945
|
style: {
|
|
@@ -787,19 +950,19 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
787
950
|
children: categoryTranslation?.title || category.name
|
|
788
951
|
}
|
|
789
952
|
),
|
|
790
|
-
category.isRequired && /* @__PURE__ */
|
|
953
|
+
category.isRequired && /* @__PURE__ */ jsx5(
|
|
791
954
|
"span",
|
|
792
955
|
{
|
|
793
956
|
style: {
|
|
794
957
|
fontSize: "0.75rem",
|
|
795
|
-
color: isDark ? "#
|
|
958
|
+
color: isDark ? "#a1a1aa" : "#71717a",
|
|
796
959
|
marginLeft: "0.5rem"
|
|
797
960
|
},
|
|
798
961
|
children: "(Required)"
|
|
799
962
|
}
|
|
800
963
|
)
|
|
801
964
|
] }),
|
|
802
|
-
/* @__PURE__ */
|
|
965
|
+
/* @__PURE__ */ jsx5(
|
|
803
966
|
Toggle,
|
|
804
967
|
{
|
|
805
968
|
checked: isEnabled,
|
|
@@ -809,7 +972,7 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
809
972
|
}
|
|
810
973
|
)
|
|
811
974
|
] }),
|
|
812
|
-
/* @__PURE__ */
|
|
975
|
+
/* @__PURE__ */ jsx5(
|
|
813
976
|
"p",
|
|
814
977
|
{
|
|
815
978
|
style: {
|
|
@@ -823,14 +986,14 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
823
986
|
] }, category.code);
|
|
824
987
|
})
|
|
825
988
|
] }),
|
|
826
|
-
/* @__PURE__ */
|
|
827
|
-
/* @__PURE__ */
|
|
828
|
-
/* @__PURE__ */
|
|
989
|
+
/* @__PURE__ */ jsxs3("div", { style: footerStyle, children: [
|
|
990
|
+
/* @__PURE__ */ jsx5("button", { onClick: hidePreferenceCenter, style: buttonSecondaryStyle, type: "button", children: "Cancel" }),
|
|
991
|
+
/* @__PURE__ */ jsx5("button", { onClick: handleSave, style: buttonPrimaryStyle, type: "button", children: translations.savePreferencesText || "Save Preferences" })
|
|
829
992
|
] }),
|
|
830
|
-
/* @__PURE__ */
|
|
993
|
+
/* @__PURE__ */ jsx5("div", { style: {
|
|
831
994
|
padding: "0.5rem 1.5rem 0.75rem",
|
|
832
995
|
textAlign: "center"
|
|
833
|
-
}, children: /* @__PURE__ */
|
|
996
|
+
}, children: /* @__PURE__ */ jsxs3(
|
|
834
997
|
"a",
|
|
835
998
|
{
|
|
836
999
|
href: "https://consent.iqworks.ai",
|
|
@@ -841,12 +1004,12 @@ function PreferenceCenter({ className, theme, style }) {
|
|
|
841
1004
|
alignItems: "center",
|
|
842
1005
|
gap: "0.35rem",
|
|
843
1006
|
fontSize: "0.7rem",
|
|
844
|
-
color: isDark ? "#
|
|
1007
|
+
color: isDark ? "#71717a" : "#a1a1aa",
|
|
845
1008
|
textDecoration: "none"
|
|
846
1009
|
},
|
|
847
1010
|
children: [
|
|
848
|
-
|
|
849
|
-
|
|
1011
|
+
"Powered by",
|
|
1012
|
+
/* @__PURE__ */ jsx5(ConsentIQLogo, { isDark })
|
|
850
1013
|
]
|
|
851
1014
|
}
|
|
852
1015
|
) })
|
|
@@ -863,7 +1026,7 @@ function Toggle({
|
|
|
863
1026
|
position: "relative",
|
|
864
1027
|
width: "44px",
|
|
865
1028
|
height: "24px",
|
|
866
|
-
backgroundColor: checked ? primaryColor || "#
|
|
1029
|
+
backgroundColor: checked ? primaryColor || "#ff6a00" : "#a1a1aa",
|
|
867
1030
|
borderRadius: "12px",
|
|
868
1031
|
cursor: disabled ? "not-allowed" : "pointer",
|
|
869
1032
|
opacity: disabled ? 0.5 : 1,
|
|
@@ -872,15 +1035,15 @@ function Toggle({
|
|
|
872
1035
|
const thumbStyle = {
|
|
873
1036
|
position: "absolute",
|
|
874
1037
|
top: "2px",
|
|
875
|
-
|
|
1038
|
+
insetInlineStart: checked ? "22px" : "2px",
|
|
876
1039
|
width: "20px",
|
|
877
1040
|
height: "20px",
|
|
878
1041
|
backgroundColor: "#ffffff",
|
|
879
1042
|
borderRadius: "50%",
|
|
880
|
-
transition: "
|
|
1043
|
+
transition: "inset-inline-start 0.2s",
|
|
881
1044
|
boxShadow: "0 1px 3px rgba(0, 0, 0, 0.2)"
|
|
882
1045
|
};
|
|
883
|
-
return /* @__PURE__ */
|
|
1046
|
+
return /* @__PURE__ */ jsx5(
|
|
884
1047
|
"button",
|
|
885
1048
|
{
|
|
886
1049
|
type: "button",
|
|
@@ -889,13 +1052,47 @@ function Toggle({
|
|
|
889
1052
|
onClick: disabled ? void 0 : onChange,
|
|
890
1053
|
style: trackStyle,
|
|
891
1054
|
disabled,
|
|
892
|
-
children: /* @__PURE__ */
|
|
1055
|
+
children: /* @__PURE__ */ jsx5("span", { style: thumbStyle })
|
|
893
1056
|
}
|
|
894
1057
|
);
|
|
895
1058
|
}
|
|
1059
|
+
function ConsentIQLogo({ isDark }) {
|
|
1060
|
+
if (isDark) {
|
|
1061
|
+
return /* @__PURE__ */ jsxs3("svg", { width: "80", height: "14", viewBox: "0 0 487 85", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
1062
|
+
/* @__PURE__ */ jsx5("path", { d: "M49.3323 11.8633L41.634 7.59045L12.417 24.7048C9.84034 52.4047 19.3957 71.4081 35.7685 82.4129C20.9524 65.4494 18.5009 39.8252 19.664 29.2678L49.3323 11.8633Z", fill: "#FF6503" }),
|
|
1063
|
+
/* @__PURE__ */ jsx5("path", { d: "M58.8505 6.18471L51.0667 2.15857L43.3711 6.59458L50.9943 10.8186L58.8505 6.18471Z", fill: "white" }),
|
|
1064
|
+
/* @__PURE__ */ jsx5("path", { d: "M28.2107 33.8309C24.131 59.3834 31.5211 76.8658 35.7261 82.413C35.7261 82.413 34.4207 77.3773 33.847 74.0981C31.4064 60.1473 32.3708 50.2576 35.1891 37.8571L66.0559 20.1421C65.3617 30.7093 59.5471 53.4338 42.7104 68.3178C50.6824 64.6214 61.1777 58.5798 64.854 51.8087C64.6636 52.2227 66.2567 49.3651 66.0559 49.771C73.3369 35.6413 74.3274 23.7642 74.3767 15.0422L66.8613 10.7477L28.2107 33.8309Z", fill: "#FF6503" }),
|
|
1065
|
+
/* @__PURE__ */ jsx5("path", { d: "M63.7104 54.4578C57.4728 65.6025 33.8945 74.3768 33.8945 74.3768C33.8945 74.3768 34.1088 75.8873 34.643 78.0695C35.1772 80.2517 35.7138 82.3943 35.7138 82.3943C43.4068 78.4438 55.3104 70.2184 63.7104 54.4578Z", fill: "white" }),
|
|
1066
|
+
/* @__PURE__ */ jsx5("path", { d: "M473.855 85V60.5074C472.26 61.7151 470.473 62.6571 468.492 63.3334C466.512 64.0581 464.362 64.4204 462.043 64.4204C457.985 64.4204 454.314 63.3817 451.029 61.3045C447.744 59.2272 445.111 56.4736 443.13 53.0436C441.198 49.5654 440.231 45.7248 440.231 41.5219C440.231 37.319 441.198 33.4784 443.13 30.0002C445.111 26.5219 447.744 23.7683 451.029 21.7393C454.314 19.6621 457.985 18.6234 462.043 18.6234C464.797 18.6234 467.333 19.1065 469.652 20.0727C471.97 21.0389 473.951 22.3674 475.594 24.0582V19.7828H486.463V85H473.855ZM463.492 53.3335C465.618 53.3335 467.55 52.8021 469.289 51.7393C471.028 50.6765 472.405 49.2513 473.42 47.4639C474.483 45.6765 475.014 43.6958 475.014 41.5219C475.014 39.348 474.483 37.3673 473.42 35.5799C472.405 33.7925 471.028 32.3673 469.289 31.3045C467.55 30.2417 465.618 29.7103 463.492 29.7103C461.367 29.7103 459.434 30.2417 457.695 31.3045C455.956 32.3673 454.555 33.7925 453.492 35.5799C452.478 37.3673 451.971 39.348 451.971 41.5219C451.971 43.6958 452.478 45.6765 453.492 47.4639C454.555 49.2513 455.956 50.6765 457.695 51.7393C459.434 52.8021 461.367 53.3335 463.492 53.3335Z", fill: "#FF6503" }),
|
|
1067
|
+
/* @__PURE__ */ jsx5("path", { d: "M420.133 63.2607V19.7826H432.742V63.2607H420.133ZM426.437 13.4782C424.553 13.4782 422.959 12.826 421.655 11.5217C420.35 10.2174 419.698 8.62316 419.698 6.73911C419.698 4.80675 420.35 3.21255 421.655 1.95651C422.959 0.65217 424.553 0 426.437 0C428.37 0 429.964 0.65217 431.22 1.95651C432.524 3.21255 433.176 4.80675 433.176 6.73911C433.176 8.62316 432.524 10.2174 431.22 11.5217C429.964 12.826 428.37 13.4782 426.437 13.4782Z", fill: "#FF6503" }),
|
|
1068
|
+
/* @__PURE__ */ jsx5("path", { d: "M392.451 63.2607V29.7825H384.335V19.7825H392.668V5.28979H404.842V19.7825H413.465V29.7825H405.06V63.2607H392.451Z", fill: "white" }),
|
|
1069
|
+
/* @__PURE__ */ jsx5("path", { d: "M338.059 63.2605V19.7824H349.363V24.565C350.909 22.536 352.817 20.9901 355.088 19.9273C357.358 18.8645 359.798 18.3331 362.406 18.3331C365.498 18.3331 368.373 19.0819 371.03 20.5795C373.735 22.0288 375.909 24.1785 377.551 27.0288C379.242 29.8307 380.087 33.2365 380.087 37.2461V63.2605H367.479V38.9128C367.479 36.4973 366.754 34.3476 365.305 32.4635C363.856 30.5795 361.778 29.6374 359.073 29.6374C356.899 29.6374 354.943 30.3862 353.203 31.8838C351.513 33.3331 350.667 35.6278 350.667 38.7679V63.2605H338.059Z", fill: "white" }),
|
|
1070
|
+
/* @__PURE__ */ jsx5("path", { d: "M310.56 64.7098C305.68 64.7098 301.381 63.6953 297.661 61.6664C293.941 59.6374 291.043 56.8596 288.966 53.333C286.888 49.7582 285.85 45.6761 285.85 41.0867C285.85 36.6906 286.864 32.8017 288.893 29.4201C290.922 25.9901 293.652 23.2848 297.081 21.3041C300.56 19.3235 304.4 18.3331 308.603 18.3331C312.903 18.3331 316.743 19.3235 320.125 21.3041C323.507 23.2365 326.164 25.8935 328.096 29.2751C330.077 32.6568 331.067 36.4973 331.067 40.7968V45.2171H304.545C303.337 45.2171 302.178 45.1447 301.067 44.9997C299.956 44.8548 298.845 44.6857 297.734 44.4925C298.313 47.391 299.738 49.7582 302.009 51.5939C304.328 53.3813 307.275 54.2751 310.85 54.2751C313.603 54.2751 316.067 53.7195 318.241 52.6084C320.463 51.4973 322.275 50.1205 323.676 48.478L326.429 59.7823C324.255 61.4248 321.792 62.6567 319.038 63.4779C316.333 64.2992 313.507 64.7098 310.56 64.7098ZM297.444 36.8838C299.859 36.3524 302.226 36.0867 304.545 36.0867H312.226C313.579 36.0867 314.859 36.135 316.067 36.2316C317.275 36.3283 318.41 36.4973 319.473 36.7389C318.748 34.1302 317.42 32.0771 315.487 30.5795C313.603 29.0819 311.26 28.3331 308.458 28.3331C305.801 28.3331 303.482 29.1061 301.502 30.6519C299.569 32.1495 298.217 34.2268 297.444 36.8838Z", fill: "white" }),
|
|
1071
|
+
/* @__PURE__ */ jsx5("path", { d: "M263.884 64.7098C260.937 64.7098 257.942 64.2267 254.898 63.2605C251.903 62.2944 249.56 60.99 247.869 59.3475L250.985 47.4635C252.386 49.3959 254.318 51.0867 256.782 52.5359C259.294 53.9852 261.879 54.7098 264.536 54.7098C266.323 54.7098 267.603 54.3717 268.376 53.6954C269.198 53.019 269.608 52.1978 269.608 51.2316C269.608 50.1205 269.198 49.3234 268.376 48.8403C267.555 48.3089 266.71 47.8741 265.84 47.536L259.753 45.2171C258.401 44.6857 256.855 43.9611 255.115 43.0432C253.376 42.1253 251.855 40.821 250.55 39.1302C249.294 37.4394 248.666 35.2171 248.666 32.4635C248.666 29.9515 249.294 27.6326 250.55 25.507C251.806 23.3814 253.618 21.6665 255.985 20.3621C258.401 19.0095 261.299 18.3331 264.681 18.3331C267.821 18.3331 270.743 18.8645 273.449 19.9273C276.202 20.9901 278.207 22.1737 279.463 23.478L276.565 34.9273C274.922 32.8017 272.966 31.1833 270.695 30.0722C268.473 28.9128 266.347 28.3331 264.318 28.3331C262.772 28.3331 261.637 28.6471 260.913 29.2751C260.188 29.9031 259.826 30.6278 259.826 31.449C259.826 32.0771 260.067 32.7051 260.55 33.3331C261.082 33.9128 261.951 34.4442 263.159 34.9273L268.811 37.0287C270.454 37.6084 272.193 38.3814 274.028 39.3476C275.913 40.3137 277.507 41.6664 278.811 43.4055C280.115 45.0963 280.768 47.4393 280.768 50.4345C280.768 54.6374 279.198 58.0673 276.057 60.7243C272.966 63.3813 268.908 64.7098 263.884 64.7098Z", fill: "white" }),
|
|
1072
|
+
/* @__PURE__ */ jsx5("path", { d: "M198.861 63.2605V19.7824H210.166V24.565C211.712 22.536 213.62 20.9901 215.89 19.9273C218.161 18.8645 220.6 18.3331 223.209 18.3331C226.301 18.3331 229.175 19.0819 231.832 20.5795C234.538 22.0288 236.711 24.1785 238.354 27.0288C240.045 29.8307 240.89 33.2365 240.89 37.2461V63.2605H228.282V38.9128C228.282 36.4973 227.557 34.3476 226.108 32.4635C224.658 30.5795 222.581 29.6374 219.876 29.6374C217.702 29.6374 215.745 30.3862 214.006 31.8838C212.315 33.3331 211.47 35.6278 211.47 38.7679V63.2605H198.861Z", fill: "white" }),
|
|
1073
|
+
/* @__PURE__ */ jsx5("path", { d: "M167.99 64.7098C163.69 64.7098 159.753 63.6712 156.178 61.5939C152.603 59.5166 149.753 56.7147 147.628 53.1881C145.55 49.6616 144.512 45.7727 144.512 41.5215C144.512 37.222 145.55 33.3331 147.628 29.8548C149.753 26.3283 152.603 23.5264 156.178 21.4491C159.753 19.3718 163.69 18.3331 167.99 18.3331C172.338 18.3331 176.275 19.3718 179.801 21.4491C183.376 23.5264 186.202 26.3283 188.28 29.8548C190.405 33.3331 191.468 37.222 191.468 41.5215C191.468 45.7727 190.405 49.6616 188.28 53.1881C186.202 56.7147 183.376 59.5166 179.801 61.5939C176.275 63.6712 172.338 64.7098 167.99 64.7098ZM167.99 53.4055C170.164 53.4055 172.12 52.8741 173.859 51.8113C175.647 50.7485 177.048 49.3234 178.062 47.536C179.125 45.7002 179.657 43.6954 179.657 41.5215C179.657 39.2993 179.125 37.2944 178.062 35.507C177.048 33.7196 175.647 32.2944 173.859 31.2316C172.12 30.1688 170.164 29.6374 167.99 29.6374C165.816 29.6374 163.835 30.1688 162.048 31.2316C160.309 32.2944 158.908 33.7196 157.845 35.507C156.831 37.2944 156.323 39.2993 156.323 41.5215C156.323 43.6954 156.831 45.7002 157.845 47.536C158.908 49.3234 160.309 50.7485 162.048 51.8113C163.835 52.8741 165.816 53.4055 167.99 53.4055Z", fill: "white" }),
|
|
1074
|
+
/* @__PURE__ */ jsx5("path", { d: "M124.478 64.7098C120.179 64.7098 116.242 63.6712 112.667 61.5939C109.092 59.5166 106.242 56.7147 104.116 53.1881C102.039 49.6616 101 45.7727 101 41.5215C101 37.222 102.039 33.3331 104.116 29.8548C106.242 26.3283 109.092 23.5264 112.667 21.4491C116.242 19.3718 120.179 18.3331 124.478 18.3331C127.473 18.3331 130.299 18.8404 132.956 19.8549C135.662 20.821 138.053 22.2703 140.13 24.2027L136.869 37.0287C135.662 35.0481 134.043 33.3331 132.014 31.8838C130.034 30.3862 127.691 29.6374 124.985 29.6374C122.715 29.6374 120.686 30.1688 118.899 31.2316C117.111 32.2944 115.71 33.7196 114.696 35.507C113.681 37.2944 113.174 39.2993 113.174 41.5215C113.174 43.6954 113.681 45.7002 114.696 47.536C115.71 49.3234 117.111 50.7485 118.899 51.8113C120.686 52.8741 122.715 53.4055 124.985 53.4055C127.691 53.4055 130.034 52.6809 132.014 51.2316C134.043 49.734 135.662 47.9949 136.869 46.0142L140.13 58.8403C138.053 60.7726 135.662 62.2461 132.956 63.2605C130.299 64.2267 127.473 64.7098 124.478 64.7098Z", fill: "white" })
|
|
1075
|
+
] });
|
|
1076
|
+
}
|
|
1077
|
+
return /* @__PURE__ */ jsxs3("svg", { width: "80", height: "14", viewBox: "0 0 487 85", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
1078
|
+
/* @__PURE__ */ jsx5("path", { d: "M48.6448 12.0775L40.9465 7.80469L11.7295 24.9191C9.15284 52.6189 18.7082 71.6223 35.081 82.6271C20.2649 65.6636 17.8134 40.0395 18.9765 29.482L48.6448 12.0775Z", fill: "#FF6503" }),
|
|
1079
|
+
/* @__PURE__ */ jsx5("path", { d: "M58.163 6.39894L50.3792 2.3728L42.6836 6.80882L50.3068 11.0328L58.163 6.39894Z", fill: "#3A3A3A" }),
|
|
1080
|
+
/* @__PURE__ */ jsx5("path", { d: "M27.5232 34.0452C23.4435 59.5977 30.8336 77.08 35.0386 82.6272C35.0386 82.6272 33.7332 77.5916 33.1595 74.3123C30.7189 60.3615 31.6833 50.4718 34.5016 38.0713L65.3684 20.3563C64.6742 30.9236 58.8596 53.6481 42.0229 68.532C49.9949 64.8357 60.4902 58.794 64.1665 52.0229C63.9761 52.437 65.5692 49.5794 65.3684 49.9853C72.6494 35.8555 73.6399 23.9785 73.6892 15.2564L66.1738 10.9619L27.5232 34.0452Z", fill: "#FF6503" }),
|
|
1081
|
+
/* @__PURE__ */ jsx5("path", { d: "M63.0229 54.672C56.7853 65.8167 33.207 74.5911 33.207 74.5911C33.207 74.5911 33.4213 76.1015 33.9555 78.2837C34.4897 80.4659 35.0263 82.6085 35.0263 82.6085C42.7193 78.658 54.6229 70.4326 63.0229 54.672Z", fill: "#3A3A3A" }),
|
|
1082
|
+
/* @__PURE__ */ jsx5("path", { d: "M473.854 85V60.5074C472.259 61.7151 470.472 62.6571 468.491 63.3334C466.511 64.0581 464.361 64.4204 462.042 64.4204C457.984 64.4204 454.313 63.3817 451.028 61.3045C447.743 59.2272 445.11 56.4736 443.129 53.0436C441.197 49.5654 440.23 45.7248 440.23 41.5219C440.23 37.319 441.197 33.4784 443.129 30.0002C445.11 26.5219 447.743 23.7683 451.028 21.7393C454.313 19.6621 457.984 18.6234 462.042 18.6234C464.796 18.6234 467.332 19.1065 469.651 20.0727C471.969 21.0389 473.95 22.3674 475.593 24.0582V19.7828H486.462V85H473.854ZM463.491 53.3335C465.617 53.3335 467.549 52.8021 469.288 51.7393C471.027 50.6765 472.404 49.2513 473.419 47.4639C474.482 45.6765 475.013 43.6958 475.013 41.5219C475.013 39.348 474.482 37.3673 473.419 35.5799C472.404 33.7925 471.027 32.3673 469.288 31.3045C467.549 30.2417 465.617 29.7103 463.491 29.7103C461.366 29.7103 459.433 30.2417 457.694 31.3045C455.955 32.3673 454.554 33.7925 453.491 35.5799C452.477 37.3673 451.97 39.348 451.97 41.5219C451.97 43.6958 452.477 45.6765 453.491 47.4639C454.554 49.2513 455.955 50.6765 457.694 51.7393C459.433 52.8021 461.366 53.3335 463.491 53.3335Z", fill: "#FF6503" }),
|
|
1083
|
+
/* @__PURE__ */ jsx5("path", { d: "M420.132 63.2607V19.7826H432.741V63.2607H420.132ZM426.436 13.4782C424.552 13.4782 422.958 12.826 421.654 11.5217C420.349 10.2174 419.697 8.62316 419.697 6.73911C419.697 4.80675 420.349 3.21255 421.654 1.95651C422.958 0.65217 424.552 0 426.436 0C428.369 0 429.963 0.65217 431.219 1.95651C432.523 3.21255 433.175 4.80675 433.175 6.73911C433.175 8.62316 432.523 10.2174 431.219 11.5217C429.963 12.826 428.369 13.4782 426.436 13.4782Z", fill: "#FF6503" }),
|
|
1084
|
+
/* @__PURE__ */ jsx5("path", { d: "M392.452 63.2607V29.7825H384.336V19.7825H392.669V5.28979H404.843V19.7825H413.466V29.7825H405.061V63.2607H392.452Z", fill: "#3A3A3A" }),
|
|
1085
|
+
/* @__PURE__ */ jsx5("path", { d: "M338.059 63.2605V19.7824H349.363V24.565C350.909 22.536 352.817 20.9901 355.088 19.9273C357.358 18.8645 359.798 18.3331 362.406 18.3331C365.498 18.3331 368.373 19.0819 371.03 20.5795C373.735 22.0288 375.909 24.1785 377.551 27.0288C379.242 29.8307 380.087 33.2365 380.087 37.2461V63.2605H367.479V38.9128C367.479 36.4973 366.754 34.3476 365.305 32.4635C363.856 30.5795 361.778 29.6374 359.073 29.6374C356.899 29.6374 354.943 30.3862 353.203 31.8838C351.513 33.3331 350.667 35.6278 350.667 38.7679V63.2605H338.059Z", fill: "#3A3A3A" }),
|
|
1086
|
+
/* @__PURE__ */ jsx5("path", { d: "M310.56 64.7098C305.68 64.7098 301.381 63.6953 297.661 61.6664C293.941 59.6374 291.043 56.8596 288.966 53.333C286.888 49.7582 285.85 45.6761 285.85 41.0867C285.85 36.6906 286.864 32.8017 288.893 29.4201C290.922 25.9901 293.652 23.2848 297.081 21.3041C300.56 19.3235 304.4 18.3331 308.603 18.3331C312.903 18.3331 316.743 19.3235 320.125 21.3041C323.507 23.2365 326.164 25.8935 328.096 29.2751C330.077 32.6568 331.067 36.4973 331.067 40.7968V45.2171H304.545C303.337 45.2171 302.178 45.1447 301.067 44.9997C299.956 44.8548 298.845 44.6857 297.734 44.4925C298.313 47.391 299.738 49.7582 302.009 51.5939C304.328 53.3813 307.275 54.2751 310.85 54.2751C313.603 54.2751 316.067 53.7195 318.241 52.6084C320.463 51.4973 322.275 50.1205 323.676 48.478L326.429 59.7823C324.255 61.4248 321.792 62.6567 319.038 63.4779C316.333 64.2992 313.507 64.7098 310.56 64.7098ZM297.444 36.8838C299.859 36.3524 302.226 36.0867 304.545 36.0867H312.226C313.579 36.0867 314.859 36.135 316.067 36.2316C317.275 36.3283 318.41 36.4973 319.473 36.7389C318.748 34.1302 317.42 32.0771 315.487 30.5795C313.603 29.0819 311.26 28.3331 308.458 28.3331C305.801 28.3331 303.482 29.1061 301.502 30.6519C299.569 32.1495 298.217 34.2268 297.444 36.8838Z", fill: "#3A3A3A" }),
|
|
1087
|
+
/* @__PURE__ */ jsx5("path", { d: "M263.884 64.7098C260.937 64.7098 257.942 64.2267 254.898 63.2605C251.903 62.2944 249.56 60.99 247.869 59.3475L250.985 47.4635C252.386 49.3959 254.318 51.0867 256.782 52.5359C259.294 53.9852 261.879 54.7098 264.536 54.7098C266.323 54.7098 267.603 54.3717 268.376 53.6954C269.198 53.019 269.608 52.1978 269.608 51.2316C269.608 50.1205 269.198 49.3234 268.376 48.8403C267.555 48.3089 266.71 47.8741 265.84 47.536L259.753 45.2171C258.401 44.6857 256.855 43.9611 255.115 43.0432C253.376 42.1253 251.855 40.821 250.55 39.1302C249.294 37.4394 248.666 35.2171 248.666 32.4635C248.666 29.9515 249.294 27.6326 250.55 25.507C251.806 23.3814 253.618 21.6665 255.985 20.3621C258.401 19.0095 261.299 18.3331 264.681 18.3331C267.821 18.3331 270.743 18.8645 273.449 19.9273C276.202 20.9901 278.207 22.1737 279.463 23.478L276.565 34.9273C274.922 32.8017 272.966 31.1833 270.695 30.0722C268.473 28.9128 266.347 28.3331 264.318 28.3331C262.772 28.3331 261.637 28.6471 260.913 29.2751C260.188 29.9031 259.826 30.6278 259.826 31.449C259.826 32.0771 260.067 32.7051 260.55 33.3331C261.082 33.9128 261.951 34.4442 263.159 34.9273L268.811 37.0287C270.454 37.6084 272.193 38.3814 274.028 39.3476C275.913 40.3137 277.507 41.6664 278.811 43.4055C280.115 45.0963 280.768 47.4393 280.768 50.4345C280.768 54.6374 279.198 58.0673 276.057 60.7243C272.966 63.3813 268.908 64.7098 263.884 64.7098Z", fill: "#3A3A3A" }),
|
|
1088
|
+
/* @__PURE__ */ jsx5("path", { d: "M198.861 63.2605V19.7824H210.166V24.565C211.712 22.536 213.62 20.9901 215.89 19.9273C218.161 18.8645 220.6 18.3331 223.209 18.3331C226.301 18.3331 229.175 19.0819 231.832 20.5795C234.538 22.0288 236.711 24.1785 238.354 27.0288C240.045 29.8307 240.89 33.2365 240.89 37.2461V63.2605H228.282V38.9128C228.282 36.4973 227.557 34.3476 226.108 32.4635C224.658 30.5795 222.581 29.6374 219.876 29.6374C217.702 29.6374 215.745 30.3862 214.006 31.8838C212.315 33.3331 211.47 35.6278 211.47 38.7679V63.2605H198.861Z", fill: "#3A3A3A" }),
|
|
1089
|
+
/* @__PURE__ */ jsx5("path", { d: "M167.99 64.7098C163.69 64.7098 159.753 63.6712 156.178 61.5939C152.603 59.5166 149.753 56.7147 147.628 53.1881C145.55 49.6616 144.512 45.7727 144.512 41.5215C144.512 37.222 145.55 33.3331 147.628 29.8548C149.753 26.3283 152.603 23.5264 156.178 21.4491C159.753 19.3718 163.69 18.3331 167.99 18.3331C172.338 18.3331 176.275 19.3718 179.801 21.4491C183.376 23.5264 186.202 26.3283 188.28 29.8548C190.405 33.3331 191.468 37.222 191.468 41.5215C191.468 45.7727 190.405 49.6616 188.28 53.1881C186.202 56.7147 183.376 59.5166 179.801 61.5939C176.275 63.6712 172.338 64.7098 167.99 64.7098ZM167.99 53.4055C170.164 53.4055 172.12 52.8741 173.859 51.8113C175.647 50.7485 177.048 49.3234 178.062 47.536C179.125 45.7002 179.657 43.6954 179.657 41.5215C179.657 39.2993 179.125 37.2944 178.062 35.507C177.048 33.7196 175.647 32.2944 173.859 31.2316C172.12 30.1688 170.164 29.6374 167.99 29.6374C165.816 29.6374 163.835 30.1688 162.048 31.2316C160.309 32.2944 158.908 33.7196 157.845 35.507C156.831 37.2944 156.323 39.2993 156.323 41.5215C156.323 43.6954 156.831 45.7002 157.845 47.536C158.908 49.3234 160.309 50.7485 162.048 51.8113C163.835 52.8741 165.816 53.4055 167.99 53.4055Z", fill: "#3A3A3A" }),
|
|
1090
|
+
/* @__PURE__ */ jsx5("path", { d: "M124.478 64.7098C120.179 64.7098 116.242 63.6712 112.667 61.5939C109.092 59.5166 106.242 56.7147 104.116 53.1881C102.039 49.6616 101 45.7727 101 41.5215C101 37.222 102.039 33.3331 104.116 29.8548C106.242 26.3283 109.092 23.5264 112.667 21.4491C116.242 19.3718 120.179 18.3331 124.478 18.3331C127.473 18.3331 130.299 18.8404 132.956 19.8549C135.662 20.821 138.053 22.2703 140.13 24.2027L136.869 37.0287C135.662 35.0481 134.043 33.3331 132.014 31.8838C130.034 30.3862 127.691 29.6374 124.985 29.6374C122.715 29.6374 120.686 30.1688 118.899 31.2316C117.111 32.2944 115.71 33.7196 114.696 35.507C113.681 37.2944 113.174 39.2993 113.174 41.5215C113.174 43.6954 113.681 45.7002 114.696 47.536C115.71 49.3234 117.111 50.7485 118.899 51.8113C120.686 52.8741 122.715 53.4055 124.985 53.4055C127.691 53.4055 130.034 52.6809 132.014 51.2316C134.043 49.734 135.662 47.9949 136.869 46.0142L140.13 58.8403C138.053 60.7726 135.662 62.2461 132.956 63.2605C130.299 64.2267 127.473 64.7098 124.478 64.7098Z", fill: "#3A3A3A" })
|
|
1091
|
+
] });
|
|
1092
|
+
}
|
|
896
1093
|
|
|
897
1094
|
// src/components/ConsentGate.tsx
|
|
898
|
-
import { Fragment as Fragment2, jsx as
|
|
1095
|
+
import { Fragment as Fragment2, jsx as jsx6 } from "react/jsx-runtime";
|
|
899
1096
|
function ConsentGate({
|
|
900
1097
|
category,
|
|
901
1098
|
children,
|
|
@@ -904,12 +1101,12 @@ function ConsentGate({
|
|
|
904
1101
|
}) {
|
|
905
1102
|
const { hasConsent, isLoading } = useConsentGate(category);
|
|
906
1103
|
if (isLoading) {
|
|
907
|
-
return /* @__PURE__ */
|
|
1104
|
+
return /* @__PURE__ */ jsx6(Fragment2, { children: loading });
|
|
908
1105
|
}
|
|
909
1106
|
if (hasConsent) {
|
|
910
|
-
return /* @__PURE__ */
|
|
1107
|
+
return /* @__PURE__ */ jsx6(Fragment2, { children });
|
|
911
1108
|
}
|
|
912
|
-
return /* @__PURE__ */
|
|
1109
|
+
return /* @__PURE__ */ jsx6(Fragment2, { children: fallback });
|
|
913
1110
|
}
|
|
914
1111
|
function withConsentGate(Component, category, FallbackComponent) {
|
|
915
1112
|
return function ConsentGatedComponent(props) {
|
|
@@ -918,19 +1115,282 @@ function withConsentGate(Component, category, FallbackComponent) {
|
|
|
918
1115
|
return null;
|
|
919
1116
|
}
|
|
920
1117
|
if (hasConsent) {
|
|
921
|
-
return /* @__PURE__ */
|
|
1118
|
+
return /* @__PURE__ */ jsx6(Component, { ...props });
|
|
922
1119
|
}
|
|
923
1120
|
if (FallbackComponent) {
|
|
924
|
-
return /* @__PURE__ */
|
|
1121
|
+
return /* @__PURE__ */ jsx6(FallbackComponent, { ...props });
|
|
925
1122
|
}
|
|
926
1123
|
return null;
|
|
927
1124
|
};
|
|
928
1125
|
}
|
|
1126
|
+
|
|
1127
|
+
// src/components/MarketingConsentForm.tsx
|
|
1128
|
+
import { forwardRef, useImperativeHandle } from "react";
|
|
1129
|
+
|
|
1130
|
+
// src/hooks/useFormConsent.ts
|
|
1131
|
+
import { useState as useState4, useEffect as useEffect3, useCallback as useCallback2, useRef } from "react";
|
|
1132
|
+
var configCache = /* @__PURE__ */ new Map();
|
|
1133
|
+
var CONFIG_TTL = 6e4;
|
|
1134
|
+
function getCachedConfig(propertyKey) {
|
|
1135
|
+
const entry = configCache.get(propertyKey);
|
|
1136
|
+
if (entry && Date.now() - entry.timestamp < CONFIG_TTL) {
|
|
1137
|
+
return entry.config;
|
|
1138
|
+
}
|
|
1139
|
+
return null;
|
|
1140
|
+
}
|
|
1141
|
+
function setCachedConfig(propertyKey, config) {
|
|
1142
|
+
configCache.set(propertyKey, { config, timestamp: Date.now() });
|
|
1143
|
+
}
|
|
1144
|
+
function useFormConsent(options) {
|
|
1145
|
+
const { propertyKey, apiUrl, subjectId, subjectType = "visitor", debug = false } = options;
|
|
1146
|
+
const [config, setConfig] = useState4(() => getCachedConfig(propertyKey));
|
|
1147
|
+
const [consents, setConsents] = useState4({});
|
|
1148
|
+
const [isLoading, setIsLoading] = useState4(!getCachedConfig(propertyKey));
|
|
1149
|
+
const [isSubmitting, setIsSubmitting] = useState4(false);
|
|
1150
|
+
const [error, setError] = useState4(null);
|
|
1151
|
+
const [lastSubmission, setLastSubmission] = useState4(null);
|
|
1152
|
+
const apiClientRef = useRef(null);
|
|
1153
|
+
useEffect3(() => {
|
|
1154
|
+
if (config) return;
|
|
1155
|
+
let cancelled = false;
|
|
1156
|
+
const client = new ConsentIQApiClient(propertyKey, apiUrl, debug);
|
|
1157
|
+
apiClientRef.current = client;
|
|
1158
|
+
client.getConfig().then((cfg) => {
|
|
1159
|
+
if (cancelled) return;
|
|
1160
|
+
setCachedConfig(propertyKey, cfg);
|
|
1161
|
+
setConfig(cfg);
|
|
1162
|
+
setIsLoading(false);
|
|
1163
|
+
}).catch((err) => {
|
|
1164
|
+
if (cancelled) return;
|
|
1165
|
+
setError(err.message || "Failed to load config");
|
|
1166
|
+
setIsLoading(false);
|
|
1167
|
+
});
|
|
1168
|
+
return () => {
|
|
1169
|
+
cancelled = true;
|
|
1170
|
+
};
|
|
1171
|
+
}, [propertyKey, apiUrl, debug]);
|
|
1172
|
+
const privacyNoticeUrl = (() => {
|
|
1173
|
+
if (!config) return null;
|
|
1174
|
+
const currentPath = typeof window !== "undefined" ? window.location.pathname : "/";
|
|
1175
|
+
const sources = config.formConsentSources || [];
|
|
1176
|
+
for (const source of sources) {
|
|
1177
|
+
if (!source.selector) continue;
|
|
1178
|
+
const selectorPath = source.selector.startsWith("/") ? source.selector.split("#")[0] : null;
|
|
1179
|
+
if (selectorPath && currentPath.startsWith(selectorPath)) {
|
|
1180
|
+
const noticeParam = source.privacyNotice.id;
|
|
1181
|
+
return `${config.privacyNoticeUrl}?notice=${noticeParam}`;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
return config.privacyNoticeUrl;
|
|
1185
|
+
})();
|
|
1186
|
+
const channels = config?.marketingChannels || [];
|
|
1187
|
+
const setConsent = useCallback2((channel, value) => {
|
|
1188
|
+
setConsents((prev) => ({ ...prev, [channel]: value }));
|
|
1189
|
+
}, []);
|
|
1190
|
+
const setAllConsents = useCallback2((value) => {
|
|
1191
|
+
if (!config) return;
|
|
1192
|
+
const newConsents = {};
|
|
1193
|
+
for (const ch of config.marketingChannels) {
|
|
1194
|
+
newConsents[ch.code] = value;
|
|
1195
|
+
}
|
|
1196
|
+
setConsents(newConsents);
|
|
1197
|
+
}, [config]);
|
|
1198
|
+
const submit = useCallback2(async () => {
|
|
1199
|
+
if (!subjectId) {
|
|
1200
|
+
setError("subjectId is required");
|
|
1201
|
+
return null;
|
|
1202
|
+
}
|
|
1203
|
+
if (!apiClientRef.current) {
|
|
1204
|
+
setError("API client not initialized");
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
1207
|
+
setIsSubmitting(true);
|
|
1208
|
+
setError(null);
|
|
1209
|
+
try {
|
|
1210
|
+
const result = await apiClientRef.current.submitConsent({
|
|
1211
|
+
subjectId,
|
|
1212
|
+
subjectType,
|
|
1213
|
+
marketingConsents: consents,
|
|
1214
|
+
consentMethod: "form"
|
|
1215
|
+
});
|
|
1216
|
+
const submission = { consentId: result.consentId, proofHash: result.proofHash };
|
|
1217
|
+
setLastSubmission(submission);
|
|
1218
|
+
setIsSubmitting(false);
|
|
1219
|
+
return submission;
|
|
1220
|
+
} catch (err) {
|
|
1221
|
+
const message = err instanceof Error ? err.message : "Failed to submit consent";
|
|
1222
|
+
setError(message);
|
|
1223
|
+
setIsSubmitting(false);
|
|
1224
|
+
return null;
|
|
1225
|
+
}
|
|
1226
|
+
}, [subjectId, subjectType, consents]);
|
|
1227
|
+
return {
|
|
1228
|
+
channels,
|
|
1229
|
+
consents,
|
|
1230
|
+
privacyNoticeUrl,
|
|
1231
|
+
lastSubmission,
|
|
1232
|
+
setConsent,
|
|
1233
|
+
setAllConsents,
|
|
1234
|
+
submit,
|
|
1235
|
+
isLoading,
|
|
1236
|
+
isSubmitting,
|
|
1237
|
+
error
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// src/components/MarketingConsentForm.tsx
|
|
1242
|
+
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1243
|
+
var MarketingConsentForm = forwardRef(
|
|
1244
|
+
function MarketingConsentForm2({
|
|
1245
|
+
propertyKey,
|
|
1246
|
+
apiUrl,
|
|
1247
|
+
subjectId,
|
|
1248
|
+
subjectType,
|
|
1249
|
+
mode = "simple",
|
|
1250
|
+
simpleLabel,
|
|
1251
|
+
channels: channelFilter,
|
|
1252
|
+
onConsentSubmitted,
|
|
1253
|
+
onConsentChange,
|
|
1254
|
+
autoSubmit = false,
|
|
1255
|
+
className,
|
|
1256
|
+
style,
|
|
1257
|
+
showDescriptions = false,
|
|
1258
|
+
showPrivacyLink = true,
|
|
1259
|
+
privacyLinkText = "Privacy Policy",
|
|
1260
|
+
privacyUrl: privacyUrlOverride
|
|
1261
|
+
}, ref) {
|
|
1262
|
+
const resolvedPropertyKey = propertyKey || "";
|
|
1263
|
+
const {
|
|
1264
|
+
channels,
|
|
1265
|
+
consents,
|
|
1266
|
+
privacyNoticeUrl,
|
|
1267
|
+
setConsent,
|
|
1268
|
+
setAllConsents,
|
|
1269
|
+
submit,
|
|
1270
|
+
isLoading,
|
|
1271
|
+
isSubmitting
|
|
1272
|
+
} = useFormConsent({
|
|
1273
|
+
propertyKey: resolvedPropertyKey,
|
|
1274
|
+
apiUrl,
|
|
1275
|
+
subjectId,
|
|
1276
|
+
subjectType
|
|
1277
|
+
});
|
|
1278
|
+
const privacyUrl = privacyUrlOverride || privacyNoticeUrl;
|
|
1279
|
+
const visibleChannels = channelFilter ? channels.filter((ch) => channelFilter.includes(ch.code)) : channels;
|
|
1280
|
+
useImperativeHandle(ref, () => ({
|
|
1281
|
+
submit: async () => {
|
|
1282
|
+
const result = await submit();
|
|
1283
|
+
if (result && onConsentSubmitted) {
|
|
1284
|
+
onConsentSubmitted({ ...result, consents });
|
|
1285
|
+
}
|
|
1286
|
+
return result;
|
|
1287
|
+
},
|
|
1288
|
+
getConsents: () => consents,
|
|
1289
|
+
reset: () => setAllConsents(false)
|
|
1290
|
+
}), [submit, consents, onConsentSubmitted, setAllConsents]);
|
|
1291
|
+
const handleChange = (channel, value) => {
|
|
1292
|
+
setConsent(channel, value);
|
|
1293
|
+
const updated = { ...consents, [channel]: value };
|
|
1294
|
+
onConsentChange?.(updated);
|
|
1295
|
+
if (autoSubmit) {
|
|
1296
|
+
submit().then((result) => {
|
|
1297
|
+
if (result && onConsentSubmitted) {
|
|
1298
|
+
onConsentSubmitted({ ...result, consents: updated });
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
const handleSimpleChange = (checked) => {
|
|
1304
|
+
setAllConsents(checked);
|
|
1305
|
+
const updated = {};
|
|
1306
|
+
for (const ch of visibleChannels) {
|
|
1307
|
+
updated[ch.code] = checked;
|
|
1308
|
+
}
|
|
1309
|
+
onConsentChange?.(updated);
|
|
1310
|
+
if (autoSubmit) {
|
|
1311
|
+
submit().then((result) => {
|
|
1312
|
+
if (result && onConsentSubmitted) {
|
|
1313
|
+
onConsentSubmitted({ ...result, consents: updated });
|
|
1314
|
+
}
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
if (isLoading) {
|
|
1319
|
+
return null;
|
|
1320
|
+
}
|
|
1321
|
+
const allChecked = visibleChannels.length > 0 && visibleChannels.every((ch) => consents[ch.code]);
|
|
1322
|
+
return /* @__PURE__ */ jsx7("div", { className, style: { fontSize: "14px", ...style }, children: mode === "simple" ? /* @__PURE__ */ jsxs4("label", { style: { display: "flex", alignItems: "flex-start", gap: "8px", cursor: "pointer" }, children: [
|
|
1323
|
+
/* @__PURE__ */ jsx7(
|
|
1324
|
+
"input",
|
|
1325
|
+
{
|
|
1326
|
+
type: "checkbox",
|
|
1327
|
+
checked: allChecked,
|
|
1328
|
+
onChange: (e) => handleSimpleChange(e.target.checked),
|
|
1329
|
+
disabled: isSubmitting,
|
|
1330
|
+
style: { marginTop: "3px" }
|
|
1331
|
+
}
|
|
1332
|
+
),
|
|
1333
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
1334
|
+
simpleLabel || "I agree to receive marketing communications",
|
|
1335
|
+
showPrivacyLink && privacyUrl && /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
1336
|
+
". ",
|
|
1337
|
+
/* @__PURE__ */ jsx7(
|
|
1338
|
+
"a",
|
|
1339
|
+
{
|
|
1340
|
+
href: privacyUrl,
|
|
1341
|
+
target: "_blank",
|
|
1342
|
+
rel: "noopener noreferrer",
|
|
1343
|
+
style: { textDecoration: "underline" },
|
|
1344
|
+
children: privacyLinkText
|
|
1345
|
+
}
|
|
1346
|
+
)
|
|
1347
|
+
] })
|
|
1348
|
+
] })
|
|
1349
|
+
] }) : /* @__PURE__ */ jsxs4("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
|
|
1350
|
+
visibleChannels.map((ch) => /* @__PURE__ */ jsxs4(
|
|
1351
|
+
"label",
|
|
1352
|
+
{
|
|
1353
|
+
style: { display: "flex", alignItems: "flex-start", gap: "8px", cursor: "pointer" },
|
|
1354
|
+
children: [
|
|
1355
|
+
/* @__PURE__ */ jsx7(
|
|
1356
|
+
"input",
|
|
1357
|
+
{
|
|
1358
|
+
type: "checkbox",
|
|
1359
|
+
checked: consents[ch.code] === true,
|
|
1360
|
+
onChange: (e) => handleChange(ch.code, e.target.checked),
|
|
1361
|
+
disabled: isSubmitting,
|
|
1362
|
+
style: { marginTop: "3px" }
|
|
1363
|
+
}
|
|
1364
|
+
),
|
|
1365
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
1366
|
+
/* @__PURE__ */ jsx7("strong", { children: ch.name }),
|
|
1367
|
+
showDescriptions && ch.description && /* @__PURE__ */ jsx7("span", { style: { display: "block", color: "#666", fontSize: "12px" }, children: ch.description })
|
|
1368
|
+
] })
|
|
1369
|
+
]
|
|
1370
|
+
},
|
|
1371
|
+
ch.code
|
|
1372
|
+
)),
|
|
1373
|
+
showPrivacyLink && privacyUrl && /* @__PURE__ */ jsx7(
|
|
1374
|
+
"a",
|
|
1375
|
+
{
|
|
1376
|
+
href: privacyUrl,
|
|
1377
|
+
target: "_blank",
|
|
1378
|
+
rel: "noopener noreferrer",
|
|
1379
|
+
style: { fontSize: "12px", textDecoration: "underline", color: "#666" },
|
|
1380
|
+
children: privacyLinkText
|
|
1381
|
+
}
|
|
1382
|
+
)
|
|
1383
|
+
] }) });
|
|
1384
|
+
}
|
|
1385
|
+
);
|
|
929
1386
|
export {
|
|
930
1387
|
ConsentGate,
|
|
931
1388
|
ConsentIQApiClient,
|
|
932
1389
|
ConsentIQProvider,
|
|
1390
|
+
ConsentTrigger,
|
|
933
1391
|
CookieBanner,
|
|
1392
|
+
LanguageSelector,
|
|
1393
|
+
MarketingConsentForm,
|
|
934
1394
|
PreferenceCenter,
|
|
935
1395
|
detectCountry,
|
|
936
1396
|
detectLanguage,
|
|
@@ -939,5 +1399,6 @@ export {
|
|
|
939
1399
|
useConsent,
|
|
940
1400
|
useConsentGate,
|
|
941
1401
|
useConsentIQ,
|
|
1402
|
+
useFormConsent,
|
|
942
1403
|
withConsentGate
|
|
943
1404
|
};
|