@everymatrix/general-preview-social-posts 1.16.1

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 (47) hide show
  1. package/dist/cjs/general-preview-social-posts.cjs.entry.js +349 -0
  2. package/dist/cjs/general-preview-social-posts.cjs.js +19 -0
  3. package/dist/cjs/index-e178764e.js +1223 -0
  4. package/dist/cjs/index.cjs.js +2 -0
  5. package/dist/cjs/loader.cjs.js +21 -0
  6. package/dist/collection/collection-manifest.json +12 -0
  7. package/dist/collection/components/general-preview-social-posts/general-preview-social-posts.css +114 -0
  8. package/dist/collection/components/general-preview-social-posts/general-preview-social-posts.js +578 -0
  9. package/dist/collection/index.js +1 -0
  10. package/dist/collection/utils/locale.utils.js +60 -0
  11. package/dist/collection/utils/utils.js +39 -0
  12. package/dist/components/general-preview-social-posts.d.ts +11 -0
  13. package/dist/components/general-preview-social-posts.js +384 -0
  14. package/dist/components/index.d.ts +26 -0
  15. package/dist/components/index.js +1 -0
  16. package/dist/esm/general-preview-social-posts.entry.js +345 -0
  17. package/dist/esm/general-preview-social-posts.js +17 -0
  18. package/dist/esm/index-8a671ab9.js +1197 -0
  19. package/dist/esm/index.js +1 -0
  20. package/dist/esm/loader.js +17 -0
  21. package/dist/esm/polyfills/core-js.js +11 -0
  22. package/dist/esm/polyfills/css-shim.js +1 -0
  23. package/dist/esm/polyfills/dom.js +79 -0
  24. package/dist/esm/polyfills/es5-html-element.js +1 -0
  25. package/dist/esm/polyfills/index.js +34 -0
  26. package/dist/esm/polyfills/system.js +6 -0
  27. package/dist/general-preview-social-posts/general-preview-social-posts.esm.js +1 -0
  28. package/dist/general-preview-social-posts/index.esm.js +0 -0
  29. package/dist/general-preview-social-posts/p-b79fd2fe.entry.js +1 -0
  30. package/dist/general-preview-social-posts/p-c682801c.js +1 -0
  31. package/dist/index.cjs.js +1 -0
  32. package/dist/index.js +1 -0
  33. package/dist/stencil.config.js +22 -0
  34. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-stencil/packages/general-preview-social-posts/.stencil/packages/general-preview-social-posts/stencil.config.d.ts +2 -0
  35. package/dist/types/components/general-preview-social-posts/general-preview-social-posts.d.ts +84 -0
  36. package/dist/types/components.d.ts +152 -0
  37. package/dist/types/index.d.ts +1 -0
  38. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  39. package/dist/types/utils/locale.utils.d.ts +2 -0
  40. package/dist/types/utils/utils.d.ts +9 -0
  41. package/loader/cdn.js +3 -0
  42. package/loader/index.cjs.js +3 -0
  43. package/loader/index.d.ts +12 -0
  44. package/loader/index.es2017.js +3 -0
  45. package/loader/index.js +4 -0
  46. package/loader/package.json +10 -0
  47. package/package.json +19 -0
