easy-component-ui 1.0.3 → 2.0.1
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/.github/workflows/publish.yml +28 -0
- package/components/Base.js +1 -90
- package/components/ea-alert/index.js +1 -298
- package/components/ea-alert/src/style/stylesheet.js +1 -0
- package/components/ea-aside/index.js +1 -0
- package/components/ea-avatar/index.js +1 -277
- package/components/ea-avatar/src/assets/defaultAvatar.js +1 -0
- package/components/ea-avatar/src/assets/errorAvatar.js +1 -0
- package/components/ea-avatar/src/assets/iconAndTextAvatar.js +1 -0
- package/components/ea-avatar/src/style/stylesheet.js +1 -0
- package/components/ea-backtop/index.js +1 -232
- package/components/ea-backtop/src/style/stylesheet.js +1 -0
- package/components/ea-badge/index.js +1 -160
- package/components/ea-badge/src/style/stylesheet.js +1 -0
- package/components/ea-breadcrumb/index.js +1 -0
- package/components/ea-breadcrumb/src/style/stylesheet.js +1 -0
- package/components/ea-breadcrumb-item/index.js +1 -0
- package/components/ea-breadcrumb-item/src/style/style.js +1 -0
- package/components/ea-button/index.js +1 -584
- package/components/ea-button/src/components/ButtonComm.js +1 -0
- package/components/ea-button/src/components/HrefComm.js +1 -0
- package/components/ea-button/src/style/stylesheet.js +1 -0
- package/components/ea-button-group/index.js +1 -459
- package/components/ea-button-group/src/style/stylesheet.js +1 -0
- package/components/ea-calendar/index.js +1 -409
- package/components/ea-calendar/src/style/stylesheet.js +1 -0
- package/components/ea-calendar/src/utils/createChangerElement.js +1 -0
- package/components/ea-calendar/src/utils/createThead.js +1 -0
- package/components/ea-calendar/src/utils/getDate.js +1 -0
- package/components/ea-calendar/src/utils/getUserWeekStart.js +1 -0
- package/components/ea-card/index.js +1 -77
- package/components/ea-card/src/style/stylesheet.js +1 -0
- package/components/ea-carousel/index.js +1 -434
- package/components/ea-carousel/src/style/stylesheet.js +1 -0
- package/components/ea-carousel/src/utils/handleIndexOverflow.js +1 -0
- package/components/ea-carousel-item/index.js +1 -0
- package/components/ea-carousel-item/src/style/stylesheet.js +1 -0
- package/components/ea-checkbox/index.js +1 -314
- package/components/ea-checkbox/src/style/stylesheet.js +1 -0
- package/components/ea-checkbox-group/index.js +1 -107
- package/components/ea-checkbox-group/src/style/stylesheet.js +1 -0
- package/components/ea-collapse/index.js +1 -293
- package/components/ea-collapse-item/index.js +1 -0
- package/components/ea-collapse-item/src/style/stylesheet.js +1 -0
- package/components/ea-container/index.js +1 -0
- package/components/ea-date-picker/index.js +1 -0
- package/components/ea-date-picker/src/style/stylesheet.js +1 -0
- package/components/ea-descriptions/index.js +1 -240
- package/components/ea-descriptions/src/components/contentTemplate.js +1 -0
- package/components/ea-descriptions/src/components/getTdTemplate_border.js +1 -0
- package/components/ea-descriptions/src/components/getTdTemplate_direction.js +1 -0
- package/components/ea-descriptions/src/components/getThTemplate_direction.js +1 -0
- package/components/ea-descriptions/src/components/getThTemplate_normal.js +1 -0
- package/components/ea-descriptions/src/style/stylesheet.js +1 -0
- package/components/ea-descriptions-item/index.js +1 -110
- package/components/ea-descriptions-item/src/stylesheet.js +1 -0
- package/components/ea-drawer/index.js +1 -0
- package/components/ea-drawer/src/style/stylesheet.js +1 -0
- package/components/ea-empty/index.js +1 -141
- package/components/ea-empty/src/assets/emptyStatusSVG.js +1 -0
- package/components/ea-empty/src/style/stylesheet.js +1 -0
- package/components/ea-footer/index.js +1 -0
- package/components/ea-form/index.js +1 -0
- package/components/ea-form-item/index.js +1 -0
- package/components/ea-form-item/src/style/stylesheet.js +1 -0
- package/components/ea-header/index.js +1 -0
- package/components/ea-icon/config.json +1029 -1017
- package/components/ea-icon/css/animation.css +85 -85
- package/components/ea-icon/css/fontello.css +226 -224
- package/components/ea-icon/font/fontello.eot +0 -0
- package/components/ea-icon/font/fontello.svg +350 -683
- package/components/ea-icon/font/fontello.ttf +0 -0
- package/components/ea-icon/font/fontello.woff +0 -0
- package/components/ea-icon/font/fontello.woff2 +0 -0
- package/components/ea-icon/index.js +1 -47
- package/components/ea-image/index.js +1 -412
- package/components/ea-image/src/assets/errorImage.js +1 -0
- package/components/ea-image/src/style/stylesheet.js +1 -0
- package/components/ea-image/src/utils/createPreviewTools.js +1 -0
- package/components/ea-infinite-scroll/index.js +1 -170
- package/components/ea-infinite-scroll-item/index.js +1 -0
- package/components/ea-input/index.js +1 -765
- package/components/ea-input/src/components/createFixIcon.js +1 -0
- package/components/ea-input/src/components/createSuggestionBoard.js +1 -0
- package/components/ea-input/src/components/createWordLimitElement.js +1 -0
- package/components/ea-input/src/style/stylesheet.js +1 -0
- package/components/ea-input/src/utils/dispatchEvent.js +1 -0
- package/components/ea-input/src/utils/handleSearchResult.js +1 -0
- package/components/ea-input/src/utils/handleSuggestionBoardTrigger.js +1 -0
- package/components/ea-input-number/index.js +1 -458
- package/components/ea-input-number/src/style/stylesheet.js +1 -0
- package/components/ea-input-number/src/utils/handleCustomEvent.js +1 -0
- package/components/ea-link/index.js +1 -200
- package/components/ea-link/src/style/stylesheet.js +1 -0
- package/components/ea-loading/index.js +1 -218
- package/components/ea-loading/src/style/stylesheet.js +1 -0
- package/components/ea-main/index.js +1 -0
- package/components/ea-menu/index.js +1 -0
- package/components/ea-menu/src/style/stylesheet.js +1 -0
- package/components/ea-menu/src/utils/handleMenuItemEvent.js +1 -0
- package/components/ea-menu-item/index.js +1 -0
- package/components/ea-menu-item/src/style/stylesheet.js +1 -0
- package/components/ea-menu-item-group/index.js +1 -0
- package/components/ea-menu-item-group/src/style/stylesheet.js +1 -0
- package/components/ea-message/index.js +1 -233
- package/components/ea-message/src/style/stylesheet.js +1 -0
- package/components/ea-message/src/utils/MessageClass.js +1 -0
- package/components/ea-message-box/index.js +1 -202
- package/components/ea-message-box/src/style/stylesheet.js +1 -0
- package/components/ea-message-box/src/utils/EaMessageBoxClass.js +1 -0
- package/components/ea-option/index.js +1 -0
- package/components/ea-option/src/style/stylesheet.js +1 -0
- package/components/ea-option-gropu/index.js +1 -0
- package/components/ea-page-header/index.js +1 -0
- package/components/ea-page-header/src/style/stylesheet.js +1 -0
- package/components/ea-pagination/index.js +1 -444
- package/components/ea-pagination/src/components/getMoreItem.js +1 -0
- package/components/ea-pagination/src/components/getPageItem.js +1 -0
- package/components/ea-pagination/src/components/getShowTotalItem.js +1 -0
- package/components/ea-pagination/src/style/stylesheet.js +1 -0
- package/components/ea-pane/index.js +1 -0
- package/components/ea-pane/src/stylesheet.js +1 -0
- package/components/ea-progress/index.js +1 -333
- package/components/ea-progress/src/components/SVGComm.js +1 -0
- package/components/ea-progress/src/style/stylesheet.js +1 -0
- package/components/ea-radio/index.js +1 -287
- package/components/ea-radio/src/style/stylesheet.js +1 -0
- package/components/ea-radio-group/index.js +1 -59
- package/components/ea-rate/index.js +1 -326
- package/components/ea-rate/src/components/rateComm.js +1 -0
- package/components/ea-rate/src/style/stylesheet.js +1 -0
- package/components/ea-result/index.js +1 -167
- package/components/ea-result/src/style/stylesheet.js +1 -0
- package/components/ea-select/index.js +1 -34
- package/components/ea-select/src/style/stylesheet.js +1 -0
- package/components/ea-skeleton/index.js +1 -341
- package/components/ea-skeleton/src/style/stylesheet.js +1 -0
- package/components/ea-skeleton/src/utils/createSkeletonElement.js +1 -0
- package/components/ea-skeleton-item/index.js +1 -0
- package/components/ea-skeleton-item/src/assets/imageSVG.js +1 -0
- package/components/ea-skeleton-item/src/style/stylesheet.js +1 -0
- package/components/ea-step/index.js +1 -0
- package/components/ea-step/src/style/stylesheet.js +1 -0
- package/components/ea-steps/index.js +1 -0
- package/components/ea-steps/src/style/stylesheet.js +1 -0
- package/components/ea-submenu/index.js +1 -0
- package/components/ea-submenu/src/style/stylesheet.js +1 -0
- package/components/ea-switch/index.js +1 -301
- package/components/ea-switch/src/style/stylesheet.js +1 -0
- package/components/ea-tab/index.js +1 -0
- package/components/ea-tab/src/style/stylesheet.js +1 -0
- package/components/ea-table/index.js +1 -0
- package/components/ea-table/src/style/stylesheet.js +1 -0
- package/components/ea-table-column/index.js +1 -0
- package/components/ea-tabs/index.js +1 -0
- package/components/ea-tabs/src/style/stylesheet.js +1 -0
- package/components/ea-tag/index.js +1 -212
- package/components/ea-tag/src/style/stylesheet.js +1 -0
- package/components/ea-textarea/index.js +1 -333
- package/components/ea-textarea/src/style/stylesheet.js +1 -0
- package/components/ea-time-picker/index.js +1 -0
- package/components/ea-time-picker/src/style/stylesheet.js +1 -0
- package/components/ea-timeline/index.js +1 -334
- package/components/ea-timeline/style/stylesheet.js +1 -0
- package/components/ea-timeline-item/index.js +1 -0
- package/components/ea-timeline-item/src/style/stylesheet.js +1 -0
- package/package.json +11 -11
- package/utils/Validator.js +1 -0
- package/utils/createElement.js +1 -30
- package/utils/handleDefaultAttrIsTrue.js +1 -0
- package/utils/handleTemplate.js +1 -19
- package/utils/setStyle.js +1 -8
- package/utils/timeout.js +1 -0
- package/components/ea-message/MessageClass.js +0 -71
- package/components/ea-message-box/EaMessageBoxClass.js +0 -48
- package/components/ea-ui-base-style.css +0 -0
|
@@ -1,434 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import Base from '../Base.js';
|
|
3
|
-
import { createElement, createSlotElement } from "../../utils/createElement.js"
|
|
4
|
-
|
|
5
|
-
const stylesheet = `
|
|
6
|
-
.ea-carousel_wrap {
|
|
7
|
-
position: relative;
|
|
8
|
-
}
|
|
9
|
-
.ea-carousel_wrap.ea-carousel--horizontal {
|
|
10
|
-
overflow-x: hidden;
|
|
11
|
-
}
|
|
12
|
-
.ea-carousel_wrap .ea-carousel_container {
|
|
13
|
-
position: relative;
|
|
14
|
-
color: #fff;
|
|
15
|
-
text-align: center;
|
|
16
|
-
height: 300px;
|
|
17
|
-
transition: transform 0.5s;
|
|
18
|
-
}
|
|
19
|
-
.ea-carousel_wrap .ea-carousel-item_arrow {
|
|
20
|
-
position: absolute;
|
|
21
|
-
top: 50%;
|
|
22
|
-
transform: translateY(-50%);
|
|
23
|
-
opacity: 0;
|
|
24
|
-
width: 1.5rem;
|
|
25
|
-
height: 1.5rem;
|
|
26
|
-
line-height: 1.5;
|
|
27
|
-
text-align: center;
|
|
28
|
-
border-radius: 50%;
|
|
29
|
-
background-color: rgba(31, 45, 61, 0.11);
|
|
30
|
-
color: #fff;
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
user-select: none;
|
|
33
|
-
transition: background-color 0.3s, transform 0.3s, opacity 0.3s;
|
|
34
|
-
}
|
|
35
|
-
.ea-carousel_wrap .ea-carousel-item_arrow.ea-carousel-item_arrow--left {
|
|
36
|
-
left: 0;
|
|
37
|
-
transform: translate(-100%, -50%);
|
|
38
|
-
}
|
|
39
|
-
.ea-carousel_wrap .ea-carousel-item_arrow.ea-carousel-item_arrow--right {
|
|
40
|
-
right: 0;
|
|
41
|
-
transform: translate(100%, -50%);
|
|
42
|
-
}
|
|
43
|
-
.ea-carousel_wrap .ea-carousel-item_arrow:hover {
|
|
44
|
-
background-color: rgba(31, 45, 61, 0.3);
|
|
45
|
-
}
|
|
46
|
-
.ea-carousel_wrap .ea-carousel-indicator_wrap {
|
|
47
|
-
position: absolute;
|
|
48
|
-
bottom: 1rem;
|
|
49
|
-
left: 50%;
|
|
50
|
-
transform: translateX(-50%);
|
|
51
|
-
display: flex;
|
|
52
|
-
align-items: center;
|
|
53
|
-
cursor: pointer;
|
|
54
|
-
}
|
|
55
|
-
.ea-carousel_wrap .ea-carousel-indicator_wrap .ea-carousel-item_indicator {
|
|
56
|
-
width: 0.5rem;
|
|
57
|
-
height: 0.5rem;
|
|
58
|
-
border-radius: 50%;
|
|
59
|
-
background-color: rgba(255, 255, 255, 0.4);
|
|
60
|
-
margin: 0 0.25rem;
|
|
61
|
-
transition: background-color 0.3s;
|
|
62
|
-
}
|
|
63
|
-
.ea-carousel_wrap .ea-carousel-indicator_wrap .ea-carousel-item_indicator.ea-carousel-item_indicator--active {
|
|
64
|
-
background-color: #fff;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
:host {
|
|
68
|
-
--odd-bgc: #d3dce6;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.ea-carousel-item_wrap {
|
|
72
|
-
display: inline-block;
|
|
73
|
-
position: absolute;
|
|
74
|
-
top: 0;
|
|
75
|
-
left: 0;
|
|
76
|
-
width: 100%;
|
|
77
|
-
height: 100%;
|
|
78
|
-
overflow: hidden;
|
|
79
|
-
z-index: 0;
|
|
80
|
-
background-color: var(--odd-bgc);
|
|
81
|
-
display: flex;
|
|
82
|
-
align-items: center;
|
|
83
|
-
justify-content: center;
|
|
84
|
-
}
|
|
85
|
-
.ea-carousel-item_wrap ::slotted(img) {
|
|
86
|
-
width: 100%;
|
|
87
|
-
height: 100%;
|
|
88
|
-
object-fit: cover;
|
|
89
|
-
}
|
|
90
|
-
`;
|
|
91
|
-
|
|
92
|
-
export class EaCarousel extends Base {
|
|
93
|
-
#wrap;
|
|
94
|
-
|
|
95
|
-
#container;
|
|
96
|
-
|
|
97
|
-
#indicatorWrap;
|
|
98
|
-
|
|
99
|
-
#timer = null;
|
|
100
|
-
|
|
101
|
-
constructor() {
|
|
102
|
-
super();
|
|
103
|
-
|
|
104
|
-
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
105
|
-
const wrap = document.createElement('div');
|
|
106
|
-
wrap.className = 'ea-carousel_wrap';
|
|
107
|
-
|
|
108
|
-
const carouselSlot = createSlotElement('');
|
|
109
|
-
const container = createElement('div', 'ea-carousel_container', [carouselSlot]);
|
|
110
|
-
wrap.appendChild(container);
|
|
111
|
-
|
|
112
|
-
const indicatorWrap = createElement('div', 'ea-carousel-indicator_wrap');
|
|
113
|
-
wrap.appendChild(indicatorWrap);
|
|
114
|
-
|
|
115
|
-
this.#wrap = wrap;
|
|
116
|
-
this.#container = container;
|
|
117
|
-
this.#indicatorWrap = indicatorWrap;
|
|
118
|
-
|
|
119
|
-
this.build(shadowRoot, stylesheet);
|
|
120
|
-
this.shadowRoot.appendChild(wrap);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// ------- direction 轮播图方向 -------
|
|
124
|
-
// #region
|
|
125
|
-
get direction() {
|
|
126
|
-
const direction = this.getAttribute('direction');
|
|
127
|
-
return ["horizontal", "vertical"].includes(direction) ? direction : "horizontal";
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
set direction(value) {
|
|
131
|
-
this.setAttribute('direction', value);
|
|
132
|
-
|
|
133
|
-
this.#wrap.classList.add(`ea-carousel--${value}`);
|
|
134
|
-
}
|
|
135
|
-
// #endregion
|
|
136
|
-
// ------- end -------
|
|
137
|
-
|
|
138
|
-
// ------- index 轮播图索引 -------
|
|
139
|
-
// #region
|
|
140
|
-
get index() {
|
|
141
|
-
return this.getAttrNumber('index') || 0;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
set index(value) {
|
|
145
|
-
const index = this.#handleIndexOverflow(value);
|
|
146
|
-
|
|
147
|
-
this.setAttribute('index', index);
|
|
148
|
-
|
|
149
|
-
this.#container.style.transform = `translateX(-${index * this.#container.getBoundingClientRect().width}px)`;
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
const indicators = this.#indicatorWrap.querySelectorAll(`.ea-carousel-item_indicator`);
|
|
153
|
-
indicators.forEach(item => {
|
|
154
|
-
item.classList.remove('ea-carousel-item_indicator--active');
|
|
155
|
-
});
|
|
156
|
-
indicators[index].classList.add('ea-carousel-item_indicator--active');
|
|
157
|
-
} catch (e) { }
|
|
158
|
-
}
|
|
159
|
-
// #endregion
|
|
160
|
-
// ------- end -------
|
|
161
|
-
|
|
162
|
-
// ------- trigger 轮播图指示器触发方式 -------
|
|
163
|
-
// #region
|
|
164
|
-
get trigger() {
|
|
165
|
-
const trigger = this.getAttribute('trigger') || "hover";
|
|
166
|
-
return ["click", "hover"].includes(trigger) ? trigger : "click";
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
set trigger(value) {
|
|
170
|
-
this.setAttribute('trigger', value);
|
|
171
|
-
}
|
|
172
|
-
// #endregion
|
|
173
|
-
// ------- end -------
|
|
174
|
-
|
|
175
|
-
// ------- interval 轮播图自动播放间隔时间 -------
|
|
176
|
-
// #region
|
|
177
|
-
get interval() {
|
|
178
|
-
return this.getAttrNumber('interval') || 3;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
set interval(value) {
|
|
182
|
-
this.setAttribute('interval', value);
|
|
183
|
-
}
|
|
184
|
-
// #endregion
|
|
185
|
-
// ------- end -------
|
|
186
|
-
|
|
187
|
-
// ------- arrow 轮播图是否一直显示箭头 -------
|
|
188
|
-
// #region
|
|
189
|
-
get arrow() {
|
|
190
|
-
const arrow = this.getAttribute('arrow') || "hover";
|
|
191
|
-
return ["always", "hover", "never"].includes(arrow) ? arrow : "hover";
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
set arrow(value) {
|
|
195
|
-
this.setAttribute('arrow', value);
|
|
196
|
-
}
|
|
197
|
-
// #endregion
|
|
198
|
-
// ------- end -------
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* 处理索引溢出问题
|
|
202
|
-
* @param {number} val - 需要检查和调整的索引值
|
|
203
|
-
* @returns {number} - 调整后的合法索引值
|
|
204
|
-
*/
|
|
205
|
-
#handleIndexOverflow(val) {
|
|
206
|
-
// 获取容器孩子的数量
|
|
207
|
-
const length = this.querySelectorAll('ea-carousel-item').length - 1;
|
|
208
|
-
|
|
209
|
-
// 如果索引值小于0,将其设置为最后一个索引
|
|
210
|
-
if (val < 0) {
|
|
211
|
-
val = length;
|
|
212
|
-
// 如果索引值大于孩子数量,将其设置为第一个索引
|
|
213
|
-
} else if (val > length) {
|
|
214
|
-
val = 0;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// 返回调整后的索引值
|
|
218
|
-
return val;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* 初始化轮播项的位置和样式。
|
|
223
|
-
*/
|
|
224
|
-
#initCarouselItem() {
|
|
225
|
-
// 获取所有轮播项元素
|
|
226
|
-
const items = this.querySelectorAll('ea-carousel-item');
|
|
227
|
-
|
|
228
|
-
// 遍历每个轮播项
|
|
229
|
-
items.forEach((item, index) => {
|
|
230
|
-
// 延迟执行,创建动画效果的延迟
|
|
231
|
-
setTimeout(() => {
|
|
232
|
-
// 如果是奇数索引,设置特殊的背景色
|
|
233
|
-
if (index % 2 === 1) {
|
|
234
|
-
item.style.setProperty('--odd-bgc', '#99a9bf');
|
|
235
|
-
}
|
|
236
|
-
// 计算并设置轮播项的初始位置
|
|
237
|
-
item.translate = index * this.#wrap.getBoundingClientRect().width;
|
|
238
|
-
}, 20);
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* 初始化轮播指示器
|
|
244
|
-
*/
|
|
245
|
-
#initIndicators() {
|
|
246
|
-
const that = this;
|
|
247
|
-
|
|
248
|
-
// 获取所有轮播项元素
|
|
249
|
-
const items = this.querySelectorAll('ea-carousel-item');
|
|
250
|
-
items.forEach((item, index) => {
|
|
251
|
-
const indicator = createElement('div', 'ea-carousel-item_indicator');
|
|
252
|
-
this.#indicatorWrap.appendChild(indicator);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
// 遍历每个指示器
|
|
256
|
-
const indicators = this.#indicatorWrap.querySelectorAll('.ea-carousel-item_indicator');
|
|
257
|
-
indicators.forEach((indicator, index) => {
|
|
258
|
-
indicator.addEventListener(this.trigger === 'click' ? 'click' : 'mouseenter', () => {
|
|
259
|
-
that.index = index;
|
|
260
|
-
|
|
261
|
-
indicators.forEach((item) => {
|
|
262
|
-
item.classList.remove('ea-carousel-item_active');
|
|
263
|
-
})
|
|
264
|
-
indicator.classList.add('ea-carousel-item_active');
|
|
265
|
-
})
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* 创建箭头项
|
|
272
|
-
* @param {string} arrow - 箭头方向,"left" 或 "right"
|
|
273
|
-
* @param {string} show - 箭头显示的时机,"always"、"hover" 或 "never"
|
|
274
|
-
* @returns {HTMLElement} - 创建的箭头元素
|
|
275
|
-
*
|
|
276
|
-
* 该函数用于创建轮播图的左右箭头元素,并设置其初始状态和点击事件。
|
|
277
|
-
* 箭头元素的样式和位置会在鼠标进入和离开时动态改变。
|
|
278
|
-
*/
|
|
279
|
-
#createArrowItem(arrow, show) {
|
|
280
|
-
// 保持当前对象的引用
|
|
281
|
-
const that = this;
|
|
282
|
-
// 创建箭头元素,并根据方向添加相应的类名
|
|
283
|
-
const arrowItem = createElement('div', `ea-carousel-item_arrow ea-carousel-item_arrow--${arrow}`);
|
|
284
|
-
// 根据箭头方向设置箭头的HTML内容
|
|
285
|
-
arrowItem.innerHTML = arrow === "left" ? `<` : `>`;
|
|
286
|
-
|
|
287
|
-
switch (show) {
|
|
288
|
-
case "always":
|
|
289
|
-
// 如果显示时机为“总是”,则设置箭头的初始位置和透明度
|
|
290
|
-
arrowItem.style.transform = `translateY(-50%) translateX(${arrow === "left" ? 1 : -1}rem)`;
|
|
291
|
-
arrowItem.style.opacity = 1;
|
|
292
|
-
break;
|
|
293
|
-
case "hover":
|
|
294
|
-
// 当鼠标进入箭头元素时,改变其位置和透明度
|
|
295
|
-
this.#wrap.addEventListener('mouseenter', (e) => {
|
|
296
|
-
arrowItem.style.transform = `translateY(-50%) translateX(${arrow === "left" ? 1 : -1}rem)`;
|
|
297
|
-
arrowItem.style.opacity = 1;
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
// 当鼠标离开箭头元素时,恢复其初始位置和透明度
|
|
301
|
-
this.#wrap.addEventListener('mouseleave', (e) => {
|
|
302
|
-
arrowItem.style.transform = `translateY(-50%) translateX(${arrow === "left" ? -100 : 100}%)`;
|
|
303
|
-
arrowItem.style.opacity = 0;
|
|
304
|
-
})
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// 绑定点击事件,根据箭头方向改变轮播图的索引
|
|
309
|
-
arrowItem.addEventListener('click', (e) => {
|
|
310
|
-
that.index = arrow === "left" ? --that.index : ++that.index;
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
// 返回创建的箭头元素
|
|
314
|
-
return arrowItem;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* 初始化箭头项
|
|
319
|
-
* 该方法用于创建并添加左右两个箭头项到指定的包装元素中。
|
|
320
|
-
* 这两个箭头项分别代表向左和向右的导航功能。
|
|
321
|
-
*
|
|
322
|
-
* @private
|
|
323
|
-
*/
|
|
324
|
-
#initArrowItem(show) {
|
|
325
|
-
if (show === "never") return;
|
|
326
|
-
|
|
327
|
-
// 创建一个向左的箭头项
|
|
328
|
-
const leftArrowItem = this.#createArrowItem("left", show);
|
|
329
|
-
// 创建一个向右的箭头项
|
|
330
|
-
const rightArrowItem = this.#createArrowItem("right", show);
|
|
331
|
-
|
|
332
|
-
// 将左箭头项添加到包装元素中
|
|
333
|
-
this.#wrap.appendChild(leftArrowItem);
|
|
334
|
-
// 将右箭头项添加到包装元素中
|
|
335
|
-
this.#wrap.appendChild(rightArrowItem);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* 初始化轮播图自动播放功能。
|
|
340
|
-
* @param {number} duration - 每张图片展示的时间间隔,单位为秒。
|
|
341
|
-
*/
|
|
342
|
-
#initCarouselAutoPlay(duration) {
|
|
343
|
-
// 保存当前上下文的引用
|
|
344
|
-
const that = this;
|
|
345
|
-
// 设置定时器,每隔一定时间自动切换到下一张图片
|
|
346
|
-
this.#timer = setInterval(() => {
|
|
347
|
-
this.index = this.index + 1;
|
|
348
|
-
}, duration * 1000);
|
|
349
|
-
|
|
350
|
-
// 当鼠标进入轮播图区域时,停止自动播放
|
|
351
|
-
this.addEventListener('mouseenter', () => {
|
|
352
|
-
clearInterval(this.#timer);
|
|
353
|
-
that.#timer = null;
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
// 当鼠标离开轮播图区域时,恢复自动播放
|
|
357
|
-
this.addEventListener('mouseleave', () => {
|
|
358
|
-
that.#timer = setInterval(() => {
|
|
359
|
-
this.index = this.index + 1;
|
|
360
|
-
}, duration * 1000)
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
init() {
|
|
365
|
-
const that = this;
|
|
366
|
-
|
|
367
|
-
this.direction = this.direction;
|
|
368
|
-
|
|
369
|
-
this.trigger = this.trigger;
|
|
370
|
-
|
|
371
|
-
this.interval = this.interval;;
|
|
372
|
-
|
|
373
|
-
this.arrow = this.arrow;
|
|
374
|
-
|
|
375
|
-
this.#initCarouselItem();
|
|
376
|
-
this.#initArrowItem(this.arrow);
|
|
377
|
-
this.#initIndicators(this.interval);
|
|
378
|
-
this.#initCarouselAutoPlay(this.interval);
|
|
379
|
-
|
|
380
|
-
this.index = this.index;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
connectedCallback() {
|
|
384
|
-
this.init();
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
export class EaCarouselItem extends Base {
|
|
389
|
-
#wrap;
|
|
390
|
-
constructor() {
|
|
391
|
-
super();
|
|
392
|
-
|
|
393
|
-
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
394
|
-
const wrap = document.createElement('div');
|
|
395
|
-
wrap.className = 'ea-carousel-item_wrap';
|
|
396
|
-
|
|
397
|
-
const carouselSlot = createSlotElement('');
|
|
398
|
-
wrap.appendChild(carouselSlot);
|
|
399
|
-
|
|
400
|
-
this.#wrap = wrap;
|
|
401
|
-
|
|
402
|
-
this.build(shadowRoot, stylesheet);
|
|
403
|
-
this.shadowRoot.appendChild(wrap);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// ------- translate 图片偏移 -------
|
|
407
|
-
// #region
|
|
408
|
-
get translate() {
|
|
409
|
-
return this.getAttribute('translate') || 0;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
set translate(value) {
|
|
413
|
-
this.setAttribute('translate', value);
|
|
414
|
-
|
|
415
|
-
this.#wrap.style.transform = `translateX(${value}px) scale(1)`;
|
|
416
|
-
}
|
|
417
|
-
// #endregion
|
|
418
|
-
// ------- end -------
|
|
419
|
-
|
|
420
|
-
init() {
|
|
421
|
-
const that = this;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
connectedCallback() {
|
|
425
|
-
this.init();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
if (!customElements.get('ea-carousel')) {
|
|
430
|
-
customElements.define('ea-carousel', EaCarousel);
|
|
431
|
-
}
|
|
432
|
-
if (!customElements.get('ea-carousel-item')) {
|
|
433
|
-
customElements.define('ea-carousel-item', EaCarouselItem);
|
|
434
|
-
}
|
|
1
|
+
import Base from"../Base.js";import"../ea-carousel-item/index.js";import{createElement}from"../../utils/createElement.js";import{handleIndexOverflow}from"./src/utils/handleIndexOverflow.js";import{stylesheet}from"./src/style/stylesheet.js";export class EaCarousel extends Base{#t;#e;#i;constructor(){super();const t=this.attachShadow({mode:"open"});t.innerHTML="\n <div class='ea-carousel_wrap' part='container'>\n <div class='ea-carousel_content-container' part='content-wrap'>\n <slot></slot>\n </div>\n <div class='ea-carousel-indicator_wrap' part='indicator-wrap'></div>\n </div>\n ",this.#t=t.querySelector(".ea-carousel_wrap"),this.#e=t.querySelector(".ea-carousel_content-container"),this.#i=t.querySelector(".ea-carousel-indicator_wrap"),this.build(t,stylesheet)}get direction(){const t=this.getAttribute("direction");return["horizontal","vertical"].includes(t)?t:"horizontal"}set direction(t){this.setAttribute("direction",t),this.#t.classList.add(`ea-carousel--${t}`)}get index(){return this.getAttrNumber("index")||0}set index(t){const e=this.querySelectorAll("ea-carousel-item").length-1,i=handleIndexOverflow(e,t);this.setAttribute("index",i);const r=this.#t.getBoundingClientRect(),s="horizontal"===this.direction?"X":"Y",a="horizontal"===this.direction?r.width:r.height;this.#e.style.transform=`translate${s}(-${i*a}px)`;try{const t=this.#i.querySelectorAll(".ea-carousel-item_indicator");t.forEach((t=>{t.classList.remove("ea-carousel-item_indicator--active")})),t[i].classList.add("ea-carousel-item_indicator--active")}catch(t){}}get trigger(){const t=this.getAttribute("trigger")||"hover";return["click","hover"].includes(t)?t:"click"}set trigger(t){this.setAttribute("trigger",t)}get interval(){return this.getAttrNumber("interval")||3}set interval(t){this.setAttribute("interval",t)}get arrow(){const t=this.getAttribute("arrow")||"hover";return["always","hover","never"].includes(t)?t:"hover"}set arrow(t){this.setAttribute("arrow",t)}#r(){const t=this.querySelectorAll("ea-carousel-item").length;for(let e=0;e<t;e++){const t=createElement("div","ea-carousel-item_indicator");this.#i.appendChild(t)}const e=this.#i.querySelectorAll(".ea-carousel-item_indicator");e[0].classList.add("ea-carousel-item_indicator--active"),e.forEach(((t,i)=>{t.addEventListener("click"===this.trigger?"click":"mouseenter",(()=>{this.index=i,e.forEach((t=>{t.classList.remove("ea-carousel-item_active")})),t.classList.add("ea-carousel-item_active")}))}))}#s(){let t=setInterval((()=>{this.index=this.index+1}),1e3*this.interval);this.addEventListener("mouseenter",(()=>{clearInterval(t),t=null})),this.addEventListener("mouseleave",(()=>{t=setInterval((()=>{this.index=this.index+1}),1e3*this.interval)}))}#a(t){let e=!1;const i=createElement("div",`ea-carousel-item_arrow ea-carousel-item_arrow--${t}`);switch(i.innerHTML="left"===t?"<":">",this.arrow){case"always":this.#t.classList.add("always-show-arrow");break;case"hover":this.#t.classList.add("hover-trigger")}return i.addEventListener("click",(()=>{e||(this.index="left"===t?--this.index:++this.index)})),this.#e.addEventListener("transitionstart",(()=>{e=!0})),this.#e.addEventListener("transitionend",(()=>{e=!1})),i}connectedCallback(){if(this.direction=this.direction,this.trigger=this.trigger,this.interval=this.interval,this.arrow=this.arrow,this.index=this.index,this.#r(),this.#s(),"never"!==this.arrow||"vertical"!==this.direction){const t=this.#a("left"),e=this.#a("right");this.#t.appendChild(t),this.#t.appendChild(e)}window.addEventListener("resize",(()=>{this.index=this.index}))}}customElements.get("ea-carousel")||customElements.define("ea-carousel",EaCarousel);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const stylesheet="\n.ea-carousel_wrap {\n position: relative;\n overflow: hidden;\n}\n.ea-carousel_wrap .ea-carousel_content-container {\n position: relative;\n display: flex;\n color: #fff;\n text-align: center;\n height: 300px;\n transition: transform 0.5s;\n}\n.ea-carousel_wrap .ea-carousel_content-container ::slotted(ea-carousel-item) {\n flex: 0 0 100%;\n width: 100%;\n}\n.ea-carousel_wrap .ea-carousel-item_arrow {\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n opacity: 0;\n width: 1.5rem;\n height: 1.5rem;\n line-height: 1.5;\n font-weight: 800;\n text-align: center;\n border-radius: 50%;\n background-color: rgba(31, 45, 61, 0.11);\n color: #fff;\n cursor: pointer;\n user-select: none;\n transition: background-color 0.3s, transform 0.3s, opacity 0.3s;\n}\n.ea-carousel_wrap .ea-carousel-item_arrow.ea-carousel-item_arrow--left {\n left: 0;\n transform: translate(-100%, -50%);\n}\n.ea-carousel_wrap .ea-carousel-item_arrow.ea-carousel-item_arrow--right {\n right: 0;\n transform: translate(100%, -50%);\n}\n.ea-carousel_wrap .ea-carousel-item_arrow:hover {\n background-color: rgba(31, 45, 61, 0.3);\n}\n.ea-carousel_wrap .ea-carousel-indicator_wrap {\n position: absolute;\n bottom: 1rem;\n left: 50%;\n transform: translateX(-50%);\n display: flex;\n flex-direction: row;\n align-items: center;\n cursor: pointer;\n}\n.ea-carousel_wrap .ea-carousel-indicator_wrap .ea-carousel-item_indicator {\n width: 0.5rem;\n height: 0.5rem;\n border-radius: 50%;\n background-color: rgba(255, 255, 255, 0.4);\n margin: 0.25rem;\n transition: background-color 0.3s;\n}\n.ea-carousel_wrap .ea-carousel-indicator_wrap .ea-carousel-item_indicator.ea-carousel-item_indicator--active {\n background-color: #fff;\n}\n.ea-carousel_wrap ::slotted(ea-carousel-item:nth-child(odd)) {\n --odd-bgc: #d3dce6;\n}\n.ea-carousel_wrap.hover-trigger:hover .ea-carousel-item_arrow.ea-carousel-item_arrow--left {\n left: 0;\n transform: translate(50%, -50%);\n opacity: 1;\n}\n.ea-carousel_wrap.hover-trigger:hover .ea-carousel-item_arrow.ea-carousel-item_arrow--right {\n right: 0;\n transform: translate(-50%, -50%);\n opacity: 1;\n}\n.ea-carousel_wrap.always-show-arrow .ea-carousel-item_arrow.ea-carousel-item_arrow--left {\n left: 0;\n transform: translate(50%, -50%);\n opacity: 1;\n}\n.ea-carousel_wrap.always-show-arrow .ea-carousel-item_arrow.ea-carousel-item_arrow--right {\n right: 0;\n transform: translate(-50%, -50%);\n opacity: 1;\n}\n.ea-carousel_wrap.ea-carousel--horizontal .ea-carousel_content-container {\n flex-direction: row;\n}\n.ea-carousel_wrap.ea-carousel--vertical .ea-carousel_content-container {\n flex-direction: column;\n}\n.ea-carousel_wrap.ea-carousel--vertical .ea-carousel-item_arrow {\n display: none;\n}\n.ea-carousel_wrap.ea-carousel--vertical .ea-carousel-indicator_wrap {\n left: 100%;\n bottom: 50%;\n flex-direction: column;\n transform: translate(-200%, 50%);\n}\n";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function handleIndexOverflow(e,n){return n<0?n=e:n>e&&(n=0),n}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import Base from"../Base.js";import{stylesheet}from"./src/style/stylesheet.js";export class EaCarouselItem extends Base{constructor(){super();const e=this.attachShadow({mode:"open"});e.innerHTML="\n <div class='ea-carousel-item_wrap' part='container'>\n <slot></slot>\n </div>\n ",this.build(e,stylesheet)}}customElements.get("ea-carousel-item")||customElements.define("ea-carousel-item",EaCarouselItem);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const stylesheet="\n:host {\n --odd-bgc: #99a9bf;\n}\n\n.ea-carousel-item_wrap {\n display: inline-block;\n width: 100%;\n height: 100%;\n overflow: hidden;\n z-index: 0;\n background-color: var(--odd-bgc);\n display: flex;\n align-items: center;\n justify-content: center;\n}\n.ea-carousel-item_wrap ::slotted(img) {\n width: 100%;\n height: 100%;\n object-fit: cover;\n}\n";
|