@placetopay/lightbox-sdk 2.1.1 → 2.1.3
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/constants.d.ts +20 -17
- package/dist/constants.js +23 -20
- package/dist/core/assemblers.d.ts +3 -3
- package/dist/core/assemblers.js +86 -78
- package/dist/core/index.d.ts +7 -7
- package/dist/core/index.js +45 -41
- package/dist/helpers.d.ts +4 -4
- package/dist/helpers.js +19 -19
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/styles.css +3 -3
- package/dist/types.d.ts +54 -46
- package/dist/types.js +1 -1
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
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
|
-
BACKDROP_COLOR = "--placetopay-lightbox-backdrop-color",
|
|
14
|
-
RADIUS = "--placetopay-lightbox-border-radius",
|
|
15
|
-
MAX_HEIGHT = "--placetopay-lightbox-max-height",
|
|
16
|
-
MAX_WIDTH = "--placetopay-lightbox-max-width"
|
|
17
|
-
|
|
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
|
+
BACKDROP_COLOR = "--placetopay-lightbox-backdrop-color",
|
|
14
|
+
RADIUS = "--placetopay-lightbox-border-radius",
|
|
15
|
+
MAX_HEIGHT = "--placetopay-lightbox-max-height",
|
|
16
|
+
MAX_WIDTH = "--placetopay-lightbox-max-width",
|
|
17
|
+
POSITION = "--placetopay-lightbox-position",
|
|
18
|
+
WRAPPER_WIDTH = "--placetopay-lightbox-wrapper-width",
|
|
19
|
+
WRAPPER_HEIGHT = "--placetopay-lightbox-wrapper-height"
|
|
20
|
+
}
|
package/dist/constants.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
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["BACKDROP_COLOR"] = "--placetopay-lightbox-backdrop-color";
|
|
17
|
-
Styles["RADIUS"] = "--placetopay-lightbox-border-radius";
|
|
18
|
-
Styles["MAX_HEIGHT"] = "--placetopay-lightbox-max-height";
|
|
19
|
-
Styles["MAX_WIDTH"] = "--placetopay-lightbox-max-width";
|
|
20
|
-
|
|
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["BACKDROP_COLOR"] = "--placetopay-lightbox-backdrop-color";
|
|
17
|
+
Styles["RADIUS"] = "--placetopay-lightbox-border-radius";
|
|
18
|
+
Styles["MAX_HEIGHT"] = "--placetopay-lightbox-max-height";
|
|
19
|
+
Styles["MAX_WIDTH"] = "--placetopay-lightbox-max-width";
|
|
20
|
+
Styles["POSITION"] = "--placetopay-lightbox-position";
|
|
21
|
+
Styles["WRAPPER_WIDTH"] = "--placetopay-lightbox-wrapper-width";
|
|
22
|
+
Styles["WRAPPER_HEIGHT"] = "--placetopay-lightbox-wrapper-height";
|
|
23
|
+
})(Styles || (Styles = {}));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { MountLightboxOptions } from '../types';
|
|
2
|
-
export declare const mountLightbox: ({ url, callbacks, styles, closeButtonEnabled, enforceStyles }: MountLightboxOptions) => void;
|
|
3
|
-
export declare const unmountLightbox: (target: string) => void;
|
|
1
|
+
import { MountLightboxOptions } from '../types';
|
|
2
|
+
export declare const mountLightbox: ({ id, url, element, callbacks, styles, closeButtonEnabled, enforceStyles, }: MountLightboxOptions) => void;
|
|
3
|
+
export declare const unmountLightbox: (target: string) => void;
|
package/dist/core/assemblers.js
CHANGED
|
@@ -1,78 +1,86 @@
|
|
|
1
|
-
import { Styles, ElementIds, LightboxEvents as LE } from '../constants';
|
|
2
|
-
import { setStyle, unsetStyle } from '../helpers';
|
|
3
|
-
let listener;
|
|
4
|
-
export const mountLightbox = ({ url, callbacks, styles, closeButtonEnabled, enforceStyles }) => {
|
|
5
|
-
const wrapper = document.createElement('div');
|
|
6
|
-
wrapper.id =
|
|
7
|
-
wrapper.className = ElementIds.WRAPPER_ID;
|
|
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
|
-
if (event.data.type === LE.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
1
|
+
import { Styles, ElementIds, LightboxEvents as LE } from '../constants';
|
|
2
|
+
import { setStyle, unsetStyle } from '../helpers';
|
|
3
|
+
let listener;
|
|
4
|
+
export const mountLightbox = ({ id, url, element, callbacks, styles, closeButtonEnabled, enforceStyles, }) => {
|
|
5
|
+
const wrapper = document.createElement('div');
|
|
6
|
+
wrapper.id = id;
|
|
7
|
+
wrapper.className = ElementIds.WRAPPER_ID;
|
|
8
|
+
if (element !== document.body) {
|
|
9
|
+
wrapper.style.setProperty(Styles.POSITION, 'absolute');
|
|
10
|
+
wrapper.style.setProperty(Styles.WRAPPER_HEIGHT, '100%');
|
|
11
|
+
wrapper.style.setProperty(Styles.WRAPPER_WIDTH, '100%');
|
|
12
|
+
}
|
|
13
|
+
const iframe = document.createElement('iframe');
|
|
14
|
+
iframe.src = url;
|
|
15
|
+
iframe.id = ElementIds.IFRAME_ID;
|
|
16
|
+
updateStyles(styles);
|
|
17
|
+
element.appendChild(wrapper);
|
|
18
|
+
wrapper.appendChild(iframe);
|
|
19
|
+
let closeButton;
|
|
20
|
+
if (closeButtonEnabled) {
|
|
21
|
+
closeButton = document.createElement('button');
|
|
22
|
+
closeButton.id = ElementIds.CLOSE_BUTTON_ID;
|
|
23
|
+
closeButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="#4b5563" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12"/></svg>`;
|
|
24
|
+
closeButton.addEventListener('click', () => {
|
|
25
|
+
unmountLightbox(id);
|
|
26
|
+
});
|
|
27
|
+
wrapper.appendChild(closeButton);
|
|
28
|
+
}
|
|
29
|
+
mountListener({ id, callbacks, styles, closeButton, enforceStyles });
|
|
30
|
+
};
|
|
31
|
+
const mountListener = ({ id, callbacks, styles, closeButton, enforceStyles }) => {
|
|
32
|
+
listener = (event) => {
|
|
33
|
+
var _a;
|
|
34
|
+
if (event.data.type === LE.CLOSE)
|
|
35
|
+
unmountLightbox(id);
|
|
36
|
+
if (event.data.type === LE.UPDATE_STYLES) {
|
|
37
|
+
const newStyles = enforceStyles
|
|
38
|
+
? Object.assign(Object.assign({}, event.data.payload), styles) : Object.assign(Object.assign({}, styles), event.data.payload);
|
|
39
|
+
updateStyles(newStyles);
|
|
40
|
+
}
|
|
41
|
+
if (event.data.type === LE.HIDE_CLOSE_BUTTON)
|
|
42
|
+
closeButton === null || closeButton === void 0 ? void 0 : closeButton.remove();
|
|
43
|
+
(_a = callbacks[event.data.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.payload);
|
|
44
|
+
};
|
|
45
|
+
globalThis.addEventListener('message', listener);
|
|
46
|
+
};
|
|
47
|
+
export const unmountLightbox = (target) => {
|
|
48
|
+
const element = document.getElementById(target);
|
|
49
|
+
if (element) {
|
|
50
|
+
element.remove();
|
|
51
|
+
clearStyles();
|
|
52
|
+
globalThis.removeEventListener('message', listener);
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
throw new Error(`Frame from "${target}" not found`);
|
|
56
|
+
};
|
|
57
|
+
const clearStyles = () => {
|
|
58
|
+
unsetStyle(Styles.BACKDROP_COLOR);
|
|
59
|
+
unsetStyle(Styles.RADIUS);
|
|
60
|
+
unsetStyle(Styles.MAX_HEIGHT);
|
|
61
|
+
unsetStyle(Styles.MAX_WIDTH);
|
|
62
|
+
};
|
|
63
|
+
const updateStyles = (styles) => {
|
|
64
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
65
|
+
setStyle(Styles.BACKDROP_COLOR, buildBackdrop((_a = styles.backdropColor) !== null && _a !== void 0 ? _a : '#000000', (_b = styles.backdropOpacity) !== null && _b !== void 0 ? _b : 0.7));
|
|
66
|
+
setStyle(Styles.RADIUS, `${(_c = styles.radius) !== null && _c !== void 0 ? _c : 0}px`);
|
|
67
|
+
setStyle(Styles.MAX_HEIGHT, buildDimension('height', (_d = styles.height) !== null && _d !== void 0 ? _d : 640));
|
|
68
|
+
setStyle(Styles.MAX_WIDTH, buildDimension('width', (_e = styles.width) !== null && _e !== void 0 ? _e : 512));
|
|
69
|
+
setStyle(Styles.POSITION, (_f = styles.position) !== null && _f !== void 0 ? _f : 'fixed');
|
|
70
|
+
setStyle(Styles.WRAPPER_WIDTH, buildDimension('width', (_g = styles.wrapperWidth) !== null && _g !== void 0 ? _g : '100vw'));
|
|
71
|
+
setStyle(Styles.WRAPPER_HEIGHT, buildDimension('height', (_h = styles.wrapperHeight) !== null && _h !== void 0 ? _h : '100vh'));
|
|
72
|
+
};
|
|
73
|
+
const buildBackdrop = (color, opacity) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const backdrop = (_a = color === null || color === void 0 ? void 0 : color.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 || _a === void 0 ? void 0 : _a.map((x) => parseInt(x, 16));
|
|
76
|
+
backdrop.push(opacity);
|
|
77
|
+
return `rgba(${backdrop.join(', ')})`;
|
|
78
|
+
};
|
|
79
|
+
const buildDimension = (type, value) => {
|
|
80
|
+
const result = String(value);
|
|
81
|
+
if (result.match(/^\d+(vh|vw|px|%)$/))
|
|
82
|
+
return result;
|
|
83
|
+
if (result.match(/^\d+$/))
|
|
84
|
+
return `${result}px`;
|
|
85
|
+
console.warn(`Invalid ${type}. Must be a number, a number followed by "px", or a number followed by "%".`);
|
|
86
|
+
};
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InitialOptions, LightboxInstance, ApiStructure, LightboxStyles } from '../types';
|
|
2
|
-
export declare const isInside: () => boolean;
|
|
3
|
-
export declare const updateStyles: (styles: LightboxStyles) => void;
|
|
4
|
-
export declare const hideCloseButton: () => void;
|
|
5
|
-
export declare const emitClose: (payload?: unknown, preventClose?: boolean) => void;
|
|
6
|
-
export declare const emit: ({ type, payload, preventClose }: ApiStructure) => void;
|
|
7
|
-
export declare const createLightbox: (url: string, options?: InitialOptions) => LightboxInstance;
|
|
1
|
+
import { InitialOptions, LightboxInstance, ApiStructure, LightboxStyles } from '../types';
|
|
2
|
+
export declare const isInside: () => boolean;
|
|
3
|
+
export declare const updateStyles: (styles: LightboxStyles) => void;
|
|
4
|
+
export declare const hideCloseButton: () => void;
|
|
5
|
+
export declare const emitClose: (payload?: unknown, preventClose?: boolean) => void;
|
|
6
|
+
export declare const emit: ({ type, payload, preventClose }: ApiStructure) => void;
|
|
7
|
+
export declare const createLightbox: (url: string, options?: InitialOptions) => LightboxInstance;
|
package/dist/core/index.js
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
import { LightboxEvents as LE } from '../constants';
|
|
2
|
-
import { postMessage, redirectBasedOnDriver } from '../helpers';
|
|
3
|
-
import { mountLightbox, unmountLightbox } from './assemblers';
|
|
4
|
-
export const isInside = () => globalThis.location !== globalThis.parent.location;
|
|
5
|
-
export const updateStyles = (styles) => postMessage(LE.UPDATE_STYLES, styles);
|
|
6
|
-
export const hideCloseButton = () => postMessage(LE.HIDE_CLOSE_BUTTON);
|
|
7
|
-
export const emitClose = (payload, preventClose) => {
|
|
8
|
-
postMessage(LE.CLOSE, payload, preventClose);
|
|
9
|
-
};
|
|
10
|
-
export const emit = ({ type, payload, preventClose }) => postMessage(type, payload, preventClose);
|
|
11
|
-
export const createLightbox = (url, options) => {
|
|
12
|
-
var _a, _b, _c, _d;
|
|
13
|
-
const lightbox = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
url
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
1
|
+
import { LightboxEvents as LE } from '../constants';
|
|
2
|
+
import { postMessage, redirectBasedOnDriver } from '../helpers';
|
|
3
|
+
import { mountLightbox, unmountLightbox } from './assemblers';
|
|
4
|
+
export const isInside = () => globalThis.location !== globalThis.parent.location;
|
|
5
|
+
export const updateStyles = (styles) => postMessage(LE.UPDATE_STYLES, styles);
|
|
6
|
+
export const hideCloseButton = () => postMessage(LE.HIDE_CLOSE_BUTTON);
|
|
7
|
+
export const emitClose = (payload, preventClose) => {
|
|
8
|
+
postMessage(LE.CLOSE, payload, preventClose);
|
|
9
|
+
};
|
|
10
|
+
export const emit = ({ type, payload, preventClose }) => postMessage(type, payload, preventClose);
|
|
11
|
+
export const createLightbox = (url, options) => {
|
|
12
|
+
var _a, _b, _c, _d, _e, _f;
|
|
13
|
+
const lightbox = {
|
|
14
|
+
id: (_a = options === null || options === void 0 ? void 0 : options.id) !== null && _a !== void 0 ? _a : new URL(url).origin,
|
|
15
|
+
element: (_b = options === null || options === void 0 ? void 0 : options.element) !== null && _b !== void 0 ? _b : document.body,
|
|
16
|
+
allowRedirects: (_c = options === null || options === void 0 ? void 0 : options.allowRedirects) !== null && _c !== void 0 ? _c : true,
|
|
17
|
+
callbacks: (_d = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _d !== void 0 ? _d : {},
|
|
18
|
+
closeButton: (_e = options === null || options === void 0 ? void 0 : options.closeButton) !== null && _e !== void 0 ? _e : true,
|
|
19
|
+
styles: (_f = options === null || options === void 0 ? void 0 : options.styles) !== null && _f !== void 0 ? _f : {},
|
|
20
|
+
url: url,
|
|
21
|
+
close: () => unmountLightbox(url),
|
|
22
|
+
updateStyles,
|
|
23
|
+
hideCloseButton,
|
|
24
|
+
on: (name, callback) => {
|
|
25
|
+
lightbox.callbacks[name] = callback;
|
|
26
|
+
},
|
|
27
|
+
open: () => {
|
|
28
|
+
var _a;
|
|
29
|
+
if (lightbox.allowRedirects)
|
|
30
|
+
redirectBasedOnDriver(url);
|
|
31
|
+
mountLightbox({
|
|
32
|
+
id: lightbox.id,
|
|
33
|
+
url,
|
|
34
|
+
element: lightbox.element,
|
|
35
|
+
callbacks: lightbox.callbacks,
|
|
36
|
+
styles: lightbox.styles,
|
|
37
|
+
closeButtonEnabled: lightbox.closeButton,
|
|
38
|
+
enforceStyles: (_a = options === null || options === void 0 ? void 0 : options.enforceStyles) !== null && _a !== void 0 ? _a : false,
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
if (options === null || options === void 0 ? void 0 : options.launch)
|
|
43
|
+
lightbox.open();
|
|
44
|
+
return lightbox;
|
|
45
|
+
};
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const postMessage: (type: string, payload?: unknown, preventClose?: boolean) => void;
|
|
2
|
-
export declare const setStyle: (name: string, value: string) => void;
|
|
3
|
-
export declare const unsetStyle: (name: string) => void;
|
|
4
|
-
export declare const redirectBasedOnDriver: (url: string) => void;
|
|
1
|
+
export declare const postMessage: (type: string, payload?: unknown, preventClose?: boolean) => void;
|
|
2
|
+
export declare const setStyle: (name: string, value: string) => void;
|
|
3
|
+
export declare const unsetStyle: (name: string) => void;
|
|
4
|
+
export declare const redirectBasedOnDriver: (url: string) => void;
|
package/dist/helpers.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export const postMessage = (type, payload, preventClose) => {
|
|
2
|
-
return globalThis.parent.postMessage({ type, preventClose, payload }, '*');
|
|
3
|
-
};
|
|
4
|
-
export const setStyle = (name, value) => {
|
|
5
|
-
document.documentElement.style.setProperty(name, value);
|
|
6
|
-
};
|
|
7
|
-
export const unsetStyle = (name) => {
|
|
8
|
-
document.documentElement.style.removeProperty(name);
|
|
9
|
-
};
|
|
10
|
-
export const redirectBasedOnDriver = (url) => {
|
|
11
|
-
if (navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
|
|
12
|
-
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) // regex from https://stackoverflow.com/a/23522755
|
|
13
|
-
) {
|
|
14
|
-
if (window.self !== window.top) {
|
|
15
|
-
window.parent.postMessage({ type: "placetopay-lightbox:redirect", url }, "*"); // dont change this, it would be a broken change
|
|
16
|
-
}
|
|
17
|
-
location.href = url;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
1
|
+
export const postMessage = (type, payload, preventClose) => {
|
|
2
|
+
return globalThis.parent.postMessage({ type, preventClose, payload }, '*');
|
|
3
|
+
};
|
|
4
|
+
export const setStyle = (name, value) => {
|
|
5
|
+
document.documentElement.style.setProperty(name, value);
|
|
6
|
+
};
|
|
7
|
+
export const unsetStyle = (name) => {
|
|
8
|
+
document.documentElement.style.removeProperty(name);
|
|
9
|
+
};
|
|
10
|
+
export const redirectBasedOnDriver = (url) => {
|
|
11
|
+
if (navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
|
|
12
|
+
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) // regex from https://stackoverflow.com/a/23522755
|
|
13
|
+
) {
|
|
14
|
+
if (window.self !== window.top) {
|
|
15
|
+
window.parent.postMessage({ type: "placetopay-lightbox:redirect", url }, "*"); // dont change this, it would be a broken change
|
|
16
|
+
}
|
|
17
|
+
location.href = url;
|
|
18
|
+
}
|
|
19
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './core';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './core';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './types';
|
package/dist/styles.css
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
.placetopay_lightbox_wrapper {
|
|
2
2
|
background: var(--placetopay-lightbox-backdrop-color);
|
|
3
|
-
position:
|
|
3
|
+
position: var(--placetopay-lightbox-position);
|
|
4
4
|
display: flex;
|
|
5
5
|
justify-content: center;
|
|
6
6
|
align-items: center;
|
|
7
7
|
top: 0;
|
|
8
8
|
left: 0;
|
|
9
|
-
width:
|
|
10
|
-
height:
|
|
9
|
+
width: var(--placetopay-lightbox-wrapper-width);
|
|
10
|
+
height: var(--placetopay-lightbox-wrapper-height);
|
|
11
11
|
z-index: 999;
|
|
12
12
|
user-select: none;
|
|
13
13
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,46 +1,54 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
backdropColor: string;
|
|
5
|
-
backdropOpacity: number;
|
|
6
|
-
height: string | number;
|
|
7
|
-
width: string | number;
|
|
8
|
-
radius: number;
|
|
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
|
-
};
|
|
1
|
+
export type ClientCallback = (payload?: unknown) => void;
|
|
2
|
+
export type ClientCallbacks = Record<string, ClientCallback | undefined>;
|
|
3
|
+
export type LightboxStyles = Partial<{
|
|
4
|
+
backdropColor: string;
|
|
5
|
+
backdropOpacity: number;
|
|
6
|
+
height: string | number;
|
|
7
|
+
width: string | number;
|
|
8
|
+
radius: number;
|
|
9
|
+
position: 'absolute' | 'fixed';
|
|
10
|
+
wrapperWidth: string | number;
|
|
11
|
+
wrapperHeight: string | number;
|
|
12
|
+
}>;
|
|
13
|
+
export type ApiStructure = {
|
|
14
|
+
type: string;
|
|
15
|
+
payload?: unknown;
|
|
16
|
+
preventClose?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type InternalOptions = Partial<{
|
|
19
|
+
launch: boolean;
|
|
20
|
+
enforceStyles: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
export type ExposedOptions = Partial<{
|
|
23
|
+
id: string;
|
|
24
|
+
element: HTMLElement;
|
|
25
|
+
allowRedirects: boolean;
|
|
26
|
+
callbacks: ClientCallbacks;
|
|
27
|
+
closeButton: boolean;
|
|
28
|
+
styles: LightboxStyles;
|
|
29
|
+
}>;
|
|
30
|
+
export type InitialOptions = ExposedOptions & InternalOptions;
|
|
31
|
+
export type MountLightboxOptions = {
|
|
32
|
+
id: string;
|
|
33
|
+
url: string;
|
|
34
|
+
element: HTMLElement;
|
|
35
|
+
callbacks: ClientCallbacks;
|
|
36
|
+
styles: LightboxStyles;
|
|
37
|
+
closeButtonEnabled: boolean;
|
|
38
|
+
enforceStyles: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type MountListenerOptions = {
|
|
41
|
+
id: string;
|
|
42
|
+
callbacks: ClientCallbacks;
|
|
43
|
+
styles: LightboxStyles;
|
|
44
|
+
closeButton: HTMLButtonElement;
|
|
45
|
+
enforceStyles: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type LightboxInstance = Required<ExposedOptions> & {
|
|
48
|
+
url: string;
|
|
49
|
+
on: (name: string, callback: ClientCallback) => void;
|
|
50
|
+
open: () => void;
|
|
51
|
+
close: (payload?: unknown) => void;
|
|
52
|
+
updateStyles: (styles: LightboxStyles) => void;
|
|
53
|
+
hideCloseButton: () => void;
|
|
54
|
+
};
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/package.json
CHANGED