@betarena/ad-engine 0.0.61 → 0.0.63

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betarena/ad-engine",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "private": false,
5
5
  "description": "Betarena ad-engine widget",
6
6
  "keywords": [
@@ -64,7 +64,9 @@
64
64
  "@betarena/scores-lib": "1.11.0-alpha.17",
65
65
  "@fontsource/roboto": "5.0.12",
66
66
  "colorthief": "2.6.0",
67
- "svelte-preprocess": "5.1.3"
67
+ "device-detector-js": "3.0.3",
68
+ "svelte-preprocess": "5.1.3",
69
+ "ua-parser-js": "2.0.0"
68
70
  },
69
71
  "main": "./dist/index.js",
70
72
  "svelte": "./src/index.js",
@@ -47,7 +47,7 @@
47
47
  import { betarenaEndpoint } from './constants/instance.js';
48
48
  import { storeSession } from './store/session.js';
49
49
  import { logger } from './utils/debug.js';
50
- import { detectDeviceType } from './utils/device.js';
50
+ import { detectDeviceWithUA } from './utils/device.js';
51
51
  import { postMod } from './utils/fetch.js';
52
52
  import { getUserLocation } from './utils/geo.js';
53
53
 
@@ -166,7 +166,7 @@
166
166
  const
167
167
  /**
168
168
  * @description
169
- * 📝 `List` of `HTMLElements` identified on `page` for a target `zone`.
169
+ * 📝 `List` of `HTMLElements` identified on `page` expecting a target `zone` advertisement injection.
170
170
  */
171
171
  listElementTarget = document.querySelectorAll('[data-betarena-zone-id]')
172
172
  ;
@@ -181,11 +181,11 @@
181
181
  );
182
182
 
183
183
  // ╭─────
184
- // │ NOTE: |:| loop over elements detected as betarena elegible ads (global/outer)
184
+ // │ NOTE: |:| loop over elements detected as betarena elegible advert injection (global/outer)
185
185
  // ╰─────
186
186
  for (const elem of listElementTarget)
187
187
  {
188
- const
188
+ let
189
189
  /**
190
190
  * @description
191
191
  * 📝 Value of Betarena Zone Id
@@ -195,9 +195,44 @@
195
195
 
196
196
  if (!value) continue;
197
197
 
198
- mapBetarenaAdvertStandardElement.set(parseInt(value), elem);
198
+ // [🐞]
199
+ logger
200
+ (
201
+ [
202
+ `🔹 [var] ➤ value ${value}`
203
+ ]
204
+ );
205
+
206
+ if (value.includes(','))
207
+ {
208
+ const
209
+ /**
210
+ * @description
211
+ * 📝 Split value by `,`
212
+ */
213
+ values = value.split(',')
214
+ ;
215
+
216
+ for (const val of values)
217
+ mapBetarenaAdvertStandardElement.set(parseInt(val), elem);
218
+ ;
219
+ }
220
+ else
221
+ {
222
+ mapBetarenaAdvertStandardElement.set(parseInt(value), elem);
223
+ }
199
224
  }
200
225
 
226
+ // [🐞]
227
+ logger
228
+ (
229
+ [
230
+ `🔹 [var] ➤ mapBetarenaAdvertStandardElement.keys ${[...mapBetarenaAdvertStandardElement.keys()]}`,
231
+ `🔹 [var] ➤ mapBetarenaAdvertStandardElement.size ${mapBetarenaAdvertStandardElement.size}`,
232
+ '🚏 checkpoint ➤ generateElementMap(..) // END'
233
+ ]
234
+ );
235
+
201
236
  return
202
237
  }
203
238
 
@@ -599,7 +634,7 @@
599
634
  (
600
635
  ): Promise < void >
