@expressivecss/expressive 0.9.1 → 0.10.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/CHANGELOG.md +184 -1
- package/README.md +178 -25
- package/dist/css/expressive.css +428 -1222
- package/dist/css/expressive.css.map +1 -1
- package/dist/css/expressive.min.css +1 -1
- package/dist/css/expressive.min.css.map +1 -1
- package/dist/fonts/material-symbols-outlined.woff2 +0 -0
- package/dist/fonts/material-symbols-rounded.woff2 +0 -0
- package/dist/fonts/material-symbols-sharp.woff2 +0 -0
- package/dist/js/chunks/chunk-7MM4VJJO.mjs +509 -0
- package/dist/js/chunks/chunk-7MM4VJJO.mjs.map +7 -0
- package/dist/js/chunks/chunk-7UXHSYIA.mjs +183 -0
- package/dist/js/chunks/chunk-7UXHSYIA.mjs.map +7 -0
- package/dist/js/chunks/chunk-A3BJA7V4.mjs +28 -0
- package/dist/js/chunks/chunk-A3BJA7V4.mjs.map +7 -0
- package/dist/js/chunks/chunk-AOGFNMXS.mjs +691 -0
- package/dist/js/chunks/chunk-AOGFNMXS.mjs.map +7 -0
- package/dist/js/chunks/chunk-D4UZ4HFN.mjs +560 -0
- package/dist/js/chunks/chunk-D4UZ4HFN.mjs.map +7 -0
- package/dist/js/chunks/chunk-EP3CVKB5.mjs +88 -0
- package/dist/js/chunks/chunk-EP3CVKB5.mjs.map +7 -0
- package/dist/js/chunks/chunk-G576EP5O.mjs +459 -0
- package/dist/js/chunks/chunk-G576EP5O.mjs.map +7 -0
- package/dist/js/chunks/chunk-GY2Z5CJ2.mjs +320 -0
- package/dist/js/chunks/chunk-GY2Z5CJ2.mjs.map +7 -0
- package/dist/js/chunks/chunk-JKNPQQWY.mjs +191 -0
- package/dist/js/chunks/chunk-JKNPQQWY.mjs.map +7 -0
- package/dist/js/chunks/chunk-JNPIWFJT.mjs +365 -0
- package/dist/js/chunks/chunk-JNPIWFJT.mjs.map +7 -0
- package/dist/js/chunks/chunk-JODJAGFS.mjs +267 -0
- package/dist/js/chunks/chunk-JODJAGFS.mjs.map +7 -0
- package/dist/js/chunks/chunk-JR24UB4X.mjs +100 -0
- package/dist/js/chunks/chunk-JR24UB4X.mjs.map +7 -0
- package/dist/js/chunks/chunk-KR44BSYQ.mjs +55 -0
- package/dist/js/chunks/chunk-KR44BSYQ.mjs.map +7 -0
- package/dist/js/chunks/chunk-LZVBJ33S.mjs +102 -0
- package/dist/js/chunks/chunk-LZVBJ33S.mjs.map +7 -0
- package/dist/js/chunks/chunk-MISGHDUU.mjs +326 -0
- package/dist/js/chunks/chunk-MISGHDUU.mjs.map +7 -0
- package/dist/js/chunks/chunk-N3UHGN3N.mjs +175 -0
- package/dist/js/chunks/chunk-N3UHGN3N.mjs.map +7 -0
- package/dist/js/chunks/chunk-PIIAEYAJ.mjs +85 -0
- package/dist/js/chunks/chunk-PIIAEYAJ.mjs.map +7 -0
- package/dist/js/chunks/chunk-QSQ24FYT.mjs +59 -0
- package/dist/js/chunks/chunk-QSQ24FYT.mjs.map +7 -0
- package/dist/js/chunks/chunk-QYCYP443.mjs +1111 -0
- package/dist/js/chunks/chunk-QYCYP443.mjs.map +7 -0
- package/dist/js/chunks/chunk-SLFNPY5M.mjs +78 -0
- package/dist/js/chunks/chunk-SLFNPY5M.mjs.map +7 -0
- package/dist/js/chunks/chunk-TK6PX2GC.mjs +663 -0
- package/dist/js/chunks/chunk-TK6PX2GC.mjs.map +7 -0
- package/dist/js/chunks/chunk-TYM6U5DY.mjs +76 -0
- package/dist/js/chunks/chunk-TYM6U5DY.mjs.map +7 -0
- package/dist/js/chunks/chunk-TZZ24ZQS.mjs +154 -0
- package/dist/js/chunks/chunk-TZZ24ZQS.mjs.map +7 -0
- package/dist/js/chunks/chunk-VAS6JQ6P.mjs +94 -0
- package/dist/js/chunks/chunk-VAS6JQ6P.mjs.map +7 -0
- package/dist/js/chunks/chunk-WWPAPHMA.mjs +1 -0
- package/dist/js/chunks/chunk-WWPAPHMA.mjs.map +7 -0
- package/dist/js/chunks/chunk-XDB3G6RL.mjs +114 -0
- package/dist/js/chunks/chunk-XDB3G6RL.mjs.map +7 -0
- package/dist/js/chunks/chunk-XO5WX3TK.mjs +226 -0
- package/dist/js/chunks/chunk-XO5WX3TK.mjs.map +7 -0
- package/dist/js/chunks/chunk-YFXEJ7GR.mjs +286 -0
- package/dist/js/chunks/chunk-YFXEJ7GR.mjs.map +7 -0
- package/dist/js/chunks/chunk-ZAOYQ6SY.mjs +7 -0
- package/dist/js/chunks/chunk-ZAOYQ6SY.mjs.map +7 -0
- package/dist/js/chunks/chunk-ZIZVUWRL.mjs +120 -0
- package/dist/js/chunks/chunk-ZIZVUWRL.mjs.map +7 -0
- package/dist/js/chunks/chunk-ZZBZI2XN.mjs +338 -0
- package/dist/js/chunks/chunk-ZZBZI2XN.mjs.map +7 -0
- package/dist/js/expressive.cjs +747 -754
- package/dist/js/expressive.cjs.map +4 -4
- package/dist/js/expressive.js +747 -754
- package/dist/js/expressive.js.map +4 -4
- package/dist/js/expressive.min.js +11 -15
- package/dist/js/expressive.min.js.map +4 -4
- package/dist/js/expressive.mjs +83 -7490
- package/dist/js/expressive.mjs.map +4 -4
- package/dist/js/internal/behaviors/bottomSheets.mjs +9 -0
- package/dist/js/internal/behaviors/bottomSheets.mjs.map +7 -0
- package/dist/js/internal/behaviors/dialogs.mjs +8 -0
- package/dist/js/internal/behaviors/dialogs.mjs.map +7 -0
- package/dist/js/internal/behaviors/forms.mjs +8 -0
- package/dist/js/internal/behaviors/forms.mjs.map +7 -0
- package/dist/js/internal/behaviors/sheetDrag.mjs +8 -0
- package/dist/js/internal/behaviors/sheetDrag.mjs.map +7 -0
- package/dist/js/internal/behaviors/sideSheets.mjs +9 -0
- package/dist/js/internal/behaviors/sideSheets.mjs.map +7 -0
- package/dist/js/internal/components/appBar.mjs +8 -0
- package/dist/js/internal/components/appBar.mjs.map +7 -0
- package/dist/js/internal/components/autocomplete.mjs +10 -0
- package/dist/js/internal/components/autocomplete.mjs.map +7 -0
- package/dist/js/internal/components/buttonGroup.mjs +8 -0
- package/dist/js/internal/components/buttonGroup.mjs.map +7 -0
- package/dist/js/internal/components/buttons.mjs +9 -0
- package/dist/js/internal/components/buttons.mjs.map +7 -0
- package/dist/js/internal/components/cards.mjs +13 -0
- package/dist/js/internal/components/cards.mjs.map +7 -0
- package/dist/js/internal/components/carousel.mjs +9 -0
- package/dist/js/internal/components/carousel.mjs.map +7 -0
- package/dist/js/internal/components/characterCounter.mjs +8 -0
- package/dist/js/internal/components/characterCounter.mjs.map +7 -0
- package/dist/js/internal/components/chips.mjs +11 -0
- package/dist/js/internal/components/chips.mjs.map +7 -0
- package/dist/js/internal/components/datepicker.mjs +12 -0
- package/dist/js/internal/components/datepicker.mjs.map +7 -0
- package/dist/js/internal/components/expandingCard.mjs +11 -0
- package/dist/js/internal/components/expandingCard.mjs.map +7 -0
- package/dist/js/internal/components/index.mjs +88 -0
- package/dist/js/internal/components/index.mjs.map +7 -0
- package/dist/js/internal/components/lightbox.mjs +9 -0
- package/dist/js/internal/components/lightbox.mjs.map +7 -0
- package/dist/js/internal/components/menu.mjs +9 -0
- package/dist/js/internal/components/menu.mjs.map +7 -0
- package/dist/js/internal/components/navigationRail.mjs +8 -0
- package/dist/js/internal/components/navigationRail.mjs.map +7 -0
- package/dist/js/internal/components/registry.mjs +33 -0
- package/dist/js/internal/components/registry.mjs.map +7 -0
- package/dist/js/internal/components/scrollspy.mjs +8 -0
- package/dist/js/internal/components/scrollspy.mjs.map +7 -0
- package/dist/js/internal/components/select.mjs +10 -0
- package/dist/js/internal/components/select.mjs.map +7 -0
- package/dist/js/internal/components/slider.mjs +9 -0
- package/dist/js/internal/components/slider.mjs.map +7 -0
- package/dist/js/internal/components/snackbar.mjs +8 -0
- package/dist/js/internal/components/snackbar.mjs.map +7 -0
- package/dist/js/internal/components/tabs.mjs +10 -0
- package/dist/js/internal/components/tabs.mjs.map +7 -0
- package/dist/js/internal/components/timepicker.mjs +10 -0
- package/dist/js/internal/components/timepicker.mjs.map +7 -0
- package/dist/js/internal/components/tooltip.mjs +9 -0
- package/dist/js/internal/components/tooltip.mjs.map +7 -0
- package/dist/js/internal/core/component.mjs +7 -0
- package/dist/js/internal/core/component.mjs.map +7 -0
- package/dist/js/internal/core/utils.mjs +7 -0
- package/dist/js/internal/core/utils.mjs.map +7 -0
- package/dist/js/internal/plugins/dockedDisplayPlugin.mjs +8 -0
- package/dist/js/internal/plugins/dockedDisplayPlugin.mjs.map +7 -0
- package/dist/js/modular.mjs +113 -0
- package/dist/js/modular.mjs.map +7 -0
- package/dist/types/behaviors/sheetDrag.d.ts +1 -1
- package/dist/types/components/appBar.d.ts +1 -1
- package/dist/types/components/autocomplete.d.ts +9 -0
- package/dist/types/components/buttons.d.ts +4 -39
- package/dist/types/components/carousel.d.ts +10 -1
- package/dist/types/components/chips.d.ts +1 -0
- package/dist/types/components/datepicker.d.ts +7 -0
- package/dist/types/components/index.d.ts +0 -2
- package/dist/types/components/lightbox.d.ts +12 -0
- package/dist/types/components/menu.d.ts +3 -0
- package/dist/types/components/registry.d.ts +0 -4
- package/dist/types/components/select.d.ts +4 -0
- package/dist/types/components/slider.d.ts +2 -1
- package/dist/types/components/snackbar.d.ts +4 -2
- package/dist/types/components/tabs.d.ts +2 -1
- package/dist/types/components/timepicker.d.ts +5 -3
- package/dist/types/components/tooltip.d.ts +5 -3
- package/dist/types/index.d.ts +1 -8
- package/dist/types/modular.d.ts +28 -0
- package/package.json +16 -4
- package/src/sass/README.md +8 -0
- package/src/sass/components/_badges.scss +1 -6
- package/src/sass/components/_button-groups.scss +5 -1
- package/src/sass/components/_buttons.scss +8 -287
- package/src/sass/components/_chips.scss +17 -2
- package/src/sass/components/_dialog.scss +9 -4
- package/src/sass/components/_fab-menu.scss +11 -9
- package/src/sass/components/_icon-buttons.scss +0 -5
- package/src/sass/components/_index.scss +0 -5
- package/src/sass/components/_menu.scss +2 -2
- package/src/sass/components/_navigation-rail.scss +1 -1
- package/src/sass/components/_panes.scss +50 -78
- package/src/sass/components/_progress.scss +73 -13
- package/src/sass/components/_scrim.scss +4 -4
- package/src/sass/components/_side-sheet.scss +22 -12
- package/src/sass/components/_toolbar.scss +1 -4
- package/src/sass/components/_tooltip.scss +20 -2
- package/src/sass/components/forms/_input-fields.scss +5 -1
- package/src/sass/components/forms/_select.scss +1 -0
- package/src/sass/components/forms/_slider.scss +81 -25
- package/src/sass/custom.scss +38 -0
- package/src/sass/utilities/_helpers.scss +18 -0
- package/src/sass/utilities/_spacing.scss +8 -1
- package/dist/types/components/navigationDrawer.d.ts +0 -110
- package/src/sass/components/_banners.scss +0 -298
- package/src/sass/components/_bottom-app-bar.scss +0 -180
- package/src/sass/components/_floating-sheet.scss +0 -86
- package/src/sass/components/_navigation-drawer.scss +0 -476
- package/src/sass/components/_segmented-buttons.scss +0 -188
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Utils
|
|
3
|
+
} from "./chunk-MISGHDUU.mjs";
|
|
4
|
+
import {
|
|
5
|
+
Component
|
|
6
|
+
} from "./chunk-QSQ24FYT.mjs";
|
|
7
|
+
|
|
8
|
+
// src/ts/components/carousel.ts
|
|
9
|
+
var _defaults = {
|
|
10
|
+
duration: 200,
|
|
11
|
+
fullWidth: false,
|
|
12
|
+
indicators: false,
|
|
13
|
+
noWrap: false,
|
|
14
|
+
interval: 0,
|
|
15
|
+
height: null,
|
|
16
|
+
onCycleTo: null,
|
|
17
|
+
i18n: {
|
|
18
|
+
carousel: "Carousel",
|
|
19
|
+
item: "Item",
|
|
20
|
+
of: "of",
|
|
21
|
+
indicators: "Slides",
|
|
22
|
+
slide: "Slide"
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var _Carousel = class _Carousel extends Component {
|
|
26
|
+
constructor(el, options) {
|
|
27
|
+
super(el, options, _Carousel);
|
|
28
|
+
this.center = 0;
|
|
29
|
+
this._ownIndicators = false;
|
|
30
|
+
this._trackEl = null;
|
|
31
|
+
this._ignoreScroll = false;
|
|
32
|
+
this._alignAfterResize = false;
|
|
33
|
+
this._trackRaf = null;
|
|
34
|
+
this._started = false;
|
|
35
|
+
this._vertical = false;
|
|
36
|
+
this._resizeObserver = null;
|
|
37
|
+
this._resizeTimeout = null;
|
|
38
|
+
this._usesWindowResize = false;
|
|
39
|
+
this._dragPointerId = null;
|
|
40
|
+
this._dragStartX = 0;
|
|
41
|
+
this._dragStartY = 0;
|
|
42
|
+
this._dragStartScroll = 0;
|
|
43
|
+
this._suppressClick = false;
|
|
44
|
+
this._suppressClickTimeout = null;
|
|
45
|
+
this._generatedContainerRole = false;
|
|
46
|
+
this._generatedContainerLabel = false;
|
|
47
|
+
this._generatedContainerDescription = false;
|
|
48
|
+
this._generatedWideLayout = false;
|
|
49
|
+
this._generatedFixedHeight = false;
|
|
50
|
+
this._authoredInlineHeight = null;
|
|
51
|
+
this._autoAdvanceTimer = null;
|
|
52
|
+
this._autoAdvances = false;
|
|
53
|
+
this._autoPaused = false;
|
|
54
|
+
this._hovered = false;
|
|
55
|
+
this._focused = false;
|
|
56
|
+
this._motion = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
57
|
+
this._generatedItemTabIndexes = /* @__PURE__ */ new Set();
|
|
58
|
+
this._generatedItemLabels = /* @__PURE__ */ new Set();
|
|
59
|
+
this._generatedItemDescriptions = /* @__PURE__ */ new Set();
|
|
60
|
+
this._generatedItemSizes = /* @__PURE__ */ new Set();
|
|
61
|
+
this._authoredItemSizes = /* @__PURE__ */ new Set();
|
|
62
|
+
this._itemA11yOriginal = /* @__PURE__ */ new Map();
|
|
63
|
+
this._handleThrottledResize = () => {
|
|
64
|
+
if (!this._started || this._resizeTimeout !== null) return;
|
|
65
|
+
this._handleResize();
|
|
66
|
+
this._resizeTimeout = setTimeout(() => {
|
|
67
|
+
this._resizeTimeout = null;
|
|
68
|
+
this._handleResize();
|
|
69
|
+
}, 200);
|
|
70
|
+
};
|
|
71
|
+
this._handleAutoAdvanceState = (e) => {
|
|
72
|
+
if (e.type === "mouseenter") this._hovered = true;
|
|
73
|
+
else if (e.type === "mouseleave") this._hovered = false;
|
|
74
|
+
else if (e.type === "focusin") this._focused = true;
|
|
75
|
+
else if (e.type === "focusout") this._focused = this.el.contains(e.relatedTarget);
|
|
76
|
+
this._syncAutoAdvance();
|
|
77
|
+
};
|
|
78
|
+
this._handleMotionChange = () => {
|
|
79
|
+
this._syncAutoAdvance();
|
|
80
|
+
if (this._motion.matches) this._scrollToIndex(this.center, false);
|
|
81
|
+
this._updateParallax();
|
|
82
|
+
};
|
|
83
|
+
this._tick = () => {
|
|
84
|
+
this._autoAdvanceTimer = null;
|
|
85
|
+
this._advance();
|
|
86
|
+
this._syncAutoAdvance();
|
|
87
|
+
};
|
|
88
|
+
this._advance = () => {
|
|
89
|
+
const next = this.center + 1;
|
|
90
|
+
if (next < this.count) {
|
|
91
|
+
this.set(next);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (this.options.noWrap) {
|
|
95
|
+
this._autoAdvances = false;
|
|
96
|
+
this._syncAutoAdvance();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.set(0);
|
|
100
|
+
};
|
|
101
|
+
this._handleNativeScroll = () => {
|
|
102
|
+
this._alignAfterResize = false;
|
|
103
|
+
this._finishScroll();
|
|
104
|
+
};
|
|
105
|
+
this._handleTrackPointerDown = (e) => {
|
|
106
|
+
this._handleNativeScroll();
|
|
107
|
+
if (e.pointerType !== "mouse" || e.button !== 0) return;
|
|
108
|
+
this.pressed = true;
|
|
109
|
+
this.dragged = false;
|
|
110
|
+
this._suppressClick = false;
|
|
111
|
+
this._dragPointerId = e.pointerId;
|
|
112
|
+
this._dragStartX = e.clientX;
|
|
113
|
+
this._dragStartY = e.clientY;
|
|
114
|
+
this._dragStartScroll = this._vertical ? this._scroller.scrollTop : this._scroller.scrollLeft;
|
|
115
|
+
try {
|
|
116
|
+
this._scroller.setPointerCapture(e.pointerId);
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
this._handleTrackPointerMove = (e) => {
|
|
121
|
+
if (!this.pressed || e.pointerId !== this._dragPointerId) return;
|
|
122
|
+
const deltaX = e.clientX - this._dragStartX;
|
|
123
|
+
const deltaY = e.clientY - this._dragStartY;
|
|
124
|
+
const primaryDelta = this._vertical ? deltaY : deltaX;
|
|
125
|
+
const crossDelta = this._vertical ? deltaX : deltaY;
|
|
126
|
+
if (!this.dragged) {
|
|
127
|
+
if (Math.abs(primaryDelta) < 6 || Math.abs(primaryDelta) <= Math.abs(crossDelta)) return;
|
|
128
|
+
this.dragged = true;
|
|
129
|
+
this.el.classList.add("dragging");
|
|
130
|
+
}
|
|
131
|
+
if (this._vertical) this._scroller.scrollTop = this._dragStartScroll - deltaY;
|
|
132
|
+
else this._scroller.scrollLeft = this._dragStartScroll - deltaX;
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
};
|
|
135
|
+
this._handleTrackPointerUp = (e) => {
|
|
136
|
+
if (!this.pressed || e.pointerId !== this._dragPointerId) return;
|
|
137
|
+
this.pressed = false;
|
|
138
|
+
this._dragPointerId = null;
|
|
139
|
+
this.el.classList.remove("dragging");
|
|
140
|
+
try {
|
|
141
|
+
this._scroller.releasePointerCapture(e.pointerId);
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
144
|
+
if (!this.dragged) return;
|
|
145
|
+
this._suppressClick = true;
|
|
146
|
+
window.clearTimeout(this._suppressClickTimeout);
|
|
147
|
+
this._suppressClickTimeout = setTimeout(() => {
|
|
148
|
+
this._suppressClick = false;
|
|
149
|
+
}, 0);
|
|
150
|
+
this._syncActive(this._nearestIndex(), true);
|
|
151
|
+
};
|
|
152
|
+
this._handleTrackClick = (e) => {
|
|
153
|
+
if (!this._suppressClick) return;
|
|
154
|
+
this._suppressClick = false;
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
e.stopImmediatePropagation();
|
|
157
|
+
};
|
|
158
|
+
this._handleTrackDragStart = (e) => {
|
|
159
|
+
if (e.target.closest("img, picture, video")) e.preventDefault();
|
|
160
|
+
};
|
|
161
|
+
this._handleItemResize = (e) => {
|
|
162
|
+
if (this._alignAfterResize && !this.pressed && e.propertyName === "flex-basis" && this.images.includes(e.target)) {
|
|
163
|
+
this._scrollToIndex(this.center, false);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
this._handleIndicatorClick = (e) => {
|
|
167
|
+
e.stopPropagation();
|
|
168
|
+
const indicator = e.target.closest(".indicator-item");
|
|
169
|
+
if (!indicator || !this._indicators.contains(indicator)) return;
|
|
170
|
+
const index = [...this._indicators.children].indexOf(indicator);
|
|
171
|
+
if (index < 0) return;
|
|
172
|
+
this._cycleTo(index);
|
|
173
|
+
};
|
|
174
|
+
this._handleKeydown = (e) => {
|
|
175
|
+
const target = e.target;
|
|
176
|
+
if (target.isContentEditable || target.closest("input, textarea, select")) return;
|
|
177
|
+
const rtl = getComputedStyle(this._scroller).direction === "rtl";
|
|
178
|
+
const forward = this._vertical ? e.key === "ArrowDown" : e.key === (rtl ? Utils.keys.ARROW_LEFT : Utils.keys.ARROW_RIGHT);
|
|
179
|
+
const backward = this._vertical ? e.key === "ArrowUp" : e.key === (rtl ? Utils.keys.ARROW_RIGHT : Utils.keys.ARROW_LEFT);
|
|
180
|
+
if (e.key === "Home") {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
this.set(0);
|
|
183
|
+
this._focusItem(0);
|
|
184
|
+
} else if (e.key === "End") {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
this.set(this.count - 1);
|
|
187
|
+
this._focusItem(this.count - 1);
|
|
188
|
+
} else if (forward) {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
this.next();
|
|
191
|
+
this._focusItem(this.center);
|
|
192
|
+
} else if (backward) {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
this.prev();
|
|
195
|
+
this._focusItem(this.center);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
this._handleTrackScroll = () => {
|
|
199
|
+
if (!this.el.classList.contains("scrolling")) this.el.classList.add("scrolling");
|
|
200
|
+
window.clearTimeout(this.scrollingTimeout);
|
|
201
|
+
this.scrollingTimeout = setTimeout(() => this.el.classList.remove("scrolling"), 120);
|
|
202
|
+
if (this._trackRaf !== null) return;
|
|
203
|
+
this._trackRaf = requestAnimationFrame(() => {
|
|
204
|
+
this._trackRaf = null;
|
|
205
|
+
this._updateParallax();
|
|
206
|
+
if (this._ignoreScroll) return;
|
|
207
|
+
const index = this._nearestIndex();
|
|
208
|
+
if (index !== this.center) this._syncActive(index, this.dragged);
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
this._handleResize = () => {
|
|
212
|
+
if (!this._started || !this.images.length) return;
|
|
213
|
+
this._syncAdaptiveMode();
|
|
214
|
+
this._syncLayoutRoles(this.center);
|
|
215
|
+
this._scrollToIndex(this.center, false);
|
|
216
|
+
this._updateParallax();
|
|
217
|
+
};
|
|
218
|
+
this._finishScroll = () => {
|
|
219
|
+
this._ignoreScroll = false;
|
|
220
|
+
clearTimeout(this._scrollEndTimeout);
|
|
221
|
+
this._scroller.removeEventListener("scrollend", this._handleScrollEnd);
|
|
222
|
+
};
|
|
223
|
+
this._handleScrollEnd = () => {
|
|
224
|
+
if (!this.images.some((item) => item.getAnimations().some((animation) => animation.playState === "running"))) {
|
|
225
|
+
this._finishScroll();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
this.el["Expressive_Carousel"] = this;
|
|
229
|
+
this.options = {
|
|
230
|
+
..._Carousel.defaults,
|
|
231
|
+
...options
|
|
232
|
+
};
|
|
233
|
+
if (options?.i18n) {
|
|
234
|
+
this.options.i18n = { ..._Carousel.defaults.i18n, ...options.i18n };
|
|
235
|
+
}
|
|
236
|
+
if (this.options.fullWidth || this.el.classList.contains("flat")) {
|
|
237
|
+
this.el.classList.add("flat");
|
|
238
|
+
this.options.fullWidth = true;
|
|
239
|
+
}
|
|
240
|
+
this._vertical = this.el.classList.contains("full-screen");
|
|
241
|
+
this.pressed = false;
|
|
242
|
+
this.dragged = false;
|
|
243
|
+
this.images = this._collectItems();
|
|
244
|
+
if (!this.images.length) {
|
|
245
|
+
console.error("Carousel: no .carousel-item elements to show");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
this.images.forEach((item) => {
|
|
249
|
+
this._itemA11yOriginal.set(item, {
|
|
250
|
+
ariaHidden: item.getAttribute("aria-hidden"),
|
|
251
|
+
tabIndex: item.getAttribute("tabindex")
|
|
252
|
+
});
|
|
253
|
+
if (item.hasAttribute("data-carousel-size")) this._authoredItemSizes.add(item);
|
|
254
|
+
});
|
|
255
|
+
this.hasMultipleSlides = this.images.length > 1;
|
|
256
|
+
this.showIndicators = this.options.indicators && this.hasMultipleSlides;
|
|
257
|
+
this.count = this.images.length;
|
|
258
|
+
this._autoAdvances = this.options.interval > 0 && this.hasMultipleSlides;
|
|
259
|
+
this.images.forEach((item) => item.classList.add("carousel-item"));
|
|
260
|
+
if (this.options.height !== null) {
|
|
261
|
+
this._generatedFixedHeight = !this.el.classList.contains("fixed-height");
|
|
262
|
+
this._authoredInlineHeight = this.el.style.getPropertyValue("--carousel-height") || null;
|
|
263
|
+
this.el.classList.add("fixed-height");
|
|
264
|
+
this.el.style.setProperty("--carousel-height", `${this.options.height}px`);
|
|
265
|
+
}
|
|
266
|
+
this._wrapTrack();
|
|
267
|
+
this._syncAdaptiveMode();
|
|
268
|
+
if (this.showIndicators) this._setupIndicators();
|
|
269
|
+
this._setupAccessibility();
|
|
270
|
+
this._setupEventHandlers();
|
|
271
|
+
this._started = true;
|
|
272
|
+
const start = Math.max(
|
|
273
|
+
0,
|
|
274
|
+
this.images.findIndex((el2) => el2.classList.contains("active"))
|
|
275
|
+
);
|
|
276
|
+
this.center = start;
|
|
277
|
+
this._syncActive(start, false);
|
|
278
|
+
this._updateParallax();
|
|
279
|
+
this._scrollToIndex(start, false);
|
|
280
|
+
this._syncAutoAdvance();
|
|
281
|
+
}
|
|
282
|
+
get _scroller() {
|
|
283
|
+
return this._trackEl ?? this.el;
|
|
284
|
+
}
|
|
285
|
+
static get defaults() {
|
|
286
|
+
return _defaults;
|
|
287
|
+
}
|
|
288
|
+
static init(els, options = {}) {
|
|
289
|
+
return super.init(els, options, _Carousel);
|
|
290
|
+
}
|
|
291
|
+
static getInstance(el) {
|
|
292
|
+
return el["Expressive_Carousel"];
|
|
293
|
+
}
|
|
294
|
+
destroy() {
|
|
295
|
+
if (this._started) this._teardown();
|
|
296
|
+
this.el["Expressive_Carousel"] = void 0;
|
|
297
|
+
}
|
|
298
|
+
_collectItems() {
|
|
299
|
+
const explicit = Array.from(this.el.children).filter(
|
|
300
|
+
(el) => el instanceof HTMLElement && el.classList.contains("carousel-item")
|
|
301
|
+
);
|
|
302
|
+
if (explicit.length) return explicit;
|
|
303
|
+
return Array.from(this.el.children).filter((el) => {
|
|
304
|
+
if (!(el instanceof HTMLElement)) return false;
|
|
305
|
+
if (el.classList.contains("indicators") || el.classList.contains("carousel-fixed-item")) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
return el.tagName !== "NAV";
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
_setupAccessibility() {
|
|
312
|
+
if (!this.el.hasAttribute("role")) {
|
|
313
|
+
this.el.setAttribute("role", "region");
|
|
314
|
+
this._generatedContainerRole = true;
|
|
315
|
+
}
|
|
316
|
+
if (!this.el.hasAttribute("aria-label") && !this.el.hasAttribute("aria-labelledby")) {
|
|
317
|
+
this.el.setAttribute("aria-label", this.options.i18n.carousel);
|
|
318
|
+
this._generatedContainerLabel = true;
|
|
319
|
+
}
|
|
320
|
+
if (!this.el.hasAttribute("aria-roledescription")) {
|
|
321
|
+
this.el.setAttribute("aria-roledescription", "carousel");
|
|
322
|
+
this._generatedContainerDescription = true;
|
|
323
|
+
}
|
|
324
|
+
const naturallyFocusable = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
325
|
+
this.images.forEach((item, index) => {
|
|
326
|
+
if (!item.hasAttribute("aria-roledescription")) {
|
|
327
|
+
item.setAttribute("aria-roledescription", "slide");
|
|
328
|
+
this._generatedItemDescriptions.add(item);
|
|
329
|
+
}
|
|
330
|
+
if (!item.hasAttribute("aria-label") && !item.hasAttribute("aria-labelledby")) {
|
|
331
|
+
const mediaName = item.querySelector("img[alt]")?.getAttribute("alt")?.trim();
|
|
332
|
+
const textName = item.textContent?.replace(/\s+/g, " ").trim();
|
|
333
|
+
const name = mediaName || textName;
|
|
334
|
+
const position = `${this.options.i18n.item} ${index + 1} ${this.options.i18n.of} ${this.count}`;
|
|
335
|
+
item.setAttribute("aria-label", name ? `${name}, ${position}` : position);
|
|
336
|
+
this._generatedItemLabels.add(item);
|
|
337
|
+
}
|
|
338
|
+
if (!item.matches(naturallyFocusable) && !item.querySelector(naturallyFocusable)) {
|
|
339
|
+
item.tabIndex = 0;
|
|
340
|
+
this._generatedItemTabIndexes.add(item);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
_setupIndicators() {
|
|
345
|
+
const existing = Array.from(this.el.children).find(
|
|
346
|
+
(el) => el instanceof HTMLElement && el.classList.contains("indicators")
|
|
347
|
+
);
|
|
348
|
+
this._indicators = existing ?? document.createElement("nav");
|
|
349
|
+
this._ownIndicators = !existing;
|
|
350
|
+
this._indicators.classList.add("indicators");
|
|
351
|
+
this._indicators.setAttribute("aria-label", this.options.i18n.indicators);
|
|
352
|
+
this._indicators.replaceChildren();
|
|
353
|
+
this.images.forEach((_, i) => {
|
|
354
|
+
const button = document.createElement("button");
|
|
355
|
+
button.type = "button";
|
|
356
|
+
button.classList.add("indicator-item");
|
|
357
|
+
if (i === 0) {
|
|
358
|
+
button.classList.add("active");
|
|
359
|
+
button.setAttribute("aria-current", "true");
|
|
360
|
+
}
|
|
361
|
+
button.setAttribute("aria-label", `${this.options.i18n.slide} ${i + 1}`);
|
|
362
|
+
this._indicators.appendChild(button);
|
|
363
|
+
});
|
|
364
|
+
if (this._ownIndicators) this.el.appendChild(this._indicators);
|
|
365
|
+
this.el.querySelector(".carousel-fixed-item")?.classList.add("with-indicators");
|
|
366
|
+
}
|
|
367
|
+
_setupEventHandlers() {
|
|
368
|
+
this.el.addEventListener("keydown", this._handleKeydown);
|
|
369
|
+
this._motion.addEventListener("change", this._handleMotionChange);
|
|
370
|
+
if (this._autoAdvances) {
|
|
371
|
+
this.el.addEventListener("mouseenter", this._handleAutoAdvanceState);
|
|
372
|
+
this.el.addEventListener("mouseleave", this._handleAutoAdvanceState);
|
|
373
|
+
this.el.addEventListener("focusin", this._handleAutoAdvanceState);
|
|
374
|
+
this.el.addEventListener("focusout", this._handleAutoAdvanceState);
|
|
375
|
+
document.addEventListener("visibilitychange", this._handleAutoAdvanceState);
|
|
376
|
+
}
|
|
377
|
+
if (this.showIndicators && this._indicators) {
|
|
378
|
+
this._indicators.addEventListener("click", this._handleIndicatorClick);
|
|
379
|
+
}
|
|
380
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
381
|
+
this._resizeObserver = new ResizeObserver(() => this._handleThrottledResize());
|
|
382
|
+
this._resizeObserver.observe(this.el);
|
|
383
|
+
}
|
|
384
|
+
this._usesWindowResize = !this._resizeObserver || this.el.classList.contains("full-screen");
|
|
385
|
+
if (this._usesWindowResize) {
|
|
386
|
+
_Carousel._live.add(this);
|
|
387
|
+
if (!_Carousel._resizeListening) {
|
|
388
|
+
window.addEventListener("resize", _Carousel._onResize, {
|
|
389
|
+
passive: true
|
|
390
|
+
});
|
|
391
|
+
_Carousel._resizeListening = true;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
this._scroller.addEventListener("scroll", this._handleTrackScroll, {
|
|
395
|
+
passive: true
|
|
396
|
+
});
|
|
397
|
+
this._scroller.addEventListener("pointerdown", this._handleTrackPointerDown);
|
|
398
|
+
this._scroller.addEventListener("wheel", this._handleNativeScroll, { passive: true });
|
|
399
|
+
this._scroller.addEventListener("pointermove", this._handleTrackPointerMove);
|
|
400
|
+
this._scroller.addEventListener("pointerup", this._handleTrackPointerUp);
|
|
401
|
+
this._scroller.addEventListener("pointercancel", this._handleTrackPointerUp);
|
|
402
|
+
this._scroller.addEventListener("click", this._handleTrackClick, true);
|
|
403
|
+
this._scroller.addEventListener("dragstart", this._handleTrackDragStart);
|
|
404
|
+
this._scroller.addEventListener("transitionend", this._handleItemResize);
|
|
405
|
+
}
|
|
406
|
+
_removeEventHandlers() {
|
|
407
|
+
this.el.removeEventListener("keydown", this._handleKeydown);
|
|
408
|
+
this._motion.removeEventListener("change", this._handleMotionChange);
|
|
409
|
+
this.el.removeEventListener("mouseenter", this._handleAutoAdvanceState);
|
|
410
|
+
this.el.removeEventListener("mouseleave", this._handleAutoAdvanceState);
|
|
411
|
+
this.el.removeEventListener("focusin", this._handleAutoAdvanceState);
|
|
412
|
+
this.el.removeEventListener("focusout", this._handleAutoAdvanceState);
|
|
413
|
+
document.removeEventListener("visibilitychange", this._handleAutoAdvanceState);
|
|
414
|
+
if (this._indicators) {
|
|
415
|
+
this._indicators.removeEventListener("click", this._handleIndicatorClick);
|
|
416
|
+
}
|
|
417
|
+
this._scroller.removeEventListener("scroll", this._handleTrackScroll);
|
|
418
|
+
this._scroller.removeEventListener("pointerdown", this._handleTrackPointerDown);
|
|
419
|
+
this._scroller.removeEventListener("wheel", this._handleNativeScroll);
|
|
420
|
+
this._scroller.removeEventListener("pointermove", this._handleTrackPointerMove);
|
|
421
|
+
this._scroller.removeEventListener("pointerup", this._handleTrackPointerUp);
|
|
422
|
+
this._scroller.removeEventListener("pointercancel", this._handleTrackPointerUp);
|
|
423
|
+
this._scroller.removeEventListener("click", this._handleTrackClick, true);
|
|
424
|
+
this._scroller.removeEventListener("dragstart", this._handleTrackDragStart);
|
|
425
|
+
this._scroller.removeEventListener("transitionend", this._handleItemResize);
|
|
426
|
+
this._resizeObserver?.disconnect();
|
|
427
|
+
this._resizeObserver = null;
|
|
428
|
+
if (this._usesWindowResize) {
|
|
429
|
+
_Carousel._live.delete(this);
|
|
430
|
+
if (_Carousel._live.size === 0 && _Carousel._resizeListening) {
|
|
431
|
+
window.removeEventListener("resize", _Carousel._onResize);
|
|
432
|
+
_Carousel._resizeListening = false;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
_teardown() {
|
|
437
|
+
this._started = false;
|
|
438
|
+
this._removeEventHandlers();
|
|
439
|
+
this._finishScroll();
|
|
440
|
+
this._autoAdvances = false;
|
|
441
|
+
this._syncAutoAdvance();
|
|
442
|
+
if (this._trackRaf !== null) cancelAnimationFrame(this._trackRaf);
|
|
443
|
+
window.clearTimeout(this.scrollingTimeout);
|
|
444
|
+
window.clearTimeout(this._suppressClickTimeout);
|
|
445
|
+
clearTimeout(this._resizeTimeout);
|
|
446
|
+
if (this._ownIndicators) this._indicators?.remove();
|
|
447
|
+
this._unwrapTrack();
|
|
448
|
+
this.images.forEach((el) => {
|
|
449
|
+
el.style.removeProperty("--md-comp-carousel-item-parallax");
|
|
450
|
+
if (this._generatedItemLabels.has(el)) el.removeAttribute("aria-label");
|
|
451
|
+
if (this._generatedItemDescriptions.has(el)) el.removeAttribute("aria-roledescription");
|
|
452
|
+
if (this._generatedItemSizes.has(el)) el.removeAttribute("data-carousel-size");
|
|
453
|
+
const original = this._itemA11yOriginal.get(el);
|
|
454
|
+
if (original?.ariaHidden === null) el.removeAttribute("aria-hidden");
|
|
455
|
+
else if (original) el.setAttribute("aria-hidden", original.ariaHidden);
|
|
456
|
+
if (original?.tabIndex === null) el.removeAttribute("tabindex");
|
|
457
|
+
else if (original) el.setAttribute("tabindex", original.tabIndex);
|
|
458
|
+
});
|
|
459
|
+
if (this._generatedContainerRole) this.el.removeAttribute("role");
|
|
460
|
+
if (this._generatedContainerLabel) this.el.removeAttribute("aria-label");
|
|
461
|
+
if (this._generatedContainerDescription) this.el.removeAttribute("aria-roledescription");
|
|
462
|
+
if (this._generatedFixedHeight) this.el.classList.remove("fixed-height");
|
|
463
|
+
if (this.options.height !== null) {
|
|
464
|
+
if (this._authoredInlineHeight === null) this.el.style.removeProperty("--carousel-height");
|
|
465
|
+
else this.el.style.setProperty("--carousel-height", this._authoredInlineHeight);
|
|
466
|
+
}
|
|
467
|
+
if (this._generatedWideLayout) {
|
|
468
|
+
this.el.classList.remove(
|
|
469
|
+
"multi-wide",
|
|
470
|
+
"multi-large",
|
|
471
|
+
"multi-extra-large",
|
|
472
|
+
"full-screen-horizontal"
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/** Start or stop the timer to match the current pause state. */
|
|
477
|
+
_syncAutoAdvance() {
|
|
478
|
+
const run = this._autoAdvances && !this._autoPaused && !this._hovered && !this._focused && !this._motion.matches && !document.hidden;
|
|
479
|
+
if (run && this._autoAdvanceTimer === null) {
|
|
480
|
+
this._autoAdvanceTimer = setTimeout(
|
|
481
|
+
this._tick,
|
|
482
|
+
this.options.duration + this.options.interval
|
|
483
|
+
);
|
|
484
|
+
} else if (!run && this._autoAdvanceTimer !== null) {
|
|
485
|
+
clearTimeout(this._autoAdvanceTimer);
|
|
486
|
+
this._autoAdvanceTimer = null;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
_paintIndicators(center) {
|
|
490
|
+
if (!this.showIndicators || !this._indicators) return;
|
|
491
|
+
const pos = (center % this.count + this.count) % this.count;
|
|
492
|
+
this._indicators.querySelectorAll(".indicator-item").forEach((el, i) => {
|
|
493
|
+
const on = i === pos;
|
|
494
|
+
el.classList.toggle("active", on);
|
|
495
|
+
if (on) el.setAttribute("aria-current", "true");
|
|
496
|
+
else el.removeAttribute("aria-current");
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
_syncActive(index, dragged) {
|
|
500
|
+
const prev = this.center;
|
|
501
|
+
this.center = index;
|
|
502
|
+
this.images.forEach((el, i) => el.classList.toggle("active", i === index));
|
|
503
|
+
this._paintIndicators(index);
|
|
504
|
+
this._syncLayoutRoles(index);
|
|
505
|
+
const curr = this.images[index];
|
|
506
|
+
if (prev !== index && typeof this.options.onCycleTo === "function") {
|
|
507
|
+
this.options.onCycleTo.call(this, curr, dragged);
|
|
508
|
+
}
|
|
509
|
+
if (typeof this.oneTimeCallback === "function") {
|
|
510
|
+
this.oneTimeCallback.call(this, curr, dragged);
|
|
511
|
+
this.oneTimeCallback = null;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
_syncLayoutRoles(index) {
|
|
515
|
+
const setSize = (item, size) => {
|
|
516
|
+
if (this._authoredItemSizes.has(item)) return;
|
|
517
|
+
item.setAttribute("data-carousel-size", size);
|
|
518
|
+
this._generatedItemSizes.add(item);
|
|
519
|
+
};
|
|
520
|
+
this.images.forEach((item) => setSize(item, "large"));
|
|
521
|
+
if (this.el.classList.contains("flat") || this.el.classList.contains("uncontained") || this.el.classList.contains("full-screen") && this._vertical) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
if (this.el.classList.contains("hero") || this.el.classList.contains("full-screen-horizontal")) {
|
|
525
|
+
const next = this.images[index + 1];
|
|
526
|
+
if (next) setSize(next, "small");
|
|
527
|
+
if (this.el.classList.contains("center-aligned")) {
|
|
528
|
+
const previous = this.images[index - 1];
|
|
529
|
+
if (previous) setSize(previous, "small");
|
|
530
|
+
}
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
const width = this.el.clientWidth;
|
|
534
|
+
const desiredLargeCount = width >= 1600 ? 4 : width >= 1200 ? 3 : width >= 600 ? 2 : 1;
|
|
535
|
+
const largeCount = Math.min(desiredLargeCount, Math.max(1, this.count - 2));
|
|
536
|
+
this.el.classList.remove("multi-wide", "multi-large", "multi-extra-large");
|
|
537
|
+
if (largeCount === 2) this.el.classList.add("multi-wide");
|
|
538
|
+
else if (largeCount === 3) this.el.classList.add("multi-large");
|
|
539
|
+
else if (largeCount >= 4) this.el.classList.add("multi-extra-large");
|
|
540
|
+
this._generatedWideLayout = this._generatedWideLayout || largeCount > 1;
|
|
541
|
+
for (let offset = 1; offset < largeCount; offset += 1) {
|
|
542
|
+
const item = this.images[index + offset];
|
|
543
|
+
if (item) setSize(item, "large");
|
|
544
|
+
}
|
|
545
|
+
const medium = this.images[index + largeCount];
|
|
546
|
+
const small = this.images[index + largeCount + 1];
|
|
547
|
+
if (medium) setSize(medium, "medium");
|
|
548
|
+
if (small) setSize(small, "small");
|
|
549
|
+
}
|
|
550
|
+
_syncAdaptiveMode() {
|
|
551
|
+
if (!this.el.classList.contains("full-screen")) return;
|
|
552
|
+
const landscape = window.matchMedia("(orientation: landscape)").matches;
|
|
553
|
+
const horizontal = this.el.clientWidth >= 840 || landscape;
|
|
554
|
+
const wasVertical = this._vertical;
|
|
555
|
+
this._vertical = !horizontal;
|
|
556
|
+
this.el.classList.toggle("full-screen-horizontal", horizontal);
|
|
557
|
+
this._generatedWideLayout = this._generatedWideLayout || horizontal;
|
|
558
|
+
if (this._started && wasVertical !== this._vertical) {
|
|
559
|
+
this._scroller.scrollTo({ left: 0, top: 0, behavior: "auto" });
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
_focusItem(index) {
|
|
563
|
+
const item = this.images[index];
|
|
564
|
+
if (!item) return;
|
|
565
|
+
const focusable = item.matches(
|
|
566
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
567
|
+
) ? item : item.querySelector(
|
|
568
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
569
|
+
);
|
|
570
|
+
(focusable ?? item).focus({ preventScroll: true });
|
|
571
|
+
}
|
|
572
|
+
_updateParallax() {
|
|
573
|
+
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
574
|
+
this.images.forEach(
|
|
575
|
+
(item) => item.style.setProperty("--md-comp-carousel-item-parallax", "0px")
|
|
576
|
+
);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const scrollerRect = this._scroller.getBoundingClientRect();
|
|
580
|
+
const viewportCenter = this._vertical ? scrollerRect.top + scrollerRect.height / 2 : scrollerRect.left + scrollerRect.width / 2;
|
|
581
|
+
const viewportSize = Math.max(1, this._vertical ? scrollerRect.height : scrollerRect.width);
|
|
582
|
+
this.images.forEach((item) => {
|
|
583
|
+
const rect = item.getBoundingClientRect();
|
|
584
|
+
const itemCenter = this._vertical ? rect.top + rect.height / 2 : rect.left + rect.width / 2;
|
|
585
|
+
const progress = Math.max(-1, Math.min(1, (itemCenter - viewportCenter) / viewportSize));
|
|
586
|
+
item.style.setProperty("--md-comp-carousel-item-parallax", `${progress * -24}px`);
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
_wrapTrack() {
|
|
590
|
+
const track = document.createElement("div");
|
|
591
|
+
track.className = "carousel-track";
|
|
592
|
+
this.images[0].before(track);
|
|
593
|
+
this.images.forEach((el) => track.appendChild(el));
|
|
594
|
+
this._trackEl = track;
|
|
595
|
+
}
|
|
596
|
+
_unwrapTrack() {
|
|
597
|
+
if (!this._trackEl) return;
|
|
598
|
+
this.images.forEach((el) => this.el.insertBefore(el, this._trackEl));
|
|
599
|
+
this._trackEl.remove();
|
|
600
|
+
this._trackEl = null;
|
|
601
|
+
}
|
|
602
|
+
_nearestIndex() {
|
|
603
|
+
const centered = this.el.classList.contains("center-aligned");
|
|
604
|
+
const style = getComputedStyle(this._scroller);
|
|
605
|
+
const rtl = !this._vertical && style.direction === "rtl";
|
|
606
|
+
const position = this._vertical ? this._scroller.scrollTop : this._scroller.scrollLeft;
|
|
607
|
+
const viewport = this._vertical ? this._scroller.clientHeight : this._scroller.clientWidth;
|
|
608
|
+
const extent = (this._vertical ? this._scroller.scrollHeight : this._scroller.scrollWidth) - viewport;
|
|
609
|
+
const padding = parseFloat(this._vertical ? style.paddingBlockStart : style.paddingInlineStart) || 0;
|
|
610
|
+
let best = this.center;
|
|
611
|
+
let bestDist = Infinity;
|
|
612
|
+
this.images.forEach((el, i) => {
|
|
613
|
+
const start = this._vertical ? el.offsetTop : el.offsetLeft;
|
|
614
|
+
const size = this._vertical ? el.offsetHeight : el.offsetWidth;
|
|
615
|
+
const target = centered ? start - (viewport - size) / 2 : start + (rtl ? size - viewport + padding : -padding);
|
|
616
|
+
const bounded = Math.max(rtl ? -extent : 0, Math.min(rtl ? 0 : extent, target));
|
|
617
|
+
const dist = Math.abs(bounded - position);
|
|
618
|
+
if (dist < bestDist || dist === bestDist && i === this.center) {
|
|
619
|
+
bestDist = dist;
|
|
620
|
+
best = i;
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
return best;
|
|
624
|
+
}
|
|
625
|
+
_scrollToIndex(n, smooth = true) {
|
|
626
|
+
const el = this.images[n];
|
|
627
|
+
if (!el) return;
|
|
628
|
+
this._finishScroll();
|
|
629
|
+
const centered = this.el.classList.contains("center-aligned");
|
|
630
|
+
const style = getComputedStyle(this._scroller);
|
|
631
|
+
const inlinePadding = Number.parseFloat(style.paddingInlineStart) || 0;
|
|
632
|
+
const blockPadding = Number.parseFloat(style.paddingBlockStart) || 0;
|
|
633
|
+
const left = centered ? el.offsetLeft - (this._scroller.clientWidth - el.offsetWidth) / 2 : style.direction === "rtl" ? el.offsetLeft + el.offsetWidth - this._scroller.clientWidth + inlinePadding : el.offsetLeft - inlinePadding;
|
|
634
|
+
const top = el.offsetTop - blockPadding;
|
|
635
|
+
this._ignoreScroll = true;
|
|
636
|
+
this._scroller.scrollTo({
|
|
637
|
+
left: this._vertical ? 0 : left,
|
|
638
|
+
top: this._vertical ? top : 0,
|
|
639
|
+
behavior: smooth && !this._motion.matches ? "smooth" : "instant"
|
|
640
|
+
});
|
|
641
|
+
this._scroller.addEventListener("scrollend", this._handleScrollEnd);
|
|
642
|
+
this._scrollEndTimeout = setTimeout(this._finishScroll, this.options.duration + 350);
|
|
643
|
+
}
|
|
644
|
+
_cycleTo(n, callback = null) {
|
|
645
|
+
this._alignAfterResize = true;
|
|
646
|
+
if (typeof callback === "function") this.oneTimeCallback = callback;
|
|
647
|
+
this._syncActive(n, false);
|
|
648
|
+
this._scrollToIndex(n);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Stop auto-advance until start() is called. Without an `interval` there is
|
|
652
|
+
* nothing to stop and this does nothing.
|
|
653
|
+
*/
|
|
654
|
+
pause() {
|
|
655
|
+
this._autoPaused = true;
|
|
656
|
+
this._syncAutoAdvance();
|
|
657
|
+
}
|
|
658
|
+
/** Resume auto-advance after pause(). */
|
|
659
|
+
start() {
|
|
660
|
+
this._autoPaused = false;
|
|
661
|
+
this._syncAutoAdvance();
|
|
662
|
+
}
|
|
663
|
+
next(n = 1) {
|
|
664
|
+
if (n === void 0 || isNaN(n)) n = 1;
|
|
665
|
+
const index = this.center + n;
|
|
666
|
+
if (index >= this.count || index < 0) return;
|
|
667
|
+
this._cycleTo(index);
|
|
668
|
+
}
|
|
669
|
+
prev(n = 1) {
|
|
670
|
+
if (n === void 0 || isNaN(n)) n = 1;
|
|
671
|
+
const index = this.center - n;
|
|
672
|
+
if (index >= this.count || index < 0) return;
|
|
673
|
+
this._cycleTo(index);
|
|
674
|
+
}
|
|
675
|
+
set(n, callback) {
|
|
676
|
+
if (n === void 0 || isNaN(n)) n = 0;
|
|
677
|
+
if (n >= this.count || n < 0) return;
|
|
678
|
+
this._cycleTo(n, callback);
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
_Carousel._live = /* @__PURE__ */ new Set();
|
|
682
|
+
_Carousel._resizeListening = false;
|
|
683
|
+
_Carousel._onResize = Utils.throttle(() => {
|
|
684
|
+
_Carousel._live.forEach((c) => c._handleResize());
|
|
685
|
+
}, 200);
|
|
686
|
+
var Carousel = _Carousel;
|
|
687
|
+
|
|
688
|
+
export {
|
|
689
|
+
Carousel
|
|
690
|
+
};
|
|
691
|
+
//# sourceMappingURL=chunk-AOGFNMXS.mjs.map
|