litos-ui 0.1.0 → 0.2.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.
Files changed (44) hide show
  1. package/lib/base.d.ts +6 -3
  2. package/lib/base.js +49 -39
  3. package/lib/browser.d.ts +5 -4
  4. package/lib/button/index.d.ts +4 -0
  5. package/lib/button/index.js +73 -59
  6. package/lib/form/form_events.d.ts +12 -4
  7. package/lib/form/form_events.js +19 -15
  8. package/lib/form/form_inner.d.ts +34 -0
  9. package/lib/form/form_inner.js +121 -0
  10. package/lib/form/form_item.d.ts +33 -0
  11. package/lib/form/form_item.js +124 -7
  12. package/lib/form/index.d.ts +22 -1
  13. package/lib/form/index.js +108 -19
  14. package/lib/form/types.js +1 -0
  15. package/lib/icon/arrow_down.js +8 -6
  16. package/lib/icon/base.js +24 -19
  17. package/lib/icon/caret_bottom.js +8 -6
  18. package/lib/icon/caret_top.js +8 -6
  19. package/lib/icon/font_icon.js +18 -13
  20. package/lib/icon/info.js +8 -6
  21. package/lib/icon/loading.js +8 -6
  22. package/lib/icon/mask_close.js +8 -6
  23. package/lib/icon/search.js +8 -6
  24. package/lib/icon/success.js +7 -5
  25. package/lib/icon/warn.js +8 -6
  26. package/lib/index-B_9rPBWp.js +4 -0
  27. package/lib/index-Boq1Q7q9.js +4 -0
  28. package/lib/index-CCcVpk6U.js +4 -0
  29. package/lib/index-ColsUDnt.js +4 -0
  30. package/lib/index.d.ts +8 -4
  31. package/lib/index.js +29 -25
  32. package/lib/input/index.d.ts +17 -16
  33. package/lib/input/index.js +86 -86
  34. package/lib/litos-ui.css +1 -1
  35. package/lib/litos-ui.min.js +1 -1
  36. package/lib/radio/index.d.ts +27 -0
  37. package/lib/radio/index.js +113 -0
  38. package/lib/transition.js +27 -22
  39. package/lib/util.js +23 -20
  40. package/package.json +6 -5
  41. package/styles/reset.css +5 -0
  42. package/lib/index-CWq5_ldX.js +0 -4
  43. package/lib/index-CbaSCp33.js +0 -4
  44. package/lib/index-JjjljTZ2.js +0 -4
