@gzmjs/ui-basic 0.1.0 → 0.3.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.
@@ -0,0 +1,61 @@
1
+ export declare function getSnakeCaseName(propName: string): string;
2
+ /**
3
+ * 基于:
4
+ * 1 - Atribute 属性(A属性)的特性,具体请看 /try/WC/attr.html
5
+ * 2 - auto-accessor 装饰器的特性,具体请看 /try/ts/auto-accessor.ts
6
+ *
7
+ * 对于所有的 auto-accessor 装饰器生成的属性,属性的类型与默认值必须按如下定义:
8
+ * 1 - 目前支持三种类型: 整数、布尔 和 字符串。其中字符串是万金油,因为 ts 中经常用字符串来定义联合类型,如 'a' | 'b' 等。
9
+ * 2 - 每种数据类型都支持两种方式:
10
+ * a - 与 undefined 联合,默认值是 void 0
11
+ * b - 不与 undefined 联合,编译器要求必须初始化,那么不要在构造函数中初始化。因为构造函数中调用的是 set() 会导致设置 A 属性,导致 createElement() 异常。
12
+ * 3 - 开发组件的时候 P属性 优先使用与 undefined 的联合类型,也就不需要默认值。可以将默认值写在 get() 时,如 this.propName ?? default。
13
+ */
14
+ /**
15
+ * @strAttr
16
+ * accessor propName: V = '';
17
+ * 或者
18
+ * @strAttr
19
+ * accessor propName: V | undefined;
20
+ */
21
+ export declare function strAttr<This extends HTMLElement, V>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
22
+ get(this: This): V;
23
+ set(this: This, value: V): void;
24
+ init(this: This, value: V): V;
25
+ };
26
+ type BoolOrUndef = boolean | undefined;
27
+ type BoolType = boolean | BoolOrUndef;
28
+ /**
29
+ * @boolAttr
30
+ * accessor propName: boolean = false;
31
+ * 或者
32
+ * @boolAttr
33
+ * accessor propName: boolean | undefined;
34
+ */
35
+ export declare function boolAttr<This extends HTMLElement, V extends BoolType>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
36
+ get(this: This): V;
37
+ set(this: This, value: V): void;
38
+ init(this: This, value: V): V;
39
+ };
40
+ type NumOrUndef = number | undefined;
41
+ type NumType = number | NumOrUndef;
42
+ /**
43
+ * @intAttr
44
+ * accessor propName: number | undefined;
45
+ * 或者
46
+ * @intAttr
47
+ * accessor propName: number = 12345;
48
+ */
49
+ export declare function intAttr<This extends HTMLElement, V extends NumType>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
50
+ get(this: This): V;
51
+ set(this: This, value: V): void;
52
+ init(this: This, value: V): V;
53
+ };
54
+ type StrArrayOrUndef = string[] | undefined;
55
+ type StrArrayType = string[] | StrArrayOrUndef;
56
+ export declare function saAttr<This extends HTMLElement, V extends StrArrayType>(_: ClassAccessorDecoratorTarget<This, V>, context: ClassAccessorDecoratorContext<This, V>): {
57
+ get(this: This): V;
58
+ set(this: This, value: V): void;
59
+ init(this: This, value: V): V;
60
+ };
61
+ export {};
@@ -0,0 +1,22 @@
1
+ export declare const borders: readonly ["bottom", "top", "right", "left"];
2
+ export type AttachBorder = typeof borders[number];
3
+ export declare const attachBorderAttributeName = "gzm-attach-border";
4
+ export interface TransitionPopup {
5
+ doTransition: boolean;
6
+ beforeOpenTransition?: () => void;
7
+ afterOpenTransition?: () => void;
8
+ }
9
+ export declare class CenterHelper {
10
+ #private;
11
+ constructor($tooltip: HTMLElement & TransitionPopup, $attachTo: HTMLElement, attachBorder: AttachBorder);
12
+ $tt: HTMLElement & TransitionPopup;
13
+ $attachTo: HTMLElement;
14
+ realBorder: AttachBorder;
15
+ x: number;
16
+ y: number;
17
+ marginLeft: string;
18
+ marginTop: string;
19
+ ttWidth: number;
20
+ ttHeight: number;
21
+ pos($tt?: HTMLElement & TransitionPopup): void;
22
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 因为 tsconfig.json erasableSyntaxOnly 所以不能使用枚举。
3
+ * xy
4
+ * 00 - 左上角 = 0
5
+ * 01 - 左下角 = 1
6
+ * 10 - 右上角 = 10
7
+ * 11 - 右下角 = 11
8
+ */
9
+ export declare const xy: {
10
+ readonly leftTop: 0;
11
+ readonly leftBottom: 1;
12
+ readonly rightTop: 10;
13
+ readonly rightBottom: 11;
14
+ };
15
+ export type Corner = typeof xy[keyof typeof xy];
16
+ export declare function isLeftCorner(c: Corner): boolean;
17
+ export declare function isTopCorner(c: Corner): boolean;
18
+ export declare function makeCorner(isLeft: boolean, isTop: boolean): Corner;
19
+ export declare class CornerHelper {
20
+ #private;
21
+ constructor($popup: HTMLElement, popupCorner: Corner, $attachTo: HTMLElement, attachCorner: Corner);
22
+ readonly $popup: HTMLElement;
23
+ readonly $attachTo: HTMLElement;
24
+ pos(): void;
25
+ }
@@ -0,0 +1,30 @@
1
+ type CustomElement = {
2
+ tagName: string;
3
+ style?: CSSStyleSheet;
4
+ mutableAttributes?: readonly string[];
5
+ /**
6
+ * 必须在 mutableAttributes 不为空时才有效。
7
+ * key 是 mutableAttributes 中的一员,value 是组件的属性名称(数组)
8
+ */
9
+ copyAttributes?: Record<string, string | string[]>;
10
+ };
11
+ export declare function defineElement(ele: CustomElement): (constructor: CustomElementConstructor, ctx: ClassDecoratorContext) => void;
12
+ /**
13
+ * 模拟 string.replaceAll() 方法
14
+ */
15
+ 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;
16
+ /**
17
+ * 模拟 getAttributeSetHandlerName(name) 的逻辑
18
+ */
19
+ type GetAttributeSetHandlerName<Name extends string> = `_${ReplaceAll<Name, '-', '_'>}_set`;
20
+ /**
21
+ * 对于每一个有 mutableAttributes 的组件,都必须实现下面这个类型。
22
+ * 其中 T 是 typeof mutableAttributes[number]
23
+ * 如果同时也有 copyAttributes,那么需要排除 copyAttributes 中的属性:
24
+ * Exclude<typeof mutableAttributes[number], keyof typeof copyAttributes>。
25
+ * 050-tree.ts 就是这么做到。
26
+ */
27
+ export type AttributeHandlers<T extends string> = {
28
+ [K in T as GetAttributeSetHandlerName<K>]: <P extends string>(nv: P | null, ov: P | null) => void;
29
+ };
30
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 防抖
3
+ * @param func
4
+ * @param wait
5
+ * @returns
6
+ */
7
+ export declare function debounce<T extends (...args: unknown[]) => unknown>(func: T, wait?: number): (...args: Parameters<T>) => void;
8
+ /**
9
+ * 生成一个随机 ID 字符串,极大概率唯一
10
+ * @returns
11
+ */
12
+ export declare function generateId(): string;
@@ -0,0 +1,93 @@
1
+ declare const zh: {
2
+ readonly close: "关闭";
3
+ readonly true: "✔️";
4
+ readonly false: "❌";
5
+ readonly undefined: "未定义";
6
+ readonly default: "默认";
7
+ readonly valueMissing: "请填写此字段。";
8
+ readonly count: "计数";
9
+ readonly min: "最小";
10
+ readonly max: "最大";
11
+ readonly sum: "合计";
12
+ readonly avg: "平均";
13
+ readonly hide: "隐藏";
14
+ readonly del: "删除";
15
+ readonly asc: "升序";
16
+ readonly desc: "降序";
17
+ readonly ok: "确定";
18
+ readonly cancel: "取消";
19
+ readonly waiting: "正在处理中,请稍候...";
20
+ readonly confirming: "请确认:{0} ?";
21
+ readonly completed: "已完成";
22
+ readonly error: "错误";
23
+ readonly attention: "注意";
24
+ readonly noMenuSet: "未设置菜单!?";
25
+ readonly readonly: "只读";
26
+ };
27
+ export declare const globalTexts: {
28
+ zh: {
29
+ readonly close: "关闭";
30
+ readonly true: "✔️";
31
+ readonly false: "❌";
32
+ readonly undefined: "未定义";
33
+ readonly default: "默认";
34
+ readonly valueMissing: "请填写此字段。";
35
+ readonly count: "计数";
36
+ readonly min: "最小";
37
+ readonly max: "最大";
38
+ readonly sum: "合计";
39
+ readonly avg: "平均";
40
+ readonly hide: "隐藏";
41
+ readonly del: "删除";
42
+ readonly asc: "升序";
43
+ readonly desc: "降序";
44
+ readonly ok: "确定";
45
+ readonly cancel: "取消";
46
+ readonly waiting: "正在处理中,请稍候...";
47
+ readonly confirming: "请确认:{0} ?";
48
+ readonly completed: "已完成";
49
+ readonly error: "错误";
50
+ readonly attention: "注意";
51
+ readonly noMenuSet: "未设置菜单!?";
52
+ readonly readonly: "只读";
53
+ };
54
+ en: {
55
+ readonly close: "关闭";
56
+ readonly true: "✔️";
57
+ readonly false: "❌";
58
+ readonly undefined: "未定义";
59
+ readonly default: "默认";
60
+ readonly valueMissing: "请填写此字段。";
61
+ readonly count: "计数";
62
+ readonly min: "最小";
63
+ readonly max: "最大";
64
+ readonly sum: "合计";
65
+ readonly avg: "平均";
66
+ readonly hide: "隐藏";
67
+ readonly del: "删除";
68
+ readonly asc: "升序";
69
+ readonly desc: "降序";
70
+ readonly ok: "确定";
71
+ readonly cancel: "取消";
72
+ readonly waiting: "正在处理中,请稍候...";
73
+ readonly confirming: "请确认:{0} ?";
74
+ readonly completed: "已完成";
75
+ readonly error: "错误";
76
+ readonly attention: "注意";
77
+ readonly noMenuSet: "未设置菜单!?";
78
+ readonly readonly: "只读";
79
+ };
80
+ };
81
+ declare const bindHtmlElement = "bindHtmlElement";
82
+ type BindableTextProxy = {
83
+ [bindHtmlElement]: <P>(this: P, $ele: HTMLElement) => P;
84
+ };
85
+ type IncludesCurlyZero<T extends string> = T extends `${string}{0}${string}` ? (...args: unknown[]) => string : string;
86
+ type TextProxy<T> = {
87
+ [K in keyof T]: T[K] extends string ? IncludesCurlyZero<T[K]> : never;
88
+ };
89
+ type GlobalTextProxy = TextProxy<typeof zh>;
90
+ 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;
91
+ export declare function createText<T extends Record<string, unknown>[]>(this: unknown, ...txts: T): JoinedText<T> & BindableTextProxy;
92
+ export declare const GT: GlobalTextProxy;
93
+ export {};
@@ -0,0 +1,27 @@
1
+ export type Rules = {
2
+ [prop: string]: string;
3
+ };
4
+ export type Style = {
5
+ [selector: string]: Rules | string;
6
+ };
7
+ export declare function createStyleSheet(style: Style): CSSStyleSheet;
8
+ export declare function getElementRules(tagName: string, ...ruleNames: string[]): Rules;
9
+ /**
10
+ * 主要是字体的设置,应该作为网页 reset 的一部分。
11
+ * 不设置 :host 的字体,具体请看 style-font.md
12
+ * 因为此项目开发的是组件,所以用不到。
13
+ *
14
+ * 以下内容是通过 tailwind.css 获得,具体方法;
15
+ * 访问:/try/tailwind/test.html,在浏览器开发工具的源代码选中 /src/style.css
16
+ */ /**
17
+ * 从 dist/assets/index.css 中提取的样式。
18
+ * 找到其中的 @layer base,然后开始做减法。
19
+ * 1 - 去掉不用的伪类,如 ::file-selector-button, ::-webkit-*。
20
+ * 2 - 去掉具体的 tag 定义,如 hr, h1-6, button, 因为多半用不到。
21
+ */
22
+ export declare const baseStyle: CSSStyleSheet;
23
+ export declare const gzmHeader = "\n background: var(--gzm-header-background);\n border: var(--gzm-header-border);\n color: var(--gzm-header-txt-color);\n";
24
+ 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";
25
+ export declare const utilityStyle: CSSStyleSheet;
26
+ export declare function createTxtBtn(txt: string): HTMLButtonElement;
27
+ export declare function isTxtBtn($btn: HTMLElement): boolean;
@@ -0,0 +1,7 @@
1
+ export declare const htmlThemeAttr = "gzm-theme";
2
+ export declare const allThemes: {
3
+ readonly name: string;
4
+ readonly label: string;
5
+ }[];
6
+ export declare function getCurrentTheme(): string;
7
+ export declare function setCurrentTheme(themeName: string): boolean;
@@ -0,0 +1,17 @@
1
+ import * as ELE from '../000-helper/element';
2
+ export declare const tagName = "GZM-BADGE";
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ [tagName]: Badge;
6
+ }
7
+ }
8
+ declare const mutableAttributes: readonly ["badge", "corner"];
9
+ export declare class Badge extends HTMLElement implements ELE.AttributeHandlers<typeof mutableAttributes[number]> {
10
+ constructor();
11
+ readonly shadowRoot: ShadowRoot;
12
+ _badge_set(badge: string | null): void;
13
+ _corner_set(): void;
14
+ accessor badge: string | undefined;
15
+ accessor corner: boolean | undefined;
16
+ }
17
+ export {};
@@ -0,0 +1,15 @@
1
+ import * as ELE from '../000-helper/element';
2
+ export declare const tagName = "GZM-CLOSE-BTN";
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ [tagName]: CloseBtn;
6
+ }
7
+ }
8
+ declare const mutableAttributes: readonly ["corner"];
9
+ export declare class CloseBtn extends HTMLElement implements ELE.AttributeHandlers<typeof mutableAttributes[number]> {
10
+ constructor();
11
+ readonly shadowRoot: ShadowRoot;
12
+ _corner_set(): void;
13
+ accessor corner: boolean | undefined;
14
+ }
15
+ export {};
@@ -0,0 +1,18 @@
1
+ import * as ELE from '../000-helper/element';
2
+ export declare const tagName = "GZM-ICON";
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ [tagName]: Icon;
6
+ }
7
+ }
8
+ declare const mutableAttributes: readonly ["icon"];
9
+ export declare class Icon extends HTMLElement implements ELE.AttributeHandlers<typeof mutableAttributes[number]> {
10
+ #private;
11
+ constructor();
12
+ readonly shadowRoot: ShadowRoot;
13
+ setImg(icon: string): boolean;
14
+ setSvg(icon: string): boolean;
15
+ _icon_set(icon: string | null): void;
16
+ accessor icon: string | undefined;
17
+ }
18
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const iconCache: {
2
+ [key: string]: string | HTMLImageElement;
3
+ };
@@ -0,0 +1,24 @@
1
+ import * as ELE from '../000-helper/element';
2
+ export declare const tagName = "GZM-CHECK-CIRCLE";
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ [tagName]: CheckCircle;
6
+ }
7
+ }
8
+ declare const mutableAttributes: readonly ["size"];
9
+ /**
10
+ * https://www.bilibili.com/video/BV17w4m1D7xi
11
+ * https://devdocs.io/svg/attribute/stroke-dasharray
12
+ * https://devdocs.io/svg/attribute/stroke-dashoffset
13
+ */
14
+ export declare class CheckCircle extends HTMLElement implements ELE.AttributeHandlers<typeof mutableAttributes[number]> {
15
+ #private;
16
+ connectedCallback(): void;
17
+ $circle?: SVGCircleElement;
18
+ $polyline?: SVGPolylineElement;
19
+ play(): Promise<unknown>;
20
+ accessor size: string | undefined;
21
+ accessor duration: number | undefined;
22
+ _size_set(nv: string | null): void;
23
+ }
24
+ export {};
@@ -0,0 +1,12 @@
1
+ export interface DialogOptions {
2
+ reusable?: boolean;
3
+ resizable?: boolean;
4
+ title?: string;
5
+ movable?: boolean;
6
+ $body?: HTMLElement;
7
+ width?: string;
8
+ height?: string;
9
+ okHandler?: ($dlg: HTMLDialogElement) => void;
10
+ }
11
+ export declare function createDialog(options: DialogOptions): HTMLDialogElement;
12
+ export declare function showDockRightModalDlg(options: DialogOptions): HTMLDialogElement;
@@ -0,0 +1,10 @@
1
+ export declare function showWaiting(title: string, msg?: string): {
2
+ $dlg: HTMLDialogElement;
3
+ complete(msg?: string): Promise<void>;
4
+ error(e?: object | string): void;
5
+ alert(msg: string): void;
6
+ close(): void;
7
+ setTitle(title: string): void;
8
+ };
9
+ export declare function showError(errMsg: string): HTMLDialogElement;
10
+ export declare function showAlert(msg: string): HTMLDialogElement;
package/dist/512.png ADDED
Binary file
@@ -0,0 +1,15 @@
1
+ export * from './000-helper/attr';
2
+ export * from './000-helper/center';
3
+ export * from './000-helper/corner';
4
+ export * from './000-helper/element';
5
+ export * from './000-helper/helper';
6
+ export * from './000-helper/lang';
7
+ export * from './000-helper/style';
8
+ export * from './000-helper/theme';
9
+ export { tagName as badgeTagName, Badge } from './003-accessory/badge';
10
+ export { tagName as closeTagName, CloseBtn } from './003-accessory/close';
11
+ export { tagName as iconTagName, Icon } from './003-accessory/icon';
12
+ export * from './003-accessory/iconCache';
13
+ export { tagName as checkCircleTagName, CheckCircle } from './011-dialog/circle';
14
+ export * from './011-dialog/dialog';
15
+ export * from './011-dialog/show';