@zoreal/oauth2-react 0.2.21 → 0.2.22

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.cjs CHANGED
@@ -42,7 +42,7 @@ var import_react2 = require("react");
42
42
 
43
43
  // src/wire.ts
44
44
  var WIRE_VERSION = 1;
45
- var SDK_VERSION = "0.2.21";
45
+ var SDK_VERSION = "0.2.22";
46
46
  var DEFAULT_ISSUER = "https://id.zoreal.com";
47
47
  var POLL_INTERVAL_MS = 2e3;
48
48
  var POLL_INTERVAL_ENROLLING_MS = 5e3;
@@ -1642,7 +1642,7 @@ function useZorealOAuth() {
1642
1642
  }
1643
1643
 
1644
1644
  // src/ZorealLogin.tsx
1645
- var import_react5 = require("react");
1645
+ var import_react4 = require("react");
1646
1646
 
1647
1647
  // src/useZorealLogin.ts
1648
1648
  var import_react3 = require("react");
@@ -2494,79 +2494,8 @@ function useZorealLogin(options) {
2494
2494
  }).login;
2495
2495
  }
2496
2496
 
2497
- // src/ring.tsx
2498
- var import_react4 = require("react");
2499
- var import_jsx_runtime5 = require("react/jsx-runtime");
2500
- var TAIL2 = 0.3;
2501
- var STACK2 = Array.from({ length: 12 }, (_, i) => 12 - i);
2502
- var HALO2 = [3, 2, 1];
2503
- function ZorealBusyRing({
2504
- busy,
2505
- radius = 8,
2506
- theme = "auto",
2507
- block = false,
2508
- className,
2509
- style,
2510
- children
2511
- }) {
2512
- (0, import_react4.useEffect)(() => {
2513
- ensureStyles();
2514
- }, []);
2515
- const wrapRef = (0, import_react4.useRef)(null);
2516
- const measureRef = (0, import_react4.useRef)(null);
2517
- (0, import_react4.useLayoutEffect)(() => {
2518
- const wrap = wrapRef.current;
2519
- const rect = measureRef.current;
2520
- if (!wrap || !rect) return;
2521
- const measure = () => {
2522
- const length = rect.getTotalLength();
2523
- if (length > 0) wrap.style.setProperty("--zrl-ring-len", `${length}px`);
2524
- };
2525
- measure();
2526
- if (typeof ResizeObserver === "undefined") return;
2527
- const observer = new ResizeObserver(measure);
2528
- observer.observe(wrap);
2529
- return () => observer.disconnect();
2530
- }, [radius]);
2531
- const rx = radius + 2;
2532
- const layer = (key, name, len, alpha, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2533
- "rect",
2534
- {
2535
- ref,
2536
- className: cx(name),
2537
- rx,
2538
- ry: rx,
2539
- style: {
2540
- strokeDasharray: `calc(var(--zrl-l) * ${len}) calc(var(--zrl-l) * ${1 - len})`,
2541
- "--zrl-s": `calc(var(--zrl-l) * ${-(TAIL2 - len)})`,
2542
- opacity: alpha
2543
- }
2544
- },
2545
- key
2546
- );
2547
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2548
- "span",
2549
- {
2550
- ref: wrapRef,
2551
- className: className ? `${cx("root")} ${cx("ring")} ${className}` : `${cx("root")} ${cx("ring")}`,
2552
- "data-theme": theme,
2553
- "data-busy": busy,
2554
- style: block ? { display: "flex", ...style } : style,
2555
- children: [
2556
- children,
2557
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", { className: cx("ring-svg"), "aria-hidden": "true", children: [
2558
- HALO2.map(
2559
- (n, i) => layer(`h${n}`, "ring-halo", TAIL2 * n / HALO2.length, `calc(var(--zrl-glow-opacity) * 0.6 / ${n})`, i === 0 ? measureRef : void 0)
2560
- ),
2561
- STACK2.map((n) => layer(`t${n}`, n <= 2 ? "ring-head" : "ring-tail", TAIL2 * n / STACK2.length, String(1 / n)))
2562
- ] })
2563
- ]
2564
- }
2565
- );
2566
- }
2567
-
2568
2497
  // src/ZorealLogin.tsx
