@placetopay/lightbox-sdk 2.0.0 → 2.0.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/config.d.ts +2 -2
- package/dist/constants.d.ts +7 -7
- package/dist/constants.js +4 -4
- package/dist/core/assemblers.js +34 -26
- package/dist/core/index.js +1 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +3 -0
- package/dist/styles.css +1 -1
- package/dist/types.d.ts +5 -6
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
package/dist/constants.d.ts
CHANGED
|
@@ -10,22 +10,22 @@ export declare enum LightboxEvents {
|
|
|
10
10
|
HIDE_CLOSE_BUTTON = "hideCloseButton"
|
|
11
11
|
}
|
|
12
12
|
export declare enum Styles {
|
|
13
|
-
|
|
13
|
+
BACKDROP_COLOR = "--placetopay-lightbox-backdrop-color",
|
|
14
14
|
ROUNDED = "--placetopay-lightbox-border-radius",
|
|
15
15
|
MAX_HEIGHT = "--placetopay-lightbox-max-height",
|
|
16
16
|
MAX_WIDTH = "--placetopay-lightbox-max-width"
|
|
17
17
|
}
|
|
18
18
|
export declare const Dimensions: {
|
|
19
19
|
SM: {
|
|
20
|
-
height:
|
|
21
|
-
width:
|
|
20
|
+
height: string;
|
|
21
|
+
width: string;
|
|
22
22
|
};
|
|
23
23
|
MD: {
|
|
24
|
-
height:
|
|
25
|
-
width:
|
|
24
|
+
height: string;
|
|
25
|
+
width: string;
|
|
26
26
|
};
|
|
27
27
|
LG: {
|
|
28
|
-
height:
|
|
29
|
-
width:
|
|
28
|
+
height: string;
|
|
29
|
+
width: string;
|
|
30
30
|
};
|
|
31
31
|
};
|
package/dist/constants.js
CHANGED
|
@@ -13,13 +13,13 @@ export var LightboxEvents;
|
|
|
13
13
|
})(LightboxEvents || (LightboxEvents = {}));
|
|
14
14
|
export var Styles;
|
|
15
15
|
(function (Styles) {
|
|
16
|
-
Styles["
|
|
16
|
+
Styles["BACKDROP_COLOR"] = "--placetopay-lightbox-backdrop-color";
|
|
17
17
|
Styles["ROUNDED"] = "--placetopay-lightbox-border-radius";
|
|
18
18
|
Styles["MAX_HEIGHT"] = "--placetopay-lightbox-max-height";
|
|
19
19
|
Styles["MAX_WIDTH"] = "--placetopay-lightbox-max-width";
|
|
20
20
|
})(Styles || (Styles = {}));
|
|
21
21
|
export const Dimensions = {
|
|
22
|
-
SM: { height: 400, width: 320 },
|
|
23
|
-
MD: { height: 640, width: 512 },
|
|
24
|
-
LG: { height: 1000, width: 800 },
|
|
22
|
+
SM: { height: '400', width: '320' },
|
|
23
|
+
MD: { height: '640', width: '512' },
|
|
24
|
+
LG: { height: '1000', width: '800' },
|
|
25
25
|
};
|
package/dist/core/assemblers.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { Config } from '../config';
|
|
2
|
-
import { Styles, ElementIds, Dimensions, LightboxEvents } from '../constants';
|
|
2
|
+
import { Styles, ElementIds, Dimensions, LightboxEvents as LE } from '../constants';
|
|
3
|
+
import { setStyle } from '../helpers';
|
|
3
4
|
export const mountListener = (callbacks, styles) => {
|
|
4
5
|
const listener = (event) => {
|
|
5
6
|
var _a, _b, _c;
|
|
6
|
-
if (event.data.type ===
|
|
7
|
+
if (event.data.type === LE.CLOSE)
|
|
7
8
|
unmountLightbox(listener, (_a = event.data.target) !== null && _a !== void 0 ? _a : event.origin);
|
|
8
|
-
if (event.data.type ===
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
if (event.data.type === LightboxEvents.HIDE_CLOSE_BUTTON) {
|
|
9
|
+
if (event.data.type === LE.UPDATE_STYLES)
|
|
10
|
+
mountStyles(Object.assign(Object.assign({}, event.data.payload), styles));
|
|
11
|
+
if (event.data.type === LE.HIDE_CLOSE_BUTTON)
|
|
13
12
|
(_b = document.getElementById(ElementIds.CLOSE_BUTTON_ID)) === null || _b === void 0 ? void 0 : _b.remove();
|
|
14
|
-
}
|
|
15
13
|
(_c = callbacks[event.data.type]) === null || _c === void 0 ? void 0 : _c.call(callbacks, event.data.payload);
|
|
16
14
|
};
|
|
17
15
|
globalThis.addEventListener('message', listener);
|
|
@@ -34,34 +32,44 @@ export const mountLightbox = (url, styles, closeButtonEnabled) => {
|
|
|
34
32
|
</svg>
|
|
35
33
|
`;
|
|
36
34
|
closeButton.addEventListener('click', () => {
|
|
37
|
-
globalThis.postMessage({ type:
|
|
35
|
+
globalThis.postMessage({ type: LE.CLOSE, target: new URL(url).origin }, '*');
|
|
38
36
|
});
|
|
39
37
|
wrapper.appendChild(closeButton);
|
|
40
38
|
}
|
|
41
39
|
};
|
|
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
40
|
const unmountLightbox = (listener, origin) => {
|
|
59
41
|
const element = document.getElementById(origin);
|
|
60
42
|
if (element) {
|
|
61
43
|
element.remove();
|
|
62
44
|
globalThis.removeEventListener('message', listener);
|
|
63
|
-
document.documentElement.style.removeProperty(Styles.
|
|
45
|
+
document.documentElement.style.removeProperty(Styles.BACKDROP_COLOR);
|
|
64
46
|
}
|
|
65
47
|
else
|
|
66
48
|
throw new Error(`Frame from "${origin}" not found`);
|
|
67
49
|
};
|
|
50
|
+
const mountStyles = (styles) => {
|
|
51
|
+
var _a;
|
|
52
|
+
setStyle(Styles.BACKDROP_COLOR, buildBackdrop(styles.backdropColor, styles.backdropOpacity));
|
|
53
|
+
setStyle(Styles.ROUNDED, `${(_a = styles.rounded) !== null && _a !== void 0 ? _a : 0}px`);
|
|
54
|
+
setStyle(Styles.MAX_HEIGHT, buildDimension('height', styles.height, styles.dimension));
|
|
55
|
+
setStyle(Styles.MAX_WIDTH, buildDimension('width', styles.width, styles.dimension));
|
|
56
|
+
};
|
|
57
|
+
const buildBackdrop = (color, opacity) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const backdrop = (_b = (_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))) !== null && _b !== void 0 ? _b : [107, 114, 128];
|
|
60
|
+
backdrop.push(opacity !== null && opacity !== void 0 ? opacity : 0.75);
|
|
61
|
+
return `rgba(${backdrop.join(', ')})`;
|
|
62
|
+
};
|
|
63
|
+
const buildDimension = (type, value = '', dimension) => {
|
|
64
|
+
let result = value.toString();
|
|
65
|
+
if (dimension)
|
|
66
|
+
result = Dimensions[dimension.toUpperCase()][type];
|
|
67
|
+
if (result.match(/^\d+%$/) || result.match(/^\d+px$/))
|
|
68
|
+
return result;
|
|
69
|
+
if (result.match(/^\d+$/))
|
|
70
|
+
return `${result}px`;
|
|
71
|
+
if (value) {
|
|
72
|
+
console.warn(`Invalid ${type}. Must be a number, a number followed by "px", or a number followed by "%".`);
|
|
73
|
+
}
|
|
74
|
+
return `${Config.defaultDimension[type]}px`;
|
|
75
|
+
};
|
package/dist/core/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export const createLightbox = (url, options) => {
|
|
|
16
16
|
callbacks: (_b = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _b !== void 0 ? _b : {},
|
|
17
17
|
closeButton: (_c = options === null || options === void 0 ? void 0 : options.closeButton) !== null && _c !== void 0 ? _c : true,
|
|
18
18
|
styles: (_d = options === null || options === void 0 ? void 0 : options.styles) !== null && _d !== void 0 ? _d : {},
|
|
19
|
+
url: url,
|
|
19
20
|
close: emitClose,
|
|
20
21
|
updateStyles: emitUpdateStyles,
|
|
21
22
|
hideCloseButton: emitHideCloseButton,
|
package/dist/helpers.d.ts
CHANGED
package/dist/helpers.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export const postMessage = (type, payload, preventClose) => {
|
|
2
2
|
return globalThis.parent.postMessage({ type, preventClose, payload }, '*');
|
|
3
3
|
};
|
|
4
|
+
export const setStyle = (name, value) => {
|
|
5
|
+
document.documentElement.style.setProperty(name, value);
|
|
6
|
+
};
|
|
4
7
|
export const redirectBasedOnDriver = (url) => {
|
|
5
8
|
if (navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
|
|
6
9
|
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) // regex from https://stackoverflow.com/a/23522755
|
package/dist/styles.css
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -3,14 +3,12 @@ export declare type ClientCallbacks = {
|
|
|
3
3
|
[key: string]: ClientCallback | undefined;
|
|
4
4
|
};
|
|
5
5
|
export declare type LightboxStyles = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
opacity?: number;
|
|
9
|
-
};
|
|
6
|
+
backdropColor?: string;
|
|
7
|
+
backdropOpacity?: number;
|
|
10
8
|
dimension?: 'sm' | 'md' | 'lg';
|
|
11
|
-
height?: number;
|
|
9
|
+
height?: string | number;
|
|
10
|
+
width?: string | number;
|
|
12
11
|
rounded?: number;
|
|
13
|
-
width?: number;
|
|
14
12
|
};
|
|
15
13
|
export declare type InitOptions = {
|
|
16
14
|
allowRedirects?: boolean;
|
|
@@ -25,6 +23,7 @@ export declare type ApiStructure = {
|
|
|
25
23
|
preventClose?: boolean;
|
|
26
24
|
};
|
|
27
25
|
export declare type LightboxInstance = Required<InitOptions> & {
|
|
26
|
+
url: string;
|
|
28
27
|
on: (name: string, callback: ClientCallback) => void;
|
|
29
28
|
open: () => void;
|
|
30
29
|
close: (payload?: unknown) => void;
|
package/package.json
CHANGED