@xto/core 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import { LocaleMessages } from '../types';
2
+ /**
3
+ * 한국어 언어 팩
4
+ */
5
+ export declare const koKR: LocaleMessages;
6
+ export default koKR;
@@ -0,0 +1,6 @@
1
+ import { LocaleMessages } from './types';
2
+ /**
3
+ * 中文语言包
4
+ */
5
+ export declare const zhCN: LocaleMessages;
6
+ export default zhCN;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 国际化类型定义
3
+ */
4
+ export type LocaleCode = 'zh-CN' | 'en-US' | 'ja-JP' | 'ko-KR';
5
+ export interface LocaleMessages {
6
+ [key: string]: string | LocaleMessages;
7
+ }
8
+ export interface LocaleConfig {
9
+ code: LocaleCode;
10
+ name: string;
11
+ messages: LocaleMessages;
12
+ }
13
+ export interface UseLocaleReturn {
14
+ locale: import('vue').Ref<LocaleCode>;
15
+ messages: import('vue').ComputedRef<LocaleMessages>;
16
+ t: (key: string, ...args: (string | number)[]) => string;
17
+ setLocale: (code: LocaleCode) => void;
18
+ mergeMessages: (messages: LocaleMessages) => void;
19
+ }
@@ -0,0 +1,91 @@
1
+ import { ThemeConfig, ComponentSize, SizeMap } from '../types';
2
+ /**
3
+ * 默认主题配置
4
+ */
5
+ export declare const defaultThemeConfig: ThemeConfig;
6
+ /**
7
+ * 组件尺寸像素映射
8
+ */
9
+ export declare const sizeMap: SizeMap;
10
+ /**
11
+ * 获取组件尺寸像素值
12
+ * @param size 组件尺寸
13
+ * @returns 像素值
14
+ */
15
+ export declare const getComponentSize: (size: ComponentSize) => number;
16
+ /**
17
+ * 生成颜色调色板
18
+ * @param color 基础颜色
19
+ * @param count 生成数量
20
+ * @returns 颜色数组
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const palette = generateColorPalette('#409eff', 10)
25
+ * // 生成 10 个不同亮度的颜色
26
+ * ```
27
+ */
28
+ export declare function generateColorPalette(color: string, count?: number): string[];
29
+ /**
30
+ * HEX 转 RGB
31
+ * @param hex HEX 颜色值
32
+ * @returns RGB 对象
33
+ */
34
+ export declare const hexToRgb: (hex: string) => {
35
+ r: number;
36
+ g: number;
37
+ b: number;
38
+ } | null;
39
+ /**
40
+ * RGB 转 HEX
41
+ * @param r 红色值
42
+ * @param g 绿色值
43
+ * @param b 蓝色值
44
+ * @returns HEX 颜色值
45
+ */
46
+ export declare const rgbToHex: (r: number, g: number, b: number) => string;
47
+ /**
48
+ * 混合颜色
49
+ * @param color1 颜色1
50
+ * @param color2 颜色2
51
+ * @param weight 权重(0-1)
52
+ * @returns 混合后的颜色
53
+ */
54
+ export declare const mixColor: (color1: string, color2: string, weight?: number) => string;
55
+ /**
56
+ * CSS 变量前缀
57
+ */
58
+ export declare const cssVarPrefix = "--xto";
59
+ /**
60
+ * 生成 CSS 变量对象
61
+ * @param config 主题配置
62
+ * @returns CSS 变量对象
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const vars = generateCSSVars(themeConfig)
67
+ * // { '--xto-color-primary': '#409eff', ... }
68
+ * ```
69
+ */
70
+ export declare function generateCSSVars(config: ThemeConfig): Record<string, string>;
71
+ /**
72
+ * 应用 CSS 变量到根元素
73
+ * @param config 主题配置
74
+ */
75
+ export declare function applyCSSVars(config: ThemeConfig): void;
76
+ /**
77
+ * 移除 CSS 变量
78
+ */
79
+ export declare function removeCSSVars(): void;
80
+ /**
81
+ * 深色主题 CSS 变量
82
+ */
83
+ export declare const darkCSSVars: Record<string, string>;
84
+ /**
85
+ * 应用深色主题
86
+ */
87
+ export declare function applyDarkTheme(): void;
88
+ /**
89
+ * 移除深色主题
90
+ */
91
+ export declare function removeDarkTheme(): void;
@@ -0,0 +1,258 @@
1
+ import { Ref, ComputedRef, PropType } from 'vue';
2
+ /**
3
+ * 组件尺寸
4
+ */
5
+ export type ComponentSize = 'large' | 'default' | 'small';
6
+ /**
7
+ * 组件状态
8
+ */
9
+ export type ComponentState = 'default' | 'hover' | 'focus' | 'active' | 'disabled';
10
+ /**
11
+ * 主题模式
12
+ */
13
+ export type ThemeMode = 'light' | 'dark';
14
+ /**
15
+ * 过渡动画名称
16
+ */
17
+ export type TransitionName = 'fade' | 'zoom' | 'slide-left' | 'slide-right' | 'slide-up' | 'slide-down';
18
+ /**
19
+ * 水平对齐方式
20
+ */
21
+ export type HorizontalAlignment = 'left' | 'center' | 'right';
22
+ /**
23
+ * 垂直对齐方式
24
+ */
25
+ export type VerticalAlignment = 'top' | 'middle' | 'bottom';
26
+ /**
27
+ * 字面量联合类型
28
+ * @example LiteralUnion<'a' | 'b'> // 'a' | 'b' | (string & {})
29
+ */
30
+ export type LiteralUnion<T extends string> = T | (string & {});
31
+ /**
32
+ * 任意函数类型
33
+ */
34
+ export type AnyFunction<T = any, R = any> = (...args: T[]) => R;
35
+ /**
36
+ * Promise 函数类型
37
+ */
38
+ export type PromiseFunction<T = any, R = any> = (...args: T[]) => Promise<R>;
39
+ /**
40
+ * 可能是 Ref 的值
41
+ */
42
+ export type MaybeRef<T> = T | Ref<T>;
43
+ /**
44
+ * 深层可能是 Ref 的值
45
+ */
46
+ export type MaybeRefDeep<T> = T extends object ? MaybeRefDeep<T> | MaybeRef<T> : MaybeRef<T>;
47
+ /**
48
+ * 可选的 Ref
49
+ */
50
+ export type MaybeComputedRef<T> = ComputedRef<T> | T;
51
+ /**
52
+ * CSS 属性类型
53
+ */
54
+ export type CSSProperties = Record<string, any>;
55
+ /**
56
+ * 类名类型
57
+ */
58
+ export type ClassName = string | Record<string, boolean> | ClassName[];
59
+ /**
60
+ * 事件处理器类型
61
+ */
62
+ export type EventHandler<T = any> = (event: T) => void;
63
+ /**
64
+ * 对象字段类型
65
+ */
66
+ export type ObjectField<T, K extends keyof T = keyof T> = K extends string ? T[K] : never;
67
+ /**
68
+ * 必填字段类型
69
+ */
70
+ export type RequiredField<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
71
+ /**
72
+ * 可选字段类型
73
+ */
74
+ export type OptionalField<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
75
+ /**
76
+ * Vue Prop 类型构造器
77
+ */
78
+ export type VuePropType<T> = BooleanConstructor | StringConstructor | NumberConstructor | ObjectConstructor | ArrayConstructor | DateConstructor | FunctionConstructor | SymbolConstructor;
79
+ /**
80
+ * Vue Prop 定义
81
+ */
82
+ export type VueProp<T> = PropType<T> | {
83
+ type: VuePropType<T>;
84
+ values?: T[];
85
+ default?: T;
86
+ };
87
+ /**
88
+ * 从 Props 类型提取
89
+ */
90
+ export type ExtractPropTypesPartial<T> = Partial<T>;
91
+ /**
92
+ * 加载配置
93
+ */
94
+ export interface LoadingConfig {
95
+ /** 加载文本 */
96
+ text?: string;
97
+ /** 文本颜色 */
98
+ textColor?: string;
99
+ /** 背景颜色 */
100
+ background?: string;
101
+ /** 自定义类名 */
102
+ customClass?: string;
103
+ /** 是否显示 */
104
+ visible?: boolean;
105
+ /** 目标元素 */
106
+ target?: HTMLElement | string;
107
+ /** 加载器尺寸 */
108
+ size?: ComponentSize;
109
+ }
110
+ /**
111
+ * Z-Index 管理
112
+ */
113
+ export interface ZIndex {
114
+ /** 当前 z-index */
115
+ current: number;
116
+ /** 获取下一个 z-index */
117
+ next: () => number;
118
+ /** 设置 z-index */
119
+ set: (zIndex: number) => void;
120
+ }
121
+ /**
122
+ * 主题配置
123
+ */
124
+ export interface ThemeConfig {
125
+ /** 主题模式 */
126
+ mode: ThemeMode;
127
+ /** 主色调 */
128
+ primary: string;
129
+ /** 成功色 */
130
+ success: string;
131
+ /** 警告色 */
132
+ warning: string;
133
+ /** 危险色 */
134
+ danger: string;
135
+ /** 信息色 */
136
+ info: string;
137
+ /** 组件尺寸 */
138
+ size: ComponentSize;
139
+ }
140
+ /**
141
+ * 命名空间配置
142
+ */
143
+ export interface NamespaceConfig {
144
+ /** 命名空间前缀 */
145
+ prefix: string;
146
+ /** 块名称 */
147
+ block: string;
148
+ /** BEM 分隔符 */
149
+ separator: string;
150
+ }
151
+ /**
152
+ * 标准事件类型
153
+ */
154
+ export interface EmitType<T = any> {
155
+ (e: 'update:modelValue', value: T): void;
156
+ (e: 'change', value: T): void;
157
+ (e: 'click', event: MouseEvent): void;
158
+ (e: 'blur', event: FocusEvent): void;
159
+ (e: 'focus', event: FocusEvent): void;
160
+ }
161
+ /**
162
+ * 键盘事件处理器
163
+ */
164
+ export type KeyboardEventHandler = (event: KeyboardEvent) => void;
165
+ /**
166
+ * 鼠标事件处理器
167
+ */
168
+ export type MouseEventHandler = (event: MouseEvent) => void;
169
+ /**
170
+ * 触摸事件处理器
171
+ */
172
+ export type TouchEventHandler = (event: TouchEvent) => void;
173
+ /**
174
+ * useNamespace 返回类型
175
+ */
176
+ export interface NamespaceReturn {
177
+ /** 命名空间 */
178
+ namespace: string;
179
+ /** 前缀 */
180
+ prefix: string;
181
+ /** 块类名 */
182
+ b: (blockSuffix?: string) => string;
183
+ /** 元素类名 */
184
+ e: (element: string) => string;
185
+ /** 修饰符类名 */
186
+ m: (modifier: string) => string;
187
+ /** 块-元素类名 */
188
+ be: (blockSuffix: string, element: string) => string;
189
+ /** 块-修饰符类名 */
190
+ bm: (blockSuffix: string, modifier: string) => string;
191
+ /** 元素-修饰符类名 */
192
+ em: (element: string, modifier: string) => string;
193
+ /** 状态类名 */
194
+ is: (name: string, condition?: boolean) => string;
195
+ }
196
+ /**
197
+ * useToggle 返回类型
198
+ */
199
+ export interface UseToggleReturn {
200
+ /** 当前值 */
201
+ value: Ref<boolean>;
202
+ /** 切换值 */
203
+ toggle: (newValue?: boolean) => void;
204
+ /** 设置为 true */
205
+ setTrue: () => void;
206
+ /** 设置为 false */
207
+ setFalse: () => void;
208
+ }
209
+ /**
210
+ * useVisible 返回类型
211
+ */
212
+ export interface UseVisibleReturn {
213
+ /** 是否可见 */
214
+ visible: Ref<boolean>;
215
+ /** 显示 */
216
+ show: () => void;
217
+ /** 隐藏 */
218
+ hide: () => void;
219
+ /** 切换 */
220
+ toggle: () => void;
221
+ }
222
+ /**
223
+ * useDisabled 返回类型
224
+ */
225
+ export interface UseDisabledReturn {
226
+ /** 是否禁用 */
227
+ disabled: Ref<boolean>;
228
+ /** 启用 */
229
+ enable: () => void;
230
+ /** 禁用 */
231
+ disable: () => void;
232
+ }
233
+ /**
234
+ * useLoading 返回类型
235
+ */
236
+ export interface UseLoadingReturn {
237
+ /** 是否加载中 */
238
+ loading: Ref<boolean>;
239
+ /** 设置加载状态 */
240
+ setLoading: (val: boolean) => void;
241
+ /** 开始加载 */
242
+ start: () => void;
243
+ /** 结束加载 */
244
+ end: () => void;
245
+ }
246
+ /**
247
+ * useFocus 返回类型
248
+ */
249
+ export interface UseFocusReturn {
250
+ /** 是否聚焦 */
251
+ focused: Ref<boolean>;
252
+ }
253
+ /**
254
+ * 组件尺寸像素映射
255
+ */
256
+ export type SizeMap = {
257
+ [K in ComponentSize]: number;
258
+ };
@@ -0,0 +1,270 @@
1
+ /**
2
+ * 工具函数集合
3
+ * 提供常用的工具函数
4
+ */
5
+ export * from './namespace';
6
+ export * from './z-index';
7
+ /**
8
+ * 检查是否为 undefined
9
+ * @param val 待检查的值
10
+ * @returns 是否为 undefined
11
+ */
12
+ export declare const isUndefined: (val: unknown) => val is undefined;
13
+ /**
14
+ * 检查是否为 null
15
+ * @param val 待检查的值
16
+ * @returns 是否为 null
17
+ */
18
+ export declare const isNull: (val: unknown) => val is null;
19
+ /**
20
+ * 检查是否为 nil(undefined 或 null)
21
+ * @param val 待检查的值
22
+ * @returns 是否为 nil
23
+ */
24
+ export declare const isNil: (val: unknown) => val is undefined | null;
25
+ /**
26
+ * 检查是否为真值
27
+ * @param val 待检查的值
28
+ * @returns 是否为 true
29
+ */
30
+ export declare const isTrue: (val: unknown) => boolean;
31
+ /**
32
+ * 检查是否为假值
33
+ * @param val 待检查的值
34
+ * @returns 是否为 false
35
+ */
36
+ export declare const isFalse: (val: unknown) => boolean;
37
+ /**
38
+ * 检查是否为空值(空数组、空对象、空字符串、null、undefined)
39
+ * @param val 待检查的值
40
+ * @returns 是否为空值
41
+ */
42
+ export declare const isEmpty: (val: unknown) => boolean;
43
+ /**
44
+ * 检查是否已定义(非 null 和 undefined)
45
+ * @param val 待检查的值
46
+ * @returns 是否已定义
47
+ */
48
+ export declare const isDefined: <T>(val: T | undefined | null) => val is T;
49
+ /**
50
+ * 检查是否为数字
51
+ * @param val 待检查的值
52
+ * @returns 是否为数字
53
+ */
54
+ export declare const isNumber: (val: unknown) => val is number;
55
+ /**
56
+ * 检查是否为字符串
57
+ * @param val 待检查的值
58
+ * @returns 是否为字符串
59
+ */
60
+ export declare const isString: (val: unknown) => val is string;
61
+ /**
62
+ * 检查是否为布尔值
63
+ * @param val 待检查的值
64
+ * @returns 是否为布尔值
65
+ */
66
+ export declare const isBoolean: (val: unknown) => val is boolean;
67
+ /**
68
+ * 检查是否为函数
69
+ * @param val 待检查的值
70
+ * @returns 是否为函数
71
+ */
72
+ export declare const isFunction: (val: unknown) => val is (...args: any[]) => any;
73
+ /**
74
+ * 检查是否为数组
75
+ * @param val 待检查的值
76
+ * @returns 是否为数组
77
+ */
78
+ export declare const isArray: (arg: any) => arg is any[];
79
+ /**
80
+ * 检查是否为对象
81
+ * @param val 待检查的值
82
+ * @returns 是否为对象
83
+ */
84
+ export declare const isObject: (val: unknown) => val is Record<string, any>;
85
+ /**
86
+ * 检查是否为纯对象
87
+ * @param val 待检查的值
88
+ * @returns 是否为纯对象
89
+ */
90
+ export declare const isPlainObject: (val: unknown) => val is Record<string, any>;
91
+ /**
92
+ * 检查是否为 Promise
93
+ * @param val 待检查的值
94
+ * @returns 是否为 Promise
95
+ */
96
+ export declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
97
+ /**
98
+ * 检查是否为日期
99
+ * @param val 待检查的值
100
+ * @returns 是否为日期
101
+ */
102
+ export declare const isDate: (val: unknown) => val is Date;
103
+ /**
104
+ * 检查是否为正则表达式
105
+ * @param val 待检查的值
106
+ * @returns 是否为正则表达式
107
+ */
108
+ export declare const isRegExp: (val: unknown) => val is RegExp;
109
+ /**
110
+ * 获取值的类型
111
+ * @param val 待检查的值
112
+ * @returns 类型字符串
113
+ */
114
+ export declare const getType: (val: unknown) => string;
115
+ /**
116
+ * 检查值是否为指定类型
117
+ * @param val 待检查的值
118
+ * @param type 类型名称
119
+ * @returns 是否为指定类型
120
+ */
121
+ export declare const isType: <T>(val: unknown, type: string) => val is T;
122
+ /**
123
+ * 一元函数包装器
124
+ * @param fn 函数
125
+ * @returns 只接受一个参数的函数
126
+ */
127
+ export declare const unary: <T>(fn: (arg: T) => any) => (arg: T) => any;
128
+ /**
129
+ * 常量函数
130
+ * @param val 常量值
131
+ * @returns 返回常量值的函数
132
+ */
133
+ export declare const constant: <T>(val: T) => () => T;
134
+ /**
135
+ * 默认值
136
+ * @param val 待检查的值
137
+ * @param defaultVal 默认值
138
+ * @returns 值或默认值
139
+ */
140
+ export declare const defaultTo: <T, D>(val: T | undefined | null, defaultVal: D) => T | D;
141
+ /**
142
+ * 空操作函数
143
+ */
144
+ export declare const noop: () => void;
145
+ /**
146
+ * 恒等函数
147
+ * @param val 值
148
+ * @returns 相同的值
149
+ */
150
+ export declare const identity: <T>(val: T) => T;
151
+ /**
152
+ * 组合函数(从右到左执行)
153
+ * @param fns 函数列表
154
+ * @returns 组合后的函数
155
+ */
156
+ export declare const compose: <T>(...fns: ((arg: any) => any)[]) => (val: T) => T;
157
+ /**
158
+ * 管道函数(从左到右执行)
159
+ * @param fns 函数列表
160
+ * @returns 管道后的函数
161
+ */
162
+ export declare const pipe: <T>(...fns: ((arg: any) => any)[]) => (val: T) => T;
163
+ /**
164
+ * 只执行一次的函数
165
+ * @param fn 函数
166
+ * @returns 只执行一次的函数
167
+ */
168
+ export declare const once: <T extends (...args: any[]) => any>(fn: T) => T;
169
+ /**
170
+ * 尝试执行函数
171
+ * @param fn 要执行的函数
172
+ * @param onError 错误处理函数
173
+ * @returns 结果或错误处理结果
174
+ */
175
+ export declare const tryCatch: <T>(fn: () => T, onError?: (error: any) => T) => T;
176
+ /**
177
+ * 强制转换为数组
178
+ * @param val 值或数组
179
+ * @returns 数组
180
+ */
181
+ export declare const coerceToArray: <T>(val: T | T[]) => T[];
182
+ /**
183
+ * 数组去重
184
+ * @param arr 数组
185
+ * @returns 去重后的数组
186
+ */
187
+ export declare const unique: <T>(arr: T[]) => T[];
188
+ /**
189
+ * 数组扁平化
190
+ * @param arr 嵌套数组
191
+ * @returns 扁平化后的数组
192
+ */
193
+ export declare const flatten: <T>(arr: (T | T[])[]) => T[];
194
+ /**
195
+ * 深度合并对象
196
+ * @param target 目标对象
197
+ * @param sources 源对象列表
198
+ * @returns 合并后的对象
199
+ */
200
+ export declare const deepMerge: <T extends Record<string, any>>(target: T, ...sources: Partial<T>[]) => T;
201
+ /**
202
+ * 深度克隆
203
+ * @param val 待克隆的值
204
+ * @returns 克隆后的值
205
+ */
206
+ export declare const deepClone: <T>(val: T) => T;
207
+ /**
208
+ * 获取嵌套属性值
209
+ * @param obj 对象
210
+ * @param path 路径
211
+ * @param defaultValue 默认值
212
+ * @returns 属性值
213
+ */
214
+ export declare const get: <T = any>(obj: Record<string, any>, path: string | string[], defaultValue?: T) => T;
215
+ /**
216
+ * 设置嵌套属性值
217
+ * @param obj 对象
218
+ * @param path 路径
219
+ * @param value 值
220
+ */
221
+ export declare const set: (obj: Record<string, any>, path: string | string[], value: any) => void;
222
+ /**
223
+ * 防抖函数
224
+ * @param fn 要防抖的函数
225
+ * @param delay 延迟时间(毫秒)
226
+ * @returns 防抖后的函数
227
+ */
228
+ export declare const debounce: <T extends (...args: any[]) => any>(fn: T, delay?: number) => ((...args: Parameters<T>) => void);
229
+ /**
230
+ * 节流函数
231
+ * @param fn 要节流的函数
232
+ * @param delay 延迟时间(毫秒)
233
+ * @returns 节流后的函数
234
+ */
235
+ export declare const throttle: <T extends (...args: any[]) => any>(fn: T, delay?: number) => ((...args: Parameters<T>) => void);
236
+ /**
237
+ * 是否为浏览器环境
238
+ */
239
+ export declare const isBrowser: boolean;
240
+ /**
241
+ * 是否支持触摸
242
+ */
243
+ export declare const isSupportTouch: boolean;
244
+ /**
245
+ * 是否为移动端
246
+ */
247
+ export declare const isMobile: boolean;
248
+ /**
249
+ * 是否为 iOS
250
+ */
251
+ export declare const isIOS: boolean;
252
+ /**
253
+ * 是否为 Android
254
+ */
255
+ export declare const isAndroid: boolean;
256
+ /**
257
+ * 是否为微信
258
+ */
259
+ export declare const isWechat: boolean;
260
+ /**
261
+ * 生成 UUID
262
+ * @returns UUID 字符串
263
+ */
264
+ export declare const uuid: () => string;
265
+ /**
266
+ * 生成短 ID
267
+ * @param length ID 长度
268
+ * @returns 短 ID 字符串
269
+ */
270
+ export declare const shortId: (length?: number) => string;