@24i/bigscreen-sdk 0.9.9-alpha.2147 → 0.9.9-alpha.2149

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.
Files changed (58) hide show
  1. package/package.json +3 -4
  2. package/packages/developer-tools/src/DeveloperConsole/utils/formatTime.ts +13 -0
  3. package/packages/developer-tools/src/DeveloperConsole/utils/index.ts +3 -0
  4. package/packages/developer-tools/src/DeveloperConsole/utils/stringify.ts +10 -0
  5. package/packages/developer-tools/src/DeveloperConsole/utils/styles.ts +24 -0
  6. package/packages/developer-tools/src/EnvironmentSelection/utils/format.ts +4 -0
  7. package/packages/developer-tools/src/TechnicalInfo/utils/eme01bSupport.ts +58 -0
  8. package/packages/developer-tools/src/TechnicalInfo/utils/emeSupport.ts +80 -0
  9. package/packages/developer-tools/src/TechnicalInfo/utils/formatTimezone.ts +15 -0
  10. package/packages/developer-tools/src/TechnicalInfo/utils/mseSupport.ts +14 -0
  11. package/packages/developer-tools/src/utils/reload.ts +6 -0
  12. package/packages/keyboard/src/utils/caret.ts +48 -0
  13. package/packages/keyboard/src/utils/generateFocusMatrixFromStringMatrix.ts +12 -0
  14. package/packages/keyboard/src/utils/input.ts +40 -0
  15. package/packages/list/utils/index.ts +1 -0
  16. package/packages/logger/src/utils/deviceInfo.ts +25 -0
  17. package/packages/logger/src/utils/index.ts +1 -0
  18. package/packages/utils/README.md +336 -0
  19. package/packages/utils/src/addClass.ts +9 -0
  20. package/packages/utils/src/counter.ts +47 -0
  21. package/packages/utils/src/debounce.ts +54 -0
  22. package/packages/utils/src/displayToggler.scss +3 -0
  23. package/packages/utils/src/displayToggler.ts +38 -0
  24. package/packages/utils/src/elementUtils.ts +58 -0
  25. package/packages/utils/src/generateUuid.ts +19 -0
  26. package/packages/utils/src/index.ts +35 -0
  27. package/packages/utils/src/memoryInfo.ts +21 -0
  28. package/packages/utils/src/nTimes.ts +9 -0
  29. package/packages/utils/src/noop.ts +1 -0
  30. package/packages/utils/src/offsetPosition.ts +56 -0
  31. package/packages/utils/src/removeClass.ts +9 -0
  32. package/packages/utils/src/scaledImage.ts +21 -0
  33. package/packages/utils/src/stopEvent.ts +10 -0
  34. package/packages/utils/src/timeConstants.ts +11 -0
  35. package/packages/utils/src/timers/createInterval.ts +19 -0
  36. package/packages/utils/src/timers/createTimeout.ts +22 -0
  37. package/packages/utils/src/timers/index.ts +4 -0
  38. package/packages/utils/src/timers/runAsync.ts +3 -0
  39. package/packages/utils/src/timers/types.ts +9 -0
  40. package/packages/utils/src/wait.ts +1 -0
  41. package/packages/utils/src/xhr/index.ts +11 -0
  42. package/packages/utils/src/xhr/xhrSend.ts +139 -0
  43. package/packages/utils/src/xhr/xhrSendRetry.ts +77 -0
  44. package/utils/create-export-maps/index.ts +3 -0
  45. package/utils/create-export-maps/src/__tests__/createExportMaps.spec.ts +50 -0
  46. package/utils/create-export-maps/src/createExportMaps.ts +61 -0
  47. package/utils/create-package/README.md +40 -0
  48. package/utils/create-package/src/createPackage.ts +72 -0
  49. package/utils/create-package/src/index.ts +3 -0
  50. package/utils/create-package/src/questionnaire/questions.ts +19 -0
  51. package/utils/create-package/src/settings/Settings.ts +5 -0
  52. package/utils/create-package/src/types.ts +4 -0
  53. package/utils/create-package/templates/typescript/README.md +9 -0
  54. package/utils/create-package/templates/typescript/exports.json +6 -0
  55. package/utils/create-package/templates/typescript/src/index.ts +0 -0
  56. package/utils/run-scripts/index.ts +3 -0
  57. package/utils/run-scripts/src/__tests__/runScripts.spec.ts +45 -0
  58. package/utils/run-scripts/src/runScripts.ts +20 -0