@@ -0,0 +1,384 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
+
3
+ const DEFAULT_LANGUAGE = 'en';
4
+ const SUPPORTED_LANGUAGES = ['de', 'en'];
5
+ let TRANSLATIONS = {
6
+ en: {
7
+ loading: 'loading...',
8
+ viewAll: 'View All ...',
9
+ moreInfo: 'MORE INFO',
10
+ playNow: 'PLAY NOW',
11
+ },
12
+ de: {
13
+ loading: 'loading...',
14
+ viewAll: 'View All ...',
15
+ moreInfo: 'MORE INFO',
16
+ playNow: 'PLAY NOW',
17
+ },
18
+ ro: {
19
+ loading: 'loading...',
20
+ viewAll: 'View All ...',
21
+ moreInfo: 'MORE INFO',
22
+ playNow: 'PLAY NOW',
23
+ },
24
+ fr: {
25
+ loading: 'loading...',
26
+ viewAll: 'View All ...',
27
+ moreInfo: 'MORE INFO',
28
+ playNow: 'PLAY NOW',
29
+ },
30
+ ar: {
31
+ loading: 'loading...',
32
+ viewAll: 'View All ...',
33
+ moreInfo: 'MORE INFO',
34
+ playNow: 'PLAY NOW',
35
+ }
36
+ };
37
+ const getTranslations = (url) => {
38
+ // fetch url, get the data, replace the TRANSLATIONS content
39
+ return new Promise((resolve) => {
40
+ fetch(url)
41
+ .then((res) => res.json())
42
+ .then((data) => {
43
+ Object.keys(data).forEach((item) => {
44
+ for (let key in data[item]) {
45
+ TRANSLATIONS[item][key] = data[item][key];
46
+ }
47
+ });
48
+ resolve(true);
49
+ });
50
+ });
51
+ };
52
+ const translate = (key, customLang, values) => {
53
+ const lang = customLang;
54
+ let translation = TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
55
+ if (values !== undefined) {
56
+ for (const [key, value] of Object.entries(values.values)) {
57
+ const regex = new RegExp(`{${key}}`, 'g');
58
+ translation = translation.replace(regex, value);
59
+ }
60
+ }
61
+ return translation;
62
+ };
63
+
64
+ /**
65
+ * @name isMobile
66
+ * @description A method that returns if the browser used to access the app is from a mobile device or not
67
+ * @param {String} userAgent window.navigator.userAgent
68
+ * @returns {Boolean} true or false
69
+ */
70
+ const getDevice = () => {
71
+ let userAgent = window.navigator.userAgent;
72
+ if (userAgent.toLowerCase().match(/android/i)) {
73
+ return 'Android';
74
+ }
75
+ if (userAgent.toLowerCase().match(/iphone/i)) {
76
+ return 'iPhone';
77
+ }
78
+ if (userAgent.toLowerCase().match(/ipad|ipod/i)) {
79
+ return 'iPad';
80
+ }
81
+ return 'PC';
82
+ };
83
+ const getDevicePlatform = () => {
84
+ const device = getDevice();
85
+ if (device) {
86
+ if (device === 'PC') {
87
+ return 'dk';
88
+ }
89
+ else if (device === 'iPad' || device === 'iPhone') {
90
+ return 'mtWeb';
91
+ }
92
+ else {
93
+ return 'mtWeb';
94
+ }
95
+ }
96
+ };
97
+
98
+ const generalPreviewSocialPostsCss = ":host {\n font-family: \"Roboto\", sans-serif;\n display: block;\n}\n\n.ModalContainer {\n container-type: inline-size;\n}\n\n.sliderWidget {\n display: block;\n max-width: 780px;\n margin: 0 auto;\n padding: 16px;\n max-height: 500px;\n}\n.sliderWidget h2 {\n font-size: 20px;\n}\n.sliderWidget .headerHontainer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n}\n.sliderWidget .headerHontainer .viewAllButton {\n cursor: pointer;\n font-weight: bold;\n color: #8e8e8e;\n}\n.sliderWidget .postSlider {\n display: flex;\n overflow-x: auto;\n scroll-snap-type: x mandatory;\n gap: 24px;\n}\n.sliderWidget .postSlider .postCard {\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n scroll-snap-align: start;\n padding: 20px;\n border-radius: 6px;\n min-width: 360px;\n background-color: #f4f4f4;\n}\n.sliderWidget .postSlider .postCard .Description {\n display: -webkit-box;\n -webkit-line-clamp: 5;\n -webkit-box-orient: vertical;\n overflow: hidden;\n margin-bottom: 14px;\n}\n.sliderWidget .postSlider .postCard .imageTitle {\n display: flex;\n justify-content: flex-start;\n gap: 20px;\n}\n.sliderWidget .postSlider .postCard .imageTitle img {\n height: 120px;\n width: 120px;\n border-radius: 6px;\n}\n.sliderWidget .postSlider .postCard .imageTitle .titleSubtitle {\n display: flex;\n flex-direction: column;\n}\n.sliderWidget .postSlider .postCard .buttons {\n display: flex;\n justify-content: center;\n gap: 12px;\n}\n.sliderWidget .postSlider .postCard .buttons .moreInfoButton, .sliderWidget .postSlider .postCard .buttons .playNowButton {\n width: 172px;\n display: block;\n padding: 8px 16px;\n border: 3px solid #63B250;\n border-radius: 6px;\n cursor: pointer;\n font-weight: bold;\n}\n.sliderWidget .postSlider .postCard .buttons .moreInfoButton {\n background-color: #f4f4f4;\n color: #63B250;\n}\n.sliderWidget .postSlider .postCard .buttons .playNowButton {\n background-color: #63B250;\n color: #fff;\n}\n\nh3, h4 {\n font-size: 18px;\n}\n\np {\n font-size: 14px;\n color: #5b5b5b;\n}\n\n@container (max-width: 480px) {\n .sliderWidget h2 {\n font-size: 18px;\n }\n .sliderWidget .postSlider .postCard {\n min-width: 250px;\n }\n\n h3, h4 {\n font-size: 16px;\n }\n\n p {\n font-size: 12px;\n }\n}";
99
+
100
+ const SocialSlider = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
101
+ constructor() {
102
+ super();
103
+ this.__registerHost();
104
+ this.__attachShadow();
105
+ this.moreInfo = createEvent(this, "moreInfo", 7);
106
+ this.playNow = createEvent(this, "playNow", 7);
107
+ this.viewAll = createEvent(this, "viewAll", 7);
108
+ /**
109
+ * The userId
110
+ */
111
+ this.userId = '';
112
+ /**
113
+ * The session
114
+ */
115
+ this.session = '';
116
+ /**
117
+ * The Posts Title
118
+ */
119
+ this.postsTitle = '';
120
+ /**
121
+ * The max cards displayed
122
+ */
123
+ this.maxCards = '';
124
+ /**
125
+ * The language
126
+ */
127
+ this.language = 'en';
128
+ /**
129
+ * The datasource
130
+ */
131
+ this.datasource = '';
132
+ /**
133
+ * The NorWAy endpoint
134
+ */
135
+ this.endpoint = '';
136
+ /**
137
+ * The NorWAy endpoint
138
+ */
139
+ this.cmsEndpoint = '';
140
+ /**
141
+ * The userRoles
142
+ */
143
+ this.userRoles = '';
144
+ /**
145
+ * The translationurl
146
+ */
147
+ this.translationUrl = '';
148
+ /**
149
+ * Client custom styling via string
150
+ */
151
+ this.clientStyling = '';
152
+ /**
153
+ * Client custom styling via url content
154
+ */
155
+ this.clientStylingUrl = '';
156
+ /**
157
+ * CMS Endpoint stage
158
+ */
159
+ this.cmsEnv = 'stage';
160
+ /**
161
+ * The page parameter for the cms call
162
+ */
163
+ this.pageName = 'casino';
164
+ this.posts = []; // State to store fetched posts
165
+ this.stylingAppends = false;
166
+ this.isLoading = false;
167
+ this.isLoggedIn = false;
168
+ this.dataImages = []; // State to store fetched images
169
+ this.gameIds = ''; // State to store fetched images
170
+ this.platform = getDevicePlatform();
171
+ this.setClientStyling = () => {
172
+ let sheet = document.createElement('style');
173
+ sheet.innerHTML = this.clientStyling;
174
+ this.stylingContainer.prepend(sheet);
175
+ };
176
+ this.setClientStylingURL = () => {
177
+ let url = new URL(this.clientStylingUrl);
178
+ let cssFile = document.createElement('style');
179
+ fetch(url.href)
180
+ .then((res) => res.text())
181
+ .then((data) => {
182
+ cssFile.innerHTML = data;
183
+ setTimeout(() => { this.stylingContainer.prepend(cssFile); }, 1);
184
+ })
185
+ .catch((err) => {
186
+ console.log('error ', err);
187
+ });
188
+ };
189
+ }
190
+ handleNewTranslations() {
191
+ this.isLoading = true;
192
+ getTranslations(this.translationUrl).then(() => {
193
+ this.isLoading = false;
194
+ });
195
+ }
196
+ async componentWillLoad() {
197
+ if (this.translationUrl.length > 2) {
198
+ await getTranslations(this.translationUrl);
199
+ }
200
+ }
201
+ watchSession(newValue, oldValue) {
202
+ if (newValue !== oldValue) {
203
+ this.isLoggedIn = newValue !== '';
204
+ }
205
+ }
206
+ connectedCallback() {
207
+ if (this.session) {
208
+ this.isLoggedIn = true;
209
+ }
210
+ }
211
+ componentDidRender() {
212
+ // start custom styling area
213
+ if (!this.stylingAppends && this.stylingContainer) {
214
+ if (this.clientStyling)
215
+ this.setClientStyling();
216
+ if (this.clientStylingUrl)
217
+ this.setClientStylingURL();
218
+ this.stylingAppends = true;
219
+ }
220
+ // end custom styling area
221
+ }
222
+ getDataImage(ids) {
223
+ try {
224
+ let url = new URL(`${this.endpoint}/v2/casino/groups/${this.datasource}`);
225
+ url.searchParams.append("language", this.language);
226
+ url.searchParams.append("expand", 'games');
227
+ url.searchParams.append("fields", 'games(id,thumbnail,launchUrl)');
228
+ url.searchParams.append("filter", ids);
229
+ url.searchParams.append('device', this.platform);
230
+ const options = {
231
+ 'method': 'GET',
232
+ 'Content-Type': 'application/json'
233
+ };
234
+ fetch(url.href, options)
235
+ .then((res) => {
236
+ if (res.status === 200) {
237
+ return res.json();
238
+ }
239
+ else {
240
+ throw new Error("HTTP status " + res.status);
241
+ }
242
+ })
243
+ .then((data) => {
244
+ data.items.forEach((item) => {
245
+ item.games.items.forEach(element => {
246
+ let { id, launchUrl, thumbnail } = element;
247
+ this.dataImages = [{ id, launchUrl, thumbnail }];
248
+ let index = this.posts.findIndex(post => post.gameId === id);
249
+ if (index !== -1) {
250
+ this.posts[index].images = this.dataImages;
251
+ }
252
+ });
253
+ });
254
+ })
255
+ .catch((err) => {
256
+ // Handle any errors
257
+ console.error(err);
258
+ });
259
+ }
260
+ catch (error) {
261
+ console.error('Error fetching verification types:', error);
262
+ }
263
+ }
264
+ async componentDidLoad() {
265
+ try {
266
+ let url = new URL(`${this.cmsEndpoint}/${this.language}/content/social-posts`);
267
+ url.searchParams.append("device", this.platform);
268
+ url.searchParams.append("page", this.pageName);
269
+ url.searchParams.append("language", this.language);
270
+ url.searchParams.append("userRoles", this.userRoles);
271
+ url.searchParams.append('env', this.cmsEnv);
272
+ const options = {
273
+ 'method': 'GET',
274
+ 'Content-Type': 'application/json'
275
+ };
276
+ fetch(url.href, options)
277
+ .then((res) => {
278
+ if (res.status === 200) {
279
+ return res.json();
280
+ }
281
+ else {
282
+ throw new Error("HTTP status " + res.status);
283
+ }
284
+ })
285
+ .then((data) => {
286
+ data.forEach(element => {
287
+ var _a;
288
+ const { gameId, title, description, subtitle } = (_a = element.previewCard) !== null && _a !== void 0 ? _a : {};
289
+ if (gameId) {
290
+ this.gameIds += `games(id=${gameId}),`;
291
+ }
292
+ this.posts.push({ gameId, title, description, subtitle });
293
+ });
294
+ if (this.gameIds.length > 0) {
295
+ this.gameIds = this.gameIds.slice(0, -1); // Removes the last comma
296
+ this.gameIds = '$or(' + this.gameIds + ')';
297
+ }
298
+ this.getDataImage(this.gameIds);
299
+ })
300
+ .catch((err) => {
301
+ // Handle any errors
302
+ console.error(err);
303
+ });
304
+ }
305
+ catch (error) {
306
+ console.error('Error fetching verification types:', error);
307
+ }
308
+ }
309
+ hasUndefinedValues(obj) {
310
+ return Object.values(obj).some((value) => value === undefined);
311
+ }
312
+ render() {
313
+ if (this.isLoading) {
314
+ return (h("div", null, h("p", null, translate('loading', this.language))));
315
+ }
316
+ else {
317
+ return (h("div", { class: "ModalContainer", ref: el => this.stylingContainer = el }, h("div", { class: "sliderWidget" }, h("div", { class: "headerHontainer" }, this.postsTitle && h("h2", null, this.postsTitle), h("div", { class: "viewAllButton", onClick: () => this.onViewAllClick() }, translate('viewAll', this.language))), h("div", { class: "postSlider" }, this.posts
318
+ .filter((post) => !this.hasUndefinedValues(post)) // Filter out posts with undefined values
319
+ .slice(0, +(this.maxCards || this.posts.length))
320
+ .map((post) => {
321
+ var _a, _b, _c, _d;
322
+ return (h("div", { class: "postCard" }, h("div", { class: "imageTitle" }, (post === null || post === void 0 ? void 0 : post.images) ? (h("a", { href: ((_b = (_a = post.images) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.launchUrl) || '', target: "_blank", rel: "noopener noreferrer" }, h("img", { src: ((_d = (_c = post.images) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.thumbnail) || '', alt: "Game Image" })))
323
+ : null, h("div", { class: "titleSubtitle" }, post.title && h("h3", null, post.title), post.subtitle && h("p", { innerHTML: post.subtitle }))), post.description &&
324
+ h("div", { class: "Description" }, h("p", { innerHTML: post.description })), h("div", { class: "buttons" }, h("button", { class: "moreInfoButton", onClick: () => this.onMoreInfoClick() }, translate('moreInfo', this.language)), this.isLoggedIn && post.gameId && h("button", { class: "playNowButton", onClick: () => this.onPlayNowClick(post.gameId) }, translate('playNow', this.language)))));
325
+ })))));
326
+ }
327
+ }
328
+ onViewAllClick() {
329
+ this.viewAll.emit();
330
+ window.postMessage({ type: 'viewAllSocialPosts' }, window.location.href);
331
+ }
332
+ onMoreInfoClick() {
333
+ this.moreInfo.emit();
334
+ window.postMessage({ type: 'moreInfoSocialPost' }, window.location.href);
335
+ }
336
+ onPlayNowClick(gameId) {
337
+ this.playNow.emit(gameId);
338
+ window.postMessage({ type: 'playNowSocialPost', gameId: gameId }, window.location.href);
339
+ }
340
+ static get watchers() { return {
341
+ "translationUrl": ["handleNewTranslations"],
342
+ "session": ["watchSession"]
343
+ }; }
344
+ static get style() { return generalPreviewSocialPostsCss; }
345
+ }, [1, "general-preview-social-posts", {
346
+ "userId": [513, "user-id"],
347
+ "session": [513],
348
+ "postsTitle": [513, "posts-title"],
349
+ "maxCards": [513, "max-cards"],
350
+ "language": [513],
351
+ "datasource": [513],
352
+ "endpoint": [513],
353
+ "cmsEndpoint": [513, "cms-endpoint"],
354
+ "userRoles": [513, "user-roles"],
355
+ "translationUrl": [513, "translation-url"],
356
+ "clientStyling": [513, "client-styling"],
357
+ "clientStylingUrl": [513, "client-styling-url"],
358
+ "cmsEnv": [513, "cms-env"],
359
+ "pageName": [513, "page-name"],
360
+ "posts": [32],
361
+ "stylingAppends": [32],
362
+ "isLoading": [32],
363
+ "isLoggedIn": [32],
364
+ "dataImages": [32],
365
+ "gameIds": [32]
366
+ }]);
367
+ function defineCustomElement$1() {
368
+ if (typeof customElements === "undefined") {
369
+ return;
370
+ }
371
+ const components = ["general-preview-social-posts"];
372
+ components.forEach(tagName => { switch (tagName) {
373
+ case "general-preview-social-posts":
374
+ if (!customElements.get(tagName)) {
375
+ customElements.define(tagName, SocialSlider);
376
+ }
377
+ break;
378
+ } });
379
+ }
380
+
381
+ const GeneralPreviewSocialPosts = SocialSlider;
382
+ const defineCustomElement = defineCustomElement$1;
383
+
384
+ export { GeneralPreviewSocialPosts, defineCustomElement };
@@ -0,0 +1,26 @@
1
+ /* GeneralPreviewSocialPosts custom elements */
2
+
3
+ import type { Components, JSX } from "../types/components";
4
+
5
+ /**
6
+ * Used to manually set the base path where assets can be found.
7
+ * If the script is used as "module", it's recommended to use "import.meta.url",
8
+ * such as "setAssetPath(import.meta.url)". Other options include
9
+ * "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to
10
+ * dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".
11
+ * But do note that this configuration depends on how your script is bundled, or lack of
12
+ * bundling, and where your assets can be loaded from. Additionally custom bundling
13
+ * will have to ensure the static assets are copied to its build directory.
14
+ */
15
+ export declare const setAssetPath: (path: string) => void;
16
+
17
+ export interface SetPlatformOptions {
18
+ raf?: (c: FrameRequestCallback) => number;
19
+ ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
20
+ rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
21
+ }
22
+ export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;
23
+
24
+ export type { Components, JSX };
25
+
26
+ export * from '../types';
@@ -0,0 +1 @@
1
+ export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client';