@@ -0,0 +1,113 @@
1
+ var C = Object.defineProperty;
2
+ var E = (o, n, e) => n in o ? C(o, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[n] = e;
3
+ var r = (o, n, e) => E(o, typeof n != "symbol" ? n + "" : n, e);
4
+ import { initAttr as A, tagAttr as h, parseAttrValue as I } from "../util.js";
5
+ import N from "../form/form_inner.js";
6
+ import { $one as d, hasClass as v, addClass as p, $ as u, iterate as m, getAttr as y, formatClass as S, on as j, off as D, removeClass as H } from "ph-utils/dom";
7
+ import { random as b } from "ph-utils";
8
+ class L extends N {
9
+ constructor() {
10
+ super(!1);
11
+ r(this, "type");
12
+ r(this, "label");
13
+ r(this, "checked", !1);
14
+ r(this, "_changeEvent");
15
+ r(this, "_radioChange", (e) => {
16
+ const a = e.target;
17
+ let t = a.parentElement;
18
+ for (; t != null && !v(t, "l-radio"); )
19
+ t = t.parentElement;
20
+ const i = d(".is-checked", this.root);
21
+ i && H(i, "is-checked"), this.value = a.value, t && p(t, "is-checked"), this.dispatchEvent(this._changeEvent);
22
+ });
23
+ A(this), this._changeEvent = new CustomEvent("change");
24
+ }
25
+ setItems(e) {
26
+ this._removeEvents(), this.root.innerHTML = this._renderItems(e), this._initEvents();
27
+ }
28
+ connectedCallback() {
29
+ super.connectedCallback(), this.loadStyle(["radio"]), this._initEvents();
30
+ }
31
+ disconnectedCallback() {
32
+ super.disconnectedCallback(), this._removeEvents();
33
+ }
34
+ attributeChange(e, a, t) {
35
+ if (e === "checked") {
36
+ const i = I(t, !1, e);
37
+ this.checked = i, this.value = i;
38
+ const s = d(".l-radio", this.root);
39
+ if (s && !v(s, "is-checked")) {
40
+ p(s, "is-checked");
41
+ const l = d("input", s);
42
+ l && (l.checked = !0);
43
+ }
44
+ }
45
+ }
46
+ render() {
47
+ this.getName() || (this.name = `la${b(3)}_${b(6)}`);
48
+ const e = [], a = d('[slot="label"]', this), t = u("[radio-value]", this);
49
+ a != null || this.label ? (this.value = this._isChecked(), a ? e.push(
50
+ this._renderItem("slot", void 0, this._isChecked(), "label")
51
+ ) : e.push(
52
+ this._renderItem(
53
+ this.label,
54
+ void 0,
55
+ this._isChecked(),
56
+ "label"
57
+ )
58
+ )) : t.length > 0 && (m(t, (i) => {
59
+ const s = i.cloneNode(!0), l = y(i, "radio-value");
60
+ e.push(
61
+ this._renderItem(s.outerHTML, l, this.value === l)
62
+ );
63
+ }), this.pushValueChange()), this.root.innerHTML = e.join("");
64
+ }
65
+ _renderItems(e) {
66
+ const a = [];
67
+ for (let t = 0, i = e.length; t < i; t++) {
68
+ const s = e[t];
69
+ a.push(
70
+ this._renderItem(
71
+ s.label,
72
+ s.value,
73
+ this.value === s.value,
74
+ s.labelPart
75
+ )
76
+ );
77
+ }
78
+ return a.join("");
79
+ }
80
+ _renderItem(e, a, t = !1, i = void 0) {
81
+ const s = S({
82
+ "l-radio": !0,
83
+ "l-radio--disabled": this.isDisabled(),
84
+ "l-radio--button": this.type === "button",
85
+ "is-checked": t
86
+ }), l = h("disabled", this.isDisabled()), _ = h("checked", t), f = h("value", a), k = `${h("name", this.getName())}${f}${l}${_}`, $ = h("part", i), c = [
87
+ `<label class="${s}">`,
88
+ `<input type="radio" class="l-radio__input"${k} />`
89
+ ];
90
+ this.type !== "button" && c.push('<span class="l-radio__inner"></span>');
91
+ let g = e === "slot" ? '<slot name="label"></slot>' : e;
92
+ return c.push(
93
+ `<div class="l-radio__label"${$}>${g}</div>`
94
+ ), c.push("</label>"), c.join("");
95
+ }
96
+ _isChecked() {
97
+ return this.checked;
98
+ }
99
+ _initEvents() {
100
+ m(u("input", this.root), (e) => {
101
+ j(e, "change", this._radioChange);
102
+ });
103
+ }
104
+ _removeEvents() {
105
+ m(u("input", this.root), (e) => {
106
+ D(e, "change", this._radioChange);
107
+ });
108
+ }
109
+ }
110
+ r(L, "baseName", "radio");
111
+ export {
112
+ L as default
113
+ };
package/lib/transition.js CHANGED
@@ -1,47 +1,52 @@
1
- import a from "./base.js";
2
- import { startTransition as l, endTransition as c } from "ph-utils/dom";
3
- const r = class r extends a {
1
+ var l = Object.defineProperty;
2
+ var c = (r, e, t) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var o = (r, e, t) => c(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import d from "./base.js";
5
+ import { startTransition as u, endTransition as g } from "ph-utils/dom";
6
+ class p extends d {
7
+ constructor() {
8
+ super();
9
+ /** 应用过滤动画的属性值, 例如: opacity: 0; transform: xx; */
10
+ o(this, "sheetRec");
11
+ this.sheetRec = this._parseSheets(this.getAttr("sheets", "opacity: 0"));
12
+ }
4
13
  static get observedAttributes() {
5
14
  return ["sheets"];
6
15
  }
7
- constructor() {
8
- super(), this.sheetRec = this._parseSheets(this.getAttr("sheets", "opacity: 0"));
9
- }
10
16
  connectedCallback() {
11
17
  super.connectedCallback(), this.show();
12
18
  }
13
19
  render() {
14
20
  this.shadow.innerHTML = "<slot></slot>";
15
21
  }
16
- attributeChangedCallback(t, e, s) {
17
- t === "sheets" && (this.sheetRec = this._parseSheets(s));
22
+ attributeChangedCallback(t, s, i) {
23
+ t === "sheets" && (this.sheetRec = this._parseSheets(i));
18
24
  }
19
25
  show() {
20
26
  const t = this._getSlotFirstChild();
21
27
  if (!t) return;
22
- const e = this.getAttr("duration", "0.3s");
23
- l(t, this.sheetRec, e);
28
+ const s = this.getAttr("duration", "0.3s");
29
+ u(t, this.sheetRec, s);
24
30
  }
25
31
  hide(t) {
26
- const e = this._getSlotFirstChild();
27
- e && c(e, this.sheetRec, t);
32
+ const s = this._getSlotFirstChild();
33
+ s && g(s, this.sheetRec, t);
28
34
  }
29
35
  _parseSheets(t) {
30
- const e = t.split(";"), s = [];
31
- return e.forEach((i) => {
32
- if (i) {
33
- const [h, n] = i.split(":");
34
- s.push([h.trim(), n.trim()]);
36
+ const s = t.split(";"), i = [];
37
+ return s.forEach((n) => {
38
+ if (n) {
39
+ const [h, a] = n.split(":");
40
+ i.push([h.trim(), a.trim()]);
35
41
  }
36
- }), s;
42
+ }), i;
37
43
  }
38
44
  _getSlotFirstChild() {
39
45
  const t = this.shadow.querySelector("slot");
40
46
  return t != null && t.assignedNodes().length > 0 ? t.assignedNodes()[0] : null;
41
47
  }
42
- };
43
- r.tagName = "transition";
44
- let o = r;
48
+ }
49
+ o(p, "tagName", "transition");
45
50
  export {
46
- o as Transition
51
+ p as Transition
47
52
  };
package/lib/util.js CHANGED
@@ -1,26 +1,26 @@
1
- import { isBlank as m } from "ph-utils";
2
- let p = -1, r = {
1
+ import { isBlank as u } from "ph-utils";
2
+ let m = -1, i = {
3
3
  /** 注册应用的前缀 */
4
4
  prefix: "l"
5
5
  };
6
6
  function g(t) {
7
- r = { ...r, ...t };
7
+ i = { ...i, ...t };
8
8
  }
9
- function y(t, n) {
10
- const e = n || `${r.prefix}-${t.baseName}`;
9
+ function h(t, n) {
10
+ const e = n || `${i.prefix}-${t.baseName}`;
11
11
  customElements.get(e) || customElements.define(e, t);
12
12
  }
13
- function b(t, n = !1) {
13
+ function l(t, n = !1) {
14
14
  t = t || "l-transition";
15
15
  let e = t;
16
16
  typeof t == "string" && (e = document.querySelector(t)), e && e.hide(() => {
17
17
  n && e.remove();
18
18
  });
19
19
  }
20
- function l() {
21
- return `${r.prefix}-${++p}`;
20
+ function y() {
21
+ return `${i.prefix}-${++m}`;
22
22
  }
23
- function a(t, n, e) {
23
+ function p(t, n, e) {
24
24
  if (t == null) return n;
25
25
  switch (typeof n) {
26
26
  case "boolean":
@@ -31,23 +31,26 @@ function a(t, n, e) {
31
31
  return t;
32
32
  }
33
33
  }
34
- function x(t) {
34
+ function b(t) {
35
35
  const n = t.attributes;
36
36
  for (const e of n) {
37
- const { name: i, value: f } = e, o = i.split("-").map((s, u) => u === 0 ? s : s[0].toUpperCase() + s.slice(1)).join(""), c = a(f, t[o], i);
38
- t[o] = c;
37
+ const { name: r, value: c } = e;
38
+ if (r.startsWith("data-") || r.startsWith("aria-") || r.startsWith("_") || r.startsWith("$"))
39
+ continue;
40
+ const o = r.split("-").map((s, a) => a === 0 ? s : s[0].toUpperCase() + s.slice(1)).join(""), f = p(c, t[o], r);
41
+ t[o] = f, r === "value" && (t._resetValue = f);
39
42
  }
40
43
  }
41
- function N(t, n) {
44
+ function x(t, n) {
42
45
  let e = " ";
43
- return n === !0 ? e = ` ${t}` : typeof n == "string" && !m(n) && (e = ` ${t}="${n}"`), e;
46
+ return n === !0 ? e = ` ${t}` : typeof n == "string" && !u(n) && (e = ` ${t}="${n}"`), e;
44
47
  }
45
48
  export {
46
49
  g as config,
47
- b as hideTransition,
48
- x as initAttr,
49
- a as parseAttrValue,
50
- y as regist,
51
- N as tagAttr,
52
- l as useId
50
+ l as hideTransition,
51
+ b as initAttr,
52
+ p as parseAttrValue,
53
+ h as regist,
54
+ x as tagAttr,
55
+ y as useId
53
56
  };
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "litos-ui",
3
3
  "description": "基于 Web Component 的 UI 组件库",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "type": "module",
6
6
  "devDependencies": {
7
7
  "@eslint/js": "^9.16.0",
8
8
  "@types/node": "^22.10.1",
9
9
  "eslint": "^9.16.0",
10
10
  "globals": "^15.13.0",
11
+ "less": "^4.2.1",
11
12
  "lightningcss": "^1.28.2",
12
- "prettier": "^3.4.1",
13
+ "prettier": "^3.4.2",
13
14
  "typescript": "^5.7.2",
14
- "typescript-eslint": "^8.16.0",
15
- "vite": "^6.0.1",
15
+ "typescript-eslint": "^8.17.0",
16
+ "vite": "^6.0.3",
16
17
  "vitepress": "^1.5.0"
17
18
  },
18
19
  "files": [
@@ -49,7 +50,7 @@
49
50
  },
50
51
  "license": "MIT",
51
52
  "dependencies": {
52
- "ph-utils": "^0.10.2",
53
+ "ph-utils": "^0.11.3",
53
54
  "shiki": "^1.24.0"
54
55
  },
55
56
  "scripts": {
package/styles/reset.css CHANGED
@@ -47,3 +47,8 @@ p {
47
47
  line-height: 1.4;
48
48
  color: #333;
49
49
  }
50
+
51
+ /* 按钮之间间隔 */
52
+ l-button:not([text]) + l-button {
53
+ margin-left: 10px;
54
+ }
@@ -1,4 +0,0 @@
1
- const i = ".l-input{--l-input-width: auto;outline:none;box-sizing:border-box;width:var(--l-input-width);max-width:100%;height:var(--l-form-edit-height, 32px);border:1px solid var(--l-border-color, #dedede);transition:border-color .3s;text-align:inherit;padding:0 5px;border-radius:3px;vertical-align:middle}.l-input.is-autosize{width:auto}.l-input:focus{border-color:var(--l-primary-color, #722ed1)}.l-input:disabled{cursor:not-allowed;background:var(--l-disabled-color, #f5f7fa)}";
2
- export {
3
- i as default
4
- };
@@ -1,4 +0,0 @@
1
- const e = "";
2
- export {
3
- e as default
4
- };
@@ -1,4 +0,0 @@
1
- const r = ".l-btn{--l-btn-text-color: #ffffff;--l-btn-hover-text-color: var(--l-btn-text-color);--l-btn-active-text-color: var(--l-btn-text-color);--l-btn-border-color: var(--l-primary-color, #722ed1);--l-btn-background: var(--l-btn-border-color);--l-btn-hover-border-color: var(--l-primary-color-light1, #9254de);--l-btn-hover-background: var(--l-btn-hover-border-color);--l-btn-active-border-color: var(--l-primary-color-dark1, #531dab);--l-btn-active-background: var(--l-btn-active-border-color);--l-btn-disabled-color: #c9c9c9;--l-btn-disabled-background: #fbfbfb;--l-btn-disabled-border-color: #e6e6e6;display:inline-flex;justify-content:center;align-items:center;cursor:pointer;outline:none;box-sizing:border-box;vertical-align:middle;padding:0 15px;line-height:1;height:var(--l-form-edit-height, 32px);border-radius:3px;font-size:14px;color:var(--l-btn-text-color);background:var(--l-btn-background);border:1px solid var(--l-btn-border-color);position:relative;gap:5px;transition:border-color .3s,background-color .3s,color .3s}.l-btn:hover{border-color:var(--l-btn-hover-border-color, var(--l-btn-hover-background));color:var(--l-btn-hover-text-color);background:var(--l-btn-hover-background)}.l-btn:active{border-color:var( --l-btn-active-border-color, var(--l-btn-active-background) );color:var(--l-btn-active-text-color);background:var(--l-btn-active-background)}.l-btn-normal{--l-btn-text-color: auto;--l-btn-background: transparent;--l-btn-border-color: #d9d9d9;--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab);--l-btn-hover-background: #fff;--l-btn-active-background: #fff;--l-btn-hover-border-color: var(--l-btn-hover-text-color);--l-btn-active-border-color: var(--l-btn-active-text-color)}.l-btn-primary{--l-btn-background: var(--l-primary-color, #722ed1);--l-btn-hover-background: var(--l-primary-color-light1, #9254de);--l-btn-active-background: var(--l-primary-color-dark1, #531dab)}.l-btn:not(.l-btn-loading):disabled{border-color:var(--l-btn-disabled-border-color);background:var(--l-btn-disabled-background);color:var(--l-btn-disabled-color);cursor:not-allowed;opacity:1}.l-btn-text{--l-btn-background: transparent;--l-btn-border-color: transparent;--l-btn-hover-border-color: transparent;--l-btn-active-border-color: transparent;--l-btn-disabled-background: transparent;--l-btn-disabled-border-color: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;height:auto;padding:5px}.l-btn-primary.l-btn-text{--l-btn-text-color: var(--l-primary-color, #722ed1);--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab)}.l-btn-ghost{--l-btn-text-color: var(--l-btn-border-color);--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;--l-btn-hover-text-color: var(--l-btn-hover-border-color);--l-btn-active-text-color: var(--l-btn-active-border-color)}.l-btn-round{border-radius:calc(var(--l-form-edit-height, 32px) / 2)}.l-btn-circle{border-radius:50%;width:var(--l-form-edit-height, 32px);padding:0}.l-btn-block{width:100%}.l-btn:not(.l-btn-text)+.l-btn{margin-left:10px}html.dark .l-btn:disabled{--l-btn-disabled-background: rgba(255, 255, 255, .08);--l-btn-disabled-color: rgba(255, 255, 255, .3);--l-btn-disabled-border-color: rgba(255, 255, 255, .3)}";
2
- export {
3
- r as default
4
- };