@onairosofficial/onairos-capacitor 0.1.2 → 0.1.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.
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // This is the most robust way to ensure:
5
5
  // - SDK looks correct (Tailwind available)
6
- // - Host app is NOT polluted (no document.head style injection)
6
+ // - Host app is NOT polluted (preflight is scoped to `.onairos-modal` at build time)
7
7
 
8
8
  let _cssText = '';
9
9
 
@@ -17,4 +17,86 @@ export function getOnairosCssText() {
17
17
  return _cssText;
18
18
  }
19
19
 
20
+ const STYLE_ATTR = 'data-onairos-sdk-css';
21
+ const FONTS_ATTR = 'data-onairos-sdk-fonts';
20
22
 
23
+ const FONTS_HREF =
24
+ 'https://fonts.googleapis.com/css2' +
25
+ '?family=IBM+Plex+Sans:wght@300;400;500;600;700' +
26
+ '&family=Inter:wght@300;400;500;600;700' +
27
+ '&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700' +
28
+ // `swap`, not `block`: a remote font with `block` leaves text invisible until it
29
+ // downloads. The display face (Instrument Serif) is embedded in the stylesheet
30
+ // instead, so the headings never wait on the network at all.
31
+ '&display=swap';
32
+
33
+ function optedOut() {
34
+ return typeof window !== 'undefined' && window.onairosDisableCssInjection === true;
35
+ }
36
+
37
+ function whenHeadReady(fn) {
38
+ if (typeof document === 'undefined') return false;
39
+ if (document.head) {
40
+ fn(document.head);
41
+ } else {
42
+ document.addEventListener('DOMContentLoaded', () => fn(document.head), { once: true });
43
+ }
44
+ return true;
45
+ }
46
+
47
+ /**
48
+ * Put the compiled SDK stylesheet in `document.head`.
49
+ *
50
+ * The ShadowRoot injection in `PageLayout` only covers the modal, and it does not
51
+ * exist until the modal opens. SDK UI that lives in the host's light DOM — most
52
+ * importantly the trigger button — is otherwise left holding Tailwind class names
53
+ * with no rules behind them, so it renders as an unstyled square instead of the pill.
54
+ *
55
+ * Safe to place in the document: the build already scopes Tailwind's base/preflight
56
+ * layer to `.onairos-modal` (see `scopeTailwindBase` in the webpack config), and the
57
+ * sheet contains no bare element selectors. What lands globally is the theme layer's
58
+ * custom properties and the utility classes, neither of which restyles host elements.
59
+ *
60
+ * Hosts that compile the SDK's classes themselves can opt out with
61
+ * `window.onairosDisableCssInjection = true` before importing the SDK.
62
+ */
63
+ export function ensureOnairosCssInDocument() {
64
+ if (optedOut() || !_cssText) return false;
65
+ return whenHeadReady((head) => {
66
+ if (!head || head.querySelector(`style[${STYLE_ATTR}="true"]`)) return;
67
+ const style = document.createElement('style');
68
+ style.setAttribute(STYLE_ATTR, 'true');
69
+ style.textContent = _cssText;
70
+ // Prepended so the host's own stylesheets still win at equal specificity.
71
+ head.insertBefore(style, head.firstChild);
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Load the SDK's typefaces.
77
+ *
78
+ * The stylesheet asks for them with `@import url(fonts.googleapis.com/…)`, but that
79
+ * rule is dropped when Tailwind compiles the sheet, and an `@import` inside an
80
+ * injected `<style>` would be ignored anyway — so shipped builds render the SDK in
81
+ * whatever the host's font stack happens to be. A `<link>` at import time loads them
82
+ * well before the modal can open.
83
+ */
84
+ export function ensureOnairosFontsInDocument() {
85
+ if (optedOut()) return false;
86
+ return whenHeadReady((head) => {
87
+ if (!head || head.querySelector(`link[${FONTS_ATTR}="true"]`)) return;
88
+ for (const href of ['https://fonts.googleapis.com', 'https://fonts.gstatic.com']) {
89
+ const pre = document.createElement('link');
90
+ pre.rel = 'preconnect';
91
+ pre.href = href;
92
+ if (href.includes('gstatic')) pre.crossOrigin = 'anonymous';
93
+ pre.setAttribute(FONTS_ATTR, 'preconnect');
94
+ head.appendChild(pre);
95
+ }
96
+ const link = document.createElement('link');
97
+ link.rel = 'stylesheet';
98
+ link.href = FONTS_HREF;
99
+ link.setAttribute(FONTS_ATTR, 'true');
100
+ head.appendChild(link);
101
+ });
102
+ }
@@ -4,6 +4,8 @@
4
4
  */
5
5
 
6
6
  @import "tailwindcss";
7
+ @import "./onairos-fonts.css";
8
+ @import "./onairos-native.css";
7
9
 
8
10
  /*
9
11
  * CRITICAL: Exclude folders from Tailwind content scanning that may contain
@@ -250,14 +250,6 @@ export const performNativeGoogleSignIn = async () => {
250
250
  } else if (typeof GoogleAuth.login === 'function') {
251
251
  // @capgo/capacitor-social-login expects an `options` object (can be empty).
252
252
  try {
253
- // Best-effort to avoid silently reusing the previous account/session on iOS.
254
- // This makes the account chooser appear even after a previous successful login.
255
- try {
256
- if (platform === 'ios' && typeof GoogleAuth.logout === 'function') {
257
- await GoogleAuth.logout({ provider: 'google' });
258
- }
259
- } catch (_) {}
260
-
261
253
  const googleLoginOptions = {};
262
254
  if (platform === 'ios') {
263
255
  // iOS-only: force the account selection prompt
@@ -290,14 +282,26 @@ export const performNativeGoogleSignIn = async () => {
290
282
  };
291
283
  }
292
284
 
293
- const userLike = pickFirstDefined(result?.user, result?.profile, result);
285
+ const nestedResult = pickFirstDefined(result?.result, result?.response, result?.data);
286
+ const userLike = pickFirstDefined(
287
+ result?.user,
288
+ result?.profile,
289
+ nestedResult?.user,
290
+ nestedResult?.profile,
291
+ result
292
+ );
294
293
 
295
294
  const idToken = pickFirstDefined(
296
295
  result?.idToken,
297
296
  result?.authentication?.idToken,
298
297
  result?.tokens?.idToken,
299
298
  result?.tokens?.id_token,
300
- result?.result?.idToken
299
+ nestedResult?.idToken,
300
+ nestedResult?.authentication?.idToken,
301
+ nestedResult?.tokens?.idToken,
302
+ nestedResult?.tokens?.id_token,
303
+ nestedResult?.credential,
304
+ result?.credential
301
305
  );
302
306
 
303
307
  const accessToken = pickFirstDefined(
@@ -305,13 +309,17 @@ export const performNativeGoogleSignIn = async () => {
305
309
  result?.authentication?.accessToken,
306
310
  result?.tokens?.accessToken,
307
311
  result?.tokens?.access_token,
308
- result?.result?.accessToken
312
+ nestedResult?.accessToken,
313
+ nestedResult?.authentication?.accessToken,
314
+ nestedResult?.tokens?.accessToken,
315
+ nestedResult?.tokens?.access_token
309
316
  );
310
317
 
311
318
  const serverAuthCode = pickFirstDefined(
312
319
  result?.serverAuthCode,
313
320
  result?.authentication?.serverAuthCode,
314
- result?.result?.serverAuthCode
321
+ nestedResult?.serverAuthCode,
322
+ nestedResult?.authentication?.serverAuthCode
315
323
  );
316
324
 
317
325
  return {