@onairosofficial/onairos-capacitor 0.1.0 → 0.1.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.
- package/LICENSE +194 -10
- package/README.md +182 -25
- package/dist/onairos.capacitor.esm.js +1 -0
- package/dist/onairos.capacitor.esm.turbopack.js +1 -0
- package/onairos.d.ts +656 -0
- package/package.json +186 -38
- package/src/OnairosReconnectButton.jsx +272 -0
- package/src/RSA.jsx +57 -0
- package/src/assets/NewLogo.png +0 -0
- package/src/assets/OnairosNewLogo.png +0 -0
- package/src/assets/chatgpt-icon.png +0 -0
- package/src/assets/fire-horse.png +0 -0
- package/src/assets/fire-horse.transparent.png +0 -0
- package/src/assets/latest-firehorse.png +0 -0
- package/src/assets/perplexity.png +0 -0
- package/src/assets/persona.png +0 -0
- package/src/assets/persona1.png +0 -0
- package/src/assets/persona2.png +0 -0
- package/src/assets/persona3.png +0 -0
- package/src/assets/persona4.png +0 -0
- package/src/assets/persona5.png +0 -0
- package/src/capacitorConnectorCatalog.js +38 -0
- package/src/capacitorOAuthConfig.js +52 -0
- package/src/chatgptHostedImport/index.js +303 -0
- package/src/components/AuthButtons.jsx +48 -0
- package/src/components/ConnectChatGPTModal.jsx +666 -0
- package/src/components/ConnectClaudeModal.jsx +610 -0
- package/src/components/ConnectGeminiModal.jsx +639 -0
- package/src/components/ConnectGrokModal.jsx +701 -0
- package/src/components/ConnectPerplexityModal.jsx +726 -0
- package/src/components/DataExplainerScreen.jsx +349 -0
- package/src/components/DataRequest.js +885 -0
- package/src/components/DataRequest.jsx +1055 -0
- package/src/components/EmailAuth.js +1871 -0
- package/src/components/EmailAuth.jsx +2062 -0
- package/src/components/ExtensionInstallPrompt.jsx +142 -0
- package/src/components/GoogleButton.js +133 -0
- package/src/components/LLMConnectorManager.jsx +201 -0
- package/src/components/LoadingPage.jsx +19 -0
- package/src/components/LoadingScreen.jsx +81 -0
- package/src/components/LunarBirthdate.jsx +96 -0
- package/src/components/LunarLoadingPage.jsx +251 -0
- package/src/components/Notification.jsx +21 -0
- package/src/components/OnairosAppButton.jsx +85 -0
- package/src/components/OnairosSSO.jsx +645 -0
- package/src/components/OnairosTrigger.jsx +61 -0
- package/src/components/PerplexityLogo.jsx +43 -0
- package/src/components/PinSetup.js +200 -0
- package/src/components/PinSetup.jsx +228 -0
- package/src/components/SDK_PIN_INTEGRATION_REQUIRED_CHANGES.md +526 -0
- package/src/components/SdkErrorBoundary.jsx +36 -0
- package/src/components/SecuritySetup.js +81 -0
- package/src/components/SessionUserBar.jsx +83 -0
- package/src/components/SignUp.js +123 -0
- package/src/components/TestTelegramButton.js +53 -0
- package/src/components/TrainingComponent.jsx +200 -0
- package/src/components/TrainingScreen.jsx +897 -0
- package/src/components/UniversalOnboarding.js +306 -0
- package/src/components/UniversalOnboarding.jsx +4837 -0
- package/src/components/ValentineLoadingPage.jsx +502 -0
- package/src/components/ValentineModeSelector.jsx +162 -0
- package/src/components/WelcomeScreen.jsx +435 -0
- package/src/components/WrappedLoadingPage.jsx +205 -0
- package/src/components/connectors/ChatGPTConnector.js +348 -0
- package/src/components/connectors/ChatGPTConnector.jsx +348 -0
- package/src/components/connectors/ClaudeConnector.js +44 -0
- package/src/components/connectors/ClaudeConnector.jsx +44 -0
- package/src/components/connectors/GeminiConnector.js +170 -0
- package/src/components/connectors/GeminiConnector.jsx +170 -0
- package/src/components/connectors/GmailConnector.js +148 -0
- package/src/components/connectors/GmailConnector.jsx +148 -0
- package/src/components/connectors/GrokConnector.js +16 -0
- package/src/components/connectors/GrokConnector.jsx +16 -0
- package/src/components/connectors/HingeConnector.js +419 -0
- package/src/components/connectors/HingeConnector.jsx +419 -0
- package/src/components/connectors/InstagramDataConnector.js +726 -0
- package/src/components/connectors/InstagramDataConnector.jsx +726 -0
- package/src/components/connectors/LinkedInConnector.js +4 -0
- package/src/components/connectors/LinkedInConnector.jsx +296 -0
- package/src/components/connectors/PerplexityConnector.jsx +16 -0
- package/src/components/connectors/PinterestConnector.js +208 -0
- package/src/components/connectors/PinterestConnector.jsx +208 -0
- package/src/components/connectors/README.md +292 -0
- package/src/components/connectors/RedditConnector.js +229 -0
- package/src/components/connectors/RedditConnector.jsx +229 -0
- package/src/components/connectors/SephoraConnector.js +482 -0
- package/src/components/connectors/SephoraConnector.jsx +482 -0
- package/src/components/connectors/TikTokConnector.jsx +430 -0
- package/src/components/connectors/YoutubeConnector.js +361 -0
- package/src/components/connectors/YoutubeConnector.jsx +361 -0
- package/src/components/connectors/index.js +50 -0
- package/src/components/icons.jsx +46 -0
- package/src/components/icons.tsx +21 -0
- package/src/components/ui/PageLayout.jsx +1255 -0
- package/src/components/ui/PrimaryButton.jsx +162 -0
- package/src/components/ui/button.jsx +49 -0
- package/src/components/ui/card.jsx +61 -0
- package/src/components/ui/checkbox.jsx +33 -0
- package/src/components/ui/label.jsx +29 -0
- package/src/components/utils/UpdateConnections.js +45 -0
- package/src/components/utils/oauthHelper.js +97 -0
- package/src/config/api-config.js +138 -0
- package/src/deepLink.jsx +38 -0
- package/src/getPin.js +26 -0
- package/src/icons/Avatar.png +0 -0
- package/src/icons/Sentiment.png +0 -0
- package/src/icons/Trait.png +0 -0
- package/src/iframe/DataRequestPage.jsx +285 -0
- package/src/iframe/OnairosButtonIntegration.md +148 -0
- package/src/iframe/components/Box.jsx +56 -0
- package/src/iframe/components/IndividualConnection.jsx +88 -0
- package/src/iframe/dataRequestHandler.js +714 -0
- package/src/iframe/data_request_iframe.html +27 -0
- package/src/iframe/data_request_page.js +47 -0
- package/src/iframe/icons/Avatar.png +1 -0
- package/src/iframe/icons/Avatar2.png +1 -0
- package/src/iframe/icons/Sentiment.png +1 -0
- package/src/iframe/icons/Trait.png +1 -0
- package/src/iframe/icons/onairos_logo.png +0 -0
- package/src/iframe/utils/api.js +57 -0
- package/src/index.js +274 -0
- package/src/laravel/OnairosVue.vue +410 -0
- package/src/laravel/blade-helpers.js +320 -0
- package/src/laravel/vite-plugin.js +179 -0
- package/src/mobile/MobileDataRequestPage.jsx +233 -0
- package/src/mobile/components/MobileBox.jsx +71 -0
- package/src/mobile/components/MobileIndividualConnection.jsx +51 -0
- package/src/mobile/shims/browser-apis.js +78 -0
- package/src/mobile/shims/lucide-shim.js +85 -0
- package/src/newUI/EMAIL_VERIFICATION_API_SCHEMA.md +268 -0
- package/src/newUI/PlatformConnectorsStep.tsx +435 -0
- package/src/newUI/PrimaryButton.tsx +213 -0
- package/src/newUI/SignInStep.tsx +194 -0
- package/src/newUI/VerificationStep.tsx +133 -0
- package/src/newUI/WelcomeScreen.tsx +311 -0
- package/src/newUI/services/connectedAccountsService.js +129 -0
- package/src/onairos.capacitor.jsx +16 -0
- package/src/onairos.core.jsx +133 -0
- package/src/onairos.jsx +14 -0
- package/src/onairos.native.jsx +15 -0
- package/src/onairosButton.jsx +9000 -0
- package/src/overlay/CheckBox.jsx +114 -0
- package/src/overlay/IndividualConnection copy.js +86 -0
- package/src/overlay/IndividualConnection.js +191 -0
- package/src/overlay/IndividualConnectionNew.jsx +157 -0
- package/src/overlay/box.js +84 -0
- package/src/overlay/overlay.js +437 -0
- package/src/styles/onairos-scoped-preflight.css +97 -0
- package/src/styles/sdkCssRegistry.js +20 -0
- package/src/styles/styleLoaderInsertShadow.js +69 -0
- package/src/styles/tailwind.capacitor.css +395 -0
- package/src/styles/tailwind.css +395 -0
- package/src/theme/colors.js +40 -0
- package/src/utils/apiKeyValidation.js +341 -0
- package/src/utils/apiResponseLogger.js +316 -0
- package/src/utils/authHeaders.js +275 -0
- package/src/utils/biometrics.js +26 -0
- package/src/utils/bookmarkletUtils.js +28 -0
- package/src/utils/capacitorDetection.js +278 -0
- package/src/utils/capacitorLLMHelper.js +352 -0
- package/src/utils/capacitorPlugins.js +366 -0
- package/src/utils/crossDomainSSO.js +587 -0
- package/src/utils/deepLinking.js +27 -0
- package/src/utils/devLogger.js +46 -0
- package/src/utils/extensionDetection.js +418 -0
- package/src/utils/extractMemory.js +277 -0
- package/src/utils/framerBrandingOverrides.js +40 -0
- package/src/utils/googleWebClientId.js +55 -0
- package/src/utils/overlayHandler.js +224 -0
- package/src/utils/platformDisconnect.js +309 -0
- package/src/utils/pollTrainingStatus.js +200 -0
- package/src/utils/rawMemoriesAccess.js +211 -0
- package/src/utils/resolveBackendAppId.js +47 -0
- package/src/utils/responseFormatter.js +140 -0
- package/src/utils/sdkDebugStorage.js +113 -0
- package/src/utils/sdkInitialization.js +645 -0
- package/src/utils/sessionManager.js +1258 -0
- package/src/utils/startBackgroundTraining.js +100 -0
- package/src/utils/userDataFormatter.js +222 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -0,0 +1,1255 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import * as ReactDOM from 'react-dom';
|
|
3
|
+
import { COLORS } from '../../theme/colors.js';
|
|
4
|
+
import { getOnairosCssText } from '../../styles/sdkCssRegistry.js';
|
|
5
|
+
|
|
6
|
+
// === CSS Isolation (consumer CSS should not affect SDK modal) ==================
|
|
7
|
+
// Consumer apps often ship Tailwind preflight / global resets that can override
|
|
8
|
+
// SDK UI (fonts, buttons, toggles). Rendering the modal in a ShadowRoot makes
|
|
9
|
+
// the SDK visually identical everywhere.
|
|
10
|
+
function getOnairosCssHref() {
|
|
11
|
+
if (typeof document === 'undefined') return null;
|
|
12
|
+
// Prefer an explicit SDK link if the host provides one.
|
|
13
|
+
const explicit =
|
|
14
|
+
document.querySelector('link#onairos-sdk-css[rel="stylesheet"]') ||
|
|
15
|
+
document.querySelector('link[data-onairos-sdk-css="true"][rel="stylesheet"]');
|
|
16
|
+
if (explicit?.href) return explicit.href;
|
|
17
|
+
|
|
18
|
+
// Fallback: look for any stylesheet link that includes "onairos" in its href.
|
|
19
|
+
const links = Array.from(document.querySelectorAll('link[rel="stylesheet"]'));
|
|
20
|
+
const candidate = links.find((l) => typeof l.href === 'string' && /onairos/i.test(l.href));
|
|
21
|
+
if (candidate?.href) return candidate.href;
|
|
22
|
+
|
|
23
|
+
// If we can't find an SDK stylesheet link, do NOT guess.
|
|
24
|
+
// Many consumer apps won't serve a hardcoded `/onairos-sdk.css`, which would lead
|
|
25
|
+
// to an unstyled Shadow DOM modal. We'll fall back to the non-shadow portal instead.
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isOnairosOauthRestore() {
|
|
30
|
+
if (typeof window === 'undefined') return false;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const hasOauthParams = (raw) => {
|
|
34
|
+
if (!raw) return false;
|
|
35
|
+
const query = raw.startsWith('?') ? raw.slice(1) : raw;
|
|
36
|
+
const params = new URLSearchParams(query);
|
|
37
|
+
return (
|
|
38
|
+
params.has('onairos_oauth_success') ||
|
|
39
|
+
params.has('onairos_oauth_platform') ||
|
|
40
|
+
params.has('onairos_oauth_error')
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (hasOauthParams(window.location.search || '')) return true;
|
|
45
|
+
const hash = window.location.hash || '';
|
|
46
|
+
if (hash.includes('?') && hasOauthParams(hash.slice(hash.indexOf('?')))) return true;
|
|
47
|
+
} catch (_) {}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
if (sessionStorage.getItem('onairos_in_onboarding_flow') === 'true') return true;
|
|
51
|
+
if (sessionStorage.getItem('onairos_oauth_return_success')) return true;
|
|
52
|
+
} catch (_) {}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
if (localStorage.getItem('onairos_post_oauth_flow') !== 'onboarding') return false;
|
|
56
|
+
const sameTabTs = parseInt(localStorage.getItem('onairos_same_tab_oauth_ts') || '', 10);
|
|
57
|
+
const contextTs = parseInt(localStorage.getItem('onairos_oauth_context_ts') || '', 10);
|
|
58
|
+
const isRecent = (ts) => Number.isFinite(ts) && Date.now() - ts < 10 * 60 * 1000;
|
|
59
|
+
return isRecent(sameTabTs) || isRecent(contextTs);
|
|
60
|
+
} catch (_) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function ensureOnairosModalShadowMount() {
|
|
66
|
+
if (typeof document === 'undefined') return null;
|
|
67
|
+
if (!document.body) return null;
|
|
68
|
+
if (typeof HTMLElement === 'undefined' || !HTMLElement.prototype.attachShadow) return null;
|
|
69
|
+
|
|
70
|
+
const hostId = 'onairos-modal-shadow-host';
|
|
71
|
+
|
|
72
|
+
function shadowAlreadyHasSdkStyles(shadowRoot) {
|
|
73
|
+
try {
|
|
74
|
+
// Capacitor bundle injects compiled CSS text into shadow.
|
|
75
|
+
if (shadowRoot.querySelector('style[data-onairos-shadow-css-text="true"]')) return true;
|
|
76
|
+
// Host-provided link mode (web/other).
|
|
77
|
+
if (shadowRoot.querySelector('link[data-onairos-shadow-css="true"]')) return true;
|
|
78
|
+
return false;
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let host = document.getElementById(hostId);
|
|
85
|
+
// If a host already exists (likely created by Capacitor CSS injection), allow shadow portal
|
|
86
|
+
// even if we can't discover a stylesheet href.
|
|
87
|
+
if (host && host.shadowRoot && shadowAlreadyHasSdkStyles(host.shadowRoot)) {
|
|
88
|
+
let mount = host.shadowRoot.querySelector('#onairos-modal-shadow-mount');
|
|
89
|
+
if (!mount) {
|
|
90
|
+
mount = document.createElement('div');
|
|
91
|
+
mount.id = 'onairos-modal-shadow-mount';
|
|
92
|
+
host.shadowRoot.appendChild(mount);
|
|
93
|
+
}
|
|
94
|
+
return mount;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Otherwise, fall back to the "host provides a stylesheet link" approach.
|
|
98
|
+
const cssText = getOnairosCssText();
|
|
99
|
+
const href = cssText ? null : getOnairosCssHref();
|
|
100
|
+
if (!cssText && !href) return null;
|
|
101
|
+
|
|
102
|
+
if (!host) {
|
|
103
|
+
host = document.createElement('div');
|
|
104
|
+
host.id = hostId;
|
|
105
|
+
// Keep the host inert; the actual modal backdrop handles pointer events.
|
|
106
|
+
host.style.all = 'initial';
|
|
107
|
+
document.body.appendChild(host);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const shadow = host.shadowRoot || host.attachShadow({ mode: 'open' });
|
|
111
|
+
|
|
112
|
+
// Minimal shadow reset so browser defaults are predictable, while letting the
|
|
113
|
+
// SDK stylesheet fully own visuals.
|
|
114
|
+
if (!shadow.querySelector('style[data-onairos-shadow-reset="true"]')) {
|
|
115
|
+
const style = document.createElement('style');
|
|
116
|
+
style.setAttribute('data-onairos-shadow-reset', 'true');
|
|
117
|
+
style.textContent = `
|
|
118
|
+
:host { all: initial; }
|
|
119
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
120
|
+
`;
|
|
121
|
+
shadow.appendChild(style);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Load SDK styles inside the shadow root so host CSS can't win the cascade.
|
|
125
|
+
if (cssText) {
|
|
126
|
+
if (!shadow.querySelector('style[data-onairos-shadow-css-text="true"]')) {
|
|
127
|
+
const style = document.createElement('style');
|
|
128
|
+
style.setAttribute('data-onairos-shadow-css-text', 'true');
|
|
129
|
+
style.textContent = cssText;
|
|
130
|
+
shadow.appendChild(style);
|
|
131
|
+
}
|
|
132
|
+
} else if (href) {
|
|
133
|
+
if (!shadow.querySelector('link[data-onairos-shadow-css="true"]')) {
|
|
134
|
+
const link = document.createElement('link');
|
|
135
|
+
link.rel = 'stylesheet';
|
|
136
|
+
link.href = href;
|
|
137
|
+
link.setAttribute('data-onairos-shadow-css', 'true');
|
|
138
|
+
shadow.appendChild(link);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let mount = shadow.querySelector('#onairos-modal-shadow-mount');
|
|
143
|
+
if (!mount) {
|
|
144
|
+
mount = document.createElement('div');
|
|
145
|
+
mount.id = 'onairos-modal-shadow-mount';
|
|
146
|
+
shadow.appendChild(mount);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return mount;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Standardized page layout component with white background
|
|
153
|
+
const PageLayout = ({
|
|
154
|
+
children,
|
|
155
|
+
title,
|
|
156
|
+
subtitle,
|
|
157
|
+
icon,
|
|
158
|
+
showHeader = true,
|
|
159
|
+
showCloseButton = false,
|
|
160
|
+
onClose,
|
|
161
|
+
onBack,
|
|
162
|
+
showBackButton = false,
|
|
163
|
+
className = '',
|
|
164
|
+
contentClassName = '',
|
|
165
|
+
centerContent = true,
|
|
166
|
+
style = {},
|
|
167
|
+
theme = 'default',
|
|
168
|
+
...props
|
|
169
|
+
}) => {
|
|
170
|
+
const isGlass = theme === 'glass';
|
|
171
|
+
const isSmallScreen = typeof window !== 'undefined' && window.innerWidth <= 768;
|
|
172
|
+
// If the caller passes a Tailwind override like "!p-0", we must respect it in inline styles.
|
|
173
|
+
// Inline styles override classes, so we mirror the intent here.
|
|
174
|
+
const disableContentPadding =
|
|
175
|
+
typeof contentClassName === 'string' &&
|
|
176
|
+
(contentClassName.includes('!p-0') || contentClassName.includes('p-0'));
|
|
177
|
+
|
|
178
|
+
const layoutStyle = {
|
|
179
|
+
backgroundColor: isGlass ? 'transparent' : COLORS.background,
|
|
180
|
+
minHeight: '100%',
|
|
181
|
+
width: '100%',
|
|
182
|
+
display: 'flex',
|
|
183
|
+
flexDirection: 'column',
|
|
184
|
+
...style
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const headerStyle = {
|
|
188
|
+
position: 'sticky',
|
|
189
|
+
top: 0,
|
|
190
|
+
backgroundColor: isGlass ? 'transparent' : COLORS.background,
|
|
191
|
+
zIndex: 10,
|
|
192
|
+
padding: isSmallScreen
|
|
193
|
+
? '6px 16px 4px'
|
|
194
|
+
: 'clamp(4px, 1vw, 8px) clamp(16px, 4vw, 32px) clamp(2px, 1vw, 6px)'
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const contentStyle = {
|
|
198
|
+
flex: 1,
|
|
199
|
+
padding: disableContentPadding ? '0' : (isSmallScreen ? '16px 16px 18px' : 'clamp(16px, 4vw, 32px)'),
|
|
200
|
+
display: 'flex',
|
|
201
|
+
flexDirection: 'column',
|
|
202
|
+
overflow: 'auto',
|
|
203
|
+
minHeight: 0, // Allow flex item to shrink below content size
|
|
204
|
+
...(centerContent && {
|
|
205
|
+
alignItems: 'center',
|
|
206
|
+
justifyContent: 'flex-start'
|
|
207
|
+
})
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const titleStyle = {
|
|
211
|
+
fontFamily: 'IBM Plex Sans, system-ui, sans-serif',
|
|
212
|
+
fontSize: 'clamp(20px, 5vw, 28px)',
|
|
213
|
+
fontWeight: '700',
|
|
214
|
+
color: isGlass ? '#FFFFFF' : COLORS.textPrimary,
|
|
215
|
+
margin: '0 0 clamp(6px, 1.5vw, 12px) 0',
|
|
216
|
+
textAlign: centerContent ? 'center' : 'left',
|
|
217
|
+
lineHeight: '1.2'
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const subtitleStyle = {
|
|
221
|
+
fontFamily: 'Inter, system-ui, sans-serif',
|
|
222
|
+
fontSize: 'clamp(14px, 3.5vw, 18px)',
|
|
223
|
+
fontWeight: '400',
|
|
224
|
+
color: isGlass ? 'rgba(255, 255, 255, 0.7)' : COLORS.textSecondary,
|
|
225
|
+
margin: isSmallScreen ? '0 0 18px 0' : '0 0 clamp(20px, 5vw, 40px) 0',
|
|
226
|
+
textAlign: centerContent ? 'center' : 'left',
|
|
227
|
+
lineHeight: '1.5'
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const iconStyle = {
|
|
231
|
+
width: 'clamp(40px, 8vw, 56px)',
|
|
232
|
+
height: 'clamp(40px, 8vw, 56px)',
|
|
233
|
+
margin: '0 auto clamp(16px, 4vw, 32px)',
|
|
234
|
+
display: 'flex',
|
|
235
|
+
alignItems: 'center',
|
|
236
|
+
justifyContent: 'center',
|
|
237
|
+
fontSize: 'clamp(20px, 5vw, 28px)'
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<div
|
|
242
|
+
className={`onairos-page-layout ${className}`}
|
|
243
|
+
style={layoutStyle}
|
|
244
|
+
{...props}
|
|
245
|
+
>
|
|
246
|
+
{/* Header with navigation */}
|
|
247
|
+
{showHeader && (
|
|
248
|
+
<div style={headerStyle}>
|
|
249
|
+
<div className="flex items-center justify-between">
|
|
250
|
+
{/* Left side: Close button (always on left when present) */}
|
|
251
|
+
<div className="flex items-center">
|
|
252
|
+
{showCloseButton && onClose && (
|
|
253
|
+
<button
|
|
254
|
+
onClick={(e) => {
|
|
255
|
+
try { e.preventDefault(); e.stopPropagation(); } catch {}
|
|
256
|
+
onClose();
|
|
257
|
+
}}
|
|
258
|
+
className={`flex items-center justify-center w-12 h-12 rounded-full transition-colors ${isGlass ? 'hover:bg-white/10' : 'hover:bg-gray-100'}`}
|
|
259
|
+
aria-label="Close"
|
|
260
|
+
type="button"
|
|
261
|
+
>
|
|
262
|
+
<span style={{ fontSize: '28px', fontWeight: '300', color: isGlass ? '#FFFFFF' : COLORS.textPrimary }}>×</span>
|
|
263
|
+
</button>
|
|
264
|
+
)}
|
|
265
|
+
{/* Invisible spacer when no close button to maintain layout */}
|
|
266
|
+
{!showCloseButton && <div className="w-12 h-12" aria-hidden="true" />}
|
|
267
|
+
</div>
|
|
268
|
+
|
|
269
|
+
{/* Right side: Back button (when present) */}
|
|
270
|
+
<div className="flex items-center">
|
|
271
|
+
{showBackButton && onBack && (
|
|
272
|
+
<button
|
|
273
|
+
onClick={onBack}
|
|
274
|
+
className="flex items-center justify-center w-8 h-8 rounded-full hover:bg-gray-100 transition-colors"
|
|
275
|
+
aria-label="Go back"
|
|
276
|
+
type="button"
|
|
277
|
+
>
|
|
278
|
+
<span style={{ fontSize: '16px', color: isGlass ? '#FFFFFF' : COLORS.textPrimary }}>←</span>
|
|
279
|
+
</button>
|
|
280
|
+
)}
|
|
281
|
+
{/* Invisible spacer when no back button to maintain layout */}
|
|
282
|
+
{!showBackButton && <div className="w-8 h-8" aria-hidden="true" />}
|
|
283
|
+
</div>
|
|
284
|
+
</div>
|
|
285
|
+
</div>
|
|
286
|
+
)}
|
|
287
|
+
|
|
288
|
+
{/* Main content area */}
|
|
289
|
+
<div
|
|
290
|
+
className={`onairos-page-content ${contentClassName}`}
|
|
291
|
+
style={contentStyle}
|
|
292
|
+
>
|
|
293
|
+
{/* Icon */}
|
|
294
|
+
{icon && (
|
|
295
|
+
<div style={iconStyle}>
|
|
296
|
+
{typeof icon === 'string' ? <span>{icon}</span> : icon}
|
|
297
|
+
</div>
|
|
298
|
+
)}
|
|
299
|
+
|
|
300
|
+
{/* Title */}
|
|
301
|
+
{title && (
|
|
302
|
+
<h1 style={titleStyle}>
|
|
303
|
+
{title}
|
|
304
|
+
</h1>
|
|
305
|
+
)}
|
|
306
|
+
|
|
307
|
+
{/* Subtitle */}
|
|
308
|
+
{subtitle && (
|
|
309
|
+
<p style={subtitleStyle}>
|
|
310
|
+
{subtitle}
|
|
311
|
+
</p>
|
|
312
|
+
)}
|
|
313
|
+
|
|
314
|
+
{/* Page content */}
|
|
315
|
+
{children}
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// Modal wrapper component for overlay-style pages
|
|
322
|
+
const ModalPageLayout = ({
|
|
323
|
+
children,
|
|
324
|
+
visible = true,
|
|
325
|
+
exiting = false,
|
|
326
|
+
onClose,
|
|
327
|
+
onBackdropClick,
|
|
328
|
+
backdropStyle = {},
|
|
329
|
+
modalStyle = {},
|
|
330
|
+
modalClassName = '',
|
|
331
|
+
usePortal = false,
|
|
332
|
+
// If true, renders the modal into a ShadowRoot to prevent consumer CSS from
|
|
333
|
+
// overriding SDK styles. Only safe when the SDK stylesheet is available to load
|
|
334
|
+
// inside the ShadowRoot. Otherwise, we fall back to normal portal rendering.
|
|
335
|
+
useShadowPortal = true,
|
|
336
|
+
// When true, render the flow INLINE (in normal document flow) filling the host
|
|
337
|
+
// container instead of as a fixed, full-screen, portaled overlay. The backdrop
|
|
338
|
+
// becomes a relative, transparent, full-size container and the modal stretches
|
|
339
|
+
// to 100% of its parent. Lets hosts embed the SDK in a chat panel / sidebar.
|
|
340
|
+
inline = false,
|
|
341
|
+
showGradientBorder = true, // New prop to enable/disable animated gradient border
|
|
342
|
+
gradientBorderStyle = 'rotate', // 'rotate' | 'shimmer' | 'none'
|
|
343
|
+
theme = 'default', // 'default' | 'glass' - glass enables frosted blur effect
|
|
344
|
+
...pageLayoutProps
|
|
345
|
+
}) => {
|
|
346
|
+
if (!visible) return null;
|
|
347
|
+
|
|
348
|
+
// Debug logging in this component can be extremely noisy because it's called during render.
|
|
349
|
+
// On iOS WKWebView (Capacitor), excessive console logging can overwhelm the bridge and lead to
|
|
350
|
+
// apparent "white screen" freezes. Keep layout logging opt-in only.
|
|
351
|
+
const shouldLayoutDebug =
|
|
352
|
+
typeof window !== 'undefined' && !!window.onairosDebugLayout;
|
|
353
|
+
const isOauthRestore = isOnairosOauthRestore();
|
|
354
|
+
|
|
355
|
+
// Detect Capacitor native platform
|
|
356
|
+
// Must be defined BEFORE usage to avoid Temporal Dead Zone (TDZ) error
|
|
357
|
+
const isCapacitorNative = typeof window !== 'undefined' &&
|
|
358
|
+
window.Capacitor &&
|
|
359
|
+
typeof window.Capacitor.isNativePlatform === 'function' &&
|
|
360
|
+
window.Capacitor.isNativePlatform();
|
|
361
|
+
|
|
362
|
+
// Detect mobile browser (not Capacitor native) from device signal, not viewport width.
|
|
363
|
+
// Embedded desktop SDKs can have narrow widths but should still use desktop modal.
|
|
364
|
+
const isMobileBrowser = (() => {
|
|
365
|
+
if (isCapacitorNative) return false;
|
|
366
|
+
if (typeof navigator === 'undefined') return false;
|
|
367
|
+
const ua = navigator.userAgent || '';
|
|
368
|
+
const isMobileUA = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
|
|
369
|
+
const isMobileUAData = navigator.userAgentData?.mobile === true;
|
|
370
|
+
const isIPadOSDesktopUA = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
|
|
371
|
+
return isMobileUA || isMobileUAData || isIPadOSDesktopUA;
|
|
372
|
+
})();
|
|
373
|
+
|
|
374
|
+
const [layoutViewport, setLayoutViewport] = useState(() => {
|
|
375
|
+
if (typeof window === 'undefined') {
|
|
376
|
+
return { width: 1280, height: 900 };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
width: window.visualViewport?.width || window.innerWidth,
|
|
381
|
+
height: window.visualViewport?.height || window.innerHeight,
|
|
382
|
+
offsetLeft: window.visualViewport?.offsetLeft || 0,
|
|
383
|
+
offsetTop: window.visualViewport?.offsetTop || 0,
|
|
384
|
+
keyboardOpen: false,
|
|
385
|
+
keyboardInset: 0,
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
const mobileViewportBaselineHeightRef = useRef(0);
|
|
389
|
+
|
|
390
|
+
useEffect(() => {
|
|
391
|
+
if (typeof window === 'undefined') return;
|
|
392
|
+
|
|
393
|
+
const isTextEntryFocused = () => {
|
|
394
|
+
if (typeof document === 'undefined') return false;
|
|
395
|
+
const el = document.activeElement;
|
|
396
|
+
if (!el || el === document.body) return false;
|
|
397
|
+
const tag = String(el.tagName || '').toLowerCase();
|
|
398
|
+
if (tag === 'textarea') return true;
|
|
399
|
+
if (tag === 'input') {
|
|
400
|
+
const type = String(el.type || '').toLowerCase();
|
|
401
|
+
return !['checkbox', 'radio', 'range', 'button', 'submit', 'reset', 'file', 'image', 'color'].includes(type);
|
|
402
|
+
}
|
|
403
|
+
return !!el.isContentEditable;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const syncLayoutViewport = () => {
|
|
407
|
+
const visualViewport = window.visualViewport;
|
|
408
|
+
const visualHeight = visualViewport?.height || window.innerHeight;
|
|
409
|
+
const keyboardOpenByInnerDiff = !!(
|
|
410
|
+
visualViewport &&
|
|
411
|
+
window.innerHeight - visualHeight > 120
|
|
412
|
+
);
|
|
413
|
+
const inputFocused = isTextEntryFocused();
|
|
414
|
+
const nextViewport = {
|
|
415
|
+
width: visualViewport?.width || window.innerWidth,
|
|
416
|
+
height: visualHeight,
|
|
417
|
+
offsetLeft: visualViewport?.offsetLeft || 0,
|
|
418
|
+
offsetTop: visualViewport?.offsetTop || 0,
|
|
419
|
+
keyboardOpen: keyboardOpenByInnerDiff,
|
|
420
|
+
keyboardInset: 0,
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
setLayoutViewport((prevViewport) => {
|
|
424
|
+
if (isMobileBrowser && !inputFocused) {
|
|
425
|
+
const baselineCandidate = Math.max(
|
|
426
|
+
prevViewport?.height || 0,
|
|
427
|
+
nextViewport.height || 0
|
|
428
|
+
);
|
|
429
|
+
if (baselineCandidate > mobileViewportBaselineHeightRef.current) {
|
|
430
|
+
mobileViewportBaselineHeightRef.current = baselineCandidate;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const baselineHeight = mobileViewportBaselineHeightRef.current || prevViewport?.height || nextViewport.height;
|
|
435
|
+
const keyboardOpenByBaselineDrop = !!(
|
|
436
|
+
isMobileBrowser &&
|
|
437
|
+
inputFocused &&
|
|
438
|
+
baselineHeight - nextViewport.height > 80
|
|
439
|
+
);
|
|
440
|
+
const keyboardOpen = keyboardOpenByInnerDiff || keyboardOpenByBaselineDrop;
|
|
441
|
+
const keyboardInset = keyboardOpen
|
|
442
|
+
? Math.max(0, Math.round(baselineHeight - nextViewport.height))
|
|
443
|
+
: 0;
|
|
444
|
+
|
|
445
|
+
// iOS/Android in-app browsers can shrink visualViewport aggressively when keyboard opens,
|
|
446
|
+
// which makes the SDK sheet appear cut in half. Keep the pre-keyboard frame while typing.
|
|
447
|
+
if (isMobileBrowser && keyboardOpen && prevViewport?.height) {
|
|
448
|
+
return {
|
|
449
|
+
...nextViewport,
|
|
450
|
+
width: prevViewport.width || nextViewport.width,
|
|
451
|
+
height: prevViewport.height,
|
|
452
|
+
offsetLeft: prevViewport.offsetLeft || 0,
|
|
453
|
+
offsetTop: prevViewport.offsetTop || 0,
|
|
454
|
+
keyboardOpen: true,
|
|
455
|
+
keyboardInset,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
...nextViewport,
|
|
460
|
+
keyboardOpen,
|
|
461
|
+
keyboardInset,
|
|
462
|
+
};
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
syncLayoutViewport();
|
|
467
|
+
|
|
468
|
+
const visualViewport = window.visualViewport;
|
|
469
|
+
window.addEventListener('resize', syncLayoutViewport);
|
|
470
|
+
window.addEventListener('orientationchange', syncLayoutViewport);
|
|
471
|
+
visualViewport?.addEventListener('resize', syncLayoutViewport);
|
|
472
|
+
visualViewport?.addEventListener('scroll', syncLayoutViewport);
|
|
473
|
+
|
|
474
|
+
return () => {
|
|
475
|
+
window.removeEventListener('resize', syncLayoutViewport);
|
|
476
|
+
window.removeEventListener('orientationchange', syncLayoutViewport);
|
|
477
|
+
visualViewport?.removeEventListener('resize', syncLayoutViewport);
|
|
478
|
+
visualViewport?.removeEventListener('scroll', syncLayoutViewport);
|
|
479
|
+
};
|
|
480
|
+
}, [isMobileBrowser]);
|
|
481
|
+
|
|
482
|
+
const viewportWidth = layoutViewport.width;
|
|
483
|
+
const viewportHeight = layoutViewport.height;
|
|
484
|
+
const viewportOffsetLeft = layoutViewport.offsetLeft || 0;
|
|
485
|
+
const viewportOffsetTop = layoutViewport.offsetTop || 0;
|
|
486
|
+
const isKeyboardOpen = !!layoutViewport.keyboardOpen;
|
|
487
|
+
const keyboardInsetPx = Math.max(0, layoutViewport.keyboardInset || 0);
|
|
488
|
+
|
|
489
|
+
// Prevent FOUC (Flash of Unstyled Content) while CSS is loading.
|
|
490
|
+
// style-loader injects CSS asynchronously, so we need to wait for styles to be ready.
|
|
491
|
+
// This applies to ALL environments, not just shadow portal cases.
|
|
492
|
+
const [stylesReady, setStylesReady] = useState(() => {
|
|
493
|
+
if (isOauthRestore) return true;
|
|
494
|
+
if (typeof document === 'undefined') return true;
|
|
495
|
+
// Check if SDK styles are already in the document
|
|
496
|
+
// For ESM builds with style-loader, check if the onairos styles are present
|
|
497
|
+
const hasOnairosStyles = (() => {
|
|
498
|
+
try {
|
|
499
|
+
// Check for inline styles from style-loader
|
|
500
|
+
const styleSheets = Array.from(document.styleSheets);
|
|
501
|
+
for (const sheet of styleSheets) {
|
|
502
|
+
try {
|
|
503
|
+
const rules = sheet.cssRules || sheet.rules;
|
|
504
|
+
if (rules && rules.length > 0) {
|
|
505
|
+
// Look for onairos-specific selectors
|
|
506
|
+
for (let i = 0; i < Math.min(rules.length, 20); i++) {
|
|
507
|
+
const rule = rules[i];
|
|
508
|
+
if (rule.selectorText && /\.onairos-|onairos-modal/.test(rule.selectorText)) {
|
|
509
|
+
return true;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
} catch {
|
|
514
|
+
// CORS can block accessing cssRules
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
// Also check for linked stylesheets with onairos in href
|
|
518
|
+
const links = document.querySelectorAll('link[rel="stylesheet"]');
|
|
519
|
+
for (const link of links) {
|
|
520
|
+
if (link.href && /onairos/i.test(link.href)) {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return false;
|
|
525
|
+
} catch {
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
})();
|
|
529
|
+
return hasOnairosStyles;
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
useEffect(() => {
|
|
533
|
+
if (typeof document === 'undefined') return;
|
|
534
|
+
|
|
535
|
+
// Check if styles are already ready
|
|
536
|
+
const checkStylesReady = () => {
|
|
537
|
+
try {
|
|
538
|
+
const styleSheets = Array.from(document.styleSheets);
|
|
539
|
+
for (const sheet of styleSheets) {
|
|
540
|
+
try {
|
|
541
|
+
const rules = sheet.cssRules || sheet.rules;
|
|
542
|
+
if (rules && rules.length > 0) {
|
|
543
|
+
for (let i = 0; i < Math.min(rules.length, 20); i++) {
|
|
544
|
+
const rule = rules[i];
|
|
545
|
+
if (rule.selectorText && /\.onairos-|onairos-modal/.test(rule.selectorText)) {
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
} catch {
|
|
551
|
+
// CORS can block accessing cssRules
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return false;
|
|
555
|
+
} catch {
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// If already ready, no need to poll
|
|
561
|
+
if (checkStylesReady()) {
|
|
562
|
+
setStylesReady(true);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// Poll for styles to be injected (style-loader is async)
|
|
567
|
+
let attempts = 0;
|
|
568
|
+
const maxAttempts = 20;
|
|
569
|
+
const pollInterval = 50; // 50ms intervals, max 1 second total
|
|
570
|
+
|
|
571
|
+
const poll = setInterval(() => {
|
|
572
|
+
attempts++;
|
|
573
|
+
if (checkStylesReady()) {
|
|
574
|
+
setStylesReady(true);
|
|
575
|
+
clearInterval(poll);
|
|
576
|
+
} else if (attempts >= maxAttempts) {
|
|
577
|
+
// Fallback: show content anyway after max wait
|
|
578
|
+
setStylesReady(true);
|
|
579
|
+
clearInterval(poll);
|
|
580
|
+
}
|
|
581
|
+
}, pollInterval);
|
|
582
|
+
|
|
583
|
+
// Also handle shadow portal case for mobile browser
|
|
584
|
+
if (useShadowPortal && isMobileBrowser && !isCapacitorNative) {
|
|
585
|
+
const shadowMount = ensureOnairosModalShadowMount();
|
|
586
|
+
const shadow = shadowMount?.getRootNode?.() || null;
|
|
587
|
+
const shadowRoot = shadow && shadow.host ? shadow : null;
|
|
588
|
+
|
|
589
|
+
if (shadowRoot && shadowRoot.querySelector) {
|
|
590
|
+
// If CSS text is injected, it's already present synchronously.
|
|
591
|
+
if (shadowRoot.querySelector('style[data-onairos-shadow-css-text="true"]')) {
|
|
592
|
+
setStylesReady(true);
|
|
593
|
+
clearInterval(poll);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
const link = shadowRoot.querySelector('link[data-onairos-shadow-css="true"]');
|
|
598
|
+
if (link) {
|
|
599
|
+
const onLoad = () => {
|
|
600
|
+
setStylesReady(true);
|
|
601
|
+
clearInterval(poll);
|
|
602
|
+
};
|
|
603
|
+
try { link.addEventListener('load', onLoad); } catch (_) {}
|
|
604
|
+
|
|
605
|
+
// Check if already loaded
|
|
606
|
+
try {
|
|
607
|
+
if (link.sheet) {
|
|
608
|
+
onLoad();
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
} catch (_) {}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
return () => {
|
|
617
|
+
clearInterval(poll);
|
|
618
|
+
};
|
|
619
|
+
}, [useShadowPortal, isMobileBrowser, isCapacitorNative]);
|
|
620
|
+
|
|
621
|
+
const shouldUseAdaptiveSheet = false;
|
|
622
|
+
|
|
623
|
+
// Mobile browser: bottom sheet.
|
|
624
|
+
// Capacitor native: tall bottom sheet so CTAs remain clear of the sheet edge.
|
|
625
|
+
// Compact laptop windows/tablets: also use the sheet layout instead of forcing a desktop dialog.
|
|
626
|
+
const isMobileModal = isMobileBrowser || isCapacitorNative || shouldUseAdaptiveSheet;
|
|
627
|
+
const isCapacitorFullscreen = false;
|
|
628
|
+
|
|
629
|
+
useEffect(() => {
|
|
630
|
+
if (typeof document === 'undefined') return;
|
|
631
|
+
if (!isMobileModal) return;
|
|
632
|
+
|
|
633
|
+
let viewportMeta = document.querySelector('meta[name="viewport"]');
|
|
634
|
+
const createdViewportMeta = !viewportMeta;
|
|
635
|
+
const previousContent = viewportMeta?.getAttribute('content') || '';
|
|
636
|
+
|
|
637
|
+
if (!viewportMeta) {
|
|
638
|
+
viewportMeta = document.createElement('meta');
|
|
639
|
+
viewportMeta.setAttribute('name', 'viewport');
|
|
640
|
+
document.head?.appendChild(viewportMeta);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
viewportMeta.setAttribute(
|
|
644
|
+
'content',
|
|
645
|
+
'width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover'
|
|
646
|
+
);
|
|
647
|
+
|
|
648
|
+
return () => {
|
|
649
|
+
try {
|
|
650
|
+
if (createdViewportMeta) {
|
|
651
|
+
viewportMeta?.parentNode?.removeChild(viewportMeta);
|
|
652
|
+
} else {
|
|
653
|
+
viewportMeta?.setAttribute('content', previousContent);
|
|
654
|
+
}
|
|
655
|
+
} catch (_) {}
|
|
656
|
+
};
|
|
657
|
+
}, [isMobileModal]);
|
|
658
|
+
|
|
659
|
+
useEffect(() => {
|
|
660
|
+
if (typeof document === 'undefined') return;
|
|
661
|
+
if (!isMobileModal) return;
|
|
662
|
+
|
|
663
|
+
const html = document.documentElement;
|
|
664
|
+
const body = document.body;
|
|
665
|
+
if (!html || !body) return;
|
|
666
|
+
|
|
667
|
+
const prev = {
|
|
668
|
+
htmlOverflow: html.style.overflow,
|
|
669
|
+
htmlOverscrollBehavior: html.style.overscrollBehavior,
|
|
670
|
+
bodyOverflow: body.style.overflow,
|
|
671
|
+
bodyPosition: body.style.position,
|
|
672
|
+
bodyWidth: body.style.width,
|
|
673
|
+
bodyTop: body.style.top,
|
|
674
|
+
bodyOverscrollBehavior: body.style.overscrollBehavior,
|
|
675
|
+
scrollY: window.scrollY || window.pageYOffset || 0,
|
|
676
|
+
};
|
|
677
|
+
const shouldFreezeBody = !isMobileBrowser;
|
|
678
|
+
|
|
679
|
+
html.style.overflow = 'hidden';
|
|
680
|
+
html.style.overscrollBehavior = 'none';
|
|
681
|
+
body.style.overflow = 'hidden';
|
|
682
|
+
if (shouldFreezeBody) {
|
|
683
|
+
body.style.position = 'fixed';
|
|
684
|
+
body.style.width = '100%';
|
|
685
|
+
body.style.top = `-${prev.scrollY}px`;
|
|
686
|
+
}
|
|
687
|
+
body.style.overscrollBehavior = 'none';
|
|
688
|
+
|
|
689
|
+
let lastTouchY = 0;
|
|
690
|
+
const getScrollableAncestor = (start) => {
|
|
691
|
+
let node = start;
|
|
692
|
+
while (node && node !== document.body && node !== document.documentElement) {
|
|
693
|
+
try {
|
|
694
|
+
if (node.nodeType === 1) {
|
|
695
|
+
const style = window.getComputedStyle(node);
|
|
696
|
+
const overflowY = style.overflowY || style.overflow;
|
|
697
|
+
const canScroll = /(auto|scroll|overlay)/i.test(overflowY) && node.scrollHeight > node.clientHeight + 1;
|
|
698
|
+
if (canScroll) return node;
|
|
699
|
+
}
|
|
700
|
+
} catch (_) {}
|
|
701
|
+
node = node.parentNode || (node.host || null);
|
|
702
|
+
}
|
|
703
|
+
return null;
|
|
704
|
+
};
|
|
705
|
+
const isInsideModal = (target) => {
|
|
706
|
+
try {
|
|
707
|
+
return !!(target && target.closest && target.closest('[data-onairos-modal="true"]'));
|
|
708
|
+
} catch (_) {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
const shouldBlockScroll = (target, deltaY) => {
|
|
713
|
+
if (!isInsideModal(target)) return true;
|
|
714
|
+
const scrollable = getScrollableAncestor(target);
|
|
715
|
+
if (!scrollable) return true;
|
|
716
|
+
const atTop = scrollable.scrollTop <= 0;
|
|
717
|
+
const atBottom = scrollable.scrollTop + scrollable.clientHeight >= scrollable.scrollHeight - 1;
|
|
718
|
+
return (deltaY < 0 && atTop) || (deltaY > 0 && atBottom);
|
|
719
|
+
};
|
|
720
|
+
const getEventTarget = (event) => {
|
|
721
|
+
try {
|
|
722
|
+
const path = event.composedPath?.();
|
|
723
|
+
return path && path.length ? path[0] : event.target;
|
|
724
|
+
} catch (_) {
|
|
725
|
+
return event.target;
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
const onTouchStart = (event) => {
|
|
729
|
+
try { lastTouchY = event.touches?.[0]?.clientY || 0; } catch (_) {}
|
|
730
|
+
};
|
|
731
|
+
const onTouchMove = (event) => {
|
|
732
|
+
const y = event.touches?.[0]?.clientY || 0;
|
|
733
|
+
const deltaY = lastTouchY - y;
|
|
734
|
+
lastTouchY = y;
|
|
735
|
+
if (shouldBlockScroll(getEventTarget(event), deltaY)) event.preventDefault();
|
|
736
|
+
};
|
|
737
|
+
const onWheel = (event) => {
|
|
738
|
+
if (shouldBlockScroll(getEventTarget(event), event.deltaY || 0)) event.preventDefault();
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
document.addEventListener('touchstart', onTouchStart, { capture: true, passive: true });
|
|
742
|
+
document.addEventListener('touchmove', onTouchMove, { capture: true, passive: false });
|
|
743
|
+
document.addEventListener('wheel', onWheel, { capture: true, passive: false });
|
|
744
|
+
|
|
745
|
+
return () => {
|
|
746
|
+
document.removeEventListener('touchstart', onTouchStart, { capture: true });
|
|
747
|
+
document.removeEventListener('touchmove', onTouchMove, { capture: true });
|
|
748
|
+
document.removeEventListener('wheel', onWheel, { capture: true });
|
|
749
|
+
html.style.overflow = prev.htmlOverflow;
|
|
750
|
+
html.style.overscrollBehavior = prev.htmlOverscrollBehavior;
|
|
751
|
+
body.style.overflow = prev.bodyOverflow;
|
|
752
|
+
body.style.position = prev.bodyPosition;
|
|
753
|
+
body.style.width = prev.bodyWidth;
|
|
754
|
+
body.style.top = prev.bodyTop;
|
|
755
|
+
body.style.overscrollBehavior = prev.bodyOverscrollBehavior;
|
|
756
|
+
if (shouldFreezeBody) {
|
|
757
|
+
try { window.scrollTo(0, prev.scrollY); } catch (_) {}
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}, [isMobileModal, isMobileBrowser]);
|
|
761
|
+
|
|
762
|
+
// Use visualViewport to avoid iOS "vh" causing phantom scroll and clipped content.
|
|
763
|
+
const [mobileModalHeightPx, setMobileModalHeightPx] = useState(() => {
|
|
764
|
+
if (typeof window === 'undefined') return null;
|
|
765
|
+
if (!isMobileBrowser) return null;
|
|
766
|
+
const h = window.innerHeight; // ALWAYS use full window innerHeight as base
|
|
767
|
+
return Math.round(h * 0.97);
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
// CRITICAL FIX: Only calculate height ONCE on mount (or significant orientation change).
|
|
771
|
+
// Do NOT update it when keyboard opens (which shrinks visualViewport height).
|
|
772
|
+
useEffect(() => {
|
|
773
|
+
if (typeof window === 'undefined') return;
|
|
774
|
+
if (!isMobileBrowser) return;
|
|
775
|
+
|
|
776
|
+
const compute = () => {
|
|
777
|
+
// Use window.innerHeight (layout viewport) which is stable on Android
|
|
778
|
+
// On iOS, it might change, so we might need screen.height check?
|
|
779
|
+
// Generally, window.innerHeight is safer for "full screen" modals than visualViewport
|
|
780
|
+
const h = window.innerHeight;
|
|
781
|
+
// Only update if difference is significant (orientation change), not just keyboard (20-40% diff)
|
|
782
|
+
// Keyboard usually takes 30-40% of screen.
|
|
783
|
+
setMobileModalHeightPx(Math.round(h * 0.97));
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
compute();
|
|
787
|
+
|
|
788
|
+
// Only re-compute on actual orientation change or massive resize,
|
|
789
|
+
// explicitly NOT on visualViewport resize (keyboard).
|
|
790
|
+
// Listen for orientation changes specifically
|
|
791
|
+
window.addEventListener('orientationchange', compute);
|
|
792
|
+
|
|
793
|
+
return () => {
|
|
794
|
+
window.removeEventListener('orientationchange', compute);
|
|
795
|
+
};
|
|
796
|
+
}, [isMobileBrowser]);
|
|
797
|
+
|
|
798
|
+
// ENHANCED DEBUG LOGGING for mobile browser height issues
|
|
799
|
+
if (shouldLayoutDebug && typeof window !== 'undefined') {
|
|
800
|
+
console.log('[Onairos SDK][ModalPageLayout] Mobile Detection', {
|
|
801
|
+
width: viewportWidth,
|
|
802
|
+
height: viewportHeight,
|
|
803
|
+
isCapacitorNative,
|
|
804
|
+
isMobileBrowser,
|
|
805
|
+
shouldUseAdaptiveSheet,
|
|
806
|
+
layoutMode: isMobileBrowser
|
|
807
|
+
? 'mobile-browser-sheet'
|
|
808
|
+
: isCapacitorNative
|
|
809
|
+
? 'capacitor-sheet'
|
|
810
|
+
: shouldUseAdaptiveSheet
|
|
811
|
+
? 'adaptive-sheet'
|
|
812
|
+
: 'desktop-dialog',
|
|
813
|
+
backdropAlign: isMobileModal ? 'flex-end' : 'center',
|
|
814
|
+
backdropPadding: isMobileModal ? '0' : '16px'
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const isGlassTheme = theme === 'glass';
|
|
819
|
+
const desktopHorizontalGutter = viewportWidth >= 1440 ? 32 : 24;
|
|
820
|
+
const desktopVerticalGutter = viewportHeight >= 900 ? 32 : 24;
|
|
821
|
+
const availableDesktopWidth = Math.max(320, viewportWidth - desktopHorizontalGutter * 2);
|
|
822
|
+
const availableDesktopHeight = Math.max(480, viewportHeight - desktopVerticalGutter * 2);
|
|
823
|
+
// Keep desktop dialogs close to the historical main-branch sizing that felt balanced,
|
|
824
|
+
// while still falling back to the adaptive sheet on constrained viewports.
|
|
825
|
+
const desktopModalWidth = `${Math.min(500, availableDesktopWidth)}px`;
|
|
826
|
+
const desktopModalHeight = `${Math.min(680, availableDesktopHeight)}px`;
|
|
827
|
+
const desktopModalMinWidth = `${Math.min(500, availableDesktopWidth)}px`;
|
|
828
|
+
const desktopModalMinHeight = `${Math.min(620, Math.min(680, availableDesktopHeight))}px`;
|
|
829
|
+
const adaptiveSheetHeight = `${Math.min(720, Math.max(420, viewportHeight - 16))}px`;
|
|
830
|
+
const mobileViewportWidth = Math.round(Math.max(1, viewportWidth));
|
|
831
|
+
const mobileViewportHeight = Math.round(Math.max(1, viewportHeight));
|
|
832
|
+
const mobileBrowserSheetHeight = Math.round(
|
|
833
|
+
Math.min(
|
|
834
|
+
mobileViewportHeight,
|
|
835
|
+
Math.max(Math.min(300, mobileViewportHeight), isKeyboardOpen && mobileModalHeightPx ? mobileModalHeightPx : mobileViewportHeight * 0.93)
|
|
836
|
+
)
|
|
837
|
+
);
|
|
838
|
+
const capacitorSheetHeight = 'min(92dvh, calc(100dvh - 44px))';
|
|
839
|
+
|
|
840
|
+
const backdropStyles = {
|
|
841
|
+
position: 'fixed',
|
|
842
|
+
top: 0,
|
|
843
|
+
left: 0,
|
|
844
|
+
right: 0,
|
|
845
|
+
bottom: 0,
|
|
846
|
+
backgroundColor: isGlassTheme ? 'transparent' : 'rgba(0, 0, 0, 0.5)',
|
|
847
|
+
zIndex: 2147483647,
|
|
848
|
+
display: 'flex',
|
|
849
|
+
alignItems: isCapacitorFullscreen ? 'stretch' : (isMobileModal ? 'flex-end' : 'center'),
|
|
850
|
+
justifyContent: 'center',
|
|
851
|
+
padding: (isCapacitorFullscreen || isMobileModal) ? '0' : '16px',
|
|
852
|
+
...(isMobileModal ? {
|
|
853
|
+
...(isMobileBrowser
|
|
854
|
+
? {
|
|
855
|
+
left: `${Math.max(0, Math.round(viewportOffsetLeft))}px`,
|
|
856
|
+
top: `${Math.max(0, Math.round(viewportOffsetTop))}px`,
|
|
857
|
+
right: 'auto',
|
|
858
|
+
bottom: 'auto',
|
|
859
|
+
width: `${mobileViewportWidth}px`,
|
|
860
|
+
maxWidth: `${mobileViewportWidth}px`,
|
|
861
|
+
height: `${mobileViewportHeight}px`,
|
|
862
|
+
maxHeight: `${mobileViewportHeight}px`,
|
|
863
|
+
}
|
|
864
|
+
: {
|
|
865
|
+
height: '100dvh',
|
|
866
|
+
maxHeight: '100dvh',
|
|
867
|
+
}),
|
|
868
|
+
width: isMobileBrowser ? `${mobileViewportWidth}px` : '100vw',
|
|
869
|
+
maxWidth: isMobileBrowser ? `${mobileViewportWidth}px` : '100vw',
|
|
870
|
+
overflow: 'hidden',
|
|
871
|
+
overflowX: 'hidden',
|
|
872
|
+
overscrollBehavior: 'none',
|
|
873
|
+
touchAction: 'none',
|
|
874
|
+
minHeight: 0,
|
|
875
|
+
} : {}),
|
|
876
|
+
// Glass theme: transition/willChange create stacking contexts that break backdrop-filter
|
|
877
|
+
...(isGlassTheme ? {} : {
|
|
878
|
+
transition: 'opacity 200ms ease',
|
|
879
|
+
willChange: 'opacity',
|
|
880
|
+
}),
|
|
881
|
+
...backdropStyle
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
// Inline presentation: the "backdrop" is no longer a fixed full-screen scrim —
|
|
885
|
+
// it becomes a transparent, in-flow container that fills the host element so
|
|
886
|
+
// the modal sits within the page (e.g. inside a chat panel) instead of over it.
|
|
887
|
+
if (inline) {
|
|
888
|
+
Object.assign(backdropStyles, {
|
|
889
|
+
position: 'relative',
|
|
890
|
+
top: 'auto', left: 'auto', right: 'auto', bottom: 'auto',
|
|
891
|
+
width: '100%', height: 'auto',
|
|
892
|
+
maxWidth: '100%', maxHeight: 'none',
|
|
893
|
+
minHeight: 0,
|
|
894
|
+
zIndex: 'auto',
|
|
895
|
+
background: 'transparent',
|
|
896
|
+
backgroundColor: 'transparent',
|
|
897
|
+
backdropFilter: 'none',
|
|
898
|
+
WebkitBackdropFilter: 'none',
|
|
899
|
+
padding: 0,
|
|
900
|
+
display: 'flex',
|
|
901
|
+
flexDirection: 'column',
|
|
902
|
+
alignItems: 'stretch',
|
|
903
|
+
justifyContent: 'flex-start',
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
const disableNativeAnimations = isCapacitorNative || isOauthRestore;
|
|
908
|
+
|
|
909
|
+
if (shouldLayoutDebug) {
|
|
910
|
+
console.log('[Onairos SDK][ModalPageLayout] 🎯 Backdrop Styles COMPUTED:', {
|
|
911
|
+
alignItems: backdropStyles.alignItems,
|
|
912
|
+
padding: backdropStyles.padding,
|
|
913
|
+
display: backdropStyles.display,
|
|
914
|
+
hasBackdropStyleOverride: Object.keys(backdropStyle).length > 0,
|
|
915
|
+
backdropStyleOverride: backdropStyle
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
const modalStyles = {
|
|
920
|
+
backgroundColor: isGlassTheme ? 'rgba(20, 20, 25, 0.05)' : COLORS.background,
|
|
921
|
+
position: 'relative',
|
|
922
|
+
borderTopLeftRadius: '24px',
|
|
923
|
+
borderTopRightRadius: '24px',
|
|
924
|
+
borderBottomLeftRadius: isMobileModal ? '0px' : '24px',
|
|
925
|
+
borderBottomRightRadius: isMobileModal ? '0px' : '24px',
|
|
926
|
+
// Glass theme: backdrop-filter directly on the modal element itself
|
|
927
|
+
// (putting it on a child div fails because inner stacking contexts block it)
|
|
928
|
+
...(isGlassTheme ? {
|
|
929
|
+
backdropFilter: 'blur(40px) saturate(100%) brightness(100%)',
|
|
930
|
+
WebkitBackdropFilter: 'blur(40px) saturate(100%) brightness(100%)',
|
|
931
|
+
border: '1px solid rgba(255, 255, 255, 0.15)',
|
|
932
|
+
boxShadow: 'inset 0 0 30px rgba(255,255,255,0.05)',
|
|
933
|
+
} : {}),
|
|
934
|
+
// Mobile browser: keep modal height STABLE while the keyboard opens.
|
|
935
|
+
// Some browsers shrink `vh` when the keyboard appears. Instead we capture a pixel height on mount
|
|
936
|
+
// (and only recompute on orientation changes) so the modal itself doesn't jump; content can scroll.
|
|
937
|
+
// Desktop dialogs should scale with the actual available viewport instead of
|
|
938
|
+
// assuming every non-mobile screen can fit the same fixed modal box.
|
|
939
|
+
height: isMobileBrowser
|
|
940
|
+
? `${mobileBrowserSheetHeight}px`
|
|
941
|
+
: (isCapacitorNative ? capacitorSheetHeight : (shouldUseAdaptiveSheet ? adaptiveSheetHeight : desktopModalHeight)),
|
|
942
|
+
maxHeight: isMobileBrowser
|
|
943
|
+
? `${mobileBrowserSheetHeight}px`
|
|
944
|
+
: (isCapacitorNative ? capacitorSheetHeight : (shouldUseAdaptiveSheet ? adaptiveSheetHeight : desktopModalHeight)),
|
|
945
|
+
minHeight: isMobileModal ? 'auto' : desktopModalMinHeight,
|
|
946
|
+
// Desktop width should flex with the viewport instead of staying pinned to a narrow fixed box.
|
|
947
|
+
width: isMobileModal ? (isMobileBrowser ? `${mobileViewportWidth}px` : 'min(100%, 100vw)') : desktopModalWidth,
|
|
948
|
+
maxWidth: isMobileModal ? (isMobileBrowser ? `${mobileViewportWidth}px` : '100vw') : desktopModalWidth,
|
|
949
|
+
minWidth: isMobileModal ? 'auto' : desktopModalMinWidth,
|
|
950
|
+
boxSizing: 'border-box',
|
|
951
|
+
...(!isGlassTheme ? { boxShadow: '0 -10px 40px rgba(0, 0, 0, 0.3)' } : {}),
|
|
952
|
+
overflow: 'hidden',
|
|
953
|
+
display: 'flex',
|
|
954
|
+
flexDirection: 'column',
|
|
955
|
+
// On mobile, don't allow flexbox to shrink the modal width due to transient layout measurements.
|
|
956
|
+
...(isMobileModal ? { flexShrink: 0 } : {}),
|
|
957
|
+
...(isMobileModal ? { overscrollBehavior: 'contain', touchAction: 'auto' } : {}),
|
|
958
|
+
// iOS safe-area: extend the white modal background into the home-indicator inset
|
|
959
|
+
...(isMobileModal ? { paddingBottom: 'env(safe-area-inset-bottom)' } : {}),
|
|
960
|
+
// Glass theme: transform breaks backdrop-filter (creates new stacking context)
|
|
961
|
+
...(isGlassTheme ? {} : {
|
|
962
|
+
transform: 'translateY(0)',
|
|
963
|
+
transition: 'transform 220ms ease, opacity 220ms ease',
|
|
964
|
+
willChange: 'transform, opacity',
|
|
965
|
+
}),
|
|
966
|
+
marginLeft: isMobileModal ? '0' : 'auto',
|
|
967
|
+
marginRight: isMobileModal ? '0' : 'auto',
|
|
968
|
+
marginBottom: isMobileModal ? '0' : 'auto',
|
|
969
|
+
marginTop: 'auto',
|
|
970
|
+
// Position sheet layouts at the bottom and prevent flex shrink during viewport churn.
|
|
971
|
+
...(isMobileModal && {
|
|
972
|
+
flexShrink: 0
|
|
973
|
+
}),
|
|
974
|
+
// CRITICAL: Do NOT spread modalStyle onto sheet layouts - it can reintroduce fixed dimensions.
|
|
975
|
+
...(isMobileModal ? {} : modalStyle)
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
// Inline presentation: the modal fills its (host-sized) container instead of the
|
|
979
|
+
// fixed ~500x680 desktop box, and drops the auto margins that center an overlay.
|
|
980
|
+
if (inline) {
|
|
981
|
+
Object.assign(modalStyles, {
|
|
982
|
+
width: '100%', maxWidth: '100%', minWidth: 0,
|
|
983
|
+
// Keep the SDK's intended desktop height (capped to the viewport on small
|
|
984
|
+
// screens). Screens like UniversalOnboarding lay out absolutely against a
|
|
985
|
+
// tall fixed modal — an auto/short height collapses them and causes the
|
|
986
|
+
// overflow + scrollbar. The host sizes width; we keep a real height here.
|
|
987
|
+
height: 'min(680px, 86vh)', maxHeight: '86vh', minHeight: 0,
|
|
988
|
+
marginLeft: 0, marginRight: 0, marginTop: 0, marginBottom: 0,
|
|
989
|
+
flexShrink: 1,
|
|
990
|
+
// The heavy overlay drop shadow reads as an off-color panel when embedded
|
|
991
|
+
// in a host surface — use a soft, neutral card shadow instead.
|
|
992
|
+
boxShadow: '0 4px 16px rgba(0, 34, 55, 0.08)',
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
if (shouldLayoutDebug) {
|
|
997
|
+
console.log('[Onairos SDK][ModalPageLayout] 🎨 Modal Styles COMPUTED:', {
|
|
998
|
+
height: modalStyles.height,
|
|
999
|
+
maxHeight: modalStyles.maxHeight,
|
|
1000
|
+
minHeight: modalStyles.minHeight,
|
|
1001
|
+
width: modalStyles.width,
|
|
1002
|
+
maxWidth: modalStyles.maxWidth,
|
|
1003
|
+
borderRadius: `${modalStyles.borderTopLeftRadius} / ${modalStyles.borderBottomLeftRadius}`,
|
|
1004
|
+
hasModalStyleOverride: Object.keys(modalStyle).length > 0,
|
|
1005
|
+
modalStyleWasApplied: isMobileModal ? 'NO (blocked for sheet layout)' : 'YES',
|
|
1006
|
+
modalStyleOverride: modalStyle
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// Warn if modalStyle is trying to override on sheet layouts
|
|
1011
|
+
if (isMobileModal && modalStyle && Object.keys(modalStyle).length > 0) {
|
|
1012
|
+
if (shouldLayoutDebug) {
|
|
1013
|
+
console.warn('[Onairos SDK][ModalPageLayout] ⚠️ BLOCKED modalStyle override on sheet layout. Ignoring:', modalStyle);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// 🔍 Layout debug logging (desktop vs native)
|
|
1018
|
+
try {
|
|
1019
|
+
if (typeof window !== 'undefined') {
|
|
1020
|
+
const width = window.innerWidth;
|
|
1021
|
+
const isDesktop = width >= 1024 && !isCapacitorNative;
|
|
1022
|
+
// Only spam logs in desktop where sizing issues occur
|
|
1023
|
+
if (isDesktop) {
|
|
1024
|
+
// Keep this fairly compact but detailed
|
|
1025
|
+
console.log('[Onairos SDK][Layout][ModalPageLayout]', {
|
|
1026
|
+
width,
|
|
1027
|
+
height: viewportHeight,
|
|
1028
|
+
isCapacitorNative,
|
|
1029
|
+
shouldUseAdaptiveSheet,
|
|
1030
|
+
modalClassName,
|
|
1031
|
+
modalStyleKeys: Object.keys(modalStyle || {}),
|
|
1032
|
+
backdropStyleKeys: Object.keys(backdropStyle || {}),
|
|
1033
|
+
desktopModalWidth,
|
|
1034
|
+
desktopModalHeight,
|
|
1035
|
+
desktopModalMinWidth,
|
|
1036
|
+
modalMaxWidth: modalStyles.maxWidth,
|
|
1037
|
+
modalMinHeight: modalStyles.minHeight,
|
|
1038
|
+
modalHeight: modalStyles.height,
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
} catch (e) {
|
|
1043
|
+
// Never let logging break rendering
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
const handleBackdropClick = (e) => {
|
|
1047
|
+
if (e.target === e.currentTarget) {
|
|
1048
|
+
console.log('🔘 Backdrop clicked outside modal');
|
|
1049
|
+
if (onBackdropClick) {
|
|
1050
|
+
console.log('📞 Calling onBackdropClick handler');
|
|
1051
|
+
onBackdropClick();
|
|
1052
|
+
} else if (onClose) {
|
|
1053
|
+
console.log('❌ Calling onClose handler');
|
|
1054
|
+
onClose();
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
// Determine the gradient border class based on style prop
|
|
1060
|
+
const getGradientBorderClass = () => {
|
|
1061
|
+
// Never on mobile browser OR Capacitor fullscreen (avoid flicker/glitch in WKWebView).
|
|
1062
|
+
// Never inline — the colored radiant glow is an overlay-only flourish; embedded
|
|
1063
|
+
// in a host surface (e.g. a chat panel) it bleeds outside the card.
|
|
1064
|
+
if (!showGradientBorder || gradientBorderStyle === 'none' || isMobileModal || isCapacitorFullscreen || inline) return '';
|
|
1065
|
+
switch (gradientBorderStyle) {
|
|
1066
|
+
case 'shimmer':
|
|
1067
|
+
return 'onairos-modal-shimmer-border';
|
|
1068
|
+
case 'rotate':
|
|
1069
|
+
default:
|
|
1070
|
+
return 'onairos-modal-gradient-border';
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
const gradientBorderClass = getGradientBorderClass();
|
|
1075
|
+
const hasGradientBorder = gradientBorderClass && !isMobileModal && !isCapacitorFullscreen && !isGlassTheme;
|
|
1076
|
+
|
|
1077
|
+
// Wrapper sizing:
|
|
1078
|
+
// - Desktop: follow the computed dialog size for the current viewport
|
|
1079
|
+
// - Mobile/Capacitor: MUST be full width. If left as an unconstrained flex item,
|
|
1080
|
+
// WKWebView can shrink-wrap it during navigation/resize churn (causing a "skinny modal").
|
|
1081
|
+
const wrapperStyles = isCapacitorFullscreen
|
|
1082
|
+
? {
|
|
1083
|
+
position: 'relative',
|
|
1084
|
+
width: '100%',
|
|
1085
|
+
height: '100%',
|
|
1086
|
+
maxWidth: '100%',
|
|
1087
|
+
flexShrink: 0,
|
|
1088
|
+
}
|
|
1089
|
+
: (!isMobileModal
|
|
1090
|
+
? {
|
|
1091
|
+
position: 'relative',
|
|
1092
|
+
width: desktopModalWidth,
|
|
1093
|
+
maxWidth: desktopModalWidth,
|
|
1094
|
+
height: desktopModalHeight,
|
|
1095
|
+
maxHeight: desktopModalHeight,
|
|
1096
|
+
flexShrink: 0,
|
|
1097
|
+
}
|
|
1098
|
+
: {
|
|
1099
|
+
position: 'relative',
|
|
1100
|
+
width: isMobileBrowser ? `${mobileViewportWidth}px` : 'min(100%, 100vw)',
|
|
1101
|
+
maxWidth: isMobileBrowser ? `${mobileViewportWidth}px` : '100vw',
|
|
1102
|
+
height: isMobileBrowser ? `${mobileViewportHeight}px` : undefined,
|
|
1103
|
+
maxHeight: isMobileBrowser ? `${mobileViewportHeight}px` : undefined,
|
|
1104
|
+
marginTop: 'auto',
|
|
1105
|
+
alignSelf: 'flex-end',
|
|
1106
|
+
flexShrink: 0,
|
|
1107
|
+
boxSizing: 'border-box',
|
|
1108
|
+
display: 'flex',
|
|
1109
|
+
flexDirection: 'column',
|
|
1110
|
+
justifyContent: 'flex-end',
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
// Inline presentation: the glow/border wrapper stretches to the host container
|
|
1114
|
+
// instead of pinning to the fixed desktop modal size.
|
|
1115
|
+
if (inline) {
|
|
1116
|
+
Object.assign(wrapperStyles, {
|
|
1117
|
+
position: 'relative',
|
|
1118
|
+
width: '100%', maxWidth: '100%',
|
|
1119
|
+
height: 'auto', maxHeight: 'none',
|
|
1120
|
+
marginTop: 0,
|
|
1121
|
+
alignSelf: 'stretch',
|
|
1122
|
+
flexShrink: 1,
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
const animationsEnabled = !(isCapacitorFullscreen || disableNativeAnimations || isGlassTheme);
|
|
1127
|
+
const backdropAnimClass = animationsEnabled
|
|
1128
|
+
? (exiting ? 'onairos-backdrop-animate-out' : 'onairos-backdrop-animate-in')
|
|
1129
|
+
: '';
|
|
1130
|
+
const modalAnimClass = animationsEnabled
|
|
1131
|
+
? (exiting ? 'onairos-modal-animate-out' : 'onairos-modal-animate-in')
|
|
1132
|
+
: '';
|
|
1133
|
+
|
|
1134
|
+
const modalContent = (
|
|
1135
|
+
<div
|
|
1136
|
+
style={backdropStyles}
|
|
1137
|
+
className={backdropAnimClass}
|
|
1138
|
+
onClick={handleBackdropClick}
|
|
1139
|
+
data-onairos-backdrop="true"
|
|
1140
|
+
data-mobile-browser={isMobileBrowser ? 'true' : 'false'}
|
|
1141
|
+
data-capacitor-native={isCapacitorNative ? 'true' : 'false'}
|
|
1142
|
+
>
|
|
1143
|
+
{isMobileModal && (
|
|
1144
|
+
<style>{`
|
|
1145
|
+
[data-onairos-backdrop="true"],
|
|
1146
|
+
[data-onairos-modal="true"],
|
|
1147
|
+
[data-onairos-modal="true"] * {
|
|
1148
|
+
-webkit-text-size-adjust: 100% !important;
|
|
1149
|
+
text-size-adjust: 100% !important;
|
|
1150
|
+
box-sizing: border-box !important;
|
|
1151
|
+
}
|
|
1152
|
+
[data-onairos-backdrop="true"],
|
|
1153
|
+
[data-onairos-backdrop="true"] > div,
|
|
1154
|
+
[data-onairos-modal="true"] {
|
|
1155
|
+
min-width: 0 !important;
|
|
1156
|
+
transform-origin: bottom center !important;
|
|
1157
|
+
}
|
|
1158
|
+
[data-onairos-modal="true"] input,
|
|
1159
|
+
[data-onairos-modal="true"] textarea,
|
|
1160
|
+
[data-onairos-modal="true"] select {
|
|
1161
|
+
font-size: 16px !important;
|
|
1162
|
+
line-height: 24px !important;
|
|
1163
|
+
}
|
|
1164
|
+
`}</style>
|
|
1165
|
+
)}
|
|
1166
|
+
{/* Soft radiant glow wrapper (desktop only) */}
|
|
1167
|
+
<div
|
|
1168
|
+
className={`${modalAnimClass} ${hasGradientBorder ? gradientBorderClass : ''}`}
|
|
1169
|
+
style={{ ...wrapperStyles, ...(exiting ? { pointerEvents: 'none' } : null) }}
|
|
1170
|
+
onClick={(e) => e.stopPropagation()}
|
|
1171
|
+
>
|
|
1172
|
+
{/* Soft glow layers behind modal */}
|
|
1173
|
+
{hasGradientBorder && (
|
|
1174
|
+
<div className="onairos-modal-glow" aria-hidden="true" />
|
|
1175
|
+
)}
|
|
1176
|
+
<div
|
|
1177
|
+
style={modalStyles}
|
|
1178
|
+
className={modalClassName}
|
|
1179
|
+
data-onairos-modal="true"
|
|
1180
|
+
data-onairos-sheet={isMobileModal ? 'true' : 'false'}
|
|
1181
|
+
data-mobile-browser={isMobileBrowser ? 'true' : 'false'}
|
|
1182
|
+
data-modal-height={modalStyles.height}
|
|
1183
|
+
>
|
|
1184
|
+
<PageLayout
|
|
1185
|
+
{...pageLayoutProps}
|
|
1186
|
+
theme={theme}
|
|
1187
|
+
showHeader={true}
|
|
1188
|
+
showCloseButton={true}
|
|
1189
|
+
onClose={onClose}
|
|
1190
|
+
style={{
|
|
1191
|
+
// Always stretch PageLayout to the modal's fixed height so
|
|
1192
|
+
// inner screens can use flex layouts to pin footers/CTAs.
|
|
1193
|
+
// Without this, mobile bottom-sheet modals can show "floating" buttons.
|
|
1194
|
+
flex: 1,
|
|
1195
|
+
minHeight: 0,
|
|
1196
|
+
height: '100%',
|
|
1197
|
+
...(isGlassTheme ? { position: 'relative' } : {}),
|
|
1198
|
+
...(pageLayoutProps.style || {}),
|
|
1199
|
+
}}
|
|
1200
|
+
>
|
|
1201
|
+
<div
|
|
1202
|
+
style={{
|
|
1203
|
+
// IMPORTANT: keep child layout identical (flex) to avoid "floating" CTAs in screens
|
|
1204
|
+
// that pin a footer/button to the bottom (e.g. UniversalOnboarding).
|
|
1205
|
+
display: 'flex',
|
|
1206
|
+
flexDirection: 'column',
|
|
1207
|
+
flex: 1,
|
|
1208
|
+
minHeight: 0,
|
|
1209
|
+
width: '100%',
|
|
1210
|
+
overflowY: isMobileBrowser && keyboardInsetPx > 0 ? 'auto' : undefined,
|
|
1211
|
+
WebkitOverflowScrolling: isMobileBrowser && keyboardInsetPx > 0 ? 'touch' : undefined,
|
|
1212
|
+
overscrollBehaviorY: isMobileBrowser && keyboardInsetPx > 0 ? 'contain' : undefined,
|
|
1213
|
+
paddingBottom: isMobileBrowser && keyboardInsetPx > 0
|
|
1214
|
+
? `${keyboardInsetPx + 12}px`
|
|
1215
|
+
: undefined,
|
|
1216
|
+
opacity: stylesReady ? 1 : 0,
|
|
1217
|
+
transition: 'opacity 120ms ease',
|
|
1218
|
+
pointerEvents: stylesReady ? 'auto' : 'none',
|
|
1219
|
+
}}
|
|
1220
|
+
data-onairos-styles-ready={stylesReady ? 'true' : 'false'}
|
|
1221
|
+
>
|
|
1222
|
+
{children}
|
|
1223
|
+
</div>
|
|
1224
|
+
</PageLayout>
|
|
1225
|
+
</div>
|
|
1226
|
+
</div>
|
|
1227
|
+
</div>
|
|
1228
|
+
);
|
|
1229
|
+
|
|
1230
|
+
// Inline presentation: render in normal document flow, in place — NEVER portal
|
|
1231
|
+
// out to body/ShadowRoot, so the flow stays embedded inside the host container.
|
|
1232
|
+
if (inline) {
|
|
1233
|
+
return modalContent;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// Prefer rendering the modal into a ShadowRoot when available.
|
|
1237
|
+
// This is required for Capacitor builds where styles are injected into shadow (not document.head).
|
|
1238
|
+
if (typeof document !== 'undefined') {
|
|
1239
|
+
if (useShadowPortal) {
|
|
1240
|
+
const shadowMount = ensureOnairosModalShadowMount();
|
|
1241
|
+
if (shadowMount) return ReactDOM.createPortal(modalContent, shadowMount);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// Use Portal to render the modal at the document body level when requested.
|
|
1245
|
+
// This avoids z-index and overflow clipping issues when the button is embedded in a container.
|
|
1246
|
+
if (usePortal) {
|
|
1247
|
+
return ReactDOM.createPortal(modalContent, document.body);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
return modalContent;
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
export { ModalPageLayout };
|
|
1255
|
+
export default PageLayout;
|