@splash-tech/jackpot-sdk 1.1.6 → 2.0.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.
@@ -1,16 +1,14 @@
1
- import { IframeOutgoingEvent, SDKMode, WidgetEventHandler, WidgetParams } from './shared/types';
2
- interface ChildMessage {
3
- type: IframeOutgoingEvent;
4
- data: unknown;
5
- jackpotId?: string | null;
6
- tag?: string | null;
7
- brand?: string | null;
8
- }
1
+ import { FooterWidgetParams } from './footerWidget/types/data';
2
+ import { ChildMessage, SDKMode, WidgetEventHandler, WidgetParams } from './shared/types';
3
+ import { WinWidgetParams } from './winWidget/types/data';
9
4
  export declare abstract class BaseWidget {
10
5
  protected iframe: HTMLIFrameElement | null;
11
6
  protected childAppOrigin: string | null;
12
7
  protected isLaunched: boolean;
13
8
  protected data: unknown;
9
+ protected position: FooterWidgetParams['position'];
10
+ protected maxWidth: string;
11
+ protected animation: WinWidgetParams['animation'];
14
12
  protected jackpotId: string | null;
15
13
  protected tag: string | null;
16
14
  protected brand: string | null;
@@ -28,4 +26,3 @@ export declare abstract class BaseWidget {
28
26
  protected emit(event: string): void;
29
27
  protected removeAllEventListeners(): void;
30
28
  }
31
- export {};
@@ -3,6 +3,9 @@ export class BaseWidget {
3
3
  this.iframe = null;
4
4
  this.childAppOrigin = null;
5
5
  this.isLaunched = false;
6
+ this.position = 'bottom';
7
+ this.maxWidth = '1300px';
8
+ this.animation = 'wheel';
6
9
  this.jackpotId = null;
7
10
  this.tag = null;
8
11
  this.brand = null;
@@ -51,12 +54,15 @@ export class BaseWidget {
51
54
  this.isLaunched = false;
52
55
  }
53
56
  setParamsData(params) {
54
- const { mode, data, jackpotId, tag, brand } = params;
57
+ const { mode, data, jackpotId, tag, brand, position, animation, maxWidth } = params;
55
58
  this.childAppOrigin = this.getBaseUrl(mode !== null && mode !== void 0 ? mode : 'production');
56
59
  this.data = data;
57
60
  this.jackpotId = jackpotId !== null && jackpotId !== void 0 ? jackpotId : null;
58
61
  this.tag = tag !== null && tag !== void 0 ? tag : null;
59
62
  this.brand = brand !== null && brand !== void 0 ? brand : null;
63
+ this.position = position !== null && position !== void 0 ? position : this.position;
64
+ this.animation = animation !== null && animation !== void 0 ? animation : this.animation;
65
+ this.maxWidth = maxWidth !== null && maxWidth !== void 0 ? maxWidth : this.maxWidth;
60
66
  }
61
67
  setLaunched(launched) {
62
68
  this.isLaunched = launched;
@@ -69,9 +75,10 @@ export class BaseWidget {
69
75
  if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
70
76
  this.childAppOrigin &&
71
77
  message.data !== undefined) {
78
+ const { data, jackpotId, tag, brand, position, maxWidth } = message;
72
79
  this.iframe.contentWindow.postMessage({
73
80
  type: message.type,
74
- payload: message.data,
81
+ payload: { data, jackpotId, tag, brand, position, maxWidth },
75
82
  }, this.childAppOrigin);
76
83
  }
77
84
  }
@@ -6,6 +6,7 @@ export declare class FooterWidget extends BaseWidget {
6
6
  static getInstance(): FooterWidget;
7
7
  private childMessageHandler;
8
8
  launch(params: FooterWidgetParams): void;
9
+ private setIframeStyles;
9
10
  updateData(partialData: unknown): void;
10
11
  private validateNonEmptyObject;
11
12
  private showPopup;
@@ -18,6 +18,8 @@ export class FooterWidget extends BaseWidget {
18
18
  jackpotId: this.jackpotId,
19
19
  tag: this.tag,
20
20
  brand: this.brand,
21
+ position: this.position,
22
+ maxWidth: this.maxWidth,
21
23
  });
22
24
  break;
23
25
  case FooterIframeIncomingEvent.showPopup: {
@@ -50,16 +52,25 @@ export class FooterWidget extends BaseWidget {
50
52
  }
51
53
  this.setParamsData(params);
52
54
  this.iframe = this.createIframe();
53
- this.iframe.style.bottom = '0';
54
- this.iframe.style.left = '0';
55
- this.iframe.style.width = '100%';
56
- this.iframe.style.height = '50px';
57
- this.iframe.style.zIndex = '999999'; // 6
55
+ this.iframe = this.setIframeStyles(this.iframe);
58
56
  this.iframe.src = `${this.childAppOrigin}/footer-widget`;
59
57
  this.appendIframe(this.iframe, params.container);
60
58
  this.setLaunched(true);
61
59
  window.addEventListener('message', this.childMessageHandler);
62
60
  }
61
+ setIframeStyles(iframe) {
62
+ iframe.style.left = '0';
63
+ iframe.style.width = '100%';
64
+ iframe.style.height = '50px';
65
+ iframe.style.zIndex = '999999'; // 6
66
+ if (this.position === 'bottom') {
67
+ iframe.style.bottom = '0';
68
+ }
69
+ else {
70
+ iframe.style.top = '0';
71
+ }
72
+ return iframe;
73
+ }
63
74
  updateData(partialData) {
64
75
  if (!this.validateNonEmptyObject(partialData))
65
76
  return;
@@ -2,6 +2,9 @@ import { SDKMode } from 'src/widgets/shared/types';
2
2
  export interface FooterWidgetParams {
3
3
  data: unknown;
4
4
  mode?: SDKMode;
5
+ position?: 'top' | 'bottom';
6
+ animation?: 'wheel' | 'airplane';
7
+ maxWidth?: string;
5
8
  container?: string;
6
9
  jackpotId?: string;
7
10
  tag?: string;
@@ -6,3 +6,13 @@ export type SDKMode = 'local' | 'dev' | 'staging' | 'production';
6
6
  export type WidgetParams = FooterWidgetParams | WinWidgetParams;
7
7
  export type IframeOutgoingEvent = FooterIframeOutgoingEvent | WinWidgetIframeOutgoingEvent;
8
8
  export type WidgetEventHandler = () => void;
9
+ export interface ChildMessage {
10
+ type: IframeOutgoingEvent;
11
+ data: unknown;
12
+ position?: FooterWidgetParams['position'];
13
+ animation?: WinWidgetParams['animation'];
14
+ maxWidth?: string;
15
+ jackpotId?: string | null;
16
+ tag?: string | null;
17
+ brand?: string | null;
18
+ }
@@ -0,0 +1,13 @@
1
+ import { BaseWidget } from '../BaseWidget';
2
+ import { WinWidgetParams } from './types/data';
3
+ export declare class WinWidget extends BaseWidget {
4
+ private static instance;
5
+ private constructor();
6
+ static getInstance(): WinWidget;
7
+ private childMessageHandler;
8
+ launch(params: WinWidgetParams): void;
9
+ private animateEnter;
10
+ private cleanupAnimation;
11
+ removeAllEventListeners(): void;
12
+ destroy(): void;
13
+ }
@@ -0,0 +1,131 @@
1
+ import { BaseWidget } from '../BaseWidget';
2
+ import { WinWidgetIframeIncomingEvent, WinWidgetIframeOutgoingEvent, } from './types/events';
3
+ export class WinWidget extends BaseWidget {
4
+ constructor() {
5
+ super();
6
+ this.childMessageHandler = (event) => {
7
+ var _a, _b;
8
+ if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
9
+ return;
10
+ if (event.origin !== this.childAppOrigin)
11
+ return;
12
+ switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
13
+ case WinWidgetIframeIncomingEvent.winWidgetLoaded:
14
+ this.sendDataToChild({
15
+ type: WinWidgetIframeOutgoingEvent.winWidgetDataInitial,
16
+ data: this.data,
17
+ jackpotId: this.jackpotId,
18
+ tag: this.tag,
19
+ brand: this.brand,
20
+ });
21
+ break;
22
+ case WinWidgetIframeIncomingEvent.winWidgetClose:
23
+ this.destroy();
24
+ this.emit('close');
25
+ break;
26
+ }
27
+ };
28
+ }
29
+ static getInstance() {
30
+ if (!WinWidget.instance) {
31
+ WinWidget.instance = new WinWidget();
32
+ }
33
+ return WinWidget.instance;
34
+ }
35
+ launch(params) {
36
+ if (this.isWidgetLaunched()) {
37
+ console.warn('Won Jackpot widget is already launched');
38
+ return;
39
+ }
40
+ this.setParamsData(params);
41
+ this.iframe = this.createIframe();
42
+ // TODO: move to set styles
43
+ console.log('RUNNING 1');
44
+ this.iframe.style.top = '0';
45
+ this.iframe.style.left = '0';
46
+ this.iframe.style.width = '100%';
47
+ this.iframe.style.height = '100%';
48
+ this.iframe.style.zIndex = '9999999'; // 7
49
+ this.iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
50
+ this.iframe.src = `${this.childAppOrigin}/win-animation-widget`;
51
+ this.animateEnter(this.iframe, params.container);
52
+ window.addEventListener('message', this.childMessageHandler);
53
+ }
54
+ animateEnter(iframe, containerSelector) {
55
+ if (!iframe) {
56
+ console.error('Failed to show win widget. Iframe not found.');
57
+ return;
58
+ }
59
+ const targetContainer = containerSelector
60
+ ? document.querySelector(containerSelector)
61
+ : document.body;
62
+ if (!targetContainer) {
63
+ console.error(`Failed to show win widget. Container "${containerSelector}" not found`);
64
+ return;
65
+ }
66
+ const isCustomContainer = !!containerSelector;
67
+ if (isCustomContainer) {
68
+ const style = window.getComputedStyle(targetContainer);
69
+ if (style.position === 'static') {
70
+ targetContainer.style.position = 'relative';
71
+ }
72
+ }
73
+ // create circular container
74
+ const container = document.createElement('div');
75
+ container.dataset.winWidget = 'container';
76
+ Object.assign(container.style, {
77
+ position: isCustomContainer ? 'absolute' : 'fixed',
78
+ inset: '0',
79
+ width: '100%',
80
+ height: '100%',
81
+ overflow: 'hidden',
82
+ zIndex: '99999999', // 8
83
+ clipPath: 'circle(0% at 50% 50%)',
84
+ transition: 'clip-path 1.2s cubic-bezier(0.22, 1, 0.36, 1)',
85
+ });
86
+ // append circular container into targetContainer, and iframe into circular container
87
+ targetContainer.appendChild(container);
88
+ container.appendChild(iframe);
89
+ // create overlay
90
+ const overlay = document.createElement('div');
91
+ overlay.dataset.winWidget = 'overlay';
92
+ Object.assign(overlay.style, {
93
+ position: isCustomContainer ? 'absolute' : 'fixed',
94
+ inset: '0',
95
+ width: '100%',
96
+ height: '100%',
97
+ background: 'rgba(0,0,0,0)',
98
+ zIndex: '9999999', // 7
99
+ backdropFilter: 'blur(0px)',
100
+ transition: 'background 0.8s ease, backdrop-filter 0.8s ease',
101
+ });
102
+ // append overlay
103
+ targetContainer.appendChild(overlay);
104
+ // animate overlay blur
105
+ setTimeout(() => {
106
+ overlay.style.background = 'rgba(0,0,0,0.4)';
107
+ overlay.style.backdropFilter = 'blur(8px)';
108
+ }, 200);
109
+ // animate circular container growth
110
+ setTimeout(() => {
111
+ container.style.clipPath = 'circle(150% at 50% 50%)';
112
+ }, 1000);
113
+ this.setLaunched(true);
114
+ }
115
+ cleanupAnimation(containerSelector) {
116
+ var _a, _b;
117
+ const container = containerSelector
118
+ ? document.querySelector(containerSelector) || document
119
+ : document;
120
+ (_a = container.querySelector('[data-win-widget="overlay"]')) === null || _a === void 0 ? void 0 : _a.remove();
121
+ (_b = container.querySelector('[data-win-widget="container"]')) === null || _b === void 0 ? void 0 : _b.remove();
122
+ }
123
+ removeAllEventListeners() {
124
+ super.removeAllEventListeners();
125
+ }
126
+ destroy() {
127
+ window.removeEventListener('message', this.childMessageHandler);
128
+ this.cleanupAnimation();
129
+ this.removeIframe();
130
+ }
131
+ }
@@ -6,6 +6,7 @@ export declare class WinWidget extends BaseWidget {
6
6
  static getInstance(): WinWidget;
7
7
  private childMessageHandler;
8
8
  launch(params: WinWidgetParams): void;
9
+ private setIframeStyles;
9
10
  private animateEnter;
10
11
  private cleanupAnimation;
11
12
  removeAllEventListeners(): void;
@@ -17,6 +17,7 @@ export class WinWidget extends BaseWidget {
17
17
  jackpotId: this.jackpotId,
18
18
  tag: this.tag,
19
19
  brand: this.brand,
20
+ animation: this.animation,
20
21
  });
21
22
  break;
22
23
  case WinWidgetIframeIncomingEvent.winWidgetClose:
@@ -39,16 +40,20 @@ export class WinWidget extends BaseWidget {
39
40
  }
40
41
  this.setParamsData(params);
41
42
  this.iframe = this.createIframe();
42
- this.iframe.style.top = '0';
43
- this.iframe.style.left = '0';
44
- this.iframe.style.width = '100%';
45
- this.iframe.style.height = '100%';
46
- this.iframe.style.zIndex = '99999999'; // 8
47
- this.iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
48
- this.iframe.src = `${this.childAppOrigin}/win-animation-widget`;
43
+ this.iframe = this.setIframeStyles(this.iframe);
44
+ this.iframe.src = `${this.childAppOrigin}/win-animation-widget?animation=${this.animation}`;
49
45
  this.animateEnter(this.iframe, params.container);
50
46
  window.addEventListener('message', this.childMessageHandler);
51
47
  }
48
+ setIframeStyles(iframe) {
49
+ iframe.style.top = '0';
50
+ iframe.style.left = '0';
51
+ iframe.style.width = '100%';
52
+ iframe.style.height = '100%';
53
+ iframe.style.zIndex = '9999999'; // 7
54
+ iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
55
+ return iframe;
56
+ }
52
57
  animateEnter(iframe, containerSelector) {
53
58
  if (!iframe) {
54
59
  console.error('Failed to show win widget. Iframe not found.');
@@ -100,14 +105,14 @@ export class WinWidget extends BaseWidget {
100
105
  // append overlay
101
106
  targetContainer.appendChild(overlay);
102
107
  // animate overlay blur
103
- requestAnimationFrame(() => {
108
+ setTimeout(() => {
104
109
  overlay.style.background = 'rgba(0,0,0,0.4)';
105
110
  overlay.style.backdropFilter = 'blur(8px)';
106
- });
111
+ }, 200);
107
112
  // animate circular container growth
108
113
  setTimeout(() => {
109
114
  container.style.clipPath = 'circle(150% at 50% 50%)';
110
- }, 800);
115
+ }, 1000);
111
116
  this.setLaunched(true);
112
117
  }
113
118
  cleanupAnimation(containerSelector) {
@@ -2,6 +2,9 @@ import { SDKMode } from 'src/widgets/shared/types';
2
2
  export interface WinWidgetParams {
3
3
  data: unknown;
4
4
  mode?: SDKMode;
5
+ position?: 'top' | 'bottom';
6
+ animation?: 'wheel' | 'airplane';
7
+ maxWidth?: string;
5
8
  container?: string;
6
9
  jackpotId?: string;
7
10
  tag?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splash-tech/jackpot-sdk",
3
- "version": "1.1.6",
3
+ "version": "2.0.1",
4
4
  "description": "SDK for managing jackpot widgets in iframes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "scripts": {
12
12
  "clean": "rm -rf dist",
13
13
  "build": "npm run clean && tsc",
14
- "publish:npm": "npm run build && npm publish",
14
+ "publish:npm": "npm run build && npm publish --access public",
15
15
  "test": "echo \"Error: no test specified\" && exit 1"
16
16
  },
17
17
  "keywords": [