@splash-tech/jackpot-sdk 1.1.6 → 2.0.0
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/dist/widgets/BaseWidget.d.ts +5 -9
- package/dist/widgets/BaseWidget.js +7 -2
- package/dist/widgets/footerWidget/FooterWidget.d.ts +1 -0
- package/dist/widgets/footerWidget/FooterWidget.js +15 -5
- package/dist/widgets/footerWidget/types/data.d.ts +2 -0
- package/dist/widgets/shared/types.d.ts +9 -0
- package/dist/widgets/winWidget/WinWidget copy.d.ts +13 -0
- package/dist/widgets/winWidget/WinWidget copy.js +131 -0
- package/dist/widgets/winWidget/WinWidget.d.ts +1 -0
- package/dist/widgets/winWidget/WinWidget.js +15 -10
- package/dist/widgets/winWidget/types/data.d.ts +2 -0
- package/package.json +2 -2
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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 animation: WinWidgetParams['animation'];
|
|
14
11
|
protected jackpotId: string | null;
|
|
15
12
|
protected tag: string | null;
|
|
16
13
|
protected brand: string | null;
|
|
@@ -28,4 +25,3 @@ export declare abstract class BaseWidget {
|
|
|
28
25
|
protected emit(event: string): void;
|
|
29
26
|
protected removeAllEventListeners(): void;
|
|
30
27
|
}
|
|
31
|
-
export {};
|
|
@@ -3,6 +3,8 @@ export class BaseWidget {
|
|
|
3
3
|
this.iframe = null;
|
|
4
4
|
this.childAppOrigin = null;
|
|
5
5
|
this.isLaunched = false;
|
|
6
|
+
this.position = 'bottom';
|
|
7
|
+
this.animation = 'wheel';
|
|
6
8
|
this.jackpotId = null;
|
|
7
9
|
this.tag = null;
|
|
8
10
|
this.brand = null;
|
|
@@ -51,12 +53,14 @@ export class BaseWidget {
|
|
|
51
53
|
this.isLaunched = false;
|
|
52
54
|
}
|
|
53
55
|
setParamsData(params) {
|
|
54
|
-
const { mode, data, jackpotId, tag, brand } = params;
|
|
56
|
+
const { mode, data, jackpotId, tag, brand, position, animation } = params;
|
|
55
57
|
this.childAppOrigin = this.getBaseUrl(mode !== null && mode !== void 0 ? mode : 'production');
|
|
56
58
|
this.data = data;
|
|
57
59
|
this.jackpotId = jackpotId !== null && jackpotId !== void 0 ? jackpotId : null;
|
|
58
60
|
this.tag = tag !== null && tag !== void 0 ? tag : null;
|
|
59
61
|
this.brand = brand !== null && brand !== void 0 ? brand : null;
|
|
62
|
+
this.position = position !== null && position !== void 0 ? position : 'bottom';
|
|
63
|
+
this.animation = animation !== null && animation !== void 0 ? animation : 'wheel';
|
|
60
64
|
}
|
|
61
65
|
setLaunched(launched) {
|
|
62
66
|
this.isLaunched = launched;
|
|
@@ -69,9 +73,10 @@ export class BaseWidget {
|
|
|
69
73
|
if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
|
|
70
74
|
this.childAppOrigin &&
|
|
71
75
|
message.data !== undefined) {
|
|
76
|
+
const { data, jackpotId, tag, brand, position } = message;
|
|
72
77
|
this.iframe.contentWindow.postMessage({
|
|
73
78
|
type: message.type,
|
|
74
|
-
payload:
|
|
79
|
+
payload: { data, jackpotId, tag, brand, position },
|
|
75
80
|
}, this.childAppOrigin);
|
|
76
81
|
}
|
|
77
82
|
}
|
|
@@ -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,7 @@ export class FooterWidget extends BaseWidget {
|
|
|
18
18
|
jackpotId: this.jackpotId,
|
|
19
19
|
tag: this.tag,
|
|
20
20
|
brand: this.brand,
|
|
21
|
+
position: this.position,
|
|
21
22
|
});
|
|
22
23
|
break;
|
|
23
24
|
case FooterIframeIncomingEvent.showPopup: {
|
|
@@ -50,16 +51,25 @@ export class FooterWidget extends BaseWidget {
|
|
|
50
51
|
}
|
|
51
52
|
this.setParamsData(params);
|
|
52
53
|
this.iframe = this.createIframe();
|
|
53
|
-
this.iframe
|
|
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
|
|
54
|
+
this.iframe = this.setIframeStyles(this.iframe);
|
|
58
55
|
this.iframe.src = `${this.childAppOrigin}/footer-widget`;
|
|
59
56
|
this.appendIframe(this.iframe, params.container);
|
|
60
57
|
this.setLaunched(true);
|
|
61
58
|
window.addEventListener('message', this.childMessageHandler);
|
|
62
59
|
}
|
|
60
|
+
setIframeStyles(iframe) {
|
|
61
|
+
iframe.style.left = '0';
|
|
62
|
+
iframe.style.width = '100%';
|
|
63
|
+
iframe.style.height = '50px';
|
|
64
|
+
iframe.style.zIndex = '999999'; // 6
|
|
65
|
+
if (this.position === 'bottom') {
|
|
66
|
+
iframe.style.bottom = '0';
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
iframe.style.top = '0';
|
|
70
|
+
}
|
|
71
|
+
return iframe;
|
|
72
|
+
}
|
|
63
73
|
updateData(partialData) {
|
|
64
74
|
if (!this.validateNonEmptyObject(partialData))
|
|
65
75
|
return;
|
|
@@ -6,3 +6,12 @@ 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
|
+
jackpotId?: string | null;
|
|
15
|
+
tag?: string | null;
|
|
16
|
+
brand?: string | null;
|
|
17
|
+
}
|
|
@@ -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
|
|
43
|
-
this.iframe.
|
|
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
|
-
|
|
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
|
-
},
|
|
115
|
+
}, 1000);
|
|
111
116
|
this.setLaunched(true);
|
|
112
117
|
}
|
|
113
118
|
cleanupAnimation(containerSelector) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splash-tech/jackpot-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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": [
|