@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.
@@ -0,0 +1,1373 @@
1
+ function getSnakeCaseName(propName) {
2
+ return propName.replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`);
3
+ }
4
+ function strAttr(_, context) {
5
+ const propName = String(context.name);
6
+ const attrName = getSnakeCaseName(propName);
7
+ let initValue = void 0;
8
+ return {
9
+ get() {
10
+ const ret = this.getAttribute(attrName);
11
+ return ret === null ? initValue : ret;
12
+ },
13
+ set(value) {
14
+ if (value ?? false) {
15
+ this.setAttribute(attrName, String(value));
16
+ } else {
17
+ this.removeAttribute(attrName);
18
+ }
19
+ },
20
+ init(value) {
21
+ initValue = value;
22
+ return value;
23
+ }
24
+ };
25
+ }
26
+ function boolAttr(_, context) {
27
+ const propName = String(context.name);
28
+ const attrName = getSnakeCaseName(propName);
29
+ let initValue = void 0;
30
+ return {
31
+ get() {
32
+ return this.hasAttribute(attrName) || initValue;
33
+ },
34
+ set(value) {
35
+ if (value) {
36
+ this.setAttribute(attrName, "");
37
+ } else {
38
+ this.removeAttribute(attrName);
39
+ }
40
+ },
41
+ init(value) {
42
+ initValue = value;
43
+ return value;
44
+ }
45
+ };
46
+ }
47
+ function intAttr(_, context) {
48
+ const propName = String(context.name);
49
+ const attrName = getSnakeCaseName(propName);
50
+ let initValue = void 0;
51
+ return {
52
+ get() {
53
+ const attr = this.getAttribute(attrName);
54
+ return attr === null ? initValue : Number(attr);
55
+ },
56
+ set(value) {
57
+ if (value !== void 0 && !Number.isNaN(value)) {
58
+ this.setAttribute(attrName, Number(value).toString());
59
+ } else {
60
+ this.removeAttribute(attrName);
61
+ }
62
+ },
63
+ init(value) {
64
+ initValue = value;
65
+ return value;
66
+ }
67
+ };
68
+ }
69
+ function saAttr(_, context) {
70
+ const propName = String(context.name);
71
+ const attrName = getSnakeCaseName(propName);
72
+ let initValue = void 0;
73
+ return {
74
+ get() {
75
+ const attr = this.getAttribute(attrName);
76
+ return attr === null ? initValue : attr.split(",");
77
+ },
78
+ set(value) {
79
+ if (value && value.length > 0) {
80
+ this.setAttribute(attrName, value.join(","));
81
+ } else {
82
+ this.removeAttribute(attrName);
83
+ }
84
+ },
85
+ init(value) {
86
+ initValue = value;
87
+ return value;
88
+ }
89
+ };
90
+ }
91
+ const borders = ["bottom", "top", "right", "left"];
92
+ const dialogTagName$1 = "DIALOG";
93
+ function getContainer$1($el) {
94
+ const root = $el.getRootNode();
95
+ if (root instanceof ShadowRoot) {
96
+ return getContainer$1(root.host);
97
+ }
98
+ return $el.closest(dialogTagName$1) ?? document.body;
99
+ }
100
+ const attachBorderAttributeName = "gzm-attach-border";
101
+ function checkPopupPosition$1($ppp) {
102
+ if (!$ppp.getAttribute("popover")) {
103
+ $ppp.setAttribute("popover", "");
104
+ }
105
+ if ($ppp.isConnected) {
106
+ const p = getComputedStyle($ppp).position;
107
+ if (p !== "fixed") {
108
+ throw new Error("popup 的样式定位必须是 fixed");
109
+ }
110
+ }
111
+ }
112
+ class CenterHelper {
113
+ constructor($tooltip, $attachTo, attachBorder) {
114
+ this.$tt = $tooltip;
115
+ this.$attachTo = $attachTo;
116
+ this.realBorder = this.#attachBorder = attachBorder;
117
+ }
118
+ $tt;
119
+ $attachTo;
120
+ #attachBorder;
121
+ #space;
122
+ //最终计算结果
123
+ realBorder;
124
+ x = 0;
125
+ y = 0;
126
+ marginLeft = "";
127
+ marginTop = "";
128
+ //$tt 的宽度和高度
129
+ ttWidth = 0;
130
+ ttHeight = 0;
131
+ pos($tt = this.$tt) {
132
+ this.#checkParent();
133
+ this.#calcCoordinates();
134
+ $tt.setAttribute(attachBorderAttributeName, this.realBorder);
135
+ $tt.style.top = Math.ceil(this.y) + "px";
136
+ $tt.style.left = Math.ceil(this.x) + "px";
137
+ this.#ani($tt);
138
+ }
139
+ #ani($tt = this.$tt, rb = this.realBorder) {
140
+ if (!$tt.doTransition) return;
141
+ if (rb !== "bottom" && rb !== "right") return;
142
+ const { width, height } = $tt.getBoundingClientRect();
143
+ $tt.style.transitionDuration = "200ms";
144
+ $tt.style.transitionProperty = "width,height";
145
+ $tt.beforeOpenTransition?.();
146
+ $tt.ontransitionend = () => {
147
+ $tt.ontransitionend = null;
148
+ $tt.afterOpenTransition?.();
149
+ if (rb === "bottom") {
150
+ $tt.style.height = "";
151
+ } else if (rb === "right") {
152
+ $tt.style.width = "";
153
+ }
154
+ };
155
+ let s = 0;
156
+ if (rb === "bottom") {
157
+ $tt.style.height = "0";
158
+ $tt.style.width = width + "px";
159
+ s = $tt.offsetHeight;
160
+ $tt.style.height = height + "px";
161
+ } else if (rb === "right") {
162
+ $tt.style.width = "0";
163
+ $tt.style.height = height + "px";
164
+ s = $tt.offsetWidth;
165
+ $tt.style.width = width + "px";
166
+ }
167
+ return s;
168
+ }
169
+ /**
170
+ * 计算 popup 显示的 top/left 以及需要调整箭头位置
171
+ */
172
+ #calcCoordinates() {
173
+ this.#calcSpace();
174
+ const border = this.#getRealAttachBorder();
175
+ if (border === "top" || border === "bottom") {
176
+ this.#calcBorderY();
177
+ this.#calcPointerX();
178
+ } else {
179
+ this.#calcBorderX();
180
+ this.#calcPointerY();
181
+ }
182
+ }
183
+ #checkParent($tt = this.$tt, $attachTo = this.$attachTo) {
184
+ const $c = getContainer$1($attachTo);
185
+ if ($tt.isConnected) {
186
+ const $pc = getContainer$1($tt);
187
+ if ($pc !== $c) {
188
+ $c.append($tt);
189
+ }
190
+ } else {
191
+ $c.append($tt);
192
+ }
193
+ checkPopupPosition$1($tt);
194
+ $tt.showPopover();
195
+ const r = $tt.getBoundingClientRect();
196
+ this.ttWidth = r.width;
197
+ this.ttHeight = r.height;
198
+ }
199
+ #calcSpace($attachTo = this.$attachTo) {
200
+ const rect = $attachTo.getBoundingClientRect();
201
+ const $dd = document.documentElement;
202
+ const r = $dd.getBoundingClientRect();
203
+ const s = {
204
+ top: rect.top - r.top,
205
+ left: rect.left - r.left,
206
+ width: rect.width,
207
+ height: rect.height,
208
+ right: r.right - rect.right - ($dd.offsetWidth - $dd.clientWidth),
209
+ bottom: r.bottom - rect.bottom - ($dd.offsetHeight - $dd.clientHeight)
210
+ };
211
+ this.#space = s;
212
+ }
213
+ /**
214
+ * 判断一种停靠方式是否有足够的空间。
215
+ * @returns 数字 = 空间 - 占用尺寸后的剩余
216
+ */
217
+ #calcBorderSpace(border, space = this.#space) {
218
+ const sp = space[border];
219
+ const sz = border === "top" || border === "bottom" ? this.ttHeight : this.ttWidth;
220
+ return sp - sz;
221
+ }
222
+ /**
223
+ * 判断应该停靠在哪一条边。
224
+ * @returns 'top'/'left'/'right'/'bottom'
225
+ */
226
+ #getRealAttachBorder() {
227
+ let ret = this.#attachBorder;
228
+ if (ret) {
229
+ if (this.#calcBorderSpace(ret) >= 0) {
230
+ return this.realBorder = ret;
231
+ }
232
+ }
233
+ let empty = -99999;
234
+ for (const b of borders) {
235
+ const s = this.#calcBorderSpace(b);
236
+ if (s > empty) {
237
+ empty = s;
238
+ ret = b;
239
+ }
240
+ }
241
+ return this.realBorder = ret;
242
+ }
243
+ /**
244
+ * 计算停靠在上下边框时的y
245
+ */
246
+ #calcBorderY(realBorder = this.realBorder, space = this.#space) {
247
+ let y = space.top;
248
+ y = realBorder === "top" ? y - this.ttHeight : y + space.height;
249
+ this.y = y;
250
+ }
251
+ /**
252
+ * 计算停靠在上下边框时的x。
253
+ * 默认是中间对齐,但当宽度太大时,需要调整水平位置。
254
+ */
255
+ #calcPointerX(space = this.#space) {
256
+ const w = (this.ttWidth - space.width) / 2;
257
+ const x = space.left - w;
258
+ if (w <= space.left && w <= space.right || w > space.left && w > space.right) {
259
+ this.x = x;
260
+ this.marginLeft = "";
261
+ return;
262
+ }
263
+ if (w > space.left) {
264
+ this.x = 0;
265
+ this.marginLeft = space.left - w + "px";
266
+ return;
267
+ }
268
+ const left = w - space.right;
269
+ this.x = x - left;
270
+ this.marginLeft = left + "px";
271
+ }
272
+ /**
273
+ * 计算停靠在左右边框时的x
274
+ */
275
+ #calcBorderX(realBorder = this.realBorder, space = this.#space) {
276
+ let x = space.left;
277
+ x = realBorder === "left" ? x - this.ttWidth : x + space.width;
278
+ this.x = x;
279
+ }
280
+ /**
281
+ * 计算停靠在左右边框时的y。
282
+ * 默认是中间对齐,但当高度太大时,需要调整垂直位置。
283
+ */
284
+ #calcPointerY(space = this.#space) {
285
+ const h = (this.ttHeight - space.height) / 2;
286
+ const y = space.top - h;
287
+ if (h <= space.top && h <= space.bottom || h > space.top && h > space.bottom) {
288
+ this.y = y;
289
+ this.marginTop = "";
290
+ return;
291
+ }
292
+ if (h > space.top) {
293
+ this.y = 0;
294
+ this.marginTop = space.top - h + "px";
295
+ return;
296
+ }
297
+ this.y = y - (h - space.bottom);
298
+ this.marginTop = h - space.bottom + "px";
299
+ }
300
+ }
301
+ const xy = {
302
+ leftTop: 0,
303
+ leftBottom: 1,
304
+ rightTop: 10,
305
+ rightBottom: 11
306
+ };
307
+ function isLeftCorner(c) {
308
+ return c < 10;
309
+ }
310
+ function isTopCorner(c) {
311
+ return c % 10 === 0;
312
+ }
313
+ function makeCorner(isLeft, isTop) {
314
+ const x = isLeft ? 0 : 10;
315
+ const y = isTop ? 0 : 1;
316
+ return x + y;
317
+ }
318
+ const dialogTagName = "DIALOG";
319
+ function getContainer($el) {
320
+ const root = $el.getRootNode();
321
+ if (root instanceof ShadowRoot) {
322
+ return getContainer(root.host);
323
+ }
324
+ return $el.closest(dialogTagName) ?? document.documentElement;
325
+ }
326
+ function checkPopupPosition($ppp) {
327
+ if (!$ppp.getAttribute("popover")) {
328
+ $ppp.setAttribute("popover", "");
329
+ }
330
+ if ($ppp.isConnected) {
331
+ const p = getComputedStyle($ppp).position;
332
+ if (p !== "fixed") {
333
+ throw new Error("popup 的样式定位必须是 fixed");
334
+ }
335
+ }
336
+ }
337
+ class CornerHelper {
338
+ constructor($popup, popupCorner, $attachTo, attachCorner) {
339
+ this.$popup = $popup;
340
+ this.#popupCorner = popupCorner;
341
+ this.$attachTo = $attachTo;
342
+ this.#attachCorner = attachCorner;
343
+ }
344
+ $popup;
345
+ $attachTo;
346
+ #popupCorner;
347
+ #attachCorner;
348
+ pos() {
349
+ this.#checkParent();
350
+ const top = this.#tryGetVerticalCorner();
351
+ const left = this.#tryGetHorizontalCorner();
352
+ const $ppp = this.$popup;
353
+ if (top !== void 0 && left !== void 0) {
354
+ $ppp.style.top = top + "px";
355
+ $ppp.style.left = left + "px";
356
+ $ppp.style.right = "auto";
357
+ $ppp.style.bottom = "auto";
358
+ } else {
359
+ const { x, y } = this.#calcAttachPoint();
360
+ this.#place(x, y);
361
+ if (top !== void 0) {
362
+ $ppp.style.top = top + "px";
363
+ } else if (left !== void 0) {
364
+ $ppp.style.left = left + "px";
365
+ }
366
+ }
367
+ $ppp.style.boxShadow = `var(--gzm-corner-shadow-${this.#popupCorner})`;
368
+ }
369
+ #checkParent($ppp = this.$popup, $attachTo = this.$attachTo) {
370
+ const $c = getContainer($attachTo);
371
+ if ($ppp.isConnected) {
372
+ const $pc = getContainer($ppp);
373
+ if ($pc !== $c) {
374
+ $c.append($ppp);
375
+ }
376
+ } else {
377
+ $c.append($ppp);
378
+ }
379
+ checkPopupPosition($ppp);
380
+ $ppp.showPopover();
381
+ }
382
+ /**
383
+ * 计算位置
384
+ * @returns
385
+ */
386
+ #place(x, y) {
387
+ const dde = document.documentElement;
388
+ const $ppp = this.$popup;
389
+ switch (this.#popupCorner) {
390
+ case 0:
391
+ $ppp.style.right = "auto";
392
+ $ppp.style.bottom = "auto";
393
+ $ppp.style.left = x + "px";
394
+ $ppp.style.top = y + "px";
395
+ break;
396
+ case 1:
397
+ $ppp.style.right = "auto";
398
+ $ppp.style.top = "auto";
399
+ $ppp.style.left = x + "px";
400
+ $ppp.style.bottom = dde.clientHeight - y + "px";
401
+ break;
402
+ case 10:
403
+ $ppp.style.left = "auto";
404
+ $ppp.style.bottom = "auto";
405
+ $ppp.style.right = dde.clientWidth - x + "px";
406
+ $ppp.style.top = y + "px";
407
+ break;
408
+ case 11:
409
+ $ppp.style.left = "auto";
410
+ $ppp.style.top = "auto";
411
+ $ppp.style.right = dde.clientWidth - x + "px";
412
+ $ppp.style.bottom = dde.clientHeight - y + "px";
413
+ break;
414
+ }
415
+ }
416
+ /**
417
+ * 计算 attach-to 元素上挂靠点的坐标
418
+ * @returns
419
+ */
420
+ #calcAttachPoint() {
421
+ const rect = this.$attachTo.getBoundingClientRect();
422
+ let x = rect.x;
423
+ let y = rect.y;
424
+ switch (this.#attachCorner) {
425
+ case 1:
426
+ y += rect.height;
427
+ break;
428
+ case 10:
429
+ x += rect.width;
430
+ break;
431
+ case 11:
432
+ x += rect.width;
433
+ y += rect.height;
434
+ break;
435
+ }
436
+ return { x, y };
437
+ }
438
+ /**
439
+ * 计算挂靠点,直接覆盖原始的 #popupCorner 和 #attachCorner。
440
+ * @returns {top, bottom} 如果不为空,说明无法计算挂高点,那么直接计算 popup 的坐标返回。
441
+ */
442
+ #tryGetVerticalCorner() {
443
+ const dde = document.documentElement;
444
+ const oh = this.$popup.offsetHeight;
445
+ if (oh >= dde.clientHeight) {
446
+ return;
447
+ }
448
+ const corners = this.#calcVertialCornerAndSpace();
449
+ const h = corners.find((c2) => c2.popupCorner === this.#popupCorner && c2.attachCorner === this.#attachCorner).height;
450
+ if (oh <= h) {
451
+ return;
452
+ }
453
+ const c = corners.sort((a, b) => b.height - a.height)[0];
454
+ if (oh <= c.height) {
455
+ this.#popupCorner = c.popupCorner;
456
+ this.#attachCorner = c.attachCorner;
457
+ return;
458
+ }
459
+ let ret = 0;
460
+ if (c.popupCorner % 10 === 0) {
461
+ ret = dde.clientHeight - oh;
462
+ }
463
+ return ret;
464
+ }
465
+ /**
466
+ * 计算 attach-to 元素多个挂靠点和可用垂直空间的关系。
467
+ */
468
+ #calcVertialCornerAndSpace() {
469
+ const corners = this.#calcVerticalCorner();
470
+ const rect = this.$attachTo.getBoundingClientRect();
471
+ for (const c of corners) {
472
+ this.#calcVerticalSpace(c, rect);
473
+ }
474
+ return corners;
475
+ }
476
+ /**
477
+ * 在垂直方向上,attach-to 和 $popup 都有 2 个选项 top 和 bottom,组合在一起就是 4 个选项。
478
+ * 这里就需要将 4 个组合的可用垂直空间计算出来。
479
+ *
480
+ * 虽然这里计算的是垂直方向,但是仍然要把水平方向的一个因素考虑进来:
481
+ * 当 attach-to 和 $popup 是左侧对齐-挂靠点都在左侧,或者是右侧对齐时,上面4个组合中的2个会导致 attach-to 和 $popup 重叠在一起。
482
+ * 即左上角、右上角重叠 和 左下角、右下角重叠。
483
+ * 当原来就是重叠的,这里只计算重叠的。如果原来不是重叠的,则不计算重叠的。
484
+ * @returns
485
+ */
486
+ #calcVerticalCorner() {
487
+ const pc = this.#popupCorner;
488
+ const cornersOfPopup = pc < 10 ? [0, 1] : [10, 11];
489
+ const ac = this.#attachCorner;
490
+ const cornersOfAttach = ac < 10 ? [0, 1] : [10, 11];
491
+ let four = [];
492
+ for (const popupCorner of cornersOfPopup) {
493
+ for (const attachCorner of cornersOfAttach) {
494
+ four.push({ popupCorner, attachCorner });
495
+ }
496
+ }
497
+ if (pc < 10 && ac < 10 || pc >= 10 && ac >= 10) {
498
+ if (pc === ac) {
499
+ four = four.filter((f) => f.popupCorner === f.attachCorner);
500
+ } else {
501
+ four = four.filter((f) => f.popupCorner !== f.attachCorner);
502
+ }
503
+ }
504
+ return four;
505
+ }
506
+ /**
507
+ * 计算挂靠点可用垂直空间
508
+ */
509
+ #calcVerticalSpace(cp, attachToRect) {
510
+ const dde = document.documentElement;
511
+ const y = attachToRect.y;
512
+ if (cp.popupCorner % 10 === 0) {
513
+ if (cp.attachCorner % 10 === 0) {
514
+ cp.height = dde.clientHeight - y;
515
+ } else {
516
+ cp.height = dde.clientHeight - (y + attachToRect.height);
517
+ }
518
+ } else {
519
+ if (cp.attachCorner % 10 === 0) {
520
+ cp.height = y;
521
+ } else {
522
+ cp.height = y + attachToRect.height;
523
+ }
524
+ }
525
+ }
526
+ /**
527
+ * 注释参考:tryGetVerticalCorner
528
+ */
529
+ #tryGetHorizontalCorner() {
530
+ const dde = document.documentElement;
531
+ const ow = this.$popup.offsetWidth;
532
+ if (ow >= dde.clientWidth) {
533
+ return;
534
+ }
535
+ const corners = this.#calcHorizontalCornerAndSpace();
536
+ const w = corners.find((c2) => c2.popupCorner === this.#popupCorner && c2.attachCorner === this.#attachCorner).width;
537
+ if (ow <= w) {
538
+ return;
539
+ }
540
+ const c = corners.sort((a, b) => b.width - a.width)[0];
541
+ if (ow <= c.width) {
542
+ this.#popupCorner = c.popupCorner;
543
+ this.#attachCorner = c.attachCorner;
544
+ return;
545
+ }
546
+ let ret = 0;
547
+ if (c.popupCorner < 10) {
548
+ ret = dde.clientWidth - ow;
549
+ }
550
+ return ret;
551
+ }
552
+ /**
553
+ * 注释参考:#calcVertialCornerAndSpace
554
+ * @returns
555
+ */
556
+ #calcHorizontalCornerAndSpace() {
557
+ const corners = this.#calcHorizontalCorner();
558
+ const rect = this.$attachTo.getBoundingClientRect();
559
+ for (const c of corners) {
560
+ this.#calcHorizontalSpace(c, rect);
561
+ }
562
+ return corners;
563
+ }
564
+ /**
565
+ * 注释参考:#calcVerticalCorner
566
+ * @returns
567
+ */
568
+ #calcHorizontalCorner() {
569
+ const pc = this.#popupCorner;
570
+ const cornersOfPopup = pc % 10 === 0 ? [0, 10] : [1, 11];
571
+ const ac = this.#attachCorner;
572
+ const cornersOfAttach = ac % 10 === 0 ? [0, 10] : [1, 11];
573
+ let four = [];
574
+ for (const popupCorner of cornersOfPopup) {
575
+ for (const attachCorner of cornersOfAttach) {
576
+ four.push({ popupCorner, attachCorner });
577
+ }
578
+ }
579
+ if (pc % 10 === ac % 10) {
580
+ if (pc === ac) {
581
+ four = four.filter((f) => f.popupCorner === f.attachCorner);
582
+ } else {
583
+ four = four.filter((f) => f.popupCorner !== f.attachCorner);
584
+ }
585
+ }
586
+ return four;
587
+ }
588
+ /**
589
+ * 注释参考:#calcVerticalSpace
590
+ * @param {popupCorner, attachCorner} cs
591
+ */
592
+ #calcHorizontalSpace(cs, attachToRect) {
593
+ const dde = document.documentElement;
594
+ const x = attachToRect.x;
595
+ if (cs.popupCorner < 10) {
596
+ if (cs.attachCorner < 10) {
597
+ cs.width = dde.clientWidth - x;
598
+ } else {
599
+ cs.width = dde.clientWidth - (x + attachToRect.width);
600
+ }
601
+ } else {
602
+ if (cs.attachCorner < 10) {
603
+ cs.width = x;
604
+ } else {
605
+ cs.width = x + attachToRect.width;
606
+ }
607
+ }
608
+ }
609
+ }
610
+ function defineElement(ele) {
611
+ return function(constructor, ctx) {
612
+ ctx.addInitializer(function() {
613
+ defineCustomElement(constructor, ele);
614
+ });
615
+ };
616
+ }
617
+ function defineCustomElement(constructor, ele) {
618
+ const tagName2 = ele.tagName.toLowerCase();
619
+ if (customElements.get(tagName2)) {
620
+ throw new Error(tagName2 + " already defined");
621
+ }
622
+ if (ele.mutableAttributes) {
623
+ observedAttributes(constructor, ele.mutableAttributes, ele.copyAttributes);
624
+ }
625
+ customElements.define(tagName2, constructor);
626
+ if (ele.style) {
627
+ document.adoptedStyleSheets.push(ele.style);
628
+ }
629
+ }
630
+ function observedAttributes(constructor, mutableAttributes2, copyAttributes) {
631
+ Reflect.set(constructor, "observedAttributes", mutableAttributes2);
632
+ if (!constructor.prototype.attributeChangedCallback) {
633
+ constructor.prototype.attributeChangedCallback = attributeChangedCallback;
634
+ }
635
+ if (copyAttributes) {
636
+ for (const p in copyAttributes) {
637
+ if (!mutableAttributes2.includes(p)) {
638
+ throw new Error(`${constructor.name} 的属性 ${p} 不属于 mutableAttributes。`);
639
+ }
640
+ }
641
+ Reflect.set(constructor, staticCopyAttributesProperty, copyAttributes);
642
+ }
643
+ }
644
+ const staticCopyAttributesProperty = "gzmCopyAttributes";
645
+ function getAttributeSetHandlerName(name) {
646
+ return "_" + name.replaceAll("-", "_") + "_set";
647
+ }
648
+ function attributeChangedCallback(name, oldValue, newValue) {
649
+ if (staticCopyAttributesProperty in this.constructor) {
650
+ const cas = this.constructor[staticCopyAttributesProperty];
651
+ if (cas) {
652
+ if (name in cas) {
653
+ const ele = cas[name];
654
+ if (ele) {
655
+ doCopyAttributes.call(this, name, newValue, ele);
656
+ }
657
+ }
658
+ }
659
+ }
660
+ const funcName = getAttributeSetHandlerName(name);
661
+ const func = Reflect.get(this, funcName);
662
+ if (typeof func === "function") {
663
+ func.call(this, newValue, oldValue);
664
+ }
665
+ }
666
+ function doCopyAttributes(attr, newValue, ele) {
667
+ ele = typeof ele === "string" ? [ele] : ele;
668
+ for (const e of ele) {
669
+ const $ele = Reflect.get(this, e);
670
+ if ($ele) {
671
+ if (newValue === null) {
672
+ $ele.removeAttribute(attr);
673
+ } else {
674
+ $ele.setAttribute(attr, newValue);
675
+ }
676
+ }
677
+ }
678
+ }
679
+ function debounce(func, wait = 200) {
680
+ let timeout = null;
681
+ return function(...args) {
682
+ if (timeout) clearTimeout(timeout);
683
+ timeout = window.setTimeout(() => {
684
+ timeout = null;
685
+ func.apply(this, args);
686
+ }, wait);
687
+ };
688
+ }
689
+ function generateId() {
690
+ return Math.random().toString(36).slice(2);
691
+ }
692
+ const zh = {
693
+ close: "关闭",
694
+ true: "✔️",
695
+ false: "❌",
696
+ undefined: "未定义",
697
+ default: "默认",
698
+ valueMissing: "请填写此字段。",
699
+ //input 验证 required 的默认错误信息。
700
+ count: "计数",
701
+ min: "最小",
702
+ max: "最大",
703
+ sum: "合计",
704
+ avg: "平均",
705
+ hide: "隐藏",
706
+ del: "删除",
707
+ asc: "升序",
708
+ desc: "降序",
709
+ ok: "确定",
710
+ cancel: "取消",
711
+ waiting: "正在处理中,请稍候...",
712
+ confirming: "请确认:{0} ?",
713
+ completed: "已完成",
714
+ error: "错误",
715
+ attention: "注意",
716
+ noMenuSet: "未设置菜单!?",
717
+ readonly: "只读"
718
+ };
719
+ const en = {
720
+ true: "✔️",
721
+ false: "❌",
722
+ valueMissing: "Please fill in this field.",
723
+ //input 验证 required 的默认错误信息。
724
+ del: "delete",
725
+ asc: "ascending",
726
+ desc: "descending",
727
+ waiting: "Processing, please wait...",
728
+ confirming: "Please confirm: {0} ?",
729
+ noMenuSet: "No menu to display!?"
730
+ };
731
+ const globalTexts = { zh, en };
732
+ const defaultLangChain = ["zh"];
733
+ const bindHtmlElement = "bindHtmlElement";
734
+ function getTargetTxt(target, property, receiver) {
735
+ if (property === bindHtmlElement) {
736
+ return function($ele2) {
737
+ target.$ele = $ele2;
738
+ target.langs = void 0;
739
+ return receiver;
740
+ };
741
+ }
742
+ let { langs, $ele } = target;
743
+ if (!langs) {
744
+ if ($ele) {
745
+ if ($ele.isConnected) {
746
+ $ele = findLangElement($ele);
747
+ if ($ele) {
748
+ langs = target.langs = createLangArray($ele.lang);
749
+ target.$ele = void 0;
750
+ }
751
+ }
752
+ }
753
+ }
754
+ langs ??= defaultLangChain;
755
+ const texts = target.texts;
756
+ for (let i = 0; i < langs.length; i++) {
757
+ const lang = langs[i];
758
+ if (!lang) {
759
+ continue;
760
+ }
761
+ for (let j = 0; j < texts.length; j++) {
762
+ const txt = texts[j];
763
+ if (!txt) {
764
+ continue;
765
+ }
766
+ if (lang in txt) {
767
+ const langTxts = txt[lang];
768
+ if (langTxts && property in langTxts) {
769
+ let ret = langTxts[property];
770
+ if (ret) {
771
+ if (!ret.includes("{0}")) {
772
+ return ret;
773
+ }
774
+ return (...args) => {
775
+ args = args.flat();
776
+ for (let i2 = 0; i2 < args.length; i2++) {
777
+ const a = args[i2];
778
+ const r = "{" + i2 + "}";
779
+ ret = ret.replaceAll(r, String(a));
780
+ }
781
+ return ret;
782
+ };
783
+ }
784
+ }
785
+ }
786
+ }
787
+ }
788
+ return property;
789
+ }
790
+ function createText(...txts) {
791
+ const target = {
792
+ texts: txts.filter((t) => t).map((t) => t)
793
+ };
794
+ if (document.documentElement.lang) {
795
+ target.langs = createLangArray(document.documentElement.lang);
796
+ }
797
+ return new Proxy(target, {
798
+ get: getTargetTxt
799
+ });
800
+ }
801
+ const GT = createText(globalTexts);
802
+ function createLangArray(lang) {
803
+ if (!lang) {
804
+ return defaultLangChain;
805
+ }
806
+ const sa = lang.split("-");
807
+ const ret = [lang];
808
+ for (let i = sa.length - 1; i > 0; i--) {
809
+ const tmp = sa.slice(0, i);
810
+ ret.push(tmp.join("-"));
811
+ }
812
+ return ret;
813
+ }
814
+ function findLangElement($ele) {
815
+ if ($ele instanceof HTMLElement && $ele.lang) return $ele;
816
+ if (!$ele.isConnected) return findLangElement(document.body);
817
+ const $p = $ele.closest("*[lang]");
818
+ if ($p instanceof HTMLElement && $p.lang) {
819
+ return $p;
820
+ }
821
+ const sr = $ele.getRootNode();
822
+ if (sr instanceof ShadowRoot) {
823
+ return findLangElement(sr.host);
824
+ }
825
+ return void 0;
826
+ }
827
+ function createStyleSheet(style2) {
828
+ const sheet = new CSSStyleSheet();
829
+ for (const selector in style2) {
830
+ const rules = style2[selector];
831
+ if (typeof rules === "string") {
832
+ sheet.insertRule(`${selector} { ${rules} }`);
833
+ } else if (rules) {
834
+ const ruleStr = formatRules(rules);
835
+ sheet.insertRule(`${selector} { ${ruleStr} }`);
836
+ }
837
+ }
838
+ return sheet;
839
+ }
840
+ function formatRules(rules) {
841
+ let ruleStr = "";
842
+ for (const prop in rules) {
843
+ ruleStr += `${prop}: ${rules[prop]}; `;
844
+ }
845
+ return ruleStr;
846
+ }
847
+ function getElementRules(tagName2, ...ruleNames) {
848
+ const $ele = document.createElement(tagName2);
849
+ document.body.append($ele);
850
+ const cs = getComputedStyle($ele);
851
+ const ret = {};
852
+ ruleNames.forEach((x) => {
853
+ if (x in cs) {
854
+ ret[x] = Reflect.get(cs, x);
855
+ }
856
+ });
857
+ $ele.remove();
858
+ return ret;
859
+ }
860
+ const disabledStyle = {
861
+ "[disabled], [disabled]>*": `
862
+ opacity: 0.5;
863
+ cursor: not-allowed;
864
+ pointer-events: none;
865
+ user-select: none;
866
+ `
867
+ };
868
+ const baseStyle = createStyleSheet({
869
+ "*, :after, :before, ::backdrop": `
870
+ box-sizing: border-box;
871
+ border: 0 solid;
872
+ margin: 0;
873
+ padding: 0;
874
+ `,
875
+ //因其语义价值成为强调内容的优先选择
876
+ strong: `
877
+ font-weight: bolder;
878
+ `,
879
+ //适用于语义化标注次要内容。默认字体大小为16px,75%=12px,也是能够正常显示的最小字体。
880
+ small: `
881
+ font-size: 75%;
882
+ `,
883
+ '[hidden]:where(:not([hidden="until-found"]))': `
884
+ display: none !important;
885
+ `,
886
+ //这个不属于 base,但我认为有用
887
+ ...disabledStyle
888
+ });
889
+ const gzmHeader = `
890
+ background: var(--gzm-header-background);
891
+ border: var(--gzm-header-border);
892
+ color: var(--gzm-header-txt-color);
893
+ `;
894
+ const gzmFrame = `
895
+ background: var(--gzm-content-background);
896
+ color: var(--gzm-content-txt-color);
897
+ border-radius: 0.5rem;
898
+ border: var(--gzm-btn-border);
899
+ padding: 0.5rem;
900
+ `;
901
+ const utilityStyle = createStyleSheet({
902
+ ".gzm-frame": gzmFrame,
903
+ ".gzm-header": gzmHeader,
904
+ //txt-btn
905
+ ".gzm-txt-btn": {
906
+ cursor: "pointer",
907
+ "font-weight": "bolder",
908
+ "border-radius": "0.25rem",
909
+ "padding-inline": "0.25rem",
910
+ "white-space": "nowrap",
911
+ background: "transparent",
912
+ color: "inherit",
913
+ "font-size": "inherit",
914
+ "outline-offset": "-1px"
915
+ //当按钮所在父元素的padding不够,导致outline无法全部显示出来。
916
+ },
917
+ ".gzm-txt-btn:hover": {
918
+ color: "var(--gzm-h-btn-txt-color)",
919
+ outline: "var(--gzm-h-btn-border)",
920
+ background: "var(--gzm-h-btn-background)"
921
+ },
922
+ ".gzm-txt-btn:active": {
923
+ color: "var(--gzm-a-btn-txt-color) !important",
924
+ outline: "var(--gzm-a-btn-border) !important",
925
+ background: "var(--gzm-a-btn-background) !important"
926
+ },
927
+ //直接在 document 中使用 gzm-btn-*,且 disabled = true 时,靠这个生效
928
+ ...disabledStyle
929
+ });
930
+ function createTxtBtn(txt) {
931
+ const $btn = document.createElement("button");
932
+ $btn.type = "button";
933
+ $btn.className = "gzm-txt-btn";
934
+ $btn.textContent = txt;
935
+ return $btn;
936
+ }
937
+ function isTxtBtn($btn) {
938
+ return $btn.classList.contains("gzm-txt-btn");
939
+ }
940
+ const defaultTheme = {
941
+ ":root": `
942
+ --gzm-border-color: rgb(197,197,197);
943
+
944
+ --gzm-btn-background: rgb(246,246,246);
945
+ --gzm-btn-border: 1px solid var(--gzm-border-color);
946
+ --gzm-btn-txt-color: rgb(69,69,69);
947
+
948
+ --gzm-h-btn-background: rgb(237,237,237);
949
+ --gzm-h-btn-border: 1px solid rgb(204,204,204);
950
+ --gzm-h-btn-txt-color: rgb(43,43,43);
951
+
952
+ --gzm-a-btn-background: rgb(0,127,255);
953
+ --gzm-a-btn-border: 1px solid rgb(0,62,255);
954
+ --gzm-a-btn-txt-color: rgb(255,255,255);
955
+
956
+ --gzm-header-background: rgb(233,233,233);
957
+ --gzm-header-border: 1px solid rgb(221,221,221);
958
+ --gzm-header-txt-color: rgb(51,51,51);
959
+
960
+ --gzm-background-color: rgb(255,255,255);
961
+
962
+ --gzm-content-background: var(--gzm-background-color);
963
+ --gzm-content-txt-color: rgb(51,51,51);
964
+
965
+ --gzm-error-txt-color: #d34d17;
966
+
967
+ --gzm-badge-background: rgb(253,223,223);
968
+ --gzm-badge-txt-color: rgb(95,63,63);
969
+
970
+ --gzm-shadow-color: rgb(102,102,102);
971
+
972
+ --gzm-corner-shadow-11:-7px -7px 7px var(--gzm-shadow-color);
973
+ --gzm-corner-shadow-0:7px 7px 7px var(--gzm-shadow-color);
974
+ --gzm-corner-shadow-10:-7px 7px 7px var(--gzm-shadow-color);
975
+ --gzm-corner-shadow-1:7px -7px 7px var(--gzm-shadow-color);
976
+
977
+ --gzm-shadow-top: drop-shadow(0px -2px 4px var(--gzm-shadow-color));
978
+ --gzm-shadow-left: drop-shadow(-2px 0px 4px var(--gzm-shadow-color));
979
+ --gzm-shadow-right: drop-shadow(2px 0px 4px var(--gzm-shadow-color));
980
+ --gzm-shadow-bottom: drop-shadow(0px 2px 4px var(--gzm-shadow-color));
981
+
982
+ --gzm-switch-background: #999;
983
+ --gzm-switch-check-background: #67c93d;
984
+ `,
985
+ ":root dialog::backdrop": `
986
+ background: rgb(170,170,170);
987
+ opacity: 0.8;
988
+ `
989
+ };
990
+ document.adoptedStyleSheets.push(createStyleSheet(defaultTheme));
991
+ const themeLocalStorageKey = "gzm-ui-basic-theme";
992
+ const htmlThemeAttr = "gzm-theme";
993
+ const allThemes = [];
994
+ function getCurrentTheme() {
995
+ return localStorage.getItem(themeLocalStorageKey) ?? "";
996
+ }
997
+ function setCurrentTheme(themeName) {
998
+ if (themeName && !allThemes.some((theme) => theme.name === themeName)) {
999
+ return false;
1000
+ }
1001
+ localStorage.setItem(themeLocalStorageKey, themeName);
1002
+ document.documentElement.setAttribute(htmlThemeAttr, themeName);
1003
+ return true;
1004
+ }
1005
+ const ct = getCurrentTheme();
1006
+ if (ct) {
1007
+ document.documentElement.setAttribute(htmlThemeAttr, ct);
1008
+ }
1009
+ window.addEventListener("storage", (event) => {
1010
+ if (event.key === themeLocalStorageKey && event.newValue) {
1011
+ document.documentElement.setAttribute(htmlThemeAttr, event.newValue);
1012
+ }
1013
+ });
1014
+ var __create$2 = Object.create;
1015
+ var __defProp$2 = Object.defineProperty;
1016
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1017
+ var __knownSymbol$2 = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
1018
+ var __typeError$2 = (msg) => {
1019
+ throw TypeError(msg);
1020
+ };
1021
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1022
+ var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
1023
+ var __decoratorStart$2 = (base) => [, , , __create$2(base?.[__knownSymbol$2("metadata")] ?? null)];
1024
+ var __decoratorStrings$2 = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
1025
+ var __expectFn$2 = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError$2("Function expected") : fn;
1026
+ var __decoratorContext$2 = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings$2[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError$2("Already initialized") : fns.push(__expectFn$2(fn || null)) });
1027
+ var __decoratorMetadata$2 = (array, target) => __defNormalProp$2(target, __knownSymbol$2("metadata"), array[3]);
1028
+ var __runInitializers$2 = (array, flags, self, value) => {
1029
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
1030
+ return value;
1031
+ };
1032
+ var __decorateElement$2 = (array, flags, name, decorators, target, extra) => {
1033
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
1034
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings$2[k + 5];
1035
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
1036
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc$2(k < 4 ? target : { get [name]() {
1037
+ return __privateGet$2(this, extra);
1038
+ }, set [name](x) {
1039
+ return __privateSet$2(this, extra, x);
1040
+ } }, name));
1041
+ k ? p && k < 4 && __name$2(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name$2(target, name);
1042
+ for (var i = decorators.length - 1; i >= 0; i--) {
1043
+ ctx = __decoratorContext$2(k, name, done = {}, array[3], extraInitializers);
1044
+ if (k) {
1045
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn$2(target, x) : (x) => name in x };
1046
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet$2 : __privateMethod$2)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
1047
+ if (k > 2) access.set = p ? (x, y) => __privateSet$2(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
1048
+ }
1049
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
1050
+ if (k ^ 4 || it === void 0) __expectFn$2(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
1051
+ else if (typeof it !== "object" || it === null) __typeError$2("Object expected");
1052
+ else __expectFn$2(fn = it.get) && (desc.get = fn), __expectFn$2(fn = it.set) && (desc.set = fn), __expectFn$2(fn = it.init) && initializers.unshift(fn);
1053
+ }
1054
+ return k || __decoratorMetadata$2(array, target), desc && __defProp$2(target, name, desc), p ? k ^ 4 ? extra : desc : target;
1055
+ };
1056
+ var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
1057
+ var __privateIn$2 = (member, obj) => Object(obj) !== obj ? __typeError$2('Cannot use the "in" operator on this value') : member.has(obj);
1058
+ var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1059
+ var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1060
+ var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
1061
+ var __privateMethod$2 = (obj, member, method) => (__accessCheck$2(obj, member, "access private method"), method);
1062
+ var _corner_dec$1, _badge_dec, _a$2, _Badge_decorators, _init$2, _badge, _corner$1;
1063
+ const tagName$2 = "GZM-BADGE";
1064
+ const styleSheet$1 = createStyleSheet({
1065
+ ":host": `
1066
+ height: 1rem;
1067
+ border-radius: 50%;
1068
+ padding: 0 0.25rem !important;
1069
+
1070
+ color: var(--gzm-badge-txt-color);
1071
+ background: var(--gzm-badge-background);
1072
+
1073
+ line-height: 1rem;
1074
+
1075
+ font-family: PingFang SC, Microsoft YaHei, Hiragino Sans GB, Heiti SC, sans-serif;
1076
+ font-size: 0.75rem;
1077
+ font-weight: bolder;
1078
+ `
1079
+ });
1080
+ const cornerStyleSheet$1 = createStyleSheet({
1081
+ ":host": `
1082
+ transform: translate(33%, -33%);
1083
+ position: absolute;
1084
+ top: 0px;
1085
+ right: 0px;
1086
+ z-index: 1;
1087
+ `
1088
+ });
1089
+ const mutableAttributes$2 = ["badge", "corner"];
1090
+ _Badge_decorators = [defineElement({ tagName: tagName$2, mutableAttributes: mutableAttributes$2 })];
1091
+ class Badge extends (_a$2 = HTMLElement, _badge_dec = [strAttr], _corner_dec$1 = [boolAttr], _a$2) {
1092
+ constructor() {
1093
+ super();
1094
+ __privateAdd$2(this, _badge, __runInitializers$2(_init$2, 8, this)), __runInitializers$2(_init$2, 11, this);
1095
+ __privateAdd$2(this, _corner$1, __runInitializers$2(_init$2, 12, this)), __runInitializers$2(_init$2, 15, this);
1096
+ const sr = this.attachShadow({ mode: "open" });
1097
+ sr.adoptedStyleSheets = [baseStyle, styleSheet$1];
1098
+ }
1099
+ _badge_set(badge) {
1100
+ this.shadowRoot.innerHTML = badge ?? "";
1101
+ }
1102
+ _corner_set() {
1103
+ this.shadowRoot.adoptedStyleSheets = this.corner ? [baseStyle, styleSheet$1, cornerStyleSheet$1] : [baseStyle, styleSheet$1];
1104
+ }
1105
+ }
1106
+ _init$2 = __decoratorStart$2(_a$2);
1107
+ _badge = /* @__PURE__ */ new WeakMap();
1108
+ _corner$1 = /* @__PURE__ */ new WeakMap();
1109
+ __decorateElement$2(_init$2, 4, "badge", _badge_dec, Badge, _badge);
1110
+ __decorateElement$2(_init$2, 4, "corner", _corner_dec$1, Badge, _corner$1);
1111
+ Badge = __decorateElement$2(_init$2, 0, "Badge", _Badge_decorators, Badge);
1112
+ __runInitializers$2(_init$2, 1, Badge);
1113
+ var __create$1 = Object.create;
1114
+ var __defProp$1 = Object.defineProperty;
1115
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
1116
+ var __knownSymbol$1 = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
1117
+ var __typeError$1 = (msg) => {
1118
+ throw TypeError(msg);
1119
+ };
1120
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1121
+ var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
1122
+ var __decoratorStart$1 = (base) => [, , , __create$1(base?.[__knownSymbol$1("metadata")] ?? null)];
1123
+ var __decoratorStrings$1 = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
1124
+ var __expectFn$1 = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError$1("Function expected") : fn;
1125
+ var __decoratorContext$1 = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings$1[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError$1("Already initialized") : fns.push(__expectFn$1(fn || null)) });
1126
+ var __decoratorMetadata$1 = (array, target) => __defNormalProp$1(target, __knownSymbol$1("metadata"), array[3]);
1127
+ var __runInitializers$1 = (array, flags, self, value) => {
1128
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
1129
+ return value;
1130
+ };
1131
+ var __decorateElement$1 = (array, flags, name, decorators, target, extra) => {
1132
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
1133
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings$1[k + 5];
1134
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
1135
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc$1(k < 4 ? target : { get [name]() {
1136
+ return __privateGet$1(this, extra);
1137
+ }, set [name](x) {
1138
+ return __privateSet$1(this, extra, x);
1139
+ } }, name));
1140
+ k ? p && k < 4 && __name$1(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name$1(target, name);
1141
+ for (var i = decorators.length - 1; i >= 0; i--) {
1142
+ ctx = __decoratorContext$1(k, name, done = {}, array[3], extraInitializers);
1143
+ if (k) {
1144
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn$1(target, x) : (x) => name in x };
1145
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet$1 : __privateMethod$1)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
1146
+ if (k > 2) access.set = p ? (x, y) => __privateSet$1(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
1147
+ }
1148
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
1149
+ if (k ^ 4 || it === void 0) __expectFn$1(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
1150
+ else if (typeof it !== "object" || it === null) __typeError$1("Object expected");
1151
+ else __expectFn$1(fn = it.get) && (desc.get = fn), __expectFn$1(fn = it.set) && (desc.set = fn), __expectFn$1(fn = it.init) && initializers.unshift(fn);
1152
+ }
1153
+ return k || __decoratorMetadata$1(array, target), desc && __defProp$1(target, name, desc), p ? k ^ 4 ? extra : desc : target;
1154
+ };
1155
+ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
1156
+ var __privateIn$1 = (member, obj) => Object(obj) !== obj ? __typeError$1('Cannot use the "in" operator on this value') : member.has(obj);
1157
+ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1158
+ var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1159
+ var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
1160
+ var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
1161
+ var _corner_dec, _a$1, _CloseBtn_decorators, _init$1, _corner;
1162
+ const tagName$1 = "GZM-CLOSE-BTN";
1163
+ const styleSheet = createStyleSheet({
1164
+ ":host": `
1165
+ font-family: ui-sans-serif, system-ui, sans-serif;
1166
+ font-size: 0.75rem;
1167
+ font-weight: bold;
1168
+ line-height: 1rem;
1169
+ display: inline-block;
1170
+ `,
1171
+ div: `
1172
+ border-radius: 9999px;
1173
+ padding-inline: 0.25rem;
1174
+ padding-block: 0px;
1175
+ `,
1176
+ [`div:hover`]: {
1177
+ color: "var(--gzm-badge-txt-color)",
1178
+ background: "var(--gzm-badge-background)",
1179
+ cursor: "pointer"
1180
+ }
1181
+ });
1182
+ const cornerStyleSheet = createStyleSheet({
1183
+ ":host": `
1184
+ position: absolute;
1185
+ right: 0px;
1186
+ top: 0px;
1187
+ `
1188
+ });
1189
+ const mutableAttributes$1 = ["corner"];
1190
+ _CloseBtn_decorators = [defineElement({ tagName: tagName$1, mutableAttributes: mutableAttributes$1 })];
1191
+ class CloseBtn extends (_a$1 = HTMLElement, _corner_dec = [boolAttr], _a$1) {
1192
+ constructor() {
1193
+ super();
1194
+ __privateAdd$1(this, _corner, __runInitializers$1(_init$1, 8, this)), __runInitializers$1(_init$1, 11, this);
1195
+ const root = this.attachShadow({ mode: "open" });
1196
+ root.adoptedStyleSheets = [baseStyle, styleSheet];
1197
+ root.innerHTML = "<div>╳</div>";
1198
+ }
1199
+ // #region 属性
1200
+ _corner_set() {
1201
+ this.shadowRoot.adoptedStyleSheets = this.corner ? [baseStyle, styleSheet, cornerStyleSheet] : [baseStyle, styleSheet];
1202
+ }
1203
+ // #endregion
1204
+ }
1205
+ _init$1 = __decoratorStart$1(_a$1);
1206
+ _corner = /* @__PURE__ */ new WeakMap();
1207
+ __decorateElement$1(_init$1, 4, "corner", _corner_dec, CloseBtn, _corner);
1208
+ CloseBtn = __decorateElement$1(_init$1, 0, "CloseBtn", _CloseBtn_decorators, CloseBtn);
1209
+ __runInitializers$1(_init$1, 1, CloseBtn);
1210
+ const iconCache = {};
1211
+ var __create = Object.create;
1212
+ var __defProp = Object.defineProperty;
1213
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1214
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
1215
+ var __typeError = (msg) => {
1216
+ throw TypeError(msg);
1217
+ };
1218
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1219
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1220
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
1221
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
1222
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
1223
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
1224
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
1225
+ var __runInitializers = (array, flags, self, value) => {
1226
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
1227
+ return value;
1228
+ };
1229
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
1230
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
1231
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
1232
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
1233
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
1234
+ return __privateGet(this, extra);
1235
+ }, set [name](x) {
1236
+ return __privateSet(this, extra, x);
1237
+ } }, name));
1238
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
1239
+ for (var i = decorators.length - 1; i >= 0; i--) {
1240
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
1241
+ if (k) {
1242
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
1243
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
1244
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
1245
+ }
1246
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
1247
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
1248
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
1249
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
1250
+ }
1251
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
1252
+ };
1253
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
1254
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
1255
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1256
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1257
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
1258
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
1259
+ var _icon_dec, _a, _Icon_decorators, _Icon_instances, showStr_fn, showCache_fn, showUnicode_fn, _init, _icon;
1260
+ const style = createStyleSheet({
1261
+ //防止网页中没有定义这些字体。如'⚙'在没有 Emoji 字体加持的情况下,显示非常难看。
1262
+ //默认不要 inline-block,选中一行包含 icon 的文字时,可以看出明显区别。
1263
+ ":host": `
1264
+ /*display: inline-block;*/
1265
+ font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
1266
+ `,
1267
+ //height - 相对于父元素的字体高度,这是关键!
1268
+ "img, svg": `
1269
+ width: 1em;
1270
+ height: 1em;
1271
+ vertical-align: middle;
1272
+ color: inherit;
1273
+ `
1274
+ });
1275
+ const tagName = "GZM-ICON";
1276
+ const mutableAttributes = ["icon"];
1277
+ _Icon_decorators = [defineElement({ tagName, mutableAttributes })];
1278
+ class Icon extends (_a = HTMLElement, _icon_dec = [strAttr], _a) {
1279
+ constructor() {
1280
+ super();
1281
+ __privateAdd(this, _Icon_instances);
1282
+ __privateAdd(this, _icon, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
1283
+ const sr = this.attachShadow({ mode: "open" });
1284
+ sr.adoptedStyleSheets = [baseStyle, style];
1285
+ }
1286
+ setImg(icon) {
1287
+ if (icon.startsWith("data:image/") || icon.includes(".") && icon.includes("/")) {
1288
+ this.shadowRoot.innerHTML = `<img src="${icon}" alt="icon">`;
1289
+ return true;
1290
+ }
1291
+ return false;
1292
+ }
1293
+ setSvg(icon) {
1294
+ if (icon.startsWith("<svg ")) {
1295
+ this.shadowRoot.innerHTML = icon;
1296
+ return true;
1297
+ }
1298
+ return false;
1299
+ }
1300
+ // #region 属性
1301
+ _icon_set(icon) {
1302
+ if (icon) {
1303
+ void (__privateMethod(this, _Icon_instances, showStr_fn).call(this, icon) || __privateMethod(this, _Icon_instances, showCache_fn).call(this, icon) || __privateMethod(this, _Icon_instances, showUnicode_fn).call(this, icon));
1304
+ } else {
1305
+ this.shadowRoot.innerHTML = "";
1306
+ }
1307
+ }
1308
+ // #endregion
1309
+ }
1310
+ _init = __decoratorStart(_a);
1311
+ _Icon_instances = /* @__PURE__ */ new WeakSet();
1312
+ showStr_fn = function(icon) {
1313
+ return this.setSvg(icon) || this.setImg(icon);
1314
+ };
1315
+ showCache_fn = function(p) {
1316
+ const cache = iconCache[p];
1317
+ if (!cache) return false;
1318
+ if (typeof cache === "string") {
1319
+ return __privateMethod(this, _Icon_instances, showStr_fn).call(this, cache);
1320
+ }
1321
+ if (cache instanceof HTMLImageElement) {
1322
+ return this.setImg(cache.src);
1323
+ }
1324
+ return false;
1325
+ };
1326
+ showUnicode_fn = function(icon) {
1327
+ this.shadowRoot.textContent = icon;
1328
+ };
1329
+ _icon = /* @__PURE__ */ new WeakMap();
1330
+ __decorateElement(_init, 4, "icon", _icon_dec, Icon, _icon);
1331
+ Icon = __decorateElement(_init, 0, "Icon", _Icon_decorators, Icon);
1332
+ __runInitializers(_init, 1, Icon);
1333
+ export {
1334
+ Badge,
1335
+ CenterHelper,
1336
+ CloseBtn,
1337
+ CornerHelper,
1338
+ GT,
1339
+ Icon,
1340
+ allThemes,
1341
+ attachBorderAttributeName,
1342
+ tagName$2 as badgeTagName,
1343
+ baseStyle,
1344
+ boolAttr,
1345
+ borders,
1346
+ tagName$1 as closeTagName,
1347
+ createStyleSheet,
1348
+ createText,
1349
+ createTxtBtn,
1350
+ debounce,
1351
+ defineElement,
1352
+ generateId,
1353
+ getCurrentTheme,
1354
+ getElementRules,
1355
+ getSnakeCaseName,
1356
+ globalTexts,
1357
+ gzmFrame,
1358
+ gzmHeader,
1359
+ htmlThemeAttr,
1360
+ iconCache,
1361
+ tagName as iconTagName,
1362
+ intAttr,
1363
+ isLeftCorner,
1364
+ isTopCorner,
1365
+ isTxtBtn,
1366
+ makeCorner,
1367
+ saAttr,
1368
+ setCurrentTheme,
1369
+ strAttr,
1370
+ utilityStyle,
1371
+ xy
1372
+ };
1373
+ //# sourceMappingURL=ui-basic.es.js.map