@placetopay/lightbox-sdk 2.2.0 → 2.3.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.
@@ -1,5 +1,6 @@
1
1
  import { Styles, ElementIds, LightboxEvents as LE } from '../constants';
2
2
  import { setStyle, unsetStyle, openWithBackup, closePopupByLightboxId, hasOpenedPopup } from '../helpers';
3
+ import { isSafariOrIOS } from './index';
3
4
  let listener;
4
5
  export const mountLightbox = ({ id, url, element, callbacks, styles, closeButtonEnabled, enforceStyles, allowRedirects, backupTarget, }) => {
5
6
  // Only respect allowRedirects for 'self' redirection
@@ -7,10 +8,7 @@ export const mountLightbox = ({ id, url, element, callbacks, styles, closeButton
7
8
  // If allowRedirects is false and backupTarget is 'self', don't redirect
8
9
  return;
9
10
  }
10
- // Check if we need to use fallback behavior for Safari/iOS
11
- const isSafariOrIOS = navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
12
- /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
13
- if (isSafariOrIOS) {
11
+ if (isSafariOrIOS()) {
14
12
  if (window.self !== window.top) {
15
13
  window.parent.postMessage({ type: "placetopay-lightbox:redirect", url }, "*"); // dont change this, it would be a broken change
16
14
  }
@@ -1,5 +1,8 @@
1
1
  import { InitialOptions, LightboxInstance, ApiStructure, LightboxStyles } from '../types';
2
2
  export declare const isInside: () => boolean;
3
+ export declare const isInsideIframe: () => boolean;
4
+ export declare const isInsidePopup: () => boolean;
5
+ export declare const isSafariOrIOS: () => boolean;
3
6
  export declare const updateStyles: (styles: LightboxStyles) => any;
4
7
  export declare const hideCloseButton: () => any;
5
8
  export declare const emitClose: (payload?: unknown, preventClose?: boolean) => void;
@@ -2,6 +2,10 @@ import { LightboxEvents as LE } from '../constants';
2
2
  import { postMessage } from '../helpers';
3
3
  import { mountLightbox, unmountLightbox } from './assemblers';
4
4
  export const isInside = () => globalThis.location !== globalThis.parent.location;
5
+ export const isInsideIframe = () => globalThis.self !== globalThis.top;
6
+ export const isInsidePopup = () => !!globalThis.opener;
7
+ export const isSafariOrIOS = () => /iPhone|iPad|iPod/i.test(navigator.userAgent) ||
8
+ /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
5
9
  export const updateStyles = (styles) => postMessage(LE.UPDATE_STYLES, styles);
6
10
  export const hideCloseButton = () => postMessage(LE.HIDE_CLOSE_BUTTON);
7
11
  export const emitClose = (payload, preventClose) => {
package/dist/helpers.js CHANGED
@@ -11,6 +11,9 @@ export const unsetStyle = (name) => {
11
11
  let openedWindow = null;
12
12
  let backdropElement = null;
13
13
  const openedWindows = {};
14
+ const generatePopupName = (lightboxId) => {
15
+ return lightboxId !== null && lightboxId !== void 0 ? lightboxId : `placetopay_${crypto.randomUUID()}`;
16
+ };
14
17
  // Private translations
15
18
  const translations = {
16
19
  en: {
@@ -35,51 +38,51 @@ export const mountBackdrop = () => {
35
38
  return;
36
39
  backdropElement = document.createElement('div');
37
40
  backdropElement.className = 'placetopay-lightbox-backdrop-overlay';
38
- backdropElement.style.cssText = `
39
- position: fixed;
40
- top: 0;
41
- left: 0;
42
- width: 100%;
43
- height: 100%;
44
- background-color: rgba(0, 0, 0, 0.7);
45
- z-index: 9998;
46
- display: flex;
47
- align-items: center;
48
- justify-content: center;
49
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
41
+ backdropElement.style.cssText = `
42
+ position: fixed;
43
+ top: 0;
44
+ left: 0;
45
+ width: 100%;
46
+ height: 100%;
47
+ background-color: rgba(0, 0, 0, 0.7);
48
+ z-index: 9998;
49
+ display: flex;
50
+ align-items: center;
51
+ justify-content: center;
52
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
50
53
  `;
51
54
  const messageContainer = document.createElement('div');
52
55
  messageContainer.className = 'placetopay-lightbox-backdrop-message-container';
53
- messageContainer.style.cssText = `
54
- background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
55
- border-radius: 16px;
56
- padding: 40px;
57
- max-width: 420px;
58
- margin: 20px;
59
- text-align: center;
60
- box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.1);
61
- backdrop-filter: blur(20px);
62
- border: 1px solid rgba(255, 255, 255, 0.1);
56
+ messageContainer.style.cssText = `
57
+ background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
58
+ border-radius: 16px;
59
+ padding: 40px;
60
+ max-width: 420px;
61
+ margin: 20px;
62
+ text-align: center;
63
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.1);
64
+ backdrop-filter: blur(20px);
65
+ border: 1px solid rgba(255, 255, 255, 0.1);
63
66
  `;
64
67
  const title = document.createElement('h2');
65
68
  title.className = 'placetopay-lightbox-backdrop-title';
66
69
  title.textContent = getText('popupTitle');
67
- title.style.cssText = `
68
- margin: 0 0 20px 0;
69
- font-size: 22px;
70
- font-weight: 700;
71
- color: #ffffff;
72
- text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
70
+ title.style.cssText = `
71
+ margin: 0 0 20px 0;
72
+ font-size: 22px;
73
+ font-weight: 700;
74
+ color: #ffffff;
75
+ text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
73
76
  `;
74
77
  const message = document.createElement('p');
75
78
  message.className = 'placetopay-lightbox-backdrop-message';
76
79
  message.textContent = getText('popupMessage');
77
- message.style.cssText = `
78
- margin: 0;
79
- font-size: 15px;
80
- line-height: 1.6;
81
- color: #d1d5db;
82
- opacity: 0.9;
80
+ message.style.cssText = `
81
+ margin: 0;
82
+ font-size: 15px;
83
+ line-height: 1.6;
84
+ color: #d1d5db;
85
+ opacity: 0.9;
83
86
  `;
84
87
  messageContainer.appendChild(title);
85
88
  messageContainer.appendChild(message);
@@ -119,7 +122,7 @@ export const openWithBackup = (url, backupTarget = 'self', lightboxId) => {
119
122
  // Calculate center position
120
123
  const left = (window.screen.width - popupWidth) / 2;
121
124
  const top = (window.screen.height - popupHeight) / 2;
122
- openedWindow = window.open(url, 'placetopay', `popup=true,width=${popupWidth},height=${popupHeight},left=${left},top=${top}`);
125
+ openedWindow = window.open(url, generatePopupName(lightboxId), `popup=true,width=${popupWidth},height=${popupHeight},left=${left},top=${top}`);
123
126
  break;
124
127
  }
125
128
  case 'self':
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "@placetopay/lightbox-sdk",
3
- "version": "2.2.0",
4
- "description": "Small javascript library to encapsulate websites in a lightbox with configurable styles and behaviors",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "files": [
8
- "/dist"
9
- ],
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/placetopay-org/lightbox-sdk.git"
13
- },
14
- "keywords": [
15
- "lightbox",
16
- "sdk",
17
- "placetopay",
18
- "javascript",
19
- "typescript"
20
- ],
21
- "author": "JuanZea",
22
- "license": "ISC",
23
- "bugs": {
24
- "url": "https://github.com/placetopay-org/lightbox-sdk/issues"
25
- },
26
- "homepage": "https://placetopay-org.github.io/lightbox-sdk",
27
- "devDependencies": {
28
- "typescript": "^5.1.6"
29
- }
30
- }
1
+ {
2
+ "name": "@placetopay/lightbox-sdk",
3
+ "version": "2.3.0",
4
+ "description": "Small javascript library to encapsulate websites in a lightbox with configurable styles and behaviors",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/placetopay-org/lightbox-sdk.git"
13
+ },
14
+ "keywords": [
15
+ "lightbox",
16
+ "sdk",
17
+ "placetopay",
18
+ "javascript",
19
+ "typescript"
20
+ ],
21
+ "author": "JuanZea",
22
+ "license": "ISC",
23
+ "bugs": {
24
+ "url": "https://github.com/placetopay-org/lightbox-sdk/issues"
25
+ },
26
+ "homepage": "https://placetopay-org.github.io/lightbox-sdk",
27
+ "devDependencies": {
28
+ "typescript": "^5.1.6"
29
+ }
30
+ }