litos-ui 0.15.8 → 0.16.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.
@@ -1,9 +1,9 @@
1
- import c from "../base.js";
1
+ import p from "../base.js";
2
2
  import { kebabToCamel as b, parseAttrValue as x } from "../utils/index.js";
3
- import { $one as h, $$ as o, iterate as g, formatStyle as p, shouldEventNext as y, on as C, off as u } from "ph-utils/dom";
3
+ import { $one as h, $$ as d, iterate as g, formatStyle as f, shouldEventNext as y, on as u, off as C } from "ph-utils/dom";
4
4
  import { random as _ } from "ph-utils";
5
- const m = ":host{--l-table-max-height: 100%;--l-table-td-padding: 10px;--l-table-th-padding: var(--l-table-td-padding);--l-table-layout: auto;display:inline-block;width:100%;max-height:var(--l-table-max-height);overflow:auto;font-size:14px}.l-table{width:100%;border-collapse:collapse;border-spacing:0;table-layout:var(--l-table-layout)}.l-table th,.l-table td{padding:var(--l-table-th-padding);border-bottom:1px solid #e6e6e6}.l-table th{text-align:left;background-color:#f2f2f2}.l-table td{background-color:#fff;transition:background-color .3s}.l-table tr:hover td{background-color:#f2f2f2}.l-table__empty-col{color:#999;text-align:center}.l-table-stripe tr:nth-child(2n) td{background-color:#fafafa}.l-table-stripe tr:nth-child(2n):hover td{background-color:#f2f2f2}.l-table-border th,.l-table-border td{border:1px solid #e6e6e6}.l-table-fixed{--l-table-layout: fixed}.l-table-fixed .l-fixed{position:-webkit-sticky;position:sticky;z-index:1;box-sizing:border-box}.l-table-fixed thead.l-fixed,.l-table-fixed tfoot.l-fixed{z-index:2}";
6
- class S extends c {
5
+ const m = ":host{display:inline-block;width:100%;max-height:var(--l-table-max-height, 100%);overflow:auto;font-size:var(--l-table-font-size, 14px)}.l-table{width:100%;border-collapse:collapse;border-spacing:0;table-layout:var(--l-table-layout, auto)}.l-table th,.l-table td{border-bottom:1px solid var(--l-table-border-color, #e6e6e6)}.l-table th{padding:var(--l-table-th-padding, 10px);text-align:left;background-color:var(--l-table-th-bg, #f2f2f2);color:var(--l-table-th-color, #000000)}.l-table td{background-color:var(--l-table-td-bg, #ffffff);color:var(--l-table-td-color, #000000);padding:var(--l-table-td-padding, 10px);transition:background-color .3s}.l-table tr:hover td{background-color:var(--l-table-row-hover-bg, #f2f2f2)}.l-table .l-table__empty-col{color:var(--l-table-empty-color, #999999);text-align:center}.l-table-stripe tr:nth-child(2n) td{background-color:var(--l-table-stripe-bg, #fafafa)}.l-table-stripe tr:nth-child(2n):hover td{background-color:var(--l-table-row-hover-bg, #f2f2f2)}.l-table-border th,.l-table-border td{border:1px solid var(--l-table-border-color, #e6e6e6)}.l-table-fixed{--l-table-layout: fixed}.l-table-fixed .l-fixed{position:-webkit-sticky;position:sticky;z-index:1;box-sizing:border-box}.l-table-fixed thead.l-fixed,.l-table-fixed tfoot.l-fixed{z-index:2}.l-table .caret-wrapper{display:inline-flex;justify-content:center;align-items:center;vertical-align:middle;height:14px;width:20px;position:relative}.l-table .caret-wrapper .ascending{border-bottom-color:var(--l-table-sort-inactive-color, #c0c4cc);top:-5px}.l-table .caret-wrapper .descending{border-top-color:var(--l-table-sort-inactive-color, #c0c4cc);bottom:-3px}.l-table .sort-caret{display:inline-block;width:0;height:0;border:5px solid transparent;position:absolute;border-radius:3px}.l-table .sort-column{cursor:pointer}.l-table .sort-asc .ascending{border-bottom-color:var(--l-primary-color, #52c41a)}.l-table .sort-desc .descending{border-top-color:var(--l-primary-color, #52c41a)}";
6
+ class H extends p {
7
7
  static baseName = "table";
8
8
  /** 斑马纹 */
9
9
  stripe = !0;
@@ -25,39 +25,36 @@ class S extends c {
25
25
  connectedCallback() {
26
26
  this.loadStyleText(m), super.connectedCallback();
27
27
  }
28
- setColumns(e) {
29
- let i = 0, t = 0;
30
- this.columns = this._parseColumns(e, i, t), this.rerender("all");
28
+ setColumns(t) {
29
+ let i = 0, e = 0;
30
+ this.columns = this._parseColumns(t, i, e), this.rerender("all");
31
31
  }
32
- setData(e) {
33
- this.data = e, this.columns && this.columns.length > 0 && this.rerender("body");
32
+ setData(t, i) {
33
+ this.data = t, this.sortInfo = i, this.columns && this.columns.length > 0 && this.rerender(i ? "all" : "body");
34
34
  }
35
- setDefaultSort(e) {
36
- this.sortInfo = e, this.rerender("all");
37
- }
38
- changeFixed(e) {
35
+ changeFixed(t) {
39
36
  const i = {
40
37
  fixedHead: this.fixedHead,
41
38
  fixedColumn: this.fixedColumn,
42
- ...e
39
+ ...t
43
40
  };
44
41
  if (this.fixedHead = i.fixedHead, this.fixedColumn = i.fixedColumn, this.rendered) {
45
- const t = h(".l-table", this.root);
46
- t && (this.fixedHead || this.fixedColumn ? t.classList.add("l-table-fixed") : t.classList.remove("l-table-fixed"));
42
+ const e = h(".l-table", this.root);
43
+ e && (this.fixedHead || this.fixedColumn ? e.classList.add("l-table-fixed") : e.classList.remove("l-table-fixed"));
47
44
  }
48
45
  }
49
46
  static get observedAttributes() {
50
47
  return ["stripe", "border", "fixed-head", "max-height", "table-layout"];
51
48
  }
52
- attributeChangedCallback(e, i, t) {
53
- e = b(e);
49
+ attributeChangedCallback(t, i, e) {
50
+ t = b(t);
54
51
  const s = x(
55
- t,
56
- this[e],
57
- e
52
+ e,
53
+ this[t],
54
+ t
58
55
  );
59
- if (s !== this[e])
60
- switch (this[e] = s, e) {
56
+ if (s !== this[t])
57
+ switch (this[t] = s, t) {
61
58
  case "stripe":
62
59
  this._classAttrChannge("stripe", s);
63
60
  break;
@@ -76,7 +73,7 @@ class S extends c {
76
73
  }
77
74
  }
78
75
  render() {
79
- const e = o("table", {
76
+ const t = d("table", {
80
77
  class: [
81
78
  "l-table",
82
79
  this.stripe ? "l-table-stripe" : "",
@@ -84,43 +81,43 @@ class S extends c {
84
81
  this.fixedHead || this.fixedColumn ? "l-table-fixed" : ""
85
82
  ]
86
83
  });
87
- return e.appendChild(this._headRender()), e.appendChild(this._bodyRender()), e;
84
+ return t.appendChild(this._headRender()), t.appendChild(this._bodyRender()), t;
88
85
  }
89
- rerender(e) {
86
+ rerender(t) {
90
87
  if (this.rendered) {
91
- if (e === "all" || e === "head") {
88
+ if (t === "all" || t === "head") {
92
89
  const i = h("thead", this.root);
93
90
  i && i.replaceWith(this._headRender());
94
91
  }
95
- if (e === "all" || e === "body") {
92
+ if (t === "all" || t === "body") {
96
93
  const i = h("tbody", this.root);
97
94
  i && i.replaceWith(this._bodyRender());
98
95
  }
99
96
  }
100
97
  }
101
- _changeCssVar(e, i) {
98
+ _changeCssVar(t, i) {
102
99
  if (!this.rendered) return;
103
- const t = `--l-table-${e}`;
104
- i ? this.style.setProperty(t, i) : this.style.removeProperty(t);
100
+ const e = `--l-table-${t}`;
101
+ i ? this.style.setProperty(e, i) : this.style.removeProperty(e);
105
102
  }
106
103
  _changeMaxHeight() {
107
- let e = this.maxHeight;
108
- e && typeof e == "number" && (e = `${e}px`), this._changeCssVar("max-height", e);
104
+ let t = this.maxHeight;
105
+ t && typeof t == "number" && (t = `${t}px`), this._changeCssVar("max-height", t);
109
106
  }
110
- _classAttrChannge(e, i) {
107
+ _classAttrChannge(t, i) {
111
108
  if (this.rendered) {
112
- const t = h("table", this.root);
113
- t && t.classList.toggle(`l-table-${e}`, i);
109
+ const e = h("table", this.root);
110
+ e && e.classList.toggle(`l-table-${t}`, i);
114
111
  }
115
112
  }
116
113
  _updateFixedHead() {
117
114
  if (this.rendered) {
118
- const e = h("thead", this.root);
119
- e && (e.classList.toggle("l-fixed", this.fixedHead), e.style.top = this.fixedHead ? "0" : "");
115
+ const t = h("thead", this.root);
116
+ t && (t.classList.toggle("l-fixed", this.fixedHead), t.style.top = this.fixedHead ? "0" : "");
120
117
  }
121
118
  }
122
119
  _headRender() {
123
- const e = o("thead", {
120
+ const t = d("thead", {
124
121
  class: {
125
122
  "l-fixed": this.fixedHead
126
123
  },
@@ -128,62 +125,62 @@ class S extends c {
128
125
  top: this.fixedHead ? "0" : void 0
129
126
  }
130
127
  });
131
- return this.columns && this._rendHeadRow(e, this.columns), e;
128
+ return this.columns && this._rendHeadRow(t, this.columns), t;
132
129
  }
133
- _rendHeadRow(e, i) {
134
- const t = o("tr");
130
+ _rendHeadRow(t, i) {
131
+ const e = d("tr");
135
132
  for (let s = 0, a = i.length; s < a; s++) {
136
133
  const r = i[s];
137
- t.appendChild(this._headColRender(r, s)), r.children && this._rendHeadRow(e, r.children);
134
+ e.appendChild(this._headColRender(r, s)), r.children && this._rendHeadRow(t, r.children);
138
135
  }
139
- e.appendChild(t);
136
+ t.appendChild(e);
140
137
  }
141
- _headColRender(e, i) {
142
- const t = o("th");
143
- if (e.titleColspan && e.titleColspan > 1 && (t.colSpan = e.titleColspan), e.titleRowspan && e.titleRowspan > 1 && (t.rowSpan = e.titleRowspan), t.style.cssText = this._getColumnStyle(e, "th"), e.fixed && t.classList.add("l-fixed"), t.appendChild(
144
- o("span", {
145
- textContent: e.title
138
+ _headColRender(t, i) {
139
+ const e = d("th");
140
+ if (t.titleColspan && t.titleColspan > 1 && (e.colSpan = t.titleColspan), t.titleRowspan && t.titleRowspan > 1 && (e.rowSpan = t.titleRowspan), e.style.cssText = this._getColumnStyle(t, "th"), t.fixed && e.classList.add("l-fixed"), e.appendChild(
141
+ d("span", {
142
+ textContent: t.title
146
143
  })
147
- ), e.sorter) {
148
- const s = o("span", { class: "caret-wrapper" });
149
- s.appendChild(o("span", { class: "sort-caret ascending" })), s.appendChild(o("span", { class: "sort-caret descending" })), t.appendChild(s);
144
+ ), t.sorter) {
145
+ const s = d("span", { class: "caret-wrapper" });
146
+ s.appendChild(d("span", { class: "sort-caret ascending" })), s.appendChild(d("span", { class: "sort-caret descending" })), e.classList.add("sort-column"), e.setAttribute("data-action", "sort"), e.setAttribute("data-col", `${i}`), e.appendChild(s);
150
147
  }
151
- return t;
148
+ return this.sortInfo && this.sortInfo.key === t.key && e.classList.add(this.sortInfo.order === "asc" ? "sort-asc" : "sort-desc"), e;
152
149
  }
153
150
  _bodyRender() {
154
- const e = o("tbody");
151
+ const t = d("tbody");
155
152
  if (this.data && this.data.length > 0)
156
- for (let i = 0, t = this.data.length; i < t; i++) {
153
+ for (let i = 0, e = this.data.length; i < e; i++) {
157
154
  const s = this.data[i];
158
155
  if (this.columns) {
159
- const a = o("tr");
160
- this._bodyRowRender(this.columns, i, s, a), e.appendChild(a);
156
+ const a = d("tr");
157
+ this._bodyRowRender(this.columns, i, s, a), t.appendChild(a);
161
158
  }
162
159
  }
163
160
  else {
164
- const i = o("tr"), t = o("td", {
161
+ const i = d("tr"), e = d("td", {
165
162
  class: "l-table__empty-col",
166
163
  textContent: "暂无数据"
167
164
  });
168
- this.columns && (t.colSpan = this.columns.length), i.appendChild(t), e.appendChild(i);
165
+ this.columns && (e.colSpan = this.columns.length), i.appendChild(e), t.appendChild(i);
169
166
  }
170
- return e;
167
+ return t;
171
168
  }
172
- _bodyRowRender(e, i, t, s) {
173
- for (let a = 0, r = e.length; a < r; a++) {
174
- const l = e[a];
169
+ _bodyRowRender(t, i, e, s) {
170
+ for (let a = 0, r = t.length; a < r; a++) {
171
+ const l = t[a];
175
172
  if (l.children && l.children.length > 0)
176
- this._bodyRowRender(l.children, i, t, s);
173
+ this._bodyRowRender(l.children, i, e, s);
177
174
  else {
178
- const d = o("td");
179
- if (typeof l.rowspan == "number" && (d.rowSpan = l.rowspan), typeof l.rowspan == "function" && (d.rowSpan = l.rowspan(t, i)), typeof l.colspan == "number" && (d.colSpan = l.colspan), typeof l.colspan == "function" && (d.colSpan = l.colspan(t, i)), l.fixed && (d.className = "l-fixed"), d.style.cssText = this._getColumnStyle(l), l.render) {
180
- const n = l.render(t, i);
181
- typeof n == "string" ? d.innerHTML = n : Array.isArray(n) ? g(n, (f) => {
182
- d.appendChild(f);
183
- }) : d.appendChild(n);
175
+ const o = d("td");
176
+ if (typeof l.rowspan == "number" && (o.rowSpan = l.rowspan), typeof l.rowspan == "function" && (o.rowSpan = l.rowspan(e, i)), typeof l.colspan == "number" && (o.colSpan = l.colspan), typeof l.colspan == "function" && (o.colSpan = l.colspan(e, i)), l.fixed && (o.className = "l-fixed"), o.style.cssText = this._getColumnStyle(l), l.render) {
177
+ const n = l.render(e, i);
178
+ typeof n == "string" ? o.innerHTML = n : Array.isArray(n) ? g(n, (c) => {
179
+ o.appendChild(c);
180
+ }) : o.appendChild(n);
184
181
  } else
185
- d.textContent = l.key ? t[l.key] : "";
186
- s.appendChild(d);
182
+ o.textContent = l.key ? e[l.key] : "";
183
+ s.appendChild(o);
187
184
  }
188
185
  }
189
186
  }
@@ -194,23 +191,23 @@ class S extends c {
194
191
  * @param rightOffset 右边固定列偏移
195
192
  * @returns
196
193
  */
197
- _parseColumns(e, i, t) {
194
+ _parseColumns(t, i, e) {
198
195
  const s = [];
199
- for (let a = 0, r = e.length; a < r; a++) {
200
- const l = e[a];
196
+ for (let a = 0, r = t.length; a < r; a++) {
197
+ const l = t[a];
201
198
  if (l.id || (l.id = l.key || l.title), l.id || (l.id = `${a}_${_(6)}`), l.fixed) {
202
- const d = Number.parseFloat(`${l.width || 0}`);
203
- l.fixed === "left" ? (l.left = i, i += d) : l.fixed === "right" && (l.right = t, t += d);
199
+ const o = Number.parseFloat(`${l.width || 0}`);
200
+ l.fixed === "left" ? (l.left = i, i += o) : l.fixed === "right" && (l.right = e, e += o);
204
201
  }
205
202
  if (l.children) {
206
- const d = this._parseColumns(
203
+ const o = this._parseColumns(
207
204
  l.children,
208
205
  i,
209
- t
206
+ e
210
207
  );
211
- l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan = d.reduce((n, f) => n + (f.titleColspan || 1), 0)), s.push({ ...l, children: d });
208
+ l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan = o.reduce((n, c) => n + (c.titleColspan || 1), 0)), s.push({ ...l, children: o });
212
209
  } else
213
- l.titleRowspan = l.titleRowspan || this._getMaxDepth(e), l.titleColspan = l.titleColspan || 1, s.push({ ...l });
210
+ l.titleRowspan = l.titleRowspan || this._getMaxDepth(t), l.titleColspan = l.titleColspan || 1, s.push({ ...l });
214
211
  }
215
212
  return s;
216
213
  }
@@ -219,42 +216,54 @@ class S extends c {
219
216
  * @param headers 表头配置
220
217
  * @returns 最大深度, 最大跨行数
221
218
  */
222
- _getMaxDepth(e) {
219
+ _getMaxDepth(t) {
223
220
  let i = 1;
224
- for (const t of e)
225
- t.children && (i = Math.max(i, this._getMaxDepth(t.children) + 1));
221
+ for (const e of t)
222
+ e.children && (i = Math.max(i, this._getMaxDepth(e.children) + 1));
226
223
  return i;
227
224
  }
228
- _getColumnStyle(e, i = "td") {
229
- const t = e.id;
230
- if (this._globalColStyles && t in this._globalColStyles)
231
- return this._globalColStyles[t][i];
225
+ _getColumnStyle(t, i = "td") {
226
+ const e = t.id;
227
+ if (this._globalColStyles && e in this._globalColStyles)
228
+ return this._globalColStyles[e][i];
232
229
  const s = {};
233
- e.width && (typeof e.width == "number" ? s.width = `${e.width}px` : s.width = e.width), e.fixed && (e.fixed === "left" ? (s.left = `${e.left}px`, s["box-shadow"] = "-4px 0 4px -4px #d9d9d9 inset") : e.fixed === "right" && (s.right = `${e.right}px`, s["box-shadow"] = "4px 0 4px -4px #d9d9d9 inset")), this._globalColStyles || (this._globalColStyles = {});
234
- const a = p(s), r = {
230
+ t.width && (typeof t.width == "number" ? s.width = `${t.width}px` : s.width = t.width), t.fixed && (t.fixed === "left" ? (s.left = `${t.left}px`, s["box-shadow"] = "-4px 0 4px -4px #d9d9d9 inset") : t.fixed === "right" && (s.right = `${t.right}px`, s["box-shadow"] = "4px 0 4px -4px #d9d9d9 inset")), this._globalColStyles || (this._globalColStyles = {});
231
+ const a = f(s), r = {
235
232
  th: a,
236
- td: a + p(e.style || "")
233
+ td: a + f(t.style || "")
237
234
  };
238
- return this._globalColStyles[t] = r, r[i];
235
+ return this._globalColStyles[e] = r, r[i];
239
236
  }
240
- _handleTap = (e) => {
241
- const [i, t, s] = y(
242
- e,
237
+ _handleTap = (t) => {
238
+ const [i, e, s] = y(
239
+ t,
243
240
  "data-action",
244
- e.currentTarget
241
+ t.currentTarget
245
242
  );
246
243
  if (i) {
247
244
  const a = s.dataset;
248
- this.emit("action", { detail: a });
245
+ if (e === "sort") {
246
+ const r = parseInt(a.col), l = this.columns[r], o = this.sortInfo && this.sortInfo.order === "desc" ? "asc" : "desc";
247
+ this.sortInfo = { key: l.key, order: o }, l.sorter === "custom" ? this.emit("sort", { detail: { index: r, key: l.key, dir: o } }) : (this.data = this._dataSort(), this.rerender("all"));
248
+ } else
249
+ this.emit(e, { detail: a });
249
250
  }
250
251
  };
251
252
  afterInit() {
252
- this._changeMaxHeight(), C(this.root, "click", this._handleTap);
253
+ this._changeMaxHeight(), u(this.root, "click", this._handleTap);
253
254
  }
254
255
  beforeDestroy() {
255
- u(this.root, "click", this._handleTap);
256
+ C(this.root, "click", this._handleTap);
257
+ }
258
+ _dataSort() {
259
+ if (!this.sortInfo || !this.data) return;
260
+ const { key: t, order: i } = this.sortInfo;
261
+ return this.data.sort((e, s) => {
262
+ const a = e[t], r = s[t];
263
+ return i === "asc" ? a - r : r - a;
264
+ });
256
265
  }
257
266
  }
258
267
  export {
259
- S as default
268
+ H as default
260
269
  };
@@ -20,7 +20,7 @@ export interface Column {
20
20
  /** 表头跨列 */
21
21
  titleColspan?: number;
22
22
  /** 列是否支持排序 */
23
- sorter?: boolean | "default" | ((a: any, b: any) => number);
23
+ sorter?: boolean | "custom";
24
24
  /** 列的样式 */
25
25
  style?: Record<string, string | null | undefined>;
26
26
  /** td colspan */
@@ -28,34 +28,9 @@ export declare function initAttr(el: HTMLElement): void;
28
28
  export declare function tagAttr(attr: string, value: string | undefined | boolean): string;
29
29
  export declare function tagAttrs(attr: [string, string | undefined | boolean][]): string;
30
30
  export declare function setAttrs(el: HTMLElement, attrs: [string, string | undefined | boolean][]): void;
31
- /**
32
- * 获取悬浮窗 y 偏移
33
- * @param targetRect
34
- * @param popoverRect
35
- * @param mainAlign
36
- * @param crossAlign
37
- * @returns
38
- */
39
- export declare function getPopoverOffsetY(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, offset?: number): number;
40
- type DomRectPos = {
41
- x: number;
42
- y: number;
43
- width: number;
44
- height: number;
45
- left: number;
46
- top: number;
47
- };
48
- export declare function getPopoverOffsetX(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, offset?: number): number;
49
- export declare function impactDetect(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, scrollLeft: number, scrollTop: number, leftDiff: number, topDiff: number, offset?: number, position?: string): {
50
- x: number;
51
- y: number;
52
- mainAlign: string;
53
- crossAlign: string;
54
- };
55
31
  /**
56
32
  * 短横线命名(kebab-case) 转换为 驼峰命名(camelCase
57
33
  * @param attr 待转换的属性名
58
34
  * @returns
59
35
  */
60
36
  export declare function kebabToCamel(attr: string): string;
61
- export {};
@@ -1,107 +1,60 @@
1
- import { isBlank as $ } from "ph-utils";
2
- let x = -1;
3
- function O(t, r) {
4
- const e = Array.isArray(t) ? t : [t];
5
- for (const s of e) {
6
- const i = r || `l-${s.baseName}`;
7
- customElements.get(i) || customElements.define(i, s);
1
+ import { isBlank as u } from "ph-utils";
2
+ let m = -1;
3
+ function b(t, e) {
4
+ const s = Array.isArray(t) ? t : [t];
5
+ for (const n of s) {
6
+ const r = e || `l-${n.baseName}`;
7
+ customElements.get(r) || customElements.define(r, n);
8
8
  }
9
9
  }
10
- function _() {
11
- return `l-${++x}`;
10
+ function y() {
11
+ return `l-${++m}`;
12
12
  }
13
- function m(t, r, e) {
14
- if (t == null) return r;
15
- switch (typeof r) {
13
+ function l(t, e, s) {
14
+ if (t == null) return e;
15
+ switch (typeof e) {
16
16
  case "boolean":
17
- return ["", "true", "1", "on", e].includes(t);
17
+ return ["", "true", "1", "on", s].includes(t);
18
18
  case "number":
19
19
  return Number(t);
20
20
  default:
21
21
  return t;
22
22
  }
23
23
  }
24
- function j(t) {
25
- const r = t.attributes;
26
- for (const e of r) {
27
- const { name: s, value: i } = e;
28
- if (s.startsWith("data-") || s.startsWith("aria-") || s.startsWith("_") || s.startsWith("$") || ["id", "class", "style"].includes(s))
24
+ function $(t) {
25
+ const e = t.attributes;
26
+ for (const s of e) {
27
+ const { name: n, value: r } = s;
28
+ if (n.startsWith("data-") || n.startsWith("aria-") || n.startsWith("_") || n.startsWith("$") || ["id", "class", "style"].includes(n))
29
29
  continue;
30
- const u = s.split("-").map((o, w) => w === 0 ? o : o[0].toUpperCase() + o.slice(1)).join(""), h = m(i, t[u], s), f = Object.getOwnPropertyNames(t);
31
- (t._ignoreInitAttrs || []).includes(u) || (s === "value" ? (t[u] = h, t._resetValue = h) : (f.includes(u) || f.includes(`_${u}`)) && (t[u] = h));
30
+ const i = n.split("-").map((c, f) => f === 0 ? c : c[0].toUpperCase() + c.slice(1)).join(""), o = l(r, t[i], n), a = Object.getOwnPropertyNames(t);
31
+ (t._ignoreInitAttrs || []).includes(i) || (n === "value" ? (t[i] = o, t._resetValue = o) : (a.includes(i) || a.includes(`_${i}`)) && (t[i] = o));
32
32
  }
33
33
  }
34
- function E(t, r) {
35
- let e = "";
36
- return r === !0 ? e = ` ${t}` : typeof r == "string" && !$(r) && (e = ` ${t}="${r}"`), e;
34
+ function p(t, e) {
35
+ let s = "";
36
+ return e === !0 ? s = ` ${t}` : typeof e == "string" && !u(e) && (s = ` ${t}="${e}"`), s;
37
37
  }
38
- function k(t) {
39
- const r = t.map((e) => E(e[0], e[1]));
40
- return r.length > 0 ? ` ${r.join("")}` : "";
38
+ function h(t) {
39
+ const e = t.map((s) => p(s[0], s[1]));
40
+ return e.length > 0 ? ` ${e.join("")}` : "";
41
41
  }
42
- function C(t, r) {
43
- for (const e of r) {
44
- const s = e[1], i = e[0];
45
- s === !0 ? t.setAttribute(i, "") : typeof s == "string" && !$(s) && t.setAttribute(i, s);
42
+ function I(t, e) {
43
+ for (const s of e) {
44
+ const n = s[1], r = s[0];
45
+ n === !0 ? t.setAttribute(r, "") : typeof n == "string" && !u(n) && t.setAttribute(r, n);
46
46
  }
47
47
  }
48
- function c(t, r, e, s, i = 10) {
49
- let n = 0;
50
- return e === "top" ? n = r.height + i : e === "bottom" ? n = -(t.height + i) : (e === "left" || e === "right") && (s === "" ? n = r.height / 2 - t.height / 2 : s === "end" && (n = r.height - t.height)), n;
51
- }
52
- function a(t, r, e, s, i = 10) {
53
- let n = 0;
54
- return e === "left" ? n = r.width + i : e === "right" ? n = -(t.width + i) : (e === "top" || e === "bottom") && (s === "" ? n = r.width / 2 - t.width / 2 : s === "end" && (n = r.width - t.width)), n;
55
- }
56
- function P(t, r, e, s, i, n, u, h, f = 10, y = "absolute") {
57
- const o = window.innerHeight + n - 10, w = window.innerWidth + i - 10;
58
- let d = t.top + n - h;
59
- d + r.height > o && (e === "left" || e === "right" ? s = "end" : e = "top", h = c(
60
- t,
61
- r,
62
- e,
63
- s,
64
- f
65
- ), d = t.top + n - h), d < n && (e === "left" || e === "right" ? s = "start" : e = "bottom");
66
- let b = t.left + i - u;
67
- return b + r.width > w && (e === "top" || e === "bottom" ? s = "end" : e = "left", u = a(
68
- t,
69
- r,
70
- e,
71
- s,
72
- f
73
- ), b = t.left + i - u), b < i && (e === "top" || e === "bottom" ? s = "start" : e = "right"), y === "fixed" && (h = c(
74
- t,
75
- r,
76
- e,
77
- s,
78
- f
79
- ), u = a(
80
- t,
81
- r,
82
- e,
83
- s,
84
- f
85
- ), b = t.left + i - u, d = t.top + n - h), {
86
- x: b,
87
- y: d,
88
- mainAlign: e,
89
- crossAlign: s
90
- };
91
- }
92
- function p(t) {
93
- return t.replace(/-(\w)/g, (r, e) => e.toUpperCase());
48
+ function N(t) {
49
+ return t.replace(/-(\w)/g, (e, s) => s.toUpperCase());
94
50
  }
95
51
  export {
96
- a as getPopoverOffsetX,
97
- c as getPopoverOffsetY,
98
- P as impactDetect,
99
- j as initAttr,
100
- p as kebabToCamel,
101
- m as parseAttrValue,
102
- O as regist,
103
- C as setAttrs,
104
- E as tagAttr,
105
- k as tagAttrs,
106
- _ as useId
52
+ $ as initAttr,
53
+ N as kebabToCamel,
54
+ l as parseAttrValue,
55
+ b as regist,
56
+ I as setAttrs,
57
+ p as tagAttr,
58
+ h as tagAttrs,
59
+ y as useId
107
60
  };
@@ -1,4 +1,4 @@
1
- import { $one as T, $ as y, iterate as $, on as d, off as a, shouldEventNext as g, $$ as w } from "ph-utils/dom";
1
+ import { $one as T, $ as y, iterate as $, on as d, off as a, shouldEventNext as P, $$ as w } from "ph-utils/dom";
2
2
  function E(s, t, e, o, n = 10, r = "x") {
3
3
  const i = r === "x" ? "width" : "height";
4
4
  let p = ["left", "right", "top", "bottom"];
@@ -50,13 +50,13 @@ function O(s, t, e, o, n = 10) {
50
50
  n,
51
51
  "x"
52
52
  ), m = s.left + i - u, f = s.top + p - c;
53
- const P = `${e}${o === "" ? "" : "-" + o}`;
53
+ const g = `${e}${o === "" ? "" : "-" + o}`;
54
54
  return {
55
55
  x: m,
56
56
  y: f,
57
57
  mainAlign: e,
58
58
  crossAlign: o,
59
- placement: P
59
+ placement: g
60
60
  };
61
61
  }
62
62
  function M(s, t, e, o) {
@@ -202,9 +202,9 @@ class z {
202
202
  this._clearHideTimer(), this.$reference != e && this.show(e);
203
203
  };
204
204
  _onMouseLeave = () => {
205
- this._clearHideTimer(), this._hideTimer = setTimeout(() => {
205
+ this._clearHideTimer(), this.options.trigger === "hover" && (this._hideTimer = setTimeout(() => {
206
206
  this.hide();
207
- }, 50);
207
+ }, 50));
208
208
  };
209
209
  _onRefTap = (t) => {
210
210
  this._destroyUpdater();
@@ -224,17 +224,24 @@ class z {
224
224
  show(t) {
225
225
  const e = t.dataset;
226
226
  let o = e.disabled;
227
- if (o == null && (o = this.options.disabled), !o && !this.$reference && (this.$reference = t, this.popoverElement || (this._renderPopover(), this._bindPopoverEvents()), this.popoverElement)) {
228
- this.options.updateContent && this.options.updateContent(this.popoverElement, e), this._destroyUpdater();
229
- const n = e.placement || this.options.placement || "top", r = Number(e.offset || this.options.offset || 10), i = e.popoverWidth || this.options.popoverWidth;
230
- this.popoverElement.style.display = "block";
231
- let p;
232
- i && (i !== "trigger" ? p = Number(i) : p = i), this.updater = L(this.$reference, this.popoverElement, {
233
- placement: n,
234
- popoverWidth: p,
235
- offset: r,
236
- arrowSize: this.options.arrowSize
237
- }), this.options.onOpenChange && this.options.onOpenChange(!0);
227
+ if (o == null && (o = this.options.disabled), !o) {
228
+ if (this.$reference) {
229
+ if (this.$reference === t)
230
+ return;
231
+ this.hide();
232
+ }
233
+ if (this.$reference = t, this.popoverElement || (this._renderPopover(), this._bindPopoverEvents()), this.popoverElement) {
234
+ this.options.updateContent && this.options.updateContent(this.popoverElement, e), this._destroyUpdater();
235
+ const n = e.placement || this.options.placement || "top", r = Number(e.offset || this.options.offset || 10), i = e.popoverWidth || this.options.popoverWidth;
236
+ this.popoverElement.style.display = "block";
237
+ let p;
238
+ i && (i !== "trigger" ? p = Number(i) : p = i), this.updater = L(this.$reference, this.popoverElement, {
239
+ placement: n,
240
+ popoverWidth: p,
241
+ offset: r,
242
+ arrowSize: this.options.arrowSize
243
+ }), this.options.onOpenChange && this.options.onOpenChange(!0);
244
+ }
238
245
  }
239
246
  }
240
247
  isShow() {
@@ -261,7 +268,7 @@ class z {
261
268
  return;
262
269
  }
263
270
  if (this.popoverElement && (this.popoverElement.contains(e) || this.popoverElement == e)) {
264
- const [o, n, r] = g(
271
+ const [o, n, r] = P(
265
272
  t,
266
273
  "data-action",
267
274
  this.popoverElement