@gzmjs/ui-basic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui-basic.d.ts +370 -0
- package/dist/ui-basic.es.js +1373 -0
- package/dist/ui-basic.es.js.map +1 -0
- package/package.json +23 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
export declare const allThemes: {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly label: string;
|
|
4
|
+
}[];
|
|
5
|
+
|
|
6
|
+
export declare type AttachBorder = typeof borders[number];
|
|
7
|
+
|
|
8
|
+
export declare const attachBorderAttributeName = "gzm-attach-border";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 对于每一个有 mutableAttributes 的组件,都必须实现下面这个类型。
|
|
12
|
+
* 其中 T 是 typeof mutableAttributes[number]
|
|
13
|
+
* 如果同时也有 copyAttributes,那么需要排除 copyAttributes 中的属性:
|
|
14
|
+
* Exclude<typeof mutableAttributes[number], keyof typeof copyAttributes>。
|
|
15
|
+
* 050-tree.ts 就是这么做到。
|
|
16
|
+
*/
|
|
17
|
+
export declare type AttributeHandlers<T extends string> = {
|
|
18
|
+
[K in T as GetAttributeSetHandlerName<K>]: <P extends string>(nv: P | null, ov: P | null) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export declare class Badge extends HTMLElement implements ELE.AttributeHandlers<typeof mutableAttributes[number]> {
|
|
22
|
+
constructor();
|
|
23
|
+
readonly shadowRoot: ShadowRoot;
|
|
24
|
+
_badge_set(badge: string | null): void;
|
|
25
|
+
_corner_set(): void;
|
|
26
|
+
accessor badge: string | undefined;
|
|
27
|
+
accessor corner: boolean | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare const badgeTagName = "GZM-BADGE";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 从 dist/assets/index.css 中提取的样式。
|
|
34
|
+
* 找到其中的 @layer base,然后开始做减法。
|
|
35
|
+
* 1 - 去掉不用的伪类,如 ::file-selector-button, ::-webkit-*。
|
|
36
|
+
* 2 - 去掉具体的 tag 定义,如 hr, h1-6, button, 因为多半用不到。
|
|
37
|
+
*/
|
|
38
|
+
export declare const baseStyle: CSSStyleSheet;
|
|
39
|
+
|
|
40
|
+
declare type BindableTextProxy = {
|
|
41
|
+
[bindHtmlElement]: <P>(this: P, $ele: HTMLElement) => P;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
declare const bindHtmlElement = "bindHtmlElement";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @boolAttr
|
|
48
|
+
* accessor propName: boolean = false;
|
|
49
|
+
* 或者
|
|
50
|
+
* @boolAttr
|
|
51
|
+
* accessor propName: boolean | undefined;
|
|
52
|
+
*/
|
|
53
|
+
export declare function boolAttr<This extends HTMLElement, V extends BoolType>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
|
|
54
|
+
get(this: This): V;
|
|
55
|
+
set(this: This, value: V): void;
|
|
56
|
+
init(this: This, value: V): V;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
declare type BoolOrUndef = boolean | undefined;
|
|
60
|
+
|
|
61
|
+
declare type BoolType = boolean | BoolOrUndef;
|
|
62
|
+
|
|
63
|
+
export declare const borders: readonly ["bottom", "top", "right", "left"];
|
|
64
|
+
|
|
65
|
+
export declare class CenterHelper {
|
|
66
|
+
#private;
|
|
67
|
+
constructor($tooltip: HTMLElement & TransitionPopup, $attachTo: HTMLElement, attachBorder: AttachBorder);
|
|
68
|
+
$tt: HTMLElement & TransitionPopup;
|
|
69
|
+
$attachTo: HTMLElement;
|
|
70
|
+
realBorder: AttachBorder;
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
marginLeft: string;
|
|
74
|
+
marginTop: string;
|
|
75
|
+
ttWidth: number;
|
|
76
|
+
ttHeight: number;
|
|
77
|
+
pos($tt?: HTMLElement & TransitionPopup): void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export declare class CloseBtn extends HTMLElement implements ELE.AttributeHandlers<typeof mutableAttributes_2[number]> {
|
|
81
|
+
constructor();
|
|
82
|
+
readonly shadowRoot: ShadowRoot;
|
|
83
|
+
_corner_set(): void;
|
|
84
|
+
accessor corner: boolean | undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export declare const closeTagName = "GZM-CLOSE-BTN";
|
|
88
|
+
|
|
89
|
+
export declare type Corner = typeof xy[keyof typeof xy];
|
|
90
|
+
|
|
91
|
+
export declare class CornerHelper {
|
|
92
|
+
#private;
|
|
93
|
+
constructor($popup: HTMLElement, popupCorner: Corner, $attachTo: HTMLElement, attachCorner: Corner);
|
|
94
|
+
readonly $popup: HTMLElement;
|
|
95
|
+
readonly $attachTo: HTMLElement;
|
|
96
|
+
pos(): void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export declare function createStyleSheet(style: Style): CSSStyleSheet;
|
|
100
|
+
|
|
101
|
+
export declare function createText<T extends Record<string, unknown>[]>(this: unknown, ...txts: T): JoinedText<T> & BindableTextProxy;
|
|
102
|
+
|
|
103
|
+
export declare function createTxtBtn(txt: string): HTMLButtonElement;
|
|
104
|
+
|
|
105
|
+
declare type CustomElement = {
|
|
106
|
+
tagName: string;
|
|
107
|
+
style?: CSSStyleSheet;
|
|
108
|
+
mutableAttributes?: readonly string[];
|
|
109
|
+
/**
|
|
110
|
+
* 必须在 mutableAttributes 不为空时才有效。
|
|
111
|
+
* key 是 mutableAttributes 中的一员,value 是组件的属性名称(数组)
|
|
112
|
+
*/
|
|
113
|
+
copyAttributes?: Record<string, string | string[]>;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 防抖
|
|
118
|
+
* @param func
|
|
119
|
+
* @param wait
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
export declare function debounce<T extends (...args: unknown[]) => unknown>(func: T, wait?: number): (...args: Parameters<T>) => void;
|
|
123
|
+
|
|
124
|
+
export declare function defineElement(ele: CustomElement): (constructor: CustomElementConstructor, ctx: ClassDecoratorContext) => void;
|
|
125
|
+
|
|
126
|
+
declare namespace ELE {
|
|
127
|
+
export {
|
|
128
|
+
defineElement,
|
|
129
|
+
AttributeHandlers
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 生成一个随机 ID 字符串,极大概率唯一
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
export declare function generateId(): string;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 模拟 getAttributeSetHandlerName(name) 的逻辑
|
|
141
|
+
*/
|
|
142
|
+
declare type GetAttributeSetHandlerName<Name extends string> = `_${ReplaceAll<Name, '-', '_'>}_set`;
|
|
143
|
+
|
|
144
|
+
export declare function getCurrentTheme(): string;
|
|
145
|
+
|
|
146
|
+
export declare function getElementRules(tagName: string, ...ruleNames: string[]): Rules;
|
|
147
|
+
|
|
148
|
+
export declare function getSnakeCaseName(propName: string): string;
|
|
149
|
+
|
|
150
|
+
declare type GlobalTextProxy = TextProxy<typeof zh>;
|
|
151
|
+
|
|
152
|
+
export declare const globalTexts: {
|
|
153
|
+
zh: {
|
|
154
|
+
readonly close: "关闭";
|
|
155
|
+
readonly true: "✔️";
|
|
156
|
+
readonly false: "❌";
|
|
157
|
+
readonly undefined: "未定义";
|
|
158
|
+
readonly default: "默认";
|
|
159
|
+
readonly valueMissing: "请填写此字段。";
|
|
160
|
+
readonly count: "计数";
|
|
161
|
+
readonly min: "最小";
|
|
162
|
+
readonly max: "最大";
|
|
163
|
+
readonly sum: "合计";
|
|
164
|
+
readonly avg: "平均";
|
|
165
|
+
readonly hide: "隐藏";
|
|
166
|
+
readonly del: "删除";
|
|
167
|
+
readonly asc: "升序";
|
|
168
|
+
readonly desc: "降序";
|
|
169
|
+
readonly ok: "确定";
|
|
170
|
+
readonly cancel: "取消";
|
|
171
|
+
readonly waiting: "正在处理中,请稍候...";
|
|
172
|
+
readonly confirming: "请确认:{0} ?";
|
|
173
|
+
readonly completed: "已完成";
|
|
174
|
+
readonly error: "错误";
|
|
175
|
+
readonly attention: "注意";
|
|
176
|
+
readonly noMenuSet: "未设置菜单!?";
|
|
177
|
+
readonly readonly: "只读";
|
|
178
|
+
};
|
|
179
|
+
en: {
|
|
180
|
+
readonly close: "关闭";
|
|
181
|
+
readonly true: "✔️";
|
|
182
|
+
readonly false: "❌";
|
|
183
|
+
readonly undefined: "未定义";
|
|
184
|
+
readonly default: "默认";
|
|
185
|
+
readonly valueMissing: "请填写此字段。";
|
|
186
|
+
readonly count: "计数";
|
|
187
|
+
readonly min: "最小";
|
|
188
|
+
readonly max: "最大";
|
|
189
|
+
readonly sum: "合计";
|
|
190
|
+
readonly avg: "平均";
|
|
191
|
+
readonly hide: "隐藏";
|
|
192
|
+
readonly del: "删除";
|
|
193
|
+
readonly asc: "升序";
|
|
194
|
+
readonly desc: "降序";
|
|
195
|
+
readonly ok: "确定";
|
|
196
|
+
readonly cancel: "取消";
|
|
197
|
+
readonly waiting: "正在处理中,请稍候...";
|
|
198
|
+
readonly confirming: "请确认:{0} ?";
|
|
199
|
+
readonly completed: "已完成";
|
|
200
|
+
readonly error: "错误";
|
|
201
|
+
readonly attention: "注意";
|
|
202
|
+
readonly noMenuSet: "未设置菜单!?";
|
|
203
|
+
readonly readonly: "只读";
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export declare const GT: GlobalTextProxy;
|
|
208
|
+
|
|
209
|
+
export declare const gzmFrame = "\n background: var(--gzm-content-background);\n color: var(--gzm-content-txt-color);\n border-radius: 0.5rem;\n border: var(--gzm-btn-border);\n padding: 0.5rem;\n";
|
|
210
|
+
|
|
211
|
+
export declare const gzmHeader = "\n background: var(--gzm-header-background);\n border: var(--gzm-header-border);\n color: var(--gzm-header-txt-color);\n";
|
|
212
|
+
|
|
213
|
+
export declare const htmlThemeAttr = "gzm-theme";
|
|
214
|
+
|
|
215
|
+
export declare class Icon extends HTMLElement implements ELE.AttributeHandlers<typeof mutableAttributes_3[number]> {
|
|
216
|
+
#private;
|
|
217
|
+
constructor();
|
|
218
|
+
readonly shadowRoot: ShadowRoot;
|
|
219
|
+
setImg(icon: string): boolean;
|
|
220
|
+
setSvg(icon: string): boolean;
|
|
221
|
+
_icon_set(icon: string | null): void;
|
|
222
|
+
accessor icon: string | undefined;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export declare const iconCache: {
|
|
226
|
+
[key: string]: string | HTMLImageElement;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export declare const iconTagName = "GZM-ICON";
|
|
230
|
+
|
|
231
|
+
declare type IncludesCurlyZero<T extends string> = T extends `${string}{0}${string}` ? (...args: unknown[]) => string : string;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @intAttr
|
|
235
|
+
* accessor propName: number | undefined;
|
|
236
|
+
* 或者
|
|
237
|
+
* @intAttr
|
|
238
|
+
* accessor propName: number = 12345;
|
|
239
|
+
*/
|
|
240
|
+
export declare function intAttr<This extends HTMLElement, V extends NumType>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
|
|
241
|
+
get(this: This): V;
|
|
242
|
+
set(this: This, value: V): void;
|
|
243
|
+
init(this: This, value: V): V;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export declare function isLeftCorner(c: Corner): boolean;
|
|
247
|
+
|
|
248
|
+
export declare function isTopCorner(c: Corner): boolean;
|
|
249
|
+
|
|
250
|
+
export declare function isTxtBtn($btn: HTMLElement): boolean;
|
|
251
|
+
|
|
252
|
+
declare type JoinedText<T extends Record<string, unknown>[]> = T extends [Record<string, infer First>, ...infer Rest] ? TextProxy<First> & JoinedText<Rest extends Record<string, unknown>[] ? Rest : []> : unknown;
|
|
253
|
+
|
|
254
|
+
export declare function makeCorner(isLeft: boolean, isTop: boolean): Corner;
|
|
255
|
+
|
|
256
|
+
declare const mutableAttributes: readonly ["badge", "corner"];
|
|
257
|
+
|
|
258
|
+
declare const mutableAttributes_2: readonly ["corner"];
|
|
259
|
+
|
|
260
|
+
declare const mutableAttributes_3: readonly ["icon"];
|
|
261
|
+
|
|
262
|
+
declare type NumOrUndef = number | undefined;
|
|
263
|
+
|
|
264
|
+
declare type NumType = number | NumOrUndef;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 模拟 string.replaceAll() 方法
|
|
268
|
+
*/
|
|
269
|
+
declare type ReplaceAll<Str extends string, From extends string, To extends string> = From extends "" ? Str : Str extends `${infer Prefix}${From}${infer Suffix}` ? `${Prefix}${To}${ReplaceAll<Suffix, From, To>}` : Str;
|
|
270
|
+
|
|
271
|
+
export declare type Rules = {
|
|
272
|
+
[prop: string]: string;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export declare function saAttr<This extends HTMLElement, V extends StrArrayType>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
|
|
276
|
+
get(this: This): V;
|
|
277
|
+
set(this: This, value: V): void;
|
|
278
|
+
init(this: This, value: V): V;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
export declare function setCurrentTheme(themeName: string): boolean;
|
|
282
|
+
|
|
283
|
+
declare type StrArrayOrUndef = string[] | undefined;
|
|
284
|
+
|
|
285
|
+
declare type StrArrayType = string[] | StrArrayOrUndef;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 基于:
|
|
289
|
+
* 1 - Atribute 属性(A属性)的特性,具体请看 /try/WC/attr.html
|
|
290
|
+
* 2 - auto-accessor 装饰器的特性,具体请看 /try/ts/auto-accessor.ts
|
|
291
|
+
*
|
|
292
|
+
* 对于所有的 auto-accessor 装饰器生成的属性,属性的类型与默认值必须按如下定义:
|
|
293
|
+
* 1 - 目前支持三种类型: 整数、布尔 和 字符串。其中字符串是万金油,因为 ts 中经常用字符串来定义联合类型,如 'a' | 'b' 等。
|
|
294
|
+
* 2 - 每种数据类型都支持两种方式:
|
|
295
|
+
* a - 与 undefined 联合,默认值是 void 0
|
|
296
|
+
* b - 不与 undefined 联合,编译器要求必须初始化,那么不要在构造函数中初始化。因为构造函数中调用的是 set() 会导致设置 A 属性,导致 createElement() 异常。
|
|
297
|
+
* 3 - 开发组件的时候 P属性 优先使用与 undefined 的联合类型,也就不需要默认值。可以将默认值写在 get() 时,如 this.propName ?? default。
|
|
298
|
+
*/
|
|
299
|
+
/**
|
|
300
|
+
* @strAttr
|
|
301
|
+
* accessor propName: V = '';
|
|
302
|
+
* 或者
|
|
303
|
+
* @strAttr
|
|
304
|
+
* accessor propName: V | undefined;
|
|
305
|
+
*/
|
|
306
|
+
export declare function strAttr<This extends HTMLElement, V>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
|
|
307
|
+
get(this: This): V;
|
|
308
|
+
set(this: This, value: V): void;
|
|
309
|
+
init(this: This, value: V): V;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export declare type Style = {
|
|
313
|
+
[selector: string]: Rules | string;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
declare type TextProxy<T> = {
|
|
317
|
+
[K in keyof T]: T[K] extends string ? IncludesCurlyZero<T[K]> : never;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export declare interface TransitionPopup {
|
|
321
|
+
doTransition: boolean;
|
|
322
|
+
beforeOpenTransition?: () => void;
|
|
323
|
+
afterOpenTransition?: () => void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export declare const utilityStyle: CSSStyleSheet;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 因为 tsconfig.json erasableSyntaxOnly 所以不能使用枚举。
|
|
330
|
+
* xy
|
|
331
|
+
* 00 - 左上角 = 0
|
|
332
|
+
* 01 - 左下角 = 1
|
|
333
|
+
* 10 - 右上角 = 10
|
|
334
|
+
* 11 - 右下角 = 11
|
|
335
|
+
*/
|
|
336
|
+
export declare const xy: {
|
|
337
|
+
readonly leftTop: 0;
|
|
338
|
+
readonly leftBottom: 1;
|
|
339
|
+
readonly rightTop: 10;
|
|
340
|
+
readonly rightBottom: 11;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
declare const zh: {
|
|
344
|
+
readonly close: "关闭";
|
|
345
|
+
readonly true: "✔️";
|
|
346
|
+
readonly false: "❌";
|
|
347
|
+
readonly undefined: "未定义";
|
|
348
|
+
readonly default: "默认";
|
|
349
|
+
readonly valueMissing: "请填写此字段。";
|
|
350
|
+
readonly count: "计数";
|
|
351
|
+
readonly min: "最小";
|
|
352
|
+
readonly max: "最大";
|
|
353
|
+
readonly sum: "合计";
|
|
354
|
+
readonly avg: "平均";
|
|
355
|
+
readonly hide: "隐藏";
|
|
356
|
+
readonly del: "删除";
|
|
357
|
+
readonly asc: "升序";
|
|
358
|
+
readonly desc: "降序";
|
|
359
|
+
readonly ok: "确定";
|
|
360
|
+
readonly cancel: "取消";
|
|
361
|
+
readonly waiting: "正在处理中,请稍候...";
|
|
362
|
+
readonly confirming: "请确认:{0} ?";
|
|
363
|
+
readonly completed: "已完成";
|
|
364
|
+
readonly error: "错误";
|
|
365
|
+
readonly attention: "注意";
|
|
366
|
+
readonly noMenuSet: "未设置菜单!?";
|
|
367
|
+
readonly readonly: "只读";
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
export { }
|