@placetopay/lightbox-sdk 0.3.0 → 0.3.2
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/LightboxApp/index.d.ts +9 -0
- package/dist/LightboxApp/index.js +16 -0
- package/dist/LightboxClient/assemblers.d.ts +3 -0
- package/dist/LightboxClient/assemblers.js +68 -0
- package/dist/LightboxClient/index.d.ts +4 -0
- package/dist/LightboxClient/index.js +20 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +4 -0
- package/dist/constants.d.ts +32 -0
- package/dist/constants.js +26 -0
- package/dist/css/close_button.css +34 -0
- package/dist/css/styles.css +28 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +39 -0
- package/dist/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LightboxAppEvents } from '../constants';
|
|
2
|
+
export const LightboxApp = {
|
|
3
|
+
close: () => {
|
|
4
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
5
|
+
},
|
|
6
|
+
emit: (type, payload) => {
|
|
7
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.EMIT, payload: { type, payload } }, '*');
|
|
8
|
+
return { close: LightboxApp.close };
|
|
9
|
+
},
|
|
10
|
+
sendStyles: (styles) => {
|
|
11
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.SEND_STYLES, payload: styles }, '*');
|
|
12
|
+
},
|
|
13
|
+
hideCloseButton: () => {
|
|
14
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.HIDE_CLOSE_BUTTON }, '*');
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Config } from '../config';
|
|
2
|
+
import { Styles, ElementIds, Dimensions, LightboxAppEvents } from '../constants';
|
|
3
|
+
export const mountListener = (callbacks, styles) => {
|
|
4
|
+
if (!callbacks)
|
|
5
|
+
return;
|
|
6
|
+
const listener = (event) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
switch (event.data.type) {
|
|
9
|
+
case LightboxAppEvents.CLOSE:
|
|
10
|
+
unmountLightbox(listener);
|
|
11
|
+
break;
|
|
12
|
+
case LightboxAppEvents.EMIT:
|
|
13
|
+
(_a = callbacks[event.data.payload.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.payload.payload);
|
|
14
|
+
break;
|
|
15
|
+
case LightboxAppEvents.SEND_STYLES:
|
|
16
|
+
mountStyles(Object.assign(Object.assign(Object.assign({}, event.data.payload), styles), { background: Object.assign(Object.assign({}, event.data.payload.background), styles.background) }));
|
|
17
|
+
break;
|
|
18
|
+
case LightboxAppEvents.HIDE_CLOSE_BUTTON:
|
|
19
|
+
(_b = document.getElementById(ElementIds.CLOSE_BUTTON_ID)) === null || _b === void 0 ? void 0 : _b.remove();
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
globalThis.addEventListener('message', listener);
|
|
24
|
+
};
|
|
25
|
+
export const mountLightbox = (url, styles, closeButtonEnabled) => {
|
|
26
|
+
const wrapper = document.createElement('div');
|
|
27
|
+
wrapper.id = ElementIds.WRAPPER_ID;
|
|
28
|
+
const iframe = document.createElement('iframe');
|
|
29
|
+
iframe.src = url;
|
|
30
|
+
iframe.id = ElementIds.IFRAME_ID;
|
|
31
|
+
mountStyles(styles);
|
|
32
|
+
document.body.appendChild(wrapper);
|
|
33
|
+
wrapper.appendChild(iframe);
|
|
34
|
+
if (closeButtonEnabled) {
|
|
35
|
+
const closeButton = document.createElement('button');
|
|
36
|
+
closeButton.id = ElementIds.CLOSE_BUTTON_ID;
|
|
37
|
+
closeButton.addEventListener('click', () => {
|
|
38
|
+
globalThis.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
39
|
+
});
|
|
40
|
+
const closeButtonContent = document.createElement('span');
|
|
41
|
+
closeButtonContent.classList.add('placetopay-close-button-content');
|
|
42
|
+
closeButtonContent.textContent = 'x';
|
|
43
|
+
closeButton.appendChild(closeButtonContent);
|
|
44
|
+
wrapper.appendChild(closeButton);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const mountStyles = (styles) => {
|
|
48
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
49
|
+
const background = (_d = (_c = (_b = (_a = styles.background) === null || _a === void 0 ? void 0 : _a.color) === null || _b === void 0 ? void 0 : _b.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => '#' + r + r + g + g + b + b).substring(1).match(/.{2}/g)) === null || _c === void 0 ? void 0 : _c.map((x) => parseInt(x, 16))) !== null && _d !== void 0 ? _d : [107, 114, 128];
|
|
50
|
+
background.push((_f = (_e = styles.background) === null || _e === void 0 ? void 0 : _e.opacity) !== null && _f !== void 0 ? _f : 0.75);
|
|
51
|
+
document.documentElement.style.setProperty(Styles.BACKGROUND_COLOR, `rgb(${background.join(', ')})`);
|
|
52
|
+
const rounded = (_g = styles.rounded) !== null && _g !== void 0 ? _g : 0;
|
|
53
|
+
document.documentElement.style.setProperty(Styles.ROUNDED, `${rounded.toString()}px`);
|
|
54
|
+
let height = (_h = styles.height) !== null && _h !== void 0 ? _h : Config.defaultDimension.height;
|
|
55
|
+
if (styles.dimension)
|
|
56
|
+
height = Dimensions[styles.dimension.toUpperCase()].height;
|
|
57
|
+
document.documentElement.style.setProperty(Styles.MAX_HEIGHT, `${height.toString()}px`);
|
|
58
|
+
let width = (_j = styles.width) !== null && _j !== void 0 ? _j : Config.defaultDimension.width;
|
|
59
|
+
if (styles.dimension)
|
|
60
|
+
width = Dimensions[styles.dimension.toUpperCase()].width;
|
|
61
|
+
document.documentElement.style.setProperty(Styles.MAX_WIDTH, `${width.toString()}px`);
|
|
62
|
+
};
|
|
63
|
+
const unmountLightbox = (listener) => {
|
|
64
|
+
var _a;
|
|
65
|
+
(_a = document.getElementById(ElementIds.WRAPPER_ID)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
66
|
+
globalThis.removeEventListener('message', listener);
|
|
67
|
+
document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
|
|
68
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { redirectBasedOnDriver } from '../helpers';
|
|
2
|
+
import { mountLightbox, mountListener } from './assemblers';
|
|
3
|
+
export const LightboxClient = {
|
|
4
|
+
init: (url, options) => {
|
|
5
|
+
var _a, _b, _c, _d;
|
|
6
|
+
const lightbox = {
|
|
7
|
+
allowRedirects: (_a = options === null || options === void 0 ? void 0 : options.allowRedirects) !== null && _a !== void 0 ? _a : true,
|
|
8
|
+
callbacks: (_b = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _b !== void 0 ? _b : {},
|
|
9
|
+
closeButton: (_c = options === null || options === void 0 ? void 0 : options.closeButton) !== null && _c !== void 0 ? _c : true,
|
|
10
|
+
styles: (_d = options === null || options === void 0 ? void 0 : options.styles) !== null && _d !== void 0 ? _d : {},
|
|
11
|
+
open: () => {
|
|
12
|
+
if (lightbox.allowRedirects)
|
|
13
|
+
redirectBasedOnDriver(url);
|
|
14
|
+
mountListener(lightbox.callbacks, lightbox.styles);
|
|
15
|
+
mountLightbox(url, lightbox.styles, lightbox.closeButton);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
return lightbox;
|
|
19
|
+
},
|
|
20
|
+
};
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare enum ElementIds {
|
|
2
|
+
WRAPPER_ID = "placetopay_lightbox_wrapper",
|
|
3
|
+
IFRAME_ID = "placetopay_lightbox",
|
|
4
|
+
CLOSE_BUTTON_ID = "placetopay_close_button",
|
|
5
|
+
STYLES_ID = "placetopay-lightbox"
|
|
6
|
+
}
|
|
7
|
+
export declare enum LightboxAppEvents {
|
|
8
|
+
CLOSE = "close",
|
|
9
|
+
EMIT = "emit",
|
|
10
|
+
SEND_STYLES = "sendStyles",
|
|
11
|
+
HIDE_CLOSE_BUTTON = "hideCloseButton"
|
|
12
|
+
}
|
|
13
|
+
export declare enum Styles {
|
|
14
|
+
BACKGROUND_COLOR = "--placetopay-lightbox-background-color",
|
|
15
|
+
ROUNDED = "--placetopay-lightbox-border-radius",
|
|
16
|
+
MAX_HEIGHT = "--placetopay-lightbox-max-height",
|
|
17
|
+
MAX_WIDTH = "--placetopay-lightbox-max-width"
|
|
18
|
+
}
|
|
19
|
+
export declare const Dimensions: {
|
|
20
|
+
SM: {
|
|
21
|
+
height: number;
|
|
22
|
+
width: number;
|
|
23
|
+
};
|
|
24
|
+
MD: {
|
|
25
|
+
height: number;
|
|
26
|
+
width: number;
|
|
27
|
+
};
|
|
28
|
+
LG: {
|
|
29
|
+
height: number;
|
|
30
|
+
width: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export var ElementIds;
|
|
2
|
+
(function (ElementIds) {
|
|
3
|
+
ElementIds["WRAPPER_ID"] = "placetopay_lightbox_wrapper";
|
|
4
|
+
ElementIds["IFRAME_ID"] = "placetopay_lightbox";
|
|
5
|
+
ElementIds["CLOSE_BUTTON_ID"] = "placetopay_close_button";
|
|
6
|
+
ElementIds["STYLES_ID"] = "placetopay-lightbox";
|
|
7
|
+
})(ElementIds || (ElementIds = {}));
|
|
8
|
+
export var LightboxAppEvents;
|
|
9
|
+
(function (LightboxAppEvents) {
|
|
10
|
+
LightboxAppEvents["CLOSE"] = "close";
|
|
11
|
+
LightboxAppEvents["EMIT"] = "emit";
|
|
12
|
+
LightboxAppEvents["SEND_STYLES"] = "sendStyles";
|
|
13
|
+
LightboxAppEvents["HIDE_CLOSE_BUTTON"] = "hideCloseButton";
|
|
14
|
+
})(LightboxAppEvents || (LightboxAppEvents = {}));
|
|
15
|
+
export var Styles;
|
|
16
|
+
(function (Styles) {
|
|
17
|
+
Styles["BACKGROUND_COLOR"] = "--placetopay-lightbox-background-color";
|
|
18
|
+
Styles["ROUNDED"] = "--placetopay-lightbox-border-radius";
|
|
19
|
+
Styles["MAX_HEIGHT"] = "--placetopay-lightbox-max-height";
|
|
20
|
+
Styles["MAX_WIDTH"] = "--placetopay-lightbox-max-width";
|
|
21
|
+
})(Styles || (Styles = {}));
|
|
22
|
+
export const Dimensions = {
|
|
23
|
+
SM: { height: 400, width: 320 },
|
|
24
|
+
MD: { height: 640, width: 512 },
|
|
25
|
+
LG: { height: 1000, width: 800 },
|
|
26
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* Initial design from uiverse.io by @Voxybuns */
|
|
2
|
+
#placetopay_close_button {
|
|
3
|
+
/* Variables */
|
|
4
|
+
--button_radius: 100%;
|
|
5
|
+
--button_color: #e8e8e8;
|
|
6
|
+
--button_outline_color: #000000;
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
padding: 0;
|
|
9
|
+
position: absolute;
|
|
10
|
+
right: 8px;
|
|
11
|
+
top: 8px;
|
|
12
|
+
font-size: 17px;
|
|
13
|
+
font-weight: bold;
|
|
14
|
+
border: none;
|
|
15
|
+
border-radius: var(--button_radius);
|
|
16
|
+
background: var(--button_outline_color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.placetopay-close-button-content {
|
|
20
|
+
display: block;
|
|
21
|
+
box-sizing: border-box;
|
|
22
|
+
border: 2px solid var(--button_outline_color);
|
|
23
|
+
border-radius: var(--button_radius);
|
|
24
|
+
padding: 2px 7px;
|
|
25
|
+
background: var(--button_color);
|
|
26
|
+
color: var(--button_outline_color);
|
|
27
|
+
transform: translateY(-0.1em);
|
|
28
|
+
transition: transform 0.1s ease;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
button:active .placetopay-close-button-content {
|
|
32
|
+
/* Push the button downwards when pressed */
|
|
33
|
+
transform: translateY(0);
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@import url('./close_button.css');
|
|
2
|
+
|
|
3
|
+
#placetopay_lightbox_wrapper {
|
|
4
|
+
background: var(--placetopay-lightbox-background-color);
|
|
5
|
+
position: fixed;
|
|
6
|
+
display: flex;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
align-items: center;
|
|
9
|
+
top: 0;
|
|
10
|
+
left: 0;
|
|
11
|
+
width: 100vw;
|
|
12
|
+
height: 100vh;
|
|
13
|
+
z-index: 999;
|
|
14
|
+
user-select: none;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#placetopay_lightbox {
|
|
18
|
+
border: 0;
|
|
19
|
+
border-radius: var(--placetopay-lightbox-border-radius);
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
background-color: white;
|
|
22
|
+
height: 100%;
|
|
23
|
+
width: 100%;
|
|
24
|
+
max-height: var(--placetopay-lightbox-max-height);
|
|
25
|
+
max-width: var(--placetopay-lightbox-max-width);
|
|
26
|
+
overflow: auto;
|
|
27
|
+
box-shadow: 0px 0px 60px rgba(0, 0, 0, 0.5);
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const redirectBasedOnDriver: (url: string) => void;
|
package/dist/helpers.js
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { LightboxAppEvents } from './constants';
|
|
2
|
+
export declare type ClientCallback = (data: unknown) => void;
|
|
3
|
+
export declare type ClientCallbacks = {
|
|
4
|
+
[key: string]: ClientCallback | undefined;
|
|
5
|
+
};
|
|
6
|
+
export declare type LightboxStyles = {
|
|
7
|
+
background?: {
|
|
8
|
+
color?: string;
|
|
9
|
+
opacity?: number;
|
|
10
|
+
};
|
|
11
|
+
dimension?: 'sm' | 'md' | 'lg';
|
|
12
|
+
height?: number;
|
|
13
|
+
rounded?: number;
|
|
14
|
+
width?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare type InitOptions = {
|
|
17
|
+
allowRedirects?: boolean;
|
|
18
|
+
callbacks?: ClientCallbacks;
|
|
19
|
+
closeButton?: boolean;
|
|
20
|
+
styles?: LightboxStyles;
|
|
21
|
+
};
|
|
22
|
+
export declare type ApiStructure = {
|
|
23
|
+
payload: unknown;
|
|
24
|
+
type: string;
|
|
25
|
+
};
|
|
26
|
+
export declare type LightboxInstance = Required<InitOptions> & {
|
|
27
|
+
open: () => void;
|
|
28
|
+
};
|
|
29
|
+
export declare type LightboxEvents = {
|
|
30
|
+
type: LightboxAppEvents.CLOSE;
|
|
31
|
+
} | {
|
|
32
|
+
type: LightboxAppEvents.EMIT;
|
|
33
|
+
payload: ApiStructure;
|
|
34
|
+
} | {
|
|
35
|
+
type: LightboxAppEvents.SEND_STYLES;
|
|
36
|
+
payload: LightboxStyles;
|
|
37
|
+
} | {
|
|
38
|
+
type: LightboxAppEvents.HIDE_CLOSE_BUTTON;
|
|
39
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED