@dargmuesli/nuxt-cookie-control 9.0.0-beta.1 → 9.0.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.
@@ -1,446 +1,382 @@
1
1
  <template>
2
- <aside class="cookieControl">
3
- <transition :name="`cookieControl__Bar--${moduleOptions.barPosition}`">
4
- <div
5
- v-if="!isConsentGiven && !moduleOptions.isModalForced"
6
- :class="`cookieControl__Bar cookieControl__Bar--${moduleOptions.barPosition}`"
7
- >
8
- <div class="cookieControl__BarContainer">
9
- <div>
10
- <slot name="bar">
11
- <h2 v-text="localeStrings?.bannerTitle" />
12
- <p v-text="localeStrings?.bannerDescription" />
13
- </slot>
14
- </div>
15
- <div class="cookieControl__BarButtons">
16
- <button
17
- type="button"
18
- @click="accept()"
19
- v-text="localeStrings?.accept"
20
- />
21
- <button
22
- v-if="moduleOptions.isAcceptNecessaryButtonEnabled"
23
- type="button"
24
- @click="decline()"
25
- v-text="localeStrings?.decline"
26
- />
27
- <button
28
- type="button"
29
- @click="isModalActive = true"
30
- v-text="localeStrings?.manageCookies"
31
- />
2
+ <ClientOnlyPrerender>
3
+ <aside class="cookieControl">
4
+ <transition :name="`cookieControl__Bar--${moduleOptions.barPosition}`">
5
+ <div
6
+ v-if="!isConsentGiven && !moduleOptions.isModalForced"
7
+ :class="`cookieControl__Bar cookieControl__Bar--${moduleOptions.barPosition}`"
8
+ >
9
+ <div class="cookieControl__BarContainer">
10
+ <div>
11
+ <slot name="bar">
12
+ <h2 v-text="localeStrings?.bannerTitle" />
13
+ <p v-text="localeStrings?.bannerDescription" />
14
+ </slot>
15
+ </div>
16
+ <div class="cookieControl__BarButtons">
17
+ <button
18
+ type="button"
19
+ @click="acceptAll()"
20
+ v-text="localeStrings?.accept"
21
+ />
22
+ <button
23
+ v-if="moduleOptions.isAcceptNecessaryButtonEnabled"
24
+ type="button"
25
+ @click="acceptNecessary()"
26
+ v-text="localeStrings?.decline"
27
+ />
28
+ <button
29
+ type="button"
30
+ @click="isModalActive = true"
31
+ v-text="localeStrings?.manageCookies"
32
+ />
33
+ </div>
32
34
  </div>
33
35
  </div>
34
- </div>
35
- </transition>
36
- <button
37
- v-if="moduleOptions.isControlButtonEnabled && isConsentGiven"
38
- aria-label="Cookie control"
39
- class="cookieControl__ControlButton"
40
- data-testid="nuxt-cookie-control-control-button"
41
- type="button"
42
- @click="isModalActive = true"
43
- >
44
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
45
- <path
46
- fill="currentColor"
47
- d="M510.52 255.82c-69.97-.85-126.47-57.69-126.47-127.86-70.17 0-127-56.49-127.86-126.45-27.26-4.14-55.13.3-79.72 12.82l-69.13 35.22a132.221 132.221 0 00-57.79 57.81l-35.1 68.88a132.645 132.645 0 00-12.82 80.95l12.08 76.27a132.521 132.521 0 0037.16 72.96l54.77 54.76a132.036 132.036 0 0072.71 37.06l76.71 12.15c27.51 4.36 55.7-.11 80.53-12.76l69.13-35.21a132.273 132.273 0 0057.79-57.81l35.1-68.88c12.56-24.64 17.01-52.58 12.91-79.91zM176 368c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32zm32-160c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32zm160 128c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32z"
48
- />
49
- </svg>
50
- </button>
51
- <transition name="cookieControl__Modal">
52
- <div
53
- v-if="isModalActive"
54
- class="cookieControl__Modal"
55
- @click.self="onModalClick"
36
+ </transition>
37
+ <button
38
+ v-if="moduleOptions.isControlButtonEnabled && isConsentGiven"
39
+ aria-label="Cookie control"
40
+ class="cookieControl__ControlButton"
41
+ data-testid="nuxt-cookie-control-control-button"
42
+ type="button"
43
+ @click="isModalActive = true"
56
44
  >
