@betarena/ad-engine 0.0.58 → 0.0.60

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.58",
3
+ "version": "0.0.60",
4
4
  "private": false,
5
5
  "description": "Betarena ad-engine widget",
6
6
  "keywords": [
@@ -53,7 +53,6 @@
53
53
  "eslint": "8.51.0",
54
54
  "eslint-config-prettier": "8.8.0",
55
55
  "eslint-plugin-svelte": "2.34.0",
56
- "json5": "2.2.3",
57
56
  "sass": "1.72.0",
58
57
  "svelte": "4.2.12",
59
58
  "svelte-check": "3.6.6",
@@ -64,6 +63,7 @@
64
63
  "dependencies": {
65
64
  "@betarena/scores-lib": "1.11.0-alpha.17",
66
65
  "@fontsource/roboto": "5.0.12",
66
+ "colorthief": "2.6.0",
67
67
  "svelte-preprocess": "5.1.3"
68
68
  },
69
69
  "main": "./dist/index.js",
@@ -43,6 +43,7 @@
43
43
  import { betarenaEndpoint } from './constants/instance.js';
44
44
  import { storeAdmin } from './store/admin.js';
45
45
  import { postMod } from './utils/fetch.js';
46
+ import { getImageBgColor } from './utils/npm.colorthief.js';
46
47
 
47
48
  import type { AdsCreativeMain } from '@betarena/scores-lib/types/_AUTO-HASURA_.js';
48
49
 
@@ -198,6 +199,12 @@
198
199
  (
199
200
  () =>
200
201
  {
202
+ getImageBgColor
203
+ (
204
+ objectAdverData.data?.media ?? '',
205
+ '--betarena-ad-engine-interscroller-advert-background-image-'
206
+ );
207
+
201
208
  injectBetarenaInterscrollerAd();
202
209
 
203
210
  storeAdmin.updateData
@@ -237,6 +244,7 @@
237
244
  right: 0px;
238
245
  width: 100vw;
239
246
  max-width: 100vw;
247
+ background-color: var(--betarena-ad-engine-interscroller-advert-background-image-);
240
248
  "
241
249
  >
242
250
  <h2 class="info-box">
@@ -263,40 +271,33 @@
263
271
  text-align: center;
264
272
  "
265
273
  >
266
- <div
267
- style=
268
- "
269
- margin: 0px auto;
270
- width: 100%;
271
- height: 100%;
272
- "
273
- >
274
- <a
275
- target="_blank"
276
- on:click=
274
+ <a
275
+ target="_blank"
276
+ on:click=
277
+ {
278
+ () =>
277
279
  {
278
- () =>
279
- {
280
- postMod
281
- (
282
- `${betarenaEndpoint}/ad/update/click`,
283
- {
284
- creativeId: objectAdverData.id
285
- }
286
- );
287
- }
280
+ postMod
281
+ (
282
+ `${betarenaEndpoint}/ad/update/click`,
283
+ {
284
+ creativeId: objectAdverData.id
285
+ }
286
+ );
288
287
  }
289
- href={objectAdverData.data?.cta_link}
290
- >
291
- <img
292
- alt="ad_image"
293
- class="ad_image"
294
- src={objectAdverData.data?.media}
295
- width="100%"
296
- height="100%"
297
- />
298
- </a>
299
- </div>
288
+ }
289
+ href={objectAdverData.data?.cta_link}
290
+ >
291
+ <div
292
+ style=
293
+ "
294
+ height: 100vh;
295
+ width: 100vw;
296
+ background-repeat: no-repeat;
297
+ background-size: contain;
298
+ "
299
+ />
300
+ </a>
300
301
  </div>
301
302
  </div>
302
303
 
@@ -323,59 +324,67 @@
323
324
  ╰──────────────────────────────────────────────────────────────────────────────╯
324
325
  */
325
326
 
326
- .info-box
327
- {
328
- color: var(--colors-text-text-primary-900, #fbfbfb);
329
- text-align: center;
330
- font-family: Roboto;
331
- font-size: 12px !important;
332
- font-style: normal;
333
- font-weight: 700 !important;
334
- line-height: 38px !important; /* 190% */
335
- text-transform: uppercase;
336
- width: 100%;
337
- margin: 0 !important;
338
- z-index: 1;
339
- background: var(--colors-background-bg-secondary, #313131);
340
- }
341
-
342
327
  .interscroller-wrapper
343
328
  {
329
+ /* 📌 position */
344
330
  position: relative !important;
345
331
  cursor: pointer !important;
346
- background: #ffffff !important;
347
332
  z-index: 10000000 !important;
333
+ /* 🛝 layout */
348
334
  flex-direction: column;
349
335
  justify-content: space-between;
350
- }
351
336
 
352
- .interscroller-bg-wrapper
353
- {
354
- position: absolute !important;
355
- width: 100% !important;
356
- left: 0 !important;
357
- }
358
-
359
- .interscroller-bg
360
- {
361
- position: fixed !important;
362
- height: 100% !important;
363
- top: 0;
364
- backface-visibility: hidden !important;
365
- -webkit-backface-visibility: hidden !important;
366
- border: 0 !important;
367
- }
337
+ .info-box
338
+ {
339
+ /* 📌 position */
340
+ z-index: 1;
341
+ /* 🎨 style */
342
+ color: var(--colors-text-text-primary-900, #fbfbfb);
343
+ text-align: center;
344
+ font-family: Roboto;
345
+ font-size: 12px !important;
346
+ font-style: normal;
347
+ font-weight: 700 !important;
348
+ line-height: 38px !important; /* 190% */
349
+ text-transform: uppercase;
350
+ width: 100%;
351
+ margin: 0 !important;
352
+ background: var(--colors-background-bg-secondary, #313131);
353
+ }
368
354
 
369
- .ad_image
370
- {
371
- width: 100% !important;
372
- height: 100% !important;
373
- max-width: 100vw !important;
374
- max-height: 100% !important;
375
- touch-action: manipulation;
376
- user-select: none;
377
- -webkit-user-drag: none;
378
- -webkit-touch-callout: none;
355
+ .interscroller-bg-wrapper
356
+ {
357
+ /* 📌 position */
358
+ position: absolute !important;
359
+ left: 0 !important;
360
+ /* 🎨 style */
361
+ width: 100% !important;
362
+
363
+ .interscroller-bg
364
+ {
365
+ /* 📌 position */
366
+ position: fixed !important;
367
+ top: 30px;
368
+ /* 🎨 style */
369
+ height: 100% !important;
370
+ backface-visibility: hidden !important;
371
+ -webkit-backface-visibility: hidden !important;
372
+ border: 0 !important;
373
+ }
374
+
375
+ .ad_image
376
+ {
377
+ /* 🎨 style */
378
+ width: 100% !important;
379
+ height: 100% !important;
380
+ max-width: 100vw !important;
381
+ max-height: 100% !important;
382
+ touch-action: manipulation;
383
+ user-select: none;
384
+ -webkit-user-drag: none;
385
+ -webkit-touch-callout: none;
386
+ }
387
+ }
379
388
  }
380
389
 
381
390
  /*
@@ -0,0 +1,160 @@
1
+ // ╭──────────────────────────────────────────────────────────────────────────────────╮
2
+ // │ 📌 High Order Component Overview │
3
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
4
+ // │ ➤ Internal Svelte Code Format :|: V.8.0 │
5
+ // │ ➤ Status :|: 🔒 LOCKED │
6
+ // │ ➤ Author(s) :|: @migbash │
7
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
8
+ // │ 📝 Description │
9
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
10
+ // │ Main Scores Color Thief Logic │
11
+ // ╰──────────────────────────────────────────────────────────────────────────────────╯
12
+
13
+ // #region ➤ 📦 Package Imports
14
+
15
+ // @ts-expect-error :: 📌 Importing the colorthief package for Types Is missing.
16
+ import ColorThief from 'colorthief/dist/color-thief.mjs';
17
+
18
+ // #endregion ➤ 📦 Package Imports
19
+
20
+ const colorThief = new ColorThief();
21
+
22
+ /**
23
+ * @author
24
+ * @migbash
25
+ * @summary
26
+ * 🟦 HELPER
27
+ * @description
28
+ * 📝 Convert RGB to Hexidecimal
29
+ * @param { number } r
30
+ * ❗️ **REQUIRED** : Red Value
31
+ * @param { number } g
32
+ * ❗️ **REQUIRED** : Green Value
33
+ * @param { number } b
34
+ * ❗️ **REQUIRED** : Blue Value
35
+ * @return { string }
36
+ * 📤 Hexidecimal Value for target RGB input.
37
+ */
38
+ export const rgbToHex = (
39
+ r: number,
40
+ g: number,
41
+ b: number
42
+ ): string =>
43
+ {
44
+ return '#' + [r, g, b]
45
+ .map
46
+ (
47
+ (
48
+ x
49
+ ) =>
50
+ {
51
+ const
52
+ /**
53
+ * @description
54
+ * 📝 Convert the number to HEX
55
+ */
56
+ hex = x.toString(16)
57
+ ;
58
+ return hex.length === 1
59
+ ? `0${hex}`
60
+ : hex
61
+ ;
62
+ }
63
+ )
64
+ .join('')
65
+ ;
66
+ }
67
+
68
+ /**
69
+ * @author
70
+ * @migbash
71
+ * @summary
72
+ * 🟦 HELPER
73
+ * @description
74
+ * 📝 Get the image background color
75
+ * @param { string } strImageUrl
76
+ * ❗️ **REQUIRED** : The image URL
77
+ * @param { string } strImageColorVariable
78
+ * ❗️ **REQUIRED** : The image variable
79
+ * @return { void }
80
+ */
81
+ export function getImageBgColor
82
+ (
83
+ strImageUrl: string,
84
+ strImageColorVariable: string
85
+ ): void
86
+ {
87
+ if (!strImageUrl) return;
88
+
89
+ try
90
+ {
91
+ const
92
+ /**
93
+ * @description
94
+ * 📝 Create a new image instance
95
+ */
96
+ img = new Image()
97
+ ;
98
+
99
+ // ╭─────
100
+ // │ NOTE:
101
+ // │ |: Listen, event to wait for the image to load
102
+ // ╰─────
103
+ img.addEventListener
104
+ (
105
+ 'load',
106
+ () =>
107
+ {
108
+ const
109
+ /**
110
+ * @description
111
+ * 📝 Get the color values from the image
112
+ */
113
+ colorValues
114
+ = colorThief.getColor(img) as [number, number, number],
115
+ /**
116
+ * @description
117
+ * 📝 Convert the color values to HEX
118
+ */
119
+ hexColor
120
+ = rgbToHex
121
+ (
122
+ colorValues[0],
123
+ colorValues[1],
124
+ colorValues[2]
125
+ ),
126
+ /**
127
+ * @description
128
+ * 📝 Pass this values as a `CSS :root` variable, accessible to all the website,
129
+ */
130
+ doc = document.documentElement
131
+ ;
132
+
133
+ doc.style.setProperty
134
+ (
135
+ strImageColorVariable,
136
+ hexColor
137
+ );
138
+ }
139
+ );
140
+
141
+ const
142
+ // [ℹ] declaring the image paramaters & CORS by-pass
143
+ imageURL = 'https://corsproxy.io/?' + encodeURIComponent(strImageUrl)
144
+ ;
145
+
146
+ img.crossOrigin = 'anonymous';
147
+ img.src = imageURL;
148
+ }
149
+ catch (e)
150
+ {
151
+ // eslint-disable-next-line no-console
152
+ console.error
153
+ (
154
+ '-- getImageBgColor() ERR --',
155
+ e
156
+ );
157
+ }
158
+
159
+ return;
160
+ }