601
636
  {
602
- deviceType = detectDeviceType() as IDeviceType;
637
+ deviceType = detectDeviceWithUA() as IDeviceType;
603
638
  geoLocation = await getUserLocation();
604
639
  generateElementMap();
605
640
 
@@ -607,9 +642,7 @@
607
642
  logger
608
643
  (
609
644
  [
610
- '🚏 checkpoint ➤ initialize(..) // START',
611
- `🔹 [var] ➤ mapBetarenaAdvertStandardElement.size ${mapBetarenaAdvertStandardElement.size}`
612
- // `🔹 [var] ➤ zoneIds ${JSON.stringify(zoneIds)}`
645
+ '🚏 checkpoint ➤ initialize(..) // START'
613
646
  ]
614
647
  );
615
648
 
@@ -663,7 +696,7 @@
663
696
  {
664
697
  () =>
665
698
  {
666
- detectDeviceType();
699
+ detectDeviceWithUA();
667
700
  return;
668
701
  }
669
702
  }
@@ -728,7 +761,7 @@
728
761
  <hr>
729
762
 
730
763
  <div
731
- data-betarena-zone-id=2
764
+ data-betarena-zone-id=2,3
732
765
  >
733
766
  {#each { length: 25 } as _, i}
734
767
  <p>
@@ -234,45 +234,31 @@
234
234
  -->
235
235
 
236
236
  <div
237
- id="inter-outer"
237
+ id='inter-outer'
238
238
  bind:this={instanceAdvertInterscroller}
239
- class="interscroller-wrapper"
240
- style=
241
- "
242
- display: none;
243
- height: 100vh;
244
- right: 0px;
245
- width: 100vw;
246
- max-width: 100vw;
247
- background-color: var(--betarena-ad-engine-interscroller-advert-background-image-);
248
- "
239
+ class=
240
+ '
241
+ interscroller-wrapper
242
+ '
249
243
  >
250
- <h2 class="info-box">
244
+ <h2 class='info-box'>
251
245
  Advertisement
252
246
  </h2>
253
247
 
254
248
  <div
255
- id="intscdiv"
256
- class="interscroller-bg-wrapper"
257
- style="height: 100%; right: 0px; clip-path: rect(0px 100vw 100vh 0px); width: 100vw;"
249
+ class=
250
+ '
251
+ interscroller-bg-wrapper
252
+ '
258
253
  >
259
254
  <div
260
- id="nxtads"
261
255
  class=
262
- "
256
+ '
263
257
  interscroller-bg
264
- "
265
- style=
266
- "
267
- height: 100%;
268
- width: 100%;
269
- padding: 0px;
270
- overflow: hidden;
271
- text-align: center;
272
- "
258
+ '
273
259
  >
274
260
  <a
275
- target="_blank"
261
+ target='_blank'
276
262
  on:click=
277
263
  {
278
264
  () =>
@@ -289,20 +275,19 @@
289
275
  href={objectAdverData.data?.cta_link}
290
276
  >
291
277
  <div
278
+ id='advert'
292
279
  style=
293
- "
294
- height: 100vh;
295
- width: 100vw;
280
+ '
296
281
  background: url({objectAdverData.data?.media});
297
282
  background-repeat: no-repeat;
298
- background-size: contain;
299
- "
283
+ background-size: 100vw 100vh;
284
+ '
300
285
  />
301
286
  </a>
302
287
  </div>
303
288
  </div>
304
289
 
305
- <h2 class="info-box">
290
+ <h2 class='info-box'>
306
291
  Scroll to continue
307
292
  </h2>
308
293
  </div>
@@ -331,15 +316,24 @@
331
316
  position: relative !important;
332
317
  cursor: pointer !important;
333
318
  z-index: 10000000 !important;
319
+ right: 0px;
334
320
  /* 🛝 layout */
335
321
  flex-direction: column;
336
322
  justify-content: space-between;
323
+ display: none;
324
+ /* 🎨 style */
325
+ min-width: 100vw;
326
+ max-width: 100vw;
327
+ height: 100vh;
328
+ min-height: 100vh;
329
+ background-color: var(--betarena-ad-engine-interscroller-advert-background-image-);
337
330
 
338
331
  .info-box
339
332
  {
340
333
  /* 📌 position */
341
334
  z-index: 1;
342
335
  /* 🎨 style */
336
+ width: 100%;
343
337
  color: var(--colors-text-text-primary-900, #fbfbfb);
344
338
  text-align: center;
345
339
  font-family: Roboto;
@@ -348,7 +342,6 @@
348
342
  font-weight: 700 !important;
349
343
  line-height: 38px !important; /* 190% */
350
344
  text-transform: uppercase;
351
- width: 100%;
352
345
  margin: 0 !important;
353
346
  background: var(--colors-background-bg-secondary, #313131);
354
347
  }
@@ -356,34 +349,47 @@
356
349
  .interscroller-bg-wrapper
357
350
  {
358
351
  /* 📌 position */
359
- position: absolute !important;
360
- left: 0 !important;
352
+ position: absolute;
353
+ left: 0;
354
+ right: 0;
361
355
  /* 🎨 style */
362
- width: 100% !important;
356
+ width: 100vw;
357
+ height: 100vh;
358
+ clip-path: rect(0 100vw 100vh 0);
363
359
 
364
360
  .interscroller-bg
365
361
  {
366
362
  /* 📌 position */
367
- position: fixed !important;
368
- top: 30px;
363
+ position: fixed;
364
+ top: 50%;
365
+ left: 50%;
366
+ transform: translate(-50%, -50%);
369
367
  /* 🎨 style */
370
- height: 100% !important;
371
- backface-visibility: hidden !important;
372
- -webkit-backface-visibility: hidden !important;
373
- border: 0 !important;
374
- }
368
+ width: 100vw;
369
+ height: 100vh;
370
+ backface-visibility: hidden;
371
+ -webkit-backface-visibility: hidden;
372
+ border: 0;
373
+ text-align: center;
374
+
375
+ a
376
+ {
377
+ /* 🎨 style */
378
+ display: block;
379
+ width: 100vw;
380
+ height: 100vh;
381
+ text-decoration: none;
375
382
 
376
- .ad_image
377
- {
378
- /* 🎨 style */
379
- width: 100% !important;
380
- height: 100% !important;
381
- max-width: 100vw !important;
382
- max-height: 100% !important;
383
- touch-action: manipulation;
384
- user-select: none;
385
- -webkit-user-drag: none;
386
- -webkit-touch-callout: none;
383
+ div#advert
384
+ {
385
+ /* 📌 position */
386
+ position: relative;
387
+ /* 🎨 style */
388
+ margin-top: -30px;
389
+ max-width: 100vw;
390
+ height: 100vh;
391
+ }
392
+ }
387
393
  }
388
394
  }
389
395
  }
@@ -15,63 +15,94 @@
15
15
 
16
16
  // #region ➤ 📦 Package Imports
17
17
 
18
+ import DeviceDetector from 'device-detector-js';
19
+ import { UAParser } from 'ua-parser-js';
20
+
18
21
  import { logger } from './debug.js';
19
22
 
23
+ import type { IDeviceType } from '@betarena/scores-lib/types/ad-engine/index.js';
24
+
20
25
  // #endregion ➤ 📦 Package Imports
21
26
 
22
27
  /**
23
28
  * @author
24
29
  * @migbash
25
30
  * @summary
26
- * 🟥 MAIN
31
+ * 🟦 HELPER
27
32
  * @description
28
- * 📝 Detect target device type, such as: `mobile` | `tablet` | `desktop`.
29
- * @returns { string }
30
- * 📤
33
+ * 📝 Detect device used from `User-Agent` data.
34
+ * @see https://discord.com/channels/457912077277855764/1067871458233159750
35
+ * @see https://discord.com/channels/457912077277855764/1067529519294070885/1067827869004341319
36
+ * @return { string }
37
+ * 📤 `device` type.
31
38
  */
32
- export function detectDeviceType
39
+ export function detectDeviceWithUA
33
40
  (
34
- ): string
41
+ ): IDeviceType
35
42
  {
36
- const
43
+ let
37
44
  /**
38
45
  * @description
46
+ * 📝 `device type`.
39
47
  */
40
- userAgentObject = navigator.userAgent.toLowerCase(),
48
+ deviceType: IDeviceType = 'mobile'
49
+ ;
50
+
51
+ const
41
52
  /**
42
53
  * @description
54
+ * 📝 `user-agent` data.
55
+ * @example
56
+ * => 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
57
+ * => [production] navigator.userAgent
43
58
  */
44
- isUserAgentMobile = userAgentObject.includes('mobile'),
59
+ userAgent = navigator.userAgent,
45
60
  /**
46
61
  * @description
62
+ * 📝 Using `ua-parser-js` module.
47
63
  */
48
- isUserAgentTablet = /tablet|ipad/.test(userAgentObject)
49
- ;
50
-
51
- let
64
+ methodRes0
65
+ // eslint-disable-next-line new-cap
66
+ = UAParser
67
+ (
68
+ userAgent
69
+ ),
52
70
  /**
53
71
  * @description
54
- * 📝 Type of device
72
+ * 📝 Using 'device-detector-js' module.
55
73
  */
56
- strDeviceType = 'desktop'
57
- ;
58
-
59
- if (isUserAgentMobile)
60
- strDeviceType = 'mobile';
61
- else if (isUserAgentTablet)
62
- strDeviceType = 'tablet';
63
- else
64
- strDeviceType = 'desktop';
74
+ methodRes1
75
+ = new DeviceDetector().parse
76
+ (
77
+ userAgent
78
+ )
65
79
  ;
66
80
 
67
81
  // [🐞]
68
82
  logger
69
83
  (
70
84
  [
71
- `🔹 [var] ➤ strDeviceType ${JSON.stringify(strDeviceType)}`,
72
- '🚏 checkpointdetectDeviceType(..) // END'
85
+ `🔹 [var] ➤ userAgent ${userAgent}`,
86
+ // `🔹 [var] methodRes0 ${JSON.stringify(methodRes0, null, 4)}`,
87
+ `🔹 [var] ➤ methodRes1 ${JSON.stringify(methodRes1, null, 4)}`,
88
+ `🔹 [var] ➤ deviceType ${deviceType}`,
89
+ '🚏 checkpoint ➤ detectDeviceWithUA(..) // END'
73
90
  ]
74
91
  );
75
92
 
76
- return strDeviceType;
93
+ // ╭─────
94
+ // │ NOTE:
95
+ // │ |: Alternative method to get device type.
96
+ // ╰─────
97
+ // deviceType = (methodRes0.device.type ?? 'mobile');
98
+
99
+ if (methodRes1.device?.type === 'smartphone')
100
+ deviceType = 'mobile';
101
+ else if (methodRes1.device?.type === 'tablet')
102
+ deviceType = 'tablet';
103
+ else
104
+ deviceType = 'desktop';
105
+ ;
106
+
107
+ return deviceType;
77
108
  }
@@ -1,5 +1,26 @@
1
+ // ╭──────────────────────────────────────────────────────────────────────────────────╮
2
+ // │ 📌 High Order Overview │
3
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
4
+ // │ ➤ Code Format // V.8.0 │
5
+ // │ ➤ Status // 🔒 LOCKED │
6
+ // │ ➤ Author(s) // @migbash │
7
+ // │ ➤ Maintainer(s) // @migbash │
8
+ // │ ➤ Created on // <date-created> │
9
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
10
+ // │ 📝 Description │
11
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
12
+ // │ BETARENA (Module)
13
+ // │ |: Geo Location Logic
14
+ // ╰──────────────────────────────────────────────────────────────────────────────────╯
15
+
16
+ // #region ➤ 📦 Package Imports
17
+
18
+ import { logger } from './debug.js';
19
+
1
20
  import type { GeoJsResponse } from '../types/geojs.js';
2
21
 
22
+ // #endregion ➤ 📦 Package Imports
23
+
3
24
  /**
4
25
  * @author
5
26
  * @migbash
@@ -7,7 +28,8 @@ import type { GeoJsResponse } from '../types/geojs.js';
7
28
  * 🟥 MAIN
8
29
  * @description
9
30
  * 📝 Detect user `geo-location`.
10
- * @returns { Promise <void> }
31
+ * @return { Promise < GeoJsResponse > }
32
+ * 📤 `geo-location` data.
11
33
  */
12
34
  export async function getUserLocation
13
35
  (
@@ -18,17 +40,29 @@ export async function getUserLocation
18
40
  * @description
19
41
  * 📝 Response from `fetch`
20
42
  */
21
- response = await fetch
22
- (
23
- 'https://get.geojs.io/v1/ip/geo.json',
24
- {
25
- method: 'GET'
26
- }
27
- )
43
+ dataRes0
44
+ = await fetch
45
+ (
46
+ 'https://get.geojs.io/v1/ip/geo.json',
47
+ {
48
+ method: 'GET'
49
+ }
50
+ ),
51
+ /**
52
+ * @description
53
+ * 📝 Response from `fetch`
54
+ */
55
+ dataRes1 = await dataRes0.json()
28
56
  ;
29
57
 
30
58
  // [🐞]
31
- // console.log('geoLocation', geoLocation);
59
+ logger
60
+ (
61
+ [
62
+ `🔹 [var] ➤ dataRes0 :: ${JSON.stringify(dataRes1, null, 4)}`,
63
+ '🚏 checkpoint ➤ getUserLocation(..) // END'
64
+ ]
65
+ );
32
66
 
33
- return await response.json();
67
+ return dataRes1;
34
68
  }