@mcistudio/unoui-vue 1.3.0 → 1.3.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/README.md CHANGED
@@ -98,7 +98,7 @@ Set `data-theme="dark"` on the document root to enable the dark theme. The light
98
98
  | --------------------- | --------------------------------------------------------------------------------------------- |
99
99
  | Layout | `Splitter`, `SplitterPanel` |
100
100
  | General | `Button`, `ButtonGroup`, `Tag`, `Badge`, `BadgeRibbon` |
101
- | Form | `Form`, `FormItem`, `Input`, `Autocomplete`, `InputTag`, `InputI18n`, `InputOtp` |
101
+ | Form | `Form`, `FormItem`, `Input`, `Autocomplete`, `InputTag`, `InputI18n`, `Captcha`, `InputOtp` |
102
102
  | Selection | `Checkbox`, `CheckboxGroup`, `Radio`, `RadioGroup`, `Switch`, `Select` |
103
103
  | Date and numeric | `DatePicker`, `RangePicker`, `TimePicker`, `TimeRangePicker`, `Slider`, `ColorPicker`, `Rate` |
104
104
  | Media | `ImageEditor` |
@@ -0,0 +1,113 @@
1
+ import { type CaptchaChallenge, type CaptchaImageReferrerPolicy, type CaptchaProvider, type CaptchaProps, type CaptchaVerifyFailure, type CaptchaVerifySuccess } from '.';
2
+ type __VLS_Props = {
3
+ /** modelValue 是后端验证成功后签发的一次性票据,不是用户输入的答案。 */
4
+ modelValue?: string;
5
+ /** provider 覆盖 configureUnoUI({ captcha }) 中配置的宿主后端服务。 */
6
+ provider?: CaptchaProvider;
7
+ /** size 是输入区和图片按钮尺寸,默认 md。 */
8
+ size?: CaptchaProps['size'];
9
+ /** disabled 表示是否禁用输入和刷新。 */
10
+ disabled?: boolean;
11
+ /** readonly 表示是否只读展示,不发起答案校验。 */
12
+ readonly?: boolean;
13
+ /** placeholder 是答案输入框占位文案。 */
14
+ placeholder?: string;
15
+ /** ariaLabel 是答案输入框的无障碍标签。 */
16
+ ariaLabel?: string;
17
+ /** imageAlt 是验证码图片的无障碍描述,画面文字本身不应写入 alt。 */
18
+ imageAlt?: string;
19
+ /** refreshAriaLabel 是图片刷新按钮的无障碍标签。 */
20
+ refreshAriaLabel?: string;
21
+ /** loadingText 是挑战加载中的文案。 */
22
+ loadingText?: string;
23
+ /** verifyingText 是后端校验中的文案。 */
24
+ verifyingText?: string;
25
+ /** verifiedText 是验证成功文案。 */
26
+ verifiedText?: string;
27
+ /** requiredText 是未填写答案时的提示。 */
28
+ requiredText?: string;
29
+ /** invalidText 是后端拒绝答案时的默认提示。 */
30
+ invalidText?: string;
31
+ /** loadErrorText 是图片或挑战加载失败时的提示。 */
32
+ loadErrorText?: string;
33
+ /** verifyErrorText 是验证服务异常时的提示。 */
34
+ verifyErrorText?: string;
35
+ /** expiredText 是挑战过期时的提示。 */
36
+ expiredText?: string;
37
+ /** hintText 是正常状态下的刷新提示。 */
38
+ hintText?: string;
39
+ /** refreshIcon 是图片角落的刷新图标类名。 */
40
+ refreshIcon?: string;
41
+ /** refreshOnFailure 表示答案错误后是否自动废弃当前挑战并换题。 */
42
+ refreshOnFailure?: boolean;
43
+ /** maxlength 是答案输入的最大字符数。 */
44
+ maxlength?: number;
45
+ /** name 是验证成功票据隐藏字段的原生名称。 */
46
+ name?: string;
47
+ /** autocomplete 是答案输入框自动填充策略,默认关闭。 */
48
+ autocomplete?: string;
49
+ /** imageWidth 是图片按钮宽度,单位 px;不传时使用 size 对应宽度。 */
50
+ imageWidth?: number;
51
+ /** imageReferrerPolicy 控制验证码图片请求的 Referer 策略。 */
52
+ imageReferrerPolicy?: CaptchaImageReferrerPolicy;
53
+ };
54
+ declare function verify(): Promise<boolean>;
55
+ declare function refresh(event?: MouseEvent): Promise<void>;
56
+ declare function focus(): void;
57
+ declare function blur(): void;
58
+ declare function clear(): Promise<void>;
59
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
60
+ blur: typeof blur;
61
+ clear: typeof clear;
62
+ focus: typeof focus;
63
+ refresh: typeof refresh;
64
+ verify: typeof verify;
65
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
66
+ error: (error: unknown) => any;
67
+ invalid: (result: CaptchaVerifyFailure) => any;
68
+ "update:modelValue": (ticket: string) => any;
69
+ verified: (result: CaptchaVerifySuccess) => any;
70
+ load: (challenge: CaptchaChallenge) => any;
71
+ refresh: (event?: MouseEvent | undefined) => any;
72
+ expired: () => any;
73
+ focus: (event: FocusEvent) => any;
74
+ blur: (event: FocusEvent) => any;
75
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
76
+ onError?: ((error: unknown) => any) | undefined;
77
+ onInvalid?: ((result: CaptchaVerifyFailure) => any) | undefined;
78
+ "onUpdate:modelValue"?: ((ticket: string) => any) | undefined;
79
+ onVerified?: ((result: CaptchaVerifySuccess) => any) | undefined;
80
+ onLoad?: ((challenge: CaptchaChallenge) => any) | undefined;
81
+ onRefresh?: ((event?: MouseEvent | undefined) => any) | undefined;
82
+ onExpired?: (() => any) | undefined;
83
+ onFocus?: ((event: FocusEvent) => any) | undefined;
84
+ onBlur?: ((event: FocusEvent) => any) | undefined;
85
+ }>, {
86
+ size: "sm" | "md" | "lg" | null;
87
+ disabled: boolean;
88
+ name: string;
89
+ modelValue: string;
90
+ provider: CaptchaProvider;
91
+ readonly: boolean;
92
+ placeholder: string;
93
+ ariaLabel: string;
94
+ imageAlt: string;
95
+ refreshAriaLabel: string;
96
+ loadingText: string;
97
+ verifyingText: string;
98
+ verifiedText: string;
99
+ requiredText: string;
100
+ invalidText: string;
101
+ loadErrorText: string;
102
+ verifyErrorText: string;
103
+ expiredText: string;
104
+ hintText: string;
105
+ refreshIcon: string;
106
+ refreshOnFailure: boolean;
107
+ maxlength: number;
108
+ autocomplete: string;
109
+ imageWidth: number;
110
+ imageReferrerPolicy: CaptchaImageReferrerPolicy;
111
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
112
+ declare const _default: typeof __VLS_export;
113
+ export default _default;
@@ -0,0 +1,74 @@
1
+ import type { VariantProps } from 'class-variance-authority';
2
+ export { default as Captcha } from './Captcha.vue';
3
+ /** CaptchaRequestContext 是宿主验证码服务接收的取消上下文。 */
4
+ export interface CaptchaRequestContext {
5
+ signal: AbortSignal;
6
+ }
7
+ /** CaptchaChallenge 是后端签发的一次性图形验证码挑战。 */
8
+ export interface CaptchaChallenge {
9
+ /** id 是后端用于定位挑战的标识,不能包含验证码答案。 */
10
+ id: string;
11
+ /** image 是图片 URL 或 data URL,由宿主后端返回;生产环境应使用栅格化 PNG/WebP,避免 SVG 文本暴露答案。 */
12
+ image: string;
13
+ /** expiresAt 是可选的毫秒时间戳,仅用于前端及时展示过期状态。 */
14
+ expiresAt?: number;
15
+ }
16
+ /** CaptchaVerifyPayload 是控件提交给宿主后端的用户答案。 */
17
+ export interface CaptchaVerifyPayload {
18
+ challengeId: string;
19
+ answer: string;
20
+ }
21
+ /** CaptchaVerifySuccess 表示后端验证通过,并签发一次性票据。 */
22
+ export interface CaptchaVerifySuccess {
23
+ verified: true;
24
+ /** ticket 供后续业务请求提交,必须由后端生成并一次性消费。 */
25
+ ticket: string;
26
+ /** expiresAt 是可选的票据过期时间,单位为毫秒。 */
27
+ expiresAt?: number;
28
+ }
29
+ /** CaptchaVerifyFailure 表示后端明确拒绝本次答案。 */
30
+ export interface CaptchaVerifyFailure {
31
+ verified: false;
32
+ /** message 是可选的、可安全展示给用户的错误文案。 */
33
+ message?: string;
34
+ }
35
+ export type CaptchaVerifyResult = CaptchaVerifySuccess | CaptchaVerifyFailure;
36
+ /** CaptchaProvider 是宿主应用提供的图形验证码后端适配器。 */
37
+ export interface CaptchaProvider {
38
+ /** getChallenge 获取图片和挑战标识;请求取消时应中止底层网络请求。 */
39
+ getChallenge(context: CaptchaRequestContext): Promise<CaptchaChallenge>;
40
+ /** verify 在后端校验答案,成功时返回一次性票据。 */
41
+ verify(payload: CaptchaVerifyPayload, context: CaptchaRequestContext): Promise<CaptchaVerifyResult>;
42
+ }
43
+ export type CaptchaState = 'loading' | 'ready' | 'verifying' | 'verified' | 'invalid' | 'expired' | 'error';
44
+ export type CaptchaImageReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
45
+ /** captchaRoot 定义图形验证码的纵向布局。 */
46
+ export declare const captchaRoot: (props?: ({
47
+ disabled?: boolean | null | undefined;
48
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
49
+ /** captchaRow 定义答案输入与图形区域的一行布局。 */
50
+ export declare const captchaRow: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
51
+ /** captchaInputWrapper 定义输入区边框、焦点、错误和禁用状态。 */
52
+ export declare const captchaInputWrapper: (props?: ({
53
+ size?: "sm" | "md" | "lg" | null | undefined;
54
+ focused?: boolean | null | undefined;
55
+ invalid?: boolean | null | undefined;
56
+ disabled?: boolean | null | undefined;
57
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
58
+ /** captchaInput 定义答案输入框的字号和水平内边距。 */
59
+ export declare const captchaInput: (props?: ({
60
+ size?: "sm" | "md" | "lg" | null | undefined;
61
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
62
+ /** captchaImageButton 定义可刷新的图形验证码图片按钮。 */
63
+ export declare const captchaImageButton: (props?: ({
64
+ size?: "sm" | "md" | "lg" | null | undefined;
65
+ state?: "error" | "loading" | "expired" | "ready" | null | undefined;
66
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
67
+ /** captchaImage 定义后端图片在按钮内的显示方式。 */
68
+ export declare const captchaImage: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
69
+ /** captchaFeedback 定义辅助、错误和成功文案的状态色。 */
70
+ export declare const captchaFeedback: (props?: ({
71
+ state?: "error" | "loading" | "invalid" | "verified" | "expired" | "ready" | "verifying" | null | undefined;
72
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
73
+ /** CaptchaProps 是图形验证码尺寸和输入容器样式推导出的属性类型。 */
74
+ export type CaptchaProps = VariantProps<typeof captchaInputWrapper>;
@@ -0,0 +1,2 @@
1
+ import { a as e, c as t, i as n, n as r, o as i, r as a, s as o, t as s } from "../chunks/captcha-DM3F32sM.js";
2
+ export { t as Captcha, s as captchaFeedback, r as captchaImage, a as captchaImageButton, n as captchaInput, e as captchaInputWrapper, i as captchaRoot, o as captchaRow };
@@ -24,14 +24,14 @@ type __VLS_Slots = {} & {
24
24
  };
25
25
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
26
26
  input: (event: Event) => any;
27
- change: (checked: boolean, event: Event) => any;
28
27
  focus: (event: FocusEvent) => any;
29
28
  blur: (event: FocusEvent) => any;
29
+ change: (checked: boolean, event: Event) => any;
30
30
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
31
31
  onInput?: ((event: Event) => any) | undefined;
32
- onChange?: ((checked: boolean, event: Event) => any) | undefined;
33
32
  onFocus?: ((event: FocusEvent) => any) | undefined;
34
33
  onBlur?: ((event: FocusEvent) => any) | undefined;
34
+ onChange?: ((checked: boolean, event: Event) => any) | undefined;
35
35
  }>, {
36
36
  disabled: boolean;
37
37
  checked: boolean;
@@ -16,11 +16,11 @@ type __VLS_Slots = {} & {
16
16
  default?: (props: typeof __VLS_1) => any;
17
17
  };
18
18
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
19
- change: (value: CheckboxValue[], event: Event) => any;
20
19
  "update:modelValue": (value: CheckboxValue[]) => any;
20
+ change: (value: CheckboxValue[], event: Event) => any;
21
21
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
22
- onChange?: ((value: CheckboxValue[], event: Event) => any) | undefined;
23
22
  "onUpdate:modelValue"?: ((value: CheckboxValue[]) => any) | undefined;
23
+ onChange?: ((value: CheckboxValue[], event: Event) => any) | undefined;
24
24
  }>, {
25
25
  size: CheckboxSize;
26
26
  disabled: boolean;
@@ -0,0 +1,401 @@
1
+ import { getUiAttrClass as e, getUiAttrStyle as t, getUiExposeAttrs as n } from "../attrs.js";
2
+ import { useUnoUIConfig as r } from "../config.js";
3
+ import { cva as i } from "class-variance-authority";
4
+ import { computed as a, createCommentVNode as o, createElementBlock as s, createElementVNode as c, defineComponent as l, mergeProps as ee, nextTick as te, normalizeClass as u, normalizeStyle as d, onBeforeUnmount as ne, onMounted as re, openBlock as f, ref as p, toDisplayString as ie, unref as m, useAttrs as ae, useId as oe, useTemplateRef as se, watch as h } from "vue";
5
+ import { clsx as g } from "clsx";
6
+ //#region src/captcha/Captcha.vue?vue&type=script&setup=true&lang.ts
7
+ var ce = ["data-state", "aria-busy"], le = [
8
+ "value",
9
+ "placeholder",
10
+ "aria-label",
11
+ "aria-invalid",
12
+ "autocomplete",
13
+ "maxlength",
14
+ "disabled",
15
+ "readonly"
16
+ ], ue = [
17
+ "aria-label",
18
+ "title",
19
+ "disabled"
20
+ ], de = [
21
+ "src",
22
+ "alt",
23
+ "referrerpolicy"
24
+ ], fe = {
25
+ key: 1,
26
+ class: "absolute inset-0 flex items-center justify-center",
27
+ "aria-hidden": "true"
28
+ }, pe = {
29
+ key: 2,
30
+ class: "flex flex-col items-center gap-0.5 text-[10px] text-red-500",
31
+ "aria-hidden": "true"
32
+ }, me = {
33
+ key: 3,
34
+ class: "flex flex-col items-center gap-0.5 text-[10px] text-amber-600",
35
+ "aria-hidden": "true"
36
+ }, he = {
37
+ key: 4,
38
+ class: "flex flex-col items-center gap-0.5 text-[10px] text-green-600",
39
+ "aria-hidden": "true"
40
+ }, ge = {
41
+ key: 5,
42
+ class: "absolute bottom-0.5 right-0.5 flex size-4 items-center justify-center rounded bg-zinc-900/70 text-white opacity-0 transition-opacity group-hover/captcha:opacity-100 group-focus-visible/captcha:opacity-100",
43
+ "aria-hidden": "true"
44
+ }, _e = { class: "min-w-0 break-words" }, ve = ["name", "value"], _ = /* @__PURE__ */ l({
45
+ inheritAttrs: !1,
46
+ __name: "Captcha",
47
+ props: {
48
+ modelValue: { default: "" },
49
+ provider: { default: void 0 },
50
+ size: { default: "md" },
51
+ disabled: {
52
+ type: Boolean,
53
+ default: !1
54
+ },
55
+ readonly: {
56
+ type: Boolean,
57
+ default: !1
58
+ },
59
+ placeholder: { default: "请输入图中字符" },
60
+ ariaLabel: { default: "图形验证码" },
61
+ imageAlt: { default: "图形验证码,点击刷新" },
62
+ refreshAriaLabel: { default: "刷新图形验证码" },
63
+ loadingText: { default: "验证码加载中" },
64
+ verifyingText: { default: "正在验证" },
65
+ verifiedText: { default: "验证成功" },
66
+ requiredText: { default: "请输入图形验证码" },
67
+ invalidText: { default: "验证码错误,请重新输入" },
68
+ loadErrorText: { default: "验证码加载失败,请点击重试" },
69
+ verifyErrorText: { default: "验证服务异常,请重试" },
70
+ expiredText: { default: "验证码已过期,请刷新" },
71
+ hintText: { default: "看不清?点击图片刷新" },
72
+ refreshIcon: { default: "i-lucide:rotate-cw" },
73
+ refreshOnFailure: {
74
+ type: Boolean,
75
+ default: !0
76
+ },
77
+ maxlength: { default: 16 },
78
+ name: { default: void 0 },
79
+ autocomplete: { default: "off" },
80
+ imageWidth: { default: void 0 },
81
+ imageReferrerPolicy: { default: "no-referrer" }
82
+ },
83
+ emits: [
84
+ "update:modelValue",
85
+ "verified",
86
+ "invalid",
87
+ "load",
88
+ "refresh",
89
+ "expired",
90
+ "error",
91
+ "focus",
92
+ "blur"
93
+ ],
94
+ setup(i, { expose: l, emit: _ }) {
95
+ let T = i, E = _, D = ae(), ye = r(), O = se("answerInputRef"), k = `ui-captcha-feedback-${oe()}`, A = p(""), j = p(String(T.modelValue ?? "")), M = p(), N = p(j.value ? "verified" : "loading"), P = p(""), F = p(!1), I = p(!1), L = 0, R = 0, z, B, V, H = a(() => T.provider ?? ye.captcha ?? void 0), U = a(() => T.disabled || N.value === "loading" || N.value === "verifying" || N.value === "verified" || N.value === "expired" || N.value === "error"), W = a(() => !T.disabled && !T.readonly && N.value !== "loading"), G = a(() => N.value === "invalid" || N.value === "expired" || N.value === "error"), be = a(() => N.value === "error" ? "error" : N.value === "expired" ? "expired" : N.value === "loading" ? "loading" : "ready"), xe = a(() => P.value ? P.value : N.value === "loading" ? T.loadingText : N.value === "verifying" ? T.verifyingText : N.value === "verified" ? T.verifiedText : N.value === "expired" ? T.expiredText : N.value === "error" ? T.loadErrorText : N.value === "invalid" ? T.invalidText : T.hintText), Se = a(() => N.value === "loading" || N.value === "verifying" ? "i-lucide:loader-2 animate-spin" : N.value === "verified" ? "i-lucide:circle-check" : N.value === "invalid" || N.value === "error" ? "i-lucide:circle-alert" : N.value === "expired" ? "i-lucide:clock-3" : "i-lucide:mouse-pointer-click"), Ce = a(() => g(e(D), v({ disabled: T.disabled }))), we = a(() => g(b({
96
+ size: T.size,
97
+ focused: F.value,
98
+ invalid: G.value,
99
+ disabled: U.value
100
+ }))), Te = a(() => S({
101
+ size: T.size,
102
+ state: be.value
103
+ })), Ee = a(() => T.imageWidth ? { width: `${Math.max(64, Math.floor(T.imageWidth))}px` } : {});
104
+ function De(e) {
105
+ return typeof e == "string" ? e : "";
106
+ }
107
+ function K(e) {
108
+ return typeof e == "object" && !!e && "name" in e && e.name === "AbortError";
109
+ }
110
+ function q() {
111
+ V !== void 0 && (clearTimeout(V), V = void 0);
112
+ }
113
+ function J() {
114
+ z?.abort(), B?.abort(), z = void 0, B = void 0, L += 1, R += 1;
115
+ }
116
+ function Y(e) {
117
+ j.value !== e && (j.value = e, E("update:modelValue", e));
118
+ }
119
+ function X() {
120
+ Y("");
121
+ }
122
+ function Oe() {
123
+ J(), q(), A.value = "", I.value = !1, X(), N.value = "expired", P.value = T.expiredText, E("expired");
124
+ }
125
+ function ke(e) {
126
+ if (q(), e === void 0 || !Number.isFinite(e)) return;
127
+ let t = e - Date.now();
128
+ if (t <= 0) {
129
+ Oe();
130
+ return;
131
+ }
132
+ V = setTimeout(Oe, t);
133
+ }
134
+ function Ae(e) {
135
+ if (!e || typeof e.id != "string" || !e.id.trim() || typeof e.image != "string" || !e.image.trim()) throw Error("Invalid captcha challenge");
136
+ return e;
137
+ }
138
+ async function Z(e = {}) {
139
+ J(), q(), X();
140
+ let t = L, n = H.value, r = new AbortController();
141
+ if (z = r, N.value = "loading", P.value = "", M.value = void 0, I.value = !0, A.value = "", !n) {
142
+ let e = /* @__PURE__ */ Error("Captcha provider is not configured");
143
+ N.value = "error", I.value = !1, P.value = T.loadErrorText, E("error", e);
144
+ return;
145
+ }
146
+ try {
147
+ let i = Ae(await n.getChallenge({ signal: r.signal }));
148
+ if (t !== L || r.signal.aborted) return;
149
+ M.value = i, N.value = e.invalidMessage ? "invalid" : "ready", P.value = e.invalidMessage ?? "", ke(i.expiresAt), E("load", i);
150
+ } catch (e) {
151
+ if (t !== L || r.signal.aborted || K(e)) return;
152
+ N.value = "error", I.value = !1, M.value = void 0, P.value = T.loadErrorText, E("error", e);
153
+ } finally {
154
+ z === r && (z = void 0);
155
+ }
156
+ }
157
+ function Q() {
158
+ te(() => O.value?.focus());
159
+ }
160
+ function je(e) {
161
+ R += 1, B?.abort(), B = void 0, X(), N.value = "invalid", P.value = e.message || T.invalidText, E("invalid", e);
162
+ }
163
+ async function Me() {
164
+ if (T.disabled || T.readonly) return !1;
165
+ if (N.value === "verified" && j.value) return !0;
166
+ let e = H.value, t = M.value;
167
+ if (!e || !t || N.value === "loading" || N.value === "verifying" || N.value === "expired" || N.value === "error") return !1;
168
+ let n = A.value.trim();
169
+ if (!n) return je({
170
+ verified: !1,
171
+ message: T.requiredText
172
+ }), Q(), !1;
173
+ R += 1;
174
+ let r = R;
175
+ B?.abort();
176
+ let i = new AbortController();
177
+ B = i, N.value = "verifying", P.value = "";
178
+ try {
179
+ let a = await e.verify({
180
+ challengeId: t.id,
181
+ answer: n
182
+ }, { signal: i.signal });
183
+ if (r !== R || i.signal.aborted) return !1;
184
+ if (a.verified && typeof a.ticket == "string" && a.ticket.trim()) return A.value = "", N.value = "verified", P.value = "", Y(a.ticket), ke(a.expiresAt), E("verified", a), !0;
185
+ let o = {
186
+ verified: !1,
187
+ message: a.verified ? void 0 : a.message
188
+ };
189
+ return je(o), T.refreshOnFailure && await Z({ invalidMessage: o.message || T.invalidText }), Q(), !1;
190
+ } catch (e) {
191
+ return r !== R || i.signal.aborted || K(e) ? !1 : (X(), N.value = "error", P.value = T.verifyErrorText, E("error", e), Q(), !1);
192
+ } finally {
193
+ B === i && (B = void 0);
194
+ }
195
+ }
196
+ async function $(e) {
197
+ E("refresh", e), await Z();
198
+ }
199
+ function Ne(e) {
200
+ T.disabled || T.readonly || U.value || (A.value = e.target.value, N.value === "invalid" && (N.value = "ready", P.value = ""));
201
+ }
202
+ function Pe(e) {
203
+ e.key !== "Enter" || e.isComposing || (e.preventDefault(), Me());
204
+ }
205
+ function Fe(e) {
206
+ F.value = !0, E("focus", e);
207
+ }
208
+ function Ie(e) {
209
+ F.value = !1, E("blur", e);
210
+ }
211
+ function Le(e) {
212
+ W.value && $(e);
213
+ }
214
+ function Re() {
215
+ I.value = !1;
216
+ }
217
+ function ze() {
218
+ I.value = !1, N.value !== "loading" && (M.value = void 0, N.value = "error", P.value = T.loadErrorText, E("error", /* @__PURE__ */ Error("Captcha image failed to load")));
219
+ }
220
+ function Be() {
221
+ Q();
222
+ }
223
+ function Ve() {
224
+ O.value?.blur();
225
+ }
226
+ async function He() {
227
+ await $(), Q();
228
+ }
229
+ return h(() => T.modelValue, (e) => {
230
+ let t = De(e);
231
+ if (j.value !== t) {
232
+ if (j.value = t, t) {
233
+ J(), A.value = "", N.value = "verified", P.value = "";
234
+ return;
235
+ }
236
+ N.value === "verified" && Z();
237
+ }
238
+ }), h(H, (e, t) => {
239
+ if (e !== t) {
240
+ if (!e) {
241
+ J(), q(), X(), A.value = "", M.value = void 0, I.value = !1, N.value = "error", P.value = T.loadErrorText, E("error", /* @__PURE__ */ Error("Captcha provider is not configured"));
242
+ return;
243
+ }
244
+ Z();
245
+ }
246
+ }), re(() => {
247
+ j.value || Z();
248
+ }), ne(() => {
249
+ J(), q();
250
+ }), l({
251
+ blur: Ve,
252
+ clear: He,
253
+ focus: Be,
254
+ refresh: $,
255
+ verify: Me
256
+ }), (e, r) => (f(), s("div", {
257
+ class: u(Ce.value),
258
+ style: d(m(t)(m(D))),
259
+ "data-state": N.value,
260
+ "aria-busy": N.value === "loading" || N.value === "verifying",
261
+ "data-ui-captcha": "true"
262
+ }, [
263
+ c("div", { class: u(m(y)()) }, [c("div", {
264
+ "data-ui-captcha-input-wrapper": "true",
265
+ class: u(we.value)
266
+ }, [c("input", ee({
267
+ ref_key: "answerInputRef",
268
+ ref: O
269
+ }, m(n)(m(D)), {
270
+ "data-ui-captcha-input": "true",
271
+ type: "text",
272
+ value: A.value,
273
+ class: m(x)({ size: i.size }),
274
+ placeholder: i.placeholder,
275
+ "aria-label": i.ariaLabel,
276
+ "aria-invalid": G.value ? "true" : void 0,
277
+ "aria-describedby": k,
278
+ autocomplete: i.autocomplete,
279
+ autocapitalize: "off",
280
+ spellcheck: !1,
281
+ maxlength: i.maxlength,
282
+ disabled: U.value,
283
+ readonly: i.readonly,
284
+ onInput: Ne,
285
+ onKeydown: Pe,
286
+ onFocus: Fe,
287
+ onBlur: Ie
288
+ }), null, 16, le)], 2), c("button", {
289
+ type: "button",
290
+ "data-ui-captcha-image-button": "true",
291
+ class: u(Te.value),
292
+ style: d(Ee.value),
293
+ "aria-label": i.refreshAriaLabel,
294
+ title: i.refreshAriaLabel,
295
+ disabled: !W.value,
296
+ onClick: Le
297
+ }, [
298
+ M.value && N.value !== "loading" ? (f(), s("img", {
299
+ key: 0,
300
+ src: M.value.image,
301
+ alt: i.imageAlt,
302
+ referrerpolicy: i.imageReferrerPolicy,
303
+ class: u([m(C)(), I.value ? "opacity-0" : "opacity-100"]),
304
+ onLoad: Re,
305
+ onError: ze
306
+ }, null, 42, de)) : o("", !0),
307
+ N.value === "loading" || I.value ? (f(), s("span", fe, [...r[0] ||= [c("span", { class: "i-lucide:loader-2 size-5 animate-spin text-brand-500" }, null, -1)]])) : N.value === "error" ? (f(), s("span", pe, [...r[1] ||= [c("span", { class: "i-lucide:image-off size-4" }, null, -1), c("span", null, "重试", -1)]])) : N.value === "expired" ? (f(), s("span", me, [...r[2] ||= [c("span", { class: "i-lucide:clock-3 size-4" }, null, -1), c("span", null, "刷新", -1)]])) : !M.value && N.value === "verified" ? (f(), s("span", he, [...r[3] ||= [c("span", { class: "i-lucide:badge-check size-4" }, null, -1), c("span", null, "已验证", -1)]])) : o("", !0),
308
+ M.value && N.value !== "loading" && N.value !== "error" && N.value !== "expired" ? (f(), s("span", ge, [c("span", { class: u([i.refreshIcon, "size-3"]) }, null, 2)])) : o("", !0)
309
+ ], 14, ue)], 2),
310
+ c("div", {
311
+ id: k,
312
+ class: u(m(w)({ state: N.value })),
313
+ role: "status",
314
+ "aria-live": "polite",
315
+ "aria-atomic": "true",
316
+ "data-ui-captcha-feedback": "true"
317
+ }, [c("span", {
318
+ class: u([Se.value, "size-3.5 shrink-0"]),
319
+ "aria-hidden": "true"
320
+ }, null, 2), c("span", _e, ie(xe.value), 1)], 2),
321
+ i.name ? (f(), s("input", {
322
+ key: 0,
323
+ type: "hidden",
324
+ name: i.name,
325
+ value: j.value
326
+ }, null, 8, ve)) : o("", !0)
327
+ ], 14, ce));
328
+ }
329
+ }), v = i("inline-flex w-full max-w-[28rem] flex-col gap-1.5 align-middle", {
330
+ variants: { disabled: {
331
+ true: "cursor-not-allowed",
332
+ false: ""
333
+ } },
334
+ defaultVariants: { disabled: !1 }
335
+ }), y = i("flex min-w-0 items-stretch gap-2"), b = i("relative flex min-w-0 flex-auto items-stretch overflow-hidden rounded-md border bg-primary text-primary transition-colors duration-150", {
336
+ variants: {
337
+ size: {
338
+ sm: "h-7",
339
+ md: "h-8",
340
+ lg: "h-9"
341
+ },
342
+ focused: {
343
+ true: "border-brand ring-2 ring-brand/15",
344
+ false: "border-control hover:border-brand/40"
345
+ },
346
+ invalid: {
347
+ true: "border-red-400 ring-2 ring-red-500/15",
348
+ false: ""
349
+ },
350
+ disabled: {
351
+ true: "cursor-not-allowed bg-tertiary/20 text-tertiary opacity-70 hover:border-control",
352
+ false: ""
353
+ }
354
+ },
355
+ defaultVariants: {
356
+ size: "md",
357
+ focused: !1,
358
+ invalid: !1,
359
+ disabled: !1
360
+ }
361
+ }), x = i("h-full min-w-0 w-full border-0 bg-transparent text-inherit outline-none placeholder:text-tertiary/60 disabled:cursor-not-allowed disabled:opacity-100", {
362
+ variants: { size: {
363
+ sm: "px-2 text-sm/5",
364
+ md: "px-3 text-base/4",
365
+ lg: "px-4 text-lg/5"
366
+ } },
367
+ defaultVariants: { size: "md" }
368
+ }), S = i("group/captcha relative flex shrink-0 cursor-pointer items-center justify-center overflow-hidden rounded-md border border-control bg-white p-0 text-zinc-500 outline-none transition-colors hover:border-brand/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/20 disabled:cursor-not-allowed disabled:opacity-60", {
369
+ variants: {
370
+ size: {
371
+ sm: "h-7 w-24",
372
+ md: "h-8 w-28",
373
+ lg: "h-9 w-32"
374
+ },
375
+ state: {
376
+ error: "border-red-300",
377
+ expired: "border-amber-300",
378
+ ready: "",
379
+ loading: ""
380
+ }
381
+ },
382
+ defaultVariants: {
383
+ size: "md",
384
+ state: "ready"
385
+ }
386
+ }), C = i("size-full object-contain"), w = i("flex min-h-4 items-center gap-1 text-xs/4", {
387
+ variants: { state: {
388
+ loading: "text-tertiary",
389
+ ready: "text-tertiary",
390
+ verifying: "text-brand",
391
+ verified: "text-green-600 dark:text-green-400",
392
+ invalid: "text-red-500",
393
+ expired: "text-amber-600 dark:text-amber-400",
394
+ error: "text-red-500"
395
+ } },
396
+ defaultVariants: { state: "ready" }
397
+ });
398
+ //#endregion
399
+ export { b as a, _ as c, x as i, C as n, v as o, S as r, y as s, w as t };
400
+
401
+ //# sourceMappingURL=captcha-DM3F32sM.js.map