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