@el7ven/cookie-kit 0.2.16 → 0.2.18

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 CHANGED
@@ -1,8 +1,8 @@
1
- # @el7ven/cookie-consent
1
+ # @el7ven/cookie-kit
2
2
 
3
- > Unified cookie consent management for GDPR compliance with React and Vue support
3
+ > Unified cookie consent management kit for GDPR compliance with React, Vue, and Vanilla JS support
4
4
 
5
- [![npm version](https://badge.fury.io/js/@el7ven%2Fcookie-consent.svg)](https://badge.fury.io/js/@el7ven%2Fcookie-consent)
5
+ [![npm version](https://badge.fury.io/js/@el7ven%2Fcookie-kit.svg)](https://badge.fury.io/js/@el7ven%2Fcookie-kit)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
8
  A comprehensive, production-ready cookie consent solution that helps websites comply with GDPR and other privacy regulations. Built with modern JavaScript and supports React, Vue, and vanilla JS applications.
@@ -21,7 +21,7 @@ A comprehensive, production-ready cookie consent solution that helps websites co
21
21
  ## 📦 Installation
22
22
 
23
23
  ```bash
24
- npm install @el7ven/cookie-consent@beta
24
+ npm install @el7ven/cookie-kit
25
25
  ```
26
26
 
27
27
  ## 🚀 Quick Start
@@ -29,8 +29,8 @@ npm install @el7ven/cookie-consent@beta
29
29
  ### Vanilla JavaScript
30
30
 
31
31
  ```javascript
32
- import { createCookieConsent } from '@el7ven/cookie-consent'
33
- import '@el7ven/cookie-consent/styles'
32
+ import { createCookieConsent } from '@el7ven/cookie-kit'
33
+ import '@el7ven/cookie-kit/styles'
34
34
 
35
35
  const cookieConsent = await createCookieConsent({
36
36
  categories: {
@@ -54,8 +54,8 @@ console.log('Analytics enabled:', consent.categories.analytics.enabled)
54
54
  ### React
55
55
 
56
56
  ```jsx
57
- import { CookieKitProvider, useCookieKit } from '@el7ven/cookie-consent/react'
58
- import '@el7ven/cookie-consent/styles'
57
+ import { CookieKitProvider, useCookieKit } from '@el7ven/cookie-kit/react'
58
+ import '@el7ven/cookie-kit/styles'
59
59
 
60
60
  function App() {
61
61
  return (
@@ -95,8 +95,8 @@ function MyComponent() {
95
95
  </template>
96
96
 
97
97
  <script setup>
98
- import { useCookieKit } from '@el7ven/cookie-consent/vue'
99
- import '@el7ven/cookie-consent/styles'
98
+ import { useCookieKit } from '@el7ven/cookie-kit/vue'
99
+ import '@el7ven/cookie-kit/styles'
100
100
 
101
101
  const { consent, acceptAll, rejectAll } = useCookieKit({
102
102
  categories: {
@@ -170,7 +170,7 @@ const config = {
170
170
  ### Custom Components
171
171
 
172
172
  ```javascript
173
- import { createCookieKit } from '@el7ven/cookie-consent'
173
+ import { createCookieKit } from '@el7ven/cookie-kit'
174
174
 
175
175
  const cookieKit = createCookieKit(config)
176
176
 
@@ -188,7 +188,7 @@ const consent = cookieKit.getConsent()
188
188
 
189
189
  ## 📄 License
190
190
 
191
- MIT © [Igor Semionov](https://github.com/El7ven)
191
+ MIT © [El7ven](https://github.com/El7ven)
192
192
 
193
193
  ## 🤝 Contributing
194
194
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@el7ven/cookie-kit",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "module": "./src/index.js",
@@ -4,9 +4,10 @@ export function useCookieConsent(config = {}) {
4
4
  const isVisible = ref(false)
5
5
  const isSettingsMode = ref(false)
6
6
  const currentTab = ref('categories')
7
- const consentVersion = ref('1.0.0')
7
+ const consentVersion = ref(config.consentVersion || '1.0.0')
8
8
 
9
- const categories = ref({
9
+ // Use config categories or default
10
+ const categories = ref(config.categories || {
10
11
  necessary: {
11
12
  required: true,
12
13
  enabled: true,
@@ -35,17 +36,19 @@ export function useCookieConsent(config = {}) {
35
36
  canCustomize: true
36
37
  })
37
38
 
38
- const isV2 = ref(true)
39
+ const isV2 = ref(consentVersion.value === 'v2')
39
40
 
40
41
  const hasConsent = computed(() => {
41
42
  return localStorage.getItem('cookie-consent') !== null
42
43
  })
43
44
 
44
- const consentData = computed(() => {
45
+ const consent = computed(() => {
45
46
  const stored = localStorage.getItem('cookie-consent')
46
47
  return stored ? JSON.parse(stored) : null
47
48
  })
48
49
 
50
+ const consentData = computed(() => consent.value)
51
+
49
52
  const showConsent = () => {
50
53
  isVisible.value = true
51
54
  }
@@ -54,6 +57,10 @@ export function useCookieConsent(config = {}) {
54
57
  isVisible.value = false
55
58
  }
56
59
 
60
+ const showSettings = () => {
61
+ isSettingsMode.value = true
62
+ }
63
+
57
64
  const openSettings = () => {
58
65
  isSettingsMode.value = true
59
66
  }
@@ -62,10 +69,19 @@ export function useCookieConsent(config = {}) {
62
69
  isSettingsMode.value = false
63
70
  }
64
71
 
72
+ const close = () => {
73
+ isVisible.value = false
74
+ isSettingsMode.value = false
75
+ }
76
+
65
77
  const selectTab = (tab) => {
66
78
  currentTab.value = tab
67
79
  }
68
80
 
81
+ const setTab = (tab) => {
82
+ currentTab.value = tab
83
+ }
84
+
69
85
  const toggleCategory = (categoryName, enabled) => {
70
86
  if (categories.value[categoryName] && !categories.value[categoryName].required) {
71
87
  categories.value[categoryName].enabled = enabled
@@ -73,7 +89,7 @@ export function useCookieConsent(config = {}) {
73
89
  }
74
90
 
75
91
  const acceptSelection = () => {
76
- const consent = {
92
+ const consentRecord = {
77
93
  version: consentVersion.value,
78
94
  timestamp: new Date().toISOString(),
79
95
  categories: Object.keys(categories.value).reduce((acc, key) => {
@@ -82,7 +98,7 @@ export function useCookieConsent(config = {}) {
82
98
  }, {})
83
99
  }
84
100
 
85
- localStorage.setItem('cookie-consent', JSON.stringify(consent))
101
+ localStorage.setItem('cookie-consent', JSON.stringify(consentRecord))
86
102
  capabilities.value.hasConsented = true
87
103
  hideConsent()
88
104
  closeSettings()
@@ -104,6 +120,10 @@ export function useCookieConsent(config = {}) {
104
120
  acceptSelection()
105
121
  }
106
122
 
123
+ const acceptSelected = () => {
124
+ acceptSelection()
125
+ }
126
+
107
127
  const resetConsent = () => {
108
128
  localStorage.removeItem('cookie-consent')
109
129
  capabilities.value.hasConsented = false
@@ -114,6 +134,33 @@ export function useCookieConsent(config = {}) {
114
134
  })
115
135
  }
116
136
 
137
+ // Focus trap functions
138
+ let activeElement = null
139
+
140
+ const activateFocusTrap = (element) => {
141
+ if (!element) return
142
+
143
+ activeElement = document.activeElement
144
+ const focusableElements = element.querySelectorAll(
145
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
146
+ )
147
+
148
+ if (focusableElements.length > 0) {
149
+ focusableElements[0].focus()
150
+ }
151
+ }
152
+
153
+ const deactivateFocusTrap = () => {
154
+ if (activeElement && activeElement.focus) {
155
+ activeElement.focus()
156
+ }
157
+ activeElement = null
158
+ }
159
+
160
+ const cleanup = () => {
161
+ deactivateFocusTrap()
162
+ }
163
+
117
164
  const handleClose = () => {
118
165
  hideConsent()
119
166
  closeSettings()
@@ -151,6 +198,10 @@ export function useCookieConsent(config = {}) {
151
198
  }
152
199
  })
153
200
 
201
+ onUnmounted(() => {
202
+ cleanup()
203
+ })
204
+
154
205
  return {
155
206
  isVisible,
156
207
  isSettingsMode,
@@ -160,17 +211,25 @@ export function useCookieConsent(config = {}) {
160
211
  isV2,
161
212
  consentVersion,
162
213
  hasConsent,
214
+ consent,
163
215
  consentData,
164
216
  showConsent,
165
217
  hideConsent,
218
+ showSettings,
166
219
  openSettings,
167
220
  closeSettings,
221
+ close,
168
222
  selectTab,
223
+ setTab,
169
224
  toggleCategory,
170
225
  acceptSelection,
171
226
  acceptAll,
172
227
  rejectAll,
228
+ acceptSelected,
173
229
  resetConsent,
230
+ activateFocusTrap,
231
+ deactivateFocusTrap,
232
+ cleanup,
174
233
  handleClose,
175
234
  handleOpenSettings,
176
235
  handleSelectTab,