@placetopay/lightbox-sdk 0.1.0 → 0.2.1

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.
@@ -0,0 +1,5 @@
1
+ import { ClientStyles } from '../types';
2
+ export declare const LightboxApp: {
3
+ emit: (type: string, data: unknown) => void;
4
+ sendStyles: (styles: ClientStyles) => void;
5
+ };
@@ -0,0 +1,9 @@
1
+ import { LightboxAppEvents } from '../constants';
2
+ export var LightboxApp = {
3
+ emit: function (type, data) {
4
+ globalThis.parent.postMessage({ event: LightboxAppEvents.EMIT, type: type, data: data }, '*');
5
+ },
6
+ sendStyles: function (styles) {
7
+ globalThis.parent.postMessage({ event: LightboxAppEvents.SEND_STYLES, styles: styles }, '*');
8
+ },
9
+ };
@@ -0,0 +1,3 @@
1
+ import { ClientCallbacks, ClientStyles } from '../types';
2
+ export declare const mountListeners: (callbacks: ClientCallbacks, styles: ClientStyles) => void;
3
+ export declare const mountIFrameElement: (url: string, styles: ClientStyles) => void;
@@ -0,0 +1,64 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { Config } from '../config';
13
+ import { Styles, ElementIds, Dimensions, LightboxAppEvents } from '../constants';
14
+ export var mountListeners = function (callbacks, styles) {
15
+ if (!callbacks)
16
+ return;
17
+ var callbacksListener = function (event) {
18
+ var _a;
19
+ if (event.data.event !== LightboxAppEvents.EMIT)
20
+ return;
21
+ (_a = callbacks[event.data.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.data);
22
+ unmountLightbox(callbacksListener);
23
+ };
24
+ var stylesListener = function (event) {
25
+ if (event.data.event !== LightboxAppEvents.SEND_STYLES)
26
+ return;
27
+ mountStyles(__assign(__assign(__assign({}, event.data.styles), styles), { background: __assign(__assign({}, event.data.styles.background), styles.background) }));
28
+ globalThis.removeEventListener('message', stylesListener);
29
+ };
30
+ globalThis.addEventListener('message', callbacksListener);
31
+ globalThis.addEventListener('message', stylesListener);
32
+ };
33
+ export var mountIFrameElement = function (url, styles) {
34
+ var wrapper = document.createElement('div');
35
+ wrapper.id = ElementIds.WRAPPER_ID;
36
+ var iframe = document.createElement('iframe');
37
+ iframe.src = url;
38
+ iframe.id = ElementIds.IFRAME_ID;
39
+ mountStyles(styles);
40
+ document.body.appendChild(wrapper);
41
+ wrapper.appendChild(iframe);
42
+ };
43
+ var mountStyles = function (styles) {
44
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
45
+ var 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, function (m, r, g, b) { return '#' + r + r + g + g + b + b; }).substring(1).match(/.{2}/g)) === null || _c === void 0 ? void 0 : _c.map(function (x) { return parseInt(x, 16); })) !== null && _d !== void 0 ? _d : [107, 114, 128];
46
+ background.push((_f = (_e = styles.background) === null || _e === void 0 ? void 0 : _e.opacity) !== null && _f !== void 0 ? _f : 0.75);
47
+ document.documentElement.style.setProperty(Styles.BACKGROUND_COLOR, "rgb(".concat(background.join(', '), ")"));
48
+ var rounded = (_g = styles.rounded) !== null && _g !== void 0 ? _g : 0;
49
+ document.documentElement.style.setProperty(Styles.ROUNDED, "".concat(rounded.toString(), "px"));
50
+ var height = (_h = styles.height) !== null && _h !== void 0 ? _h : Config.defaultDimension.height;
51
+ if (styles.dimension)
52
+ height = Dimensions[styles.dimension.toUpperCase()].height;
53
+ document.documentElement.style.setProperty(Styles.MAX_HEIGHT, "".concat(height.toString(), "px"));
54
+ var width = (_j = styles.width) !== null && _j !== void 0 ? _j : Config.defaultDimension.width;
55
+ if (styles.dimension)
56
+ width = Dimensions[styles.dimension.toUpperCase()].width;
57
+ document.documentElement.style.setProperty(Styles.MAX_WIDTH, "".concat(width.toString(), "px"));
58
+ };
59
+ var unmountLightbox = function (listener) {
60
+ var _a;
61
+ (_a = document.getElementById(ElementIds.WRAPPER_ID)) === null || _a === void 0 ? void 0 : _a.remove();
62
+ globalThis.removeEventListener('message', listener);
63
+ document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
64
+ };
@@ -1,4 +1,4 @@
1
- import { InitOptions, LightboxInstance } from '@/types';
1
+ import { InitOptions, LightboxInstance } from '../types';
2
2
  export declare const LightboxClient: {
3
3
  init: (url: string, options?: InitOptions) => LightboxInstance;
4
4
  };
