@dargmuesli/nuxt-cookie-control 9.0.0-beta.1 → 9.0.1

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,383 @@
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 ClientOnlyPrerender from "#cookie-control/components/ClientOnlyPrerender.vue";
203
+ import { COOKIE_ID_SEPARATOR } from "#cookie-control/constants";
217
204
  import {
218
205
  getAllCookieIdsString,
219
206
  getCookieIds,
220
207
  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
-
208
+ resolveTranslatable
209
+ } from "#cookie-control/methods";
210
+ import setCssVariables from "#cookie-control/set-vars";
211
+ import {
212
+ CookieType
213
+ } from "#cookie-control/types";
214
+ import { useCookieControl, useCookie, useNuxtApp } from "#imports";
215
+ const { locale = "en" } = defineProps({
216
+ locale: { type: String, required: false }
217
+ });
234
218
  const {
235
219
  cookiesEnabled,
236
220
  cookiesEnabledIds,
237
221
  isConsentGiven,
238
222
  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)
223
+ moduleOptions
224
+ } = useCookieControl();
225
+ const nuxtApp = useNuxtApp();
226
+ const expires = new Date(Date.now() + moduleOptions.cookieExpiryOffsetMs);
227
+ const localCookiesEnabled = ref([...cookiesEnabled.value || []]);
228
+ const allCookieIdsString = getAllCookieIdsString(moduleOptions);
247
229
  const cookieIsConsentGiven = useCookie(moduleOptions.cookieNameIsConsentGiven, {
248
230
  expires,
249
- ...moduleOptions.cookieOptions,
250
- })
251
-
231
+ ...moduleOptions.cookieOptions
232
+ });
252
233
  const cookieCookiesEnabledIds = useCookie(
253
234
  moduleOptions.cookieNameCookiesEnabledIds,
254
235
  {
255
236
  expires,
256
- ...moduleOptions.cookieOptions,
257
- },
258
- )
259
-
260
- // computations
237
+ ...moduleOptions.cookieOptions
238
+ }
239
+ );
261
240
  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 = () => {
241
+ () => getCookieIds(cookiesEnabled.value || []).sort().join(COOKIE_ID_SEPARATOR) !== getCookieIds(localCookiesEnabled.value).sort().join(COOKIE_ID_SEPARATOR)
242
+ );
243
+ const localeStrings = computed(() => moduleOptions.localeTexts[locale]);
244
+ const acceptAll = () => {
272
245
  setCookies({
273
246
  isConsentGiven: true,
274
- cookiesOptionalEnabled: moduleOptions.cookies.optional,
275
- })
276
- }
247
+ cookiesOptionalEnabled: moduleOptions.cookies.optional
248
+ });
249
+ };
277
250
  const acceptPartial = () => {
278
- const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value)
279
-
251
+ const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value);
280
252
  setCookies({
281
253
  isConsentGiven: true,
282
254
  cookiesOptionalEnabled: [
283
255
  ...moduleOptions.cookies.necessary,
284
- ...moduleOptions.cookies.optional,
285
- ].filter((cookie) => localCookiesEnabledIds.includes(cookie.id)),
286
- })
287
- }
288
- const decline = () => {
256
+ ...moduleOptions.cookies.optional
257
+ ].filter((cookie) => localCookiesEnabledIds.includes(cookie.id))
258
+ });
259
+ };
260
+ const acceptNecessary = () => {
289
261
  setCookies({
290
262
  isConsentGiven: true,
291
- cookiesOptionalEnabled: moduleOptions.cookies.necessary,
292
- })
293
- }
294
- const declineAll = () => {
263
+ cookiesOptionalEnabled: moduleOptions.cookies.necessary
264
+ });
265
+ };
266
+ const acceptNone = () => {
295
267
  setCookies({
296
268
  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
- }
269
+ cookiesOptionalEnabled: []
270
+ });
271
+ };
272
+ const getDescription = (description) => `${moduleOptions.isDashInDescriptionEnabled === false ? "" : "-"} ${resolveTranslatable(description, locale)}`;
273
+ const getName = (name) => {
274
+ return name === "functional" ? localeStrings.value?.cookiesFunctional : resolveTranslatable(name, locale);
275
+ };
309
276
  const init = () => {
310
- nuxtApp.$cookies.locale.value = props.locale
311
- }
277
+ nuxtApp.$cookies.locale.value = locale;
278
+ };
312
279
  const onModalClick = () => {
313
280
  if (moduleOptions.closeModalOnClickOutside) {
314
- isModalActive.value = false
281
+ isModalActive.value = false;
315
282
  }
316
- }
283
+ };
317
284
  const setCookies = ({
318
285
  cookiesOptionalEnabled: cookiesOptionalEnabledNew,
319
- isConsentGiven: isConsentGivenNew,
320
- }: {
321
- cookiesOptionalEnabled: Cookie[]
322
- isConsentGiven: boolean
286
+ isConsentGiven: isConsentGivenNew
323
287
  }) => {
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
-
288
+ isConsentGiven.value = isConsentGivenNew;
289
+ cookiesEnabled.value = isConsentGivenNew ? [
290
+ ...moduleOptions.cookies.necessary,
291
+ ...moduleOptions.cookies.optional.filter(
292
+ (cookieOptional) => cookiesOptionalEnabledNew.includes(cookieOptional)
293
+ )
294
+ ] : [];
295
+ cookiesEnabledIds.value = isConsentGivenNew ? getCookieIds(cookiesEnabled.value) : [];
296
+ };
297
+ const toggleButton = ($event) => {
298
+ ;
299
+ $event.target?.nextSibling?.click();
300
+ };
301
+ const toogleCookie = (cookie) => {
302
+ const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(cookie.id);
346
303
  if (cookieIndex < 0) {
347
- localCookiesEnabled.value.push(cookie)
304
+ localCookiesEnabled.value.push(cookie);
348
305
  } else {
349
- localCookiesEnabled.value.splice(cookieIndex, 1)
306
+ localCookiesEnabled.value.splice(cookieIndex, 1);
350
307
  }
351
- }
352
- const toggleLabel = ($event: KeyboardEvent) => {
353
- if ($event.key === ' ') ($event.target as HTMLLabelElement | null)?.click()
354
- }
355
-
356
- // lifecycle
308
+ };
309
+ const toggleLabel = ($event) => {
310
+ if ($event.key === " ") $event.target?.click();
311
+ };
357
312
  onBeforeMount(() => {
358
313
  if (moduleOptions.colors) {
359
- const variables: Record<string, string> = {}
360
-
314
+ const variables = {};
361
315
  for (const key in moduleOptions.colors) {
362
- variables[`cookie-control-${key}`] = `${moduleOptions.colors[key]}`
316
+ variables[`cookie-control-${key}`] = `${moduleOptions.colors[key]}`;
363
317
  }
364
-
365
- setCssVariables(variables)
318
+ setCssVariables(variables);
366
319
  }
367
-
368
320
  if (moduleOptions.isModalForced && !isConsentGiven.value) {
369
- isModalActive.value = true
321
+ isModalActive.value = true;
370
322
  }
371
- })
323
+ });
372
324
  watch(
373
325
  () => cookiesEnabled.value,
374
326
  (current, _previous) => {
375
- localCookiesEnabled.value = [...(current || [])]
376
-
327
+ localCookiesEnabled.value = [...current || []];
377
328
  if (isConsentGiven.value) {
378
329
  cookieCookiesEnabledIds.value = getCookieIds(current || []).join(
379
- COOKIE_ID_SEPARATOR,
380
- )
381
-
330
+ COOKIE_ID_SEPARATOR
331
+ );
382
332
  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)
333
+ if (!cookieEnabled.src) continue;
334
+ const script = document.createElement("script");
335
+ script.src = cookieEnabled.src;
336
+ const headElement = document.getElementsByTagName("head")[0];
337
+ if (!headElement) return;
338
+ headElement.appendChild(script);
392
339
  }