@@ -0,0 +1,336 @@
1
+ ---
2
+ id: README
3
+ title: Utils
4
+ hide_title: true
5
+ sidebar_label: Utils
6
+ ---
7
+
8
+ # Utils
9
+ This package is a set of tools that do not fit to any other package.
10
+
11
+ You can either import all utils if you use it like this:
12
+ ```ts
13
+ import { generateUuid } from '@24i/bigscreen-sdk/utils';
14
+ ```
15
+ Or you can import single functions like this:
16
+ ```ts
17
+ import { generateUuid } from '@24i/bigscreen-sdk/utils/generateUuid';
18
+ ```
19
+
20
+ ## Available utils
21
+ - **[addClass](#addClass)** - safely adds class to reference.
22
+ - **[debounce](#debounce)** - debounced function is only executed again after a period of not being called, supports leading, trailing (default) and both executions.
23
+ - **[displayToggler](#displayToggler)** - exports `getDisplayToggler` that allows you to easily show/hide an element with guard preventing unnecessary DOM calls.
24
+ - **[generateUuid](#generateUuid)** - function to get UUIDv4 according to RFC 4122.
25
+ - **[isMouseUsed](#isMouseUsed)** - **DEPRECATED** moved to `device` package.
26
+ - **[memoryInfo](#memoryInfo)** - two functions that returns currently active segment size and total allocated size of JS heap, in bytes.
27
+ - **[noop](#noop)** - for all your noop needs, keep only 1 reference.
28
+ - **[nTimes](#nTimes)** - for generating n of something (e.g. 4 same elements).
29
+ - **[offsetPosition](#offsetPosition)** - safely sets references transform to translate x/y, uses top/left if transform not supported, allows for forcing top/left or transform mode.
30
+ - **[removeClass](#removeClass)** - safely removes class from reference.
31
+ - **[scaledImage](#scaledImage)** - returns URL for scaledImage.
32
+ - **[stopEvent](#stopEvent)** - calls stopPropagation and preventDefault on provided event.
33
+ - **[timeConstants](#timeConstants)** - exports frequently used time constants.
34
+ - **[timers](#timers)** - functions to simplify work with setTimeout and setInterval.
35
+ - **[counter](#counter)** - exports `createCounter` that allows you to add value to counter till callback is triggered at some point.
36
+ - **[xhr](#xhr)** - provides wrap over `XMLHttpRequest`, with the possibility to repeat the failing request.
37
+
38
+ ### addClass
39
+ Adds a class to the element in the reference.
40
+
41
+ It takes two params:
42
+ - `element: Reference<HTMLElement>` - ref to element to which to add the class
43
+ - `class: string` - class to add
44
+
45
+ ### debounce
46
+ Debounces the function to prevent too frequent calls.
47
+
48
+ It takes 2 mandatory and 1 optional param:
49
+ - `func: Function` - function to debounce
50
+ - `debounceTime: number` - time of debounce in ms
51
+ - `{ leading?, trailing? }?: DebounceConfig = { trailing: true }` - setting whether to call on leading or trailing edge
52
+ **Usage**
53
+ ```ts
54
+ showVertical = debounce((model: Program) => {
55
+ // implementation
56
+ }, this.props.verticalDebounceTime);
57
+
58
+ showHorizontal = debounce((model: Program) => {
59
+ // implementation
60
+ }, this.props.horizontalDebounceTime);
61
+
62
+ show(model: Program) {
63
+ const isVertical = // some condition
64
+ this.activeDebounce?.cancel();
65
+ this.activeDebounce = isVertical ? this.showVertical(model) : this.showHorizontal(model);
66
+ }
67
+ ```
68
+
69
+ ### displayToggler
70
+ Unifies showing and hiding an element. Has guard to prevent multiple unnecessary DOM calls.
71
+ It is important to correctly set the `initialIsHidden` value and not to change the display class in other ways.
72
+ You can keep calling show/hide multiple times in a row. Classlist will be accessed and edited only once.
73
+ It imports the needed styles for you so you do not need to take care of that in the project.
74
+ ```scss
75
+ .display-none {
76
+ display: none;
77
+ }
78
+ ```
79
+
80
+ It exports 3 values:
81
+ - `DISPLAY_NONE` - string `display-none` (class name)
82
+ - `getDisplayToggler` - setup function with element and initial shown/hide value
83
+ - `IDisplayToggler` - interface returned by `getDisplayToggler`
84
+
85
+ `getDisplayToggler` takes 1 mandatory and 1 optional param:
86
+ - `element: Reference<HTMLElement>` - element that will be shown/hidden
87
+ - `initialIsHidden?: boolean = false` - initial state of hidden value
88
+
89
+ And returns `IDisplayToggler` interface with 4 functions:
90
+ - `show: () => void;` - removes `display-none` class
91
+ - `hide: () => void;` - adds `display-none` class
92
+ - `isVisible: () => boolean;` - returns true if the element is visible, false otherwise
93
+ - `isHidden: () => boolean;` - returns true if the element is hidden, false otherwise
94
+
95
+ ### generateUuid
96
+ Returns an UUIDv4 according to RFC 4122, like ex. "123e4567-e89b-12d3-a456-426614174000".
97
+
98
+ ### isMouseUsed
99
+ **DEPRECATED** moved to `device` package.
100
+
101
+ ### memoryInfo
102
+ It exports 2 function:
103
+ - `getUsedJSHeapSize: () => number;` - The currently active segment of JS heap, in bytes.
104
+ - `getTotalJSHeapSize: () => number;` - The total allocated heap size, in bytes.
105
+
106
+ ### noop
107
+ No operation function for your needs.
108
+
109
+ ### nTimes
110
+ Maps an array of n empty elements to another array. E.g.:
111
+ ```tsx
112
+ const MAX_DIGITS = 5;
113
+
114
+ <div className="numeri-zapper">
115
+ {nTimes(MAX_DIGITS, () => <div className="zapper-number">-</div>)}
116
+ </div>
117
+ ```
118
+
119
+ ### offsetPosition
120
+ Function to change the position of the element in x, y fashion.
121
+ It automatically uses `transform` if available and if not disabled by the application.
122
+ It also takes into account the language direction and
123
+ automatically flips the x offset for right-to-left cases.
124
+
125
+ It takes 2 mandatory params and 1 optional:
126
+ - `element: Reference<HTMLElement>` - element which position will be changed
127
+ - `offset: { x?: number | string, y?: number | string }` - position offset
128
+ You can pass either number or `${number}px` to offset and you can set only one of x, y or both.
129
+ - `rtl: boolean = isRtl()` - boolean flag setting text direction defaulting to used language.
130
+
131
+ It also has 3 namespaced functions for your control:
132
+ - `offsetPosition.usesTransform() => boolean` - returns true if transform is used
133
+ - `offsetPosition.forceTransform() => void` - enforces the use of transform
134
+ - `offsetPosition.forceTopLeft() => void` - enforces the use of top/left properties
135
+
136
+ ### removeClass
137
+ Removes a class from the element in the reference.
138
+
139
+ It takes 2 params:
140
+ - `element: Reference<HTMLElement>` - ref to element from which to remove the class
141
+ - `class: string` - class to remove
142
+
143
+ ### scaledImage
144
+ Returns the URL for scaled image
145
+
146
+ It takes 2 required params and 1 optional:
147
+ - `url: string` - the URL of image to scale
148
+ - `dimensions: { height: number; width: number, fit?: 'cover' | 'contain' | 'inside' }` -
149
+ the dimensions of the resulting image, `fit` defaults to `'cover'`
150
+ - `scalingServer` - optional base url of scaling server (defaults to `http://imageresize.24i.com`)
151
+
152
+ Fit option:
153
+ - `cover` - similar to CSS cover it crops the image to fully cover required area with image data
154
+ - `contain` - it fits the image inside the required frame and then adds transparent areas to fill
155
+ the required size
156
+ - `inside` - it fits the image inside the required frame and returns smaller image. (It does not add
157
+ the transparent sides like `contain` does.)
158
+
159
+ ### stopEvent
160
+ Calls `preventDefault` and `stopPropagation`
161
+
162
+ It takes 1 param:
163
+ - `event: Event` - event to stop
164
+
165
+ If you need to stop event immediately, there is also an export `stopEventImmediately` that calls
166
+ `stopImmediatePropagation` as well.
167
+
168
+ ### timeConstants
169
+ ```ts
170
+ export const SECONDS_PER_MINUTE = 60;
171
+ export const MINUTES_PER_HALF_HOUR = 30;
172
+ export const MINUTES_PER_HOUR = 60;
173
+ export const HOURS_PER_DAY = 24;
174
+ export const DAYS_PER_WEEK = 7;
175
+ export const SECOND_IN_MS = 1000;
176
+ export const MINUTE_IN_MS = SECOND_IN_MS * SECONDS_PER_MINUTE;
177
+ export const HALF_HOUR_IN_MS = MINUTE_IN_MS * MINUTES_PER_HALF_HOUR;
178
+ export const HOUR_IN_MS = MINUTE_IN_MS * MINUTES_PER_HOUR;
179
+ export const DAY_IN_MS = HOUR_IN_MS * HOURS_PER_DAY;
180
+ ```
181
+
182
+ ### timers
183
+ Timers exports three functions: `createTimeout`, `createInterval` and `runAsync`.
184
+
185
+ #### createTimeout and createInterval
186
+ `createTimeout` and `createInterval` differ only in calling either set/clearTimeout or set/clearInterval.
187
+ Therefore only one is needed to be described. The idea behind these functions is to remove the need
188
+ to handle the work with timeout/interval id in the code by yourself.
189
+
190
+ They both return the same interface (also exported):
191
+ ```ts
192
+ interface TimedFunction {
193
+ /**
194
+ * Function to set timeout or interval the same way you would setTimeout or setInterval
195
+ * @param callbackFn function to call on timeout or every interval
196
+ * @param timeMs timeout in ms or interval length in ms
197
+ */
198
+ set: (callbackFn: () => void, timeMs: number) => void,
199
+ /**
200
+ * Function to cancel the timeout or interval
201
+ */
202
+ clear: () => void,
203
+ /**
204
+ * Function that returns true if the timeout or interval is active.
205
+ * Timeout: was not yet run && was not cancel (in other words is pending)
206
+ * Interval: waiting for next run (in other words was set and not cleared)
207
+ */
208
+ isActive: () => boolean,
209
+ }
210
+ ```
211
+
212
+ Usual example how you would do it without these utils:
213
+ ```ts
214
+ class MyComponent extends Component<Props> {
215
+ updateIntervalId: number | null = null;
216
+
217
+ componentDidMount() {
218
+ this.updateIntervalId = window.setInterval(this.onInterval, UPDATE_INTERVAL_TIME);
219
+ }
220
+
221
+ componentWillUnmount() {
222
+ if (this.updateIntervalId !== null) {
223
+ window.clearInterval(this.updateIntervalId);
224
+ this.updateIntervalId = null;
225
+ }
226
+ }
227
+ }
228
+ ```
229
+ now with `createInterval`:
230
+ ```ts
231
+ class MyComponent extends Component<Props> {
232
+ updateInterval = createInterval();
233
+
234
+ componentDidMount() {
235
+ this.updateInterval.set(this.onInterval, UPDATE_INTERVAL_TIME);
236
+ }
237
+
238
+ componentWillUnmount() {
239
+ this.updateInterval.clear();
240
+ }
241
+ }
242
+ ```
243
+ Sometimes you also extend the timeout before it runs little bit like this:
244
+ ```ts
245
+ if (this.debounceTimeoutId) {
246
+ window.clearTimeout(this.debounceTimeoutId);
247
+ }
248
+ this.debounceTimeoutId = window.setTimeout(this.debouncedFn, DEBOUNCE_TIME);
249
+ ```
250
+ with `createTimeout` you can shorten this to:
251
+ ```ts
252
+ this.debounceTimeout.set(this.debouncedFn, DEBOUNCE_TIME);
253
+ ```
254
+ The clearing of the previous timeout is done for you. The same applies to `createInterval`.
255
+
256
+ #### runAsync
257
+
258
+ `runAsync` is just a tiny utility to make code more readable. From time to time, we need to run part
259
+ of the code to run async from the rest. Usually, we do it like this:
260
+ ```ts
261
+ window.setTimeout(() => {
262
+ // code that runs async
263
+ }, 0);
264
+ ```
265
+ with `runAsync` we can write it like this:
266
+ ```ts
267
+ runAsync(() => {
268
+ // code that runs async
269
+ });
270
+ ```
271
+ The advantage is a clear code that tells you nicely what it does (plus it is slightly shorter).
272
+
273
+ ### counter
274
+ Unify simple functionality of triggering callback after certain value is on or above limit. For example, you need to
275
+ trigger callback after 3 iterations increased by number 1, so you will create counter like this:
276
+
277
+ ```ts
278
+ const counter = createCounter({
279
+ triggerAt: 3,
280
+ callback: () => { console.log('All systems nominal') }
281
+ });
282
+
283
+ counter.add(); // increase counter by default number 1
284
+ counter.add();
285
+ counter.add();
286
+ // All systems nominal
287
+
288
+ counter.reset();
289
+ counter.add(3); // increase counter by custom number 3
290
+ // All systems nominal
291
+ ```
292
+
293
+ ### xhr
294
+ Provides wrap over `XMLHttpRequest`, with the possibility to repeat the failing request.
295
+ Exports two methods: `xhrSend` and `xhrSendRetry`.
296
+
297
+ #### xhrSend
298
+ Wrap over `XMLHttpRequest`, without the possibility to repeat the failing request.
299
+
300
+ ```ts
301
+ const url = 'http://test.com';
302
+ const options = {
303
+ method: 'POST',
304
+ headers: {
305
+ headerA: 'headerValueA',
306
+ },
307
+ body: 'payload data',
308
+ };
309
+ const response = await xhrSend(url, options);
310
+ ```
311
+
312
+ #### xhrSendRetry
313
+ Wraps `xhrSend` function to allow retrying the failing request X times.
314
+
315
+ ```ts
316
+ const url = 'http://test.com';
317
+ const xhrSendOptions = {
318
+ method: 'POST',
319
+ headers: {
320
+ headerA: 'headerValueA',
321
+ },
322
+ body: 'payload data',
323
+ };
324
+ const retryConfig = {
325
+ retry: 2,
326
+ retryDelay: 10,
327
+ shouldRetry: (data: ShouldRetryParam) => {
328
+ const { error, response } = data;
329
+ if (error) return true;
330
+ if (!response || !response.ok) return true;
331
+ return false;
332
+ },
333
+ };
334
+ const options = { ...xhrSendOptions, retryConfig };
335
+ const response = await xhrSendRetry(url, options);
336
+ ```
@@ -0,0 +1,9 @@
1
+ import { Reference } from '@24i/bigscreen-sdk/jsx';
2
+
3
+ export const addClass = (
4
+ reference: Reference,
5
+ className: string,
6
+ ): void => {
7
+ if (!reference.current) return;
8
+ reference.current.classList.add(className);
9
+ };
@@ -0,0 +1,47 @@
1
+ type CounterProps = {
2
+ triggerAt: number;
3
+ callback: () => void;
4
+ };
5
+
6
+ export interface ICounter {
7
+ /**
8
+ * Add number to counter value
9
+ * @param value Number to be added to counter value. If no number supplied,
10
+ * counter value is increased by 1.
11
+ */
12
+ add: (value?: number) => void,
13
+ /**
14
+ * @returns The current value of counter
15
+ */
16
+ getCurrentValue: () => number,
17
+ /**
18
+ * Check if `triggerAt` value is equal or greater than current value of counter.
19
+ * @returns True if `triggerAt` value is equal or greater than counter value.
20
+ */
21
+ isTriggered: () => boolean,
22
+ /**
23
+ * Check if number is equal to counter value
24
+ * @param value Number to be checked. If no number supplied,
25
+ * the `triggerAt` value is used to compare.
26
+ */
27
+ isEqual: (value?: number) => boolean,
28
+ /**
29
+ * Reset counter value, it is set to zero
30
+ */
31
+ reset: () => void,
32
+ }
33
+
34
+ export const createCounter = ({ triggerAt, callback }: CounterProps): ICounter => {
35
+ let counter = 0;
36
+ return {
37
+ add: (value = 1) => {
38
+ const oldCounter = counter;
39
+ counter += value;
40
+ if (oldCounter < triggerAt && counter >= triggerAt) callback();
41
+ },
42
+ getCurrentValue: () => counter,
43
+ isTriggered: () => counter >= triggerAt,
44
+ isEqual: (value: number = triggerAt) => counter === value,
45
+ reset: () => { counter = 0; },
46
+ };
47
+ };
@@ -0,0 +1,54 @@
1
+ export type DebounceResult = {
2
+ cancel: () => void;
3
+ flush: () => void;
4
+ };
5
+
6
+ export type DebounceOptions = {
7
+ leading?: boolean;
8
+ trailing?: boolean;
9
+ };
10
+
11
+ export const debounce = <T extends any[], U extends (...args: T) => any>(
12
+ func: U,
13
+ debounceTime: number,
14
+ { leading, trailing }: DebounceOptions = { trailing: true },
15
+ // eslint-disable-next-line sonarjs/cognitive-complexity
16
+ ): (...args: T) => DebounceResult => {
17
+ if (typeof func !== 'function') {
18
+ throw new Error('The first parameter of debounce must be a function');
19
+ }
20
+
21
+ const isLeading = !!leading;
22
+ const isTrailing = !!trailing || !isLeading;
23
+ let wasExecuted = false;
24
+ let timeoutID: number | null = null;
25
+ return ((...args: T) => {
26
+ wasExecuted = false;
27
+ if (timeoutID !== null) {
28
+ clearTimeout(timeoutID);
29
+ } else if (isLeading) {
30
+ func(...args);
31
+ wasExecuted = true;
32
+ }
33
+ timeoutID = window.setTimeout(() => {
34
+ if (isTrailing && !wasExecuted) {
35
+ func(...args);
36
+ wasExecuted = true;
37
+ }
38
+ timeoutID = null;
39
+ }, debounceTime);
40
+
41
+ return {
42
+ cancel: () => {
43
+ if (timeoutID === null) return;
44
+ clearTimeout(timeoutID);
45
+ timeoutID = null;
46
+ },
47
+ flush: () => {
48
+ if (timeoutID === null) return;
49
+ clearTimeout(timeoutID);
50
+ if (!wasExecuted) func(...args);
51
+ },
52
+ };
53
+ });
54
+ };
@@ -0,0 +1,3 @@
1
+ .display-none {
2
+ display: none;
3
+ }
@@ -0,0 +1,38 @@
1
+ import { Reference } from '@24i/bigscreen-sdk/jsx';
2
+ import { addClass } from './addClass';
3
+ import { removeClass } from './removeClass';
4
+ import './displayToggler.scss';
5
+
6
+ export const DISPLAY_NONE = 'display-none';
7
+
8
+ export interface IDisplayToggler {
9
+ show: () => void,
10
+ hide: () => void,
11
+ isVisible: () => boolean,
12
+ isHidden: () => boolean,
13
+ }
14
+
15
+ export const getDisplayToggler = (
16
+ element: Reference<HTMLElement>,
17
+ initialIsHidden = false,
18
+ ): IDisplayToggler => {
19
+ let isHiddenFlag: boolean = initialIsHidden;
20
+
21
+ const show = () => {
22
+ if (!isHiddenFlag) return;
23
+ isHiddenFlag = false;
24
+ removeClass(element, DISPLAY_NONE);
25
+ };
26
+
27
+ const hide = () => {
28
+ if (isHiddenFlag) return;
29
+ isHiddenFlag = true;
30
+ addClass(element, DISPLAY_NONE);
31
+ };
32
+
33
+ const isVisible = () => !isHiddenFlag;
34
+
35
+ const isHidden = () => isHiddenFlag;
36
+
37
+ return { show, hide, isVisible, isHidden };
38
+ };
@@ -0,0 +1,58 @@
1
+ import { Reference, unwrapReference } from '@24i/bigscreen-sdk/jsx';
2
+
3
+ export const isElementVisible = (
4
+ elementOrReference: HTMLElement | Reference<HTMLElement>,
5
+ ) => {
6
+ const element = unwrapReference(elementOrReference);
7
+ if (!element) return false;
8
+ const style = window.getComputedStyle(element);
9
+ return style.display !== 'none' && style.visibility !== 'hidden';
10
+ };
11
+
12
+ export const isElementFullyVisible = (
13
+ elementOrReference: HTMLElement | Reference<HTMLElement>,
14
+ ) => {
15
+ const element = unwrapReference(elementOrReference);
16
+ if (isElementVisible(element)) {
17
+ let parent = element.parentElement;
18
+ while (parent) {
19
+ if (parent === document.body) {
20
+ return true;
21
+ }
22
+ if (!isElementVisible(parent)) {
23
+ return false;
24
+ }
25
+ parent = parent.parentElement;
26
+ }
27
+ return false;
28
+ }
29
+ return false;
30
+ };
31
+
32
+ export const isElementWrappedBy = (
33
+ elementOrReference: HTMLElement | Reference<HTMLElement>,
34
+ wrapperElementOrReferenceOrCondition:
35
+ HTMLElement | Reference<HTMLElement> | ((currentWrapper: HTMLElement) => boolean),
36
+ includesElementItself = false,
37
+ ) => {
38
+ const element = unwrapReference(elementOrReference);
39
+ let currentParent = includesElementItself ? element : element.parentElement;
40
+ let wrapperElement: HTMLElement | null = null;
41
+ let condition: ((currentWrapper: HTMLElement) => boolean) | null = null;
42
+ if (typeof wrapperElementOrReferenceOrCondition === 'function') {
43
+ condition = wrapperElementOrReferenceOrCondition;
44
+ } else {
45
+ wrapperElement = unwrapReference(wrapperElementOrReferenceOrCondition);
46
+ if (!wrapperElement) return false;
47
+ }
48
+ while (currentParent) {
49
+ if (condition && condition(currentParent)) {
50
+ return true;
51
+ }
52
+ if (currentParent === wrapperElement) {
53
+ return true;
54
+ }
55
+ currentParent = currentParent.parentElement;
56
+ }
57
+ return false;
58
+ };
@@ -0,0 +1,19 @@
1
+ /* eslint-disable no-magic-numbers */
2
+ /* eslint-disable no-nested-ternary */
3
+ /* eslint-disable no-bitwise */
4
+
5
+ /**
6
+ * Generates Universally Unique ID (UUIDv4 - RFC 4122)
7
+ * @returns universally unique identifier. Ex. "123e4567-e89b-12d3-a456-426614174000"
8
+ */
9
+ export const generateUuid = (): string => {
10
+ let id = '';
11
+ for (let i = 0; i < 32; i++) {
12
+ const random = Math.random() * 16 | 0;
13
+ if (i === 8 || i === 12 || i === 16 || i === 20) {
14
+ id += '-';
15
+ }
16
+ id += (i === 12 ? 4 : (i === 16 ? ((random & 3) | 8) : random)).toString(16);
17
+ }
18
+ return id;
19
+ };
@@ -0,0 +1,35 @@
1
+ export { generateUuid } from './generateUuid';
2
+ export { stopEvent } from './stopEvent';
3
+ export { noop } from './noop';
4
+ export { offsetPosition } from './offsetPosition';
5
+ export { addClass } from './addClass';
6
+ export { removeClass } from './removeClass';
7
+ export { debounce } from './debounce';
8
+ export { wait } from './wait';
9
+ export { scaledImage } from './scaledImage';
10
+ export { nTimes } from './nTimes';
11
+ export { getDisplayToggler, DISPLAY_NONE } from './displayToggler';
12
+ export type { IDisplayToggler } from './displayToggler';
13
+ export { getUsedJSHeapSize, getTotalJSHeapSize } from './memoryInfo';
14
+ export {
15
+ isElementVisible,
16
+ isElementFullyVisible,
17
+ isElementWrappedBy,
18
+ } from './elementUtils';
19
+ export { createInterval, createTimeout, runAsync } from './timers';
20
+ export type { TimedFunction } from './timers';
21
+ export { createCounter } from './counter';
22
+ export type { ICounter } from './counter';
23
+ export {
24
+ DAY_IN_MS,
25
+ HOURS_PER_DAY,
26
+ HALF_HOUR_IN_MS,
27
+ HOUR_IN_MS,
28
+ MINUTES_PER_HALF_HOUR,
29
+ MINUTES_PER_HOUR,
30
+ MINUTE_IN_MS,
31
+ SECONDS_PER_MINUTE,
32
+ SECOND_IN_MS,
33
+ } from './timeConstants';
34
+ export { xhrSend, xhrSendRetry, defaultRetryConfig, mockXhr } from './xhr';
35
+ export type { XhrOptions, XhrResponse, RetryConfig, RSOptions, ShouldRetryParam } from './xhr';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The currently active segment size of JS heap, in bytes.
3
+ * @return {Number} size value. If size is unknown, returns 0.
4
+ */
5
+
6
+ function getUsedJSHeapSize() {
7
+ return (window.performance as any)?.memory?.usedJSHeapSize as number || 0;
8
+ }
9
+
10
+ /**
11
+ * The total allocated heap size, in bytes.
12
+ * @return size value. If size is unknown, returns 0.
13
+ */
14
+ function getTotalJSHeapSize() {
15
+ return (window.performance as any)?.memory?.totalJSHeapSize as number || 0;
16
+ }
17
+
18
+ export {
19
+ getUsedJSHeapSize,
20
+ getTotalJSHeapSize,
21
+ };
@@ -0,0 +1,9 @@
1
+ import { map } from '@24i/bigscreen-sdk/perf-utils/array';
2
+
3
+ export const nTimes = <T>(
4
+ n: number,
5
+ mappingFunction: (_: undefined, index: number) => T,
6
+ ): T[] => {
7
+ const array = new Array(n);
8
+ return map(array, mappingFunction);
9
+ };
@@ -0,0 +1 @@
1
+ export const noop = () => {};