@@ -0,0 +1,22 @@
1
+ import { redirectBasedOnDriver } from '../helpers';
2
+ import { mountIFrameElement, mountListeners } from './assemblers';
3
+ export var LightboxClient = {
4
+ init: function (url, options) {
5
+ var _a, _b, _c;
6
+ var lightbox = {
7
+ callbacks: (_a = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _a !== void 0 ? _a : {},
8
+ allowRedirects: (_b = options === null || options === void 0 ? void 0 : options.allowRedirects) !== null && _b !== void 0 ? _b : true,
9
+ styles: (_c = options === null || options === void 0 ? void 0 : options.styles) !== null && _c !== void 0 ? _c : {},
10
+ open: function () {
11
+ if (lightbox.allowRedirects)
12
+ redirectBasedOnDriver(url);
13
+ mountListeners(lightbox.callbacks, lightbox.styles);
14
+ mountIFrameElement(url, lightbox.styles);
15
+ },
16
+ };
17
+ if (options === null || options === void 0 ? void 0 : options.dispatch)
18
+ lightbox.open();
19
+ console.log("lightbox-sdk | client initialized (".concat(url, ")"));
20
+ return lightbox;
21
+ },
22
+ };
@@ -0,0 +1,6 @@
1
+ export declare const Config: {
2
+ defaultDimension: {
3
+ height: number;
4
+ width: number;
5
+ };
6
+ };
package/dist/config.js ADDED
@@ -0,0 +1,4 @@
1
+ import { Dimensions } from './constants';
2
+ export var Config = {
3
+ defaultDimension: Dimensions.MD,
4
+ };
@@ -0,0 +1,29 @@
1
+ export declare const ElementIds: {
2
+ WRAPPER_ID: string;
3
+ IFRAME_ID: string;
4
+ STYLES_ID: string;
5
+ };
6
+ export declare enum LightboxAppEvents {
7
+ EMIT = "emit",
8
+ SEND_STYLES = "sendStyles"
9
+ }
10
+ export declare const Styles: {
11
+ BACKGROUND_COLOR: string;
12
+ ROUNDED: string;
13
+ MAX_HEIGHT: string;
14
+ MAX_WIDTH: string;
15
+ };
16
+ export declare const Dimensions: {
17
+ SM: {
18
+ height: number;
19
+ width: number;
20
+ };
21
+ MD: {
22
+ height: number;
23
+ width: number;
24
+ };
25
+ LG: {
26
+ height: number;
27
+ width: number;
28
+ };
29
+ };
@@ -0,0 +1,21 @@
1
+ export var ElementIds = {
2
+ WRAPPER_ID: 'placetopay_lightbox_wrapper',
3
+ IFRAME_ID: 'placetopay_lightbox',
4
+ STYLES_ID: 'placetopay-lightbox',
5
+ };
6
+ export var LightboxAppEvents;
7
+ (function (LightboxAppEvents) {
8
+ LightboxAppEvents["EMIT"] = "emit";
9
+ LightboxAppEvents["SEND_STYLES"] = "sendStyles";
10
+ })(LightboxAppEvents || (LightboxAppEvents = {}));
11
+ export var Styles = {
12
+ BACKGROUND_COLOR: '--placetopay-lightbox-background-color',
13
+ ROUNDED: '--placetopay-lightbox-border-radius',
14
+ MAX_HEIGHT: '--placetopay-lightbox-max-height',
15
+ MAX_WIDTH: '--placetopay-lightbox-max-width',
16
+ };
17
+ export var Dimensions = {
18
+ SM: { height: 400, width: 320 },
19
+ MD: { height: 640, width: 512 },
20
+ LG: { height: 1000, width: 800 },
21
+ };
@@ -0,0 +1 @@
1
+ export declare const redirectBasedOnDriver: (url: string) => void;
@@ -0,0 +1,7 @@
1
+ export var redirectBasedOnDriver = function (url) {
2
+ if (navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
3
+ /^((?!chrome|android).)*safari/i.test(navigator.userAgent) // regex from https://stackoverflow.com/a/23522755
4
+ ) {
5
+ location.href = url;
6
+ }
7
+ };
@@ -1,2 +1,3 @@
1
1
  export { LightboxApp } from './LightboxApp';
2
2
  export { LightboxClient } from './LightboxClient';
3
+ export * from './types';
@@ -1,2 +1,3 @@
1
1
  export { LightboxApp } from './LightboxApp';
2
2
  export { LightboxClient } from './LightboxClient';
3
+ export * from './types';
@@ -9,6 +9,7 @@
9
9
  width: 100vw;
10
10
  height: 100vh;
11
11
  z-index: 999;
12
+ user-select: none;
12
13
  }
