litos-ui 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base.d.ts +1 -1
- package/lib/base.js +3 -3
- package/lib/carousel/index.d.ts +20 -0
- package/lib/carousel/index.js +280 -0
- package/lib/carousel/item.d.ts +6 -0
- package/lib/carousel/item.js +15 -0
- package/lib/carousel/timer.d.ts +5 -0
- package/lib/carousel/timer.js +19 -0
- package/lib/check/check.d.ts +22 -0
- package/lib/check/check.js +81 -0
- package/lib/check/checkbox.d.ts +7 -0
- package/lib/check/checkbox.js +25 -0
- package/lib/check/checkbox_group.d.ts +9 -0
- package/lib/check/checkbox_group.js +33 -0
- package/lib/check/index.d.ts +12 -0
- package/lib/check/index.js +35 -0
- package/lib/check/radio.d.ts +6 -0
- package/lib/check/radio.js +19 -0
- package/lib/check/radio_group.d.ts +6 -0
- package/lib/check/radio_group.js +24 -0
- package/lib/check-BlDsQQo0.js +4 -0
- package/lib/color_picker/index.d.ts +1 -1
- package/lib/color_picker/index.js +5 -5
- package/lib/form/form_inner.d.ts +1 -8
- package/lib/form/form_inner.js +31 -39
- package/lib/form/form_item.d.ts +1 -1
- package/lib/form/form_item.js +30 -37
- package/lib/form/index.js +5 -5
- package/lib/icon/close_filled.d.ts +1 -1
- package/lib/index.d.ts +12 -4
- package/lib/index.js +80 -72
- package/lib/input/index.js +10 -10
- package/lib/list/index.d.ts +1 -2
- package/lib/list/index.js +17 -17
- package/lib/md_input/index.js +9 -9
- package/lib/menu/index.d.ts +2 -0
- package/lib/menu/index.js +47 -42
- package/lib/menu/sub_menu.d.ts +4 -2
- package/lib/menu/sub_menu.js +59 -41
- package/lib/select_ori/index.d.ts +1 -1
- package/lib/select_ori/index.js +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +49 -49
- package/lib/utils/transition.js +3 -2
- package/package.json +1 -1
- package/lib/checkbox/index.d.ts +0 -17
- package/lib/checkbox/index.js +0 -135
- package/lib/radio/index.d.ts +0 -28
- package/lib/radio/index.js +0 -122
package/lib/base.d.ts
CHANGED
|
@@ -51,5 +51,5 @@ export default class BaseComponent extends HTMLElement {
|
|
|
51
51
|
* @param eventOption 自定义事件配置选项, 默认: bubbles: true
|
|
52
52
|
* @returns 是否成功触发事件
|
|
53
53
|
*/
|
|
54
|
-
emit(name: string, eventOption
|
|
54
|
+
emit(name: string, eventOption?: Partial<CustomEventInit>): boolean;
|
|
55
55
|
}
|
package/lib/base.js
CHANGED
|
@@ -4,7 +4,7 @@ class i extends HTMLElement {
|
|
|
4
4
|
/** 组件是否渲染完成, 是否已经调用 connectedCallback */
|
|
5
5
|
rendered = !1;
|
|
6
6
|
constructor(t = !0, e = {}) {
|
|
7
|
-
super(), t && this.attachShadow({ mode: "open", ...e });
|
|
7
|
+
super(), this.rendered = !1, t && this.attachShadow({ mode: "open", ...e });
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* 返回一个数组,表示观察的属性列表
|
|
@@ -13,7 +13,7 @@ class i extends HTMLElement {
|
|
|
13
13
|
return [];
|
|
14
14
|
}
|
|
15
15
|
// 当属性发生变化时调用的回调函数
|
|
16
|
-
attributeChangedCallback(t, e,
|
|
16
|
+
attributeChangedCallback(t, e, s) {
|
|
17
17
|
}
|
|
18
18
|
/** @deprecated */
|
|
19
19
|
get shadow() {
|
|
@@ -45,7 +45,7 @@ class i extends HTMLElement {
|
|
|
45
45
|
} else t.length ? this.root.append(...t) : this.root.append(t);
|
|
46
46
|
}
|
|
47
47
|
connectedCallback() {
|
|
48
|
-
this.appendToRoot(this.render()), this.initEvents(), this.afterInit()
|
|
48
|
+
this.appendToRoot(this.render()), this.rendered = !0, this.initEvents(), this.afterInit();
|
|
49
49
|
}
|
|
50
50
|
disconnectedCallback() {
|
|
51
51
|
this.removeEvents(), this.beforeDestroy(), this.root.innerHTML = "", this.rendered = !1;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BaseComponent from "../base";
|
|
2
|
+
export default class Carousel extends BaseComponent {
|
|
3
|
+
#private;
|
|
4
|
+
static baseName: string;
|
|
5
|
+
/** 是否显示箭头 */
|
|
6
|
+
arrows: "hover" | "always" | "never";
|
|
7
|
+
currentIndex: number;
|
|
8
|
+
allIndex: number;
|
|
9
|
+
loop: boolean;
|
|
10
|
+
observer?: MutationObserver;
|
|
11
|
+
autoplay: boolean;
|
|
12
|
+
static get observedAttributes(): string[];
|
|
13
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
|
|
14
|
+
connectedCallback(): void;
|
|
15
|
+
afterInit(): void;
|
|
16
|
+
beforeDestroy(): void;
|
|
17
|
+
render(): DocumentFragment;
|
|
18
|
+
renderArrows(fragment: DocumentFragment): void;
|
|
19
|
+
renderNavigationButton(dir: "prev" | "next" | undefined, fragment: DocumentFragment): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import u from "../base.js";
|
|
2
|
+
import { getAttr as m, on as l, $one as h, off as r, $$ as c, $ as p, iterate as f, shouldEventNext as v } from "ph-utils/dom";
|
|
3
|
+
import { debounce as x } from "ph-utils/web";
|
|
4
|
+
import { parseAttrValue as d } from "../utils/index.js";
|
|
5
|
+
import b from "./timer.js";
|
|
6
|
+
const g = ":host{display:block;width:100%;height:180px;margin:0 auto;box-sizing:border-box;position:relative;overflow:hidden}.container{min-width:900%;height:100%;box-sizing:border-box;position:relative;display:flex}.nav-button{position:absolute;top:50%;transform:translateY(-50%);width:30px;height:30px;border:none;outline:none;border-radius:50%;cursor:pointer;display:flex;justify-content:center;align-items:center;z-index:20;font-size:16px;background-color:#292d3d4d;margin:0;padding:0;color:#fff;transition:background-color .3s}.nav-button:hover{background-color:#292d3d66}.nav-button:active{background-color:#292d3d80}.nav-prev{left:20px}.nav-next{right:20px}.pagination{position:absolute;bottom:10px;left:0;width:100%;z-index:2;display:flex;align-items:center;gap:8px;justify-content:center}.bullet{display:inline-block;width:8px;height:8px;border-radius:50%;background-color:#0000004d;cursor:pointer;transition:background-color .3s}.bullet.active{background-color:var(--l-primary-color, #722ed1)}";
|
|
7
|
+
class A extends u {
|
|
8
|
+
static baseName = "carousel";
|
|
9
|
+
/** 是否显示箭头 */
|
|
10
|
+
arrows = "hover";
|
|
11
|
+
currentIndex = 0;
|
|
12
|
+
allIndex = -1;
|
|
13
|
+
#s = 0;
|
|
14
|
+
// 当前偏移量
|
|
15
|
+
loop = !0;
|
|
16
|
+
observer;
|
|
17
|
+
autoplay = !1;
|
|
18
|
+
#e = void 0;
|
|
19
|
+
/* 手势 */
|
|
20
|
+
#o = 0;
|
|
21
|
+
#i = !1;
|
|
22
|
+
#d = 0;
|
|
23
|
+
#r = 0;
|
|
24
|
+
// 节点引用
|
|
25
|
+
#t;
|
|
26
|
+
static get observedAttributes() {
|
|
27
|
+
return ["arrows", "loop", "current-index", "autoplay"];
|
|
28
|
+
}
|
|
29
|
+
attributeChangedCallback(t, e, i) {
|
|
30
|
+
switch (t) {
|
|
31
|
+
case "arrows":
|
|
32
|
+
const s = d(i, "hover");
|
|
33
|
+
if (s !== this.arrows) {
|
|
34
|
+
this.arrows = s;
|
|
35
|
+
const a = document.createDocumentFragment();
|
|
36
|
+
this.renderArrows(a), this.root.appendChild(a);
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case "loop":
|
|
40
|
+
this.loop = d(i, !1, "loop");
|
|
41
|
+
break;
|
|
42
|
+
case "current-index":
|
|
43
|
+
const n = d(i, 0);
|
|
44
|
+
n !== this.currentIndex && this.#x(this.loop ? n + 1 : n);
|
|
45
|
+
break;
|
|
46
|
+
case "autoplay":
|
|
47
|
+
const o = d(i, !1, "autoplay");
|
|
48
|
+
o !== this.autoplay && (this.autoplay = o, this.#e && (o ? this.#e.start() : this.#e.stop()));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
connectedCallback() {
|
|
53
|
+
this.loadStyleText(g), this.style.setProperty(
|
|
54
|
+
"--carousel-width",
|
|
55
|
+
`${Math.floor(this.clientWidth)}px`
|
|
56
|
+
);
|
|
57
|
+
const t = m(this, "height");
|
|
58
|
+
t && this.style.setProperty("height", `${t}px`), this.#m(), super.connectedCallback();
|
|
59
|
+
}
|
|
60
|
+
afterInit() {
|
|
61
|
+
this.setAttribute("data-page", "__stop__"), l(this.root, "click", this.#v), this.#f(), this.#e = b(() => {
|
|
62
|
+
this.#a("next");
|
|
63
|
+
}), this.autoplay && this.#e.start(), this.#t = h(".container", this.root), l(this.#t, "pointerdown", this.#y), l(this.#t, "pointerup", this.#I), l(this.#t, "pointermove", this.#$), l(this.#t, "pointercancel", this.#n), l(this.#t, "pointerleave", this.#n);
|
|
64
|
+
}
|
|
65
|
+
beforeDestroy() {
|
|
66
|
+
r(this, "mouseenter", this.#l), r(this, "mouseleave", this.#h), r(this.root, "click", this.#v), r(this.#t, "pointerdown", this.#y), r(this.#t, "pointerup", this.#I), r(this.#t, "pointermove", this.#$), r(this.#t, "pointercancel", this.#n), r(this.#t, "pointerleave", this.#n), this.#t = void 0, this.#u(!0), this.#e.stop(), this.#e = void 0;
|
|
67
|
+
}
|
|
68
|
+
render() {
|
|
69
|
+
const t = document.createDocumentFragment();
|
|
70
|
+
let e = "";
|
|
71
|
+
if (this.allIndex > 0) {
|
|
72
|
+
const n = this.loop ? this.currentIndex + 1 : this.currentIndex, o = Math.floor(n * this.clientWidth * -1);
|
|
73
|
+
e = `transform:translateX(${o}px);`;
|
|
74
|
+
const a = Math.floor(this.clientWidth * (this.allIndex + 3));
|
|
75
|
+
e += `min-width:${a}px;`, this.#s = o;
|
|
76
|
+
}
|
|
77
|
+
const i = c("div", {
|
|
78
|
+
class: "container",
|
|
79
|
+
style: e,
|
|
80
|
+
"data-container": "1"
|
|
81
|
+
});
|
|
82
|
+
i.appendChild(c("slot")), t.appendChild(i), this.renderArrows(t);
|
|
83
|
+
const s = c("div", { class: "pagination", part: "pagination" });
|
|
84
|
+
return this.allIndex >= 0 && s.replaceChildren(this.#p()), t.appendChild(s), t;
|
|
85
|
+
}
|
|
86
|
+
renderArrows(t) {
|
|
87
|
+
if (this.arrows !== "never")
|
|
88
|
+
this.renderNavigationButton("prev", t), this.renderNavigationButton("next", t), this.arrows === "hover" && (l(this, "mouseenter", this.#l), l(this, "mouseleave", this.#h));
|
|
89
|
+
else {
|
|
90
|
+
r(this, "mouseenter", this.#l), r(this, "mouseleave", this.#h);
|
|
91
|
+
const e = p(".nav-button", this.root);
|
|
92
|
+
e.length && f(e, (i) => {
|
|
93
|
+
i.remove();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
#p() {
|
|
98
|
+
const t = document.createDocumentFragment();
|
|
99
|
+
for (let e = 0; e <= this.allIndex; e++)
|
|
100
|
+
t.appendChild(
|
|
101
|
+
c("div", {
|
|
102
|
+
class: ["bullet", e === this.currentIndex ? "active" : ""],
|
|
103
|
+
"aria-label": `第 ${e + 1} 页`,
|
|
104
|
+
"data-page": `${e}`,
|
|
105
|
+
id: `bullet-${e}`
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
return t;
|
|
109
|
+
}
|
|
110
|
+
renderNavigationButton(t = "prev", e) {
|
|
111
|
+
let i = h(`.nav-${t}`, this.root);
|
|
112
|
+
if (i == null) {
|
|
113
|
+
const s = t === "prev" ? "left" : "right";
|
|
114
|
+
i = c("button", {
|
|
115
|
+
class: `nav-button nav-${t}`,
|
|
116
|
+
type: "button",
|
|
117
|
+
innerHTML: `<l-arrow-${s}-icon></l-arrow-${s}-icon>`,
|
|
118
|
+
"aria-label": t,
|
|
119
|
+
"data-page": t
|
|
120
|
+
}), e.appendChild(i);
|
|
121
|
+
}
|
|
122
|
+
this.arrows === "always" ? i.style.display = "flex" : i.style.display = "none";
|
|
123
|
+
}
|
|
124
|
+
#f() {
|
|
125
|
+
this.observer == null && (this.observer = new MutationObserver(this.#C)), this.observer.observe(this, { childList: !0 });
|
|
126
|
+
}
|
|
127
|
+
#u(t = !1) {
|
|
128
|
+
this.observer && (this.observer.disconnect(), t && (this.observer = void 0));
|
|
129
|
+
}
|
|
130
|
+
#w = x(() => {
|
|
131
|
+
const t = h("#cloneFirst", this);
|
|
132
|
+
t && t.remove();
|
|
133
|
+
const e = h("#cloneLast", this);
|
|
134
|
+
if (e && e.remove(), this.#m(), this.#t) {
|
|
135
|
+
if (this.allIndex > 0) {
|
|
136
|
+
const o = Math.floor(
|
|
137
|
+
this.clientWidth * (this.allIndex + 3)
|
|
138
|
+
);
|
|
139
|
+
this.#t.style.minWidth = `${o}px`;
|
|
140
|
+
} else
|
|
141
|
+
this.#t.style.minWidth = "900%";
|
|
142
|
+
const s = this.loop ? this.currentIndex + 1 : this.currentIndex, n = Math.floor(s * this.clientWidth * -1);
|
|
143
|
+
this.#t.style.transform = `translateX(${n}px)`, this.#s = n;
|
|
144
|
+
}
|
|
145
|
+
const i = h(".pagination", this.root);
|
|
146
|
+
i && i.replaceChildren(this.#p()), this.#f();
|
|
147
|
+
}, 300);
|
|
148
|
+
#m() {
|
|
149
|
+
const t = this.children, e = t.length;
|
|
150
|
+
if (e > 0 && this.loop) {
|
|
151
|
+
const i = t[0].cloneNode(!0);
|
|
152
|
+
i.id = "cloneFirst";
|
|
153
|
+
const s = t[e - 1].cloneNode(!0);
|
|
154
|
+
s.id = "cloneLast", this.children[e - 1].insertAdjacentElement("afterend", i), this.children[0].insertAdjacentElement("beforebegin", s);
|
|
155
|
+
}
|
|
156
|
+
this.allIndex = this.children.length - (this.loop ? 3 : 1);
|
|
157
|
+
}
|
|
158
|
+
#C = (t) => {
|
|
159
|
+
for (const e of t)
|
|
160
|
+
e.type === "childList" && (this.#u(), this.#w());
|
|
161
|
+
};
|
|
162
|
+
#v = (t) => {
|
|
163
|
+
const [e, i] = v(t, "data-page", this.root);
|
|
164
|
+
e && this.#a(i);
|
|
165
|
+
};
|
|
166
|
+
#a(t) {
|
|
167
|
+
this.#e.stop();
|
|
168
|
+
const e = this.loop ? this.currentIndex + 1 : this.currentIndex;
|
|
169
|
+
let i = e;
|
|
170
|
+
if (t === "prev")
|
|
171
|
+
this.loop && this.currentIndex === 0 ? i = 0 : i = e - 1, i < 0 && (i = 0);
|
|
172
|
+
else if (t === "next")
|
|
173
|
+
this.loop && this.currentIndex === this.allIndex ? i = this.allIndex + 2 : i = e + 1, !this.loop && i > this.allIndex && (i = this.allIndex);
|
|
174
|
+
else {
|
|
175
|
+
const s = Number(t);
|
|
176
|
+
s !== this.currentIndex && (i = this.loop ? s + 1 : s);
|
|
177
|
+
}
|
|
178
|
+
i !== e && this.#x(i), requestAnimationFrame(() => {
|
|
179
|
+
this.#c();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
#x(t) {
|
|
183
|
+
if (this.#t) {
|
|
184
|
+
const s = Math.floor(t * this.clientWidth * -1), n = this.#t.style.transform;
|
|
185
|
+
this.#t.animate(
|
|
186
|
+
[{ transform: n }, { transform: `translateX(${s}px)` }],
|
|
187
|
+
{ duration: 300 }
|
|
188
|
+
).addEventListener(
|
|
189
|
+
"finish",
|
|
190
|
+
() => {
|
|
191
|
+
let a = s;
|
|
192
|
+
this.loop && t === this.allIndex + 2 ? a = Math.floor(this.clientWidth * -1) : this.loop && t === 0 && (a = Math.floor(this.clientWidth * (this.allIndex + 1) * -1)), this.#t.style.transform = `translateX(${a}px)`, this.#s = a;
|
|
193
|
+
},
|
|
194
|
+
{ once: !0 }
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
this.loop && this.allIndex > 0 && t === this.allIndex + 2 ? this.currentIndex = 0 : this.loop && this.allIndex > 0 && t === 0 ? this.currentIndex = this.allIndex : this.currentIndex = this.loop ? t - 1 : t;
|
|
198
|
+
const e = h(".bullet.active", this.root);
|
|
199
|
+
e && e.classList.remove("active");
|
|
200
|
+
const i = h(`#bullet-${this.currentIndex}`, this.root);
|
|
201
|
+
i && i.classList.add("active");
|
|
202
|
+
}
|
|
203
|
+
#l = () => {
|
|
204
|
+
if (this.arrows === "hover") {
|
|
205
|
+
const t = p(".nav-button", this.root);
|
|
206
|
+
f(t, (e) => {
|
|
207
|
+
e.style.display = "flex", this.#b(e, !0);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
#h = () => {
|
|
212
|
+
if (this.arrows === "hover") {
|
|
213
|
+
const t = p(".nav-button", this.root);
|
|
214
|
+
f(t, (e) => {
|
|
215
|
+
this.#b(e, !1);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
#b(t, e = !0) {
|
|
220
|
+
const s = t.getAttribute("data-page") === "prev" ? -10 : 10, n = [];
|
|
221
|
+
e ? n.push(
|
|
222
|
+
{ opacity: 0, transform: `translate3d(${s}px, -50%, 0)` },
|
|
223
|
+
{ opacity: 1, transform: "translate3d(0px, -50%, 0)" }
|
|
224
|
+
) : n.push(
|
|
225
|
+
{ opacity: 1, transform: "translate3d(0px, -50%, 0)" },
|
|
226
|
+
{ opacity: 0, transform: `translate3d(${s}px, -50%, 0)` }
|
|
227
|
+
);
|
|
228
|
+
const o = t.animate(n, {
|
|
229
|
+
duration: 300,
|
|
230
|
+
fill: "both"
|
|
231
|
+
});
|
|
232
|
+
e || o.addEventListener(
|
|
233
|
+
"finish",
|
|
234
|
+
() => {
|
|
235
|
+
t.style.display = "none";
|
|
236
|
+
},
|
|
237
|
+
{ once: !0 }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
#g = () => {
|
|
241
|
+
const t = h(".container", this.root);
|
|
242
|
+
t.style.transition = "transform 0.3s", requestAnimationFrame(() => {
|
|
243
|
+
t.style.transform = `translateX(${this.#s}px)`;
|
|
244
|
+
}), t.addEventListener(
|
|
245
|
+
"transitionend",
|
|
246
|
+
() => {
|
|
247
|
+
t.style.transition = "";
|
|
248
|
+
},
|
|
249
|
+
{ once: !0 }
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
#y = (t) => {
|
|
253
|
+
this.#o = t.clientX, this.#i = !0, this.#d = Date.now(), this.#e.stop();
|
|
254
|
+
};
|
|
255
|
+
#$ = (t) => {
|
|
256
|
+
this.#i && (this.#r && cancelAnimationFrame(this.#r), this.#r = requestAnimationFrame(() => {
|
|
257
|
+
const e = Math.floor(t.clientX - this.#o);
|
|
258
|
+
if (!this.loop && (e < 0 && this.currentIndex === this.allIndex || e > 0 && this.currentIndex === 0))
|
|
259
|
+
return;
|
|
260
|
+
const i = this.#s + e;
|
|
261
|
+
this.#t.style.transform = `translateX(${i}px)`;
|
|
262
|
+
}), t.preventDefault());
|
|
263
|
+
};
|
|
264
|
+
#I = (t) => {
|
|
265
|
+
if (!this.#i) return;
|
|
266
|
+
const e = Date.now() - this.#d, i = t.clientX - this.#o;
|
|
267
|
+
if (this.#i = !1, i === 0) return;
|
|
268
|
+
let s = "cancel";
|
|
269
|
+
e <= 200 ? i >= 20 ? s = "prev" : i <= -20 && (s = "next") : i >= this.clientWidth / 2 ? s = "prev" : i <= -this.clientWidth / 2 && (s = "next"), s === "cancel" ? this.#g() : this.#a(s), this.#c();
|
|
270
|
+
};
|
|
271
|
+
#c = () => {
|
|
272
|
+
this.autoplay && this.#e.start();
|
|
273
|
+
};
|
|
274
|
+
#n = () => {
|
|
275
|
+
this.#i && (this.#i = !1, this.#g(), this.#c());
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
export {
|
|
279
|
+
A as default
|
|
280
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import e from "../base.js";
|
|
2
|
+
import { $$ as t } from "ph-utils/dom";
|
|
3
|
+
const o = ":host{width:var(--carousel-width, 100%);height:100%;box-sizing:border-box;display:block}:host(.active){display:block}";
|
|
4
|
+
class r extends e {
|
|
5
|
+
static baseName = "carousel-item";
|
|
6
|
+
connectedCallback() {
|
|
7
|
+
this.loadStyleText(o), super.connectedCallback();
|
|
8
|
+
}
|
|
9
|
+
render() {
|
|
10
|
+
return t("slot");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
r as default
|
|
15
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function o(a, l = 3e3) {
|
|
2
|
+
let n = 0, t = !1, e = null;
|
|
3
|
+
function u() {
|
|
4
|
+
t || (t = !0, n = 0, e = requestAnimationFrame(r));
|
|
5
|
+
}
|
|
6
|
+
function f() {
|
|
7
|
+
t = !1, e && (cancelAnimationFrame(e), e = null);
|
|
8
|
+
}
|
|
9
|
+
function r(i) {
|
|
10
|
+
t && (n || (n = i), i - n >= l && (a(), n = i), e = requestAnimationFrame(r));
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
start: u,
|
|
14
|
+
stop: f
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
o as default
|
|
19
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import FormInner from "../form/form_inner";
|
|
2
|
+
export default class Check extends FormInner {
|
|
3
|
+
#private;
|
|
4
|
+
/** 是否选中 */
|
|
5
|
+
private _checked;
|
|
6
|
+
label?: string;
|
|
7
|
+
/** 是否为按钮样式 */
|
|
8
|
+
button: boolean;
|
|
9
|
+
_inputType: string;
|
|
10
|
+
setChecked(isChecked: boolean): void;
|
|
11
|
+
getChecked(): boolean;
|
|
12
|
+
constructor();
|
|
13
|
+
static get observedAttributes(): string[];
|
|
14
|
+
connectedCallback(): void;
|
|
15
|
+
afterInit(): void;
|
|
16
|
+
beforeDestroy(): void;
|
|
17
|
+
render(): DocumentFragment;
|
|
18
|
+
protected attributeChange(name: string, _oldValue: string, newValue: string): void;
|
|
19
|
+
protected checkedChange(): void;
|
|
20
|
+
protected disabledChange(): void;
|
|
21
|
+
_doChangeAction(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import d from "../form/form_inner.js";
|
|
2
|
+
import { initAttr as n, parseAttrValue as l } from "../utils/index.js";
|
|
3
|
+
import { addClass as c, on as r, off as o, $$ as i, removeClass as k, $one as u, toggleClass as p } from "ph-utils/dom";
|
|
4
|
+
class m extends d {
|
|
5
|
+
/** 是否选中 */
|
|
6
|
+
_checked = !1;
|
|
7
|
+
label;
|
|
8
|
+
/** 是否为按钮样式 */
|
|
9
|
+
button = !1;
|
|
10
|
+
_inputType = "radio";
|
|
11
|
+
// input类型
|
|
12
|
+
setChecked(e) {
|
|
13
|
+
this._checked = e, this.checkedChange();
|
|
14
|
+
}
|
|
15
|
+
getChecked() {
|
|
16
|
+
return this._checked;
|
|
17
|
+
}
|
|
18
|
+
constructor() {
|
|
19
|
+
super(), Object.defineProperty(this, "checked", {
|
|
20
|
+
configurable: !0,
|
|
21
|
+
enumerable: !0,
|
|
22
|
+
get: this.getChecked,
|
|
23
|
+
set: this.setChecked
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static get observedAttributes() {
|
|
27
|
+
return ["disabled", "checked"];
|
|
28
|
+
}
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
n(this), super.connectedCallback(), this.getChecked() && c(this, "is-checked"), this.isDisabled() && c(this, "is-disabled");
|
|
31
|
+
}
|
|
32
|
+
afterInit() {
|
|
33
|
+
r(this, "click", this.#e);
|
|
34
|
+
}
|
|
35
|
+
beforeDestroy() {
|
|
36
|
+
o(this, "click", this.#e);
|
|
37
|
+
}
|
|
38
|
+
render() {
|
|
39
|
+
const e = document.createDocumentFragment(), h = i("input", {
|
|
40
|
+
type: this._inputType,
|
|
41
|
+
class: "l-check__input",
|
|
42
|
+
name: this.getName(),
|
|
43
|
+
value: this.value,
|
|
44
|
+
disabled: this.isDisabled(),
|
|
45
|
+
checked: this.getChecked()
|
|
46
|
+
});
|
|
47
|
+
if (e.appendChild(h), !this.button) {
|
|
48
|
+
const a = i("span", { class: "l-check__inner" });
|
|
49
|
+
e.appendChild(a);
|
|
50
|
+
}
|
|
51
|
+
const t = i("label", {
|
|
52
|
+
class: "l-check__label",
|
|
53
|
+
part: "label"
|
|
54
|
+
}), s = i("slot", {
|
|
55
|
+
textContent: this.label
|
|
56
|
+
});
|
|
57
|
+
return t.appendChild(s), e.appendChild(t), e;
|
|
58
|
+
}
|
|
59
|
+
attributeChange(e, h, t) {
|
|
60
|
+
if (e === "checked") {
|
|
61
|
+
const s = l(t, !1, "checked");
|
|
62
|
+
s !== this.getChecked() && this.setChecked(s);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
checkedChange() {
|
|
66
|
+
this.getChecked() ? c(this, "is-checked") : k(this, "is-checked");
|
|
67
|
+
const e = u("input", this.root);
|
|
68
|
+
e && (e.checked = this._checked);
|
|
69
|
+
}
|
|
70
|
+
disabledChange() {
|
|
71
|
+
p(this, "is-disabled");
|
|
72
|
+
}
|
|
73
|
+
#e = () => {
|
|
74
|
+
this.isDisabled() || this._doChangeAction();
|
|
75
|
+
};
|
|
76
|
+
_doChangeAction() {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
m as default
|
|
81
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import e from "./check.js";
|
|
2
|
+
import { c as r } from "../check-BlDsQQo0.js";
|
|
3
|
+
const o = '.l-check__inner:after{content:"";width:calc(var(--l-check-size) * .6);height:calc(var(--l-check-size) * .3);display:block;border:solid 1px transparent;border-right:none;border-top:none;transform:rotate(-45deg);transition:border-color .2s ease-in-out;margin-top:-3px}:host([indeterminate]) .l-check__inner{background-color:var(--l-primary-color, #722ed1)}:host([indeterminate]) .l-check__inner:after{content:"";width:calc(var(--l-check-size) * .4);height:1px;display:block;border:1px solid #fff;border-right:none;border-top:none;border-left:none;transform:rotate(0);margin-top:0}:host(.is-checked) .l-check__inner{background-color:var(--l-primary-color, #722ed1)}:host(.is-checked) .l-check__inner:after{border-color:#fff}:host(.is-disabled) .l-check__inner{background-color:var(--l-disabled-color, #e6e6e6);border-color:var(--l-disabled-color, #e6e6e6)}';
|
|
4
|
+
class a extends e {
|
|
5
|
+
static baseName = "checkbox";
|
|
6
|
+
constructor() {
|
|
7
|
+
super(), this._inputType = "checkbox";
|
|
8
|
+
}
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
this.loadStyleText([r, o]), super.connectedCallback();
|
|
11
|
+
}
|
|
12
|
+
_doChangeAction() {
|
|
13
|
+
this.getChecked() ? this.removeAttribute("checked") : this.setAttribute("checked", ""), this.emit("change", {
|
|
14
|
+
detail: {
|
|
15
|
+
value: this.value,
|
|
16
|
+
name: this.getName(),
|
|
17
|
+
checked: this.getChecked()
|
|
18
|
+
},
|
|
19
|
+
composed: !0
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
a as default
|
|
25
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import CheckGroup from ".";
|
|
2
|
+
export default class CheckboxGroup extends CheckGroup {
|
|
3
|
+
static baseName: string;
|
|
4
|
+
set value(value: string);
|
|
5
|
+
get value(): string;
|
|
6
|
+
afterInit(): void;
|
|
7
|
+
protected updateChangedStatus(): void;
|
|
8
|
+
valueChange(value: string): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import a from "./index.js";
|
|
2
|
+
import { $ as u, iterate as i } from "ph-utils/dom";
|
|
3
|
+
class d extends a {
|
|
4
|
+
static baseName = "checkbox-group";
|
|
5
|
+
set value(t) {
|
|
6
|
+
super.setValue(t), this.rendered && this.updateChangedStatus();
|
|
7
|
+
}
|
|
8
|
+
get value() {
|
|
9
|
+
return this._value;
|
|
10
|
+
}
|
|
11
|
+
afterInit() {
|
|
12
|
+
super.afterInit(), this.updateChangedStatus();
|
|
13
|
+
}
|
|
14
|
+
updateChangedStatus() {
|
|
15
|
+
if (this.value) {
|
|
16
|
+
const e = this.value.split("&");
|
|
17
|
+
this.checkedValues.push(...e.map((s) => decodeURIComponent(s)));
|
|
18
|
+
} else
|
|
19
|
+
this.checkedValues = [];
|
|
20
|
+
const t = u("l-checkbox[value]", this);
|
|
21
|
+
i(t, (e) => {
|
|
22
|
+
let s = e.value;
|
|
23
|
+
s || (s = e.getAttribute("value")), s && (this.checkedValues.includes(s) ? e.setAttribute("checked", "") : e.removeAttribute("checked"));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
valueChange(t) {
|
|
27
|
+
let e = this.checkedValues.indexOf(t);
|
|
28
|
+
e >= 0 ? this.checkedValues.splice(e, 1) : this.checkedValues.push(t), this.setValue(this.checkedValues.join("&"));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
d as default
|
|
33
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import FormInner from "../form/form_inner";
|
|
2
|
+
export default class CheckGroup extends FormInner {
|
|
3
|
+
#private;
|
|
4
|
+
button: boolean;
|
|
5
|
+
checkedValues: string[];
|
|
6
|
+
constructor();
|
|
7
|
+
connectedCallback(): void;
|
|
8
|
+
afterInit(): void;
|
|
9
|
+
beforeDestroy(): void;
|
|
10
|
+
render(): HTMLElement;
|
|
11
|
+
valueChange(_value: string): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import t from "../form/form_inner.js";
|
|
2
|
+
import { on as s, off as a, $$ as o } from "ph-utils/dom";
|
|
3
|
+
import { initAttr as r } from "../utils/index.js";
|
|
4
|
+
const l = ":host{display:flex;align-items:center}";
|
|
5
|
+
class u extends t {
|
|
6
|
+
button = !1;
|
|
7
|
+
// 是否为按钮样式
|
|
8
|
+
checkedValues;
|
|
9
|
+
constructor() {
|
|
10
|
+
super(!1), this.checkedValues = [];
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
r(this), this.loadStyleText([l]), super.connectedCallback();
|
|
14
|
+
}
|
|
15
|
+
afterInit() {
|
|
16
|
+
s(this.root, "change", this.#e);
|
|
17
|
+
}
|
|
18
|
+
beforeDestroy() {
|
|
19
|
+
a(this.root, "change", this.#e), this.checkedValues = [];
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
return o("slot");
|
|
23
|
+
}
|
|
24
|
+
#e = (e) => {
|
|
25
|
+
this.valueChange(e.detail.value), e.stopPropagation(), this.emit("change", {
|
|
26
|
+
detail: { value: [...this.checkedValues] },
|
|
27
|
+
composed: !0
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
valueChange(e) {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
u as default
|
|
35
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import e from "./check.js";
|
|
2
|
+
import { c as o } from "../check-BlDsQQo0.js";
|
|
3
|
+
import { $one as r } from "ph-utils/dom";
|
|
4
|
+
const t = '.l-check__inner{border-radius:50%}.l-check__inner:after{content:"";display:block;width:60%;height:60%;background-color:transparent;border-radius:50%;transition:background-color .3s ease-in-out}:host(.is-checked) .l-check__inner:after{background-color:var(--l-primary-color, #722ed1)}:host(.is-disabled) .l-check__inner{border-color:var(--l-disabled-color, #e6e6e6)}:host(.is-disabled) .l-check__inner:after{background-color:var(--l-disabled-color, #e6e6e6)}';
|
|
5
|
+
class d extends e {
|
|
6
|
+
static baseName = "radio";
|
|
7
|
+
connectedCallback() {
|
|
8
|
+
this.loadStyleText([o, t]), super.connectedCallback();
|
|
9
|
+
}
|
|
10
|
+
_doChangeAction() {
|
|
11
|
+
r("input", this.root).checked || (this.setAttribute("checked", ""), this.emit("change", {
|
|
12
|
+
detail: { value: this.value, name: this.getName() },
|
|
13
|
+
composed: !0
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
d as default
|
|
19
|
+
};
|