@gi-base/utils 0.0.0-stage → 0.0.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/LICENSE +20 -0
- package/README.md +13 -2
- package/dist/color.d.ts +33 -0
- package/dist/hooks/context.d.ts +31 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/useComposition.d.ts +7 -0
- package/dist/hooks/useFormItem.d.ts +9 -0
- package/dist/hooks/useGlobalConfig.d.ts +10 -0
- package/dist/hooks/useSize.d.ts +9 -0
- package/dist/hooks/useVModel.d.ts +14 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +208 -0
- package/dist/string.d.ts +2 -0
- package/dist/svg.d.ts +25 -0
- package/dist/useAiTarget.d.ts +39 -0
- package/dist/useNamespace.d.ts +17 -0
- package/dist/withInstall.d.ts +3 -0
- package/package.json +33 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2026-present GI Base
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gi-base/utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
GI UI 的共享工具与组合式函数,包括命名空间、尺寸与全局配置、表单联动、浮层定位、AI 目标注册等。
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { useNamespace, useSize, useAiTarget } from '@gi-base/utils'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
- `useNamespace`:生成 BEM 类名。
|
|
10
|
+
- `useSize` / `useGlobalConfig`:读取 FormItem、ConfigProvider 或父级注入的尺寸与全局配置。
|
|
11
|
+
- `useAiTarget`:向 AI 运行时注册语义目标;无 Provider 时 no-op。
|
|
12
|
+
- `useFloating` / `useClickOutside`:浮层定位与外部点击关闭。
|
|
13
|
+
|
|
14
|
+
该包只依赖 Vue,可被 UI、AI 与业务层共同复用。
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type RGB = [number, number, number];
|
|
2
|
+
export interface GiColorScheme {
|
|
3
|
+
/** 基色 */
|
|
4
|
+
base: string;
|
|
5
|
+
/** 实心 hover(亮色变深、暗色变浅,保证变化可见) */
|
|
6
|
+
hover: string;
|
|
7
|
+
/** 实心 active */
|
|
8
|
+
active: string;
|
|
9
|
+
/** 基色上的最佳文字色 */
|
|
10
|
+
text: string;
|
|
11
|
+
/** 10% 基色 + 90% 白,用于 plain / text+bg 底色 */
|
|
12
|
+
wash: string;
|
|
13
|
+
/** 50% 基色 + 50% 白,用于 plain 边框 */
|
|
14
|
+
edge: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 解析颜色:支持 #rgb / #rrggbb / rgb() / rgba()
|
|
18
|
+
* 不支持的颜色格式返回 null(组件侧会退化为普通按钮)
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseColor(input: string): RGB | null;
|
|
21
|
+
/** 按权重混合:weight 为 a 的占比(0–1) */
|
|
22
|
+
export declare function mixColor(a: RGB, b: RGB, weight: number): RGB;
|
|
23
|
+
export declare function toHex(rgb: RGB): string;
|
|
24
|
+
/** WCAG 相对亮度 */
|
|
25
|
+
export declare function relativeLuminance([r, g, b]: RGB): number;
|
|
26
|
+
/** 依据亮度给出可读文字色 */
|
|
27
|
+
export declare function contrastColor(rgb: RGB): string;
|
|
28
|
+
/**
|
|
29
|
+
* 生成自定义颜色的完整色板。
|
|
30
|
+
* hover / active 方向随亮度自适应:亮底变深、暗底变浅,保证 hover 肉眼可见。
|
|
31
|
+
*/
|
|
32
|
+
export declare function createColorScheme(color: string): GiColorScheme | null;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** 组件间通信契约:注入 key 与上下文类型集中在此,避免各自的 Symbol 互不相认 */
|
|
2
|
+
export declare const componentSizes: readonly ["large", "default", "small"];
|
|
3
|
+
export type ComponentSize = (typeof componentSizes)[number];
|
|
4
|
+
/** 尺寸继承:ButtonGroup → Button、Form → FormItem → Input 等 */
|
|
5
|
+
export declare const SIZE_INJECTION_KEY: unique symbol;
|
|
6
|
+
/** 全局配置:ConfigProvider 注入 */
|
|
7
|
+
export declare const GLOBAL_CONFIG_INJECTION_KEY: unique symbol;
|
|
8
|
+
export interface GlobalConfigContext {
|
|
9
|
+
/** 全局默认尺寸 */
|
|
10
|
+
size?: ComponentSize;
|
|
11
|
+
/** 浮层层级起点 */
|
|
12
|
+
zIndex?: number;
|
|
13
|
+
/** 命名空间前缀,默认 gi */
|
|
14
|
+
namespace?: string;
|
|
15
|
+
/** 文案语言包,组件按 key 取值 */
|
|
16
|
+
locale?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/** 表单上下文:FormItem 注入给表单控件 */
|
|
19
|
+
export declare const FORM_ITEM_INJECTION_KEY: unique symbol;
|
|
20
|
+
export type FormValidateTrigger = 'blur' | 'change' | 'input';
|
|
21
|
+
export interface FormItemContext {
|
|
22
|
+
/** 触发该控件的校验 */
|
|
23
|
+
validate?: (trigger?: FormValidateTrigger) => void;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
size?: ComponentSize | '';
|
|
26
|
+
formItemId?: string;
|
|
27
|
+
labelId?: string;
|
|
28
|
+
inputIds?: string[];
|
|
29
|
+
addInputId?: (id: string) => void;
|
|
30
|
+
removeInputId?: (id: string) => void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FormItemContext } from './context';
|
|
2
|
+
export declare function provideFormItem(ctx: FormItemContext): void;
|
|
3
|
+
/**
|
|
4
|
+
* 表单控件读取 FormItem 上下文。
|
|
5
|
+
* 未挂载 FormItem 时返回 undefined,所有调用点都要按可空处理(no-op)。
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFormItem(): {
|
|
8
|
+
formItem: FormItemContext | undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { GlobalConfigContext } from './context';
|
|
3
|
+
export declare function provideGlobalConfig(ctx: Ref<GlobalConfigContext>): void;
|
|
4
|
+
/** 读取 ConfigProvider 提供的全局配置;未挂载 provider 时返回空对象 */
|
|
5
|
+
export declare function useGlobalConfig(): {
|
|
6
|
+
config: import('vue').ComputedRef<GlobalConfigContext>;
|
|
7
|
+
size: import('vue').ComputedRef<"large" | "default" | "small" | undefined>;
|
|
8
|
+
zIndex: import('vue').ComputedRef<number | undefined>;
|
|
9
|
+
locale: import('vue').ComputedRef<Record<string, unknown> | undefined>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { ComponentSize } from './context';
|
|
3
|
+
export declare function provideSize(size: Ref<ComponentSize | '' | undefined>): void;
|
|
4
|
+
/**
|
|
5
|
+
* 尺寸回退顺序:显式 props.size → 父级 provide → ConfigProvider 全局 size → 'default'
|
|
6
|
+
*/
|
|
7
|
+
export declare function useSize(props: {
|
|
8
|
+
size?: ComponentSize | '';
|
|
9
|
+
}): import('vue').ComputedRef<"large" | "default" | "small">;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** v-model 修饰符:与 Vue 的 v-model.trim / v-model.number 语义一致 */
|
|
2
|
+
export declare function applyModelModifiers<T>(value: T, modifiers?: Record<string, boolean>): T;
|
|
3
|
+
export interface UseVModelOptions {
|
|
4
|
+
/** Vue 编译注入的 modelModifiers */
|
|
5
|
+
modifiers?: Record<string, boolean>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 双向绑定:读写 props[key],写入时先套用修饰符再回传。
|
|
9
|
+
* 同时返回 normalize,方便在事件里拿到“已修饰”的值。
|
|
10
|
+
*/
|
|
11
|
+
export declare function useVModel<T>(props: any, key: string, setter: (value: T) => void, options?: UseVModelOptions): {
|
|
12
|
+
model: import('vue').WritableComputedRef<T, T>;
|
|
13
|
+
normalize: (value: T) => T;
|
|
14
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { inject as l, onUnmounted as S, provide as I, computed as c, ref as y } from "vue";
|
|
2
|
+
const z = (t, n) => (t.install = (e) => {
|
|
3
|
+
const r = n || t.name || "GiComponent";
|
|
4
|
+
e.component(r, t);
|
|
5
|
+
}, t);
|
|
6
|
+
function w(t, n = "gi") {
|
|
7
|
+
const e = `${n}-${t}`;
|
|
8
|
+
return {
|
|
9
|
+
namespace: n,
|
|
10
|
+
b: () => e,
|
|
11
|
+
be: (o) => `${e}__${o}`,
|
|
12
|
+
bm: (o) => o ? `${e}--${o}` : e,
|
|
13
|
+
is: (o, p) => p === !1 ? "" : `is-${o}`,
|
|
14
|
+
cssVar: (o) => `var(--${n}-${o})`,
|
|
15
|
+
bmAll: (...o) => o.filter(Boolean).map((p) => `${e}--${p}`)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const N = Symbol("gi-ai-target-registry");
|
|
19
|
+
function A(t) {
|
|
20
|
+
const n = l(N, null), e = t.code || t.field;
|
|
21
|
+
return n && e && (n.register(t), S(() => n.unregister(t))), {
|
|
22
|
+
registered: !!(n && e)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function $(t) {
|
|
26
|
+
if (!t) return null;
|
|
27
|
+
const n = t.trim().toLowerCase();
|
|
28
|
+
if (n.startsWith("#")) {
|
|
29
|
+
const r = n.slice(1);
|
|
30
|
+
return /^[0-9a-f]{3}$/.test(r) ? [
|
|
31
|
+
parseInt(r[0] + r[0], 16),
|
|
32
|
+
parseInt(r[1] + r[1], 16),
|
|
33
|
+
parseInt(r[2] + r[2], 16)
|
|
34
|
+
] : /^[0-9a-f]{6}$/.test(r) ? [
|
|
35
|
+
parseInt(r.slice(0, 2), 16),
|
|
36
|
+
parseInt(r.slice(2, 4), 16),
|
|
37
|
+
parseInt(r.slice(4, 6), 16)
|
|
38
|
+
] : null;
|
|
39
|
+
}
|
|
40
|
+
const e = n.match(/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/);
|
|
41
|
+
return e ? [
|
|
42
|
+
m(Number(e[1])),
|
|
43
|
+
m(Number(e[2])),
|
|
44
|
+
m(Number(e[3]))
|
|
45
|
+
] : null;
|
|
46
|
+
}
|
|
47
|
+
function u(t, n, e) {
|
|
48
|
+
const r = Math.min(1, Math.max(0, e));
|
|
49
|
+
return [
|
|
50
|
+
Math.round(t[0] * r + n[0] * (1 - r)),
|
|
51
|
+
Math.round(t[1] * r + n[1] * (1 - r)),
|
|
52
|
+
Math.round(t[2] * r + n[2] * (1 - r))
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
function i(t) {
|
|
56
|
+
return `#${t.map((n) => m(n).toString(16).padStart(2, "0")).join("")}`;
|
|
57
|
+
}
|
|
58
|
+
function b([t, n, e]) {
|
|
59
|
+
const r = (s) => {
|
|
60
|
+
const a = s / 255;
|
|
61
|
+
return a <= 0.03928 ? a / 12.92 : Math.pow((a + 0.055) / 1.055, 2.4);
|
|
62
|
+
};
|
|
63
|
+
return 0.2126 * r(t) + 0.7152 * r(n) + 0.0722 * r(e);
|
|
64
|
+
}
|
|
65
|
+
function _(t) {
|
|
66
|
+
return b(t) > 0.5 ? "#1a1d21" : "#ffffff";
|
|
67
|
+
}
|
|
68
|
+
const g = [255, 255, 255], d = [0, 0, 0];
|
|
69
|
+
function T(t) {
|
|
70
|
+
const n = $(t);
|
|
71
|
+
if (!n) return null;
|
|
72
|
+
const e = b(n) > 0.5, r = i(e ? u(n, d, 0.85) : u(n, g, 0.8)), s = i(e ? u(n, d, 0.75) : u(n, d, 0.88));
|
|
73
|
+
return {
|
|
74
|
+
base: i(n),
|
|
75
|
+
hover: r,
|
|
76
|
+
active: s,
|
|
77
|
+
text: _(n),
|
|
78
|
+
wash: i(u(n, g, 0.1)),
|
|
79
|
+
edge: i(u(n, g, 0.5))
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function m(t) {
|
|
83
|
+
return Math.min(255, Math.max(0, Math.round(t)));
|
|
84
|
+
}
|
|
85
|
+
function G(t, n) {
|
|
86
|
+
const e = (t ?? "").trim();
|
|
87
|
+
if (!e) return "none";
|
|
88
|
+
if (e.startsWith("#")) return "symbol";
|
|
89
|
+
if (/\s/.test(e)) return "font-class";
|
|
90
|
+
const r = (n == null ? void 0 : n.prefix) ?? "gi-";
|
|
91
|
+
return r && e.length > r.length && e.startsWith(r) && /^[A-Za-z0-9_-]+$/.test(e) ? "iconfont" : e.includes("#") ? "symbol" : "class";
|
|
92
|
+
}
|
|
93
|
+
function K(t) {
|
|
94
|
+
return t.replace(/<script[\s\S]*?<\/script>/gi, "").replace(/<style[\s\S]*?<\/style>/gi, "").replace(/\son\w+\s*=\s*"[^"]*"/gi, "").replace(/\son\w+\s*=\s*'[^']*'/gi, "").replace(/\son\w+\s*=\s*[^\s>]+/gi, "").replace(/javascript:/gi, "").trim();
|
|
95
|
+
}
|
|
96
|
+
function L(t) {
|
|
97
|
+
if (!(t == null || t === ""))
|
|
98
|
+
return typeof t == "number" ? `${t}px` : t;
|
|
99
|
+
}
|
|
100
|
+
const O = ["large", "default", "small"], h = Symbol("gi-size"), v = Symbol("gi-global-config"), C = Symbol("gi-form-item");
|
|
101
|
+
function F(t) {
|
|
102
|
+
I(h, t);
|
|
103
|
+
}
|
|
104
|
+
function Y(t) {
|
|
105
|
+
const n = l(
|
|
106
|
+
h,
|
|
107
|
+
void 0
|
|
108
|
+
), e = l(
|
|
109
|
+
v,
|
|
110
|
+
void 0
|
|
111
|
+
);
|
|
112
|
+
return c(() => t.size ? t.size : n != null && n.value ? n.value : (e == null ? void 0 : e.value.size) || "default");
|
|
113
|
+
}
|
|
114
|
+
function B(t) {
|
|
115
|
+
I(v, t);
|
|
116
|
+
}
|
|
117
|
+
function R() {
|
|
118
|
+
const t = l(
|
|
119
|
+
v,
|
|
120
|
+
void 0
|
|
121
|
+
), n = c(() => (t == null ? void 0 : t.value) ?? {});
|
|
122
|
+
return {
|
|
123
|
+
config: n,
|
|
124
|
+
size: c(() => n.value.size),
|
|
125
|
+
zIndex: c(() => n.value.zIndex),
|
|
126
|
+
locale: c(() => n.value.locale)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function E(t, n = {}) {
|
|
130
|
+
if (typeof t != "string") return t;
|
|
131
|
+
let e = t;
|
|
132
|
+
if (n.trim && (e = e.trim()), n.number) {
|
|
133
|
+
const r = parseFloat(String(e));
|
|
134
|
+
if (!Number.isNaN(r)) return r;
|
|
135
|
+
}
|
|
136
|
+
return e;
|
|
137
|
+
}
|
|
138
|
+
function W(t, n, e, r = {}) {
|
|
139
|
+
const s = (f) => E(f, r.modifiers ?? {});
|
|
140
|
+
return { model: c({
|
|
141
|
+
get: () => t[n],
|
|
142
|
+
set: (f) => e(s(f))
|
|
143
|
+
}), normalize: s };
|
|
144
|
+
}
|
|
145
|
+
function J() {
|
|
146
|
+
const t = y(!1);
|
|
147
|
+
return {
|
|
148
|
+
isComposing: t,
|
|
149
|
+
onCompositionStart: () => {
|
|
150
|
+
t.value = !0;
|
|
151
|
+
},
|
|
152
|
+
onCompositionUpdate: () => {
|
|
153
|
+
t.value = !0;
|
|
154
|
+
},
|
|
155
|
+
onCompositionEnd: () => {
|
|
156
|
+
t.value = !1;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function U(t) {
|
|
161
|
+
I(C, t);
|
|
162
|
+
}
|
|
163
|
+
function V() {
|
|
164
|
+
return { formItem: l(
|
|
165
|
+
C,
|
|
166
|
+
void 0
|
|
167
|
+
) };
|
|
168
|
+
}
|
|
169
|
+
function H(t) {
|
|
170
|
+
if (typeof t != "string") return 0;
|
|
171
|
+
const n = Intl;
|
|
172
|
+
if (typeof n.Segmenter == "function") {
|
|
173
|
+
const e = new n.Segmenter(void 0, { granularity: "grapheme" });
|
|
174
|
+
let r = 0;
|
|
175
|
+
for (const s of e.segment(t)) r++;
|
|
176
|
+
return r;
|
|
177
|
+
}
|
|
178
|
+
return Array.from(t).length;
|
|
179
|
+
}
|
|
180
|
+
export {
|
|
181
|
+
N as AI_TARGET_REGISTRY_KEY,
|
|
182
|
+
C as FORM_ITEM_INJECTION_KEY,
|
|
183
|
+
v as GLOBAL_CONFIG_INJECTION_KEY,
|
|
184
|
+
h as SIZE_INJECTION_KEY,
|
|
185
|
+
E as applyModelModifiers,
|
|
186
|
+
O as componentSizes,
|
|
187
|
+
_ as contrastColor,
|
|
188
|
+
H as countGrapheme,
|
|
189
|
+
T as createColorScheme,
|
|
190
|
+
u as mixColor,
|
|
191
|
+
$ as parseColor,
|
|
192
|
+
U as provideFormItem,
|
|
193
|
+
B as provideGlobalConfig,
|
|
194
|
+
F as provideSize,
|
|
195
|
+
b as relativeLuminance,
|
|
196
|
+
G as resolveIconKind,
|
|
197
|
+
K as sanitizeSvg,
|
|
198
|
+
L as toCssSize,
|
|
199
|
+
i as toHex,
|
|
200
|
+
A as useAiTarget,
|
|
201
|
+
J as useComposition,
|
|
202
|
+
V as useFormItem,
|
|
203
|
+
R as useGlobalConfig,
|
|
204
|
+
w as useNamespace,
|
|
205
|
+
Y as useSize,
|
|
206
|
+
W as useVModel,
|
|
207
|
+
z as withInstall
|
|
208
|
+
};
|
package/dist/string.d.ts
ADDED
package/dist/svg.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** 图标形态判定与 SVG 安全清洗,供 GiIcon / GiButton 共用 */
|
|
2
|
+
export type IconKind = 'none' | 'symbol' | 'font-class' | 'iconfont' | 'class';
|
|
3
|
+
export interface ResolveIconOptions {
|
|
4
|
+
/** 内置图标库类名前缀,默认 `gi-` */
|
|
5
|
+
prefix?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 判定一个图标字符串该用哪种渲染方式:
|
|
9
|
+
* - `#icon-star` → symbol(当前文档内的 sprite)
|
|
10
|
+
* - `./sprite.svg#icon-star` → symbol(外部 sprite 文件)
|
|
11
|
+
* - `iconfont icon-x` → font-class(含空格,挂 class)
|
|
12
|
+
* - `gi-Globe` → iconfont(图标字体,前缀可配)
|
|
13
|
+
* - 其它单词 → class(挂任意 CSS 图标类,如 `el-icon-search`)
|
|
14
|
+
*
|
|
15
|
+
* 组件库不再维护手写 path 表,所有内置图标都来自 iconfont。
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveIconKind(value: string | undefined | null, options?: ResolveIconOptions): IconKind;
|
|
18
|
+
/**
|
|
19
|
+
* 清洗外部传入的 SVG 源码。
|
|
20
|
+
* 只做最小必要的剥离:脚本、事件属性、style 标签、javascript: 协议。
|
|
21
|
+
* 仍建议只传可信内容,组件库不做完整 sanitizer。
|
|
22
|
+
*/
|
|
23
|
+
export declare function sanitizeSvg(source: string): string;
|
|
24
|
+
/** 把 number 尺寸转 px,string 原样返回 */
|
|
25
|
+
export declare function toCssSize(size: number | string | undefined): string | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** AI 目标注册表注入 key(AI 能力层提供;不存在时组件自动 no-op) */
|
|
2
|
+
export declare const AI_TARGET_REGISTRY_KEY: unique symbol;
|
|
3
|
+
export interface AiTargetHandle {
|
|
4
|
+
/** 语义码,优先于 DOM 选择器 */
|
|
5
|
+
code?: string;
|
|
6
|
+
entity?: string;
|
|
7
|
+
field?: string;
|
|
8
|
+
/** 读取当前值 */
|
|
9
|
+
getValue?: () => unknown;
|
|
10
|
+
/** 写入值(必须走组件原生 setter) */
|
|
11
|
+
setValue?: (value: any) => void;
|
|
12
|
+
focus?: () => void;
|
|
13
|
+
/** 执行语义命令,返回结果交给 AI 能力层 */
|
|
14
|
+
execute?: (command: string, payload?: Record<string, unknown>) => unknown;
|
|
15
|
+
/** 触发无参数动作(点击、展开等) */
|
|
16
|
+
trigger?: (action?: string) => void;
|
|
17
|
+
/** 读取能力描述 */
|
|
18
|
+
getSchema?: () => unknown;
|
|
19
|
+
/** 读取当前记录摘要,用于删除确认 */
|
|
20
|
+
getRecords?: (action?: {
|
|
21
|
+
type?: string;
|
|
22
|
+
target?: string;
|
|
23
|
+
command?: string;
|
|
24
|
+
payload?: Record<string, unknown>;
|
|
25
|
+
}) => Record<string, unknown>[];
|
|
26
|
+
isEnabled?: () => boolean;
|
|
27
|
+
isVisible?: () => boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface AiTargetRegistry {
|
|
30
|
+
register: (handle: AiTargetHandle) => void;
|
|
31
|
+
unregister: (handle: AiTargetHandle) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 注册 AI 语义目标。
|
|
35
|
+
* 未挂载 AI 能力层时完全 no-op,保证组件库可独立使用。
|
|
36
|
+
*/
|
|
37
|
+
export declare function useAiTarget(handle: AiTargetHandle): {
|
|
38
|
+
registered: boolean;
|
|
39
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BEM 命名空间,默认前缀 gi
|
|
3
|
+
* b(): gi-button
|
|
4
|
+
* be(): gi-button__text
|
|
5
|
+
* bm(): gi-button--primary
|
|
6
|
+
* is(): is-disabled
|
|
7
|
+
*/
|
|
8
|
+
export declare function useNamespace(block: string, namespace?: string): {
|
|
9
|
+
namespace: string;
|
|
10
|
+
b: () => string;
|
|
11
|
+
be: (element: string) => string;
|
|
12
|
+
bm: (modifier?: string) => string;
|
|
13
|
+
is: (state: string, when?: boolean) => string;
|
|
14
|
+
cssVar: (name: string) => string;
|
|
15
|
+
bmAll: (...modifiers: (string | false | undefined)[]) => string[];
|
|
16
|
+
};
|
|
17
|
+
export type Namespace = ReturnType<typeof useNamespace>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gi-base/utils",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "GI Base shared utilities",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/index.mjs",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"vue": "^3.4.0"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"registry": "https://registry.npmjs.org/"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/gi-base/gi-ui.git",
|
|
29
|
+
"directory": "packages/utils"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "vite build",
|
|
33
|
+
"test": "vitest run --passWithNoTests",
|
|
34
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
35
|
+
}
|
|
6
36
|
}
|