@rcarls/rc-carousel 0.6.0 → 0.7.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/CHANGELOG.md +117 -0
- package/README.md +8 -0
- package/dist/custom-elements.json +257 -5
- package/dist/{rc-carousel-CdDEH9fb.js → rc-carousel-CGHUVDLI.js} +245 -275
- package/dist/rc-carousel-CGHUVDLI.js.map +1 -0
- package/dist/rc-carousel-define.js +3 -1
- package/dist/rc-carousel-define.js.map +1 -1
- package/dist/rc-carousel.js +4 -3
- package/dist/types/packages/rc-carousel/src/rc-carousel-item.d.ts +9 -1
- package/dist/types/packages/rc-carousel/src/rc-carousel.d.ts +66 -5
- package/package.json +2 -2
- package/dist/rc-carousel-CdDEH9fb.js.map +0 -1
|
@@ -1,64 +1,40 @@
|
|
|
1
|
-
import { css as
|
|
2
|
-
import { property as
|
|
3
|
-
import { DragGestureController as
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
min-block-size: 0;
|
|
10
|
-
scroll-snap-align: var(--rc-carousel-item-scroll-snap-align, start);
|
|
11
|
-
/*
|
|
12
|
-
* Without this, a normal-speed swipe carries enough fling momentum to
|
|
13
|
-
* sail past the very next item and settle two (or more) items over —
|
|
14
|
-
* \`mandatory\` scroll-snap-type on the track alone only guarantees
|
|
15
|
-
* landing on *a* snap point, not the nearest one. \`always\` forces the
|
|
16
|
-
* browser to stop at each snap point in turn.
|
|
17
|
-
*/
|
|
18
|
-
scroll-snap-stop: always;
|
|
19
|
-
overflow: var(--rc-carousel-item-overflow, hidden);
|
|
20
|
-
border-radius: var(--rc-carousel-item-border-radius, 0);
|
|
21
|
-
background: var(--rc-carousel-item-background, transparent);
|
|
22
|
-
color: var(--rc-carousel-item-color, CanvasText);
|
|
23
|
-
color-scheme: inherit;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
:host([hidden]) {
|
|
27
|
-
display: none;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
* Peeking/off-screen items are hidden from assistive technology (see
|
|
32
|
-
* rc-carousel-item.ts's IntersectionObserver) but must stay visually and
|
|
33
|
-
* interactively present — a peek is a legitimate visual affordance, not
|
|
34
|
-
* decoration to strip. This only removes it from the accessibility tree
|
|
35
|
-
* and, via inert, the tab sequence, matching the same technique proven
|
|
36
|
-
* carousels (e.g. Shoelace's sl-carousel) use for exactly this problem.
|
|
37
|
-
*/
|
|
38
|
-
:host([aria-hidden='true']) {
|
|
39
|
-
pointer-events: none;
|
|
40
|
-
}
|
|
41
|
-
`;
|
|
42
|
-
var S = Object.defineProperty, E = (c, t, e, s) => {
|
|
43
|
-
for (var i = void 0, n = c.length - 1, a; n >= 0; n--)
|
|
44
|
-
(a = c[n]) && (i = a(t, e, i) || i);
|
|
45
|
-
return i && S(t, e, i), i;
|
|
1
|
+
import { css as k, LitElement as A, html as h, nothing as p } from "lit";
|
|
2
|
+
import { property as c, query as S, state as w } from "lit/decorators.js";
|
|
3
|
+
import { syncDefaultAttribute as _, RafScheduler as E, MessagesController as T, HORIZONTAL_LTR_FLOW as O, DragGestureController as D, logicalDelta as v, findNearestSnapIndex as P, findExtremeSnapIndex as m, resolveFlow as b, clientSize as $, physicalAxis as z, getScrollOffset as N, setScrollOffset as x, findNextSnapIndex as R, keyNavigation as I, numberFormat as y } from "@rcarls/rc-common";
|
|
4
|
+
const L = k`:host{box-sizing:border-box;scroll-snap-align:var(--rc-carousel-item-scroll-snap-align,start);scroll-snap-stop:always;min-block-size:0;min-inline-size:0;overflow:var(--rc-carousel-item-overflow,hidden);border-radius:var(--rc-carousel-item-border-radius,0);background:var(--rc-carousel-item-background,transparent);color:var(--rc-carousel-item-color,CanvasText);color-scheme:inherit;display:block}:host([hidden]){display:none}:host([aria-hidden=true]){pointer-events:none}`;
|
|
5
|
+
var F = Object.defineProperty, C = (l, t, e, i) => {
|
|
6
|
+
for (var s = void 0, n = l.length - 1, o; n >= 0; n--)
|
|
7
|
+
(o = l[n]) && (s = o(t, e, s) || s);
|
|
8
|
+
return s && F(t, e, s), s;
|
|
46
9
|
};
|
|
47
|
-
const
|
|
10
|
+
const f = class f extends A {
|
|
48
11
|
constructor() {
|
|
49
|
-
super(), this._intersectionObserver = null, this.position = "", this._internals = this.attachInternals(), this._internals.role = "group";
|
|
12
|
+
super(), this._intersectionObserver = null, this.position = "", this.roleDescription = "slide", this._writtenLabel = null, this._writtenRoleDescription = null, this._internals = this.attachInternals(), this._internals.role = "group";
|
|
50
13
|
}
|
|
51
14
|
connectedCallback() {
|
|
52
|
-
super.connectedCallback(), this.hasAttribute("role") || this.setAttribute("role", "group"), this.
|
|
15
|
+
super.connectedCallback(), this.hasAttribute("role") || this.setAttribute("role", "group"), this._syncRoleDescription(), this._observeIntersection();
|
|
53
16
|
}
|
|
54
17
|
disconnectedCallback() {
|
|
55
18
|
super.disconnectedCallback(), this._intersectionObserver?.disconnect(), this._intersectionObserver = null;
|
|
56
19
|
}
|
|
57
20
|
updated(t) {
|
|
58
|
-
super.updated(t), t.has("position") && this._syncDefaultLabel();
|
|
21
|
+
super.updated(t), t.has("position") && this._syncDefaultLabel(), t.has("roleDescription") && this._syncRoleDescription();
|
|
59
22
|
}
|
|
60
23
|
_syncDefaultLabel() {
|
|
61
|
-
this.hasAttribute("aria-
|
|
24
|
+
this.hasAttribute("aria-labelledby") || !this.position || (this._writtenLabel = _(
|
|
25
|
+
this,
|
|
26
|
+
"aria-label",
|
|
27
|
+
this.position,
|
|
28
|
+
this._writtenLabel
|
|
29
|
+
));
|
|
30
|
+
}
|
|
31
|
+
_syncRoleDescription() {
|
|
32
|
+
this._writtenRoleDescription = _(
|
|
33
|
+
this,
|
|
34
|
+
"aria-roledescription",
|
|
35
|
+
this.roleDescription,
|
|
36
|
+
this._writtenRoleDescription
|
|
37
|
+
);
|
|
62
38
|
}
|
|
63
39
|
/**
|
|
64
40
|
* Observes intersection against the parent carousel's own scroll
|
|
@@ -83,9 +59,9 @@ const p = class p extends m {
|
|
|
83
59
|
return;
|
|
84
60
|
}
|
|
85
61
|
this._intersectionObserver = new IntersectionObserver(
|
|
86
|
-
([
|
|
87
|
-
const
|
|
88
|
-
|
|
62
|
+
([i]) => {
|
|
63
|
+
const s = i !== void 0 && !i.isIntersecting;
|
|
64
|
+
s ? (this.contains(this.ownerDocument.activeElement) && t?.trackElement?.focus(), this.setAttribute("aria-hidden", "true")) : this.removeAttribute("aria-hidden"), this.toggleAttribute("inert", s);
|
|
89
65
|
},
|
|
90
66
|
// A low/zero threshold would count a peeking neighbor's own sliver
|
|
91
67
|
// of visible pixels as "intersecting", never hiding it — a peek is
|
|
@@ -99,168 +75,76 @@ const p = class p extends m {
|
|
|
99
75
|
return h`<slot></slot>`;
|
|
100
76
|
}
|
|
101
77
|
};
|
|
102
|
-
|
|
103
|
-
let u =
|
|
104
|
-
|
|
105
|
-
|
|
78
|
+
f.styles = L;
|
|
79
|
+
let u = f;
|
|
80
|
+
C([
|
|
81
|
+
c({ type: String, attribute: !1 })
|
|
106
82
|
], u.prototype, "position");
|
|
107
|
-
|
|
108
|
-
:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
#track {
|
|
116
|
-
display: grid;
|
|
117
|
-
grid-auto-flow: column;
|
|
118
|
-
grid-auto-columns: var(--rc-carousel-slide-size, calc(100% - 4rem));
|
|
119
|
-
column-gap: var(--rc-carousel-gap, 8px);
|
|
120
|
-
inline-size: 100%;
|
|
121
|
-
block-size: 100%;
|
|
122
|
-
overflow-x: auto;
|
|
123
|
-
overflow-y: hidden;
|
|
124
|
-
overscroll-behavior-x: contain;
|
|
125
|
-
scroll-snap-type: x mandatory;
|
|
126
|
-
/*
|
|
127
|
-
* Deliberately no \`scroll-behavior: smooth\` here — _scrollToIndex in
|
|
128
|
-
* rc-carousel.ts passes \`behavior: 'smooth'\` explicitly per
|
|
129
|
-
* programmatic call instead, which is unaffected either way (an
|
|
130
|
-
* explicit argument always overrides this CSS default). Setting it
|
|
131
|
-
* here as an ambient default would also apply to the browser's own
|
|
132
|
-
* native snap-settle correction after a swipe — a documented
|
|
133
|
-
* cross-browser conflict with scroll-snap-stop: always (each
|
|
134
|
-
* rc-carousel-item sets that; Firefox bugzilla 1643217, 1959811)
|
|
135
|
-
* that produces a jerk-then-snap-back artifact on an ordinary swipe.
|
|
136
|
-
*/
|
|
137
|
-
scrollbar-width: none;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
#track::-webkit-scrollbar {
|
|
141
|
-
display: none;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
:host([mouse-dragging]) #track {
|
|
145
|
-
cursor: grab;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
:host([mouse-dragging]) #track.dragging {
|
|
149
|
-
cursor: grabbing;
|
|
150
|
-
/*
|
|
151
|
-
* scroll-snap-type itself is toggled imperatively in rc-carousel.ts,
|
|
152
|
-
* not here — it must be off before the very first scrollLeft write of
|
|
153
|
-
* a drag, and this class only lands on the next reactive render, a
|
|
154
|
-
* render pass too late for that first write (the browser eagerly
|
|
155
|
-
* resnaps a plain scrollLeft assignment right back to the nearest
|
|
156
|
-
* snap point, same as any other programmatic scroll).
|
|
157
|
-
*/
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
#navigation {
|
|
161
|
-
display: contents;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
[part~='navigation-button'] {
|
|
165
|
-
position: absolute;
|
|
166
|
-
top: 50%;
|
|
167
|
-
translate: 0 -50%;
|
|
168
|
-
display: inline-flex;
|
|
169
|
-
align-items: center;
|
|
170
|
-
justify-content: center;
|
|
171
|
-
inline-size: var(--rc-carousel-navigation-button-size, 40px);
|
|
172
|
-
block-size: var(--rc-carousel-navigation-button-size, 40px);
|
|
173
|
-
border: none;
|
|
174
|
-
border-radius: 50%;
|
|
175
|
-
background: var(
|
|
176
|
-
--rc-carousel-navigation-button-background,
|
|
177
|
-
color-mix(in srgb, CanvasText 12%, transparent)
|
|
178
|
-
);
|
|
179
|
-
color: var(--rc-carousel-navigation-button-color, CanvasText);
|
|
180
|
-
cursor: pointer;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
[part~='navigation-button'][aria-disabled='true'] {
|
|
184
|
-
opacity: 0.38;
|
|
185
|
-
cursor: default;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
[part~='navigation-button-previous'] {
|
|
189
|
-
inset-inline-start: var(--rc-carousel-navigation-inset, 8px);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
[part~='navigation-button-next'] {
|
|
193
|
-
inset-inline-end: var(--rc-carousel-navigation-inset, 8px);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
#pagination {
|
|
197
|
-
position: absolute;
|
|
198
|
-
inset-block-end: var(--rc-carousel-navigation-inset, 8px);
|
|
199
|
-
inset-inline: 0;
|
|
200
|
-
display: flex;
|
|
201
|
-
justify-content: center;
|
|
202
|
-
gap: var(--rc-carousel-gap, 8px);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
[part~='pagination-item'] {
|
|
206
|
-
inline-size: var(--rc-carousel-pagination-item-size, 8px);
|
|
207
|
-
block-size: var(--rc-carousel-pagination-item-size, 8px);
|
|
208
|
-
padding: 0;
|
|
209
|
-
border: none;
|
|
210
|
-
border-radius: 50%;
|
|
211
|
-
background: var(
|
|
212
|
-
--rc-carousel-pagination-item-color,
|
|
213
|
-
color-mix(in srgb, CanvasText 40%, transparent)
|
|
214
|
-
);
|
|
215
|
-
cursor: pointer;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
[part~='pagination-item-active'] {
|
|
219
|
-
background: var(--rc-carousel-pagination-item-active-color, Highlight);
|
|
220
|
-
cursor: default;
|
|
221
|
-
}
|
|
222
|
-
`;
|
|
223
|
-
var T = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, o = (c, t, e, s) => {
|
|
224
|
-
for (var i = s > 1 ? void 0 : s ? $(t, e) : t, n = c.length - 1, a; n >= 0; n--)
|
|
225
|
-
(a = c[n]) && (i = (s ? a(t, e, i) : a(i)) || i);
|
|
226
|
-
return s && i && T(t, e, i), i;
|
|
83
|
+
C([
|
|
84
|
+
c({ type: String, attribute: !1 })
|
|
85
|
+
], u.prototype, "roleDescription");
|
|
86
|
+
const q = k`:host{color:var(--rc-carousel-color,CanvasText);color-scheme:inherit;display:block;position:relative}#track{grid-auto-flow:column;grid-auto-columns:var(--rc-carousel-slide-size,calc(100% - 4rem));column-gap:var(--rc-carousel-gap,8px);overflow-inline:auto;overflow-block:hidden;overscroll-behavior-inline:contain;scroll-snap-type:inline mandatory;scrollbar-width:none;block-size:100%;inline-size:100%;display:grid;overflow:auto hidden}#track::-webkit-scrollbar{display:none}:host([mouse-dragging]) #track{cursor:grab}:host([mouse-dragging]) #track.dragging{cursor:grabbing}#navigation{display:contents}[part~=navigation-button]{inline-size:var(--rc-carousel-navigation-button-size,40px);block-size:var(--rc-carousel-navigation-button-size,40px);background:var(--rc-carousel-navigation-button-background,color-mix(in srgb, CanvasText 12%, transparent));color:var(--rc-carousel-navigation-button-color,CanvasText);cursor:pointer;border:none;border-radius:50%;justify-content:center;align-items:center;display:inline-flex;position:absolute;top:50%;translate:0 -50%}[part~=navigation-button][aria-disabled=true]{opacity:.38;cursor:default}[part~=navigation-button-previous]{inset-inline-start:var(--rc-carousel-navigation-inset,8px)}[part~=navigation-button-next]{inset-inline-end:var(--rc-carousel-navigation-inset,8px)}#pagination{justify-content:center;gap:var(--rc-carousel-gap,8px);display:flex;position:absolute;inset-block-end:var(--rc-carousel-navigation-inset,8px);inset-inline:0}[part~=pagination-item]{inline-size:var(--rc-carousel-pagination-item-size,8px);block-size:var(--rc-carousel-pagination-item-size,8px);background:var(--rc-carousel-pagination-item-color,color-mix(in srgb, CanvasText 40%, transparent));cursor:pointer;border:none;border-radius:50%;padding:0}[part~=pagination-item-active]{background:var(--rc-carousel-pagination-item-active-color,Highlight);cursor:default}:host(:dir(rtl)) [part~=navigation-button] svg{transform:scaleX(-1)}`;
|
|
87
|
+
var M = Object.defineProperty, U = Object.getOwnPropertyDescriptor, a = (l, t, e, i) => {
|
|
88
|
+
for (var s = i > 1 ? void 0 : i ? U(t, e) : t, n = l.length - 1, o; n >= 0; n--)
|
|
89
|
+
(o = l[n]) && (s = (i ? o(t, e, s) : o(s)) || s);
|
|
90
|
+
return i && s && M(t, e, s), s;
|
|
227
91
|
};
|
|
228
|
-
const
|
|
92
|
+
const B = 300, j = Object.freeze({
|
|
93
|
+
carousel: "carousel",
|
|
94
|
+
slide: "slide",
|
|
95
|
+
position: (l, t, e) => {
|
|
96
|
+
const i = y(e, { useGrouping: !1 });
|
|
97
|
+
return `${i.format(l)} of ${i.format(t)}`;
|
|
98
|
+
},
|
|
99
|
+
previous: "Previous slide",
|
|
100
|
+
next: "Next slide",
|
|
101
|
+
picker: "Choose slide to display",
|
|
102
|
+
goToSlide: (l, t, e) => `Go to slide ${y(e, { useGrouping: !1 }).format(l)}`
|
|
103
|
+
}), G = 120, g = class g extends A {
|
|
229
104
|
constructor() {
|
|
230
|
-
super(), this._items = [], this._cloneItems = [], this._mounted = !1, this._suppressSync = !1, this._pendingInstant = !1, this.
|
|
105
|
+
super(), this._items = [], this._cloneItems = [], this._mounted = !1, this._suppressSync = !1, this._pendingInstant = !1, this._initialPosition = new E(this), this._writtenRoleDescription = null, this._messages = new T(
|
|
106
|
+
this,
|
|
107
|
+
"rc-carousel",
|
|
108
|
+
j,
|
|
109
|
+
{
|
|
110
|
+
overrides: () => this.messages
|
|
111
|
+
}
|
|
112
|
+
), this.loop = !1, this.navigation = !1, this.pagination = !1, this.mouseDragging = !1, this._dragging = !1, this._dragStartOffset = 0, this._flow = O, this._dragAxis = "x", this._suppressNextClick = !1, this._dragController = new D(this, {
|
|
231
113
|
target: () => this._trackEl ?? null,
|
|
232
114
|
axis: "x",
|
|
233
115
|
activation: "axis",
|
|
234
|
-
canStart: (t) => this.mouseDragging
|
|
116
|
+
canStart: (t) => !this.mouseDragging || t.pointerType !== "mouse" ? !1 : (this._resolveFlow(), !0),
|
|
235
117
|
onStart: () => {
|
|
236
|
-
this._dragging = !0, this.
|
|
118
|
+
this._dragging = !0, this._dragStartOffset = this._trackOffset(), this._suppressNextClick = !0, this._trackEl && (this._trackEl.style.scrollSnapType = "none");
|
|
237
119
|
},
|
|
238
120
|
onMove: (t) => {
|
|
239
|
-
this.
|
|
121
|
+
this._setTrackOffset(
|
|
122
|
+
this._dragStartOffset - v({ dx: t.deltaX, dy: t.deltaY }, "inline", this._flow)
|
|
123
|
+
);
|
|
240
124
|
},
|
|
241
125
|
onEnd: (t) => this._endDrag(t),
|
|
242
126
|
onCancel: (t) => this._endDrag(t)
|
|
243
127
|
}), this._busy = !1, this._defaultActiveIndex = 0, this._activeIndexInitialized = !1, this._onSlotChange = () => {
|
|
244
128
|
this._syncItems();
|
|
245
129
|
}, this._onScroll = () => {
|
|
246
|
-
this._settleTimer !== void 0 && clearTimeout(this._settleTimer), this._busy = !0, this._settleTimer = setTimeout(this._commitSettledIndex,
|
|
130
|
+
this._settleTimer !== void 0 && clearTimeout(this._settleTimer), this._busy = !0, this._settleTimer = setTimeout(this._commitSettledIndex, G);
|
|
247
131
|
}, this._commitSettledIndex = () => {
|
|
248
132
|
if (this._busy = !1, !this._trackEl)
|
|
249
133
|
return;
|
|
250
|
-
const t = this._trackSlots(), e =
|
|
134
|
+
const t = this._trackSlots(), e = P(
|
|
251
135
|
t.map((n) => n.point),
|
|
252
|
-
this.
|
|
253
|
-
),
|
|
254
|
-
if (!
|
|
136
|
+
this._trackOffset()
|
|
137
|
+
), i = e >= 0 ? t[e] : void 0;
|
|
138
|
+
if (!i)
|
|
255
139
|
return;
|
|
256
|
-
if (
|
|
257
|
-
const n = t.find((
|
|
258
|
-
n &&
|
|
140
|
+
if (i.isClone) {
|
|
141
|
+
const n = t.find((o) => !o.isClone && o.index === i.index);
|
|
142
|
+
n && this._setTrackOffset(n.point);
|
|
259
143
|
}
|
|
260
|
-
if (
|
|
144
|
+
if (i.index === this.activeIndex)
|
|
261
145
|
return;
|
|
262
|
-
const
|
|
263
|
-
|
|
146
|
+
const s = this._activeIndex !== void 0;
|
|
147
|
+
s || (this._suppressSync = !0), this._setActiveIndex(i.index, "swipe"), s && this.activeIndex !== i.index && this._scrollToIndex(this.activeIndex, !0);
|
|
264
148
|
}, this._onNavigate = (t) => {
|
|
265
149
|
switch (t) {
|
|
266
150
|
case "next":
|
|
@@ -270,12 +154,12 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
270
154
|
this._step(-1, "keyboard");
|
|
271
155
|
break;
|
|
272
156
|
case "start": {
|
|
273
|
-
const e =
|
|
157
|
+
const e = m(this._snapPoints(), -1);
|
|
274
158
|
e >= 0 && this._setActiveIndex(e, "keyboard");
|
|
275
159
|
break;
|
|
276
160
|
}
|
|
277
161
|
case "end": {
|
|
278
|
-
const e =
|
|
162
|
+
const e = m(this._snapPoints(), 1);
|
|
279
163
|
e >= 0 && this._setActiveIndex(e, "keyboard");
|
|
280
164
|
break;
|
|
281
165
|
}
|
|
@@ -283,19 +167,19 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
283
167
|
}, this._onTrackClickCapture = (t) => {
|
|
284
168
|
this._suppressNextClick && (this._suppressNextClick = !1, t.stopPropagation(), t.preventDefault());
|
|
285
169
|
}, this._onPaginationFocus = (t) => {
|
|
286
|
-
const e = this._paginationButtons(),
|
|
287
|
-
|
|
170
|
+
const e = this._paginationButtons(), i = t.composedPath().find((s) => e.includes(s));
|
|
171
|
+
i && e.forEach((s) => s.setAttribute("tabindex", s === i ? "0" : "-1"));
|
|
288
172
|
}, this._onPaginationNavigate = (t) => {
|
|
289
173
|
const e = this._paginationButtons();
|
|
290
174
|
if (!e.length)
|
|
291
175
|
return;
|
|
292
|
-
const
|
|
176
|
+
const i = e.indexOf(this.shadowRoot?.activeElement), s = i < 0 ? 0 : i;
|
|
293
177
|
switch (t) {
|
|
294
178
|
case "next":
|
|
295
|
-
e[(
|
|
179
|
+
e[(s + 1) % e.length]?.focus();
|
|
296
180
|
break;
|
|
297
181
|
case "prev":
|
|
298
|
-
e[(
|
|
182
|
+
e[(s - 1 + e.length) % e.length]?.focus();
|
|
299
183
|
break;
|
|
300
184
|
case "start":
|
|
301
185
|
e[0]?.focus();
|
|
@@ -332,17 +216,21 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
332
216
|
return this._trackEl ?? null;
|
|
333
217
|
}
|
|
334
218
|
connectedCallback() {
|
|
335
|
-
super.connectedCallback(), this._items = this._directItems(), this._setItemPositions(), this.hasAttribute("role") || this.setAttribute("role", "group"), this.
|
|
219
|
+
super.connectedCallback(), this._items = this._directItems(), this._setItemPositions(), this.hasAttribute("role") || this.setAttribute("role", "group"), this._syncText(), this.hasUpdated && !this._mounted && this._queueInitialPosition();
|
|
336
220
|
}
|
|
337
221
|
disconnectedCallback() {
|
|
338
222
|
super.disconnectedCallback(), this._settleTimer !== void 0 && clearTimeout(this._settleTimer);
|
|
339
223
|
}
|
|
340
224
|
firstUpdated() {
|
|
341
|
-
this.
|
|
225
|
+
this._syncActiveItemAccessibility(this.activeIndex), this._queueInitialPosition();
|
|
342
226
|
}
|
|
343
227
|
updated(t) {
|
|
344
|
-
if (super.updated(t), this._initPaginationTabIndex(), t.has("loop") && this._mounted && this._syncItems(), !t.has("activeIndex"))
|
|
228
|
+
if (super.updated(t), this._syncText(), this._initPaginationTabIndex(), t.has("loop") && this._mounted && this._syncItems(), !t.has("activeIndex"))
|
|
229
|
+
return;
|
|
230
|
+
if (this._syncActiveItemAccessibility(this.activeIndex), !this._mounted) {
|
|
231
|
+
this._queueInitialPosition();
|
|
345
232
|
return;
|
|
233
|
+
}
|
|
346
234
|
if (this._suppressSync) {
|
|
347
235
|
this._suppressSync = !1;
|
|
348
236
|
return;
|
|
@@ -384,7 +272,7 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
384
272
|
}
|
|
385
273
|
_snapPoints() {
|
|
386
274
|
const t = this._itemStep();
|
|
387
|
-
return this._items.map((e,
|
|
275
|
+
return this._items.map((e, i) => i * t);
|
|
388
276
|
}
|
|
389
277
|
/**
|
|
390
278
|
* Every scrollable track position in rendered order, including cloned
|
|
@@ -394,38 +282,96 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
394
282
|
* an index and reading back a settled scroll position can stay in terms
|
|
395
283
|
* of real indices while the clones do the seamless-wrap work.
|
|
396
284
|
*/
|
|
397
|
-
_trackSlots() {
|
|
398
|
-
const
|
|
399
|
-
return !this.loop || e < 2 ? this._items.map((
|
|
285
|
+
_trackSlots(t = this._itemStep()) {
|
|
286
|
+
const e = this._items.length;
|
|
287
|
+
return !this.loop || e < 2 ? this._items.map((i, s) => ({ point: s * t, index: s, isClone: !1 })) : [
|
|
400
288
|
{ point: 0, index: e - 1, isClone: !0 },
|
|
401
|
-
...this._items.map((
|
|
289
|
+
...this._items.map((i, s) => ({ point: (s + 1) * t, index: s, isClone: !1 })),
|
|
402
290
|
{ point: (e + 1) * t, index: 0, isClone: !0 }
|
|
403
291
|
];
|
|
404
292
|
}
|
|
405
293
|
_itemStep() {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
294
|
+
const t = this._measureTrack();
|
|
295
|
+
return t ? (this._applyFlow(t.flow), t.step) : 1;
|
|
296
|
+
}
|
|
297
|
+
_measureTrack() {
|
|
298
|
+
const t = this._trackEl;
|
|
299
|
+
if (!t)
|
|
300
|
+
return null;
|
|
301
|
+
const e = this._items[0], i = b(t), s = e instanceof HTMLElement ? (i.inline === "x" ? e.offsetWidth : e.offsetHeight) + (Number.parseFloat(getComputedStyle(t).columnGap || "0") || 0) : $(t, "inline", i);
|
|
302
|
+
return { track: t, flow: i, step: s };
|
|
303
|
+
}
|
|
304
|
+
_applyFlow(t) {
|
|
305
|
+
this._flow = t;
|
|
306
|
+
const e = z("inline", t);
|
|
307
|
+
!this._dragging && e !== this._dragAxis && (this._dragAxis = e, this._dragController.setOptions({ axis: e }));
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Re-reads the track's writing mode and direction. Called at the start of
|
|
311
|
+
* each scroll operation and on each drag's pointerdown rather than cached
|
|
312
|
+
* for the element's life, since neither a `dir` nor a writing-mode change
|
|
313
|
+
* on an ancestor fires an event. The drag gesture's physical axis follows,
|
|
314
|
+
* so a carousel in vertical text drags vertically.
|
|
315
|
+
*/
|
|
316
|
+
_resolveFlow() {
|
|
317
|
+
return this._trackEl ? (this._applyFlow(b(this._trackEl)), this._flow) : this._flow;
|
|
318
|
+
}
|
|
319
|
+
/** Scroll distance from the track's logical start, never negative. */
|
|
320
|
+
_trackOffset() {
|
|
321
|
+
return this._trackEl ? N(this._trackEl, "inline", this._flow) : 0;
|
|
322
|
+
}
|
|
323
|
+
_setTrackOffset(t, e = "auto") {
|
|
324
|
+
this._trackEl && x(this._trackEl, "inline", t, this._flow, e);
|
|
413
325
|
}
|
|
414
326
|
_setActiveIndex(t, e) {
|
|
415
|
-
const
|
|
416
|
-
|
|
327
|
+
const i = this._clampIndex(t), s = this.activeIndex;
|
|
328
|
+
s !== i && (this._activeIndex === void 0 && (this._uncontrolledActiveIndex = i, this.requestUpdate("activeIndex", s)), this.dispatchEvent(
|
|
417
329
|
new CustomEvent("rc-carousel-change", {
|
|
418
330
|
bubbles: !0,
|
|
419
331
|
composed: !0,
|
|
420
|
-
detail: { index:
|
|
332
|
+
detail: { index: i, trigger: e }
|
|
421
333
|
})
|
|
422
334
|
));
|
|
423
335
|
}
|
|
424
336
|
_scrollToIndex(t, e) {
|
|
425
337
|
if (!this._trackEl)
|
|
426
338
|
return;
|
|
427
|
-
const
|
|
428
|
-
e || n ?
|
|
339
|
+
const i = this._trackSlots().find((o) => !o.isClone && o.index === t), s = i ? i.point : t * this._itemStep(), n = this.ownerDocument.defaultView?.matchMedia("(prefers-reduced-motion: reduce)").matches ?? !1;
|
|
340
|
+
this._setTrackOffset(s, e || n ? "auto" : "smooth");
|
|
341
|
+
}
|
|
342
|
+
_queueInitialPosition() {
|
|
343
|
+
this._initialPosition.schedulePhased(
|
|
344
|
+
() => this._sampleInitialPosition(),
|
|
345
|
+
(t) => this._applyInitialPosition(t)
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
_sampleInitialPosition() {
|
|
349
|
+
const t = this._measureTrack();
|
|
350
|
+
if (!t)
|
|
351
|
+
return null;
|
|
352
|
+
const e = this._trackSlots(t.step).find(
|
|
353
|
+
(i) => !i.isClone && i.index === this.activeIndex
|
|
354
|
+
);
|
|
355
|
+
return {
|
|
356
|
+
...t,
|
|
357
|
+
offset: e ? e.point : this.activeIndex * t.step
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
_applyInitialPosition(t) {
|
|
361
|
+
!t || !this.isConnected || this._trackEl !== t.track || (this._applyFlow(t.flow), x(t.track, "inline", t.offset, t.flow, "auto"), this._mounted = !0);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Keep the authored active slide available to assistive technology even
|
|
365
|
+
* before a programmatic scroll produces its next intersection callback.
|
|
366
|
+
* IntersectionObserver still takes over during direct manipulation, where
|
|
367
|
+
* the visually dominant slide can change before scroll settling updates the
|
|
368
|
+
* public active index.
|
|
369
|
+
*/
|
|
370
|
+
_syncActiveItemAccessibility(t) {
|
|
371
|
+
this._directItems().forEach((e, i) => {
|
|
372
|
+
const s = i !== t;
|
|
373
|
+
e.toggleAttribute("aria-hidden", s), e.toggleAttribute("inert", s);
|
|
374
|
+
});
|
|
429
375
|
}
|
|
430
376
|
_directItems() {
|
|
431
377
|
return Array.from(this.children).filter(
|
|
@@ -433,10 +379,20 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
433
379
|
);
|
|
434
380
|
}
|
|
435
381
|
_setItemPositions() {
|
|
436
|
-
this.
|
|
437
|
-
|
|
382
|
+
const t = this._messages.value;
|
|
383
|
+
this._items.forEach((e, i) => {
|
|
384
|
+
e.position = t.position(i + 1, this._items.length, this._messages.locale), e.roleDescription = t.slide;
|
|
438
385
|
});
|
|
439
386
|
}
|
|
387
|
+
/** Re-applies text written outside the template, for a new locale or `messages`. */
|
|
388
|
+
_syncText() {
|
|
389
|
+
this._writtenRoleDescription = _(
|
|
390
|
+
this,
|
|
391
|
+
"aria-roledescription",
|
|
392
|
+
this._messages.value.carousel,
|
|
393
|
+
this._writtenRoleDescription
|
|
394
|
+
), this._setItemPositions();
|
|
395
|
+
}
|
|
440
396
|
/**
|
|
441
397
|
* Prepending/appending the loop clones below is itself a light-DOM
|
|
442
398
|
* mutation on this host, which re-fires `slotchange` (asynchronously) —
|
|
@@ -450,9 +406,9 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
450
406
|
*/
|
|
451
407
|
_syncItems() {
|
|
452
408
|
const e = (this._slotEl?.assignedElements() ?? []).filter(
|
|
453
|
-
(
|
|
454
|
-
),
|
|
455
|
-
this._items = e, this._setItemPositions(),
|
|
409
|
+
(o) => o.tagName === "RC-CAROUSEL-ITEM" && !o.hasAttribute("data-clone")
|
|
410
|
+
), i = e.length !== this._items.length || e.some((o, d) => o !== this._items[d]), s = this.loop && e.length > 1, n = this._cloneItems.length > 0;
|
|
411
|
+
this._items = e, this._setItemPositions(), i && this._mounted && this.requestUpdate(), !(!i && s === n) && (this._removeClones(), s && this._addClones());
|
|
456
412
|
}
|
|
457
413
|
/**
|
|
458
414
|
* Clones the first and last slide and prepends/appends them
|
|
@@ -467,10 +423,10 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
467
423
|
const t = this._items[0], e = this._items[this._items.length - 1];
|
|
468
424
|
if (!t || !e)
|
|
469
425
|
return;
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
const
|
|
473
|
-
|
|
426
|
+
const i = e.cloneNode(!0);
|
|
427
|
+
i.setAttribute("data-clone", String(this._items.length - 1)), this._sanitizeClone(i), this.prepend(i);
|
|
428
|
+
const s = t.cloneNode(!0);
|
|
429
|
+
s.setAttribute("data-clone", "0"), this._sanitizeClone(s), this.append(s), this._cloneItems = [i, s];
|
|
474
430
|
}
|
|
475
431
|
/** Keeps visual loop clones out of forms, focus order, and the accessibility tree. */
|
|
476
432
|
_sanitizeClone(t) {
|
|
@@ -482,24 +438,30 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
482
438
|
this._cloneItems.forEach((t) => t.remove()), this._cloneItems = [];
|
|
483
439
|
}
|
|
484
440
|
/**
|
|
485
|
-
* On release, a fast enough flick pre-nudges
|
|
441
|
+
* On release, a fast enough flick pre-nudges the scroll offset to the next
|
|
486
442
|
* snap point in the drag direction (a "decisive swipe" — mirroring
|
|
487
443
|
* `rc-bottom-sheet`'s own velocity-vs-nearest-point settle heuristic,
|
|
488
444
|
* adapted from "jump to the extreme end" for a 2-point sheet to "advance
|
|
489
445
|
* one further point" for a carousel that can have many). Either way,
|
|
490
446
|
* this hands off to the same debounced settle path a native swipe
|
|
491
|
-
* already goes through — our own
|
|
447
|
+
* already goes through — our own scroll offset writes during the drag
|
|
492
448
|
* already fired real `scroll` events, so `_onScroll` just needs to run
|
|
493
449
|
* its usual timer to pick up wherever things ended.
|
|
494
450
|
*/
|
|
495
451
|
_endDrag(t) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
452
|
+
this._dragging = !1, this._trackEl && (this._trackEl.style.scrollSnapType = "");
|
|
453
|
+
const e = v(
|
|
454
|
+
{ dx: t.velocityX, dy: t.velocityY },
|
|
455
|
+
"inline",
|
|
456
|
+
this._flow
|
|
457
|
+
);
|
|
458
|
+
if (this._trackEl && Math.abs(e) > B) {
|
|
459
|
+
const i = this._trackSlots(), s = e < 0 ? 1 : -1, n = R(
|
|
460
|
+
i.map((d) => d.point),
|
|
461
|
+
this._trackOffset(),
|
|
500
462
|
s
|
|
501
|
-
),
|
|
502
|
-
|
|
463
|
+
), o = i[n];
|
|
464
|
+
o && this._setTrackOffset(o.point);
|
|
503
465
|
}
|
|
504
466
|
this._onScroll();
|
|
505
467
|
}
|
|
@@ -520,18 +482,18 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
520
482
|
});
|
|
521
483
|
}
|
|
522
484
|
render() {
|
|
523
|
-
const t = this._canStep(-1), e = this._canStep(1);
|
|
485
|
+
const t = this._canStep(-1), e = this._canStep(1), i = this._messages.value;
|
|
524
486
|
return h`
|
|
525
487
|
<div
|
|
526
488
|
id="track"
|
|
527
489
|
part="track"
|
|
528
490
|
tabindex="0"
|
|
529
|
-
class=${this._dragging ? "dragging" :
|
|
491
|
+
class=${this._dragging ? "dragging" : p}
|
|
530
492
|
aria-busy=${this._busy ? "true" : "false"}
|
|
531
493
|
aria-atomic="true"
|
|
532
494
|
@scroll=${this._onScroll}
|
|
533
495
|
@click=${{ handleEvent: this._onTrackClickCapture, capture: !0 }}
|
|
534
|
-
${
|
|
496
|
+
${I(this._onNavigate, { navigationAxis: "horizontal" })}
|
|
535
497
|
>
|
|
536
498
|
<slot @slotchange=${this._onSlotChange}></slot>
|
|
537
499
|
</div>
|
|
@@ -541,7 +503,7 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
541
503
|
<button
|
|
542
504
|
type="button"
|
|
543
505
|
part="navigation-button navigation-button-previous"
|
|
544
|
-
aria-label
|
|
506
|
+
aria-label=${i.previous}
|
|
545
507
|
aria-disabled=${t ? "false" : "true"}
|
|
546
508
|
@click=${() => {
|
|
547
509
|
t && this._step(-1, "button");
|
|
@@ -567,7 +529,7 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
567
529
|
<button
|
|
568
530
|
type="button"
|
|
569
531
|
part="navigation-button navigation-button-next"
|
|
570
|
-
aria-label
|
|
532
|
+
aria-label=${i.next}
|
|
571
533
|
aria-disabled=${e ? "false" : "true"}
|
|
572
534
|
@click=${() => {
|
|
573
535
|
e && this._step(1, "button");
|
|
@@ -591,68 +553,76 @@ const z = 300, P = 120, _ = class _ extends m {
|
|
|
591
553
|
</span>
|
|
592
554
|
</button>
|
|
593
555
|
</div>
|
|
594
|
-
` :
|
|
556
|
+
` : p}
|
|
595
557
|
${this.pagination ? h`
|
|
596
558
|
<div
|
|
597
559
|
id="pagination"
|
|
598
560
|
part="pagination"
|
|
599
561
|
role="group"
|
|
600
|
-
aria-label
|
|
562
|
+
aria-label=${i.picker}
|
|
601
563
|
@focusin=${this._onPaginationFocus}
|
|
602
|
-
${
|
|
564
|
+
${I(this._onPaginationNavigate, { navigationAxis: "horizontal" })}
|
|
603
565
|
>
|
|
604
566
|
${this._items.map(
|
|
605
|
-
(s,
|
|
567
|
+
(s, n) => h`
|
|
606
568
|
<button
|
|
607
569
|
type="button"
|
|
608
570
|
data-pagination-item
|
|
609
|
-
part="pagination-item${
|
|
610
|
-
aria-label
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
571
|
+
part="pagination-item${n === this.activeIndex ? " pagination-item-active" : ""}"
|
|
572
|
+
aria-label=${i.goToSlide(
|
|
573
|
+
n + 1,
|
|
574
|
+
this._items.length,
|
|
575
|
+
this._messages.locale
|
|
576
|
+
)}
|
|
577
|
+
aria-current=${n === this.activeIndex ? "true" : "false"}
|
|
578
|
+
aria-disabled=${n === this.activeIndex ? "true" : "false"}
|
|
579
|
+
@click=${() => this._setActiveIndex(n, "button")}
|
|
614
580
|
></button>
|
|
615
581
|
`
|
|
616
582
|
)}
|
|
617
583
|
</div>
|
|
618
|
-
` :
|
|
584
|
+
` : p}
|
|
619
585
|
`;
|
|
620
586
|
}
|
|
621
587
|
};
|
|
622
|
-
|
|
623
|
-
let r =
|
|
624
|
-
|
|
625
|
-
|
|
588
|
+
g.styles = q;
|
|
589
|
+
let r = g;
|
|
590
|
+
a([
|
|
591
|
+
S("#track")
|
|
626
592
|
], r.prototype, "_trackEl", 2);
|
|
627
|
-
|
|
628
|
-
|
|
593
|
+
a([
|
|
594
|
+
S("slot:not([name])")
|
|
629
595
|
], r.prototype, "_slotEl", 2);
|
|
630
|
-
|
|
631
|
-
|
|
596
|
+
a([
|
|
597
|
+
c({ attribute: !1 })
|
|
598
|
+
], r.prototype, "messages", 2);
|
|
599
|
+
a([
|
|
600
|
+
c({ type: Boolean, reflect: !0 })
|
|
632
601
|
], r.prototype, "loop", 2);
|
|
633
|
-
|
|
634
|
-
|
|
602
|
+
a([
|
|
603
|
+
c({ type: Boolean, reflect: !0 })
|
|
635
604
|
], r.prototype, "navigation", 2);
|
|
636
|
-
|
|
637
|
-
|
|
605
|
+
a([
|
|
606
|
+
c({ type: Boolean, reflect: !0 })
|
|
638
607
|
], r.prototype, "pagination", 2);
|
|
639
|
-
|
|
640
|
-
|
|
608
|
+
a([
|
|
609
|
+
c({ type: Boolean, reflect: !0, attribute: "mouse-dragging" })
|
|
641
610
|
], r.prototype, "mouseDragging", 2);
|
|
642
|
-
|
|
643
|
-
|
|
611
|
+
a([
|
|
612
|
+
w()
|
|
644
613
|
], r.prototype, "_dragging", 2);
|
|
645
|
-
|
|
646
|
-
|
|
614
|
+
a([
|
|
615
|
+
w()
|
|
647
616
|
], r.prototype, "_busy", 2);
|
|
648
|
-
|
|
649
|
-
|
|
617
|
+
a([
|
|
618
|
+
c({ type: Number, attribute: "active-index" })
|
|
650
619
|
], r.prototype, "activeIndex", 1);
|
|
651
|
-
|
|
652
|
-
|
|
620
|
+
a([
|
|
621
|
+
c({ type: Number, attribute: "default-active-index" })
|
|
653
622
|
], r.prototype, "defaultActiveIndex", 1);
|
|
654
623
|
export {
|
|
624
|
+
j as D,
|
|
655
625
|
r as R,
|
|
656
626
|
u as a
|
|
657
627
|
};
|
|
658
|
-
//# sourceMappingURL=rc-carousel-
|
|
628
|
+
//# sourceMappingURL=rc-carousel-CGHUVDLI.js.map
|