@zoreal/oauth2-react 0.2.21 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { createContext, useContext, useMemo, useState as useState2 } from "react
5
5
 
6
6
  // src/wire.ts
7
7
  var WIRE_VERSION = 1;
8
- var SDK_VERSION = "0.2.21";
8
+ var SDK_VERSION = "0.2.23";
9
9
  var DEFAULT_ISSUER = "https://id.zoreal.com";
10
10
  var POLL_INTERVAL_MS = 2e3;
11
11
  var POLL_INTERVAL_ENROLLING_MS = 5e3;
@@ -1605,7 +1605,7 @@ function useZorealOAuth() {
1605
1605
  }
1606
1606
 
1607
1607
  // src/ZorealLogin.tsx
1608
- import { useMemo as useMemo2, useState as useState4 } from "react";
1608
+ import { useMemo as useMemo2 } from "react";
1609
1609
 
1610
1610
  // src/useZorealLogin.ts
1611
1611
  import { useCallback, useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
@@ -1749,6 +1749,30 @@ function markReturnDone(requestId) {
1749
1749
  function isReturnDone(requestId) {
1750
1750
  return storage()?.getItem(DONE + requestId) !== null && storage()?.getItem(DONE + requestId) !== void 0;
1751
1751
  }
1752
+ function visibleOrDone(requestId, signal) {
1753
+ if (typeof document === "undefined" || document.visibilityState !== "hidden") {
1754
+ return Promise.resolve(!isReturnDone(requestId));
1755
+ }
1756
+ return new Promise((resolve) => {
1757
+ const finish = (value) => {
1758
+ document.removeEventListener("visibilitychange", onVisible);
1759
+ window.removeEventListener("storage", onStorage);
1760
+ signal?.removeEventListener("abort", onAbort);
1761
+ resolve(value);
1762
+ };
1763
+ const onVisible = () => {
1764
+ if (document.visibilityState !== "hidden") finish(!isReturnDone(requestId));
1765
+ };
1766
+ const onStorage = () => {
1767
+ if (isReturnDone(requestId)) finish(false);
1768
+ };
1769
+ const onAbort = () => finish(false);
1770
+ document.addEventListener("visibilitychange", onVisible);
1771
+ window.addEventListener("storage", onStorage);
1772
+ signal?.addEventListener("abort", onAbort, { once: true });
1773
+ if (isReturnDone(requestId)) finish(false);
1774
+ });
1775
+ }
1752
1776
  function returnToUrl() {
1753
1777
  if (typeof window === "undefined") return void 0;
1754
1778
  const { href } = window.location;
@@ -2311,7 +2335,7 @@ function useZorealFlow(options) {
2311
2335
  controller.signal,
2312
2336
  { tolerateUnknownUntil: Date.now() + 15e3 }
2313
2337
  );
2314
- if (isReturnDone(requestId)) {
2338
+ if (!await visibleOrDone(requestId, controller.signal)) {
2315
2339
  throw new DOMException("aborted", "AbortError");
2316
2340
  }
2317
2341
  } else {
@@ -2457,79 +2481,8 @@ function useZorealLogin(options) {
2457
2481
  }).login;
2458
2482
  }
2459
2483
 
2460
- // src/ring.tsx
2461
- import { useEffect as useEffect3, useLayoutEffect, useRef as useRef3 } from "react";
2462
- import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
2463
- var TAIL2 = 0.3;
2464
- var STACK2 = Array.from({ length: 12 }, (_, i) => 12 - i);
2465
- var HALO2 = [3, 2, 1];
2466
- function ZorealBusyRing({
2467
- busy,
2468
- radius = 8,
2469
- theme = "auto",
2470
- block = false,
2471
- className,
2472
- style,
2473
- children
2474
- }) {
2475
- useEffect3(() => {
2476
- ensureStyles();
2477
- }, []);
2478
- const wrapRef = useRef3(null);
2479
- const measureRef = useRef3(null);
2480
- useLayoutEffect(() => {
2481
- const wrap = wrapRef.current;
2482
- const rect = measureRef.current;
2483
- if (!wrap || !rect) return;
2484
- const measure = () => {
2485
- const length = rect.getTotalLength();
2486
- if (length > 0) wrap.style.setProperty("--zrl-ring-len", `${length}px`);
2487
- };
2488
- measure();
2489
- if (typeof ResizeObserver === "undefined") return;
2490
- const observer = new ResizeObserver(measure);
2491
- observer.observe(wrap);
2492
- return () => observer.disconnect();
2493
- }, [radius]);
2494
- const rx = radius + 2;
2495
- const layer = (key, name, len, alpha, ref) => /* @__PURE__ */ jsx5(
2496
- "rect",
2497
- {
2498
- ref,
2499
- className: cx(name),
2500
- rx,
2501
- ry: rx,
2502
- style: {
2503
- strokeDasharray: `calc(var(--zrl-l) * ${len}) calc(var(--zrl-l) * ${1 - len})`,
2504
- "--zrl-s": `calc(var(--zrl-l) * ${-(TAIL2 - len)})`,
2505
- opacity: alpha
2506
- }
2507
- },
2508
- key
2509
- );
2510
- return /* @__PURE__ */ jsxs5(
2511
- "span",
2512
- {
2513
- ref: wrapRef,
2514
- className: className ? `${cx("root")} ${cx("ring")} ${className}` : `${cx("root")} ${cx("ring")}`,
2515
- "data-theme": theme,
2516
- "data-busy": busy,
2517
- style: block ? { display: "flex", ...style } : style,
2518
- children: [
2519
- children,
2520
- /* @__PURE__ */ jsxs5("svg", { className: cx("ring-svg"), "aria-hidden": "true", children: [
2521
- HALO2.map(
2522
- (n, i) => layer(`h${n}`, "ring-halo", TAIL2 * n / HALO2.length, `calc(var(--zrl-glow-opacity) * 0.6 / ${n})`, i === 0 ? measureRef : void 0)
2523
- ),
2524
- STACK2.map((n) => layer(`t${n}`, n <= 2 ? "ring-head" : "ring-tail", TAIL2 * n / STACK2.length, String(1 / n)))
2525
- ] })
2526
- ]
2527
- }
2528
- );
2529
- }
2530
-
2531
2484
  // src/ZorealLogin.tsx
2532
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
2485
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
2533
2486
  var TEXTS = {
2534
2487
  continue_with: null,
2535
2488
  signin_with: "Sign in with ZOREAL",
@@ -2560,26 +2513,13 @@ function ZorealLogin(props) {
2560
2513
  } = props;
2561
2514
  const { locale } = useZorealOAuth();
2562
2515
  const label = TEXTS[text] ?? strings(locale).buttonContinue;
2563
- const [busy, setBusy] = useState4(false);
2564
2516
  const { login } = useZorealFlow({
2565
2517
  ...request,
2566
2518
  flow,
2567
- onCredential: flow === "browser-direct" ? (r) => {
2568
- setBusy(false);
2569
- onSuccess(r);
2570
- } : void 0,
2571
- onCode: flow === "auth-code" ? (r) => {
2572
- setBusy(false);
2573
- onSuccess(r);
2574
- } : void 0,
2575
- onError: (e) => {
2576
- setBusy(false);
2577
- onError?.({ type: "unknown", description: e.description ?? e.error });
2578
- },
2579
- onNonOAuthError: (e) => {
2580
- setBusy(false);
2581
- onError?.(e);
2582
- }
2519
+ onCredential: flow === "browser-direct" ? onSuccess : void 0,
2520
+ onCode: flow === "auth-code" ? onSuccess : void 0,
2521
+ onError: (e) => onError?.({ type: "unknown", description: e.description ?? e.error }),
2522
+ onNonOAuthError: (e) => onError?.(e)
2583
2523
  });
2584
2524
  const s = SIZES[size];
2585
2525
  const radius = shape === "pill" ? s.height / 2 : shape === "square" ? 4 : s.radius;
@@ -2602,25 +2542,92 @@ function ZorealLogin(props) {
2602
2542
  }),
2603
2543
  [logo_alignment, s, radius, theme, width]
2604
2544
  );
2605
- return /* @__PURE__ */ jsx6("div", { ...containerProps, children: /* @__PURE__ */ jsx6(ZorealBusyRing, { busy, radius, theme: theme === "outline" ? "auto" : "light", children: /* @__PURE__ */ jsxs6(
2545
+ return /* @__PURE__ */ jsx5("div", { ...containerProps, children: /* @__PURE__ */ jsxs5(
2606
2546
  "button",
2607
2547
  {
2608
2548
  type: "button",
2609
- style: busy ? { ...style, cursor: "progress" } : style,
2610
- disabled: busy,
2611
- "aria-busy": busy,
2612
- onClick: () => {
2613
- if (busy) return;
2549
+ style,
2550
+ onClick: (event) => {
2614
2551
  click_listener?.();
2615
- setBusy(true);
2616
- login();
2552
+ login(event);
2617
2553
  },
2618
2554
  children: [
2619
- /* @__PURE__ */ jsx6(ZorealMark, { size: s.mark, brand: brandMark }),
2555
+ /* @__PURE__ */ jsx5(ZorealMark, { size: s.mark, brand: brandMark }),
2620
2556
  type === "standard" && label
2621
2557
  ]
2622
2558
  }
2623
- ) }) });
2559
+ ) });
2560
+ }
2561
+
2562
+ // src/ring.tsx
2563
+ import { useEffect as useEffect3, useLayoutEffect, useRef as useRef3 } from "react";
2564
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
2565
+ var TAIL2 = 0.3;
2566
+ var STACK2 = Array.from({ length: 12 }, (_, i) => 12 - i);
2567
+ var HALO2 = [3, 2, 1];
2568
+ function ZorealBusyRing({
2569
+ busy,
2570
+ radius = 8,
2571
+ theme = "auto",
2572
+ block = false,
2573
+ className,
2574
+ style,
2575
+ children
2576
+ }) {
2577
+ useEffect3(() => {
2578
+ ensureStyles();
2579
+ }, []);
2580
+ const wrapRef = useRef3(null);
2581
+ const measureRef = useRef3(null);
2582
+ useLayoutEffect(() => {
2583
+ const wrap = wrapRef.current;
2584
+ const rect = measureRef.current;
2585
+ if (!wrap || !rect) return;
2586
+ const measure = () => {
2587
+ const length = rect.getTotalLength();
2588
+ if (length > 0) wrap.style.setProperty("--zrl-ring-len", `${length}px`);
2589
+ };
2590
+ measure();
2591
+ if (typeof ResizeObserver === "undefined") return;
2592
+ const observer = new ResizeObserver(measure);
2593
+ observer.observe(wrap);
2594
+ return () => observer.disconnect();
2595
+ }, [radius]);
2596
+ const rx = radius + 2;
2597
+ const layer = (key, name, len, alpha, ref) => /* @__PURE__ */ jsx6(
2598
+ "rect",
2599
+ {
2600
+ ref,
2601
+ className: cx(name),
2602
+ rx,
2603
+ ry: rx,
2604
+ style: {
2605
+ strokeDasharray: `calc(var(--zrl-l) * ${len}) calc(var(--zrl-l) * ${1 - len})`,
2606
+ "--zrl-s": `calc(var(--zrl-l) * ${-(TAIL2 - len)})`,
2607
+ opacity: alpha
2608
+ }
2609
+ },
2610
+ key
2611
+ );
2612
+ return /* @__PURE__ */ jsxs6(
2613
+ "span",
2614
+ {
2615
+ ref: wrapRef,
2616
+ className: className ? `${cx("root")} ${cx("ring")} ${className}` : `${cx("root")} ${cx("ring")}`,
2617
+ "data-theme": theme,
2618
+ "data-busy": busy,
2619
+ style: block ? { display: "flex", ...style } : style,
2620
+ children: [
2621
+ children,
2622
+ /* @__PURE__ */ jsxs6("svg", { className: cx("ring-svg"), "aria-hidden": "true", children: [
2623
+ HALO2.map(
2624
+ (n, i) => layer(`h${n}`, "ring-halo", TAIL2 * n / HALO2.length, `calc(var(--zrl-glow-opacity) * 0.6 / ${n})`, i === 0 ? measureRef : void 0)
2625
+ ),
2626
+ STACK2.map((n) => layer(`t${n}`, n <= 2 ? "ring-head" : "ring-tail", TAIL2 * n / STACK2.length, String(1 / n)))
2627
+ ] })
2628
+ ]
2629
+ }
2630
+ );
2624
2631
  }
2625
2632
 
2626
2633
  // src/useZorealAutoLogin.ts