57
- <p
58
- v-if="isSaved"
59
- class="cookieControl__ModalUnsaved"
60
- v-text="localeStrings?.settingsUnsaved"
61
- />
62
- <div class="cookieControl__ModalContent">
63
- <div class="cookieControl__ModalContentInner">
64
- <slot name="modal" />
65
- <button
66
- v-if="!moduleOptions.isModalForced"
67
- class="cookieControl__ModalClose"
68
- type="button"
69
- @click="isModalActive = false"
70
- v-text="localeStrings?.close"
45
+ <slot name="controlButton">
46
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
47
+ <path
48
+ fill="currentColor"
49
+ d="M510.52 255.82c-69.97-.85-126.47-57.69-126.47-127.86-70.17 0-127-56.49-127.86-126.45-27.26-4.14-55.13.3-79.72 12.82l-69.13 35.22a132.221 132.221 0 00-57.79 57.81l-35.1 68.88a132.645 132.645 0 00-12.82 80.95l12.08 76.27a132.521 132.521 0 0037.16 72.96l54.77 54.76a132.036 132.036 0 0072.71 37.06l76.71 12.15c27.51 4.36 55.7-.11 80.53-12.76l69.13-35.21a132.273 132.273 0 0057.79-57.81l35.1-68.88c12.56-24.64 17.01-52.58 12.91-79.91zM176 368c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32zm32-160c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32zm160 128c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32z"
71
50
  />
72
- <template v-for="cookieType in CookieType" :key="cookieType">
73
- <template v-if="moduleOptions.cookies[cookieType].length">
74
- <h2
75
- v-text="
76
- localeStrings &&
77
- (cookieType === CookieType.NECESSARY
78
- ? localeStrings.cookiesNecessary
79
- : localeStrings.cookiesOptional)
80
- "
81
- />
82
- <ul>
83
- <li
84
- v-for="cookie in moduleOptions.cookies[cookieType]"
85
- :key="cookie.id"
86
- >
87
- <slot name="cookie" v-bind="{ cookie }">
88
- <div class="cookieControl__ModalInputWrapper">
89
- <input
90
- v-if="
91
- cookieType === CookieType.NECESSARY &&
92
- cookie.name !== 'functional'
93
- "
94
- :id="resolveTranslatable(cookie.name, props.locale)"
95
- type="checkbox"
96
- disabled
97
- checked
98
- />
99
- <input
100
- v-else
101
- :id="resolveTranslatable(cookie.name, props.locale)"
102
- type="checkbox"
103
- :checked="
104
- isConsentGiven === undefined
105
- ? cookie.isPreselected
106
- : getCookieIds(localCookiesEnabled).includes(
107
- cookie.id,
108
- )
109
- "
110
- @change="toogleCookie(cookie)"
111
- />
112
- <button type="button" @click="toggleButton($event)">
113
- {{ getName(cookie.name) }}
114
- </button>
115
- <label
116
- class="cookieControl__ModalCookieName"
117
- :for="resolveTranslatable(cookie.name, props.locale)"
118
- tabindex="0"
119
- @keydown="toggleLabel($event)"
120
- >
121
- {{ getName(cookie.name) }}
122
- <span v-if="cookie.description">
123
- {{ getDescription(cookie.description) }}
124
- </span>
125
- <span
51
+ </svg>
52
+ </slot>
53
+ </button>
54
+ <transition name="cookieControl__Modal">
55
+ <div
56
+ v-if="isModalActive"
57
+ class="cookieControl__Modal"
58
+ @click.self="onModalClick"
59
+ >
60
+ <p
61
+ v-if="isSaved"
62
+ class="cookieControl__ModalUnsaved"
63
+ v-text="localeStrings?.settingsUnsaved"
64
+ />
65
+ <div class="cookieControl__ModalContent">
66
+ <div class="cookieControl__ModalContentInner">
67
+ <slot name="modal" />
68
+ <button
69
+ v-if="!moduleOptions.isModalForced"
70
+ class="cookieControl__ModalClose"
71
+ type="button"
72
+ @click="isModalActive = false"
73
+ v-text="localeStrings?.close"
74
+ />
75
+ <template v-for="cookieType in CookieType" :key="cookieType">
76
+ <template v-if="moduleOptions.cookies[cookieType].length">
77
+ <h2
78
+ v-text="
79
+ localeStrings && (cookieType === CookieType.NECESSARY ? localeStrings.cookiesNecessary : localeStrings.cookiesOptional)
80
+ "
81
+ />
82
+ <ul>
83
+ <li
84
+ v-for="cookie in moduleOptions.cookies[cookieType]"
85
+ :key="cookie.id"
86
+ >
87
+ <slot name="cookie" v-bind="{ cookie }">
88
+ <div class="cookieControl__ModalInputWrapper">
89
+ <input
126
90
  v-if="
