@nice2dev/auth 1.1.10 → 1.2.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/dist/index.mjs CHANGED
@@ -1,587 +1,423 @@
1
- import { useState as _, useCallback as w, forwardRef as B, useMemo as X, useRef as U, useImperativeHandle as ae, useEffect as W } from "react";
2
- import { jsxs as a, jsx as e, Fragment as ie } from "react/jsx-runtime";
3
- function ye(c = {}) {
4
- const { onLogin: t, onRefresh: i, onLogout: n, storageKey: r = "nice_auth", persistAuth: l = !1 } = c, [o, p] = _(() => {
5
- if (l && typeof window < "u")
1
+ import { useState as g, useCallback as $, forwardRef as G, useMemo as ne, useRef as H, useEffect as Q, useImperativeHandle as oe } from "react";
2
+ import { jsxs as a, jsx as e, Fragment as ae } from "react/jsx-runtime";
3
+ function Ce(r = {}) {
4
+ const { onLogin: t, onRefresh: c, onLogout: n, storageKey: i = "nice_auth", persistAuth: h = !1 } = r, [l, s] = g(() => {
5
+ if (h && typeof window < "u")
6
6
  try {
7
- const h = localStorage.getItem(r);
8
- if (h)
9
- return { ...JSON.parse(h), loading: !1, error: null };
7
+ const o = localStorage.getItem(i);
8
+ if (o)
9
+ return { ...JSON.parse(o), loading: !1, error: null };
10
10
  } catch {
11
11
  }
12
12
  return { isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null };
13
- }), d = w(
14
- (h) => {
15
- p((m) => {
16
- const f = { ...m, ...h };
17
- return l && typeof window < "u" && (f.isAuthenticated ? localStorage.setItem(
18
- r,
13
+ }), u = $(
14
+ (o) => {
15
+ s((p) => {
16
+ const f = { ...p, ...o };
17
+ return h && typeof window < "u" && (f.isAuthenticated ? localStorage.setItem(
18
+ i,
19
19
  JSON.stringify({ isAuthenticated: !0, user: f.user })
20
- ) : localStorage.removeItem(r)), f;
20
+ ) : localStorage.removeItem(i)), f;
21
21
  });
22
22
  },
23
- [l, r]
24
- ), $ = w(
25
- async (h, m) => {
26
- d({ loading: !0, error: null });
23
+ [h, i]
24
+ ), S = $(
25
+ async (o, p) => {
26
+ u({ loading: !0, error: null });
27
27
  try {
28
28
  if (t) {
29
- const f = await t(h, m);
30
- return d({
29
+ const f = await t(o, p);
30
+ return u({
31
31
  isAuthenticated: !0,
32
32
  user: f.user,
33
33
  tokens: f.tokens,
34
34
  loading: !1
35
35
  }), !0;
36
36
  }
37
- return d({ loading: !1, error: "No login handler configured" }), !1;
37
+ return u({ loading: !1, error: "No login handler configured" }), !1;
38
38
  } catch (f) {
39
- return d({
39
+ return u({
40
40
  loading: !1,
41
41
  error: (f == null ? void 0 : f.message) ?? "Login failed"
42
42
  }), !1;
43
43
  }
44
44
  },
45
- [t, d]
46
- ), s = w(() => {
47
- n == null || n(), d({ isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null });
48
- }, [n, d]), C = w(async () => {
49
- var h;
50
- if (!((h = o.tokens) != null && h.refreshToken) || !i)
45
+ [t, u]
46
+ ), d = $(() => {
47
+ n == null || n(), u({ isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null });
48
+ }, [n, u]), A = $(async () => {
49
+ var o;
50
+ if (!((o = l.tokens) != null && o.refreshToken) || !c)
51
51
  return !1;
52
52
  try {
53
- const m = await i(o.tokens.refreshToken);
54
- return d({ tokens: m }), !0;
53
+ const p = await c(l.tokens.refreshToken);
54
+ return u({ tokens: p }), !0;
55
55
  } catch {
56
- return s(), !1;
56
+ return d(), !1;
57
57
  }
58
- }, [o.tokens, i, d, s]), b = w(
59
- (h, m) => {
60
- d({ isAuthenticated: !0, user: h, tokens: m, loading: !1, error: null });
58
+ }, [l.tokens, c, u, d]), b = $(
59
+ (o, p) => {
60
+ u({ isAuthenticated: !0, user: o, tokens: p, loading: !1, error: null });
61
61
  },
62
- [d]
63
- ), x = w(
64
- (...h) => o.user ? h.every((m) => o.user.roles.includes(m)) : !1,
65
- [o.user]
66
- ), g = w(
67
- (...h) => o.user ? h.every((m) => o.user.permissions.includes(m)) : !1,
68
- [o.user]
69
- ), F = w(() => {
70
- d({ error: null });
71
- }, [d]);
62
+ [u]
63
+ ), k = $(
64
+ (...o) => l.user ? o.every((p) => l.user.roles.includes(p)) : !1,
65
+ [l.user]
66
+ ), _ = $(
67
+ (...o) => l.user ? o.every((p) => l.user.permissions.includes(p)) : !1,
68
+ [l.user]
69
+ ), F = $(() => {
70
+ u({ error: null });
71
+ }, [u]);
72
72
  return {
73
- ...o,
74
- login: $,
75
- logout: s,
76
- refreshToken: C,
73
+ ...l,
74
+ login: S,
75
+ logout: d,
76
+ refreshToken: A,
77
77
  setAuth: b,
78
- hasRoles: x,
79
- hasPermissions: g,
78
+ hasRoles: k,
79
+ hasPermissions: _,
80
80
  clearError: F
81
81
  };
82
82
  }
83
- const ce = B(
84
- ({
85
- onSubmit: c,
86
- loading: t = !1,
87
- error: i,
88
- showRememberMe: n = !0,
89
- showForgotPassword: r = !0,
90
- onForgotPassword: l,
91
- showRegisterLink: o = !0,
92
- onRegisterClick: p,
93
- title: d = "Sign In",
94
- submitLabel: $ = "Sign In",
95
- logo: s,
96
- footer: C,
97
- className: b,
98
- style: x,
99
- emailLabel: g = "Email",
100
- passwordLabel: F = "Password",
101
- tracelessPolicy: h,
102
- privacyMessage: m
103
- }, f) => {
104
- const [T, N] = _(""), [P, S] = _(""), [E, k] = _(!1), D = X(() => !(!n || h && !h.cookiesAllowed), [n, h]), O = w(
105
- (A) => {
106
- A.preventDefault();
107
- const M = (h == null ? void 0 : h.cookiesAllowed) === !1 ? !1 : E;
108
- c == null || c({ email: T, password: P, rememberMe: M });
109
- },
110
- [T, P, E, c, h]
111
- );
112
- return /* @__PURE__ */ a(
113
- "form",
114
- {
115
- ref: f,
116
- className: `nice-login-form${b ? ` ${b}` : ""}`,
117
- style: x,
118
- onSubmit: O,
119
- noValidate: !0,
120
- children: [
121
- s && /* @__PURE__ */ e("div", { className: "nice-login-form__logo", children: s }),
122
- /* @__PURE__ */ e("h2", { className: "nice-login-form__title", children: d }),
123
- i && /* @__PURE__ */ e("div", { className: "nice-login-form__error", role: "alert", children: i }),
124
- /* @__PURE__ */ a("div", { className: "nice-login-form__field", children: [
125
- /* @__PURE__ */ e("label", { htmlFor: "nice-login-email", children: g }),
126
- /* @__PURE__ */ e(
127
- "input",
128
- {
129
- id: "nice-login-email",
130
- className: "nice-input",
131
- type: "email",
132
- value: T,
133
- onChange: (A) => N(A.target.value),
134
- autoComplete: "email",
135
- required: !0,
136
- disabled: t
137
- }
138
- )
139
- ] }),
140
- /* @__PURE__ */ a("div", { className: "nice-login-form__field", children: [
141
- /* @__PURE__ */ e("label", { htmlFor: "nice-login-password", children: F }),
142
- /* @__PURE__ */ e(
143
- "input",
144
- {
145
- id: "nice-login-password",
146
- className: "nice-input",
147
- type: "password",
148
- value: P,
149
- onChange: (A) => S(A.target.value),
150
- autoComplete: "current-password",
151
- required: !0,
152
- disabled: t
153
- }
154
- )
155
- ] }),
156
- /* @__PURE__ */ a("div", { className: "nice-login-form__options", children: [
157
- D && /* @__PURE__ */ a("label", { className: "nice-login-form__remember", children: [
83
+ const xe = /* @__PURE__ */ Object.assign(
84
+ /* @__PURE__ */ G(
85
+ ({
86
+ onSubmit: r,
87
+ loading: t = !1,
88
+ error: c,
89
+ showRememberMe: n = !0,
90
+ showForgotPassword: i = !0,
91
+ onForgotPassword: h,
92
+ showRegisterLink: l = !0,
93
+ onRegisterClick: s,
94
+ title: u = "Sign In",
95
+ submitLabel: S = "Sign In",
96
+ logo: d,
97
+ footer: A,
98
+ className: b,
99
+ style: k,
100
+ emailLabel: _ = "Email",
101
+ passwordLabel: F = "Password",
102
+ tracelessPolicy: o,
103
+ privacyMessage: p
104
+ }, f) => {
105
+ const [M, w] = g(""), [C, T] = g(""), [E, N] = g(!1), I = ne(() => !(!n || o && !o.cookiesAllowed), [n, o]), O = $(
106
+ (x) => {
107
+ x.preventDefault();
108
+ const D = (o == null ? void 0 : o.cookiesAllowed) === !1 ? !1 : E;
109
+ r == null || r({ email: M, password: C, rememberMe: D });
110
+ },
111
+ [M, C, E, r, o]
112
+ );
113
+ return /* @__PURE__ */ a(
114
+ "form",
115
+ {
116
+ ref: f,
117
+ className: `nice-login-form${b ? ` ${b}` : ""}`,
118
+ style: k,
119
+ onSubmit: O,
120
+ noValidate: !0,
121
+ children: [
122
+ d && /* @__PURE__ */ e("div", { className: "nice-login-form__logo", children: d }),
123
+ /* @__PURE__ */ e("h2", { className: "nice-login-form__title", children: u }),
124
+ c && /* @__PURE__ */ e("div", { className: "nice-login-form__error", role: "alert", children: c }),
125
+ /* @__PURE__ */ a("div", { className: "nice-login-form__field", children: [
126
+ /* @__PURE__ */ e("label", { htmlFor: "nice-login-email", children: _ }),
158
127
  /* @__PURE__ */ e(
159
128
  "input",
160
129
  {
161
- type: "checkbox",
162
- checked: E,
163
- onChange: (A) => k(A.target.checked),
130
+ id: "nice-login-email",
131
+ className: "nice-input",
132
+ type: "email",
133
+ value: M,
134
+ onChange: (x) => w(x.target.value),
135
+ autoComplete: "email",
136
+ required: !0,
164
137
  disabled: t
165
138
  }
166
- ),
167
- /* @__PURE__ */ e("span", { children: "Remember me" })
139
+ )
168
140
  ] }),
169
- !D && n && m && /* @__PURE__ */ e("span", { className: "nice-login-form__privacy-notice", children: m }),
170
- r && /* @__PURE__ */ e(
141
+ /* @__PURE__ */ a("div", { className: "nice-login-form__field", children: [
142
+ /* @__PURE__ */ e("label", { htmlFor: "nice-login-password", children: F }),
143
+ /* @__PURE__ */ e(
144
+ "input",
145
+ {
146
+ id: "nice-login-password",
147
+ className: "nice-input",
148
+ type: "password",
149
+ value: C,
150
+ onChange: (x) => T(x.target.value),
151
+ autoComplete: "current-password",
152
+ required: !0,
153
+ disabled: t
154
+ }
155
+ )
156
+ ] }),
157
+ /* @__PURE__ */ a("div", { className: "nice-login-form__options", children: [
158
+ I && /* @__PURE__ */ a("label", { className: "nice-login-form__remember", children: [
159
+ /* @__PURE__ */ e(
160
+ "input",
161
+ {
162
+ type: "checkbox",
163
+ checked: E,
164
+ onChange: (x) => N(x.target.checked),
165
+ disabled: t
166
+ }
167
+ ),
168
+ /* @__PURE__ */ e("span", { children: "Remember me" })
169
+ ] }),
170
+ !I && n && p && /* @__PURE__ */ e("span", { className: "nice-login-form__privacy-notice", children: p }),
171
+ i && /* @__PURE__ */ e(
172
+ "button",
173
+ {
174
+ type: "button",
175
+ className: "nice-login-form__forgot",
176
+ onClick: h,
177
+ disabled: t,
178
+ children: "Forgot password?"
179
+ }
180
+ )
181
+ ] }),
182
+ /* @__PURE__ */ e(
171
183
  "button",
172
184
  {
173
- type: "button",
174
- className: "nice-login-form__forgot",
175
- onClick: l,
176
- disabled: t,
177
- children: "Forgot password?"
185
+ type: "submit",
186
+ className: "nice-btn nice-btn--primary nice-login-form__submit",
187
+ disabled: t || !M || !C,
188
+ children: t ? "…" : S
178
189
  }
179
- )
180
- ] }),
181
- /* @__PURE__ */ e(
182
- "button",
183
- {
184
- type: "submit",
185
- className: "nice-btn nice-btn--primary nice-login-form__submit",
186
- disabled: t || !T || !P,
187
- children: t ? "…" : $
188
- }
189
- ),
190
- o && /* @__PURE__ */ a("div", { className: "nice-login-form__register", children: [
191
- /* @__PURE__ */ e("span", { children: "Don't have an account? " }),
192
- /* @__PURE__ */ e("button", { type: "button", onClick: p, disabled: t, children: "Register" })
193
- ] }),
194
- C && /* @__PURE__ */ e("div", { className: "nice-login-form__footer", children: C })
195
- ]
196
- }
197
- );
198
- }
199
- );
200
- ce.displayName = "NiceLoginForm";
201
- const re = {
190
+ ),
191
+ l && /* @__PURE__ */ a("div", { className: "nice-login-form__register", children: [
192
+ /* @__PURE__ */ e("span", { children: "Don't have an account? " }),
193
+ /* @__PURE__ */ e("button", { type: "button", onClick: s, disabled: t, children: "Register" })
194
+ ] }),
195
+ A && /* @__PURE__ */ e("div", { className: "nice-login-form__footer", children: A })
196
+ ]
197
+ }
198
+ );
199
+ }
200
+ ),
201
+ { displayName: "NiceLoginForm" }
202
+ ), de = {
202
203
  0: "Very weak",
203
204
  1: "Weak",
204
205
  2: "Fair",
205
206
  3: "Strong",
206
207
  4: "Very strong"
207
- }, se = {
208
+ }, he = {
208
209
  0: "#d9534f",
209
210
  1: "#f0ad4e",
210
211
  2: "#5bc0de",
211
212
  3: "#5cb85c",
212
213
  4: "#2e7d32"
213
214
  };
214
- function J(c) {
215
- if (!c)
215
+ function X(r) {
216
+ if (!r)
216
217
  return 0;
217
218
  let t = 0;
218
- return c.length >= 8 && t++, c.length >= 12 && t++, /[a-z]/.test(c) && /[A-Z]/.test(c) && t++, /\d/.test(c) && t++, /[^a-zA-Z0-9]/.test(c) && t++, Math.min(4, t);
219
+ return r.length >= 8 && t++, r.length >= 12 && t++, /[a-z]/.test(r) && /[A-Z]/.test(r) && t++, /\d/.test(r) && t++, /[^a-zA-Z0-9]/.test(r) && t++, Math.min(4, t);
219
220
  }
220
- const Z = B(
221
- ({ password: c, strength: t, showLabel: i = !0, labels: n = re, className: r }, l) => {
222
- const o = t ?? J(c), p = se[o], d = (o + 1) / 5 * 100;
223
- return /* @__PURE__ */ a("div", { ref: l, className: `nice-password-strength${r ? ` ${r}` : ""}`, children: [
224
- /* @__PURE__ */ e("div", { className: "nice-password-strength__bar", children: /* @__PURE__ */ e(
225
- "div",
221
+ const Y = /* @__PURE__ */ Object.assign(
222
+ /* @__PURE__ */ G(
223
+ ({
224
+ password: r,
225
+ strength: t,
226
+ showLabel: c = !0,
227
+ labels: n = de,
228
+ className: i
229
+ }, h) => {
230
+ const l = t ?? X(r), s = he[l], u = (l + 1) / 5 * 100;
231
+ return /* @__PURE__ */ a("div", { ref: h, className: `nice-password-strength${i ? ` ${i}` : ""}`, children: [
232
+ /* @__PURE__ */ e("div", { className: "nice-password-strength__bar", children: /* @__PURE__ */ e(
233
+ "div",
234
+ {
235
+ className: "nice-password-strength__fill",
236
+ style: { width: `${u}%`, backgroundColor: s }
237
+ }
238
+ ) }),
239
+ c && /* @__PURE__ */ e("span", { className: "nice-password-strength__label", style: { color: s }, children: n[l] })
240
+ ] });
241
+ }
242
+ ),
243
+ { displayName: "NicePasswordStrength" }
244
+ ), $e = /* @__PURE__ */ Object.assign(
245
+ /* @__PURE__ */ G(
246
+ ({
247
+ onSubmit: r,
248
+ loading: t = !1,
249
+ error: c,
250
+ onLoginClick: n,
251
+ showPasswordStrength: i = !0,
252
+ minPasswordStrength: h = 2,
253
+ termsUrl: l,
254
+ privacyUrl: s,
255
+ title: u = "Create Account",
256
+ logo: S,
257
+ footer: d,
258
+ className: A,
259
+ style: b
260
+ }, k) => {
261
+ const [_, F] = g(""), [o, p] = g(""), [f, M] = g(""), [w, C] = g(""), [T, E] = g(""), [N, I] = g(!1), O = X(w), x = w === T, D = _ && f && w && x && N && O >= h && !t, m = $(
262
+ (v) => {
263
+ v.preventDefault(), D && (r == null || r({ firstName: _, lastName: o, email: f, password: w, acceptTerms: N }));
264
+ },
265
+ [D, _, o, f, w, N, r]
266
+ );
267
+ return /* @__PURE__ */ a(
268
+ "form",
226
269
  {
227
- className: "nice-password-strength__fill",
228
- style: { width: `${d}%`, backgroundColor: p }
229
- }
230
- ) }),
231
- i && /* @__PURE__ */ e("span", { className: "nice-password-strength__label", style: { color: p }, children: n[o] })
232
- ] });
233
- }
234
- );
235
- Z.displayName = "NicePasswordStrength";
236
- const le = B(
237
- ({
238
- onSubmit: c,
239
- loading: t = !1,
240
- error: i,
241
- onLoginClick: n,
242
- showPasswordStrength: r = !0,
243
- minPasswordStrength: l = 2,
244
- termsUrl: o,
245
- privacyUrl: p,
246
- title: d = "Create Account",
247
- logo: $,
248
- footer: s,
249
- className: C,
250
- style: b
251
- }, x) => {
252
- const [g, F] = _(""), [h, m] = _(""), [f, T] = _(""), [N, P] = _(""), [S, E] = _(""), [k, D] = _(!1), O = J(N), A = N === S, M = g && f && N && A && k && O >= l && !t, u = w(
253
- (v) => {
254
- v.preventDefault(), M && (c == null || c({ firstName: g, lastName: h, email: f, password: N, acceptTerms: k }));
255
- },
256
- [M, g, h, f, N, k, c]
257
- );
258
- return /* @__PURE__ */ a(
259
- "form",
260
- {
261
- ref: x,
262
- className: `nice-register-form${C ? ` ${C}` : ""}`,
263
- style: b,
264
- onSubmit: u,
265
- noValidate: !0,
266
- children: [
267
- $ && /* @__PURE__ */ e("div", { className: "nice-register-form__logo", children: $ }),
268
- /* @__PURE__ */ e("h2", { className: "nice-register-form__title", children: d }),
269
- i && /* @__PURE__ */ e("div", { className: "nice-register-form__error", role: "alert", children: i }),
270
- /* @__PURE__ */ a("div", { className: "nice-register-form__row", children: [
270
+ ref: k,
271
+ className: `nice-register-form${A ? ` ${A}` : ""}`,
272
+ style: b,
273
+ onSubmit: m,
274
+ noValidate: !0,
275
+ children: [
276
+ S && /* @__PURE__ */ e("div", { className: "nice-register-form__logo", children: S }),
277
+ /* @__PURE__ */ e("h2", { className: "nice-register-form__title", children: u }),
278
+ c && /* @__PURE__ */ e("div", { className: "nice-register-form__error", role: "alert", children: c }),
279
+ /* @__PURE__ */ a("div", { className: "nice-register-form__row", children: [
280
+ /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
281
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-first", children: "First name *" }),
282
+ /* @__PURE__ */ e(
283
+ "input",
284
+ {
285
+ id: "nice-reg-first",
286
+ className: "nice-input",
287
+ type: "text",
288
+ value: _,
289
+ onChange: (v) => F(v.target.value),
290
+ required: !0,
291
+ disabled: t,
292
+ autoComplete: "given-name"
293
+ }
294
+ )
295
+ ] }),
296
+ /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
297
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-last", children: "Last name" }),
298
+ /* @__PURE__ */ e(
299
+ "input",
300
+ {
301
+ id: "nice-reg-last",
302
+ className: "nice-input",
303
+ type: "text",
304
+ value: o,
305
+ onChange: (v) => p(v.target.value),
306
+ disabled: t,
307
+ autoComplete: "family-name"
308
+ }
309
+ )
310
+ ] })
311
+ ] }),
271
312
  /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
272
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-first", children: "First name *" }),
313
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-email", children: "Email *" }),
273
314
  /* @__PURE__ */ e(
274
315
  "input",
275
316
  {
276
- id: "nice-reg-first",
317
+ id: "nice-reg-email",
277
318
  className: "nice-input",
278
- type: "text",
279
- value: g,
280
- onChange: (v) => F(v.target.value),
319
+ type: "email",
320
+ value: f,
321
+ onChange: (v) => M(v.target.value),
281
322
  required: !0,
282
323
  disabled: t,
283
- autoComplete: "given-name"
324
+ autoComplete: "email"
284
325
  }
285
326
  )
286
327
  ] }),
287
328
  /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
288
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-last", children: "Last name" }),
329
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-pass", children: "Password *" }),
289
330
  /* @__PURE__ */ e(
290
331
  "input",
291
332
  {
292
- id: "nice-reg-last",
333
+ id: "nice-reg-pass",
293
334
  className: "nice-input",
294
- type: "text",
295
- value: h,
296
- onChange: (v) => m(v.target.value),
335
+ type: "password",
336
+ value: w,
337
+ onChange: (v) => C(v.target.value),
338
+ required: !0,
297
339
  disabled: t,
298
- autoComplete: "family-name"
340
+ autoComplete: "new-password"
299
341
  }
300
- )
301
- ] })
302
- ] }),
303
- /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
304
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-email", children: "Email *" }),
305
- /* @__PURE__ */ e(
306
- "input",
307
- {
308
- id: "nice-reg-email",
309
- className: "nice-input",
310
- type: "email",
311
- value: f,
312
- onChange: (v) => T(v.target.value),
313
- required: !0,
314
- disabled: t,
315
- autoComplete: "email"
316
- }
317
- )
318
- ] }),
319
- /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
320
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-pass", children: "Password *" }),
321
- /* @__PURE__ */ e(
322
- "input",
323
- {
324
- id: "nice-reg-pass",
325
- className: "nice-input",
326
- type: "password",
327
- value: N,
328
- onChange: (v) => P(v.target.value),
329
- required: !0,
330
- disabled: t,
331
- autoComplete: "new-password"
332
- }
333
- ),
334
- r && N.length > 0 && /* @__PURE__ */ e(Z, { password: N })
335
- ] }),
336
- /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
337
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-confirm", children: "Confirm password *" }),
338
- /* @__PURE__ */ e(
339
- "input",
340
- {
341
- id: "nice-reg-confirm",
342
- className: "nice-input",
343
- type: "password",
344
- value: S,
345
- onChange: (v) => E(v.target.value),
346
- required: !0,
347
- disabled: t,
348
- autoComplete: "new-password"
349
- }
350
- ),
351
- S && !A && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
352
- ] }),
353
- /* @__PURE__ */ a("label", { className: "nice-register-form__terms", children: [
354
- /* @__PURE__ */ e(
355
- "input",
356
- {
357
- type: "checkbox",
358
- checked: k,
359
- onChange: (v) => D(v.target.checked),
360
- disabled: t
361
- }
362
- ),
363
- /* @__PURE__ */ a("span", { children: [
364
- "I accept the",
365
- " ",
366
- o ? /* @__PURE__ */ e("a", { href: o, target: "_blank", rel: "noopener noreferrer", children: "Terms" }) : "Terms",
367
- p && /* @__PURE__ */ a(ie, { children: [
368
- " ",
369
- "and",
342
+ ),
343
+ i && w.length > 0 && /* @__PURE__ */ e(Y, { password: w })
344
+ ] }),
345
+ /* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
346
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-confirm", children: "Confirm password *" }),
347
+ /* @__PURE__ */ e(
348
+ "input",
349
+ {
350
+ id: "nice-reg-confirm",
351
+ className: "nice-input",
352
+ type: "password",
353
+ value: T,
354
+ onChange: (v) => E(v.target.value),
355
+ required: !0,
356
+ disabled: t,
357
+ autoComplete: "new-password"
358
+ }
359
+ ),
360
+ T && !x && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
361
+ ] }),
362
+ /* @__PURE__ */ a("label", { className: "nice-register-form__terms", children: [
363
+ /* @__PURE__ */ e(
364
+ "input",
365
+ {
366
+ type: "checkbox",
367
+ checked: N,
368
+ onChange: (v) => I(v.target.checked),
369
+ disabled: t
370
+ }
371
+ ),
372
+ /* @__PURE__ */ a("span", { children: [
373
+ "I accept the",
370
374
  " ",
371
- /* @__PURE__ */ e("a", { href: p, target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" })
372
- ] }),
373
- " *"
374
- ] })
375
- ] }),
376
- /* @__PURE__ */ e(
377
- "button",
378
- {
379
- type: "submit",
380
- className: "nice-btn nice-btn--primary nice-register-form__submit",
381
- disabled: !M,
382
- children: t ? "…" : "Register"
383
- }
384
- ),
385
- n && /* @__PURE__ */ a("div", { className: "nice-register-form__login", children: [
386
- /* @__PURE__ */ e("span", { children: "Already have an account? " }),
387
- /* @__PURE__ */ e("button", { type: "button", onClick: n, children: "Sign in" })
388
- ] }),
389
- s && /* @__PURE__ */ e("div", { className: "nice-register-form__footer", children: s })
390
- ]
391
- }
392
- );
393
- }
394
- );
395
- le.displayName = "NiceRegistrationForm";
396
- const oe = B(
397
- ({
398
- requireCurrentPassword: c = !0,
399
- onSubmit: t,
400
- loading: i = !1,
401
- error: n,
402
- success: r,
403
- minPasswordStrength: l = 2,
404
- title: o = "Change Password",
405
- className: p,
406
- style: d
407
- }, $) => {
408
- const [s, C] = _(""), [b, x] = _(""), [g, F] = _(""), h = J(b), m = b === g, f = (!c || s.length > 0) && b.length > 0 && m && h >= l && !i, T = w(
409
- (N) => {
410
- N.preventDefault(), f && (t == null || t({
411
- currentPassword: c ? s : void 0,
412
- newPassword: b
413
- }));
414
- },
415
- [f, s, b, c, t]
416
- );
417
- return /* @__PURE__ */ a(
418
- "form",
419
- {
420
- ref: $,
421
- className: `nice-change-password${p ? ` ${p}` : ""}`,
422
- style: d,
423
- onSubmit: T,
424
- noValidate: !0,
425
- children: [
426
- /* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: o }),
427
- n && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: n }),
428
- r && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: r }),
429
- c && /* @__PURE__ */ a("div", { className: "nice-change-password__field", children: [
430
- /* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
431
- /* @__PURE__ */ e(
432
- "input",
433
- {
434
- id: "nice-cp-current",
435
- className: "nice-input",
436
- type: "password",
437
- value: s,
438
- onChange: (N) => C(N.target.value),
439
- autoComplete: "current-password",
440
- disabled: i,
441
- required: !0
442
- }
443
- )
444
- ] }),
445
- /* @__PURE__ */ a("div", { className: "nice-change-password__field", children: [
446
- /* @__PURE__ */ e("label", { htmlFor: "nice-cp-new", children: "New password" }),
447
- /* @__PURE__ */ e(
448
- "input",
449
- {
450
- id: "nice-cp-new",
451
- className: "nice-input",
452
- type: "password",
453
- value: b,
454
- onChange: (N) => x(N.target.value),
455
- autoComplete: "new-password",
456
- disabled: i,
457
- required: !0
458
- }
459
- ),
460
- b.length > 0 && /* @__PURE__ */ e(Z, { password: b })
461
- ] }),
462
- /* @__PURE__ */ a("div", { className: "nice-change-password__field", children: [
463
- /* @__PURE__ */ e("label", { htmlFor: "nice-cp-confirm", children: "Confirm new password" }),
375
+ l ? /* @__PURE__ */ e("a", { href: l, target: "_blank", rel: "noopener noreferrer", children: "Terms" }) : "Terms",
376
+ s && /* @__PURE__ */ a(ae, { children: [
377
+ " ",
378
+ "and",
379
+ " ",
380
+ /* @__PURE__ */ e("a", { href: s, target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" })
381
+ ] }),
382
+ " *"
383
+ ] })
384
+ ] }),
464
385
  /* @__PURE__ */ e(
465
- "input",
386
+ "button",
466
387
  {
467
- id: "nice-cp-confirm",
468
- className: "nice-input",
469
- type: "password",
470
- value: g,
471
- onChange: (N) => F(N.target.value),
472
- autoComplete: "new-password",
473
- disabled: i,
474
- required: !0
388
+ type: "submit",
389
+ className: "nice-btn nice-btn--primary nice-register-form__submit",
390
+ disabled: !D,
391
+ children: t ? "…" : "Register"
475
392
  }
476
393
  ),
477
- g && !m && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
478
- ] }),
479
- /* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !f, children: i ? "…" : "Change Password" })
480
- ]
481
- }
482
- );
483
- }
484
- );
485
- oe.displayName = "NiceChangePassword";
486
- const de = B(
487
- ({
488
- secret: c,
489
- qrCodeUrl: t,
490
- issuer: i,
491
- accountName: n,
492
- onVerify: r,
493
- loading: l = !1,
494
- error: o,
495
- onCancel: p,
496
- recoveryCodes: d,
497
- step: $ = "setup",
498
- onStepChange: s,
499
- className: C,
500
- style: b
501
- }, x) => {
502
- const [g, F] = _(""), [h, m] = _(!1), [f, T] = _(!1), N = w(
503
- (S) => {
504
- S.preventDefault(), g.length >= 6 && (r == null || r(g));
505
- },
506
- [g, r]
507
- ), P = `otpauth://totp/${i ? `${i}:` : ""}${n ?? "user"}?secret=${c}${i ? `&issuer=${i}` : ""}&digits=6&period=30`;
508
- return /* @__PURE__ */ a("div", { ref: x, className: `nice-2fa-setup${C ? ` ${C}` : ""}`, style: b, children: [
509
- /* @__PURE__ */ e("h3", { className: "nice-2fa-setup__title", children: "Two-Factor Authentication" }),
510
- $ === "setup" && /* @__PURE__ */ a("div", { className: "nice-2fa-setup__step", children: [
511
- /* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.):" }),
512
- t ? /* @__PURE__ */ e("img", { src: t, alt: "2FA QR Code", className: "nice-2fa-setup__qr" }) : /* @__PURE__ */ a("div", { className: "nice-2fa-setup__qr-placeholder", children: [
513
- /* @__PURE__ */ e("span", { children: "QR Code" }),
514
- /* @__PURE__ */ e("code", { className: "nice-2fa-setup__uri", children: P })
515
- ] }),
516
- /* @__PURE__ */ a("div", { className: "nice-2fa-setup__secret", children: [
517
- /* @__PURE__ */ e("span", { children: "Or enter manually: " }),
518
- h ? /* @__PURE__ */ e("code", { className: "nice-2fa-setup__secret-key", children: c }) : /* @__PURE__ */ e("button", { type: "button", onClick: () => m(!0), children: "Show secret key" })
519
- ] }),
520
- /* @__PURE__ */ e(
521
- "button",
522
- {
523
- type: "button",
524
- className: "nice-btn nice-btn--primary",
525
- onClick: () => s == null ? void 0 : s("verify"),
526
- children: "Next — Verify"
527
- }
528
- )
529
- ] }),
530
- $ === "verify" && /* @__PURE__ */ a("form", { className: "nice-2fa-setup__step", onSubmit: N, children: [
531
- /* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Enter the 6-digit code from your authenticator app:" }),
532
- o && /* @__PURE__ */ e("div", { className: "nice-2fa-setup__error", role: "alert", children: o }),
533
- /* @__PURE__ */ e(
534
- "input",
535
- {
536
- className: "nice-input nice-2fa-setup__code-input",
537
- type: "text",
538
- inputMode: "numeric",
539
- maxLength: 6,
540
- value: g,
541
- onChange: (S) => F(S.target.value.replace(/\D/g, "").slice(0, 6)),
542
- placeholder: "000000",
543
- autoFocus: !0,
544
- disabled: l,
545
- autoComplete: "one-time-code"
546
- }
547
- ),
548
- /* @__PURE__ */ a("div", { className: "nice-2fa-setup__actions", children: [
549
- /* @__PURE__ */ e("button", { type: "button", className: "nice-btn", onClick: () => s == null ? void 0 : s("setup"), children: "Back" }),
550
- /* @__PURE__ */ e(
551
- "button",
552
- {
553
- type: "submit",
554
- className: "nice-btn nice-btn--primary",
555
- disabled: l || g.length < 6,
556
- children: l ? "…" : "Verify"
557
- }
558
- )
559
- ] })
560
- ] }),
561
- $ === "recovery" && d && /* @__PURE__ */ a("div", { className: "nice-2fa-setup__step", children: [
562
- /* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Save these recovery codes in a safe place. Each code can only be used once:" }),
563
- /* @__PURE__ */ e("div", { className: "nice-2fa-setup__recovery-codes", children: d.map((S, E) => /* @__PURE__ */ e("code", { className: "nice-2fa-setup__recovery-code", children: S }, E)) }),
564
- /* @__PURE__ */ e(
565
- "button",
566
- {
567
- type: "button",
568
- className: "nice-btn",
569
- onClick: () => {
570
- var S;
571
- (S = navigator.clipboard) == null || S.writeText(d.join(`
572
- `)), T(!0);
573
- },
574
- children: f ? "Copied!" : "Copy all codes"
575
- }
576
- ),
577
- p && /* @__PURE__ */ e("button", { type: "button", className: "nice-btn nice-btn--primary", onClick: p, children: "Done" })
578
- ] }),
579
- p && $ !== "recovery" && /* @__PURE__ */ e("button", { type: "button", className: "nice-2fa-setup__cancel", onClick: p, children: "Cancel" })
580
- ] });
394
+ n && /* @__PURE__ */ a("div", { className: "nice-register-form__login", children: [
395
+ /* @__PURE__ */ e("span", { children: "Already have an account? " }),
396
+ /* @__PURE__ */ e("button", { type: "button", onClick: n, children: "Sign in" })
397
+ ] }),
398
+ d && /* @__PURE__ */ e("div", { className: "nice-register-form__footer", children: d })
399
+ ]
400
+ }
401
+ );
402
+ }
403
+ ),
404
+ { displayName: "NiceRegistrationForm" }
405
+ ), ue = ({ style: r }) => /* @__PURE__ */ e(
406
+ "span",
407
+ {
408
+ "aria-hidden": "true",
409
+ style: {
410
+ display: "inline-block",
411
+ width: "0.3em",
412
+ height: "0.6em",
413
+ margin: "0 0.35em 0.15em 0.1em",
414
+ borderRight: "0.12em solid currentColor",
415
+ borderBottom: "0.12em solid currentColor",
416
+ transform: "rotate(45deg)",
417
+ ...r
418
+ }
581
419
  }
582
- );
583
- de.displayName = "NiceTwoFaSetup";
584
- const he = ({ style: c }) => /* @__PURE__ */ e(
420
+ ), re = ({ style: r }) => /* @__PURE__ */ e(
585
421
  "span",
586
422
  {
587
423
  "aria-hidden": "true",
@@ -593,504 +429,879 @@ const he = ({ style: c }) => /* @__PURE__ */ e(
593
429
  border: "0.12em solid currentColor",
594
430
  borderTopColor: "transparent",
595
431
  transform: "rotate(-45deg)",
596
- ...c
432
+ ...r
597
433
  }
598
434
  }
599
- ), ue = 500;
600
- function I(c, t) {
601
- return Math.floor(Math.random() * (t - c + 1)) + c;
602
- }
603
- function me() {
604
- return `${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
605
- }
606
- function pe(c, t) {
607
- switch (c) {
608
- case "math": {
609
- const i = t === "easy" ? 5 : t === "hard" ? 20 : 10, n = I(1, i), r = I(1, i), l = t !== "easy" && n >= r && Math.random() < 0.5, o = l ? n - r : n + r;
610
- return { kind: "math", prompt: `${n} ${l ? "−" : "+"} ${r}`, answer: o };
611
- }
612
- case "text": {
613
- const i = t === "easy" ? 4 : t === "hard" ? 7 : 5, n = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
614
- let r = "";
615
- for (let l = 0; l < i; l++)
616
- r += n[I(0, n.length - 1)];
617
- return { kind: "text", text: r };
618
- }
619
- case "slider":
620
- return { kind: "slider", target: I(70, 92), tolerance: t === "easy" ? 8 : t === "hard" ? 2 : 4 };
621
- case "checkbox":
622
- default:
623
- return { kind: "checkbox" };
435
+ ), ee = {
436
+ lowercase: "abcdefghijklmnopqrstuvwxyz",
437
+ uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
438
+ digits: "0123456789",
439
+ symbols: "!@#$%^&*()-_=+[]{};:,.?/~"
440
+ }, me = /[0Oo1lI|]/g, W = {
441
+ length: 16,
442
+ lowercase: !0,
443
+ uppercase: !0,
444
+ digits: !0,
445
+ symbols: !0,
446
+ excludeAmbiguous: !1
447
+ }, pe = {
448
+ password: "Generated password",
449
+ length: "Length",
450
+ lowercase: "Lowercase (a–z)",
451
+ uppercase: "Uppercase (A–Z)",
452
+ digits: "Digits (0–9)",
453
+ symbols: "Symbols (!@#…)",
454
+ excludeAmbiguous: "Avoid look-alikes (0 O 1 l I)",
455
+ generate: "Generate",
456
+ copy: "Copy",
457
+ copied: "Copied",
458
+ noCharacterSets: "Pick at least one kind of character."
459
+ }, fe = (r) => {
460
+ const t = globalThis.crypto;
461
+ if (!t || typeof t.getRandomValues != "function")
462
+ throw new Error("generatePassword: crypto.getRandomValues is not available");
463
+ return t.getRandomValues(r);
464
+ };
465
+ let ge = 0;
466
+ function J(r, t) {
467
+ const c = Math.floor(4294967296 / r) * r, n = new Uint32Array(1);
468
+ for (; ; ) {
469
+ const i = t(n)[0];
470
+ if (i < c)
471
+ return i % r;
624
472
  }
625
473
  }
626
- function fe(c, t, i) {
627
- if (!c)
628
- return;
629
- const n = c.getContext("2d");
630
- if (!n)
631
- return;
632
- const r = c.width, l = c.height;
633
- n.clearRect(0, 0, r, l), n.fillStyle = i ? "#1a1a1a" : "#f3f4f6", n.fillRect(0, 0, r, l), n.strokeStyle = i ? "rgba(255,255,255,0.18)" : "rgba(0,0,0,0.18)", n.lineWidth = 1;
634
- for (let p = 0; p < 6; p++)
635
- n.beginPath(), n.moveTo(I(0, r), I(0, l)), n.lineTo(I(0, r), I(0, l)), n.stroke();
636
- n.fillStyle = i ? "#e5e7eb" : "#111827", n.textBaseline = "middle";
637
- const o = r / (t.length + 1);
638
- for (let p = 0; p < t.length; p++) {
639
- const d = I(22, 30);
640
- n.save(), n.translate(o * (p + 1), l / 2 + I(-4, 4)), n.rotate(I(-22, 22) * Math.PI / 180), n.font = `bold ${d}px monospace`, n.fillText(t[p], -d / 3, 0), n.restore();
474
+ function te(r = {}, t = fe) {
475
+ const c = { ...W, ...r }, n = ["lowercase", "uppercase", "digits", "symbols"].filter((s) => c[s]).map((s) => c.excludeAmbiguous ? ee[s].replace(me, "") : ee[s]).filter((s) => s.length > 0);
476
+ if (n.length === 0)
477
+ return "";
478
+ const i = Math.max(n.length, Math.min(1024, Math.floor(c.length))), h = n.join(""), l = n.map((s) => s[J(s.length, t)]);
479
+ for (; l.length < i; )
480
+ l.push(h[J(h.length, t)]);
481
+ for (let s = l.length - 1; s > 0; s--) {
482
+ const u = J(s + 1, t);
483
+ [l[s], l[u]] = [l[u], l[s]];
641
484
  }
485
+ return l.join("");
642
486
  }
643
- const ge = B((c, t) => {
644
- const {
645
- variant: i,
646
- difficulty: n = "medium",
647
- refreshable: r = !0,
648
- verifyToken: l,
649
- expiresMs: o,
650
- label: p = "I'm not a robot",
651
- provider: d = "custom",
652
- siteKey: $,
653
- onVerify: s,
654
- onExpire: C,
655
- onError: b,
656
- onRefresh: x,
657
- theme: g = "light",
658
- size: F = "normal",
659
- customRender: h,
660
- className: m,
661
- style: f
662
- } = c, T = U(null), N = U(null), P = U(void 0), [S, E] = _(0), [k, D] = _("idle"), [O, A] = _(""), [M, u] = _(""), [v, z] = _(0), R = X(
663
- () => pe(i ?? "checkbox", n),
664
- [i, n, S]
665
- ), K = w(() => {
666
- D("idle"), A(""), u(""), z(0), E((y) => y + 1);
667
- }, []), G = w(() => {
668
- K(), x == null || x();
669
- }, [K, x]);
670
- ae(
671
- t,
672
- () => ({ reset: K, refresh: G, container: T.current }),
673
- [K, G]
674
- ), W(() => {
675
- i === "text" && R.kind === "text" && fe(N.current, R.text, g === "dark");
676
- }, [i, R, g]), W(() => {
677
- if (k !== "verified" || !o)
678
- return;
679
- const y = setTimeout(() => {
680
- C == null || C(), K();
681
- }, o);
682
- return () => clearTimeout(y);
683
- }, [k, o, C, K]);
684
- const q = w(() => {
685
- const y = `ntd-cap:${i}:${me()}`;
686
- l ? (D("verifying"), A(""), Promise.resolve().then(() => l(y)).then((Q) => {
687
- Q ? (D("verified"), s == null || s(y)) : (D("error"), A("Verification failed. Please try again."), E((ne) => ne + 1), u(""));
688
- }).catch((Q) => {
689
- D("error"), A("Verification error. Please try again."), b == null || b(Q);
690
- })) : (D("verified"), s == null || s(y));
691
- }, [i, l, s, b]), H = w(() => {
692
- D("error"), A("Incorrect, please try again."), E((y) => y + 1), u("");
693
- }, []), Y = w(() => {
694
- k === "verifying" || k === "verified" || (D("verifying"), A(""), P.current = setTimeout(q, ue));
695
- }, [k, q]);
696
- W(() => () => clearTimeout(P.current), []);
697
- const j = w(() => {
698
- R.kind === "math" ? M.trim() !== "" && Number(M) === R.answer ? q() : H() : R.kind === "text" && (M.trim().toUpperCase() === R.text ? q() : H());
699
- }, [R, M, q, H]), ee = w(
700
- (y) => {
701
- z(y), !(R.kind !== "slider" || k === "verified" || k === "verifying") && Math.abs(y - R.target) <= R.tolerance && q();
487
+ const Ae = ({
488
+ value: r,
489
+ defaultValue: t = "",
490
+ onChange: c,
491
+ options: n,
492
+ defaultOptions: i,
493
+ onOptionsChange: h,
494
+ minLength: l = 8,
495
+ maxLength: s = 64,
496
+ showStrength: u = !0,
497
+ showCopy: S = !0,
498
+ onCopy: d,
499
+ labels: A,
500
+ disabled: b = !1,
501
+ className: k,
502
+ style: _,
503
+ id: F
504
+ }) => {
505
+ const o = { ...pe, ...A }, [p] = g(() => `nice-password-generator-${++ge}`), f = F ?? p, [M, w] = g(() => ({
506
+ ...W,
507
+ ...i
508
+ })), C = n ? { ...W, ...n } : M, [T, E] = g(
509
+ () => r === void 0 && !t ? te({ ...W, ...i, ...n }) : t
510
+ ), N = r ?? T, [I, O] = g(!1), x = H(void 0);
511
+ Q(() => () => clearTimeout(x.current), []);
512
+ const D = $(
513
+ (P) => {
514
+ r === void 0 && E(P), O(!1), c == null || c(P);
702
515
  },
703
- [R, k, q]
704
- );
705
- if (!i)
706
- return d === "custom" && h ? /* @__PURE__ */ e(
707
- "div",
708
- {
709
- ref: T,
710
- className: `nice-captcha nice-captcha--custom${m ? ` ${m}` : ""}`,
711
- style: f,
712
- children: h
713
- }
714
- ) : /* @__PURE__ */ e(
715
- "div",
716
- {
717
- ref: T,
718
- className: `nice-captcha nice-captcha--${d} nice-captcha--${g}${F === "compact" ? " nice-captcha--compact" : ""}${m ? ` ${m}` : ""}`,
719
- style: f,
720
- "data-sitekey": $,
721
- "data-theme": g,
722
- "data-size": F,
723
- children: /* @__PURE__ */ a("div", { className: "nice-captcha__placeholder", children: [
724
- /* @__PURE__ */ a("span", { children: [
725
- "Captcha (",
726
- d,
727
- ")"
728
- ] }),
729
- /* @__PURE__ */ a("p", { children: [
730
- "Load the ",
731
- d,
732
- " SDK to activate verification."
733
- ] })
734
- ] })
735
- }
736
- );
737
- const L = k === "verifying", V = k === "verified", te = `nice-captcha nice-captcha--${i} nice-captcha--${g} nice-captcha--${k}${F === "compact" ? " nice-captcha--compact" : ""}${m ? ` ${m}` : ""}`;
516
+ [r, c]
517
+ ), m = $(
518
+ (P) => D(te(P)),
519
+ [D]
520
+ ), v = (P, L) => {
521
+ const q = { ...C, [P]: L };
522
+ n || w(q), h == null || h(q), m(q);
523
+ }, z = async () => {
524
+ !N || !navigator.clipboard || (await navigator.clipboard.writeText(N), O(!0), clearTimeout(x.current), x.current = setTimeout(() => O(!1), 1500), d == null || d(N));
525
+ }, R = !C.lowercase && !C.uppercase && !C.digits && !C.symbols, B = Math.min(s, Math.max(l, C.length));
738
526
  return /* @__PURE__ */ a(
739
527
  "div",
740
528
  {
741
- ref: T,
742
- className: te,
743
- style: f,
744
- role: "group",
745
- "aria-label": "Captcha challenge",
746
- "data-variant": i,
747
- "data-status": k,
748
- "data-theme": g,
529
+ id: F,
530
+ className: `nice-password-generator${k ? ` ${k}` : ""}`,
531
+ style: _,
749
532
  children: [
750
- i === "checkbox" && /* @__PURE__ */ a(
751
- "button",
752
- {
753
- type: "button",
754
- className: "nice-captcha__checkbox",
755
- role: "checkbox",
756
- "aria-checked": V,
757
- "aria-busy": L,
758
- disabled: L || V,
759
- onClick: Y,
760
- children: [
761
- /* @__PURE__ */ e("span", { className: "nice-captcha__box", "aria-hidden": "true", children: L ? "…" : V ? /* @__PURE__ */ e(
762
- "span",
763
- {
764
- style: {
765
- display: "inline-block",
766
- width: "0.3em",
767
- height: "0.6em",
768
- marginBottom: "0.15em",
769
- borderRight: "0.12em solid currentColor",
770
- borderBottom: "0.12em solid currentColor",
771
- transform: "rotate(45deg)"
772
- }
773
- }
774
- ) : "" }),
775
- /* @__PURE__ */ e("span", { className: "nice-captcha__label", children: p })
776
- ]
777
- }
778
- ),
779
- i === "math" && R.kind === "math" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge", children: [
780
- /* @__PURE__ */ a("span", { className: "nice-captcha__prompt", "aria-hidden": "true", children: [
781
- R.prompt,
782
- " ="
783
- ] }),
533
+ /* @__PURE__ */ a("div", { className: "nice-password-generator__output", children: [
784
534
  /* @__PURE__ */ e(
785
535
  "input",
786
536
  {
787
- className: "nice-input nice-captcha__answer",
788
- type: "number",
789
- inputMode: "numeric",
790
- value: M,
791
- "aria-label": `What is ${R.prompt}?`,
792
- disabled: L || V,
793
- onChange: (y) => u(y.target.value),
794
- onKeyDown: (y) => {
795
- y.key === "Enter" && (y.preventDefault(), j());
796
- }
537
+ id: `${f}-value`,
538
+ className: "nice-password-generator__value",
539
+ type: "text",
540
+ readOnly: !0,
541
+ spellCheck: !1,
542
+ autoComplete: "off",
543
+ value: N,
544
+ "aria-label": o.password
797
545
  }
798
546
  ),
799
547
  /* @__PURE__ */ e(
800
548
  "button",
801
549
  {
802
550
  type: "button",
803
- className: "nice-btn nice-btn--primary nice-captcha__verify",
804
- disabled: L || V || M.trim() === "",
805
- onClick: j,
806
- children: L ? "…" : "Verify"
551
+ className: "nice-password-generator__button",
552
+ onClick: () => m(C),
553
+ disabled: b || R,
554
+ "aria-label": o.generate,
555
+ title: o.generate,
556
+ children: /* @__PURE__ */ e(re, {})
807
557
  }
808
- )
809
- ] }),
810
- i === "text" && R.kind === "text" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge", children: [
811
- /* @__PURE__ */ e(
812
- "canvas",
558
+ ),
559
+ S && /* @__PURE__ */ e(
560
+ "button",
813
561
  {
814
- ref: N,
815
- className: "nice-captcha__canvas",
816
- width: 160,
817
- height: 56,
818
- "aria-hidden": "true"
562
+ type: "button",
563
+ className: "nice-password-generator__button nice-password-generator__button--copy",
564
+ onClick: z,
565
+ disabled: b || !N,
566
+ "aria-live": "polite",
567
+ children: I ? /* @__PURE__ */ a(ae, { children: [
568
+ /* @__PURE__ */ e(ue, {}),
569
+ " ",
570
+ o.copied
571
+ ] }) : o.copy
819
572
  }
820
- ),
573
+ )
574
+ ] }),
575
+ u && /* @__PURE__ */ e(Y, { password: N }),
576
+ /* @__PURE__ */ a("div", { className: "nice-password-generator__length", children: [
577
+ /* @__PURE__ */ e("label", { htmlFor: `${f}-length`, children: o.length }),
821
578
  /* @__PURE__ */ e(
822
579
  "input",
823
580
  {
824
- className: "nice-input nice-captcha__answer",
825
- type: "text",
826
- autoCapitalize: "characters",
827
- autoComplete: "off",
828
- value: M,
829
- "aria-label": "Type the characters shown in the image",
830
- disabled: L || V,
831
- onChange: (y) => u(y.target.value),
832
- onKeyDown: (y) => {
833
- y.key === "Enter" && (y.preventDefault(), j());
834
- }
581
+ id: `${f}-length`,
582
+ type: "range",
583
+ min: l,
584
+ max: s,
585
+ value: B,
586
+ disabled: b,
587
+ onChange: (P) => v("length", Number(P.target.value))
835
588
  }
836
589
  ),
837
- /* @__PURE__ */ e(
590
+ /* @__PURE__ */ e("output", { htmlFor: `${f}-length`, className: "nice-password-generator__length-value", children: B })
591
+ ] }),
592
+ /* @__PURE__ */ e("div", { className: "nice-password-generator__sets", children: ["lowercase", "uppercase", "digits", "symbols", "excludeAmbiguous"].map(
593
+ (P) => /* @__PURE__ */ a("label", { className: "nice-password-generator__option", children: [
594
+ /* @__PURE__ */ e(
595
+ "input",
596
+ {
597
+ type: "checkbox",
598
+ checked: C[P],
599
+ disabled: b,
600
+ onChange: (L) => v(P, L.target.checked)
601
+ }
602
+ ),
603
+ o[P]
604
+ ] }, P)
605
+ ) }),
606
+ R && /* @__PURE__ */ e("p", { className: "nice-password-generator__error", role: "alert", children: o.noCharacterSets })
607
+ ]
608
+ }
609
+ );
610
+ }, Se = /* @__PURE__ */ Object.assign(
611
+ /* @__PURE__ */ G(
612
+ ({
613
+ requireCurrentPassword: r = !0,
614
+ onSubmit: t,
615
+ loading: c = !1,
616
+ error: n,
617
+ success: i,
618
+ minPasswordStrength: h = 2,
619
+ title: l = "Change Password",
620
+ className: s,
621
+ style: u
622
+ }, S) => {
623
+ const [d, A] = g(""), [b, k] = g(""), [_, F] = g(""), o = X(b), p = b === _, f = (!r || d.length > 0) && b.length > 0 && p && o >= h && !c, M = $(
624
+ (w) => {
625
+ w.preventDefault(), f && (t == null || t({
626
+ currentPassword: r ? d : void 0,
627
+ newPassword: b
628
+ }));
629
+ },
630
+ [f, d, b, r, t]
631
+ );
632
+ return /* @__PURE__ */ a(
633
+ "form",
634
+ {
635
+ ref: S,
636
+ className: `nice-change-password${s ? ` ${s}` : ""}`,
637
+ style: u,
638
+ onSubmit: M,
639
+ noValidate: !0,
640
+ children: [
641
+ /* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: l }),
642
+ n && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: n }),
643
+ i && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: i }),
644
+ r && /* @__PURE__ */ a("div", { className: "nice-change-password__field", children: [
645
+ /* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
646
+ /* @__PURE__ */ e(
647
+ "input",
648
+ {
649
+ id: "nice-cp-current",
650
+ className: "nice-input",
651
+ type: "password",
652
+ value: d,
653
+ onChange: (w) => A(w.target.value),
654
+ autoComplete: "current-password",
655
+ disabled: c,
656
+ required: !0
657
+ }
658
+ )
659
+ ] }),
660
+ /* @__PURE__ */ a("div", { className: "nice-change-password__field", children: [
661
+ /* @__PURE__ */ e("label", { htmlFor: "nice-cp-new", children: "New password" }),
662
+ /* @__PURE__ */ e(
663
+ "input",
664
+ {
665
+ id: "nice-cp-new",
666
+ className: "nice-input",
667
+ type: "password",
668
+ value: b,
669
+ onChange: (w) => k(w.target.value),
670
+ autoComplete: "new-password",
671
+ disabled: c,
672
+ required: !0
673
+ }
674
+ ),
675
+ b.length > 0 && /* @__PURE__ */ e(Y, { password: b })
676
+ ] }),
677
+ /* @__PURE__ */ a("div", { className: "nice-change-password__field", children: [
678
+ /* @__PURE__ */ e("label", { htmlFor: "nice-cp-confirm", children: "Confirm new password" }),
679
+ /* @__PURE__ */ e(
680
+ "input",
681
+ {
682
+ id: "nice-cp-confirm",
683
+ className: "nice-input",
684
+ type: "password",
685
+ value: _,
686
+ onChange: (w) => F(w.target.value),
687
+ autoComplete: "new-password",
688
+ disabled: c,
689
+ required: !0
690
+ }
691
+ ),
692
+ _ && !p && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
693
+ ] }),
694
+ /* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !f, children: c ? "…" : "Change Password" })
695
+ ]
696
+ }
697
+ );
698
+ }
699
+ ),
700
+ { displayName: "NiceChangePassword" }
701
+ ), Te = /* @__PURE__ */ Object.assign(
702
+ /* @__PURE__ */ G(
703
+ ({
704
+ secret: r,
705
+ qrCodeUrl: t,
706
+ issuer: c,
707
+ accountName: n,
708
+ onVerify: i,
709
+ loading: h = !1,
710
+ error: l,
711
+ onCancel: s,
712
+ recoveryCodes: u,
713
+ step: S = "setup",
714
+ onStepChange: d,
715
+ className: A,
716
+ style: b
717
+ }, k) => {
718
+ const [_, F] = g(""), [o, p] = g(!1), [f, M] = g(!1), w = $(
719
+ (T) => {
720
+ T.preventDefault(), _.length >= 6 && (i == null || i(_));
721
+ },
722
+ [_, i]
723
+ ), C = `otpauth://totp/${c ? `${c}:` : ""}${n ?? "user"}?secret=${r}${c ? `&issuer=${c}` : ""}&digits=6&period=30`;
724
+ return /* @__PURE__ */ a(
725
+ "div",
726
+ {
727
+ ref: k,
728
+ className: `nice-2fa-setup${A ? ` ${A}` : ""}`,
729
+ style: b,
730
+ children: [
731
+ /* @__PURE__ */ e("h3", { className: "nice-2fa-setup__title", children: "Two-Factor Authentication" }),
732
+ S === "setup" && /* @__PURE__ */ a("div", { className: "nice-2fa-setup__step", children: [
733
+ /* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.):" }),
734
+ t ? /* @__PURE__ */ e("img", { src: t, alt: "2FA QR Code", className: "nice-2fa-setup__qr" }) : /* @__PURE__ */ a("div", { className: "nice-2fa-setup__qr-placeholder", children: [
735
+ /* @__PURE__ */ e("span", { children: "QR Code" }),
736
+ /* @__PURE__ */ e("code", { className: "nice-2fa-setup__uri", children: C })
737
+ ] }),
738
+ /* @__PURE__ */ a("div", { className: "nice-2fa-setup__secret", children: [
739
+ /* @__PURE__ */ e("span", { children: "Or enter manually: " }),
740
+ o ? /* @__PURE__ */ e("code", { className: "nice-2fa-setup__secret-key", children: r }) : /* @__PURE__ */ e("button", { type: "button", onClick: () => p(!0), children: "Show secret key" })
741
+ ] }),
742
+ /* @__PURE__ */ e(
743
+ "button",
744
+ {
745
+ type: "button",
746
+ className: "nice-btn nice-btn--primary",
747
+ onClick: () => d == null ? void 0 : d("verify"),
748
+ children: "Next — Verify"
749
+ }
750
+ )
751
+ ] }),
752
+ S === "verify" && /* @__PURE__ */ a("form", { className: "nice-2fa-setup__step", onSubmit: w, children: [
753
+ /* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Enter the 6-digit code from your authenticator app:" }),
754
+ l && /* @__PURE__ */ e("div", { className: "nice-2fa-setup__error", role: "alert", children: l }),
755
+ /* @__PURE__ */ e(
756
+ "input",
757
+ {
758
+ className: "nice-input nice-2fa-setup__code-input",
759
+ type: "text",
760
+ inputMode: "numeric",
761
+ maxLength: 6,
762
+ value: _,
763
+ onChange: (T) => F(T.target.value.replace(/\D/g, "").slice(0, 6)),
764
+ placeholder: "000000",
765
+ autoFocus: !0,
766
+ disabled: h,
767
+ autoComplete: "one-time-code"
768
+ }
769
+ ),
770
+ /* @__PURE__ */ a("div", { className: "nice-2fa-setup__actions", children: [
771
+ /* @__PURE__ */ e("button", { type: "button", className: "nice-btn", onClick: () => d == null ? void 0 : d("setup"), children: "Back" }),
772
+ /* @__PURE__ */ e(
773
+ "button",
774
+ {
775
+ type: "submit",
776
+ className: "nice-btn nice-btn--primary",
777
+ disabled: h || _.length < 6,
778
+ children: h ? "…" : "Verify"
779
+ }
780
+ )
781
+ ] })
782
+ ] }),
783
+ S === "recovery" && u && /* @__PURE__ */ a("div", { className: "nice-2fa-setup__step", children: [
784
+ /* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Save these recovery codes in a safe place. Each code can only be used once:" }),
785
+ /* @__PURE__ */ e("div", { className: "nice-2fa-setup__recovery-codes", children: u.map((T, E) => /* @__PURE__ */ e("code", { className: "nice-2fa-setup__recovery-code", children: T }, E)) }),
786
+ /* @__PURE__ */ e(
787
+ "button",
788
+ {
789
+ type: "button",
790
+ className: "nice-btn",
791
+ onClick: () => {
792
+ var T;
793
+ (T = navigator.clipboard) == null || T.writeText(u.join(`
794
+ `)), M(!0);
795
+ },
796
+ children: f ? "Copied!" : "Copy all codes"
797
+ }
798
+ ),
799
+ s && /* @__PURE__ */ e("button", { type: "button", className: "nice-btn nice-btn--primary", onClick: s, children: "Done" })
800
+ ] }),
801
+ s && S !== "recovery" && /* @__PURE__ */ e("button", { type: "button", className: "nice-2fa-setup__cancel", onClick: s, children: "Cancel" })
802
+ ]
803
+ }
804
+ );
805
+ }
806
+ ),
807
+ { displayName: "NiceTwoFaSetup" }
808
+ ), be = 500;
809
+ function V(r, t) {
810
+ return Math.floor(Math.random() * (t - r + 1)) + r;
811
+ }
812
+ function _e() {
813
+ return `${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
814
+ }
815
+ function Ne(r, t) {
816
+ switch (r) {
817
+ case "math": {
818
+ const c = t === "easy" ? 5 : t === "hard" ? 20 : 10, n = V(1, c), i = V(1, c), h = t !== "easy" && n >= i && Math.random() < 0.5, l = h ? n - i : n + i;
819
+ return { kind: "math", prompt: `${n} ${h ? "−" : "+"} ${i}`, answer: l };
820
+ }
821
+ case "text": {
822
+ const c = t === "easy" ? 4 : t === "hard" ? 7 : 5, n = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
823
+ let i = "";
824
+ for (let h = 0; h < c; h++)
825
+ i += n[V(0, n.length - 1)];
826
+ return { kind: "text", text: i };
827
+ }
828
+ case "slider":
829
+ return { kind: "slider", target: V(70, 92), tolerance: t === "easy" ? 8 : t === "hard" ? 2 : 4 };
830
+ case "checkbox":
831
+ default:
832
+ return { kind: "checkbox" };
833
+ }
834
+ }
835
+ function we(r, t, c) {
836
+ if (!r)
837
+ return;
838
+ const n = r.getContext("2d");
839
+ if (!n)
840
+ return;
841
+ const i = r.width, h = r.height;
842
+ n.clearRect(0, 0, i, h), n.fillStyle = c ? "#1a1a1a" : "#f3f4f6", n.fillRect(0, 0, i, h), n.strokeStyle = c ? "rgba(255,255,255,0.18)" : "rgba(0,0,0,0.18)", n.lineWidth = 1;
843
+ for (let s = 0; s < 6; s++)
844
+ n.beginPath(), n.moveTo(V(0, i), V(0, h)), n.lineTo(V(0, i), V(0, h)), n.stroke();
845
+ n.fillStyle = c ? "#e5e7eb" : "#111827", n.textBaseline = "middle";
846
+ const l = i / (t.length + 1);
847
+ for (let s = 0; s < t.length; s++) {
848
+ const u = V(22, 30);
849
+ n.save(), n.translate(l * (s + 1), h / 2 + V(-4, 4)), n.rotate(V(-22, 22) * Math.PI / 180), n.font = `bold ${u}px monospace`, n.fillText(t[s], -u / 3, 0), n.restore();
850
+ }
851
+ }
852
+ const Re = /* @__PURE__ */ Object.assign(
853
+ /* @__PURE__ */ G((r, t) => {
854
+ const {
855
+ variant: c,
856
+ difficulty: n = "medium",
857
+ refreshable: i = !0,
858
+ verifyToken: h,
859
+ expiresMs: l,
860
+ label: s = "I'm not a robot",
861
+ provider: u = "custom",
862
+ siteKey: S,
863
+ onVerify: d,
864
+ onExpire: A,
865
+ onError: b,
866
+ onRefresh: k,
867
+ theme: _ = "light",
868
+ size: F = "normal",
869
+ customRender: o,
870
+ className: p,
871
+ style: f
872
+ } = r, M = H(null), w = H(null), C = H(void 0), [T, E] = g(0), [N, I] = g("idle"), [O, x] = g(""), [D, m] = g(""), [v, z] = g(0), R = ne(
873
+ () => Ne(c ?? "checkbox", n),
874
+ [c, n, T]
875
+ ), B = $(() => {
876
+ I("idle"), x(""), m(""), z(0), E((y) => y + 1);
877
+ }, []), P = $(() => {
878
+ B(), k == null || k();
879
+ }, [B, k]);
880
+ oe(
881
+ t,
882
+ () => ({ reset: B, refresh: P, container: M.current }),
883
+ [B, P]
884
+ ), Q(() => {
885
+ c === "text" && R.kind === "text" && we(w.current, R.text, _ === "dark");
886
+ }, [c, R, _]), Q(() => {
887
+ if (N !== "verified" || !l)
888
+ return;
889
+ const y = setTimeout(() => {
890
+ A == null || A(), B();
891
+ }, l);
892
+ return () => clearTimeout(y);
893
+ }, [N, l, A, B]);
894
+ const L = $(() => {
895
+ const y = `ntd-cap:${c}:${_e()}`;
896
+ h ? (I("verifying"), x(""), Promise.resolve().then(() => h(y)).then((Z) => {
897
+ Z ? (I("verified"), d == null || d(y)) : (I("error"), x("Verification failed. Please try again."), E((le) => le + 1), m(""));
898
+ }).catch((Z) => {
899
+ I("error"), x("Verification error. Please try again."), b == null || b(Z);
900
+ })) : (I("verified"), d == null || d(y));
901
+ }, [c, h, d, b]), q = $(() => {
902
+ I("error"), x("Incorrect, please try again."), E((y) => y + 1), m("");
903
+ }, []), ce = $(() => {
904
+ N === "verifying" || N === "verified" || (I("verifying"), x(""), C.current = setTimeout(L, be));
905
+ }, [N, L]);
906
+ Q(() => () => clearTimeout(C.current), []);
907
+ const K = $(() => {
908
+ R.kind === "math" ? D.trim() !== "" && Number(D) === R.answer ? L() : q() : R.kind === "text" && (D.trim().toUpperCase() === R.text ? L() : q());
909
+ }, [R, D, L, q]), se = $(
910
+ (y) => {
911
+ z(y), !(R.kind !== "slider" || N === "verified" || N === "verifying") && Math.abs(y - R.target) <= R.tolerance && L();
912
+ },
913
+ [R, N, L]
914
+ );
915
+ if (!c)
916
+ return u === "custom" && o ? /* @__PURE__ */ e(
917
+ "div",
918
+ {
919
+ ref: M,
920
+ className: `nice-captcha nice-captcha--custom${p ? ` ${p}` : ""}`,
921
+ style: f,
922
+ children: o
923
+ }
924
+ ) : /* @__PURE__ */ e(
925
+ "div",
926
+ {
927
+ ref: M,
928
+ className: `nice-captcha nice-captcha--${u} nice-captcha--${_}${F === "compact" ? " nice-captcha--compact" : ""}${p ? ` ${p}` : ""}`,
929
+ style: f,
930
+ "data-sitekey": S,
931
+ "data-theme": _,
932
+ "data-size": F,
933
+ children: /* @__PURE__ */ a("div", { className: "nice-captcha__placeholder", children: [
934
+ /* @__PURE__ */ a("span", { children: [
935
+ "Captcha (",
936
+ u,
937
+ ")"
938
+ ] }),
939
+ /* @__PURE__ */ a("p", { children: [
940
+ "Load the ",
941
+ u,
942
+ " SDK to activate verification."
943
+ ] })
944
+ ] })
945
+ }
946
+ );
947
+ const j = N === "verifying", U = N === "verified", ie = `nice-captcha nice-captcha--${c} nice-captcha--${_} nice-captcha--${N}${F === "compact" ? " nice-captcha--compact" : ""}${p ? ` ${p}` : ""}`;
948
+ return /* @__PURE__ */ a(
949
+ "div",
950
+ {
951
+ ref: M,
952
+ className: ie,
953
+ style: f,
954
+ role: "group",
955
+ "aria-label": "Captcha challenge",
956
+ "data-variant": c,
957
+ "data-status": N,
958
+ "data-theme": _,
959
+ children: [
960
+ c === "checkbox" && /* @__PURE__ */ a(
838
961
  "button",
839
962
  {
840
963
  type: "button",
841
- className: "nice-btn nice-btn--primary nice-captcha__verify",
842
- disabled: L || V || M.trim() === "",
843
- onClick: j,
844
- children: L ? "…" : "Verify"
964
+ className: "nice-captcha__checkbox",
965
+ role: "checkbox",
966
+ "aria-checked": U,
967
+ "aria-busy": j,
968
+ disabled: j || U,
969
+ onClick: ce,
970
+ children: [
971
+ /* @__PURE__ */ e("span", { className: "nice-captcha__box", "aria-hidden": "true", children: j ? "…" : U ? /* @__PURE__ */ e(
972
+ "span",
973
+ {
974
+ style: {
975
+ display: "inline-block",
976
+ width: "0.3em",
977
+ height: "0.6em",
978
+ marginBottom: "0.15em",
979
+ borderRight: "0.12em solid currentColor",
980
+ borderBottom: "0.12em solid currentColor",
981
+ transform: "rotate(45deg)"
982
+ }
983
+ }
984
+ ) : "" }),
985
+ /* @__PURE__ */ e("span", { className: "nice-captcha__label", children: s })
986
+ ]
845
987
  }
846
- )
847
- ] }),
848
- i === "slider" && R.kind === "slider" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge nice-captcha__challenge--slider", children: [
849
- /* @__PURE__ */ e("span", { className: "nice-captcha__slider-hint", "aria-hidden": "true", children: V ? "Verified" : "Slide to the marker" }),
850
- /* @__PURE__ */ a("div", { className: "nice-captcha__track", children: [
988
+ ),
989
+ c === "math" && R.kind === "math" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge", children: [
990
+ /* @__PURE__ */ a("span", { className: "nice-captcha__prompt", "aria-hidden": "true", children: [
991
+ R.prompt,
992
+ " ="
993
+ ] }),
994
+ /* @__PURE__ */ e(
995
+ "input",
996
+ {
997
+ className: "nice-input nice-captcha__answer",
998
+ type: "number",
999
+ inputMode: "numeric",
1000
+ value: D,
1001
+ "aria-label": `What is ${R.prompt}?`,
1002
+ disabled: j || U,
1003
+ onChange: (y) => m(y.target.value),
1004
+ onKeyDown: (y) => {
1005
+ y.key === "Enter" && (y.preventDefault(), K());
1006
+ }
1007
+ }
1008
+ ),
1009
+ /* @__PURE__ */ e(
1010
+ "button",
1011
+ {
1012
+ type: "button",
1013
+ className: "nice-btn nice-btn--primary nice-captcha__verify",
1014
+ disabled: j || U || D.trim() === "",
1015
+ onClick: K,
1016
+ children: j ? "…" : "Verify"
1017
+ }
1018
+ )
1019
+ ] }),
1020
+ c === "text" && R.kind === "text" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge", children: [
851
1021
  /* @__PURE__ */ e(
852
- "span",
1022
+ "canvas",
853
1023
  {
854
- className: "nice-captcha__target",
855
- "aria-hidden": "true",
856
- style: { left: `${R.target}%` }
1024
+ ref: w,
1025
+ className: "nice-captcha__canvas",
1026
+ width: 160,
1027
+ height: 56,
1028
+ "aria-hidden": "true"
857
1029
  }
858
1030
  ),
859
1031
  /* @__PURE__ */ e(
860
1032
  "input",
861
1033
  {
862
- className: "nice-captcha__slider",
863
- type: "range",
864
- min: 0,
865
- max: 100,
866
- value: v,
867
- "aria-label": "Slide the handle to the marker to verify",
868
- "aria-valuetext": `${v}%`,
869
- disabled: V || L,
870
- onChange: (y) => ee(Number(y.target.value))
1034
+ className: "nice-input nice-captcha__answer",
1035
+ type: "text",
1036
+ autoCapitalize: "characters",
1037
+ autoComplete: "off",
1038
+ value: D,
1039
+ "aria-label": "Type the characters shown in the image",
1040
+ disabled: j || U,
1041
+ onChange: (y) => m(y.target.value),
1042
+ onKeyDown: (y) => {
1043
+ y.key === "Enter" && (y.preventDefault(), K());
1044
+ }
1045
+ }
1046
+ ),
1047
+ /* @__PURE__ */ e(
1048
+ "button",
1049
+ {
1050
+ type: "button",
1051
+ className: "nice-btn nice-btn--primary nice-captcha__verify",
1052
+ disabled: j || U || D.trim() === "",
1053
+ onClick: K,
1054
+ children: j ? "…" : "Verify"
1055
+ }
1056
+ )
1057
+ ] }),
1058
+ c === "slider" && R.kind === "slider" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge nice-captcha__challenge--slider", children: [
1059
+ /* @__PURE__ */ e("span", { className: "nice-captcha__slider-hint", "aria-hidden": "true", children: U ? "Verified" : "Slide to the marker" }),
1060
+ /* @__PURE__ */ a("div", { className: "nice-captcha__track", children: [
1061
+ /* @__PURE__ */ e(
1062
+ "span",
1063
+ {
1064
+ className: "nice-captcha__target",
1065
+ "aria-hidden": "true",
1066
+ style: { left: `${R.target}%` }
1067
+ }
1068
+ ),
1069
+ /* @__PURE__ */ e(
1070
+ "input",
1071
+ {
1072
+ className: "nice-captcha__slider",
1073
+ type: "range",
1074
+ min: 0,
1075
+ max: 100,
1076
+ value: v,
1077
+ "aria-label": "Slide the handle to the marker to verify",
1078
+ "aria-valuetext": `${v}%`,
1079
+ disabled: U || j,
1080
+ onChange: (y) => se(Number(y.target.value))
1081
+ }
1082
+ )
1083
+ ] })
1084
+ ] }),
1085
+ /* @__PURE__ */ a("div", { className: "nice-captcha__footer", children: [
1086
+ /* @__PURE__ */ e("div", { className: "nice-captcha__message", role: "status", "aria-live": "polite", children: O }),
1087
+ i && /* @__PURE__ */ e(
1088
+ "button",
1089
+ {
1090
+ type: "button",
1091
+ className: "nice-captcha__refresh",
1092
+ "aria-label": "Refresh challenge",
1093
+ title: "Refresh challenge",
1094
+ onClick: P,
1095
+ children: /* @__PURE__ */ e(re, {})
871
1096
  }
872
1097
  )
873
1098
  ] })
874
- ] }),
875
- /* @__PURE__ */ a("div", { className: "nice-captcha__footer", children: [
876
- /* @__PURE__ */ e("div", { className: "nice-captcha__message", role: "status", "aria-live": "polite", children: O }),
877
- r && /* @__PURE__ */ e(
878
- "button",
879
- {
880
- type: "button",
881
- className: "nice-captcha__refresh",
882
- "aria-label": "Refresh challenge",
883
- title: "Refresh challenge",
884
- onClick: G,
885
- children: /* @__PURE__ */ e(he, {})
886
- }
887
- )
888
- ] })
889
- ]
890
- }
891
- );
892
- });
893
- ge.displayName = "NiceCaptcha";
894
- const _e = [
1099
+ ]
1100
+ }
1101
+ );
1102
+ }),
1103
+ { displayName: "NiceCaptcha" }
1104
+ ), ve = [
895
1105
  { id: "google", label: "Google", color: "#4285f4", textColor: "#fff" },
896
1106
  { id: "microsoft", label: "Microsoft", color: "#00a4ef", textColor: "#fff" },
897
1107
  { id: "discord", label: "Discord", color: "#5865f2", textColor: "#fff" },
898
1108
  { id: "spotify", label: "Spotify", color: "#1db954", textColor: "#fff" },
899
1109
  { id: "github", label: "GitHub", color: "#24292e", textColor: "#fff" }
900
- ], be = B(
901
- ({
902
- providers: c = _e,
903
- onProviderClick: t,
904
- disabled: i = !1,
905
- loadingProvider: n,
906
- direction: r = "vertical",
907
- separatorText: l = "or continue with",
908
- showSeparator: o = !0,
909
- className: p,
1110
+ ], Fe = /* @__PURE__ */ Object.assign(
1111
+ /* @__PURE__ */ G(
1112
+ ({
1113
+ providers: r = ve,
1114
+ onProviderClick: t,
1115
+ disabled: c = !1,
1116
+ loadingProvider: n,
1117
+ direction: i = "vertical",
1118
+ separatorText: h = "or continue with",
1119
+ showSeparator: l = !0,
1120
+ className: s,
1121
+ style: u
1122
+ }, S) => /* @__PURE__ */ a(
1123
+ "div",
1124
+ {
1125
+ ref: S,
1126
+ className: `nice-oauth nice-oauth--${i}${s ? ` ${s}` : ""}`,
1127
+ style: u,
1128
+ children: [
1129
+ l && /* @__PURE__ */ a("div", { className: "nice-oauth__separator", children: [
1130
+ /* @__PURE__ */ e("hr", {}),
1131
+ /* @__PURE__ */ e("span", { children: h }),
1132
+ /* @__PURE__ */ e("hr", {})
1133
+ ] }),
1134
+ /* @__PURE__ */ e("div", { className: "nice-oauth__buttons", children: r.map((d) => /* @__PURE__ */ a(
1135
+ "button",
1136
+ {
1137
+ type: "button",
1138
+ className: `nice-oauth__btn${n === d.id ? " nice-oauth__btn--loading" : ""}`,
1139
+ style: { backgroundColor: d.color, color: d.textColor },
1140
+ onClick: () => t == null ? void 0 : t(d.id),
1141
+ disabled: c || !!n,
1142
+ children: [
1143
+ d.icon && /* @__PURE__ */ e("span", { className: "nice-oauth__btn-icon", children: d.icon }),
1144
+ /* @__PURE__ */ e("span", { className: "nice-oauth__btn-label", children: n === d.id ? "…" : d.label })
1145
+ ]
1146
+ },
1147
+ d.id
1148
+ )) })
1149
+ ]
1150
+ }
1151
+ )
1152
+ ),
1153
+ { displayName: "NiceOAuthButtons" }
1154
+ ), Me = /* @__PURE__ */ G(function(t, c) {
1155
+ const {
1156
+ tokens: n,
1157
+ onCreate: i,
1158
+ onRevoke: h,
1159
+ availableScopes: l = [],
1160
+ maxTokens: s = 10,
1161
+ title: u = "API Tokens",
1162
+ className: S,
910
1163
  style: d
911
- }, $) => /* @__PURE__ */ a(
912
- "div",
913
- {
914
- ref: $,
915
- className: `nice-oauth nice-oauth--${r}${p ? ` ${p}` : ""}`,
916
- style: d,
917
- children: [
918
- o && /* @__PURE__ */ a("div", { className: "nice-oauth__separator", children: [
919
- /* @__PURE__ */ e("hr", {}),
920
- /* @__PURE__ */ e("span", { children: l }),
921
- /* @__PURE__ */ e("hr", {})
922
- ] }),
923
- /* @__PURE__ */ e("div", { className: "nice-oauth__buttons", children: c.map((s) => /* @__PURE__ */ a(
924
- "button",
925
- {
926
- type: "button",
927
- className: `nice-oauth__btn${n === s.id ? " nice-oauth__btn--loading" : ""}`,
928
- style: { backgroundColor: s.color, color: s.textColor },
929
- onClick: () => t == null ? void 0 : t(s.id),
930
- disabled: i || !!n,
931
- children: [
932
- s.icon && /* @__PURE__ */ e("span", { className: "nice-oauth__btn-icon", children: s.icon }),
933
- /* @__PURE__ */ e("span", { className: "nice-oauth__btn-label", children: n === s.id ? "…" : s.label })
934
- ]
935
- },
936
- s.id
937
- )) })
938
- ]
1164
+ } = t, [A, b] = g(!1), [k, _] = g(""), [F, o] = g([]), [p, f] = g("90"), [M, w] = g(null), [C, T] = g(!1), [E, N] = g(null), I = $(async () => {
1165
+ if (!(!i || !k.trim())) {
1166
+ T(!0);
1167
+ try {
1168
+ const m = p ? parseInt(p, 10) : void 0, v = await i(k.trim(), F, m);
1169
+ w(v), _(""), o([]), b(!1);
1170
+ } finally {
1171
+ T(!1);
1172
+ }
939
1173
  }
940
- )
941
- );
942
- be.displayName = "NiceOAuthButtons";
943
- const ke = B(
944
- function(t, i) {
945
- const {
946
- tokens: n,
947
- onCreate: r,
948
- onRevoke: l,
949
- availableScopes: o = [],
950
- maxTokens: p = 10,
951
- title: d = "API Tokens",
952
- className: $,
953
- style: s
954
- } = t, [C, b] = _(!1), [x, g] = _(""), [F, h] = _([]), [m, f] = _("90"), [T, N] = _(null), [P, S] = _(!1), [E, k] = _(null), D = w(async () => {
955
- if (!(!r || !x.trim())) {
956
- S(!0);
1174
+ }, [i, k, F, p]), O = $(
1175
+ async (m) => {
1176
+ if (h) {
1177
+ N(m);
957
1178
  try {
958
- const u = m ? parseInt(m, 10) : void 0, v = await r(x.trim(), F, u);
959
- N(v), g(""), h([]), b(!1);
1179
+ await h(m);
960
1180
  } finally {
961
- S(!1);
1181
+ N(null);
962
1182
  }
963
1183
  }
964
- }, [r, x, F, m]), O = w(
965
- async (u) => {
966
- if (l) {
967
- k(u);
968
- try {
969
- await l(u);
970
- } finally {
971
- k(null);
972
- }
1184
+ },
1185
+ [h]
1186
+ ), x = (m) => {
1187
+ o(
1188
+ (v) => v.includes(m) ? v.filter((z) => z !== m) : [...v, m]
1189
+ );
1190
+ }, D = n.length < s;
1191
+ return /* @__PURE__ */ a("div", { ref: c, className: `nice-token-management ${S ?? ""}`, style: d, children: [
1192
+ /* @__PURE__ */ a("div", { className: "nice-token-management__header", children: [
1193
+ /* @__PURE__ */ e("h3", { children: u }),
1194
+ D && /* @__PURE__ */ e(
1195
+ "button",
1196
+ {
1197
+ className: "nice-token-management__new-btn",
1198
+ onClick: () => b(!0),
1199
+ disabled: A,
1200
+ children: "+ New Token"
973
1201
  }
974
- },
975
- [l]
976
- ), A = (u) => {
977
- h(
978
- (v) => v.includes(u) ? v.filter((z) => z !== u) : [...v, u]
979
- );
980
- }, M = n.length < p;
981
- return /* @__PURE__ */ a("div", { ref: i, className: `nice-token-management ${$ ?? ""}`, style: s, children: [
982
- /* @__PURE__ */ a("div", { className: "nice-token-management__header", children: [
983
- /* @__PURE__ */ e("h3", { children: d }),
984
- M && /* @__PURE__ */ e(
985
- "button",
1202
+ )
1203
+ ] }),
1204
+ M && /* @__PURE__ */ a("div", { className: "nice-token-management__reveal", children: [
1205
+ /* @__PURE__ */ a("p", { children: [
1206
+ /* @__PURE__ */ e("strong", { children: "New token created!" }),
1207
+ " Copy it now — it won't be shown again."
1208
+ ] }),
1209
+ /* @__PURE__ */ e("code", { className: "nice-token-management__token-value", children: M }),
1210
+ /* @__PURE__ */ e("button", { onClick: () => w(null), children: "Dismiss" })
1211
+ ] }),
1212
+ A && /* @__PURE__ */ a("div", { className: "nice-token-management__create-form", children: [
1213
+ /* @__PURE__ */ a("label", { children: [
1214
+ "Name",
1215
+ /* @__PURE__ */ e(
1216
+ "input",
986
1217
  {
987
- className: "nice-token-management__new-btn",
988
- onClick: () => b(!0),
989
- disabled: C,
990
- children: "+ New Token"
1218
+ type: "text",
1219
+ value: k,
1220
+ onChange: (m) => _(m.target.value),
1221
+ placeholder: "My API token",
1222
+ maxLength: 64
991
1223
  }
992
1224
  )
993
1225
  ] }),
994
- T && /* @__PURE__ */ a("div", { className: "nice-token-management__reveal", children: [
995
- /* @__PURE__ */ a("p", { children: [
996
- /* @__PURE__ */ e("strong", { children: "New token created!" }),
997
- " Copy it now — it won't be shown again."
998
- ] }),
999
- /* @__PURE__ */ e("code", { className: "nice-token-management__token-value", children: T }),
1000
- /* @__PURE__ */ e("button", { onClick: () => N(null), children: "Dismiss" })
1001
- ] }),
1002
- C && /* @__PURE__ */ a("div", { className: "nice-token-management__create-form", children: [
1003
- /* @__PURE__ */ a("label", { children: [
1004
- "Name",
1005
- /* @__PURE__ */ e(
1006
- "input",
1007
- {
1008
- type: "text",
1009
- value: x,
1010
- onChange: (u) => g(u.target.value),
1011
- placeholder: "My API token",
1012
- maxLength: 64
1013
- }
1014
- )
1015
- ] }),
1016
- o.length > 0 && /* @__PURE__ */ a("fieldset", { children: [
1017
- /* @__PURE__ */ e("legend", { children: "Scopes" }),
1018
- o.map((u) => /* @__PURE__ */ a("label", { className: "nice-token-management__scope", children: [
1019
- /* @__PURE__ */ e(
1020
- "input",
1021
- {
1022
- type: "checkbox",
1023
- checked: F.includes(u),
1024
- onChange: () => A(u)
1025
- }
1026
- ),
1027
- u
1028
- ] }, u))
1029
- ] }),
1030
- /* @__PURE__ */ a("label", { children: [
1031
- "Expires in (days)",
1226
+ l.length > 0 && /* @__PURE__ */ a("fieldset", { children: [
1227
+ /* @__PURE__ */ e("legend", { children: "Scopes" }),
1228
+ l.map((m) => /* @__PURE__ */ a("label", { className: "nice-token-management__scope", children: [
1032
1229
  /* @__PURE__ */ e(
1033
1230
  "input",
1034
1231
  {
1035
- type: "number",
1036
- value: m,
1037
- onChange: (u) => f(u.target.value),
1038
- min: 1,
1039
- max: 365
1232
+ type: "checkbox",
1233
+ checked: F.includes(m),
1234
+ onChange: () => x(m)
1040
1235
  }
1041
- )
1042
- ] }),
1043
- /* @__PURE__ */ a("div", { className: "nice-token-management__create-actions", children: [
1044
- /* @__PURE__ */ e("button", { onClick: D, disabled: P || !x.trim(), children: P ? "Creating…" : "Create Token" }),
1045
- /* @__PURE__ */ e("button", { onClick: () => b(!1), children: "Cancel" })
1046
- ] })
1236
+ ),
1237
+ m
1238
+ ] }, m))
1047
1239
  ] }),
1048
- n.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-token-management__empty", children: "No API tokens yet." }) : /* @__PURE__ */ a("table", { className: "nice-token-management__table", children: [
1049
- /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ a("tr", { children: [
1050
- /* @__PURE__ */ e("th", { children: "Name" }),
1051
- /* @__PURE__ */ e("th", { children: "Prefix" }),
1052
- /* @__PURE__ */ e("th", { children: "Created" }),
1053
- /* @__PURE__ */ e("th", { children: "Expires" }),
1054
- /* @__PURE__ */ e("th", { children: "Last Used" }),
1055
- /* @__PURE__ */ e("th", { children: "Scopes" }),
1056
- /* @__PURE__ */ e("th", {})
1057
- ] }) }),
1058
- /* @__PURE__ */ e("tbody", { children: n.map((u) => {
1059
- var v;
1060
- return /* @__PURE__ */ a("tr", { children: [
1061
- /* @__PURE__ */ e("td", { children: u.name }),
1062
- /* @__PURE__ */ e("td", { children: /* @__PURE__ */ a("code", { children: [
1063
- u.prefix,
1064
- "…"
1065
- ] }) }),
1066
- /* @__PURE__ */ e("td", { children: u.createdAt }),
1067
- /* @__PURE__ */ e("td", { children: u.expiresAt ?? "—" }),
1068
- /* @__PURE__ */ e("td", { children: u.lastUsedAt ?? "Never" }),
1069
- /* @__PURE__ */ e("td", { children: ((v = u.scopes) == null ? void 0 : v.join(", ")) || "—" }),
1070
- /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
1071
- "button",
1072
- {
1073
- className: "nice-token-management__revoke-btn",
1074
- onClick: () => O(u.id),
1075
- disabled: E === u.id,
1076
- children: E === u.id ? "Revoking…" : "Revoke"
1077
- }
1078
- ) })
1079
- ] }, u.id);
1080
- }) })
1240
+ /* @__PURE__ */ a("label", { children: [
1241
+ "Expires in (days)",
1242
+ /* @__PURE__ */ e(
1243
+ "input",
1244
+ {
1245
+ type: "number",
1246
+ value: p,
1247
+ onChange: (m) => f(m.target.value),
1248
+ min: 1,
1249
+ max: 365
1250
+ }
1251
+ )
1252
+ ] }),
1253
+ /* @__PURE__ */ a("div", { className: "nice-token-management__create-actions", children: [
1254
+ /* @__PURE__ */ e("button", { onClick: I, disabled: C || !k.trim(), children: C ? "Creating…" : "Create Token" }),
1255
+ /* @__PURE__ */ e("button", { onClick: () => b(!1), children: "Cancel" })
1081
1256
  ] })
1082
- ] });
1083
- }
1084
- );
1257
+ ] }),
1258
+ n.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-token-management__empty", children: "No API tokens yet." }) : /* @__PURE__ */ a("table", { className: "nice-token-management__table", children: [
1259
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ a("tr", { children: [
1260
+ /* @__PURE__ */ e("th", { children: "Name" }),
1261
+ /* @__PURE__ */ e("th", { children: "Prefix" }),
1262
+ /* @__PURE__ */ e("th", { children: "Created" }),
1263
+ /* @__PURE__ */ e("th", { children: "Expires" }),
1264
+ /* @__PURE__ */ e("th", { children: "Last Used" }),
1265
+ /* @__PURE__ */ e("th", { children: "Scopes" }),
1266
+ /* @__PURE__ */ e("th", {})
1267
+ ] }) }),
1268
+ /* @__PURE__ */ e("tbody", { children: n.map((m) => {
1269
+ var v;
1270
+ return /* @__PURE__ */ a("tr", { children: [
1271
+ /* @__PURE__ */ e("td", { children: m.name }),
1272
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ a("code", { children: [
1273
+ m.prefix,
1274
+ "…"
1275
+ ] }) }),
1276
+ /* @__PURE__ */ e("td", { children: m.createdAt }),
1277
+ /* @__PURE__ */ e("td", { children: m.expiresAt ?? "—" }),
1278
+ /* @__PURE__ */ e("td", { children: m.lastUsedAt ?? "Never" }),
1279
+ /* @__PURE__ */ e("td", { children: ((v = m.scopes) == null ? void 0 : v.join(", ")) || "—" }),
1280
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
1281
+ "button",
1282
+ {
1283
+ className: "nice-token-management__revoke-btn",
1284
+ onClick: () => O(m.id),
1285
+ disabled: E === m.id,
1286
+ children: E === m.id ? "Revoking…" : "Revoke"
1287
+ }
1288
+ ) })
1289
+ ] }, m.id);
1290
+ }) })
1291
+ ] })
1292
+ ] });
1293
+ });
1085
1294
  export {
1086
- ge as NiceCaptcha,
1087
- oe as NiceChangePassword,
1088
- ce as NiceLoginForm,
1089
- be as NiceOAuthButtons,
1090
- Z as NicePasswordStrength,
1091
- le as NiceRegistrationForm,
1092
- ke as NiceTokenManagement,
1093
- de as NiceTwoFaSetup,
1094
- J as calcPasswordStrength,
1095
- ye as useAuth
1295
+ Re as NiceCaptcha,
1296
+ Se as NiceChangePassword,
1297
+ xe as NiceLoginForm,
1298
+ Fe as NiceOAuthButtons,
1299
+ Ae as NicePasswordGenerator,
1300
+ Y as NicePasswordStrength,
1301
+ $e as NiceRegistrationForm,
1302
+ Me as NiceTokenManagement,
1303
+ Te as NiceTwoFaSetup,
1304
+ X as calcPasswordStrength,
1305
+ te as generatePassword,
1306
+ Ce as useAuth
1096
1307
  };