@nice2dev/auth 1.2.0 → 1.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,147 @@
1
1
  # @nice2dev/auth — Changelog
2
2
 
3
+ ## 1.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 06eb0d2: 1.2.2 — library texts through the translator, a translator in the packages that had none, and the
8
+ end of the hook-dependency warnings. Nothing removed or renamed. Upgrade notes:
9
+ `documentation/omniverk/OMNIVERK_UPGRADE_1.2.2.md`.
10
+
11
+ **Translations.** 2,825 new keys in the global dictionary (en, pl, de, fr, es, uk), 80 in the local
12
+ dictionaries of ui-math, ui-diagrams and ui-presentations: column headers, option labels, texts in
13
+ conditions and templates, messages given to setters, labels returned by helpers, Polish texts that
14
+ were the English default. Relative dates through `Intl.RelativeTimeFormat`, plural forms through
15
+ `…One` / `…Many` keys. ui-science, ui-platform, ui-mobile, auth, licensing, templates, social and
16
+ the icon tools translate through `useNiceTranslation` (new peer `@nice2dev/ui-core ^1.2.0`);
17
+ ui-security reads the global translator when its own provider is absent.
18
+
19
+ **Additions.** `labelKey` on ui-mobile `TabItem` and `SwipeAction` (the presets set it);
20
+ `registerWebAuthn` / `authenticateWebAuthn` take the WebAuthn options `NiceWebAuthnButton` used to
21
+ drop (defaults unchanged); `NiceKeyboardHint` shows `descriptionKey`. Eight icons in
22
+ `@nice2dev/icons` — `NtdPoint`, `NtdSegment`, `NtdPerpendicular`, `NtdParallel`, `NtdMidpoint`,
23
+ `NtdAngleBisector`, `NtdGroup`, `NtdUngroup` — and the same names as `NiceIcon` built-ins.
24
+
25
+ **Behaviour changes, agreed.** ui-math, ui-diagrams and ui-presentations follow the app's global
26
+ `NiceI18nProvider` language when their own provider is absent (they stayed English);
27
+ `NicePresentationEditor` without `lang` takes the surrounding language. Icons drawn as glyphs are
28
+ Nice icons: the `NiceGeometry` tools, Align / Group / Ungroup / Layout of the diagram toolbar, the
29
+ presentation grid toggle, zoom and "Add Track" of `NiceDMXTimeline`. icons-gaming and
30
+ icons-filetypes name an icon by its `title` and are decorative without one, like `createIcon`
31
+ (screen readers read "GiHeart" or "DOCX file icon"); new optional `title` on the gaming icon props.
32
+
33
+ **Hook dependencies (161 → 0).** Fixed along the way: `NiceLowPowerMode` re-rendered forever from
34
+ mount and overflowed the stack on wake; `GenericPlayer` / `NiceGenericPlayerStage` restarted the
35
+ track on a volume change; `NiceDMXTimeline` called `onPlay` on every frame and missed cues added
36
+ during playback; `NiceConflictResolution` `autoResolve` never resolved; `NiceMAM` selected by the
37
+ previous filter; `NiceRulesEngine` "Run All" kept only the last result; `NiceCodeEditor` saved with
38
+ the first render's `onSave`; a consumer's cursor handler switched off `NiceCodeEditorAI`
39
+ completion; `useRadioStream` lost a volume set before the first play; `NiceGameEditor` shortcuts,
40
+ `useVoiceControl` continuous sessions, `NiceDeviceTrust` with a host storing the score.
41
+
42
+ ## 1.2.1
43
+
44
+ ### Patch Changes
45
+
46
+ - 8c82c30: 1.2.1 — the decisions that waited since 1.2.0, and the debts the CI gates were holding. One API
47
+ change, agreed: `NiceIconSuggestorAI` suggests Nice icons only. Two stylesheets to import if you use
48
+ the packages: `@nice2dev/social/style.css`, `@nice2dev/ui-science/style.css`. Upgrade notes:
49
+ `documentation/omniverk/OMNIVERK_UPGRADE_1.2.1.md`.
50
+
51
+ **Tree-shaking.** An import from a package no longer brings the whole package. Module-level
52
+ statements that may have a side effect — a `displayName` assigned after each component (now
53
+ `Object.assign` inside `/* @__PURE__ */`, or under a development check for plain functions),
54
+ unannotated `forwardRef` / `memo` / `createContext` / icon-factory calls, spreads, registries filled
55
+ at import, `<style>` tags injected at import, a direct `eval` in ui-math — are gone. One import from
56
+ each of 53 packages: 5066.5 kB → 1171.6 kB (`@nice2dev/ui` 1928.2 kB → 12.9 kB, icon packs 48–275 kB
57
+ → 1.6–2.6 kB). `defaultViewRegistry` has the Nice\* input controls from the start, each loading its
58
+ module on first render; sixteen controls add their styles to `<head>` on first render.
59
+
60
+ **Dead code.** 405 source files no entry point imported (never on npm) are deleted;
61
+ `NiceClipboardStack` (`@nice2dev/ui`) and `NiceSampleBrowser` (`@nice2dev/ui-audio`), finished and
62
+ documented, are exported.
63
+
64
+ **ui-mobile draws Nice icons.** New peer `@nice2dev/icons ^1.2.0`; `TabIcons`, `DrawerIcons`,
65
+ `HeaderIcons`, the `NiceSwipeActions` presets and the `NiceInfiniteScroll` states are `Ntd*` icons
66
+ instead of pasted `<svg>`, simple glyphs are CSS marks. `@nice2dev/icons` adds `NtdReply` and
67
+ `NtdInbox`; an icon no longer throws without `window.matchMedia`.
68
+
69
+ **`NiceIconSuggestorAI` (breaking, agreed).** `AIIconLibrary` is `'nice'`; `svgPath` and `unicode`
70
+ left `AISuggestedIcon`; the preview is a `<NiceIcon>`, "Copy SVG" is "Copy JSX".
71
+
72
+ **Peer ranges.** Every internal `@nice2dev/*` peer is `^1.2.0` (was as wide as `^1.0.20`), except
73
+ `@nice2dev/icons ^1.2.1` where a package draws an icon new in 1.2.1: ui-mobile (`NtdReply`,
74
+ `NtdInbox`), ui-audio (`NtdMicrophoneOff`) and ui-security (`NtdBackspace`). ui-security, licensing
75
+ (`^1.2.0`) and templates (`^1.2.0`) gain the `@nice2dev/icons` peer: their glyph icons (`⌫`, `←`,
76
+ `→`, `↑`, `↓`) are Nice icons now. `@nice2dev/icons` adds `NtdBackspace`.
77
+
78
+ **Class names inside components.** 834 class names in library stylesheets had no `nice-` prefix
79
+ (`.tab-button`, `.status-badge`, `.selected`, …) and styled every element of that name on the page.
80
+ They follow `nice-{block}__{element}--{modifier}` now — no change on screen. The class theme hooks
81
+ next to `[data-theme]` on seven controls (`dark` on the AI chart / data grid / code and HTML
82
+ editors / form builder, `light-theme` on `NiceMAM` and `NiceVideoAnnotator`) are `nice-dark` /
83
+ `nice-light`; `NiceLowPowerMode` marks `<html>` with `nice-lpm-no-animations` /
84
+ `nice-lpm-reduced-quality`; the `NiceVideoEditor` of `@nice2dev/ui-video` styles its elements under
85
+ `nice-video-studio`, so they no longer collide with the `NiceVideoEditor` of `@nice2dev/ui`.
86
+ Rules for classes nothing rendered are gone, among them the stylesheet of `NiceGanttChart`, which
87
+ left ui-erp in 1.0.10.
88
+
89
+ **Translations.** About 3,400 UI texts in 32 packages were hard-coded; they go through `t()` now,
90
+ with the English text unchanged and pl / de / fr / es / uk in `@nice2dev/i18n` (ui-diagrams,
91
+ ui-presentations and ui-math in their own dictionaries). In `@nice2dev/events` and
92
+ `@nice2dev/admin` that includes column headers, option labels and the statuses and roles they used
93
+ to print raw (`checked-in`, `no-show`) — English labels for those come from the dictionary. ui-3d and ui-graphics read the app's
94
+ global translator, as ui-audio does since 1.2.0 — their own provider overrides it. ui-audio's
95
+ controls used 631 keys the dictionary did not have (English in every language), and the radio
96
+ player showed raw keys (`search_stations`). Texts that were hard-coded **in Polish** — in
97
+ `NiceSidebarNav`, `NiceNetworkDiscoveryPanel`, the backup and smart-home controls,
98
+ `NiceSavedQueryPanel`, `NiceNotificationPreferences`, the ui-buildings panels, the ui-printing
99
+ template editor and the photo editor — default to English now; Polish is in the dictionary. English
100
+ plurals glued on (`result{s}`) are two keys. `presentationsTranslator(lang)` (ui-presentations)
101
+ translates outside its provider.
102
+
103
+ **List props are optional.** 170 list props (`items`, `columns`, `data`, …) in 15 packages that
104
+ were required without a default are optional, with a stable empty default; every one of those
105
+ controls mounts without data (tested). `NiceStockChart` without data no longer computes NaN
106
+ coordinates.
107
+
108
+ **Unstyled components get stylesheets.** 98 components rendered class names no stylesheet had —
109
+ admin panels, auth forms, events rounds and pickers, the ERP invoice / purchase order / VAT table /
110
+ HR dashboard, the radio player, `NiceInbox`, PWA prompts, `NiceViewRenderer`, shells, smart-home,
111
+ … The fixed layout that sat in inline style objects is in classes now, so an app can override it;
112
+ values that depend on data stay inline. **`@nice2dev/social` and `@nice2dev/ui-science` ship a
113
+ stylesheet — import `@nice2dev/social/style.css` / `@nice2dev/ui-science/style.css`.** ui-science's
114
+ `sideEffects` is `["*.css"]`. Colours, spacing and radii in every stylesheet come from theme tokens
115
+ (visible in dark themes: `NiceRecipe` difficulty badges, transcoder states, warehouse heat map).
116
+
117
+ **Icons only from Nice.** About 130 glyphs (`×`, `→`, `↑`) and 100 pasted `<svg>` used as icons
118
+ are Nice icons; 11 `<svg>` stay as the control's own graphic (logos, spinners, checkbox mark). `NiceIcon`
119
+ gains `pin`, `mic-off`, `log-out`, `chevrons-left`, `chevrons-right`, `zoom-in`, `zoom-out`,
120
+ `navigation`, `refresh-ccw`, `minimize` and `smartphone`; `@nice2dev/icons` gains
121
+ `NtdMicrophoneOff`. The `icon` fields of the module, menu, tab, mode, quick-action, scene and admin
122
+ widget DTOs, notification channels and view toolbar items are rendered through `NiceIcon` — they
123
+ used to be printed as text. `NiceRatings` `thumbs` draws shapes instead of emoji.
124
+
125
+ **Dialogs instead of `window.prompt` / `confirm` / `alert`.** New `useNiceDialogs()` — `prompt`,
126
+ `confirm` and `alert` as promises on `NicePromptDialog` / `NiceConfirmDialog` — and
127
+ `NiceConfirmDialog.showReject`. Seventeen controls asked through the browser's blocking dialogs and
128
+ use the library's now (`NiceFileManager`, `NiceHtmlEditor`, `NiceViewRenderer` action `confirm`, the 3D,
129
+ vector and pixel editors, …). Keys pressed in `NicePromptDialog` / `NiceConfirmDialog` no longer
130
+ reach the page's shortcuts (Escape still closes them), and `NicePromptDialog`'s backdrop covers the
131
+ whole viewport.
132
+
133
+ **Smaller fixes.** `NiceFileManager.items` is optional. `NiceMLStudio` status badges: `draft`,
134
+ `registered`, `archived`, `cancelled` get a neutral colour, deploying / stopped deployments theirs.
135
+ Component docs (`doc.json`) list only props the components have. `NiceMobileTabs`: tabs beyond
136
+ `maxTabs` open from "More" (it only logged). `NiceInventoryManager`: new `onCreatePurchaseOrder`;
137
+ without it the "Create PO" button is gone (it only logged). Keyboard: `NiceNavShell` tabs follow the
138
+ WAI-ARIA tabs pattern, clickable `NiceDeviceTile` / `NiceCardGroup` cards and animated icons with
139
+ `trigger="click"` are focusable. ui-math: `CalculatorService.evaluate` parses instead of running
140
+ `new Function` (`asin`, `sinh`, `ceil`, exponents and `angleUnit` were wrong); `ExpressionParser`
141
+ takes `functions`, `constants`, `ignoreCase` and `strict`, multiplies implicitly (`2x`) and reads `^`
142
+ right to left. `InvoiceLine.vatRate` and `VatRate.rate` are documented as fractions (0.23).
143
+ `AmqpServerBinding` is `Record<string, never>`.
144
+
3
145
  ## 1.2.0