127
- moduleOptions.isCookieIdVisible &&
128
- cookie.targetCookieIds
129
- "
130
- >
131
- <br />
132
- {{
133
- 'IDs: ' +
134
- cookie.targetCookieIds
135
- .map((id) => `"${id}"`)
136
- .join(', ')
137
- }}
138
- </span>
139
- <template
140
- v-if="Object.entries(cookie.links || {}).length"
91
+ cookieType === CookieType.NECESSARY && cookie.name !== 'functional'
92
+ "
93
+ :id="resolveTranslatable(cookie.name, locale)"
94
+ type="checkbox"
95
+ disabled
96
+ checked
97
+ />
98
+ <input
99
+ v-else
100
+ :id="resolveTranslatable(cookie.name, locale)"
101
+ type="checkbox"
102
+ :checked="
103
+ isConsentGiven === void 0 ? cookie.isPreselected : getCookieIds(localCookiesEnabled).includes(
104
+ cookie.id
105
+ )
106
+ "
107
+ @change="toogleCookie(cookie)"
108
+ />
109
+ <button type="button" @click="toggleButton($event)">
110
+ {{ getName(cookie.name) }}
111
+ </button>
112
+ <label
113
+ class="cookieControl__ModalCookieName"
114
+ :for="resolveTranslatable(cookie.name, locale)"
115
+ tabindex="0"
116
+ @keydown="toggleLabel($event)"
141
117
  >
118
+ {{ getName(cookie.name) }}
119
+ <span v-if="cookie.description">
120
+ {{ getDescription(cookie.description) }}
121
+ </span>
142
122
  <span
143
- v-for="entry in Object.entries(
144
- cookie.links || {},
145
- )"
146
- :key="entry[0]"
123
+ v-if="
124
+ moduleOptions.isCookieIdVisible && cookie.targetCookieIds
125
+ "
147
126
  >
148
127
  <br />
149
- <NuxtLink
150
- :to="entry[0]"
151
- @click="
152
- !entry[0].toLowerCase().startsWith('http')
153
- ? (isModalActive = false)
154
- : null
155
- "
156
- >
157
- {{ entry[1] || entry[0] }}
158
- </NuxtLink>
128
+ {{
129
+ "IDs: " + cookie.targetCookieIds.map((id) => `"${id}"`).join(", ")
130
+ }}
159
131
  </span>
160
- </template>
161
- </label>
162
- </div>
163
- </slot>
164
- </li>
165
- </ul>
132
+ <template
133
+ v-if="Object.entries(cookie.links || {}).length"
134
+ >
135
+ <span
136
+ v-for="entry in Object.entries(
137
+ cookie.links || {}
138
+ )"
139
+ :key="entry[0]"
140
+ >
141
+ <br />
142
+ <NuxtLink
143
+ :to="entry[0]"
144
+ @click="
145
+ !entry[0].toLowerCase().startsWith('http') ? isModalActive = false : null
146
+ "
147
+ >
148
+ {{ entry[1] || entry[0] }}
149
+ </NuxtLink>
150
+ </span>
151
+ </template>
152
+ </label>
153
+ </div>
154
+ </slot>
155
+ </li>
156
+ </ul>
157
+ </template>
166
158
  </template>
