@entur/utils 1.0.0-alpha.0 → 1.0.0-next.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,665 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
- var warning = require('tiny-warning');
7
- var tokens = require('@entur/tokens');
8
-
9
- function useDebounce(callBack, debounceTime) {
10
- var timeoutRef = React.useRef();
11
- React.useEffect(function () {
12
- return function () {
13
- if (timeoutRef.current) {
14
- clearTimeout(timeoutRef.current);
15
- }
16
- };
17
- }, []);
18
- var debouncedFunc = function debouncedFunc() {
19
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
20
- args[_key] = arguments[_key];
21
- }
22
- if (timeoutRef.current) {
23
- clearTimeout(timeoutRef.current);
24
- }
25
- timeoutRef.current = setTimeout(function () {
26
- callBack.apply(void 0, args);
27
- }, debounceTime);
28
- };
29
- return debouncedFunc;
30
- }
31
-
32
- var useRandomId = function useRandomId(prefix) {
33
- var ref = React.useRef(String(Math.random()).substring(2));
34
- return prefix + "-" + ref.current;
35
- };
36
-
37
- function useOnMount(callback) {
38
- var hasRun = React.useRef(false);
39
- React.useEffect(function () {
40
- if (!hasRun.current) {
41
- hasRun.current = true;
42
- callback();
43
- }
44
- }, [callback]);
45
- }
46
-
47
- var mergeRefs = function mergeRefs() {
48
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
49
- refs[_key] = arguments[_key];
50
- }
51
- return function (node) {
52
- for (var _i = 0, _refs = refs; _i < _refs.length; _i++) {
53
- var ref = _refs[_i];
54
- if (typeof ref === 'function') {
55
- ref(node);
56
- } else if (ref) ref.current = node;
57
- }
58
- };
59
- };
60
-
61
- var useForceUpdate = function useForceUpdate() {
62
- var _useState = React.useState(0),
63
- setValue = _useState[1];
64
- return function () {
65
- return setValue(function (value) {
66
- return value + 1;
67
- });
68
- };
69
- };
70
-
71
- var useOnClickOutside = function useOnClickOutside(refs, handler) {
72
- React.useEffect(function () {
73
- var listener = function listener(event) {
74
- // If the ref contains the clicked element, then the click is not outside
75
- if (refs.some(function (ref) {
76
- return elementContainsEventTarget(ref.current, event);
77
- })) {
78
- return;
79
- }
80
- handler();
81
- };
82
- document.addEventListener('mousedown', listener);
83
- document.addEventListener('touchstart', listener);
84
- return function () {
85
- document.removeEventListener('mousedown', listener);
86
- document.removeEventListener('touchstart', listener);
87
- };
88
- }, [refs, handler]);
89
- };
90
- var elementContainsEventTarget = function elementContainsEventTarget(element, event) {
91
- if (!element) {
92
- return false;
93
- }
94
- if (element.contains(event.target)) {
95
- return true;
96
- }
97
- // For elements inside a Shadow DOM we need to check the composedPath
98
- if (event.composed && event.composedPath) {
99
- var contains = event.composedPath().find(function (target) {
100
- if (target === window) {
101
- return false;
102
- }
103
- return element.contains(target);
104
- });
105
- return contains ? true : false;
106
- }
107
- return false;
108
- };
109
-
110
- var useOnEscape = function useOnEscape(ref, handler) {
111
- React.useEffect(function () {
112
- var runIfKeyIsEscape = function runIfKeyIsEscape(event) {
113
- if (event.key === 'Escape') handler();
114
- };
115
- var currentRef = ref.current;
116
- currentRef == null ? void 0 : currentRef.addEventListener('keydown', runIfKeyIsEscape);
117
- return function () {
118
- return currentRef == null ? void 0 : currentRef.removeEventListener('keydown', runIfKeyIsEscape);
119
- };
120
- }, [ref, handler]);
121
- };
122
-
123
- // from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs
124
- var getWindowDimensions = function getWindowDimensions() {
125
- if (typeof window === 'undefined') return {
126
- width: undefined,
127
- height: undefined
128
- };
129
- var _window = window,
130
- width = _window.innerWidth,
131
- height = _window.innerHeight;
132
- return {
133
- width: width,
134
- height: height
135
- };
136
- };
137
- var useWindowDimensions = function useWindowDimensions() {
138
- var _useState = React.useState(getWindowDimensions()),
139
- windowDimensions = _useState[0],
140
- setWindowDimensions = _useState[1];
141
- React.useEffect(function () {
142
- function handleResize() {
143
- setWindowDimensions(getWindowDimensions());
144
- }
145
- if (typeof window !== 'undefined') {
146
- window.addEventListener('resize', handleResize);
147
- return function () {
148
- return window.removeEventListener('resize', handleResize);
149
- };
150
- }
151
- }, []);
152
- return windowDimensions;
153
- };
154
-
155
- var ConditionalWrapper = function ConditionalWrapper(_ref) {
156
- var condition = _ref.condition,
157
- wrapper = _ref.wrapper,
158
- children = _ref.children;
159
- return condition ? wrapper(children) : React.createElement(React.Fragment, null, children);
160
- };
161
-
162
- var packagesToCheck = /*#__PURE__*/new Set();
163
- var checkTimeoutId;
164
- function checkAndWarn() {
165
- var missingImports = Array.from(packagesToCheck).filter(function (namespace) {
166
- return parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--eds-" + namespace)) !== 1;
167
- }).sort();
168
- // Finally, we warn about those pesky imports
169
- var singleMissingImport = missingImports.length === 1;
170
- warning(missingImports.length === 0, "You are missing " + (singleMissingImport ? 'a CSS import' : missingImports.length + " CSS imports") + "!\n\nPlease add the following CSS import" + (singleMissingImport ? '' : 's') + " somewhere in your app:\n\n" + missingImports.map(function (namespace) {
171
- return "\t@import '@entur/" + namespace + "/dist/styles.css';";
172
- }).join('\n') + "\n") ;
173
- }
174
- /** Warns the developer if they have forgotten to include styles */
175
- function warnAboutMissingStyles() {
176
- var _process, _process$env;
177
- // We skip this check in production, and when we build static sites
178
- if (typeof window === 'undefined' || typeof process !== 'undefined' && ((_process = process) == null ? void 0 : (_process$env = _process.env) == null ? void 0 : _process$env.TEST) === 'true') {
179
- return;
180
- }
181
- // First, let's clear earlier calls to setTimeout
182
- window.clearTimeout(checkTimeoutId);
183
- // Next, let's add all namespaces to the set of packages to check
184
- for (var _len = arguments.length, namespaces = new Array(_len), _key = 0; _key < _len; _key++) {
185
- namespaces[_key] = arguments[_key];
186
- }
187
- namespaces.forEach(function (namespace) {
188
- return packagesToCheck.add(namespace);
189
- });
190
- // Finally. let's trigger a run of the checker.
191
- checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
192
- }
193
-
194
- // with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react
195
- var getNodeText = function getNodeText(node) {
196
- var _node$props$children, _node$props;
197
- if (node === null || node === undefined) return '';
198
- if (['string', 'number'].includes(typeof node)) return node.toString();
199
- if (node instanceof Array) return node.map(getNodeText).join('').trim();
200
- if (typeof node === 'object')
201
- // @ts-expect-error props does exist for react nodes
202
- return getNodeText((_node$props$children = (_node$props = node.props) == null ? void 0 : _node$props.children) != null ? _node$props$children : '').trim();
203
- return 'unknown';
204
- };
205
-
206
- function _regeneratorRuntime() {
207
- _regeneratorRuntime = function () {
208
- return exports;
209
- };
210
- var exports = {},
211
- Op = Object.prototype,
212
- hasOwn = Op.hasOwnProperty,
213
- defineProperty = Object.defineProperty || function (obj, key, desc) {
214
- obj[key] = desc.value;
215
- },
216
- $Symbol = "function" == typeof Symbol ? Symbol : {},
217
- iteratorSymbol = $Symbol.iterator || "@@iterator",
218
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
219
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
220
- function define(obj, key, value) {
221
- return Object.defineProperty(obj, key, {
222
- value: value,
223
- enumerable: !0,
224
- configurable: !0,
225
- writable: !0
226
- }), obj[key];
227
- }
228
- try {
229
- define({}, "");
230
- } catch (err) {
231
- define = function (obj, key, value) {
232
- return obj[key] = value;
233
- };
234
- }
235
- function wrap(innerFn, outerFn, self, tryLocsList) {
236
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
237
- generator = Object.create(protoGenerator.prototype),
238
- context = new Context(tryLocsList || []);
239
- return defineProperty(generator, "_invoke", {
240
- value: makeInvokeMethod(innerFn, self, context)
241
- }), generator;
242
- }
243
- function tryCatch(fn, obj, arg) {
244
- try {
245
- return {
246
- type: "normal",
247
- arg: fn.call(obj, arg)
248
- };
249
- } catch (err) {
250
- return {
251
- type: "throw",
252
- arg: err
253
- };
254
- }
255
- }
256
- exports.wrap = wrap;
257
- var ContinueSentinel = {};
258
- function Generator() {}
259
- function GeneratorFunction() {}
260
- function GeneratorFunctionPrototype() {}
261
- var IteratorPrototype = {};
262
- define(IteratorPrototype, iteratorSymbol, function () {
263
- return this;
264
- });
265
- var getProto = Object.getPrototypeOf,
266
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
267
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
268
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
269
- function defineIteratorMethods(prototype) {
270
- ["next", "throw", "return"].forEach(function (method) {
271
- define(prototype, method, function (arg) {
272
- return this._invoke(method, arg);
273
- });
274
- });
275
- }
276
- function AsyncIterator(generator, PromiseImpl) {
277
- function invoke(method, arg, resolve, reject) {
278
- var record = tryCatch(generator[method], generator, arg);
279
- if ("throw" !== record.type) {
280
- var result = record.arg,
281
- value = result.value;
282
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
283
- invoke("next", value, resolve, reject);
284
- }, function (err) {
285
- invoke("throw", err, resolve, reject);
286
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
287
- result.value = unwrapped, resolve(result);
288
- }, function (error) {
289
- return invoke("throw", error, resolve, reject);
290
- });
291
- }
292
- reject(record.arg);
293
- }
294
- var previousPromise;
295
- defineProperty(this, "_invoke", {
296
- value: function (method, arg) {
297
- function callInvokeWithMethodAndArg() {
298
- return new PromiseImpl(function (resolve, reject) {
299
- invoke(method, arg, resolve, reject);
300
- });
301
- }
302
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
303
- }
304
- });
305
- }
306
- function makeInvokeMethod(innerFn, self, context) {
307
- var state = "suspendedStart";
308
- return function (method, arg) {
309
- if ("executing" === state) throw new Error("Generator is already running");
310
- if ("completed" === state) {
311
- if ("throw" === method) throw arg;
312
- return doneResult();
313
- }
314
- for (context.method = method, context.arg = arg;;) {
315
- var delegate = context.delegate;
316
- if (delegate) {
317
- var delegateResult = maybeInvokeDelegate(delegate, context);
318
- if (delegateResult) {
319
- if (delegateResult === ContinueSentinel) continue;
320
- return delegateResult;
321
- }
322
- }
323
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
324
- if ("suspendedStart" === state) throw state = "completed", context.arg;
325
- context.dispatchException(context.arg);
326
- } else "return" === context.method && context.abrupt("return", context.arg);
327
- state = "executing";
328
- var record = tryCatch(innerFn, self, context);
329
- if ("normal" === record.type) {
330
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
331
- return {
332
- value: record.arg,
333
- done: context.done
334
- };
335
- }
336
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
337
- }
338
- };
339
- }
340
- function maybeInvokeDelegate(delegate, context) {
341
- var methodName = context.method,
342
- method = delegate.iterator[methodName];
343
- if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
344
- var record = tryCatch(method, delegate.iterator, context.arg);
345
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
346
- var info = record.arg;
347
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
348
- }
349
- function pushTryEntry(locs) {
350
- var entry = {
351
- tryLoc: locs[0]
352
- };
353
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
354
- }
355
- function resetTryEntry(entry) {
356
- var record = entry.completion || {};
357
- record.type = "normal", delete record.arg, entry.completion = record;
358
- }
359
- function Context(tryLocsList) {
360
- this.tryEntries = [{
361
- tryLoc: "root"
362
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
363
- }
364
- function values(iterable) {
365
- if (iterable) {
366
- var iteratorMethod = iterable[iteratorSymbol];
367
- if (iteratorMethod) return iteratorMethod.call(iterable);
368
- if ("function" == typeof iterable.next) return iterable;
369
- if (!isNaN(iterable.length)) {
370
- var i = -1,
371
- next = function next() {
372
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
373
- return next.value = undefined, next.done = !0, next;
374
- };
375
- return next.next = next;
376
- }
377
- }
378
- return {
379
- next: doneResult
380
- };
381
- }
382
- function doneResult() {
383
- return {
384
- value: undefined,
385
- done: !0
386
- };
387
- }
388
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
389
- value: GeneratorFunctionPrototype,
390
- configurable: !0
391
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
392
- value: GeneratorFunction,
393
- configurable: !0
394
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
395
- var ctor = "function" == typeof genFun && genFun.constructor;
396
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
397
- }, exports.mark = function (genFun) {
398
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
399
- }, exports.awrap = function (arg) {
400
- return {
401
- __await: arg
402
- };
403
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
404
- return this;
405
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
406
- void 0 === PromiseImpl && (PromiseImpl = Promise);
407
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
408
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
409
- return result.done ? result.value : iter.next();
410
- });
411
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
412
- return this;
413
- }), define(Gp, "toString", function () {
414
- return "[object Generator]";
415
- }), exports.keys = function (val) {
416
- var object = Object(val),
417
- keys = [];
418
- for (var key in object) keys.push(key);
419
- return keys.reverse(), function next() {
420
- for (; keys.length;) {
421
- var key = keys.pop();
422
- if (key in object) return next.value = key, next.done = !1, next;
423
- }
424
- return next.done = !0, next;
425
- };
426
- }, exports.values = values, Context.prototype = {
427
- constructor: Context,
428
- reset: function (skipTempReset) {
429
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
430
- },
431
- stop: function () {
432
- this.done = !0;
433
- var rootRecord = this.tryEntries[0].completion;
434
- if ("throw" === rootRecord.type) throw rootRecord.arg;
435
- return this.rval;
436
- },
437
- dispatchException: function (exception) {
438
- if (this.done) throw exception;
439
- var context = this;
440
- function handle(loc, caught) {
441
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
442
- }
443
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
444
- var entry = this.tryEntries[i],
445
- record = entry.completion;
446
- if ("root" === entry.tryLoc) return handle("end");
447
- if (entry.tryLoc <= this.prev) {
448
- var hasCatch = hasOwn.call(entry, "catchLoc"),
449
- hasFinally = hasOwn.call(entry, "finallyLoc");
450
- if (hasCatch && hasFinally) {
451
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
452
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
453
- } else if (hasCatch) {
454
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
455
- } else {
456
- if (!hasFinally) throw new Error("try statement without catch or finally");
457
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
458
- }
459
- }
460
- }
461
- },
462
- abrupt: function (type, arg) {
463
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
464
- var entry = this.tryEntries[i];
465
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
466
- var finallyEntry = entry;
467
- break;
468
- }
469
- }
470
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
471
- var record = finallyEntry ? finallyEntry.completion : {};
472
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
473
- },
474
- complete: function (record, afterLoc) {
475
- if ("throw" === record.type) throw record.arg;
476
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
477
- },
478
- finish: function (finallyLoc) {
479
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
480
- var entry = this.tryEntries[i];
481
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
482
- }
483
- },
484
- catch: function (tryLoc) {
485
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
486
- var entry = this.tryEntries[i];
487
- if (entry.tryLoc === tryLoc) {
488
- var record = entry.completion;
489
- if ("throw" === record.type) {
490
- var thrown = record.arg;
491
- resetTryEntry(entry);
492
- }
493
- return thrown;
494
- }
495
- }
496
- throw new Error("illegal catch attempt");
497
- },
498
- delegateYield: function (iterable, resultName, nextLoc) {
499
- return this.delegate = {
500
- iterator: values(iterable),
501
- resultName: resultName,
502
- nextLoc: nextLoc
503
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
504
- }
505
- }, exports;
506
- }
507
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
508
- try {
509
- var info = gen[key](arg);
510
- var value = info.value;
511
- } catch (error) {
512
- reject(error);
513
- return;
514
- }
515
- if (info.done) {
516
- resolve(value);
517
- } else {
518
- Promise.resolve(value).then(_next, _throw);
519
- }
520
- }
521
- function _asyncToGenerator(fn) {
522
- return function () {
523
- var self = this,
524
- args = arguments;
525
- return new Promise(function (resolve, reject) {
526
- var gen = fn.apply(self, args);
527
- function _next(value) {
528
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
529
- }
530
- function _throw(err) {
531
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
532
- }
533
- _next(undefined);
534
- });
535
- };
536
- }
537
-
538
- var CMP_INITIALIZE_EVENT = 'UC_UI_INITIALIZED';
539
- var CONSENT_UPDATED_EVENT = 'UC_CONSENT';
540
- var CMP_SHADOW_ROOT_ID = 'usercentrics-cmp-ui';
541
- var acceptAllConsents = function acceptAllConsents() {
542
- return window.__ucCmp.acceptAllConsents();
543
- };
544
- var denyAllConsents = function denyAllConsents() {
545
- return window.__ucCmp.denyAllConsents();
546
- };
547
- var updateServicesConsents = function updateServicesConsents(serviceConsents) {
548
- return window.__ucCmp.updateServicesConsents(serviceConsents);
549
- };
550
- var changeLanguage = function changeLanguage(language) {
551
- return window.__ucCmp.changeLanguage(language);
552
- };
553
- var showCookieBanner = function showCookieBanner() {
554
- return window.__ucCmp.showFirstLayer();
555
- };
556
- var hideCookieBanner = function hideCookieBanner() {
557
- return window.__ucCmp.closeCmp();
558
- };
559
- function styleCookieBanner() {
560
- return _styleCookieBanner.apply(this, arguments);
561
- }
562
- function _styleCookieBanner() {
563
- _styleCookieBanner = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
564
- var _cmpElement$shadowRoo;
565
- var cmpElement, sheet;
566
- return _regeneratorRuntime().wrap(function _callee$(_context) {
567
- while (1) {
568
- switch (_context.prev = _context.next) {
569
- case 0:
570
- _context.next = 2;
571
- return waitForElementWithId(CMP_SHADOW_ROOT_ID);
572
- case 2:
573
- cmpElement = document.getElementById(CMP_SHADOW_ROOT_ID);
574
- console.log('cmp', cmpElement);
575
- sheet = new CSSStyleSheet();
576
- sheet.replaceSync(cmpStyleSheet);
577
- cmpElement == null ? void 0 : (_cmpElement$shadowRoo = cmpElement.shadowRoot) == null ? void 0 : _cmpElement$shadowRoo.adoptedStyleSheets.push(sheet);
578
- case 7:
579
- case "end":
580
- return _context.stop();
581
- }
582
- }
583
- }, _callee);
584
- }));
585
- return _styleCookieBanner.apply(this, arguments);
586
- }
587
- function formatConsentEvent(event) {
588
- var _event$detail$service, _event$detail;
589
- return Object.entries((_event$detail$service = event == null ? void 0 : (_event$detail = event.detail) == null ? void 0 : _event$detail.services) != null ? _event$detail$service : {}).map(function (service) {
590
- var _service$1$consent$gi, _service$1$consent;
591
- return {
592
- id: service[0],
593
- name: service[1].name,
594
- consentGiven: (_service$1$consent$gi = (_service$1$consent = service[1].consent) == null ? void 0 : _service$1$consent.given) != null ? _service$1$consent$gi : false,
595
- category: service[1].category
596
- };
597
- });
598
- }
599
- var cookieBanner = {
600
- acceptAllConsents: acceptAllConsents,
601
- denyAllConsents: denyAllConsents,
602
- updateServicesConsents: updateServicesConsents,
603
- changeLanguage: changeLanguage,
604
- showCookieBanner: showCookieBanner,
605
- hideCookieBanner: hideCookieBanner,
606
- eventListner: {
607
- CONSENT_UPDATED_EVENT: CONSENT_UPDATED_EVENT,
608
- CMP_INITIALIZE_EVENT: CMP_INITIALIZE_EVENT
609
- },
610
- formatConsentEvent: formatConsentEvent
611
- };
612
- if (typeof window !== 'undefined') styleCookieBanner();
613
- /** Utils */
614
- // Returns true when element with id is available in the DOM
615
- function waitForElementWithId(_x) {
616
- return _waitForElementWithId.apply(this, arguments);
617
- }
618
- /** Stylesheet for CookieBanner */
619
- function _waitForElementWithId() {
620
- _waitForElementWithId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(selector) {
621
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
622
- while (1) {
623
- switch (_context2.prev = _context2.next) {
624
- case 0:
625
- return _context2.abrupt("return", new Promise(function (resolve) {
626
- var observer = new MutationObserver(function (_, observer) {
627
- var element = document.querySelector('#' + selector);
628
- if (element) {
629
- observer.disconnect();
630
- resolve(true);
631
- }
632
- });
633
- observer.observe(document.body, {
634
- childList: true,
635
- subtree: true
636
- });
637
- }));
638
- case 1:
639
- case "end":
640
- return _context2.stop();
641
- }
642
- }
643
- }, _callee2);
644
- }));
645
- return _waitForElementWithId.apply(this, arguments);
646
- }
647
- var cmpStyleSheet = "\n .cmp-wrapper.cmp-wrapper.cmp-wrapper { \n width: 100%;\n\n .cmp:not(.second) {\n padding: " + tokens.space.rem.large + "rem calc((100dvw - 54rem) / 2);\n border-radius: unset;\n box-shadow: " + tokens.shadows.cardShadow + ";\n\n .language-selector-menu {\n right: calc((100dvw - 64rem) / 2);\n }\n } \n\n .privacy-title {\n font-size: " + tokens.fontSizes.rem.extraLarge2 + "rem;\n }\n .privacy-text {\n font-size: " + tokens.fontSizes.rem.large + "rem;\n line-height: " + tokens.lineHeights.rem.large + "rem;\n }\n\n\n .buttons-row {\n justify-content: flex-end;\n }\n\n button[data-action=\"consent\"] {\n flex-grow: unset;\n flex-basis: unset;\n width: fit-content;\n min-width: 9.5rem;\n height: 3rem;\n cursor: pointer;\n font-size: 1rem;\n line-height: 1.5rem;\n font-weight: 500;\n \n &[data-action-type=\"accept\"] {\n background-color: var(--components-button-primary-contrast-default);\n color: var(--components-button-primary-contrast-text);\n\n &:hover {\n background-color: var(--components-button-primary-contrast-hover);\n }\n }\n \n &[data-action-type=\"more\"],\n &[data-action-type=\"deny\"] {\n background-color: transparent;\n color: var(--components-button-secondary-contrast-text);\n border: 2px solid var(--components-button-secondary-contrast-border);\n\n &:hover {\n background-color: var(--components-button-secondary-contrast-hover);\n }\n }\n }\n\n .poweredBy {\n display: none;\n }\n }\n";
648
-
649
- exports.CMP_INITIALIZE_EVENT = CMP_INITIALIZE_EVENT;
650
- exports.CONSENT_UPDATED_EVENT = CONSENT_UPDATED_EVENT;
651
- exports.ConditionalWrapper = ConditionalWrapper;
652
- exports.cmpStyleSheet = cmpStyleSheet;
653
- exports.cookieBanner = cookieBanner;
654
- exports.getNodeText = getNodeText;
655
- exports.mergeRefs = mergeRefs;
656
- exports.useDebounce = useDebounce;
657
- exports.useForceUpdate = useForceUpdate;
658
- exports.useOnClickOutside = useOnClickOutside;
659
- exports.useOnEscape = useOnEscape;
660
- exports.useOnMount = useOnMount;
661
- exports.useRandomId = useRandomId;
662
- exports.useWindowDimensions = useWindowDimensions;
663
- exports.waitForElementWithId = waitForElementWithId;
664
- exports.warnAboutMissingStyles = warnAboutMissingStyles;
665
- //# sourceMappingURL=utils.cjs.development.js.map