4
146
 
5
147
  ### Minor Changes
@@ -70,4 +70,6 @@ export interface NiceCaptchaProps {
70
70
  * SECURITY: built-in challenges run client-side and are a UX/deterrent layer
71
71
  * only. Enforce real verification on the server (see `verifyToken`).
72
72
  */
73
- export declare const NiceCaptcha: React.ForwardRefExoticComponent<NiceCaptchaProps & React.RefAttributes<NiceCaptchaHandle>>;
73
+ export declare const NiceCaptcha: React.ForwardRefExoticComponent<NiceCaptchaProps & React.RefAttributes<NiceCaptchaHandle>> & {
74
+ displayName: string;
75
+ };
@@ -24,4 +24,6 @@ export interface NiceChangePasswordProps {
24
24
  /**
25
25
  * {@link NiceChangePassword} — Change/reset password form with strength meter.
26
26
  */
27
- export declare const NiceChangePassword: React.ForwardRefExoticComponent<NiceChangePasswordProps & React.RefAttributes<HTMLFormElement>>;
27
+ export declare const NiceChangePassword: React.ForwardRefExoticComponent<NiceChangePasswordProps & React.RefAttributes<HTMLFormElement>> & {
28
+ displayName: string;
29
+ };
@@ -53,5 +53,7 @@ export interface NiceLoginFormProps {
53
53
  * are not allowed, the "Remember me" checkbox is automatically hidden to
54
54
  * respect user privacy settings.
55
55
  */
56
- export declare const NiceLoginForm: React.ForwardRefExoticComponent<NiceLoginFormProps & React.RefAttributes<HTMLFormElement>>;
56
+ export declare const NiceLoginForm: React.ForwardRefExoticComponent<NiceLoginFormProps & React.RefAttributes<HTMLFormElement>> & {
57
+ displayName: string;
58
+ };
57
59
  export {};
@@ -34,4 +34,6 @@ export interface NiceOAuthButtonsProps {
34
34
  /**
35
35
  * {@link NiceOAuthButtons} — OAuth login/registration buttons for popular providers.
36
36
  */
37
- export declare const NiceOAuthButtons: React.ForwardRefExoticComponent<NiceOAuthButtonsProps & React.RefAttributes<HTMLDivElement>>;
37
+ export declare const NiceOAuthButtons: React.ForwardRefExoticComponent<NiceOAuthButtonsProps & React.RefAttributes<HTMLDivElement>> & {
38
+ displayName: string;
39
+ };
@@ -19,4 +19,6 @@ export declare function calcPasswordStrength(password: string): PasswordStrength
19
19
  * {@link NicePasswordStrength} — Visual password strength indicator bar
20
20
  * with color-coded levels and text labels.
21
21
  */
22
- export declare const NicePasswordStrength: React.ForwardRefExoticComponent<NicePasswordStrengthProps & React.RefAttributes<HTMLDivElement>>;
22
+ export declare const NicePasswordStrength: React.ForwardRefExoticComponent<NicePasswordStrengthProps & React.RefAttributes<HTMLDivElement>> & {
23
+ displayName: string;
24
+ };
@@ -38,4 +38,6 @@ export interface NiceRegistrationFormProps {
38
38
  * {@link NiceRegistrationForm} — Registration form with name, email, password,
39
39
  * strength meter, terms acceptance, and optional OAuth footer.
40
40
  */
41
- export declare const NiceRegistrationForm: React.ForwardRefExoticComponent<NiceRegistrationFormProps & React.RefAttributes<HTMLFormElement>>;
41
+ export declare const NiceRegistrationForm: React.ForwardRefExoticComponent<NiceRegistrationFormProps & React.RefAttributes<HTMLFormElement>> & {
42
+ displayName: string;
43
+ };
@@ -30,4 +30,6 @@ export interface NiceTwoFaSetupProps {
30
30
  * {@link NiceTwoFaSetup} — Two-factor authentication setup wizard with
31
31
  * QR code display, secret key, verification code input, and recovery codes.
32
32
  */
33
- export declare const NiceTwoFaSetup: React.ForwardRefExoticComponent<NiceTwoFaSetupProps & React.RefAttributes<HTMLDivElement>>;
33
+ export declare const NiceTwoFaSetup: React.ForwardRefExoticComponent<NiceTwoFaSetupProps & React.RefAttributes<HTMLDivElement>> & {
34
+ displayName: string;
35
+ };
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),e=require("react/jsx-runtime");function le(n={}){const{onLogin:s,onRefresh:r,onLogout:a,storageKey:i="nice_auth",persistAuth:u=!1}=n,[l,c]=t.useState(()=>{if(u&&typeof window<"u")try{const o=localStorage.getItem(i);if(o)return{...JSON.parse(o),loading:!1,error:null}}catch{}return{isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null}}),h=t.useCallback(o=>{c(p=>{const f={...p,...o};return u&&typeof window<"u"&&(f.isAuthenticated?localStorage.setItem(i,JSON.stringify({isAuthenticated:!0,user:f.user})):localStorage.removeItem(i)),f})},[u,i]),C=t.useCallback(async(o,p)=>{h({loading:!0,error:null});try{if(s){const f=await s(o,p);return h({isAuthenticated:!0,user:f.user,tokens:f.tokens,loading:!1}),!0}return h({loading:!1,error:"No login handler configured"}),!1}catch(f){return h({loading:!1,error:(f==null?void 0:f.message)??"Login failed"}),!1}},[s,h]),d=t.useCallback(()=>{a==null||a(),h({isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null})},[a,h]),y=t.useCallback(async()=>{var o;if(!((o=l.tokens)!=null&&o.refreshToken)||!r)return!1;try{const p=await r(l.tokens.refreshToken);return h({tokens:p}),!0}catch{return d(),!1}},[l.tokens,r,h,d]),g=t.useCallback((o,p)=>{h({isAuthenticated:!0,user:o,tokens:p,loading:!1,error:null})},[h]),w=t.useCallback((...o)=>l.user?o.every(p=>l.user.roles.includes(p)):!1,[l.user]),x=t.useCallback((...o)=>l.user?o.every(p=>l.user.permissions.includes(p)):!1,[l.user]),A=t.useCallback(()=>{h({error:null})},[h]);return{...l,login:C,logout:d,refreshToken:y,setAuth:g,hasRoles:w,hasPermissions:x,clearError:A}}const J=t.forwardRef(({onSubmit:n,loading:s=!1,error:r,showRememberMe:a=!0,showForgotPassword:i=!0,onForgotPassword:u,showRegisterLink:l=!0,onRegisterClick:c,title:h="Sign In",submitLabel:C="Sign In",logo:d,footer:y,className:g,style:w,emailLabel:x="Email",passwordLabel:A="Password",tracelessPolicy:o,privacyMessage:p},f)=>{const[R,_]=t.useState(""),[v,S]=t.useState(""),[P,b]=t.useState(!1),F=t.useMemo(()=>!(!a||o&&!o.cookiesAllowed),[a,o]),E=t.useCallback(k=>{k.preventDefault();const T=(o==null?void 0:o.cookiesAllowed)===!1?!1:P;n==null||n({email:R,password:v,rememberMe:T})},[R,v,P,n,o]);return e.jsxs("form",{ref:f,className:`nice-login-form${g?` ${g}`:""}`,style:w,onSubmit:E,noValidate:!0,children:[d&&e.jsx("div",{className:"nice-login-form__logo",children:d}),e.jsx("h2",{className:"nice-login-form__title",children:h}),r&&e.jsx("div",{className:"nice-login-form__error",role:"alert",children:r}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-email",children:x}),e.jsx("input",{id:"nice-login-email",className:"nice-input",type:"email",value:R,onChange:k=>_(k.target.value),autoComplete:"email",required:!0,disabled:s})]}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-password",children:A}),e.jsx("input",{id:"nice-login-password",className:"nice-input",type:"password",value:v,onChange:k=>S(k.target.value),autoComplete:"current-password",required:!0,disabled:s})]}),e.jsxs("div",{className:"nice-login-form__options",children:[F&&e.jsxs("label",{className:"nice-login-form__remember",children:[e.jsx("input",{type:"checkbox",checked:P,onChange:k=>b(k.target.checked),disabled:s}),e.jsx("span",{children:"Remember me"})]}),!F&&a&&p&&e.jsx("span",{className:"nice-login-form__privacy-notice",children:p}),i&&e.jsx("button",{type:"button",className:"nice-login-form__forgot",onClick:u,disabled:s,children:"Forgot password?"})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-login-form__submit",disabled:s||!R||!v,children:s?"…":C}),l&&e.jsxs("div",{className:"nice-login-form__register",children:[e.jsx("span",{children:"Don't have an account? "}),e.jsx("button",{type:"button",onClick:c,disabled:s,children:"Register"})]}),y&&e.jsx("div",{className:"nice-login-form__footer",children:y})]})});J.displayName="NiceLoginForm";const oe={0:"Very weak",1:"Weak",2:"Fair",3:"Strong",4:"Very strong"},de={0:"#d9534f",1:"#f0ad4e",2:"#5bc0de",3:"#5cb85c",4:"#2e7d32"};function K(n){if(!n)return 0;let s=0;return n.length>=8&&s++,n.length>=12&&s++,/[a-z]/.test(n)&&/[A-Z]/.test(n)&&s++,/\d/.test(n)&&s++,/[^a-zA-Z0-9]/.test(n)&&s++,Math.min(4,s)}const q=t.forwardRef(({password:n,strength:s,showLabel:r=!0,labels:a=oe,className:i},u)=>{const l=s??K(n),c=de[l],h=(l+1)/5*100;return e.jsxs("div",{ref:u,className:`nice-password-strength${i?` ${i}`:""}`,children:[e.jsx("div",{className:"nice-password-strength__bar",children:e.jsx("div",{className:"nice-password-strength__fill",style:{width:`${h}%`,backgroundColor:c}})}),r&&e.jsx("span",{className:"nice-password-strength__label",style:{color:c},children:a[l]})]})});q.displayName="NicePasswordStrength";const X=t.forwardRef(({onSubmit:n,loading:s=!1,error:r,onLoginClick:a,showPasswordStrength:i=!0,minPasswordStrength:u=2,termsUrl:l,privacyUrl:c,title:h="Create Account",logo:C,footer:d,className:y,style:g},w)=>{const[x,A]=t.useState(""),[o,p]=t.useState(""),[f,R]=t.useState(""),[_,v]=t.useState(""),[S,P]=t.useState(""),[b,F]=t.useState(!1),E=K(_),k=_===S,T=x&&f&&_&&k&&b&&E>=u&&!s,m=t.useCallback(j=>{j.preventDefault(),T&&(n==null||n({firstName:x,lastName:o,email:f,password:_,acceptTerms:b}))},[T,x,o,f,_,b,n]);return e.jsxs("form",{ref:w,className:`nice-register-form${y?` ${y}`:""}`,style:g,onSubmit:m,noValidate:!0,children:[C&&e.jsx("div",{className:"nice-register-form__logo",children:C}),e.jsx("h2",{className:"nice-register-form__title",children:h}),r&&e.jsx("div",{className:"nice-register-form__error",role:"alert",children:r}),e.jsxs("div",{className:"nice-register-form__row",children:[e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-first",children:"First name *"}),e.jsx("input",{id:"nice-reg-first",className:"nice-input",type:"text",value:x,onChange:j=>A(j.target.value),required:!0,disabled:s,autoComplete:"given-name"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-last",children:"Last name"}),e.jsx("input",{id:"nice-reg-last",className:"nice-input",type:"text",value:o,onChange:j=>p(j.target.value),disabled:s,autoComplete:"family-name"})]})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-email",children:"Email *"}),e.jsx("input",{id:"nice-reg-email",className:"nice-input",type:"email",value:f,onChange:j=>R(j.target.value),required:!0,disabled:s,autoComplete:"email"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-pass",children:"Password *"}),e.jsx("input",{id:"nice-reg-pass",className:"nice-input",type:"password",value:_,onChange:j=>v(j.target.value),required:!0,disabled:s,autoComplete:"new-password"}),i&&_.length>0&&e.jsx(q,{password:_})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-confirm",children:"Confirm password *"}),e.jsx("input",{id:"nice-reg-confirm",className:"nice-input",type:"password",value:S,onChange:j=>P(j.target.value),required:!0,disabled:s,autoComplete:"new-password"}),S&&!k&&e.jsx("span",{className:"nice-error-text",children:"Passwords do not match"})]}),e.jsxs("label",{className:"nice-register-form__terms",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:j=>F(j.target.checked),disabled:s}),e.jsxs("span",{children:["I accept the"," ",l?e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",children:"Terms"}):"Terms",c&&e.jsxs(e.Fragment,{children:[" ","and"," ",e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:"Privacy Policy"})]})," *"]})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-register-form__submit",disabled:!T,children:s?"…":"Register"}),a&&e.jsxs("div",{className:"nice-register-form__login",children:[e.jsx("span",{children:"Already have an account? "}),e.jsx("button",{type:"button",onClick:a,children:"Sign in"})]}),d&&e.jsx("div",{className:"nice-register-form__footer",children:d})]})});X.displayName="NiceRegistrationForm";const ue=({style:n})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.3em",height:"0.6em",margin:"0 0.35em 0.15em 0.1em",borderRight:"0.12em solid currentColor",borderBottom:"0.12em solid currentColor",transform:"rotate(45deg)",...n}}),Y=({style:n})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.85em",height:"0.85em",borderRadius:"50%",border:"0.12em solid currentColor",borderTopColor:"transparent",transform:"rotate(-45deg)",...n}}),Z={lowercase:"abcdefghijklmnopqrstuvwxyz",uppercase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",digits:"0123456789",symbols:"!@#$%^&*()-_=+[]{};:,.?/~"},he=/[0Oo1lI|]/g,z={length:16,lowercase:!0,uppercase:!0,digits:!0,symbols:!0,excludeAmbiguous:!1},me={password:"Generated password",length:"Length",lowercase:"Lowercase (a–z)",uppercase:"Uppercase (A–Z)",digits:"Digits (0–9)",symbols:"Symbols (!@#…)",excludeAmbiguous:"Avoid look-alikes (0 O 1 l I)",generate:"Generate",copy:"Copy",copied:"Copied",noCharacterSets:"Pick at least one kind of character."},pe=n=>{const s=globalThis.crypto;if(!s||typeof s.getRandomValues!="function")throw new Error("generatePassword: crypto.getRandomValues is not available");return s.getRandomValues(n)};let fe=0;function Q(n,s){const r=Math.floor(4294967296/n)*n,a=new Uint32Array(1);for(;;){const i=s(a)[0];if(i<r)return i%n}}function W(n={},s=pe){const r={...z,...n},a=["lowercase","uppercase","digits","symbols"].filter(c=>r[c]).map(c=>r.excludeAmbiguous?Z[c].replace(he,""):Z[c]).filter(c=>c.length>0);if(a.length===0)return"";const i=Math.max(a.length,Math.min(1024,Math.floor(r.length))),u=a.join(""),l=a.map(c=>c[Q(c.length,s)]);for(;l.length<i;)l.push(u[Q(u.length,s)]);for(let c=l.length-1;c>0;c--){const h=Q(c+1,s);[l[c],l[h]]=[l[h],l[c]]}return l.join("")}const ge=({value:n,defaultValue:s="",onChange:r,options:a,defaultOptions:i,onOptionsChange:u,minLength:l=8,maxLength:c=64,showStrength:h=!0,showCopy:C=!0,onCopy:d,labels:y,disabled:g=!1,className:w,style:x,id:A})=>{const o={...me,...y},[p]=t.useState(()=>`nice-password-generator-${++fe}`),f=A??p,[R,_]=t.useState(()=>({...z,...i})),v=a?{...z,...a}:R,[S,P]=t.useState(()=>n===void 0&&!s?W({...z,...i,...a}):s),b=n??S,[F,E]=t.useState(!1),k=t.useRef(void 0);t.useEffect(()=>()=>clearTimeout(k.current),[]);const T=t.useCallback(M=>{n===void 0&&P(M),E(!1),r==null||r(M)},[n,r]),m=t.useCallback(M=>T(W(M)),[T]),j=(M,D)=>{const B={...v,[M]:D};a||_(B),u==null||u(B),m(B)},U=async()=>{!b||!navigator.clipboard||(await navigator.clipboard.writeText(b),E(!0),clearTimeout(k.current),k.current=setTimeout(()=>E(!1),1500),d==null||d(b))},$=!v.lowercase&&!v.uppercase&&!v.digits&&!v.symbols,O=Math.min(c,Math.max(l,v.length));return e.jsxs("div",{id:A,className:`nice-password-generator${w?` ${w}`:""}`,style:x,children:[e.jsxs("div",{className:"nice-password-generator__output",children:[e.jsx("input",{id:`${f}-value`,className:"nice-password-generator__value",type:"text",readOnly:!0,spellCheck:!1,autoComplete:"off",value:b,"aria-label":o.password}),e.jsx("button",{type:"button",className:"nice-password-generator__button",onClick:()=>m(v),disabled:g||$,"aria-label":o.generate,title:o.generate,children:e.jsx(Y,{})}),C&&e.jsx("button",{type:"button",className:"nice-password-generator__button nice-password-generator__button--copy",onClick:U,disabled:g||!b,"aria-live":"polite",children:F?e.jsxs(e.Fragment,{children:[e.jsx(ue,{})," ",o.copied]}):o.copy})]}),h&&e.jsx(q,{password:b}),e.jsxs("div",{className:"nice-password-generator__length",children:[e.jsx("label",{htmlFor:`${f}-length`,children:o.length}),e.jsx("input",{id:`${f}-length`,type:"range",min:l,max:c,value:O,disabled:g,onChange:M=>j("length",Number(M.target.value))}),e.jsx("output",{htmlFor:`${f}-length`,className:"nice-password-generator__length-value",children:O})]}),e.jsx("div",{className:"nice-password-generator__sets",children:["lowercase","uppercase","digits","symbols","excludeAmbiguous"].map(M=>e.jsxs("label",{className:"nice-password-generator__option",children:[e.jsx("input",{type:"checkbox",checked:v[M],disabled:g,onChange:D=>j(M,D.target.checked)}),o[M]]},M))}),$&&e.jsx("p",{className:"nice-password-generator__error",role:"alert",children:o.noCharacterSets})]})},ee=t.forwardRef(({requireCurrentPassword:n=!0,onSubmit:s,loading:r=!1,error:a,success:i,minPasswordStrength:u=2,title:l="Change Password",className:c,style:h},C)=>{const[d,y]=t.useState(""),[g,w]=t.useState(""),[x,A]=t.useState(""),o=K(g),p=g===x,f=(!n||d.length>0)&&g.length>0&&p&&o>=u&&!r,R=t.useCallback(_=>{_.preventDefault(),f&&(s==null||s({currentPassword:n?d:void 0,newPassword:g}))},[f,d,g,n,s]);return e.jsxs("form",{ref:C,className:`nice-change-password${c?` ${c}`:""}`,style:h,onSubmit:R,noValidate:!0,children:[e.jsx("h3",{className:"nice-change-password__title",children:l}),a&&e.jsx("div",{className:"nice-change-password__error",role:"alert",children:a}),i&&e.jsx("div",{className:"nice-change-password__success",role:"status",children:i}),n&&e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-current",children:"Current password"}),e.jsx("input",{id:"nice-cp-current",className:"nice-input",type:"password",value:d,onChange:_=>y(_.target.value),autoComplete:"current-password",disabled:r,required:!0})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-new",children:"New password"}),e.jsx("input",{id:"nice-cp-new",className:"nice-input",type:"password",value:g,onChange:_=>w(_.target.value),autoComplete:"new-password",disabled:r,required:!0}),g.length>0&&e.jsx(q,{password:g})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-confirm",children:"Confirm new password"}),e.jsx("input",{id:"nice-cp-confirm",className:"nice-input",type:"password",value:x,onChange:_=>A(_.target.value),autoComplete:"new-password",disabled:r,required:!0}),x&&!p&&e.jsx("span",{className:"nice-error-text",children:"Passwords do not match"})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:!f,children:r?"…":"Change Password"})]})});ee.displayName="NiceChangePassword";const te=t.forwardRef(({secret:n,qrCodeUrl:s,issuer:r,accountName:a,onVerify:i,loading:u=!1,error:l,onCancel:c,recoveryCodes:h,step:C="setup",onStepChange:d,className:y,style:g},w)=>{const[x,A]=t.useState(""),[o,p]=t.useState(!1),[f,R]=t.useState(!1),_=t.useCallback(S=>{S.preventDefault(),x.length>=6&&(i==null||i(x))},[x,i]),v=`otpauth://totp/${r?`${r}:`:""}${a??"user"}?secret=${n}${r?`&issuer=${r}`:""}&digits=6&period=30`;return e.jsxs("div",{ref:w,className:`nice-2fa-setup${y?` ${y}`:""}`,style:g,children:[e.jsx("h3",{className:"nice-2fa-setup__title",children:"Two-Factor Authentication"}),C==="setup"&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:"Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.):"}),s?e.jsx("img",{src:s,alt:"2FA QR Code",className:"nice-2fa-setup__qr"}):e.jsxs("div",{className:"nice-2fa-setup__qr-placeholder",children:[e.jsx("span",{children:"QR Code"}),e.jsx("code",{className:"nice-2fa-setup__uri",children:v})]}),e.jsxs("div",{className:"nice-2fa-setup__secret",children:[e.jsx("span",{children:"Or enter manually: "}),o?e.jsx("code",{className:"nice-2fa-setup__secret-key",children:n}):e.jsx("button",{type:"button",onClick:()=>p(!0),children:"Show secret key"})]}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",onClick:()=>d==null?void 0:d("verify"),children:"Next — Verify"})]}),C==="verify"&&e.jsxs("form",{className:"nice-2fa-setup__step",onSubmit:_,children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:"Enter the 6-digit code from your authenticator app:"}),l&&e.jsx("div",{className:"nice-2fa-setup__error",role:"alert",children:l}),e.jsx("input",{className:"nice-input nice-2fa-setup__code-input",type:"text",inputMode:"numeric",maxLength:6,value:x,onChange:S=>A(S.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",autoFocus:!0,disabled:u,autoComplete:"one-time-code"}),e.jsxs("div",{className:"nice-2fa-setup__actions",children:[e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>d==null?void 0:d("setup"),children:"Back"}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:u||x.length<6,children:u?"…":"Verify"})]})]}),C==="recovery"&&h&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:"Save these recovery codes in a safe place. Each code can only be used once:"}),e.jsx("div",{className:"nice-2fa-setup__recovery-codes",children:h.map((S,P)=>e.jsx("code",{className:"nice-2fa-setup__recovery-code",children:S},P))}),e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>{var S;(S=navigator.clipboard)==null||S.writeText(h.join(`
2
- `)),R(!0)},children:f?"Copied!":"Copy all codes"}),c&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",onClick:c,children:"Done"})]}),c&&C!=="recovery"&&e.jsx("button",{type:"button",className:"nice-2fa-setup__cancel",onClick:c,children:"Cancel"})]})});te.displayName="NiceTwoFaSetup";const xe=500;function I(n,s){return Math.floor(Math.random()*(s-n+1))+n}function be(){return`${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}function _e(n,s){switch(n){case"math":{const r=s==="easy"?5:s==="hard"?20:10,a=I(1,r),i=I(1,r),u=s!=="easy"&&a>=i&&Math.random()<.5,l=u?a-i:a+i;return{kind:"math",prompt:`${a} ${u?"−":"+"} ${i}`,answer:l}}case"text":{const r=s==="easy"?4:s==="hard"?7:5,a="ABCDEFGHJKMNPQRSTUVWXYZ23456789";let i="";for(let u=0;u<r;u++)i+=a[I(0,a.length-1)];return{kind:"text",text:i}}case"slider":return{kind:"slider",target:I(70,92),tolerance:s==="easy"?8:s==="hard"?2:4};case"checkbox":default:return{kind:"checkbox"}}}function je(n,s,r){if(!n)return;const a=n.getContext("2d");if(!a)return;const i=n.width,u=n.height;a.clearRect(0,0,i,u),a.fillStyle=r?"#1a1a1a":"#f3f4f6",a.fillRect(0,0,i,u),a.strokeStyle=r?"rgba(255,255,255,0.18)":"rgba(0,0,0,0.18)",a.lineWidth=1;for(let c=0;c<6;c++)a.beginPath(),a.moveTo(I(0,i),I(0,u)),a.lineTo(I(0,i),I(0,u)),a.stroke();a.fillStyle=r?"#e5e7eb":"#111827",a.textBaseline="middle";const l=i/(s.length+1);for(let c=0;c<s.length;c++){const h=I(22,30);a.save(),a.translate(l*(c+1),u/2+I(-4,4)),a.rotate(I(-22,22)*Math.PI/180),a.font=`bold ${h}px monospace`,a.fillText(s[c],-h/3,0),a.restore()}}const se=t.forwardRef((n,s)=>{const{variant:r,difficulty:a="medium",refreshable:i=!0,verifyToken:u,expiresMs:l,label:c="I'm not a robot",provider:h="custom",siteKey:C,onVerify:d,onExpire:y,onError:g,onRefresh:w,theme:x="light",size:A="normal",customRender:o,className:p,style:f}=n,R=t.useRef(null),_=t.useRef(null),v=t.useRef(void 0),[S,P]=t.useState(0),[b,F]=t.useState("idle"),[E,k]=t.useState(""),[T,m]=t.useState(""),[j,U]=t.useState(0),$=t.useMemo(()=>_e(r??"checkbox",a),[r,a,S]),O=t.useCallback(()=>{F("idle"),k(""),m(""),U(0),P(N=>N+1)},[]),M=t.useCallback(()=>{O(),w==null||w()},[O,w]);t.useImperativeHandle(s,()=>({reset:O,refresh:M,container:R.current}),[O,M]),t.useEffect(()=>{r==="text"&&$.kind==="text"&&je(_.current,$.text,x==="dark")},[r,$,x]),t.useEffect(()=>{if(b!=="verified"||!l)return;const N=setTimeout(()=>{y==null||y(),O()},l);return()=>clearTimeout(N)},[b,l,y,O]);const D=t.useCallback(()=>{const N=`ntd-cap:${r}:${be()}`;u?(F("verifying"),k(""),Promise.resolve().then(()=>u(N)).then(H=>{H?(F("verified"),d==null||d(N)):(F("error"),k("Verification failed. Please try again."),P(ie=>ie+1),m(""))}).catch(H=>{F("error"),k("Verification error. Please try again."),g==null||g(H)})):(F("verified"),d==null||d(N))},[r,u,d,g]),B=t.useCallback(()=>{F("error"),k("Incorrect, please try again."),P(N=>N+1),m("")},[]),ne=t.useCallback(()=>{b==="verifying"||b==="verified"||(F("verifying"),k(""),v.current=setTimeout(D,xe))},[b,D]);t.useEffect(()=>()=>clearTimeout(v.current),[]);const G=t.useCallback(()=>{$.kind==="math"?T.trim()!==""&&Number(T)===$.answer?D():B():$.kind==="text"&&(T.trim().toUpperCase()===$.text?D():B())},[$,T,D,B]),re=t.useCallback(N=>{U(N),!($.kind!=="slider"||b==="verified"||b==="verifying")&&Math.abs(N-$.target)<=$.tolerance&&D()},[$,b,D]);if(!r)return h==="custom"&&o?e.jsx("div",{ref:R,className:`nice-captcha nice-captcha--custom${p?` ${p}`:""}`,style:f,children:o}):e.jsx("div",{ref:R,className:`nice-captcha nice-captcha--${h} nice-captcha--${x}${A==="compact"?" nice-captcha--compact":""}${p?` ${p}`:""}`,style:f,"data-sitekey":C,"data-theme":x,"data-size":A,children:e.jsxs("div",{className:"nice-captcha__placeholder",children:[e.jsxs("span",{children:["Captcha (",h,")"]}),e.jsxs("p",{children:["Load the ",h," SDK to activate verification."]})]})});const L=b==="verifying",V=b==="verified",ce=`nice-captcha nice-captcha--${r} nice-captcha--${x} nice-captcha--${b}${A==="compact"?" nice-captcha--compact":""}${p?` ${p}`:""}`;return e.jsxs("div",{ref:R,className:ce,style:f,role:"group","aria-label":"Captcha challenge","data-variant":r,"data-status":b,"data-theme":x,children:[r==="checkbox"&&e.jsxs("button",{type:"button",className:"nice-captcha__checkbox",role:"checkbox","aria-checked":V,"aria-busy":L,disabled:L||V,onClick:ne,children:[e.jsx("span",{className:"nice-captcha__box","aria-hidden":"true",children:L?"…":V?e.jsx("span",{style:{display:"inline-block",width:"0.3em",height:"0.6em",marginBottom:"0.15em",borderRight:"0.12em solid currentColor",borderBottom:"0.12em solid currentColor",transform:"rotate(45deg)"}}):""}),e.jsx("span",{className:"nice-captcha__label",children:c})]}),r==="math"&&$.kind==="math"&&e.jsxs("div",{className:"nice-captcha__challenge",children:[e.jsxs("span",{className:"nice-captcha__prompt","aria-hidden":"true",children:[$.prompt," ="]}),e.jsx("input",{className:"nice-input nice-captcha__answer",type:"number",inputMode:"numeric",value:T,"aria-label":`What is ${$.prompt}?`,disabled:L||V,onChange:N=>m(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),G())}}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary nice-captcha__verify",disabled:L||V||T.trim()==="",onClick:G,children:L?"…":"Verify"})]}),r==="text"&&$.kind==="text"&&e.jsxs("div",{className:"nice-captcha__challenge",children:[e.jsx("canvas",{ref:_,className:"nice-captcha__canvas",width:160,height:56,"aria-hidden":"true"}),e.jsx("input",{className:"nice-input nice-captcha__answer",type:"text",autoCapitalize:"characters",autoComplete:"off",value:T,"aria-label":"Type the characters shown in the image",disabled:L||V,onChange:N=>m(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),G())}}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary nice-captcha__verify",disabled:L||V||T.trim()==="",onClick:G,children:L?"…":"Verify"})]}),r==="slider"&&$.kind==="slider"&&e.jsxs("div",{className:"nice-captcha__challenge nice-captcha__challenge--slider",children:[e.jsx("span",{className:"nice-captcha__slider-hint","aria-hidden":"true",children:V?"Verified":"Slide to the marker"}),e.jsxs("div",{className:"nice-captcha__track",children:[e.jsx("span",{className:"nice-captcha__target","aria-hidden":"true",style:{left:`${$.target}%`}}),e.jsx("input",{className:"nice-captcha__slider",type:"range",min:0,max:100,value:j,"aria-label":"Slide the handle to the marker to verify","aria-valuetext":`${j}%`,disabled:V||L,onChange:N=>re(Number(N.target.value))})]})]}),e.jsxs("div",{className:"nice-captcha__footer",children:[e.jsx("div",{className:"nice-captcha__message",role:"status","aria-live":"polite",children:E}),i&&e.jsx("button",{type:"button",className:"nice-captcha__refresh","aria-label":"Refresh challenge",title:"Refresh challenge",onClick:M,children:e.jsx(Y,{})})]})]})});se.displayName="NiceCaptcha";const Ne=[{id:"google",label:"Google",color:"#4285f4",textColor:"#fff"},{id:"microsoft",label:"Microsoft",color:"#00a4ef",textColor:"#fff"},{id:"discord",label:"Discord",color:"#5865f2",textColor:"#fff"},{id:"spotify",label:"Spotify",color:"#1db954",textColor:"#fff"},{id:"github",label:"GitHub",color:"#24292e",textColor:"#fff"}],ae=t.forwardRef(({providers:n=Ne,onProviderClick:s,disabled:r=!1,loadingProvider:a,direction:i="vertical",separatorText:u="or continue with",showSeparator:l=!0,className:c,style:h},C)=>e.jsxs("div",{ref:C,className:`nice-oauth nice-oauth--${i}${c?` ${c}`:""}`,style:h,children:[l&&e.jsxs("div",{className:"nice-oauth__separator",children:[e.jsx("hr",{}),e.jsx("span",{children:u}),e.jsx("hr",{})]}),e.jsx("div",{className:"nice-oauth__buttons",children:n.map(d=>e.jsxs("button",{type:"button",className:`nice-oauth__btn${a===d.id?" nice-oauth__btn--loading":""}`,style:{backgroundColor:d.color,color:d.textColor},onClick:()=>s==null?void 0:s(d.id),disabled:r||!!a,children:[d.icon&&e.jsx("span",{className:"nice-oauth__btn-icon",children:d.icon}),e.jsx("span",{className:"nice-oauth__btn-label",children:a===d.id?"…":d.label})]},d.id))})]}));ae.displayName="NiceOAuthButtons";const we=t.forwardRef(function(s,r){const{tokens:a,onCreate:i,onRevoke:u,availableScopes:l=[],maxTokens:c=10,title:h="API Tokens",className:C,style:d}=s,[y,g]=t.useState(!1),[w,x]=t.useState(""),[A,o]=t.useState([]),[p,f]=t.useState("90"),[R,_]=t.useState(null),[v,S]=t.useState(!1),[P,b]=t.useState(null),F=t.useCallback(async()=>{if(!(!i||!w.trim())){S(!0);try{const m=p?parseInt(p,10):void 0,j=await i(w.trim(),A,m);_(j),x(""),o([]),g(!1)}finally{S(!1)}}},[i,w,A,p]),E=t.useCallback(async m=>{if(u){b(m);try{await u(m)}finally{b(null)}}},[u]),k=m=>{o(j=>j.includes(m)?j.filter(U=>U!==m):[...j,m])},T=a.length<c;return e.jsxs("div",{ref:r,className:`nice-token-management ${C??""}`,style:d,children:[e.jsxs("div",{className:"nice-token-management__header",children:[e.jsx("h3",{children:h}),T&&e.jsx("button",{className:"nice-token-management__new-btn",onClick:()=>g(!0),disabled:y,children:"+ New Token"})]}),R&&e.jsxs("div",{className:"nice-token-management__reveal",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"New token created!"})," Copy it now — it won't be shown again."]}),e.jsx("code",{className:"nice-token-management__token-value",children:R}),e.jsx("button",{onClick:()=>_(null),children:"Dismiss"})]}),y&&e.jsxs("div",{className:"nice-token-management__create-form",children:[e.jsxs("label",{children:["Name",e.jsx("input",{type:"text",value:w,onChange:m=>x(m.target.value),placeholder:"My API token",maxLength:64})]}),l.length>0&&e.jsxs("fieldset",{children:[e.jsx("legend",{children:"Scopes"}),l.map(m=>e.jsxs("label",{className:"nice-token-management__scope",children:[e.jsx("input",{type:"checkbox",checked:A.includes(m),onChange:()=>k(m)}),m]},m))]}),e.jsxs("label",{children:["Expires in (days)",e.jsx("input",{type:"number",value:p,onChange:m=>f(m.target.value),min:1,max:365})]}),e.jsxs("div",{className:"nice-token-management__create-actions",children:[e.jsx("button",{onClick:F,disabled:v||!w.trim(),children:v?"Creating…":"Create Token"}),e.jsx("button",{onClick:()=>g(!1),children:"Cancel"})]})]}),a.length===0?e.jsx("p",{className:"nice-token-management__empty",children:"No API tokens yet."}):e.jsxs("table",{className:"nice-token-management__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Prefix"}),e.jsx("th",{children:"Created"}),e.jsx("th",{children:"Expires"}),e.jsx("th",{children:"Last Used"}),e.jsx("th",{children:"Scopes"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:a.map(m=>{var j;return e.jsxs("tr",{children:[e.jsx("td",{children:m.name}),e.jsx("td",{children:e.jsxs("code",{children:[m.prefix,"…"]})}),e.jsx("td",{children:m.createdAt}),e.jsx("td",{children:m.expiresAt??"—"}),e.jsx("td",{children:m.lastUsedAt??"Never"}),e.jsx("td",{children:((j=m.scopes)==null?void 0:j.join(", "))||"—"}),e.jsx("td",{children:e.jsx("button",{className:"nice-token-management__revoke-btn",onClick:()=>E(m.id),disabled:P===m.id,children:P===m.id?"Revoking…":"Revoke"})})]},m.id)})})]})]})});exports.NiceCaptcha=se;exports.NiceChangePassword=ee;exports.NiceLoginForm=J;exports.NiceOAuthButtons=ae;exports.NicePasswordGenerator=ge;exports.NicePasswordStrength=q;exports.NiceRegistrationForm=X;exports.NiceTokenManagement=we;exports.NiceTwoFaSetup=te;exports.calcPasswordStrength=K;exports.generatePassword=W;exports.useAuth=le;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),e=require("react/jsx-runtime"),q=require("@nice2dev/ui-core");function re(r={}){const{onLogin:a,onRefresh:n,onLogout:t,storageKey:i="nice_auth",persistAuth:d=!1}=r,[l,c]=s.useState(()=>{if(d&&typeof window<"u")try{const h=localStorage.getItem(i);if(h)return{...JSON.parse(h),loading:!1,error:null}}catch{}return{isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null}}),u=s.useCallback(h=>{c(p=>{const x={...p,...h};return d&&typeof window<"u"&&(x.isAuthenticated?localStorage.setItem(i,JSON.stringify({isAuthenticated:!0,user:x.user})):localStorage.removeItem(i)),x})},[d,i]),k=s.useCallback(async(h,p)=>{u({loading:!0,error:null});try{if(a){const x=await a(h,p);return u({isAuthenticated:!0,user:x.user,tokens:x.tokens,loading:!1}),!0}return u({loading:!1,error:"No login handler configured"}),!1}catch(x){return u({loading:!1,error:(x==null?void 0:x.message)??"Login failed"}),!1}},[a,u]),f=s.useCallback(()=>{t==null||t(),u({isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null})},[t,u]),g=s.useCallback(async()=>{var h;if(!((h=l.tokens)!=null&&h.refreshToken)||!n)return!1;try{const p=await n(l.tokens.refreshToken);return u({tokens:p}),!0}catch{return f(),!1}},[l.tokens,n,u,f]),C=s.useCallback((h,p)=>{u({isAuthenticated:!0,user:h,tokens:p,loading:!1,error:null})},[u]),w=s.useCallback((...h)=>l.user?h.every(p=>l.user.roles.includes(p)):!1,[l.user]),o=s.useCallback((...h)=>l.user?h.every(p=>l.user.permissions.includes(p)):!1,[l.user]),b=s.useCallback(()=>{u({error:null})},[u]);return{...l,login:k,logout:f,refreshToken:g,setAuth:C,hasRoles:w,hasPermissions:o,clearError:b}}const ce=Object.assign(s.forwardRef(({onSubmit:r,loading:a=!1,error:n,showRememberMe:t=!0,showForgotPassword:i=!0,onForgotPassword:d,showRegisterLink:l=!0,onRegisterClick:c,title:u,submitLabel:k,logo:f,footer:g,className:C,style:w,emailLabel:o,passwordLabel:b,tracelessPolicy:h,privacyMessage:p},x)=>{const{t:j}=q.useNiceTranslation(),[$,N]=s.useState(""),[S,F]=s.useState(""),[I,_]=s.useState(!1),P=s.useMemo(()=>!(!t||h&&!h.cookiesAllowed),[t,h]),D=s.useCallback(T=>{T.preventDefault();const R=(h==null?void 0:h.cookiesAllowed)===!1?!1:I;r==null||r({email:$,password:S,rememberMe:R})},[$,S,I,r,h]);return e.jsxs("form",{ref:x,className:`nice-login-form${C?` ${C}`:""}`,style:w,onSubmit:D,noValidate:!0,children:[f&&e.jsx("div",{className:"nice-login-form__logo",children:f}),e.jsx("h2",{className:"nice-login-form__title",children:u??j("loginForm.title","Sign In")}),n&&e.jsx("div",{className:"nice-login-form__error",role:"alert",children:n}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-email",children:o??j("loginForm.email","Email")}),e.jsx("input",{id:"nice-login-email",className:"nice-input",type:"email",value:$,onChange:T=>N(T.target.value),autoComplete:"email",required:!0,disabled:a})]}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-password",children:b??j("loginForm.password","Password")}),e.jsx("input",{id:"nice-login-password",className:"nice-input",type:"password",value:S,onChange:T=>F(T.target.value),autoComplete:"current-password",required:!0,disabled:a})]}),e.jsxs("div",{className:"nice-login-form__options",children:[P&&e.jsxs("label",{className:"nice-login-form__remember",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:T=>_(T.target.checked),disabled:a}),e.jsx("span",{children:j("loginForm.rememberMe","Remember me")})]}),!P&&t&&p&&e.jsx("span",{className:"nice-login-form__privacy-notice",children:p}),i&&e.jsx("button",{type:"button",className:"nice-login-form__forgot",onClick:d,disabled:a,children:j("loginForm.forgotPassword","Forgot password?")})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-login-form__submit",disabled:a||!$||!S,children:a?"…":k??j("loginForm.signIn","Sign In")}),l&&e.jsxs("div",{className:"nice-login-form__register",children:[e.jsxs("span",{children:[j("loginForm.dontHaveAnAccount","Don't have an account?")," "]}),e.jsx("button",{type:"button",onClick:c,disabled:a,children:j("loginForm.register","Register")})]}),g&&e.jsx("div",{className:"nice-login-form__footer",children:g})]})}),{displayName:"NiceLoginForm"}),ie={0:"Very weak",1:"Weak",2:"Fair",3:"Strong",4:"Very strong"},oe={0:"#d9534f",1:"#f0ad4e",2:"#5bc0de",3:"#5cb85c",4:"#2e7d32"};function H(r){if(!r)return 0;let a=0;return r.length>=8&&a++,r.length>=12&&a++,/[a-z]/.test(r)&&/[A-Z]/.test(r)&&a++,/\d/.test(r)&&a++,/[^a-zA-Z0-9]/.test(r)&&a++,Math.min(4,a)}const W=Object.assign(s.forwardRef(({password:r,strength:a,showLabel:n=!0,labels:t,className:i},d)=>{const{t:l}=q.useNiceTranslation(),c=a??H(r),u=oe[c],k=(c+1)/5*100;return e.jsxs("div",{ref:d,className:`nice-password-strength${i?` ${i}`:""}`,children:[e.jsx("div",{className:"nice-password-strength__bar",children:e.jsx("div",{className:"nice-password-strength__fill",style:{width:`${k}%`,backgroundColor:u}})}),n&&e.jsx("span",{className:"nice-password-strength__label",style:{color:u},children:t?t[c]:l(`passwordStrength.level.${c}`,ie[c])})]})}),{displayName:"NicePasswordStrength"}),le=Object.assign(s.forwardRef(({onSubmit:r,loading:a=!1,error:n,onLoginClick:t,showPasswordStrength:i=!0,minPasswordStrength:d=2,termsUrl:l,privacyUrl:c,title:u,logo:k,footer:f,className:g,style:C},w)=>{const{t:o}=q.useNiceTranslation(),[b,h]=s.useState(""),[p,x]=s.useState(""),[j,$]=s.useState(""),[N,S]=s.useState(""),[F,I]=s.useState(""),[_,P]=s.useState(!1),D=H(N),T=N===F,R=b&&j&&N&&T&&_&&D>=d&&!a,m=s.useCallback(v=>{v.preventDefault(),R&&(r==null||r({firstName:b,lastName:p,email:j,password:N,acceptTerms:_}))},[R,b,p,j,N,_,r]);return e.jsxs("form",{ref:w,className:`nice-register-form${g?` ${g}`:""}`,style:C,onSubmit:m,noValidate:!0,children:[k&&e.jsx("div",{className:"nice-register-form__logo",children:k}),e.jsx("h2",{className:"nice-register-form__title",children:u??o("registrationForm.title","Create Account")}),n&&e.jsx("div",{className:"nice-register-form__error",role:"alert",children:n}),e.jsxs("div",{className:"nice-register-form__row",children:[e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-first",children:o("registrationForm.firstName","First name *")}),e.jsx("input",{id:"nice-reg-first",className:"nice-input",type:"text",value:b,onChange:v=>h(v.target.value),required:!0,disabled:a,autoComplete:"given-name"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-last",children:o("registrationForm.lastName","Last name")}),e.jsx("input",{id:"nice-reg-last",className:"nice-input",type:"text",value:p,onChange:v=>x(v.target.value),disabled:a,autoComplete:"family-name"})]})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-email",children:o("registrationForm.email","Email *")}),e.jsx("input",{id:"nice-reg-email",className:"nice-input",type:"email",value:j,onChange:v=>$(v.target.value),required:!0,disabled:a,autoComplete:"email"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-pass",children:o("registrationForm.password","Password *")}),e.jsx("input",{id:"nice-reg-pass",className:"nice-input",type:"password",value:N,onChange:v=>S(v.target.value),required:!0,disabled:a,autoComplete:"new-password"}),i&&N.length>0&&e.jsx(W,{password:N})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-confirm",children:o("registrationForm.confirmPassword","Confirm password *")}),e.jsx("input",{id:"nice-reg-confirm",className:"nice-input",type:"password",value:F,onChange:v=>I(v.target.value),required:!0,disabled:a,autoComplete:"new-password"}),F&&!T&&e.jsx("span",{className:"nice-error-text",children:o("registrationForm.passwordsDoNotMatch","Passwords do not match")})]}),e.jsxs("label",{className:"nice-register-form__terms",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:v=>P(v.target.checked),disabled:a}),e.jsxs("span",{children:[o("registrationForm.iAcceptThe","I accept the")," ",l?e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",children:o("registrationForm.terms","Terms")}):o("registrationForm.terms","Terms"),c&&e.jsxs(e.Fragment,{children:[" ",o("registrationForm.and","and")," ",e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:o("registrationForm.privacyPolicy","Privacy Policy")})]})," *"]})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-register-form__submit",disabled:!R,children:a?"…":o("registrationForm.register","Register")}),t&&e.jsxs("div",{className:"nice-register-form__login",children:[e.jsxs("span",{children:[o("registrationForm.alreadyHaveAnAccount","Already have an account?")," "]}),e.jsx("button",{type:"button",onClick:t,children:o("registrationForm.signIn","Sign in")})]}),f&&e.jsx("div",{className:"nice-register-form__footer",children:f})]})}),{displayName:"NiceRegistrationForm"}),de=({style:r})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.3em",height:"0.6em",margin:"0 0.35em 0.15em 0.1em",borderRight:"0.12em solid currentColor",borderBottom:"0.12em solid currentColor",transform:"rotate(45deg)",...r}}),ee=({style:r})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.85em",height:"0.85em",borderRadius:"50%",border:"0.12em solid currentColor",borderTopColor:"transparent",transform:"rotate(-45deg)",...r}}),Y={lowercase:"abcdefghijklmnopqrstuvwxyz",uppercase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",digits:"0123456789",symbols:"!@#$%^&*()-_=+[]{};:,.?/~"},ue=/[0Oo1lI|]/g,z={length:16,lowercase:!0,uppercase:!0,digits:!0,symbols:!0,excludeAmbiguous:!1},X={password:"Generated password",length:"Length",lowercase:"Lowercase (a–z)",uppercase:"Uppercase (A–Z)",digits:"Digits (0–9)",symbols:"Symbols (!@#…)",excludeAmbiguous:"Avoid look-alikes (0 O 1 l I)",generate:"Generate",copy:"Copy",copied:"Copied",noCharacterSets:"Pick at least one kind of character."},he=r=>{const a=globalThis.crypto;if(!a||typeof a.getRandomValues!="function")throw new Error("generatePassword: crypto.getRandomValues is not available");return a.getRandomValues(r)};let me=0;function Z(r,a){const n=Math.floor(4294967296/r)*r,t=new Uint32Array(1);for(;;){const i=a(t)[0];if(i<n)return i%r}}function J(r={},a=he){const n={...z,...r},t=["lowercase","uppercase","digits","symbols"].filter(c=>n[c]).map(c=>n.excludeAmbiguous?Y[c].replace(ue,""):Y[c]).filter(c=>c.length>0);if(t.length===0)return"";const i=Math.max(t.length,Math.min(1024,Math.floor(n.length))),d=t.join(""),l=t.map(c=>c[Z(c.length,a)]);for(;l.length<i;)l.push(d[Z(d.length,a)]);for(let c=l.length-1;c>0;c--){const u=Z(c+1,a);[l[c],l[u]]=[l[u],l[c]]}return l.join("")}const pe=({value:r,defaultValue:a="",onChange:n,options:t,defaultOptions:i,onOptionsChange:d,minLength:l=8,maxLength:c=64,showStrength:u=!0,showCopy:k=!0,onCopy:f,labels:g,disabled:C=!1,className:w,style:o,id:b})=>{const{t:h}=q.useNiceTranslation(),p={...Object.fromEntries(Object.keys(X).map(M=>[M,h(`passwordGenerator.${M}`,X[M])])),...g},[x]=s.useState(()=>`nice-password-generator-${++me}`),j=b??x,[$,N]=s.useState(()=>({...z,...i})),S=t?{...z,...t}:$,[F,I]=s.useState(()=>r===void 0&&!a?J({...z,...i,...t}):a),_=r??F,[P,D]=s.useState(!1),T=s.useRef(void 0);s.useEffect(()=>()=>clearTimeout(T.current),[]);const R=s.useCallback(M=>{r===void 0&&I(M),D(!1),n==null||n(M)},[r,n]),m=s.useCallback(M=>R(J(M)),[R]),v=(M,E)=>{const U={...S,[M]:E};t||N(U),d==null||d(U),m(U)},G=async()=>{!_||!navigator.clipboard||(await navigator.clipboard.writeText(_),D(!0),clearTimeout(T.current),T.current=setTimeout(()=>D(!1),1500),f==null||f(_))},A=!S.lowercase&&!S.uppercase&&!S.digits&&!S.symbols,V=Math.min(c,Math.max(l,S.length));return e.jsxs("div",{id:b,className:`nice-password-generator${w?` ${w}`:""}`,style:o,children:[e.jsxs("div",{className:"nice-password-generator__output",children:[e.jsx("input",{id:`${j}-value`,className:"nice-password-generator__value",type:"text",readOnly:!0,spellCheck:!1,autoComplete:"off",value:_,"aria-label":p.password}),e.jsx("button",{type:"button",className:"nice-password-generator__button",onClick:()=>m(S),disabled:C||A,"aria-label":p.generate,title:p.generate,children:e.jsx(ee,{})}),k&&e.jsx("button",{type:"button",className:"nice-password-generator__button nice-password-generator__button--copy",onClick:G,disabled:C||!_,"aria-live":"polite",children:P?e.jsxs(e.Fragment,{children:[e.jsx(de,{})," ",p.copied]}):p.copy})]}),u&&e.jsx(W,{password:_}),e.jsxs("div",{className:"nice-password-generator__length",children:[e.jsx("label",{htmlFor:`${j}-length`,children:p.length}),e.jsx("input",{id:`${j}-length`,type:"range",min:l,max:c,value:V,disabled:C,onChange:M=>v("length",Number(M.target.value))}),e.jsx("output",{htmlFor:`${j}-length`,className:"nice-password-generator__length-value",children:V})]}),e.jsx("div",{className:"nice-password-generator__sets",children:["lowercase","uppercase","digits","symbols","excludeAmbiguous"].map(M=>e.jsxs("label",{className:"nice-password-generator__option",children:[e.jsx("input",{type:"checkbox",checked:S[M],disabled:C,onChange:E=>v(M,E.target.checked)}),p[M]]},M))}),A&&e.jsx("p",{className:"nice-password-generator__error",role:"alert",children:p.noCharacterSets})]})},ge=Object.assign(s.forwardRef(({requireCurrentPassword:r=!0,onSubmit:a,loading:n=!1,error:t,success:i,minPasswordStrength:d=2,title:l,className:c,style:u},k)=>{const{t:f}=q.useNiceTranslation(),[g,C]=s.useState(""),[w,o]=s.useState(""),[b,h]=s.useState(""),p=H(w),x=w===b,j=(!r||g.length>0)&&w.length>0&&x&&p>=d&&!n,$=s.useCallback(N=>{N.preventDefault(),j&&(a==null||a({currentPassword:r?g:void 0,newPassword:w}))},[j,g,w,r,a]);return e.jsxs("form",{ref:k,className:`nice-change-password${c?` ${c}`:""}`,style:u,onSubmit:$,noValidate:!0,children:[e.jsx("h3",{className:"nice-change-password__title",children:l??f("changePassword.title","Change Password")}),t&&e.jsx("div",{className:"nice-change-password__error",role:"alert",children:t}),i&&e.jsx("div",{className:"nice-change-password__success",role:"status",children:i}),r&&e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-current",children:f("changePassword.currentPassword","Current password")}),e.jsx("input",{id:"nice-cp-current",className:"nice-input",type:"password",value:g,onChange:N=>C(N.target.value),autoComplete:"current-password",disabled:n,required:!0})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-new",children:f("changePassword.newPassword","New password")}),e.jsx("input",{id:"nice-cp-new",className:"nice-input",type:"password",value:w,onChange:N=>o(N.target.value),autoComplete:"new-password",disabled:n,required:!0}),w.length>0&&e.jsx(W,{password:w})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-confirm",children:f("changePassword.confirmNewPassword","Confirm new password")}),e.jsx("input",{id:"nice-cp-confirm",className:"nice-input",type:"password",value:b,onChange:N=>h(N.target.value),autoComplete:"new-password",disabled:n,required:!0}),b&&!x&&e.jsx("span",{className:"nice-error-text",children:f("changePassword.passwordsDoNotMatch","Passwords do not match")})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:!j,children:n?"…":f("changePassword.changePassword","Change Password")})]})}),{displayName:"NiceChangePassword"}),fe=Object.assign(s.forwardRef(({secret:r,qrCodeUrl:a,issuer:n,accountName:t,onVerify:i,loading:d=!1,error:l,onCancel:c,recoveryCodes:u,step:k="setup",onStepChange:f,className:g,style:C},w)=>{const{t:o}=q.useNiceTranslation(),[b,h]=s.useState(""),[p,x]=s.useState(!1),[j,$]=s.useState(!1),N=s.useCallback(F=>{F.preventDefault(),b.length>=6&&(i==null||i(b))},[b,i]),S=`otpauth://totp/${n?`${n}:`:""}${t??"user"}?secret=${r}${n?`&issuer=${n}`:""}&digits=6&period=30`;return e.jsxs("div",{ref:w,className:`nice-2fa-setup${g?` ${g}`:""}`,style:C,children:[e.jsx("h3",{className:"nice-2fa-setup__title",children:o("twoFaSetup.twoFactorAuthentication","Two-Factor Authentication")}),k==="setup"&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.scanThisQrCodeWith","Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.):")}),a?e.jsx("img",{src:a,alt:o("twoFaSetup.n2faQrCode","2FA QR Code"),className:"nice-2fa-setup__qr"}):e.jsxs("div",{className:"nice-2fa-setup__qr-placeholder",children:[e.jsx("span",{children:o("twoFaSetup.qrCode","QR Code")}),e.jsx("code",{className:"nice-2fa-setup__uri",children:S})]}),e.jsxs("div",{className:"nice-2fa-setup__secret",children:[e.jsxs("span",{children:[o("twoFaSetup.orEnterManually","Or enter manually:")," "]}),p?e.jsx("code",{className:"nice-2fa-setup__secret-key",children:r}):e.jsx("button",{type:"button",onClick:()=>x(!0),children:o("twoFaSetup.showSecretKey","Show secret key")})]}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",onClick:()=>f==null?void 0:f("verify"),children:o("twoFaSetup.nextVerify","Next — Verify")})]}),k==="verify"&&e.jsxs("form",{className:"nice-2fa-setup__step",onSubmit:N,children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.enterThe6DigitCode","Enter the 6-digit code from your authenticator app:")}),l&&e.jsx("div",{className:"nice-2fa-setup__error",role:"alert",children:l}),e.jsx("input",{className:"nice-input nice-2fa-setup__code-input",type:"text",inputMode:"numeric",maxLength:6,value:b,onChange:F=>h(F.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",autoFocus:!0,disabled:d,autoComplete:"one-time-code"}),e.jsxs("div",{className:"nice-2fa-setup__actions",children:[e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>f==null?void 0:f("setup"),children:o("twoFaSetup.back","Back")}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:d||b.length<6,children:d?"…":o("twoFaSetup.verify","Verify")})]})]}),k==="recovery"&&u&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.saveTheseRecoveryCodesIn","Save these recovery codes in a safe place. Each code can only be used once:")}),e.jsx("div",{className:"nice-2fa-setup__recovery-codes",children:u.map((F,I)=>e.jsx("code",{className:"nice-2fa-setup__recovery-code",children:F},I))}),e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>{var F;(F=navigator.clipboard)==null||F.writeText(u.join(`
2
+ `)),$(!0)},children:j?o("twoFaSetup.copied","Copied!"):o("twoFaSetup.copyAllCodes","Copy all codes")}),c&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",onClick:c,children:o("twoFaSetup.done","Done")})]}),c&&k!=="recovery"&&e.jsx("button",{type:"button",className:"nice-2fa-setup__cancel",onClick:c,children:o("twoFaSetup.cancel","Cancel")})]})}),{displayName:"NiceTwoFaSetup"}),xe=500;function O(r,a){return Math.floor(Math.random()*(a-r+1))+r}function be(){return`${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}function je(r,a){switch(r){case"math":{const n=a==="easy"?5:a==="hard"?20:10,t=O(1,n),i=O(1,n),d=a!=="easy"&&t>=i&&Math.random()<.5,l=d?t-i:t+i;return{kind:"math",prompt:`${t} ${d?"−":"+"} ${i}`,answer:l}}case"text":{const n=a==="easy"?4:a==="hard"?7:5,t="ABCDEFGHJKMNPQRSTUVWXYZ23456789";let i="";for(let d=0;d<n;d++)i+=t[O(0,t.length-1)];return{kind:"text",text:i}}case"slider":return{kind:"slider",target:O(70,92),tolerance:a==="easy"?8:a==="hard"?2:4};case"checkbox":default:return{kind:"checkbox"}}}function _e(r,a,n){if(!r)return;const t=r.getContext("2d");if(!t)return;const i=r.width,d=r.height;t.clearRect(0,0,i,d),t.fillStyle=n?"#1a1a1a":"#f3f4f6",t.fillRect(0,0,i,d),t.strokeStyle=n?"rgba(255,255,255,0.18)":"rgba(0,0,0,0.18)",t.lineWidth=1;for(let c=0;c<6;c++)t.beginPath(),t.moveTo(O(0,i),O(0,d)),t.lineTo(O(0,i),O(0,d)),t.stroke();t.fillStyle=n?"#e5e7eb":"#111827",t.textBaseline="middle";const l=i/(a.length+1);for(let c=0;c<a.length;c++){const u=O(22,30);t.save(),t.translate(l*(c+1),d/2+O(-4,4)),t.rotate(O(-22,22)*Math.PI/180),t.font=`bold ${u}px monospace`,t.fillText(a[c],-u/3,0),t.restore()}}const we=Object.assign(s.forwardRef((r,a)=>{const{t:n}=q.useNiceTranslation(),{variant:t,difficulty:i="medium",refreshable:d=!0,verifyToken:l,expiresMs:c,label:u=n("captcha.imNotARobot","I'm not a robot"),provider:k="custom",siteKey:f,onVerify:g,onExpire:C,onError:w,onRefresh:o,theme:b="light",size:h="normal",customRender:p,className:x,style:j}=r,$=s.useRef(null),N=s.useRef(null),S=s.useRef(void 0),[F,I]=s.useState(0),[_,P]=s.useState("idle"),[D,T]=s.useState(""),[R,m]=s.useState(""),[v,G]=s.useState(0),A=s.useMemo(()=>je(t??"checkbox",i),[t,i,F]),V=s.useCallback(()=>{P("idle"),T(""),m(""),G(0),I(y=>y+1)},[]),M=s.useCallback(()=>{V(),o==null||o()},[V,o]);s.useImperativeHandle(a,()=>({reset:V,refresh:M,container:$.current}),[V,M]),s.useEffect(()=>{t==="text"&&A.kind==="text"&&_e(N.current,A.text,b==="dark")},[t,A,b]),s.useEffect(()=>{if(_!=="verified"||!c)return;const y=setTimeout(()=>{C==null||C(),V()},c);return()=>clearTimeout(y)},[_,c,C,V]);const E=s.useCallback(()=>{const y=`ntd-cap:${t}:${be()}`;l?(P("verifying"),T(""),Promise.resolve().then(()=>l(y)).then(Q=>{Q?(P("verified"),g==null||g(y)):(P("error"),T(n("captcha.verificationFailedPleaseTryAgain","Verification failed. Please try again.")),I(ne=>ne+1),m(""))}).catch(Q=>{P("error"),T(n("captcha.verificationErrorPleaseTryAgain","Verification error. Please try again.")),w==null||w(Q)})):(P("verified"),g==null||g(y))},[t,l,g,w,n]),U=s.useCallback(()=>{P("error"),T(n("captcha.incorrectPleaseTryAgain","Incorrect, please try again.")),I(y=>y+1),m("")},[n]),te=s.useCallback(()=>{_==="verifying"||_==="verified"||(P("verifying"),T(""),S.current=setTimeout(E,xe))},[_,E]);s.useEffect(()=>()=>clearTimeout(S.current),[]);const K=s.useCallback(()=>{A.kind==="math"?R.trim()!==""&&Number(R)===A.answer?E():U():A.kind==="text"&&(R.trim().toUpperCase()===A.text?E():U())},[A,R,E,U]),se=s.useCallback(y=>{G(y),!(A.kind!=="slider"||_==="verified"||_==="verifying")&&Math.abs(y-A.target)<=A.tolerance&&E()},[A,_,E]);if(!t)return k==="custom"&&p?e.jsx("div",{ref:$,className:`nice-captcha nice-captcha--custom${x?` ${x}`:""}`,style:j,children:p}):e.jsx("div",{ref:$,className:`nice-captcha nice-captcha--${k} nice-captcha--${b}${h==="compact"?" nice-captcha--compact":""}${x?` ${x}`:""}`,style:j,"data-sitekey":f,"data-theme":b,"data-size":h,children:e.jsxs("div",{className:"nice-captcha__placeholder",children:[e.jsx("span",{children:n("captcha.captcha","Captcha ({provider})").replace("{provider}",String(k))}),e.jsx("p",{children:n("captcha.loadTheSdkToActivate","Load the {provider} SDK to activate verification.").replace("{provider}",String(k))})]})});const L=_==="verifying",B=_==="verified",ae=`nice-captcha nice-captcha--${t} nice-captcha--${b} nice-captcha--${_}${h==="compact"?" nice-captcha--compact":""}${x?` ${x}`:""}`;return e.jsxs("div",{ref:$,className:ae,style:j,role:"group","aria-label":n("captcha.captchaChallenge","Captcha challenge"),"data-variant":t,"data-status":_,"data-theme":b,children:[t==="checkbox"&&e.jsxs("button",{type:"button",className:"nice-captcha__checkbox",role:"checkbox","aria-checked":B,"aria-busy":L,disabled:L||B,onClick:te,children:[e.jsx("span",{className:"nice-captcha__box","aria-hidden":"true",children:L?"…":B?e.jsx("span",{style:{display:"inline-block",width:"0.3em",height:"0.6em",marginBottom:"0.15em",borderRight:"0.12em solid currentColor",borderBottom:"0.12em solid currentColor",transform:"rotate(45deg)"}}):""}),e.jsx("span",{className:"nice-captcha__label",children:u})]}),t==="math"&&A.kind==="math"&&e.jsxs("div",{className:"nice-captcha__challenge",children:[e.jsxs("span",{className:"nice-captcha__prompt","aria-hidden":"true",children:[A.prompt," ="]}),e.jsx("input",{className:"nice-input nice-captcha__answer",type:"number",inputMode:"numeric",value:R,"aria-label":n("captcha.whatIs","What is {prompt}?").replace("{prompt}",String(A.prompt)),disabled:L||B,onChange:y=>m(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),K())}}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary nice-captcha__verify",disabled:L||B||R.trim()==="",onClick:K,children:L?"…":n("captcha.verify","Verify")})]}),t==="text"&&A.kind==="text"&&e.jsxs("div",{className:"nice-captcha__challenge",children:[e.jsx("canvas",{ref:N,className:"nice-captcha__canvas",width:160,height:56,"aria-hidden":"true"}),e.jsx("input",{className:"nice-input nice-captcha__answer",type:"text",autoCapitalize:"characters",autoComplete:"off",value:R,"aria-label":n("captcha.typeTheCharactersShownIn","Type the characters shown in the image"),disabled:L||B,onChange:y=>m(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),K())}}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary nice-captcha__verify",disabled:L||B||R.trim()==="",onClick:K,children:L?"…":n("captcha.verify","Verify")})]}),t==="slider"&&A.kind==="slider"&&e.jsxs("div",{className:"nice-captcha__challenge nice-captcha__challenge--slider",children:[e.jsx("span",{className:"nice-captcha__slider-hint","aria-hidden":"true",children:B?n("captcha.verified","Verified"):n("captcha.slideToTheMarker","Slide to the marker")}),e.jsxs("div",{className:"nice-captcha__track",children:[e.jsx("span",{className:"nice-captcha__target","aria-hidden":"true",style:{left:`${A.target}%`}}),e.jsx("input",{className:"nice-captcha__slider",type:"range",min:0,max:100,value:v,"aria-label":n("captcha.slideTheHandleToThe","Slide the handle to the marker to verify"),"aria-valuetext":`${v}%`,disabled:B||L,onChange:y=>se(Number(y.target.value))})]})]}),e.jsxs("div",{className:"nice-captcha__footer",children:[e.jsx("div",{className:"nice-captcha__message",role:"status","aria-live":"polite",children:D}),d&&e.jsx("button",{type:"button",className:"nice-captcha__refresh","aria-label":n("captcha.refreshChallenge","Refresh challenge"),title:n("captcha.refreshChallenge","Refresh challenge"),onClick:M,children:e.jsx(ee,{})})]})]})}),{displayName:"NiceCaptcha"}),Ne=[{id:"google",label:"Google",color:"#4285f4",textColor:"#fff"},{id:"microsoft",label:"Microsoft",color:"#00a4ef",textColor:"#fff"},{id:"discord",label:"Discord",color:"#5865f2",textColor:"#fff"},{id:"spotify",label:"Spotify",color:"#1db954",textColor:"#fff"},{id:"github",label:"GitHub",color:"#24292e",textColor:"#fff"}],ve=Object.assign(s.forwardRef(({providers:r=Ne,onProviderClick:a,disabled:n=!1,loadingProvider:t,direction:i="vertical",separatorText:d,showSeparator:l=!0,className:c,style:u},k)=>{const{t:f}=q.useNiceTranslation();return e.jsxs("div",{ref:k,className:`nice-oauth nice-oauth--${i}${c?` ${c}`:""}`,style:u,children:[l&&e.jsxs("div",{className:"nice-oauth__separator",children:[e.jsx("hr",{}),e.jsx("span",{children:d??f("oAuthButtons.orContinueWith","or continue with")}),e.jsx("hr",{})]}),e.jsx("div",{className:"nice-oauth__buttons",children:r.map(g=>e.jsxs("button",{type:"button",className:`nice-oauth__btn${t===g.id?" nice-oauth__btn--loading":""}`,style:{backgroundColor:g.color,color:g.textColor},onClick:()=>a==null?void 0:a(g.id),disabled:n||!!t,children:[g.icon&&e.jsx("span",{className:"nice-oauth__btn-icon",children:g.icon}),e.jsx("span",{className:"nice-oauth__btn-label",children:t===g.id?"…":g.label})]},g.id))})]})}),{displayName:"NiceOAuthButtons"}),ke=s.forwardRef(function(a,n){const{t}=q.useNiceTranslation(),{tokens:i,onCreate:d,onRevoke:l,availableScopes:c=[],maxTokens:u=10,title:k=t("tokenManagement.apiTokens","API Tokens"),className:f,style:g}=a,[C,w]=s.useState(!1),[o,b]=s.useState(""),[h,p]=s.useState([]),[x,j]=s.useState("90"),[$,N]=s.useState(null),[S,F]=s.useState(!1),[I,_]=s.useState(null),P=s.useCallback(async()=>{if(!(!d||!o.trim())){F(!0);try{const m=x?parseInt(x,10):void 0,v=await d(o.trim(),h,m);N(v),b(""),p([]),w(!1)}finally{F(!1)}}},[d,o,h,x]),D=s.useCallback(async m=>{if(l){_(m);try{await l(m)}finally{_(null)}}},[l]),T=m=>{p(v=>v.includes(m)?v.filter(G=>G!==m):[...v,m])},R=i.length<u;return e.jsxs("div",{ref:n,className:`nice-token-management ${f??""}`,style:g,children:[e.jsxs("div",{className:"nice-token-management__header",children:[e.jsx("h3",{children:k}),R&&e.jsx("button",{className:"nice-token-management__new-btn",onClick:()=>w(!0),disabled:C,children:t("tokenManagement.newToken","+ New Token")})]}),$&&e.jsxs("div",{className:"nice-token-management__reveal",children:[e.jsxs("p",{children:[e.jsx("strong",{children:t("tokenManagement.newTokenCreated","New token created!")})," ",t("tokenManagement.copyItNowItWont","Copy it now — it won't be shown again.")]}),e.jsx("code",{className:"nice-token-management__token-value",children:$}),e.jsx("button",{onClick:()=>N(null),children:t("tokenManagement.dismiss","Dismiss")})]}),C&&e.jsxs("div",{className:"nice-token-management__create-form",children:[e.jsxs("label",{children:[t("tokenManagement.name","Name"),e.jsx("input",{type:"text",value:o,onChange:m=>b(m.target.value),placeholder:t("tokenManagement.myApiToken","My API token"),maxLength:64})]}),c.length>0&&e.jsxs("fieldset",{children:[e.jsx("legend",{children:t("tokenManagement.scopes","Scopes")}),c.map(m=>e.jsxs("label",{className:"nice-token-management__scope",children:[e.jsx("input",{type:"checkbox",checked:h.includes(m),onChange:()=>T(m)}),m]},m))]}),e.jsxs("label",{children:[t("tokenManagement.expiresInDays","Expires in (days)"),e.jsx("input",{type:"number",value:x,onChange:m=>j(m.target.value),min:1,max:365})]}),e.jsxs("div",{className:"nice-token-management__create-actions",children:[e.jsx("button",{onClick:P,disabled:S||!o.trim(),children:S?t("tokenManagement.creating","Creating…"):t("tokenManagement.createToken","Create Token")}),e.jsx("button",{onClick:()=>w(!1),children:t("tokenManagement.cancel","Cancel")})]})]}),i.length===0?e.jsx("p",{className:"nice-token-management__empty",children:t("tokenManagement.noApiTokensYet","No API tokens yet.")}):e.jsxs("table",{className:"nice-token-management__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:t("tokenManagement.name","Name")}),e.jsx("th",{children:t("tokenManagement.prefix","Prefix")}),e.jsx("th",{children:t("tokenManagement.created","Created")}),e.jsx("th",{children:t("tokenManagement.expires","Expires")}),e.jsx("th",{children:t("tokenManagement.lastUsed","Last Used")}),e.jsx("th",{children:t("tokenManagement.scopes","Scopes")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:i.map(m=>{var v;return e.jsxs("tr",{children:[e.jsx("td",{children:m.name}),e.jsx("td",{children:e.jsxs("code",{children:[m.prefix,"…"]})}),e.jsx("td",{children:m.createdAt}),e.jsx("td",{children:m.expiresAt??"—"}),e.jsx("td",{children:m.lastUsedAt??t("tokenManagement.never","Never")}),e.jsx("td",{children:((v=m.scopes)==null?void 0:v.join(", "))||"—"}),e.jsx("td",{children:e.jsx("button",{className:"nice-token-management__revoke-btn",onClick:()=>D(m.id),disabled:I===m.id,children:I===m.id?t("tokenManagement.revoking","Revoking…"):t("tokenManagement.revoke","Revoke")})})]},m.id)})})]})]})});exports.NiceCaptcha=we;exports.NiceChangePassword=ge;exports.NiceLoginForm=ce;exports.NiceOAuthButtons=ve;exports.NicePasswordGenerator=pe;exports.NicePasswordStrength=W;exports.NiceRegistrationForm=le;exports.NiceTokenManagement=ke;exports.NiceTwoFaSetup=fe;exports.calcPasswordStrength=H;exports.generatePassword=J;exports.useAuth=re;