2569
- var import_jsx_runtime6 = require("react/jsx-runtime");
2498
+ var import_jsx_runtime5 = require("react/jsx-runtime");
2570
2499
  var TEXTS = {
2571
2500
  continue_with: null,
2572
2501
  signin_with: "Sign in with ZOREAL",
@@ -2597,31 +2526,18 @@ function ZorealLogin(props) {
2597
2526
  } = props;
2598
2527
  const { locale } = useZorealOAuth();
2599
2528
  const label = TEXTS[text] ?? strings(locale).buttonContinue;
2600
- const [busy, setBusy] = (0, import_react5.useState)(false);
2601
2529
  const { login } = useZorealFlow({
2602
2530
  ...request,
2603
2531
  flow,
2604
- onCredential: flow === "browser-direct" ? (r) => {
2605
- setBusy(false);
2606
- onSuccess(r);
2607
- } : void 0,
2608
- onCode: flow === "auth-code" ? (r) => {
2609
- setBusy(false);
2610
- onSuccess(r);
2611
- } : void 0,
2612
- onError: (e) => {
2613
- setBusy(false);
2614
- onError?.({ type: "unknown", description: e.description ?? e.error });
2615
- },
2616
- onNonOAuthError: (e) => {
2617
- setBusy(false);
2618
- onError?.(e);
2619
- }
2532
+ onCredential: flow === "browser-direct" ? onSuccess : void 0,
2533
+ onCode: flow === "auth-code" ? onSuccess : void 0,
2534
+ onError: (e) => onError?.({ type: "unknown", description: e.description ?? e.error }),
2535
+ onNonOAuthError: (e) => onError?.(e)
2620
2536
  });
2621
2537
  const s = SIZES[size];
2622
2538
  const radius = shape === "pill" ? s.height / 2 : shape === "square" ? 4 : s.radius;
2623
2539
  const brandMark = theme !== "filled";
2624
- const style = (0, import_react5.useMemo)(
2540
+ const style = (0, import_react4.useMemo)(
2625
2541
  () => ({
2626
2542
  display: "inline-flex",
2627
2543
  alignItems: "center",
@@ -2639,25 +2555,92 @@ function ZorealLogin(props) {
2639
2555
  }),
2640
2556
  [logo_alignment, s, radius, theme, width]
2641
2557
  );
2642
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { ...containerProps, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ZorealBusyRing, { busy, radius, theme: theme === "outline" ? "auto" : "light", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2558
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ...containerProps, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2643
2559
  "button",
2644
2560
  {
2645
2561
  type: "button",
2646
- style: busy ? { ...style, cursor: "progress" } : style,
2647
- disabled: busy,
2648
- "aria-busy": busy,
2649
- onClick: () => {
2650
- if (busy) return;
2562
+ style,
2563
+ onClick: (event) => {
2651
2564
  click_listener?.();
2652
- setBusy(true);
2653
- login();
2565
+ login(event);
2654
2566
  },
2655
2567
  children: [
2656
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ZorealMark, { size: s.mark, brand: brandMark }),
2568
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ZorealMark, { size: s.mark, brand: brandMark }),
2657
2569
  type === "standard" && label
2658
2570
  ]
2659
2571
  }
2660
- ) }) });
2572
+ ) });
2573
+ }
2574
+
2575
+ // src/ring.tsx
2576
+ var import_react5 = require("react");
2577
+ var import_jsx_runtime6 = require("react/jsx-runtime");
2578
+ var TAIL2 = 0.3;
2579
+ var STACK2 = Array.from({ length: 12 }, (_, i) => 12 - i);
2580
+ var HALO2 = [3, 2, 1];
2581
+ function ZorealBusyRing({
2582
+ busy,
2583
+ radius = 8,
2584
+ theme = "auto",
2585
+ block = false,
2586
+ className,
2587
+ style,
2588
+ children
2589
+ }) {
2590
+ (0, import_react5.useEffect)(() => {
2591
+ ensureStyles();
2592
+ }, []);
2593
+ const wrapRef = (0, import_react5.useRef)(null);
2594
+ const measureRef = (0, import_react5.useRef)(null);
2595
+ (0, import_react5.useLayoutEffect)(() => {
2596
+ const wrap = wrapRef.current;
2597
+ const rect = measureRef.current;
2598
+ if (!wrap || !rect) return;
2599
+ const measure = () => {
2600
+ const length = rect.getTotalLength();
2601
+ if (length > 0) wrap.style.setProperty("--zrl-ring-len", `${length}px`);
2602
+ };
2603
+ measure();
2604
+ if (typeof ResizeObserver === "undefined") return;
2605
+ const observer = new ResizeObserver(measure);
2606
+ observer.observe(wrap);
2607
+ return () => observer.disconnect();
2608
+ }, [radius]);
2609
+ const rx = radius + 2;
2610
+ const layer = (key, name, len, alpha, ref) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2611
+ "rect",
2612
+ {
2613
+ ref,
2614
+ className: cx(name),
2615
+ rx,
2616
+ ry: rx,
2617
+ style: {
2618
+ strokeDasharray: `calc(var(--zrl-l) * ${len}) calc(var(--zrl-l) * ${1 - len})`,
2619
+ "--zrl-s": `calc(var(--zrl-l) * ${-(TAIL2 - len)})`,
2620
+ opacity: alpha
2621
+ }
2622
+ },
2623
+ key
2624
+ );
2625
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2626
+ "span",
2627
+ {
2628
+ ref: wrapRef,
2629
+ className: className ? `${cx("root")} ${cx("ring")} ${className}` : `${cx("root")} ${cx("ring")}`,
2630
+ "data-theme": theme,
2631
+ "data-busy": busy,
2632
+ style: block ? { display: "flex", ...style } : style,
2633
+ children: [
2634
+ children,
2635
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("svg", { className: cx("ring-svg"), "aria-hidden": "true", children: [
2636
+ HALO2.map(
2637
+ (n, i) => layer(`h${n}`, "ring-halo", TAIL2 * n / HALO2.length, `calc(var(--zrl-glow-opacity) * 0.6 / ${n})`, i === 0 ? measureRef : void 0)
2638
+ ),
2639
+ STACK2.map((n) => layer(`t${n}`, n <= 2 ? "ring-head" : "ring-tail", TAIL2 * n / STACK2.length, String(1 / n)))
2640
+ ] })
2641
+ ]
2642
+ }
2643
+ );
2661
2644
  }
2662
2645
 
2663
2646
  // src/useZorealAutoLogin.ts