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