393
340
  } else {
394
- cookieCookiesEnabledIds.value = undefined
341
+ cookieCookiesEnabledIds.value = void 0;
395
342
  }
396
-
397
- // delete formerly enabled cookies that are now disabled
398
343
  const cookiesOptionalDisabled = moduleOptions.cookies.optional.filter(
399
- (cookieOptional) => !(current || []).includes(cookieOptional),
400
- )
401
-
344
+ (cookieOptional) => !(current || []).includes(cookieOptional)
345
+ );
402
346
  for (const cookieOptionalDisabled of cookiesOptionalDisabled) {
403
- if (!cookieOptionalDisabled.targetCookieIds) continue
404
-
347
+ if (!cookieOptionalDisabled.targetCookieIds) continue;
405
348
  for (const cookieOptionalDisabledId of cookieOptionalDisabled.targetCookieIds) {
406
- removeCookie(cookieOptionalDisabledId)
349
+ removeCookie(cookieOptionalDisabledId);
407
350
  }
408
-
409
351
  if (cookieOptionalDisabled.src) {
410
352
  for (const script of [
411
353
  ...document.head.querySelectorAll(
412
- `script[src="${cookieOptionalDisabled.src}"]`,
413
- ),
354
+ `script[src="${cookieOptionalDisabled.src}"]`
355
+ )
414
356
  ]) {
415
- script.parentNode?.removeChild(script)
357
+ script.parentNode?.removeChild(script);
416
358
  }
417
359
  }
418
360
  }
419
361
  },
420
- { deep: true },
421
- )
422
-
362
+ { deep: true }
363
+ );
423
364
  watch(isConsentGiven, (current, _previous) => {
424
- if (current === undefined) {
425
- cookieIsConsentGiven.value = undefined
365
+ if (current === void 0) {
366
+ cookieIsConsentGiven.value = void 0;
426
367
  } else {
427
- cookieIsConsentGiven.value = current ? allCookieIdsString : '0'
368
+ cookieIsConsentGiven.value = current ? allCookieIdsString : "0";
428
369
  }
429
- })
430
-
370
+ });
431
371
  watch(
432
- () => props.locale,
433
- (locale) => {
434
- nuxtApp.$cookies.locale.value = locale
435
- },
436
- )
437
-
438
- // initialization
439
- init()
440
-
372
+ () => locale,
373
+ (locale2) => {
374
+ nuxtApp.$cookies.locale.value = locale2;
375
+ }
376
+ );
377
+ init();
441
378
  defineExpose({
442
- accept,
379
+ accept: acceptAll,
443
380
  acceptPartial,
444
- decline,
445
- })
381
+ decline: acceptNecessary
382
+ });
446
383
  </script>