@bulut5/ck 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ interface BrandConfig {
|
|
|
32
32
|
};
|
|
33
33
|
/** Bump to force a re-prompt when the policy / categories change. Default 1. */
|
|
34
34
|
version?: number;
|
|
35
|
+
/** Log the Consent Mode / UET signal updates to the console (also enabled by
|
|
36
|
+
* adding `?ckdebug` to the URL). Off by default. */
|
|
37
|
+
debug?: boolean;
|
|
35
38
|
}
|
|
36
39
|
interface StoredConsent {
|
|
37
40
|
decision: ConsentDecision;
|
|
@@ -79,7 +82,7 @@ declare function saveConsent(decision: ConsentDecision, version: number): Stored
|
|
|
79
82
|
declare function applyConsent(decision: ConsentDecision, signals?: {
|
|
80
83
|
google?: boolean;
|
|
81
84
|
bing?: boolean;
|
|
82
|
-
}): void;
|
|
85
|
+
}, debug?: boolean): void;
|
|
83
86
|
/** Load any stored decision and re-apply its signals. Returns the decision or null. */
|
|
84
87
|
declare function applyStoredConsent(config: BrandConfig): ConsentDecision | null;
|
|
85
88
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createContext,useState,useEffect,useCallback,useContext}from'react';import {jsx,jsxs}from'react/jsx-runtime';var
|
|
1
|
+
import {createContext,useState,useEffect,useCallback,useContext}from'react';import {jsx,jsxs}from'react/jsx-runtime';var R="ck.consent",m={marketing:false,analytics:false,personalization:false},A={marketing:true,analytics:true,personalization:true};function w(){return typeof window<"u"}function h(e){if(!w())return null;try{let o=window.localStorage.getItem(R);if(!o)return null;let t=JSON.parse(o);return !t||t.version!==e||!t.decision?null:t}catch{return null}}function L(e,o){let t={decision:e,version:o,ts:Date.now()};if(w())try{window.localStorage.setItem(R,JSON.stringify(t));}catch{}return t}function p(e){return e?"granted":"denied"}function N(e){return e?.debug?true:w()&&new URLSearchParams(window.location.search).has("ckdebug")}function x(e,o={},t=false){if(!w())return;let s=window,{google:l=true,bing:g=true}=o;if(l&&typeof s.gtag=="function"){let i={ad_storage:p(e.marketing),ad_user_data:p(e.marketing),ad_personalization:p(e.marketing),analytics_storage:p(e.analytics),personalization_storage:p(e.personalization)};s.gtag("consent","update",i),t&&console.log("[ck] Google Consent Mode update \u2192",i);}else l&&t&&console.warn("[ck] window.gtag not found \u2014 Google consent not updated");if(g){let i={ad_storage:p(e.marketing)};s.uetq=s.uetq||[],s.uetq.push("consent","update",i),t&&console.log("[ck] Microsoft UET consent update \u2192",i);}}function G(e){let o=h(e.version??1);return o?(x(o.decision,e.signals,N(e)),o.decision):null}var E=createContext(null);function Y({config:e,children:o}){let t=e.version??1,[s,l]=useState(null),[g,i]=useState(false),[D,C]=useState(false);useEffect(()=>{let a=h(t);a&&(l(a.decision),x(a.decision,e.signals,N(e))),i(true);},[t]);let d=useCallback(a=>{L(a,t),x(a,e.signals,N(e)),l(a),C(false);},[t,e.signals]),y=useCallback(()=>d({...A}),[d]),b=useCallback(()=>d({...m}),[d]),v=useCallback(a=>d(a),[d]),k=useCallback(()=>C(true),[]),r=useCallback(()=>C(false),[]),S={decision:s,decided:s!==null,mounted:g,open:D,config:e,acceptAll:y,rejectAll:b,saveSelection:v,reopen:k,close:r};return jsx(E.Provider,{value:S,children:o})}function z(){let e=useContext(E);if(!e)throw new Error("useConsent must be used within <ConsentProvider>");return e}var I=["marketing","analytics","personalization"];function M(){let{mounted:e,decided:o,open:t,decision:s,config:l,acceptAll:g,rejectAll:i,saveSelection:D,reopen:C,close:d}=z(),[y,b]=useState(false),[v,k]=useState({...m});if(!e)return null;let{copy:r}=l;if(o&&!t)return jsx("button",{type:"button",onClick:C,"aria-label":r.badgeLabel,className:"fixed bottom-4 right-4 z-[60] flex h-11 w-11 items-center justify-center rounded-full border border-border bg-background text-foreground shadow-lg transition hover:opacity-90",children:jsx("span",{"aria-hidden":true,className:"text-lg",children:"\u{1F36A}"})});let S=()=>{k(s?{...s}:{...m}),b(true);},a=c=>k(P=>({...P,[c]:!P[c]})),B=()=>{b(false),d();};return jsxs("div",{role:"dialog","aria-label":r.title,className:"fixed bottom-4 right-4 z-[60] w-[calc(100vw-2rem)] max-w-sm rounded-xl border border-border bg-background p-5 text-foreground shadow-2xl",children:[jsxs("div",{className:"mb-2 flex items-center gap-2 text-base font-semibold",children:[jsx("span",{"aria-hidden":true,className:"text-lg",children:"\u{1F36A}"}),r.title]}),jsx("p",{className:"mb-3 text-sm leading-relaxed text-muted-foreground",children:r.body}),jsx("a",{href:l.privacyPolicyUrl,target:"_blank",rel:"noopener noreferrer",className:"mb-4 inline-block text-sm font-medium underline underline-offset-2 hover:opacity-80",children:r.privacyLinkText}),y&&jsx("div",{className:"mb-4 space-y-3 border-t border-border pt-4",children:I.map(c=>jsxs("label",{className:"flex items-start gap-3 text-sm",children:[jsx("input",{type:"checkbox",checked:v[c],onChange:()=>a(c),className:"mt-0.5 h-4 w-4 shrink-0 accent-primary"}),jsxs("span",{children:[jsx("span",{className:"font-medium",children:r.categories[c].label}),jsx("span",{className:"block text-muted-foreground",children:r.categories[c].description})]})]},c))}),y?jsxs("div",{className:"flex gap-2",children:[jsx("button",{type:"button",onClick:()=>D(v),className:"flex-1 rounded-md bg-primary px-3 py-2 text-sm font-medium text-primary-foreground transition hover:opacity-90",children:r.save}),jsx("button",{type:"button",onClick:()=>b(false),className:"rounded-md border border-border bg-background px-3 py-2 text-sm font-medium text-foreground transition hover:bg-muted",children:r.back})]}):jsxs("div",{className:"flex flex-col gap-2",children:[jsxs("div",{className:"flex gap-2",children:[jsx("button",{type:"button",onClick:g,className:"flex-1 rounded-md bg-primary px-3 py-2 text-sm font-medium text-primary-foreground transition hover:opacity-90",children:r.acceptAll}),jsx("button",{type:"button",onClick:i,className:"flex-1 rounded-md border border-border bg-background px-3 py-2 text-sm font-medium text-foreground transition hover:bg-muted",children:r.rejectAll})]}),jsx("button",{type:"button",onClick:S,className:"rounded-md px-3 py-2 text-sm font-medium text-muted-foreground underline underline-offset-2 transition hover:text-foreground",children:r.select}),o&&jsx("button",{type:"button",onClick:B,"aria-label":"Close",className:"absolute right-3 top-3 text-muted-foreground transition hover:text-foreground",children:"\u2715"})]})]})}export{Y as ConsentProvider,M as CookieConsent,m as DENY_ALL,A as GRANT_ALL,x as applyConsent,G as applyStoredConsent,h as loadConsent,L as saveConsent,z as useConsent};
|