@skerbis/nativecss 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/LICENSE +28 -0
- package/README.md +144 -2
- package/dist/base.css +225 -0
- package/dist/browser-fixes.css +32 -0
- package/dist/colors.css +288 -0
- package/dist/components/accordion-split.css +269 -0
- package/dist/components/alert.css +179 -0
- package/dist/components/app-shell.css +266 -0
- package/dist/components/audio-player.css +697 -0
- package/dist/components/audio.css +35 -0
- package/dist/components/aurora.css +132 -0
- package/dist/components/avatar.css +102 -0
- package/dist/components/back-to-top.css +120 -0
- package/dist/components/backdrop.css +94 -0
- package/dist/components/badge.css +95 -0
- package/dist/components/breadcrumb.css +58 -0
- package/dist/components/card.css +721 -0
- package/dist/components/code-block.css +234 -0
- package/dist/components/combobox.css +103 -0
- package/dist/components/command-palette.css +351 -0
- package/dist/components/comments.css +243 -0
- package/dist/components/compare.css +218 -0
- package/dist/components/count-up.css +140 -0
- package/dist/components/countdown.css +74 -0
- package/dist/components/cover.css +45 -0
- package/dist/components/curtain.css +116 -0
- package/dist/components/dialog-close.css +44 -0
- package/dist/components/disclosure.css +37 -0
- package/dist/components/downloads.css +47 -0
- package/dist/components/dropdown.css +260 -0
- package/dist/components/dropzone.css +181 -0
- package/dist/components/effects.css +236 -0
- package/dist/components/empty-state.css +74 -0
- package/dist/components/events.css +165 -0
- package/dist/components/expand-panels.css +220 -0
- package/dist/components/filter.css +179 -0
- package/dist/components/floating-label.css +69 -0
- package/dist/components/footer.css +56 -0
- package/dist/components/hero.css +139 -0
- package/dist/components/hovercard.css +146 -0
- package/dist/components/input-group.css +67 -0
- package/dist/components/kbd.css +44 -0
- package/dist/components/leaders.css +99 -0
- package/dist/components/lightbox.css +165 -0
- package/dist/components/lists.css +221 -0
- package/dist/components/livesearch.css +106 -0
- package/dist/components/map.css +245 -0
- package/dist/components/marginnote.css +109 -0
- package/dist/components/marquee.css +119 -0
- package/dist/components/modal.css +385 -0
- package/dist/components/morph.css +317 -0
- package/dist/components/nav-drilldown.css +190 -0
- package/dist/components/nav-priority.css +157 -0
- package/dist/components/nav.css +528 -0
- package/dist/components/notification.css +290 -0
- package/dist/components/off-canvas.css +107 -0
- package/dist/components/overlay.css +122 -0
- package/dist/components/pagination.css +139 -0
- package/dist/components/pill-group.css +143 -0
- package/dist/components/placeholder.css +28 -0
- package/dist/components/preferences-fonts.css +65 -0
- package/dist/components/preferences.css +283 -0
- package/dist/components/pricing.css +220 -0
- package/dist/components/rating.css +121 -0
- package/dist/components/reveal-pin.css +165 -0
- package/dist/components/roadmap.css +173 -0
- package/dist/components/scroll-frames.css +97 -0
- package/dist/components/scroll-horizontal.css +141 -0
- package/dist/components/scroll-progress.css +63 -0
- package/dist/components/scroll-stack.css +363 -0
- package/dist/components/scroll-video.css +172 -0
- package/dist/components/scrolly.css +190 -0
- package/dist/components/search.css +52 -0
- package/dist/components/segmented.css +209 -0
- package/dist/components/select.css +186 -0
- package/dist/components/slideshow.css +441 -0
- package/dist/components/sortable.css +186 -0
- package/dist/components/sparkline.css +50 -0
- package/dist/components/spinner.css +50 -0
- package/dist/components/split.css +85 -0
- package/dist/components/spotlight.css +111 -0
- package/dist/components/stat.css +82 -0
- package/dist/components/stepper.css +217 -0
- package/dist/components/subnav.css +151 -0
- package/dist/components/table-sort.css +111 -0
- package/dist/components/tabs.css +304 -0
- package/dist/components/tag.css +130 -0
- package/dist/components/testimonial.css +188 -0
- package/dist/components/text-reveal.css +141 -0
- package/dist/components/theme-toggle.css +62 -0
- package/dist/components/tile.css +53 -0
- package/dist/components/timeline.css +211 -0
- package/dist/components/toolbar.css +139 -0
- package/dist/components/tooltip.css +89 -0
- package/dist/components/topbar.css +92 -0
- package/dist/components/video-bg.css +176 -0
- package/dist/components/video-card.css +145 -0
- package/dist/components/video-float.css +142 -0
- package/dist/components/video-player.css +1116 -0
- package/dist/components/video-text.css +91 -0
- package/dist/components/video.css +65 -0
- package/dist/fonts/README.md +29 -0
- package/dist/fonts/atkinson-hyperlegible-next/OFL.txt +93 -0
- package/dist/fonts/atkinson-hyperlegible-next/atkinson-hyperlegible-next.woff2 +0 -0
- package/dist/fonts/lexend/OFL.txt +93 -0
- package/dist/fonts/lexend/lexend.woff2 +0 -0
- package/dist/fonts/opendyslexic/OFL.txt +94 -0
- package/dist/fonts/opendyslexic/OpenDyslexic-Bold.woff2 +0 -0
- package/dist/fonts/opendyslexic/OpenDyslexic-Regular.woff2 +0 -0
- package/dist/helpers/a11y.css +71 -0
- package/dist/helpers/animations.css +206 -0
- package/dist/helpers/elevation.css +87 -0
- package/dist/helpers/float.css +117 -0
- package/dist/helpers/forms.css +503 -0
- package/dist/helpers/icons.css +130 -0
- package/dist/helpers/layout.css +549 -0
- package/dist/helpers/media.css +77 -0
- package/dist/helpers/reveal.css +172 -0
- package/dist/helpers/scroll-shadow.css +129 -0
- package/dist/helpers/scroll.css +163 -0
- package/dist/helpers/surfaces.css +87 -0
- package/dist/helpers/tables.css +85 -0
- package/dist/helpers/typography.css +347 -0
- package/dist/helpers/visibility.css +134 -0
- package/dist/integrations/fontawesome-font-display-fix.css +67 -0
- package/dist/integrations/webawesome-bridge.css +195 -0
- package/dist/js/audio-player.js +942 -0
- package/dist/js/backdrop.js +119 -0
- package/dist/js/code-block.js +238 -0
- package/dist/js/combobox.js +382 -0
- package/dist/js/command-fallback.js +35 -0
- package/dist/js/command-palette.js +477 -0
- package/dist/js/compare.js +73 -0
- package/dist/js/content-observer.js +82 -0
- package/dist/js/count-up.js +150 -0
- package/dist/js/countdown.js +185 -0
- package/dist/js/dialog-light-dismiss.js +123 -0
- package/dist/js/dismiss.js +144 -0
- package/dist/js/downloads.js +181 -0
- package/dist/js/dropdown.js +300 -0
- package/dist/js/dropzone.js +304 -0
- package/dist/js/events.js +501 -0
- package/dist/js/filter.js +177 -0
- package/dist/js/hero-video-motion.js +37 -0
- package/dist/js/hide-on-scroll-fallback.js +102 -0
- package/dist/js/hovercard.js +228 -0
- package/dist/js/icon.js +166 -0
- package/dist/js/ics.js +290 -0
- package/dist/js/lightbox.js +144 -0
- package/dist/js/livesearch.js +253 -0
- package/dist/js/map.js +625 -0
- package/dist/js/marquee.js +108 -0
- package/dist/js/modal-router.js +298 -0
- package/dist/js/nav-drilldown.js +250 -0
- package/dist/js/nav-priority.js +221 -0
- package/dist/js/nav.js +28 -0
- package/dist/js/ncss-container.js +117 -0
- package/dist/js/notification.js +372 -0
- package/dist/js/page-transitions-quiet.js +44 -0
- package/dist/js/preferences-early.js +51 -0
- package/dist/js/preferences.js +346 -0
- package/dist/js/reveal.js +79 -0
- package/dist/js/scroll-frames.js +284 -0
- package/dist/js/scroll-horizontal.js +121 -0
- package/dist/js/scroll-stack-fallback.js +250 -0
- package/dist/js/scroll-video.js +332 -0
- package/dist/js/scrolly.js +109 -0
- package/dist/js/slideshow.js +416 -0
- package/dist/js/sortable.js +530 -0
- package/dist/js/sparkline.js +199 -0
- package/dist/js/spotlight.js +104 -0
- package/dist/js/subnav.js +163 -0
- package/dist/js/table-sort.js +312 -0
- package/dist/js/tabs.js +243 -0
- package/dist/js/text-reveal.js +108 -0
- package/dist/js/theme-toggle-early.js +28 -0
- package/dist/js/theme-toggle.js +135 -0
- package/dist/js/toolbar.js +130 -0
- package/dist/js/tooltip.js +214 -0
- package/dist/js/video-bg.js +193 -0
- package/dist/js/video-card.js +80 -0
- package/dist/js/video-float.js +119 -0
- package/dist/js/video-player.js +1267 -0
- package/dist/js/view-transitions.js +118 -0
- package/dist/js/wa-close-on-scroll.js +56 -0
- package/dist/ncss.css +165 -0
- package/dist/page-transitions.css +150 -0
- package/dist/reset.css +196 -0
- package/dist/theme.css +112 -0
- package/dist/tokens.css +238 -0
- package/package.json +52 -4
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - <ncss-slideshow>: Pfeile, Punkte und optionales Autoplay für
|
|
3
|
+
* components/slideshow.css. Light-DOM-Custom-Element ohne Shadow Root - der Track
|
|
4
|
+
* bleibt ein ganz normaler Scroll-Snap-Container (Wischen, Trackpad, Tastatur wie
|
|
5
|
+
* bisher), das Script ergänzt nur Bedienelemente.
|
|
6
|
+
*
|
|
7
|
+
* Markup:
|
|
8
|
+
* <ncss-slideshow class="ncss-slideshow ncss-slideshow--controls" autoplay="6000">
|
|
9
|
+
* <ul class="ncss-slideshow-track" tabindex="0" aria-label="Fotos">
|
|
10
|
+
* <li class="ncss-slideshow-item">...</li>
|
|
11
|
+
* </ul>
|
|
12
|
+
* </ncss-slideshow>
|
|
13
|
+
*
|
|
14
|
+
* Nie doppelte Steuerung: Pfeile baut das Script nur ohne ::scroll-button(), Punkte nur
|
|
15
|
+
* ohne ::scroll-marker - exakt dieselben Bedingungen wie die @supports-Blöcke in
|
|
16
|
+
* slideshow.css. In Chromium 135+ bleibt bei .ncss-slideshow--controls also alles nativ,
|
|
17
|
+
* das Script kümmert sich dort nur noch um ein eventuelles Autoplay.
|
|
18
|
+
*
|
|
19
|
+
* Mit .ncss-slideshow--shadow setzt das Script zusätzlich data-ncss-overflow="start end"
|
|
20
|
+
* (Richtungen mit weiterem Inhalt) - davon hängen die Randschatten ab, wo die rein
|
|
21
|
+
* scroll-getriebene CSS-Variante nicht greift (Safari, reduzierte Bewegung).
|
|
22
|
+
*
|
|
23
|
+
* Attribute (am Element):
|
|
24
|
+
* autoplay[="ms"] automatischer Wechsel, Standard AUS; Wert = Intervall (Default 6000).
|
|
25
|
+
* Bringt immer einen Pause-Knopf mit (WCAG 2.2.2), hält bei Hover/
|
|
26
|
+
* Fokus in der Slideshow an, startet bei reduzierter Bewegung
|
|
27
|
+
* (System oder <html data-motion="reduce">) gar nicht erst.
|
|
28
|
+
* Beschriftungen: Deutsch/Englisch nach <html lang>, jede per data-label-<key> am Track
|
|
29
|
+
* (oder am Element) überschreibbar: prev, next, dots, dot ("{n} von {total}"), play, pause.
|
|
30
|
+
*
|
|
31
|
+
* Events (bubbeln): ncss-slideshow-change { index } bei neuem aktuellem Element,
|
|
32
|
+
* ncss-slideshow-play / ncss-slideshow-pause beim Umschalten des Autoplays.
|
|
33
|
+
* Öffentlich: el.next(), el.prev(), el.goTo(index), el.play(), el.pause(), el.index.
|
|
34
|
+
* Dynamische Elemente im Track: nach dem Einfügen "ncss-content-change" auslösen (oder
|
|
35
|
+
* js/content-observer.js einbinden) - Punkte und Pfeile werden dann neu berechnet.
|
|
36
|
+
*
|
|
37
|
+
* Ohne customElements wird nichts registriert (Element bleibt :not(:defined)) - die
|
|
38
|
+
* Slideshow bleibt per Wischen/Scrollen voll bedienbar, nur ohne Fallback-Knöpfe.
|
|
39
|
+
*/
|
|
40
|
+
(function () {
|
|
41
|
+
"use strict";
|
|
42
|
+
|
|
43
|
+
if (!window.customElements || customElements.get("ncss-slideshow")) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var TEXTS = {
|
|
48
|
+
de: { prev: "Vorheriges Element", next: "Nächstes Element", dots: "Element wählen",
|
|
49
|
+
dot: "{n} von {total}", play: "Automatisch abspielen", pause: "Automatik anhalten" },
|
|
50
|
+
en: { prev: "Previous item", next: "Next item", dots: "Choose item",
|
|
51
|
+
dot: "{n} of {total}", play: "Play automatically", pause: "Pause autoplay" }
|
|
52
|
+
};
|
|
53
|
+
var lang = (document.documentElement.getAttribute("lang") || "de").slice(0, 2) === "en" ? "en" : "de";
|
|
54
|
+
|
|
55
|
+
var supports = window.CSS && CSS.supports ? CSS.supports.bind(CSS) : function () { return false; };
|
|
56
|
+
var NATIVE_BUTTONS = supports("selector(::scroll-button(*))");
|
|
57
|
+
var NATIVE_MARKERS = supports("selector(::scroll-marker)");
|
|
58
|
+
|
|
59
|
+
var reduceMq = window.matchMedia ? window.matchMedia("(prefers-reduced-motion: reduce)") : null;
|
|
60
|
+
function reducedMotion() {
|
|
61
|
+
var m = document.documentElement.getAttribute("data-motion");
|
|
62
|
+
if (m === "reduce") return true;
|
|
63
|
+
if (m === "full") return false;
|
|
64
|
+
return !!(reduceMq && reduceMq.matches);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var uid = 0;
|
|
68
|
+
|
|
69
|
+
customElements.define(
|
|
70
|
+
"ncss-slideshow",
|
|
71
|
+
class extends HTMLElement {
|
|
72
|
+
connectedCallback() {
|
|
73
|
+
if (this._track) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
var track = this.querySelector(":scope > .ncss-slideshow-track");
|
|
77
|
+
if (!track) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this._track = track;
|
|
81
|
+
this._index = -1;
|
|
82
|
+
if (!track.id) {
|
|
83
|
+
track.id = "ncss-slideshow-" + (++uid);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (this.classList.contains("ncss-slideshow--controls")) {
|
|
87
|
+
if (!NATIVE_BUTTONS) {
|
|
88
|
+
this._prev = this._button("prev", "‹");
|
|
89
|
+
this._next = this._button("next", "›");
|
|
90
|
+
track.after(this._prev, this._next);
|
|
91
|
+
}
|
|
92
|
+
if (!NATIVE_MARKERS) {
|
|
93
|
+
this._dots = document.createElement("div");
|
|
94
|
+
this._dots.className = "ncss-slideshow-dots";
|
|
95
|
+
this._dots.setAttribute("role", "group");
|
|
96
|
+
this._dots.setAttribute("aria-label", this._text("dots"));
|
|
97
|
+
this._dots.addEventListener("click", this._onDot.bind(this));
|
|
98
|
+
(this._next || track).after(this._dots);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this._onScroll = this._schedule.bind(this);
|
|
103
|
+
track.addEventListener("scroll", this._onScroll, { passive: true });
|
|
104
|
+
if (window.ResizeObserver) {
|
|
105
|
+
this._ro = new ResizeObserver(this._onScroll);
|
|
106
|
+
this._ro.observe(track);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Dynamisch eingefügte Elemente (htmx, fetch+innerHTML): Punkte und Pfeil-Zustand
|
|
110
|
+
// neu berechnen (siehe js/content-observer.js).
|
|
111
|
+
var self = this;
|
|
112
|
+
this._onContent = function (event) {
|
|
113
|
+
var root = (event.detail && event.detail.root) || document;
|
|
114
|
+
if (root === document || self.contains(root) || (root.contains && root.contains(self))) {
|
|
115
|
+
self._schedule();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
document.addEventListener("ncss-content-change", this._onContent);
|
|
119
|
+
|
|
120
|
+
if (this.hasAttribute("autoplay")) {
|
|
121
|
+
this._setupAutoplay();
|
|
122
|
+
}
|
|
123
|
+
this._update();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
disconnectedCallback() {
|
|
127
|
+
if (this._track && this._onScroll) {
|
|
128
|
+
this._track.removeEventListener("scroll", this._onScroll);
|
|
129
|
+
}
|
|
130
|
+
if (this._ro) {
|
|
131
|
+
this._ro.disconnect();
|
|
132
|
+
}
|
|
133
|
+
this._stopTimer();
|
|
134
|
+
document.removeEventListener("ncss-content-change", this._onContent);
|
|
135
|
+
if (this._onMotion) {
|
|
136
|
+
if (reduceMq && reduceMq.removeEventListener) reduceMq.removeEventListener("change", this._onMotion);
|
|
137
|
+
document.removeEventListener("ncss-preferences-change", this._onMotion);
|
|
138
|
+
document.removeEventListener("visibilitychange", this._onMotion);
|
|
139
|
+
}
|
|
140
|
+
// Erzeugte Knöpfe entfernen - beim erneuten Einhängen entstehen sie frisch.
|
|
141
|
+
[this._prev, this._next, this._dots, this._toggle].forEach(function (el) {
|
|
142
|
+
if (el) el.remove();
|
|
143
|
+
});
|
|
144
|
+
this._track = this._prev = this._next = this._dots = this._toggle = null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
get index() {
|
|
148
|
+
return this._index;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
next() {
|
|
152
|
+
this._step(1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
prev() {
|
|
156
|
+
this._step(-1);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
goTo(i) {
|
|
160
|
+
var items = this._items();
|
|
161
|
+
if (!items[i]) return;
|
|
162
|
+
this._scrollTo(this._offset(items[i]));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
play() {
|
|
166
|
+
if (!this._toggle) return;
|
|
167
|
+
this._userPaused = false;
|
|
168
|
+
this._syncAutoplay(true);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
pause() {
|
|
172
|
+
if (!this._toggle) return;
|
|
173
|
+
this._userPaused = true;
|
|
174
|
+
this._syncAutoplay(true);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// --- Hilfen ------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
_text(key) {
|
|
180
|
+
var t = this._track;
|
|
181
|
+
return (t && t.getAttribute("data-label-" + key)) || this.getAttribute("data-label-" + key) || TEXTS[lang][key];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_button(dir, glyph) {
|
|
185
|
+
var b = document.createElement("button");
|
|
186
|
+
b.type = "button";
|
|
187
|
+
b.className = "ncss-slideshow-button ncss-slideshow-button--" + dir;
|
|
188
|
+
b.setAttribute("aria-label", this._text(dir));
|
|
189
|
+
b.setAttribute("aria-controls", this._track.id);
|
|
190
|
+
var span = document.createElement("span");
|
|
191
|
+
span.setAttribute("aria-hidden", "true");
|
|
192
|
+
span.textContent = glyph;
|
|
193
|
+
b.appendChild(span);
|
|
194
|
+
var self = this;
|
|
195
|
+
b.addEventListener("click", function () {
|
|
196
|
+
if (b.getAttribute("aria-disabled") !== "true") self._step(dir === "next" ? 1 : -1);
|
|
197
|
+
});
|
|
198
|
+
return b;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_items() {
|
|
202
|
+
return Array.prototype.slice.call(this._track.querySelectorAll(":scope > .ncss-slideshow-item"));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
_rtl() {
|
|
206
|
+
return getComputedStyle(this._track).direction === "rtl";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Abstand eines Elements vom Anfang des sichtbaren Track-Bereichs (in
|
|
210
|
+
// Leserichtung, also auch bei RTL positiv = "weiter hinten").
|
|
211
|
+
_offset(item) {
|
|
212
|
+
var t = this._track.getBoundingClientRect();
|
|
213
|
+
var r = item.getBoundingClientRect();
|
|
214
|
+
var pad = parseFloat(getComputedStyle(this._track).scrollPaddingInlineStart) || 0;
|
|
215
|
+
return this._rtl() ? t.right - pad - r.right : r.left - t.left - pad;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
_scrollTo(delta) {
|
|
219
|
+
// scroll-behavior des Tracks (smooth, bei reduzierter Bewegung auto) gilt auch hier.
|
|
220
|
+
this._track.scrollBy({ left: this._rtl() ? -delta : delta });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
_edges() {
|
|
224
|
+
var t = this._track;
|
|
225
|
+
var pos = Math.abs(t.scrollLeft);
|
|
226
|
+
var max = t.scrollWidth - t.clientWidth;
|
|
227
|
+
return { start: pos <= 1, end: pos >= max - 1 };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
_step(dir) {
|
|
231
|
+
var items = this._items();
|
|
232
|
+
var target = null;
|
|
233
|
+
for (var i = 0; i < items.length; i++) {
|
|
234
|
+
var off = this._offset(items[i]);
|
|
235
|
+
if (dir > 0 && off > 2) {
|
|
236
|
+
target = off;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
if (dir < 0 && off < -2) {
|
|
240
|
+
target = off;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (target !== null) this._scrollTo(target);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
_currentIndex(items) {
|
|
247
|
+
if (!items.length) return -1;
|
|
248
|
+
var edges = this._edges();
|
|
249
|
+
// Am Ende: das letzte Element - schmale Elemente (--peek) erreichen den Anfang des
|
|
250
|
+
// Tracks nie, ihr Punkt soll trotzdem aktiv werden können.
|
|
251
|
+
if (edges.end && !edges.start) return items.length - 1;
|
|
252
|
+
var best = 0;
|
|
253
|
+
var bestDist = Infinity;
|
|
254
|
+
for (var i = 0; i < items.length; i++) {
|
|
255
|
+
var d = Math.abs(this._offset(items[i]));
|
|
256
|
+
if (d < bestDist) {
|
|
257
|
+
bestDist = d;
|
|
258
|
+
best = i;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return best;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_schedule() {
|
|
265
|
+
if (this._raf) return;
|
|
266
|
+
var self = this;
|
|
267
|
+
this._raf = requestAnimationFrame(function () {
|
|
268
|
+
self._raf = 0;
|
|
269
|
+
self._update();
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
_update() {
|
|
274
|
+
if (!this._track) return;
|
|
275
|
+
var items = this._items();
|
|
276
|
+
var edges = this._edges();
|
|
277
|
+
if (this._prev) {
|
|
278
|
+
this._prev.setAttribute("aria-disabled", edges.start ? "true" : "false");
|
|
279
|
+
this._next.setAttribute("aria-disabled", edges.end ? "true" : "false");
|
|
280
|
+
}
|
|
281
|
+
// Für .ncss-slideshow--shadow: in welche Richtung geht es weiter? (CSS blendet
|
|
282
|
+
// danach die Randschatten ein - Fallback für Browser ohne funktionierende
|
|
283
|
+
// scroll-getriebene Animation, siehe slideshow.css.)
|
|
284
|
+
if (this.classList.contains("ncss-slideshow--shadow")) {
|
|
285
|
+
var more = [];
|
|
286
|
+
if (!edges.start) more.push("start");
|
|
287
|
+
if (!edges.end) more.push("end");
|
|
288
|
+
this.setAttribute("data-ncss-overflow", more.join(" "));
|
|
289
|
+
}
|
|
290
|
+
var index = this._currentIndex(items);
|
|
291
|
+
if (this._dots) this._renderDots(items, index);
|
|
292
|
+
if (index !== this._index) {
|
|
293
|
+
var first = this._index === -1;
|
|
294
|
+
this._index = index;
|
|
295
|
+
if (!first) {
|
|
296
|
+
this.dispatchEvent(new CustomEvent("ncss-slideshow-change", { bubbles: true, detail: { index: index } }));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
_renderDots(items, index) {
|
|
302
|
+
var dots = this._dots;
|
|
303
|
+
// Anzahl geändert (dynamisch eingefügte Elemente)? Dann neu aufbauen.
|
|
304
|
+
if (dots.children.length !== items.length) {
|
|
305
|
+
var focused = dots.contains(document.activeElement);
|
|
306
|
+
dots.textContent = "";
|
|
307
|
+
for (var i = 0; i < items.length; i++) {
|
|
308
|
+
var b = document.createElement("button");
|
|
309
|
+
b.type = "button";
|
|
310
|
+
b.className = "ncss-slideshow-dot";
|
|
311
|
+
b.setAttribute("aria-controls", this._track.id);
|
|
312
|
+
b.setAttribute("aria-label", this._text("dot").replace("{n}", i + 1).replace("{total}", items.length));
|
|
313
|
+
dots.appendChild(b);
|
|
314
|
+
}
|
|
315
|
+
if (focused && dots.firstChild) dots.firstChild.focus();
|
|
316
|
+
}
|
|
317
|
+
for (var j = 0; j < dots.children.length; j++) {
|
|
318
|
+
if (j === index) {
|
|
319
|
+
dots.children[j].setAttribute("aria-current", "true");
|
|
320
|
+
} else {
|
|
321
|
+
dots.children[j].removeAttribute("aria-current");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
_onDot(event) {
|
|
327
|
+
var b = event.target.closest(".ncss-slideshow-dot");
|
|
328
|
+
if (!b) return;
|
|
329
|
+
this.goTo(Array.prototype.indexOf.call(this._dots.children, b));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// --- Autoplay (opt-in) -----------------------------------------------------------
|
|
333
|
+
|
|
334
|
+
_setupAutoplay() {
|
|
335
|
+
var self = this;
|
|
336
|
+
var ms = parseInt(this.getAttribute("autoplay"), 10);
|
|
337
|
+
this._interval = ms >= 1000 ? ms : 6000;
|
|
338
|
+
this._userPaused = reducedMotion();
|
|
339
|
+
this._hold = false;
|
|
340
|
+
|
|
341
|
+
this._toggle = document.createElement("button");
|
|
342
|
+
this._toggle.type = "button";
|
|
343
|
+
this._toggle.className = "ncss-slideshow-toggle";
|
|
344
|
+
this._toggle.setAttribute("aria-controls", this._track.id);
|
|
345
|
+
this._toggle.addEventListener("click", function () {
|
|
346
|
+
self._userPaused = !self._userPaused;
|
|
347
|
+
self._syncAutoplay(true);
|
|
348
|
+
});
|
|
349
|
+
// Im DOM VOR dem Track: der Pause-Knopf ist das Erste, was Tastatur- und
|
|
350
|
+
// Screenreader-Nutzer erreichen (optisch steht er unten links).
|
|
351
|
+
this.insertBefore(this._toggle, this.firstChild);
|
|
352
|
+
|
|
353
|
+
// Anhalten, solange Maus oder Fokus in der Slideshow sind - außer der Fokus liegt
|
|
354
|
+
// auf dem Pause-Knopf selbst (sonst könnte man das Autoplay nie per Tastatur starten
|
|
355
|
+
// und gleichzeitig beobachten).
|
|
356
|
+
// Nur einmal pro Element binden (auch nach Aus- und Wiedereinhängen).
|
|
357
|
+
if (!this._holdBound) {
|
|
358
|
+
this._holdBound = true;
|
|
359
|
+
var hold = function () {
|
|
360
|
+
var a = document.activeElement;
|
|
361
|
+
self._hold = self._hover || (self.contains(a) && a !== self._toggle);
|
|
362
|
+
self._syncAutoplay(false);
|
|
363
|
+
};
|
|
364
|
+
this.addEventListener("pointerenter", function () { self._hover = true; hold(); });
|
|
365
|
+
this.addEventListener("pointerleave", function () { self._hover = false; hold(); });
|
|
366
|
+
this.addEventListener("focusin", hold);
|
|
367
|
+
this.addEventListener("focusout", function () { setTimeout(hold, 0); });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
this._onMotion = function () {
|
|
371
|
+
if (reducedMotion()) self._userPaused = true;
|
|
372
|
+
self._syncAutoplay(false);
|
|
373
|
+
};
|
|
374
|
+
if (reduceMq && reduceMq.addEventListener) reduceMq.addEventListener("change", this._onMotion);
|
|
375
|
+
document.addEventListener("ncss-preferences-change", this._onMotion);
|
|
376
|
+
document.addEventListener("visibilitychange", this._onMotion);
|
|
377
|
+
|
|
378
|
+
this._syncAutoplay(false);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
_syncAutoplay(notify) {
|
|
382
|
+
if (!this._toggle) return;
|
|
383
|
+
var playing = !this._userPaused;
|
|
384
|
+
this._toggle.textContent = playing ? this._text("pause") : this._text("play");
|
|
385
|
+
var run = playing && !this._hold && !document.hidden;
|
|
386
|
+
if (run) {
|
|
387
|
+
this._startTimer();
|
|
388
|
+
} else {
|
|
389
|
+
this._stopTimer();
|
|
390
|
+
}
|
|
391
|
+
if (notify) {
|
|
392
|
+
this.dispatchEvent(new CustomEvent(playing ? "ncss-slideshow-play" : "ncss-slideshow-pause", { bubbles: true }));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
_startTimer() {
|
|
397
|
+
if (this._timer) return;
|
|
398
|
+
var self = this;
|
|
399
|
+
this._timer = setInterval(function () {
|
|
400
|
+
if (self._edges().end) {
|
|
401
|
+
self._scrollTo(-Math.abs(self._track.scrollLeft) - 1);
|
|
402
|
+
} else {
|
|
403
|
+
self._step(1);
|
|
404
|
+
}
|
|
405
|
+
}, this._interval);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
_stopTimer() {
|
|
409
|
+
if (this._timer) {
|
|
410
|
+
clearInterval(this._timer);
|
|
411
|
+
this._timer = 0;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
})();
|