167
- </template>
168
- <div class="cookieControl__ModalButtons">
169
- <button
170
- type="button"
171
- @click="
172
- () => {
173
- acceptPartial()
174
- isModalActive = false
175
- }
176
- "
177
- v-text="localeStrings?.save"
178
- />
179
- <button
180
- type="button"
181
- @click="
182
- () => {
183
- accept()
184
- isModalActive = false
185
- }
186
- "
187
- v-text="localeStrings?.acceptAll"
188
- />
189
- <button
190
- v-if="!moduleOptions.isModalForced"
191
- type="button"
192
- @click="
193
- () => {
194
- declineAll()
195
- isModalActive = false
196
- }
197
- "
198
- v-text="localeStrings?.declineAll"
199
- />
159
+ <div class="cookieControl__ModalButtons">
160
+ <button
161
+ type="button"
162
+ @click="
163
+ () => {
164
+ acceptPartial();
165
+ isModalActive = false;
166
+ }
167
+ "
168
+ v-text="localeStrings?.save"
169
+ />
170
+ <button
171
+ type="button"
172
+ @click="
173
+ () => {
174
+ acceptNecessary();
175
+ isModalActive = false;
176
+ }
177
+ "
178
+ v-text="localeStrings?.acceptAll"
179
+ />
180
+ <button
181
+ v-if="!moduleOptions.isModalForced"
182
+ type="button"
183
+ @click="
184
+ () => {
185
+ acceptNone();
186
+ isModalActive = false;
187
+ }
188
+ "
189
+ v-text="localeStrings?.declineAll"
190
+ />
191
+ </div>
200
192
  </div>
201
193
  </div>
202
194
  </div>
203
- </div>
204
- </transition>
205
- </aside>
195
+ </transition>
196
+ </aside>
197
+ </ClientOnlyPrerender>
206
198
  </template>
207
199
 
