@placetopay/lightbox-sdk 1.0.0 → 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/README.md +3 -15
- package/dist/config.d.ts +6 -6
- package/dist/config.js +4 -4
- package/dist/constants.d.ts +31 -31
- package/dist/constants.js +25 -25
- package/dist/{LightboxClient → core}/assemblers.d.ts +3 -3
- package/dist/{LightboxClient → core}/assemblers.js +67 -70
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.js +35 -0
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.js +10 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/{css/styles.css → styles.css} +18 -3
- package/dist/types.d.ts +33 -27
- package/dist/types.js +1 -1
- package/package.json +4 -4
- package/dist/LightboxApp/index.d.ts +0 -10
- package/dist/LightboxApp/index.js +0 -20
- package/dist/LightboxClient/index.d.ts +0 -4
- package/dist/LightboxClient/index.js +0 -20
- package/dist/css/close_button.css +0 -34
package/README.md
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
# Lightbox-sdk
|
|
2
|
-
|
|
2
|
+
Lightbox SDK is a comprehensive npm library designed to facilitate the creation and manipulation of iframes within your application in the form of modals.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
## Getting Started
|
|
5
5
|
|
|
6
|
-
-
|
|
7
|
-
- LightboxClient
|
|
8
|
-
|
|
9
|
-
If you have a site A, and within it you want to display a site B using Lightbox-sdk:
|
|
10
|
-
|
|
11
|
-
On site A the LightboxClient will be used (site that will display a lightbox)
|
|
12
|
-
|
|
13
|
-
- It will define which site will be displayed in the lightbox
|
|
14
|
-
- It will define the callbacks for each lightbox event
|
|
15
|
-
|
|
16
|
-
On site B LightboxApp will be used (site that will be shown in a lightbox)
|
|
17
|
-
|
|
18
|
-
- Define the event emission logic
|
|
6
|
+
Please follow the documentation at [Lightbox SDK Docs](https://placetopay-org.github.io/lightbox-sdk/)!
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const Config: {
|
|
2
|
-
defaultDimension: {
|
|
3
|
-
height: number;
|
|
4
|
-
width: number;
|
|
5
|
-
};
|
|
6
|
-
};
|
|
1
|
+
export declare const Config: {
|
|
2
|
+
defaultDimension: {
|
|
3
|
+
height: number;
|
|
4
|
+
width: number;
|
|
5
|
+
};
|
|
6
|
+
};
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dimensions } from './constants';
|
|
2
|
-
export const Config = {
|
|
3
|
-
defaultDimension: Dimensions.MD,
|
|
4
|
-
};
|
|
1
|
+
import { Dimensions } from './constants';
|
|
2
|
+
export const Config = {
|
|
3
|
+
defaultDimension: Dimensions.MD,
|
|
4
|
+
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
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
|
|
8
|
-
CLOSE = "
|
|
9
|
-
|
|
10
|
-
HIDE_CLOSE_BUTTON = "
|
|
11
|
-
}
|
|
12
|
-
export declare enum Styles {
|
|
13
|
-
BACKGROUND_COLOR = "--placetopay-lightbox-background-color",
|
|
14
|
-
ROUNDED = "--placetopay-lightbox-border-radius",
|
|
15
|
-
MAX_HEIGHT = "--placetopay-lightbox-max-height",
|
|
16
|
-
MAX_WIDTH = "--placetopay-lightbox-max-width"
|
|
17
|
-
}
|
|
18
|
-
export declare const Dimensions: {
|
|
19
|
-
SM: {
|
|
20
|
-
height: number;
|
|
21
|
-
width: number;
|
|
22
|
-
};
|
|
23
|
-
MD: {
|
|
24
|
-
height: number;
|
|
25
|
-
width: number;
|
|
26
|
-
};
|
|
27
|
-
LG: {
|
|
28
|
-
height: number;
|
|
29
|
-
width: number;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
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 LightboxEvents {
|
|
8
|
+
CLOSE = "close",
|
|
9
|
+
UPDATE_STYLES = "updateStyles",
|
|
10
|
+
HIDE_CLOSE_BUTTON = "hideCloseButton"
|
|
11
|
+
}
|
|
12
|
+
export declare enum Styles {
|
|
13
|
+
BACKGROUND_COLOR = "--placetopay-lightbox-background-color",
|
|
14
|
+
ROUNDED = "--placetopay-lightbox-border-radius",
|
|
15
|
+
MAX_HEIGHT = "--placetopay-lightbox-max-height",
|
|
16
|
+
MAX_WIDTH = "--placetopay-lightbox-max-width"
|
|
17
|
+
}
|
|
18
|
+
export declare const Dimensions: {
|
|
19
|
+
SM: {
|
|
20
|
+
height: number;
|
|
21
|
+
width: number;
|
|
22
|
+
};
|
|
23
|
+
MD: {
|
|
24
|
+
height: number;
|
|
25
|
+
width: number;
|
|
26
|
+
};
|
|
27
|
+
LG: {
|
|
28
|
+
height: number;
|
|
29
|
+
width: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
package/dist/constants.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
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
|
|
9
|
-
(function (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})(
|
|
14
|
-
export var Styles;
|
|
15
|
-
(function (Styles) {
|
|
16
|
-
Styles["BACKGROUND_COLOR"] = "--placetopay-lightbox-background-color";
|
|
17
|
-
Styles["ROUNDED"] = "--placetopay-lightbox-border-radius";
|
|
18
|
-
Styles["MAX_HEIGHT"] = "--placetopay-lightbox-max-height";
|
|
19
|
-
Styles["MAX_WIDTH"] = "--placetopay-lightbox-max-width";
|
|
20
|
-
})(Styles || (Styles = {}));
|
|
21
|
-
export const Dimensions = {
|
|
22
|
-
SM: { height: 400, width: 320 },
|
|
23
|
-
MD: { height: 640, width: 512 },
|
|
24
|
-
LG: { height: 1000, width: 800 },
|
|
25
|
-
};
|
|
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 LightboxEvents;
|
|
9
|
+
(function (LightboxEvents) {
|
|
10
|
+
LightboxEvents["CLOSE"] = "close";
|
|
11
|
+
LightboxEvents["UPDATE_STYLES"] = "updateStyles";
|
|
12
|
+
LightboxEvents["HIDE_CLOSE_BUTTON"] = "hideCloseButton";
|
|
13
|
+
})(LightboxEvents || (LightboxEvents = {}));
|
|
14
|
+
export var Styles;
|
|
15
|
+
(function (Styles) {
|
|
16
|
+
Styles["BACKGROUND_COLOR"] = "--placetopay-lightbox-background-color";
|
|
17
|
+
Styles["ROUNDED"] = "--placetopay-lightbox-border-radius";
|
|
18
|
+
Styles["MAX_HEIGHT"] = "--placetopay-lightbox-max-height";
|
|
19
|
+
Styles["MAX_WIDTH"] = "--placetopay-lightbox-max-width";
|
|
20
|
+
})(Styles || (Styles = {}));
|
|
21
|
+
export const Dimensions = {
|
|
22
|
+
SM: { height: 400, width: 320 },
|
|
23
|
+
MD: { height: 640, width: 512 },
|
|
24
|
+
LG: { height: 1000, width: 800 },
|
|
25
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ClientCallbacks, LightboxStyles } from '../types';
|
|
2
|
-
export declare const mountListener: (callbacks: ClientCallbacks, styles: LightboxStyles) => void;
|
|
3
|
-
export declare const mountLightbox: (url: string, styles: LightboxStyles, closeButtonEnabled: boolean) => void;
|
|
1
|
+
import { ClientCallbacks, LightboxStyles } from '../types';
|
|
2
|
+
export declare const mountListener: (callbacks: ClientCallbacks, styles: LightboxStyles) => void;
|
|
3
|
+
export declare const mountLightbox: (url: string, styles: LightboxStyles, closeButtonEnabled: boolean) => void;
|
|
@@ -1,70 +1,67 @@
|
|
|
1
|
-
import { Config } from '../config';
|
|
2
|
-
import { Styles, ElementIds, Dimensions,
|
|
3
|
-
export const mountListener = (callbacks, styles) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
document.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
globalThis.removeEventListener('message', listener);
|
|
69
|
-
document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
|
|
70
|
-
};
|
|
1
|
+
import { Config } from '../config';
|
|
2
|
+
import { Styles, ElementIds, Dimensions, LightboxEvents } from '../constants';
|
|
3
|
+
export const mountListener = (callbacks, styles) => {
|
|
4
|
+
const listener = (event) => {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
if (event.data.type === LightboxEvents.CLOSE)
|
|
7
|
+
unmountLightbox(listener, (_a = event.data.target) !== null && _a !== void 0 ? _a : event.origin);
|
|
8
|
+
if (event.data.type === LightboxEvents.UPDATE_STYLES) {
|
|
9
|
+
const receivedStyles = event.data.payload;
|
|
10
|
+
mountStyles(Object.assign(Object.assign(Object.assign({}, receivedStyles), styles), { background: Object.assign(Object.assign({}, receivedStyles === null || receivedStyles === void 0 ? void 0 : receivedStyles.background), styles.background) }));
|
|
11
|
+
}
|
|
12
|
+
if (event.data.type === LightboxEvents.HIDE_CLOSE_BUTTON) {
|
|
13
|
+
(_b = document.getElementById(ElementIds.CLOSE_BUTTON_ID)) === null || _b === void 0 ? void 0 : _b.remove();
|
|
14
|
+
}
|
|
15
|
+
(_c = callbacks[event.data.type]) === null || _c === void 0 ? void 0 : _c.call(callbacks, event.data.payload);
|
|
16
|
+
};
|
|
17
|
+
globalThis.addEventListener('message', listener);
|
|
18
|
+
};
|
|
19
|
+
export const mountLightbox = (url, styles, closeButtonEnabled) => {
|
|
20
|
+
const wrapper = document.createElement('div');
|
|
21
|
+
wrapper.id = new URL(url).origin;
|
|
22
|
+
wrapper.className = ElementIds.WRAPPER_ID;
|
|
23
|
+
const iframe = document.createElement('iframe');
|
|
24
|
+
iframe.src = url;
|
|
25
|
+
iframe.id = ElementIds.IFRAME_ID;
|
|
26
|
+
mountStyles(styles);
|
|
27
|
+
document.body.appendChild(wrapper);
|
|
28
|
+
wrapper.appendChild(iframe);
|
|
29
|
+
if (closeButtonEnabled) {
|
|
30
|
+
const closeButton = document.createElement('button');
|
|
31
|
+
closeButton.id = ElementIds.CLOSE_BUTTON_ID;
|
|
32
|
+
closeButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="#4b5563" height="24px" width="24px">
|
|
33
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
34
|
+
</svg>
|
|
35
|
+
`;
|
|
36
|
+
closeButton.addEventListener('click', () => {
|
|
37
|
+
globalThis.postMessage({ type: LightboxEvents.CLOSE, target: new URL(url).origin }, '*');
|
|
38
|
+
});
|
|
39
|
+
wrapper.appendChild(closeButton);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const mountStyles = (styles) => {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
44
|
+
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];
|
|
45
|
+
background.push((_f = (_e = styles.background) === null || _e === void 0 ? void 0 : _e.opacity) !== null && _f !== void 0 ? _f : 0.75);
|
|
46
|
+
document.documentElement.style.setProperty(Styles.BACKGROUND_COLOR, `rgb(${background.join(', ')})`);
|
|
47
|
+
const rounded = (_g = styles.rounded) !== null && _g !== void 0 ? _g : 0;
|
|
48
|
+
document.documentElement.style.setProperty(Styles.ROUNDED, `${rounded.toString()}px`);
|
|
49
|
+
let height = (_h = styles.height) !== null && _h !== void 0 ? _h : Config.defaultDimension.height;
|
|
50
|
+
if (styles.dimension)
|
|
51
|
+
height = Dimensions[styles.dimension.toUpperCase()].height;
|
|
52
|
+
document.documentElement.style.setProperty(Styles.MAX_HEIGHT, `${height.toString()}px`);
|
|
53
|
+
let width = (_j = styles.width) !== null && _j !== void 0 ? _j : Config.defaultDimension.width;
|
|
54
|
+
if (styles.dimension)
|
|
55
|
+
width = Dimensions[styles.dimension.toUpperCase()].width;
|
|
56
|
+
document.documentElement.style.setProperty(Styles.MAX_WIDTH, `${width.toString()}px`);
|
|
57
|
+
};
|
|
58
|
+
const unmountLightbox = (listener, origin) => {
|
|
59
|
+
const element = document.getElementById(origin);
|
|
60
|
+
if (element) {
|
|
61
|
+
element.remove();
|
|
62
|
+
globalThis.removeEventListener('message', listener);
|
|
63
|
+
document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
throw new Error(`Frame from "${origin}" not found`);
|
|
67
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InitOptions, LightboxInstance, ApiStructure, LightboxStyles } from '../types';
|
|
2
|
+
export declare const isInside: () => boolean;
|
|
3
|
+
export declare const emitClose: (payload?: unknown) => void;
|
|
4
|
+
export declare const emitUpdateStyles: (styles: LightboxStyles) => void;
|
|
5
|
+
export declare const emitHideCloseButton: () => void;
|
|
6
|
+
export declare const emit: ({ type, payload, preventClose }: ApiStructure) => {
|
|
7
|
+
close: (payload?: unknown) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const createLightbox: (url: string, options?: InitOptions & {
|
|
10
|
+
launch?: boolean;
|
|
11
|
+
}) => LightboxInstance;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LightboxEvents } from '../constants';
|
|
2
|
+
import { postMessage, redirectBasedOnDriver } from '../helpers';
|
|
3
|
+
import { mountLightbox, mountListener } from './assemblers';
|
|
4
|
+
export const isInside = () => globalThis.location !== globalThis.parent.location;
|
|
5
|
+
export const emitClose = (payload) => postMessage(LightboxEvents.CLOSE, payload);
|
|
6
|
+
export const emitUpdateStyles = (styles) => postMessage(LightboxEvents.UPDATE_STYLES, styles);
|
|
7
|
+
export const emitHideCloseButton = () => postMessage(LightboxEvents.HIDE_CLOSE_BUTTON);
|
|
8
|
+
export const emit = ({ type, payload, preventClose }) => {
|
|
9
|
+
postMessage(type, payload, preventClose);
|
|
10
|
+
return { close: emitClose };
|
|
11
|
+
};
|
|
12
|
+
export const createLightbox = (url, options) => {
|
|
13
|
+
var _a, _b, _c, _d;
|
|
14
|
+
const lightbox = {
|
|
15
|
+
allowRedirects: (_a = options === null || options === void 0 ? void 0 : options.allowRedirects) !== null && _a !== void 0 ? _a : true,
|
|
16
|
+
callbacks: (_b = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _b !== void 0 ? _b : {},
|
|
17
|
+
closeButton: (_c = options === null || options === void 0 ? void 0 : options.closeButton) !== null && _c !== void 0 ? _c : true,
|
|
18
|
+
styles: (_d = options === null || options === void 0 ? void 0 : options.styles) !== null && _d !== void 0 ? _d : {},
|
|
19
|
+
close: emitClose,
|
|
20
|
+
updateStyles: emitUpdateStyles,
|
|
21
|
+
hideCloseButton: emitHideCloseButton,
|
|
22
|
+
on: (name, callback) => {
|
|
23
|
+
lightbox.callbacks[name] = callback;
|
|
24
|
+
},
|
|
25
|
+
open: () => {
|
|
26
|
+
if (lightbox.allowRedirects)
|
|
27
|
+
redirectBasedOnDriver(url);
|
|
28
|
+
mountListener(lightbox.callbacks, lightbox.styles);
|
|
29
|
+
mountLightbox(url, lightbox.styles, lightbox.closeButton);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
if (options === null || options === void 0 ? void 0 : options.launch)
|
|
33
|
+
lightbox.open();
|
|
34
|
+
return lightbox;
|
|
35
|
+
};
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const postMessage: (type: string, payload?: unknown, preventClose?: boolean) => void;
|
|
2
|
+
export declare const redirectBasedOnDriver: (url: string) => void;
|
package/dist/helpers.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export const postMessage = (type, payload, preventClose) => {
|
|
2
|
+
return globalThis.parent.postMessage({ type, preventClose, payload }, '*');
|
|
3
|
+
};
|
|
4
|
+
export const redirectBasedOnDriver = (url) => {
|
|
5
|
+
if (navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
|
|
6
|
+
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) // regex from https://stackoverflow.com/a/23522755
|
|
7
|
+
) {
|
|
8
|
+
location.href = url;
|
|
9
|
+
}
|
|
10
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './types';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
#placetopay_lightbox_wrapper {
|
|
1
|
+
.placetopay_lightbox_wrapper {
|
|
4
2
|
background: var(--placetopay-lightbox-background-color);
|
|
5
3
|
position: fixed;
|
|
6
4
|
display: flex;
|
|
@@ -26,3 +24,20 @@
|
|
|
26
24
|
overflow: auto;
|
|
27
25
|
box-shadow: 0px 0px 60px rgba(0, 0, 0, 0.5);
|
|
28
26
|
}
|
|
27
|
+
|
|
28
|
+
#placetopay_close_button {
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
padding: 4px;
|
|
31
|
+
position: absolute;
|
|
32
|
+
right: 8px;
|
|
33
|
+
top: 8px;
|
|
34
|
+
border: 2px solid #4b5563;
|
|
35
|
+
background: #fff;
|
|
36
|
+
padding: 4px;
|
|
37
|
+
border-radius: 100%;
|
|
38
|
+
transition: all 0.05s ease-in-out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#placetopay_close_button:hover {
|
|
42
|
+
transform: scale(0.9);
|
|
43
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
export declare type ClientCallback = (
|
|
2
|
-
export declare type ClientCallbacks = {
|
|
3
|
-
[key: string]: ClientCallback | undefined;
|
|
4
|
-
};
|
|
5
|
-
export declare type LightboxStyles = {
|
|
6
|
-
background?: {
|
|
7
|
-
color?: string;
|
|
8
|
-
opacity?: number;
|
|
9
|
-
};
|
|
10
|
-
dimension?: 'sm' | 'md' | 'lg';
|
|
11
|
-
height?: number;
|
|
12
|
-
rounded?: number;
|
|
13
|
-
width?: number;
|
|
14
|
-
};
|
|
15
|
-
export declare type InitOptions = {
|
|
16
|
-
allowRedirects?: boolean;
|
|
17
|
-
callbacks?: ClientCallbacks;
|
|
18
|
-
closeButton?: boolean;
|
|
19
|
-
styles?: LightboxStyles;
|
|
20
|
-
};
|
|
21
|
-
export declare type ApiStructure = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
export declare type ClientCallback = (payload?: unknown) => void;
|
|
2
|
+
export declare type ClientCallbacks = {
|
|
3
|
+
[key: string]: ClientCallback | undefined;
|
|
4
|
+
};
|
|
5
|
+
export declare type LightboxStyles = {
|
|
6
|
+
background?: {
|
|
7
|
+
color?: string;
|
|
8
|
+
opacity?: number;
|
|
9
|
+
};
|
|
10
|
+
dimension?: 'sm' | 'md' | 'lg';
|
|
11
|
+
height?: number;
|
|
12
|
+
rounded?: number;
|
|
13
|
+
width?: number;
|
|
14
|
+
};
|
|
15
|
+
export declare type InitOptions = {
|
|
16
|
+
allowRedirects?: boolean;
|
|
17
|
+
callbacks?: ClientCallbacks;
|
|
18
|
+
closeButton?: boolean;
|
|
19
|
+
styles?: LightboxStyles;
|
|
20
|
+
};
|
|
21
|
+
export declare type ApiStructure = {
|
|
22
|
+
type: string;
|
|
23
|
+
target?: string;
|
|
24
|
+
payload?: unknown;
|
|
25
|
+
preventClose?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare type LightboxInstance = Required<InitOptions> & {
|
|
28
|
+
on: (name: string, callback: ClientCallback) => void;
|
|
29
|
+
open: () => void;
|
|
30
|
+
close: (payload?: unknown) => void;
|
|
31
|
+
updateStyles: (styles: LightboxStyles) => void;
|
|
32
|
+
hideCloseButton: () => void;
|
|
33
|
+
};
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@placetopay/lightbox-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Small javascript library to encapsulate websites in a lightbox with configurable styles and behaviors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://
|
|
12
|
+
"url": "git+https://github.com/placetopay-org/lightbox-sdk.git"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"lightbox",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"author": "JuanZea",
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"bugs": {
|
|
24
|
-
"url": "https://
|
|
24
|
+
"url": "https://github.com/placetopay-org/lightbox-sdk/issues"
|
|
25
25
|
},
|
|
26
|
-
"homepage": "https://
|
|
26
|
+
"homepage": "https://placetopay-org.github.io/lightbox-sdk",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "^4.8.3"
|
|
29
29
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { LightboxStyles } from '../types';
|
|
2
|
-
export declare const LightboxApp: {
|
|
3
|
-
isInside: () => boolean;
|
|
4
|
-
sendStyles: (styles: LightboxStyles) => void;
|
|
5
|
-
hideCloseButton: () => void;
|
|
6
|
-
close: (url?: string) => void;
|
|
7
|
-
emit: (type: string, payload: unknown) => {
|
|
8
|
-
close: (url?: string) => void;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { LightboxAppEvents } from '../constants';
|
|
2
|
-
export const LightboxApp = {
|
|
3
|
-
isInside: () => globalThis.location !== globalThis.parent.location,
|
|
4
|
-
sendStyles: (styles) => {
|
|
5
|
-
globalThis.parent.postMessage({ type: LightboxAppEvents.SEND_STYLES, payload: styles }, '*');
|
|
6
|
-
},
|
|
7
|
-
hideCloseButton: () => {
|
|
8
|
-
globalThis.parent.postMessage({ type: LightboxAppEvents.HIDE_CLOSE_BUTTON }, '*');
|
|
9
|
-
},
|
|
10
|
-
close: (url) => {
|
|
11
|
-
if (!url || LightboxApp.isInside())
|
|
12
|
-
globalThis.parent.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
13
|
-
else
|
|
14
|
-
globalThis.location.href = url;
|
|
15
|
-
},
|
|
16
|
-
emit: (type, payload) => {
|
|
17
|
-
globalThis.parent.postMessage({ type, payload }, '*');
|
|
18
|
-
return { close: LightboxApp.close };
|
|
19
|
-
},
|
|
20
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|