13
14
 
14
15
  #placetopay_lightbox {
@@ -16,4 +17,10 @@
16
17
  border-radius: var(--placetopay-lightbox-border-radius);
17
18
  overflow: hidden;
18
19
  background-color: white;
20
+ height: 100%;
21
+ width: 100%;
22
+ max-height: var(--placetopay-lightbox-max-height);
23
+ max-width: var(--placetopay-lightbox-max-width);
24
+ overflow: auto;
25
+ box-shadow: 0px 0px 60px rgba(0, 0, 0, 0.5);
19
26
  }
@@ -1,3 +1,4 @@
1
+ import { LightboxAppEvents } from './constants';
1
2
  export declare type ClientCallback = (data: unknown) => void;
2
3
  export declare type ClientCallbacks = {
3
4
  [key: string]: ClientCallback | undefined;
@@ -15,14 +16,17 @@ export declare type ClientStyles = {
15
16
  export declare type InitOptions = {
16
17
  dispatch?: boolean;
17
18
  callbacks?: ClientCallbacks;
19
+ allowRedirects?: boolean;
18
20
  styles?: ClientStyles;
19
21
  };
20
22
  export declare type ApiStructure = {
23
+ event: LightboxAppEvents;
21
24
  data: unknown;
22
25
  type: string;
23
26
  };
24
27
  export declare type LightboxInstance = {
25
28
  styles: ClientStyles;
29
+ allowRedirects: boolean;
26
30
  callbacks: ClientCallbacks;
27
31
  open: () => void;
28
32
  };
File without changes
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "@placetopay/lightbox-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
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",
7
7
  "files": [
8
- "/dist/lib"
8
+ "/dist"
9
9
  ],
10
10
  "scripts": {
11
- "dev": "vite",
12
11
  "prebuild": "npm run clean-build",
13
12
  "build": "tsc",
14
13
  "postbuild": "copyfiles -u 1 src/**/*.css dist/",
@@ -28,6 +27,7 @@
28
27
  "keywords": [
29
28
  "lightbox",
30
29
  "sdk",
30
+ "placetopay",
31
31
  "javascript",
32
32
  "typescript"
33
33
  ],
@@ -38,19 +38,12 @@
38
38
  },
39
39
  "homepage": "https://bitbucket.org/placetopay/lightbox-sdk#readme",
40
40
  "devDependencies": {
41
- "@types/node": "^18.7.23",
42
- "@types/react": "^18.0.21",
43
- "@types/react-dom": "^18.0.6",
44
41
  "@typescript-eslint/eslint-plugin": "^5.38.1",
45
42
  "@typescript-eslint/parser": "^5.38.1",
46
- "@vitejs/plugin-react": "^2.1.0",
47
43
  "copyfiles": "^2.4.1",
48
44
  "eslint": "^8.24.0",
49
45
  "prettier": "^2.7.1",
50
- "react": "^18.2.0",
51
- "react-dom": "^18.2.0",
52
46
  "rimraf": "^3.0.2",
53
- "typescript": "^4.8.3",
54
- "vite": "^3.1.4"
47
+ "typescript": "^4.8.3"
55
48
  }
56
49
  }
package/README.md DELETED
@@ -1,19 +0,0 @@
1
- # Lightbox-sdk
2
- Small javascript library to encapsulate websites in a lightbox with configurable styles and behaviors.
3
-
4
- The library consists of 2 parts:
5
-
6
- - LightboxClient
7
- - LightboxApp
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 style of the lightbox
15
- - It will define the callbacks for each lightbox event
16
-
17
- On site B LightboxApp will be used (site that will be shown in a lightbox)
18
-
19
- - Define the event emission logic
@@ -1,3 +0,0 @@
1
- export declare const LightboxApp: {
2
- emit: (type: string, data: unknown) => void;
3
- };
@@ -1,5 +0,0 @@
1
- export var LightboxApp = {
2
- emit: function (type, data) {
3
- globalThis.parent.postMessage({ type: type, data: data }, '*');
4
- },
5
- };
@@ -1,3 +0,0 @@
1
- import { ClientCallbacks, ClientStyles } from '@/types';
2
- export declare const mountListener: (callbacks: ClientCallbacks) => void;
3
- export declare const mountIFrameElement: (url: string, styles: ClientStyles) => void;
@@ -1,35 +0,0 @@
1
- import { Styles, Ids } from '@/constants';
2
- export var mountListener = function (callbacks) {
3
- if (!callbacks)
4
- return;
5
- var listener = function (event) {
6
- var _a;
7
- (_a = callbacks[event.data.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.data);
8
- unmountLightbox(listener);
9
- };
10
- globalThis.addEventListener('message', listener);
11
- };
12
- export var mountIFrameElement = function (url, styles) {
13
- var wrapper = document.createElement('div');
14
- wrapper.id = Ids.WRAPPER_ID;
15
- var iframe = document.createElement('iframe');
16
- iframe.src = url;
17
- iframe.id = Ids.IFRAME_ID;
18
- mountStyles(styles);
19
- document.body.appendChild(wrapper);
20
- wrapper.appendChild(iframe);
21
- };
22
- var mountStyles = function (styles) {
23
- var _a, _b, _c, _d, _e, _f, _g;
24
- var 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, function (m, r, g, b) { return '#' + r + r + g + g + b + b; }).substring(1).match(/.{2}/g)) === null || _c === void 0 ? void 0 : _c.map(function (x) { return parseInt(x, 16); })) !== null && _d !== void 0 ? _d : [107, 114, 128];
25
- background.push((_f = (_e = styles.background) === null || _e === void 0 ? void 0 : _e.opacity) !== null && _f !== void 0 ? _f : 0.75);
26
- document.documentElement.style.setProperty(Styles.BACKGROUND_COLOR, "rgb(".concat(background.join(', '), ")"));
27
- var rounded = (_g = styles.rounded) !== null && _g !== void 0 ? _g : 0;
28
- document.documentElement.style.setProperty(Styles.ROUNDED, "".concat(rounded.toString(), "px"));
29
- };
30
- var unmountLightbox = function (listener) {
31
- var _a;
32
- (_a = document.getElementById(Ids.WRAPPER_ID)) === null || _a === void 0 ? void 0 : _a.remove();
33
- globalThis.removeEventListener('message', listener);
34
- document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
35
- };
@@ -1,18 +0,0 @@
1
- import { mountIFrameElement, mountListener } from './assemblers';
2
- export var LightboxClient = {
3
- init: function (url, options) {
4
- var _a, _b;
5
- var lightbox = {
6
- callbacks: (_a = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _a !== void 0 ? _a : {},
7
- styles: (_b = options === null || options === void 0 ? void 0 : options.styles) !== null && _b !== void 0 ? _b : {},
8
- open: function () {
9
- mountListener(lightbox.callbacks);
10
- mountIFrameElement(url, lightbox.styles);
11
- },
12
- };
13
- if (options === null || options === void 0 ? void 0 : options.dispatch)
14
- lightbox.open();
15
- console.log("lightbox-sdk | client initialized (".concat(url, ")"));
16
- return lightbox;
17
- },
18
- };
@@ -1,9 +0,0 @@
1
- export declare const Styles: {
2
- BACKGROUND_COLOR: string;
3
- ROUNDED: string;
4
- };
5
- export declare const Ids: {
6
- WRAPPER_ID: string;
7
- IFRAME_ID: string;
8
- STYLES_ID: string;
9
- };
@@ -1,9 +0,0 @@
1
- export var Styles = {
2
- BACKGROUND_COLOR: '--placetopay-lightbox-background-color',
3
- ROUNDED: '--placetopay-lightbox-border-radius',
4
- };
5
- export var Ids = {
6
- WRAPPER_ID: 'placetopay_lightbox_wrapper',
7
- IFRAME_ID: 'placetopay_lightbox',
8
- STYLES_ID: 'placetopay-lightbox',
9
- };