208
- <script setup lang="ts">
209
- import { ref, computed, onBeforeMount, watch } from 'vue'
210
-
211
- import {
212
- type Cookie,
213
- CookieType,
214
- type Locale,
215
- type Translatable,
216
- } from '#cookie-control/types'
200
+ <script setup>
201
+ import { ref, computed, onBeforeMount, watch } from "vue";
202
+ import { COOKIE_ID_SEPARATOR } from "#cookie-control/constants";
217
203
  import {
218
204
  getAllCookieIdsString,
219
205
  getCookieIds,
220
206
  removeCookie,
221
- resolveTranslatable,
222
- } from '#cookie-control/methods'
223
- import { COOKIE_ID_SEPARATOR } from '#cookie-control/constants'
224
- import setCssVariables from '#cookie-control/set-vars'
225
- import { useCookieControl, useCookie, useNuxtApp } from '#imports'
226
-
227
- export interface Props {
228
- locale?: Locale
229
- }
230
- const props = withDefaults(defineProps<Props>(), {
231
- locale: 'en',
232
- })
233
-
207
+ resolveTranslatable
208
+ } from "#cookie-control/methods";
209
+ import setCssVariables from "#cookie-control/set-vars";
210
+ import { useCookieControl, useCookie, useNuxtApp } from "#imports";
211
+ const { locale = "en" } = defineProps({
212
+ locale: {
213
+ type: String,
214
+ required: false
215
+ }
216
+ });
234
217
  const {
235
218
  cookiesEnabled,
236
219
  cookiesEnabledIds,
237
220
  isConsentGiven,
238
221
  isModalActive,
239
- moduleOptions,
240
- } = useCookieControl()
241
- const nuxtApp = useNuxtApp()
242
-
243
- // data
244
- const expires = new Date(Date.now() + moduleOptions.cookieExpiryOffsetMs)
245
- const localCookiesEnabled = ref([...(cookiesEnabled.value || [])])
246
- const allCookieIdsString = getAllCookieIdsString(moduleOptions)
222
+ moduleOptions
223
+ } = useCookieControl();
224
+ const nuxtApp = useNuxtApp();
225
+ const expires = new Date(Date.now() + moduleOptions.cookieExpiryOffsetMs);
226
+ const localCookiesEnabled = ref([...cookiesEnabled.value || []]);
227
+ const allCookieIdsString = getAllCookieIdsString(moduleOptions);
247
228
  const cookieIsConsentGiven = useCookie(moduleOptions.cookieNameIsConsentGiven, {
248
229
  expires,
249
- ...moduleOptions.cookieOptions,
250
- })
251
-
230
+ ...moduleOptions.cookieOptions
231
+ });
252
232
  const cookieCookiesEnabledIds = useCookie(
253
233
  moduleOptions.cookieNameCookiesEnabledIds,
254
234
  {
255
235
  expires,
256
- ...moduleOptions.cookieOptions,
257
- },
258
- )
259
-
260
- // computations
236
+ ...moduleOptions.cookieOptions
237
+ }
238
+ );
261
239
  const isSaved = computed(
262
- () =>
263
- getCookieIds(cookiesEnabled.value || [])
264
- .sort()
265
- .join(COOKIE_ID_SEPARATOR) !==
266
- getCookieIds(localCookiesEnabled.value).sort().join(COOKIE_ID_SEPARATOR),
267
- )
268
- const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
269
-
270
- // methods
271
- const accept = () => {
240
+ () => getCookieIds(cookiesEnabled.value || []).sort().join(COOKIE_ID_SEPARATOR) !== getCookieIds(localCookiesEnabled.value).sort().join(COOKIE_ID_SEPARATOR)
241
+ );
242
+ const localeStrings = computed(() => moduleOptions.localeTexts[locale]);
243
+ const acceptAll = () => {
272
244
  setCookies({
273
245
  isConsentGiven: true,
274
- cookiesOptionalEnabled: moduleOptions.cookies.optional,
275
- })
276
- }
246
+ cookiesOptionalEnabled: moduleOptions.cookies.optional
247
+ });
248
+ };
277
249
  const acceptPartial = () => {
278
- const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value)
279
-
250
+ const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value);
280
251
  setCookies({
281
252
  isConsentGiven: true,
282
253
  cookiesOptionalEnabled: [
283
254
  ...moduleOptions.cookies.necessary,
284
- ...moduleOptions.cookies.optional,
285
- ].filter((cookie) => localCookiesEnabledIds.includes(cookie.id)),
286
- })
287
- }
288
- const decline = () => {
255
+ ...moduleOptions.cookies.optional
256
+ ].filter((cookie) => localCookiesEnabledIds.includes(cookie.id))
257
+ });
258
+ };
259
+ const acceptNecessary = () => {
289
260
  setCookies({
290
261
  isConsentGiven: true,
291
- cookiesOptionalEnabled: moduleOptions.cookies.necessary,
292
- })
293
- }
294
- const declineAll = () => {
262
+ cookiesOptionalEnabled: moduleOptions.cookies.necessary
263
+ });
264
+ };
265
+ const acceptNone = () => {
295
266
  setCookies({
296
267
  isConsentGiven: false,
297
- cookiesOptionalEnabled: [],
298
- })
299
- }
300
- const getDescription = (description: Translatable) =>
301
- `${
302
- moduleOptions.isDashInDescriptionEnabled === false ? '' : '-'
303
- } ${resolveTranslatable(description, props.locale)}`
304
- const getName = (name: Translatable) => {
305
- return name === 'functional'
306
- ? localeStrings.value?.cookiesFunctional
307
- : resolveTranslatable(name, props.locale)
308
- }
268
+ cookiesOptionalEnabled: []
269
+ });
270
+ };
271
+ const getDescription = (description) => `${moduleOptions.isDashInDescriptionEnabled === false ? "" : "-"} ${resolveTranslatable(description, locale)}`;
272
+ const getName = (name) => {
273
+ return name === "functional" ? localeStrings.value?.cookiesFunctional : resolveTranslatable(name, locale);
274
+ };
309
275
  const init = () => {
310
- nuxtApp.$cookies.locale.value = props.locale
311
- }
276
+ nuxtApp.$cookies.locale.value = locale;
277
+ };
312
278
  const onModalClick = () => {
313
279
  if (moduleOptions.closeModalOnClickOutside) {
314
- isModalActive.value = false
280
+ isModalActive.value = false;
315
281
  }
316
- }
282
+ };
317
283
  const setCookies = ({
318
284
  cookiesOptionalEnabled: cookiesOptionalEnabledNew,
319
- isConsentGiven: isConsentGivenNew,
320
- }: {
321
- cookiesOptionalEnabled: Cookie[]
322
- isConsentGiven: boolean
285
+ isConsentGiven: isConsentGivenNew
323
286
  }) => {
324
- isConsentGiven.value = isConsentGivenNew // must come before an update to `cookiesEnabled`
325
- cookiesEnabled.value = isConsentGivenNew
326
- ? [
327
- ...moduleOptions.cookies.necessary,
328
- ...moduleOptions.cookies.optional.filter((cookieOptional: Cookie) =>
329
- cookiesOptionalEnabledNew.includes(cookieOptional),
330
- ),
331
- ]
332
- : []
333
- cookiesEnabledIds.value = isConsentGivenNew
334
- ? getCookieIds(cookiesEnabled.value)
335
- : []
336
- }
337
- const toggleButton = ($event: MouseEvent) => {
338
- ;(
339
- ($event.target as HTMLButtonElement | null)
340
- ?.nextSibling as HTMLLabelElement | null
341
- )?.click()
342
- }
343
- const toogleCookie = (cookie: Cookie) => {
344
- const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(cookie.id)
345
-
287
+ isConsentGiven.value = isConsentGivenNew;
288
+ cookiesEnabled.value = isConsentGivenNew ? [
289
+ ...moduleOptions.cookies.necessary,
290
+ ...moduleOptions.cookies.optional.filter(
291
+ (cookieOptional) => cookiesOptionalEnabledNew.includes(cookieOptional)
292
+ )
293
+ ] : [];
294
+ cookiesEnabledIds.value = isConsentGivenNew ? getCookieIds(cookiesEnabled.value) : [];
295
+ };
296
+ const toggleButton = ($event) => {
297
+ ;
298
+ $event.target?.nextSibling?.click();
299
+ };
300
+ const toogleCookie = (cookie) => {
301
+ const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(cookie.id);
346
302
  if (cookieIndex < 0) {
347
- localCookiesEnabled.value.push(cookie)
303
+ localCookiesEnabled.value.push(cookie);
348
304
  } else {
349
- localCookiesEnabled.value.splice(cookieIndex, 1)
305
+ localCookiesEnabled.value.splice(cookieIndex, 1);
350
306
  }
351
- }
352
- const toggleLabel = ($event: KeyboardEvent) => {
353
- if ($event.key === ' ') ($event.target as HTMLLabelElement | null)?.click()
354
- }
355
-
356
- // lifecycle
307
+ };
308
+ const toggleLabel = ($event) => {
309
+ if ($event.key === " ") $event.target?.click();
310
+ };
357
311
  onBeforeMount(() => {
358
312
  if (moduleOptions.colors) {
359
- const variables: Record<string, string> = {}
360
-
313
+ const variables = {};
361
314
  for (const key in moduleOptions.colors) {
362
- variables[`cookie-control-${key}`] = `${moduleOptions.colors[key]}`
315
+ variables[`cookie-control-${key}`] = `${moduleOptions.colors[key]}`;
363
316
  }
364
-
365
- setCssVariables(variables)
317
+ setCssVariables(variables);
366
318
  }
367
-
368
319
  if (moduleOptions.isModalForced && !isConsentGiven.value) {
369
- isModalActive.value = true
320
+ isModalActive.value = true;
370
321
  }
371
- })
322
+ });
372
323
  watch(
373
324
  () => cookiesEnabled.value,
374
325
  (current, _previous) => {
375
- localCookiesEnabled.value = [...(current || [])]
376
-
326
+ localCookiesEnabled.value = [...current || []];
377
327
  if (isConsentGiven.value) {
378
328
  cookieCookiesEnabledIds.value = getCookieIds(current || []).join(
379
- COOKIE_ID_SEPARATOR,
380
- )
381
-
329
+ COOKIE_ID_SEPARATOR
330
+ );
382
331
  for (const cookieEnabled of current || []) {
383
- if (!cookieEnabled.src) continue
384
-
385
- const script = document.createElement('script')
386
- script.src = cookieEnabled.src
387
-
388
- const headElement = document.getElementsByTagName('head')[0]
389
- if (!headElement) return
390
-
391
- headElement.appendChild(script)
332
+ if (!cookieEnabled.src) continue;
333
+ const script = document.createElement("script");
334
+ script.src = cookieEnabled.src;
335
+ const headElement = document.getElementsByTagName("head")[0];
336
+ if (!headElement) return;
337
+ headElement.appendChild(script);
392
338
  }
393
339
  } else {
394
- cookieCookiesEnabledIds.value = undefined
340
+ cookieCookiesEnabledIds.value = void 0;
395
341
  }
396
-
397
- // delete formerly enabled cookies that are now disabled
398
342
  const cookiesOptionalDisabled = moduleOptions.cookies.optional.filter(
399
- (cookieOptional) => !(current || []).includes(cookieOptional),
400
- )
401
-
343
+ (cookieOptional) => !(current || []).includes(cookieOptional)
344
+ );
402
345
  for (const cookieOptionalDisabled of cookiesOptionalDisabled) {
403
- if (!cookieOptionalDisabled.targetCookieIds) continue
404
-
346
+ if (!cookieOptionalDisabled.targetCookieIds) continue;
405
347
  for (const cookieOptionalDisabledId of cookieOptionalDisabled.targetCookieIds) {
406
- removeCookie(cookieOptionalDisabledId)
348
+ removeCookie(cookieOptionalDisabledId);
407
349
  }
408
-
409
350
  if (cookieOptionalDisabled.src) {
410
351
  for (const script of [
411
352
  ...document.head.querySelectorAll(
412
- `script[src="${cookieOptionalDisabled.src}"]`,
413
- ),
353
+ `script[src="${cookieOptionalDisabled.src}"]`
354
+ )
414
355
  ]) {
415
- script.parentNode?.removeChild(script)
356
+ script.parentNode?.removeChild(script);
416
357
  }
417
358
  }
418
359
  }
419
360
  },
420
- { deep: true },
421
- )
422
-
361
+ { deep: true }
362
+ );
423
363
  watch(isConsentGiven, (current, _previous) => {
424
- if (current === undefined) {
425
- cookieIsConsentGiven.value = undefined
364
+ if (current === void 0) {
365
+ cookieIsConsentGiven.value = void 0;
426
366
  } else {
427
- cookieIsConsentGiven.value = current ? allCookieIdsString : '0'
367
+ cookieIsConsentGiven.value = current ? allCookieIdsString : "0";
428
368
  }
429
- })
430
-
369
+ });
431
370
  watch(
432
- () => props.locale,
433
- (locale) => {
434
- nuxtApp.$cookies.locale.value = locale
435
- },
436
- )
437
-
438
- // initialization
439
- init()
440
-
371
+ () => locale,
372
+ (locale2) => {
373
+ nuxtApp.$cookies.locale.value = locale2;
374
+ }
375
+ );
376
+ init();
441
377
  defineExpose({
442
- accept,
378
+ accept: acceptAll,
443
379
  acceptPartial,
444
- decline,
445
- })
380
+ decline: acceptNecessary
381
+ });
446
382
  </script>