@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,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeCSS - opt-in Begleiter für components/count-up.css
|
|
3
|
+
* (<span class="ncss-count-up" data-ncss-count-up style="--ncss-count-to: 40">40</span>,
|
|
4
|
+
* oder data-ncss-count-up auf einem Vorfahren, z.B. <dl class="ncss-dl--stats"
|
|
5
|
+
* data-ncss-count-up> - dann zählt jedes .ncss-count-up darin).
|
|
6
|
+
*
|
|
7
|
+
* Mit diesem Script zählt die Zahl IMMER zeitbasiert per JS (requestAnimationFrame), in
|
|
8
|
+
* allen Browsern - auch dort, wo CSS-Scroll-Trigger (timeline-trigger, Chromium) die
|
|
9
|
+
* Zählung selbst abspielen könnten. Grund: die reine CSS-Variante zählt über counter(),
|
|
10
|
+
* und counter() kennt keine Tausender-Trenner ("12500" statt "12.500" während des
|
|
11
|
+
* Zählens, per Demo-Test gefunden). Das Script formatiert jeden Zwischenwert per
|
|
12
|
+
* Intl.NumberFormat in der Sprache des nächsten [lang]-Vorfahren (de: "12.500",
|
|
13
|
+
* en: "12,500") und schreibt ihn nach data-ncss-count-text, das ::after per attr() zeigt.
|
|
14
|
+
* Der echte, fertig formatierte DOM-Text bleibt unverändert (Screenreader, Kopieren).
|
|
15
|
+
*
|
|
16
|
+
* Start, sobald die Zahl ins Bild kommt (IntersectionObserver). Nachkommastellen: aus
|
|
17
|
+
* --ncss-count-to übernommen ("4.5" -> eine Stelle) oder per data-ncss-count-decimals.
|
|
18
|
+
* Fehlt --ncss-count-to, wird der Zielwert aus dem Text gelesen ("12.500" -> 12500).
|
|
19
|
+
* Unter prefers-reduced-motion: keine Änderung, die fertige Zahl bleibt stehen.
|
|
20
|
+
*
|
|
21
|
+
* Dynamische Inhalte: neu eingefügte Zahlen per
|
|
22
|
+
* document.dispatchEvent(new CustomEvent("ncss-content-change", { detail: { root: el } }))
|
|
23
|
+
* melden (oder js/content-observer.js einbinden) - bereits verarbeitete Elemente werden
|
|
24
|
+
* nie doppelt gestartet.
|
|
25
|
+
*
|
|
26
|
+
* Benötigt: components/count-up.css.
|
|
27
|
+
* Einbindung: <script src="ncss/js/count-up.js" defer></script>
|
|
28
|
+
*/
|
|
29
|
+
(function () {
|
|
30
|
+
// Bewegung reduzieren? Systemeinstellung ODER ausdrückliche Wahl am <html>
|
|
31
|
+
// (data-motion="reduce"/"full", gesetzt von js/preferences.js) - "full" hebt ein
|
|
32
|
+
// System-"reduce" nur als bewusste Nutzerwahl auf, nie von selbst.
|
|
33
|
+
function ncssReducedMotion() {
|
|
34
|
+
var choice = document.documentElement.getAttribute("data-motion");
|
|
35
|
+
if (choice === "reduce") return true;
|
|
36
|
+
if (choice === "full") return false;
|
|
37
|
+
return !!(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
38
|
+
}
|
|
39
|
+
if (
|
|
40
|
+
typeof IntersectionObserver === "undefined" ||
|
|
41
|
+
typeof WeakSet === "undefined" ||
|
|
42
|
+
typeof window.requestAnimationFrame !== "function" ||
|
|
43
|
+
ncssReducedMotion()
|
|
44
|
+
) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var SELECTOR = "[data-ncss-count-up]";
|
|
49
|
+
|
|
50
|
+
function langOf(el) {
|
|
51
|
+
var host = el.closest("[lang]");
|
|
52
|
+
return (host && host.getAttribute("lang")) || document.documentElement.getAttribute("lang") || undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function formatter(el, decimals) {
|
|
56
|
+
try {
|
|
57
|
+
return new Intl.NumberFormat(langOf(el), { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Ungültiger lang-Wert - Browser-Standardsprache statt gar keiner Formatierung.
|
|
60
|
+
return new Intl.NumberFormat(undefined, { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Dauer aus --ncss-count-duration ("2s"/"1500ms"), Default 2 s wie im CSS.
|
|
65
|
+
function duration(el) {
|
|
66
|
+
var raw = getComputedStyle(el).getPropertyValue("--ncss-count-duration").trim();
|
|
67
|
+
var n = parseFloat(raw);
|
|
68
|
+
if (isNaN(n)) return 2000;
|
|
69
|
+
return /ms$/.test(raw) ? n : n * 1000;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Nähert --ncss-motion-easing-emphasized an (schneller Start, sanftes Auslaufen).
|
|
73
|
+
function ease(t) {
|
|
74
|
+
return 1 - Math.pow(1 - t, 3);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function run(el) {
|
|
78
|
+
var cs = getComputedStyle(el);
|
|
79
|
+
var toRaw = cs.getPropertyValue("--ncss-count-to").trim();
|
|
80
|
+
if (!toRaw) {
|
|
81
|
+
var parsed = parseInt(el.textContent.replace(/[^\d-]/g, ""), 10);
|
|
82
|
+
if (isNaN(parsed)) return;
|
|
83
|
+
toRaw = String(parsed);
|
|
84
|
+
el.style.setProperty("--ncss-count-to", parsed);
|
|
85
|
+
}
|
|
86
|
+
var to = parseFloat(toRaw);
|
|
87
|
+
if (isNaN(to)) return;
|
|
88
|
+
var from = parseFloat(cs.getPropertyValue("--ncss-count-from")) || 0;
|
|
89
|
+
var decAttr = parseInt(el.getAttribute("data-ncss-count-decimals"), 10);
|
|
90
|
+
var decimals = !isNaN(decAttr) ? decAttr : (toRaw.split(".")[1] || "").length;
|
|
91
|
+
var fmt = formatter(el, decimals);
|
|
92
|
+
var ms = duration(el);
|
|
93
|
+
var start = null;
|
|
94
|
+
|
|
95
|
+
el.setAttribute("data-ncss-count-text", fmt.format(from));
|
|
96
|
+
el.classList.add("ncss-count-up--js");
|
|
97
|
+
|
|
98
|
+
function frame(now) {
|
|
99
|
+
if (start === null) start = now;
|
|
100
|
+
var t = Math.min(1, (now - start) / ms);
|
|
101
|
+
el.setAttribute("data-ncss-count-text", fmt.format(from + (to - from) * ease(t)));
|
|
102
|
+
if (t < 1) {
|
|
103
|
+
requestAnimationFrame(frame);
|
|
104
|
+
} else {
|
|
105
|
+
el.classList.add("is-counted");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var io = new IntersectionObserver(
|
|
110
|
+
function (entries) {
|
|
111
|
+
entries.forEach(function (entry) {
|
|
112
|
+
if (!entry.isIntersecting) return;
|
|
113
|
+
io.disconnect();
|
|
114
|
+
el.classList.add("is-counting");
|
|
115
|
+
requestAnimationFrame(frame);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
{ rootMargin: "0px 0px -15% 0px" }
|
|
119
|
+
);
|
|
120
|
+
io.observe(el);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Dynamische Inhalte (htmx, fetch+innerHTML, REDAXO-Frontend-Editing): scan() ist
|
|
124
|
+
// idempotent - bereits verarbeitete Zahlen merkt sich ein WeakSet, bewusst KEIN
|
|
125
|
+
// data-Attribut (per innerHTML kopiertes Markup trüge sonst eine veraltete Markierung
|
|
126
|
+
// mit und würde nie gestartet).
|
|
127
|
+
var seen = new WeakSet();
|
|
128
|
+
function scan(root) {
|
|
129
|
+
if (!root || !root.querySelectorAll) return;
|
|
130
|
+
var hosts = Array.prototype.slice.call(root.querySelectorAll(SELECTOR));
|
|
131
|
+
if (root.matches && root.matches(SELECTOR)) hosts.unshift(root);
|
|
132
|
+
// Ein Element INNERHALB eines [data-ncss-count-up]-Vorfahren, der selbst neu ist.
|
|
133
|
+
if (root.closest && root.classList && root.classList.contains("ncss-count-up") && root.closest(SELECTOR)) hosts.push(root);
|
|
134
|
+
hosts.forEach(function (host) {
|
|
135
|
+
var nums = host.classList.contains("ncss-count-up")
|
|
136
|
+
? [host]
|
|
137
|
+
: Array.prototype.slice.call(host.querySelectorAll(".ncss-count-up"));
|
|
138
|
+
nums.forEach(function (el) {
|
|
139
|
+
if (seen.has(el)) return;
|
|
140
|
+
seen.add(el);
|
|
141
|
+
run(el);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
scan(document);
|
|
147
|
+
document.addEventListener("ncss-content-change", function (event) {
|
|
148
|
+
scan((event.detail && event.detail.root) || document);
|
|
149
|
+
});
|
|
150
|
+
})();
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - <ncss-countdown>: Restzeit bis zu einem Zeitpunkt (Markup/Optik siehe
|
|
3
|
+
* components/countdown.css). Reines Light-DOM-Custom-Element.
|
|
4
|
+
*
|
|
5
|
+
* Ohne JS bleibt der Inhalt stehen, den das Markup mitbringt - ein normales <time> mit
|
|
6
|
+
* dem ausgeschriebenen Datum ("24. Dezember 2026, 18 Uhr"), immer lesbar und korrekt.
|
|
7
|
+
* Mit JS: sichtbare Ziffern-Kacheln (aria-hidden, sie ticken jede Sekunde) + eine
|
|
8
|
+
* Screenreader-Zeile mit role="timer" (ARIA: implizit aria-live="off"), die nur
|
|
9
|
+
* MINÜTLICH neu geschrieben wird - jederzeit lesbar, aber nie ungefragt vorgelesen (eine
|
|
10
|
+
* Sekunden-Ansage wäre unbenutzbar). Ansagen laufen über eine ZWEITE, von Anfang an
|
|
11
|
+
* leere role="status"-Region (eine Live-Region erst nachträglich auf "polite" umzustellen
|
|
12
|
+
* ist in Screenreadern unzuverlässig):
|
|
13
|
+
* - data-ncss-announce="minute": dort zusätzlich minütlich der neue Stand.
|
|
14
|
+
* - Das ENDE wird immer angesagt.
|
|
15
|
+
*
|
|
16
|
+
* Attribute:
|
|
17
|
+
* datetime="2026-12-24T18:00:00+01:00" Zielzeitpunkt (Pflicht, ISO 8601; ohne Zone =
|
|
18
|
+
* lokale Zeit des Besuchers)
|
|
19
|
+
* data-ncss-units="days hours minutes seconds" sichtbare Einheiten (Default alle)
|
|
20
|
+
* data-ncss-done-text="Jetzt live!" Text nach Ablauf (Default: "Abgelaufen")
|
|
21
|
+
* Einheiten-Beschriftung + Zahlenformat kommen aus Intl.NumberFormat (style "unit") nach
|
|
22
|
+
* lang des Elements/der Seite - "Tage"/"days" ohne eigene Übersetzungstabelle.
|
|
23
|
+
*
|
|
24
|
+
* Event: "ncss-countdown-end" (bubbles), nur wenn der Zeitpunkt WÄHREND des Besuchs
|
|
25
|
+
* erreicht wird - ist er beim Laden schon vorbei, zeigt das Element still den Endzustand
|
|
26
|
+
* (sonst feuerte jede spätere Seitenansicht erneut z.B. eine Benachrichtigung).
|
|
27
|
+
* Endzustand zusätzlich als Attribut data-ncss-ended (für CSS).
|
|
28
|
+
*/
|
|
29
|
+
(function () {
|
|
30
|
+
"use strict";
|
|
31
|
+
|
|
32
|
+
if (typeof customElements === "undefined" || customElements.get("ncss-countdown")) return;
|
|
33
|
+
if (typeof Intl === "undefined" || typeof Intl.NumberFormat !== "function") return;
|
|
34
|
+
|
|
35
|
+
var UNIT = { days: ["day", 86400], hours: ["hour", 3600], minutes: ["minute", 60], seconds: ["second", 1] };
|
|
36
|
+
var TEXT = {
|
|
37
|
+
de: { left: "Noch {t}", done: "Abgelaufen" },
|
|
38
|
+
en: { left: "{t} left", done: "Time is up" }
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function langOf(el) {
|
|
42
|
+
var host = el.closest("[lang]");
|
|
43
|
+
return (host && host.getAttribute("lang")) || document.documentElement.lang || "en";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
customElements.define(
|
|
47
|
+
"ncss-countdown",
|
|
48
|
+
class extends HTMLElement {
|
|
49
|
+
connectedCallback() {
|
|
50
|
+
if (this._timer) return;
|
|
51
|
+
var target = Date.parse(this.getAttribute("datetime") || "");
|
|
52
|
+
if (isNaN(target)) return;
|
|
53
|
+
this._target = target;
|
|
54
|
+
this._lang = langOf(this);
|
|
55
|
+
this._text = TEXT[this._lang.slice(0, 2)] || TEXT.en;
|
|
56
|
+
var wanted = (this.getAttribute("data-ncss-units") || "days hours minutes seconds").split(/\s+/);
|
|
57
|
+
this._units = wanted.filter(function (u) { return UNIT[u]; });
|
|
58
|
+
if (!this._units.length) this._units = ["days", "hours", "minutes", "seconds"];
|
|
59
|
+
|
|
60
|
+
if (!this._built) this._build();
|
|
61
|
+
this._lastMinute = null;
|
|
62
|
+
this._ended = Date.now() >= target;
|
|
63
|
+
this._tick(true);
|
|
64
|
+
if (!this._ended) {
|
|
65
|
+
var self = this;
|
|
66
|
+
this._timer = setInterval(function () { self._tick(false); }, 1000);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
disconnectedCallback() {
|
|
71
|
+
clearInterval(this._timer);
|
|
72
|
+
this._timer = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_build() {
|
|
76
|
+
var self = this;
|
|
77
|
+
this._built = true;
|
|
78
|
+
// Originalinhalt (z.B. <time>) bleibt für Screenreader als Kontext erhalten -
|
|
79
|
+
// nur optisch versteckt, er nennt das absolute Datum zusätzlich zur Restzeit.
|
|
80
|
+
var original = document.createElement("span");
|
|
81
|
+
original.className = "ncss-countdown-fallback";
|
|
82
|
+
while (this.firstChild) original.appendChild(this.firstChild);
|
|
83
|
+
|
|
84
|
+
this._visual = document.createElement("span");
|
|
85
|
+
this._visual.className = "ncss-countdown-units";
|
|
86
|
+
this._visual.setAttribute("aria-hidden", "true");
|
|
87
|
+
this._cells = {};
|
|
88
|
+
this._units.forEach(function (u) {
|
|
89
|
+
var cell = document.createElement("span");
|
|
90
|
+
cell.className = "ncss-countdown-unit";
|
|
91
|
+
var value = document.createElement("span");
|
|
92
|
+
value.className = "ncss-countdown-value";
|
|
93
|
+
var label = document.createElement("span");
|
|
94
|
+
label.className = "ncss-countdown-label";
|
|
95
|
+
cell.append(value, label);
|
|
96
|
+
self._visual.appendChild(cell);
|
|
97
|
+
self._cells[u] = { value: value, label: label };
|
|
98
|
+
});
|
|
99
|
+
this._sr = document.createElement("span");
|
|
100
|
+
this._sr.className = "ncss-countdown-sr";
|
|
101
|
+
this._sr.setAttribute("role", "timer");
|
|
102
|
+
this._say = document.createElement("span");
|
|
103
|
+
this._say.className = "ncss-countdown-sr";
|
|
104
|
+
this._say.setAttribute("role", "status");
|
|
105
|
+
this._done = document.createElement("span");
|
|
106
|
+
this._done.className = "ncss-countdown-done";
|
|
107
|
+
this._done.setAttribute("aria-hidden", "true");
|
|
108
|
+
this._done.hidden = true;
|
|
109
|
+
this.append(this._visual, this._done, original, this._sr, this._say);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_parts(unit, n) {
|
|
113
|
+
// formatToParts trennt Zahl und Einheit sprachrichtig ("3 Tage", "1 day").
|
|
114
|
+
try {
|
|
115
|
+
var parts = new Intl.NumberFormat(this._lang, {
|
|
116
|
+
style: "unit", unit: UNIT[unit][0], unitDisplay: "long"
|
|
117
|
+
}).formatToParts(n);
|
|
118
|
+
var num = "", label = "";
|
|
119
|
+
parts.forEach(function (p) {
|
|
120
|
+
if (p.type === "integer" || p.type === "group") num += p.value;
|
|
121
|
+
else if (p.type === "unit") label += p.value;
|
|
122
|
+
});
|
|
123
|
+
return { num: num, label: label, full: parts.map(function (p) { return p.value; }).join("") };
|
|
124
|
+
} catch (e) {
|
|
125
|
+
return { num: String(n), label: unit, full: n + " " + unit };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_tick(initial) {
|
|
130
|
+
var self = this;
|
|
131
|
+
var rest = Math.max(0, Math.round((this._target - Date.now()) / 1000));
|
|
132
|
+
var spoken = [];
|
|
133
|
+
var remaining = rest;
|
|
134
|
+
this._units.forEach(function (u, i) {
|
|
135
|
+
var size = UNIT[u][1];
|
|
136
|
+
// Größte gewählte Einheit nimmt den ganzen Rest auf (z.B. 40 Stunden ohne "days").
|
|
137
|
+
var n = Math.floor(remaining / size);
|
|
138
|
+
remaining -= n * size;
|
|
139
|
+
var p = self._parts(u, n);
|
|
140
|
+
var cell = self._cells[u];
|
|
141
|
+
cell.value.textContent = i === 0 ? p.num : p.num.padStart(2, "0");
|
|
142
|
+
cell.label.textContent = p.label;
|
|
143
|
+
if (size >= 60 || self._units.length === 1) spoken.push(p.full);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (rest <= 0) {
|
|
147
|
+
this._finish(initial);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// Screenreader-Zeile nur minütlich neu schreiben (bei reinen Sekunden-Countdowns
|
|
151
|
+
// ohne größere Einheit: bei jeder vollen Minute bzw. am Anfang).
|
|
152
|
+
var minute = Math.floor(rest / 60);
|
|
153
|
+
if (minute !== this._lastMinute) {
|
|
154
|
+
this._lastMinute = minute;
|
|
155
|
+
var list = rest < 60 || !spoken.length ? [this._parts("seconds", rest).full] : spoken;
|
|
156
|
+
var joined;
|
|
157
|
+
try {
|
|
158
|
+
joined = new Intl.ListFormat(this._lang, { style: "long", type: "unit" }).format(list);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
joined = list.join(", ");
|
|
161
|
+
}
|
|
162
|
+
this._sr.textContent = this._text.left.replace("{t}", joined);
|
|
163
|
+
if (!initial && this.getAttribute("data-ncss-announce") === "minute") this._say.textContent = this._sr.textContent;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
_finish(initial) {
|
|
168
|
+
clearInterval(this._timer);
|
|
169
|
+
this._timer = null;
|
|
170
|
+
var text = this.getAttribute("data-ncss-done-text") || this._text.done;
|
|
171
|
+
this._done.textContent = text;
|
|
172
|
+
this._done.hidden = false;
|
|
173
|
+
this._visual.hidden = true;
|
|
174
|
+
this.setAttribute("data-ncss-ended", "");
|
|
175
|
+
// Ende während des Besuchs: höflich ansagen, egal welcher Ansage-Modus.
|
|
176
|
+
this._sr.textContent = text;
|
|
177
|
+
if (!initial) this._say.textContent = text;
|
|
178
|
+
if (!initial && !this._ended) {
|
|
179
|
+
this._ended = true;
|
|
180
|
+
this.dispatchEvent(new CustomEvent("ncss-countdown-end", { bubbles: true }));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
})();
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - "Klick daneben schließt" (Light Dismiss) für ncss-Dialoge: .ncss-modal,
|
|
3
|
+
* .ncss-offcanvas (inkl. Nav-Panel), .ncss-command (Befehlspalette), Lightbox.
|
|
4
|
+
*
|
|
5
|
+
* Nativ heißt das <dialog closedby="any">: Klick auf den Backdrop UND Esc schließen. Dieses
|
|
6
|
+
* Script macht das zum DEFAULT, ohne dass jedes Markup das Attribut tragen muss:
|
|
7
|
+
* (a) jeder passende <dialog> OHNE closedby-Attribut bekommt closedby="any" - beim Laden,
|
|
8
|
+
* bei ncss-content-change (detail.root) und spätestens beim Öffnen (toggle-Event),
|
|
9
|
+
* egal ob per command="show-modal", showModal() oder js/command-fallback.js;
|
|
10
|
+
* (b) Browser ohne closedby (HTMLDialogElement.prototype.closedBy fehlt): dasselbe
|
|
11
|
+
* Verhalten emuliert - pointerdown UND click müssen beide AUSSERHALB der Panel-Box
|
|
12
|
+
* auf dem Dialog selbst (= Backdrop) liegen. Eine Textmarkierung, die im Panel
|
|
13
|
+
* beginnt und daneben endet, schließt dadurch NICHT. Geschlossen wird per
|
|
14
|
+
* requestClose() (feuert "cancel" - event.preventDefault() hält den Dialog offen),
|
|
15
|
+
* ohne requestClose ein selbst gefeuertes, abbrechbares "cancel" + close().
|
|
16
|
+
*
|
|
17
|
+
* Abschalten pro Dialog - einfach das native Attribut selbst setzen, das Script fasst einen
|
|
18
|
+
* Dialog MIT closedby nie an:
|
|
19
|
+
* closedby="closerequest" nur Esc + Buttons (kein Klick daneben)
|
|
20
|
+
* closedby="none" nur Buttons (z.B. lange Formulare; im Emulations-Pfad wird
|
|
21
|
+
* dann auch Esc abgefangen)
|
|
22
|
+
*
|
|
23
|
+
* Fokus: der Browser gibt ihn beim Schließen eines per showModal() geöffneten Dialogs
|
|
24
|
+
* selbst an den Auslöser zurück - unabhängig davon, wie geschlossen wurde.
|
|
25
|
+
*
|
|
26
|
+
* Abhängigkeiten: keine anderen ncss-Scripts. Ohne <dialog>-Unterstützung tut es nichts.
|
|
27
|
+
*/
|
|
28
|
+
(function () {
|
|
29
|
+
"use strict";
|
|
30
|
+
|
|
31
|
+
if (typeof HTMLDialogElement !== "function" || window.ncssDialogLightDismissLoaded) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
window.ncssDialogLightDismissLoaded = true;
|
|
35
|
+
|
|
36
|
+
var SELECTOR = "dialog.ncss-modal, dialog.ncss-offcanvas, dialog.ncss-command, dialog.ncss-lightbox";
|
|
37
|
+
var native = "closedBy" in HTMLDialogElement.prototype;
|
|
38
|
+
var done = typeof WeakSet === "function" ? new WeakSet() : null;
|
|
39
|
+
|
|
40
|
+
function mark(dialog) {
|
|
41
|
+
if (done && done.has(dialog)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (done) {
|
|
45
|
+
done.add(dialog);
|
|
46
|
+
}
|
|
47
|
+
if (!dialog.hasAttribute("closedby")) {
|
|
48
|
+
dialog.setAttribute("closedby", "any");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function scan(root) {
|
|
53
|
+
if (!root) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (root.matches && root.matches(SELECTOR)) {
|
|
57
|
+
mark(root);
|
|
58
|
+
}
|
|
59
|
+
if (root.querySelectorAll) {
|
|
60
|
+
Array.prototype.forEach.call(root.querySelectorAll(SELECTOR), mark);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Spätestens beim Öffnen - erfasst auch Dialoge, die ohne ncss-content-change eingefügt
|
|
65
|
+
// wurden (toggle bubbelt nicht, daher in der Capture-Phase am document).
|
|
66
|
+
document.addEventListener("toggle", function (event) {
|
|
67
|
+
var d = event.target;
|
|
68
|
+
if (d && d.matches && d.matches(SELECTOR)) {
|
|
69
|
+
mark(d);
|
|
70
|
+
}
|
|
71
|
+
}, true);
|
|
72
|
+
|
|
73
|
+
if (!native) {
|
|
74
|
+
var mode = function (dialog) {
|
|
75
|
+
return (dialog.getAttribute("closedby") || "any").toLowerCase();
|
|
76
|
+
};
|
|
77
|
+
var outside = function (dialog, event) {
|
|
78
|
+
var r = dialog.getBoundingClientRect();
|
|
79
|
+
return event.clientX < r.left || event.clientX > r.right ||
|
|
80
|
+
event.clientY < r.top || event.clientY > r.bottom;
|
|
81
|
+
};
|
|
82
|
+
var downOn = null;
|
|
83
|
+
|
|
84
|
+
document.addEventListener("pointerdown", function (event) {
|
|
85
|
+
var d = event.target;
|
|
86
|
+
downOn = d && d.matches && d.matches(SELECTOR) && d.open && mode(d) === "any" &&
|
|
87
|
+
outside(d, event) ? d : null;
|
|
88
|
+
}, true);
|
|
89
|
+
|
|
90
|
+
document.addEventListener("click", function (event) {
|
|
91
|
+
var d = downOn;
|
|
92
|
+
downOn = null;
|
|
93
|
+
if (!d || event.target !== d || !d.open || !outside(d, event)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (typeof d.requestClose === "function") {
|
|
97
|
+
d.requestClose();
|
|
98
|
+
} else if (d.dispatchEvent(new Event("cancel", { cancelable: true }))) {
|
|
99
|
+
d.close();
|
|
100
|
+
}
|
|
101
|
+
}, true);
|
|
102
|
+
|
|
103
|
+
// closedby="none": auch Esc darf dann nicht schließen.
|
|
104
|
+
document.addEventListener("cancel", function (event) {
|
|
105
|
+
var d = event.target;
|
|
106
|
+
if (d && d.matches && d.matches("dialog[closedby='none' i]")) {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
}
|
|
109
|
+
}, true);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function start() {
|
|
113
|
+
scan(document);
|
|
114
|
+
}
|
|
115
|
+
if (document.readyState === "loading") {
|
|
116
|
+
document.addEventListener("DOMContentLoaded", start);
|
|
117
|
+
} else {
|
|
118
|
+
start();
|
|
119
|
+
}
|
|
120
|
+
document.addEventListener("ncss-content-change", function (event) {
|
|
121
|
+
scan((event.detail && event.detail.root) || document);
|
|
122
|
+
});
|
|
123
|
+
})();
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - Generisches "Schließen/Entfernen" für Alerts, Tags/Chips und alles andere mit
|
|
3
|
+
* [data-ncss-dismissible] (siehe components/alert.css, components/tag.css).
|
|
4
|
+
*
|
|
5
|
+
* Markup:
|
|
6
|
+
* <div class="ncss-alert" data-ncss-dismissible> ...
|
|
7
|
+
* <button type="button" data-ncss-dismiss aria-label="Hinweis schließen"></button>
|
|
8
|
+
* </div>
|
|
9
|
+
* <button data-ncss-dismiss="#banner">...</button> Ziel per Selektor statt Vorfahre
|
|
10
|
+
* data-ncss-dismissible="hide" nur verstecken (hidden) statt
|
|
11
|
+
* aus dem DOM entfernen
|
|
12
|
+
* data-ncss-dismiss-focus="#selector" (am Ziel) Fokus-Ziel danach
|
|
13
|
+
*
|
|
14
|
+
* Fokus (WCAG 2.4.3): lag der Fokus im entfernten Element, landet er nicht im Nichts
|
|
15
|
+
* (document.body), sondern auf dem nächsten Geschwister-Ziel gleicher Art (dessen
|
|
16
|
+
* Schließen-Button - z.B. der nächste Tag in einer Liste), sonst dem vorherigen, sonst auf
|
|
17
|
+
* data-ncss-dismiss-focus, sonst auf dem Eltern-Element (tabindex="-1" wird dafür gesetzt).
|
|
18
|
+
*
|
|
19
|
+
* Event (am Ziel, bubbelt, abbrechbar): ncss-dismiss-remove, detail { trigger } -
|
|
20
|
+
* event.preventDefault() verhindert das Entfernen (z.B. erst Server-Request abwarten).
|
|
21
|
+
*
|
|
22
|
+
* Ohne JS: der Button tut nichts. Wer keinen toten Button zeigen will, setzt hidden auf
|
|
23
|
+
* den Button - das Script entfernt es (beim Laden und bei ncss-content-change).
|
|
24
|
+
*
|
|
25
|
+
* Dynamische Inhalte: Klick-Delegation am document - nachgeladene Elemente funktionieren
|
|
26
|
+
* ohne weiteres Zutun. Nur das hidden-Entfernen an neuen Buttons läuft über scan(root) +
|
|
27
|
+
* ncss-content-change (detail.root).
|
|
28
|
+
*
|
|
29
|
+
* Abhängigkeiten: keine anderen ncss-Scripts.
|
|
30
|
+
*/
|
|
31
|
+
(function () {
|
|
32
|
+
"use strict";
|
|
33
|
+
|
|
34
|
+
if (!document.addEventListener || !Element.prototype.closest || window.ncssDismissLoaded) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
window.ncssDismissLoaded = true;
|
|
38
|
+
|
|
39
|
+
var SELECTOR = "[data-ncss-dismiss]";
|
|
40
|
+
|
|
41
|
+
function scan(root) {
|
|
42
|
+
var list = [];
|
|
43
|
+
if (root.matches && root.matches(SELECTOR)) {
|
|
44
|
+
list.push(root);
|
|
45
|
+
}
|
|
46
|
+
if (root.querySelectorAll) {
|
|
47
|
+
list = list.concat(Array.prototype.slice.call(root.querySelectorAll(SELECTOR)));
|
|
48
|
+
}
|
|
49
|
+
list.forEach(function (btn) {
|
|
50
|
+
if (btn.hidden) {
|
|
51
|
+
btn.hidden = false;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function targetOf(btn) {
|
|
57
|
+
var sel = btn.getAttribute("data-ncss-dismiss");
|
|
58
|
+
if (sel) {
|
|
59
|
+
try { return document.querySelector(sel); } catch (e) { return null; }
|
|
60
|
+
}
|
|
61
|
+
return btn.closest("[data-ncss-dismissible]");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Die "Einheit" in einer Liste: der Tag selbst oder sein <li>, falls er allein darin steckt.
|
|
65
|
+
function unitOf(target) {
|
|
66
|
+
var p = target.parentElement;
|
|
67
|
+
return p && p.tagName === "LI" && p.children.length === 1 ? p : target;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function focusAfter(target) {
|
|
71
|
+
var unit = unitOf(target);
|
|
72
|
+
var pick = function (el) {
|
|
73
|
+
return el.matches(SELECTOR) ? el : el.querySelector(SELECTOR);
|
|
74
|
+
};
|
|
75
|
+
var el = unit.nextElementSibling;
|
|
76
|
+
while (el && !pick(el)) { el = el.nextElementSibling; }
|
|
77
|
+
if (!el) {
|
|
78
|
+
el = unit.previousElementSibling;
|
|
79
|
+
while (el && !pick(el)) { el = el.previousElementSibling; }
|
|
80
|
+
}
|
|
81
|
+
if (el) {
|
|
82
|
+
return pick(el);
|
|
83
|
+
}
|
|
84
|
+
var sel = target.getAttribute("data-ncss-dismiss-focus");
|
|
85
|
+
if (sel) {
|
|
86
|
+
try {
|
|
87
|
+
var explicit = document.querySelector(sel);
|
|
88
|
+
if (explicit) {
|
|
89
|
+
return explicit;
|
|
90
|
+
}
|
|
91
|
+
} catch (e) { /* ungültiger Selektor */ }
|
|
92
|
+
}
|
|
93
|
+
var parent = unit.parentElement;
|
|
94
|
+
while (parent && parent.matches("ul, ol, li")) {
|
|
95
|
+
parent = parent.parentElement;
|
|
96
|
+
}
|
|
97
|
+
return parent;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
document.addEventListener("click", function (event) {
|
|
101
|
+
var btn = event.target.closest(SELECTOR);
|
|
102
|
+
if (!btn) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
var target = targetOf(btn);
|
|
106
|
+
if (!target) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
var proceed = target.dispatchEvent(new CustomEvent("ncss-dismiss-remove", {
|
|
111
|
+
bubbles: true,
|
|
112
|
+
cancelable: true,
|
|
113
|
+
detail: { trigger: btn }
|
|
114
|
+
}));
|
|
115
|
+
if (!proceed) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var hadFocus = target.contains(document.activeElement);
|
|
119
|
+
var focusTarget = hadFocus ? focusAfter(target) : null;
|
|
120
|
+
if (target.getAttribute("data-ncss-dismissible") === "hide") {
|
|
121
|
+
target.hidden = true;
|
|
122
|
+
} else {
|
|
123
|
+
unitOf(target).remove();
|
|
124
|
+
}
|
|
125
|
+
if (focusTarget) {
|
|
126
|
+
if (!focusTarget.matches("a[href], button, input, select, textarea, [tabindex]")) {
|
|
127
|
+
focusTarget.setAttribute("tabindex", "-1");
|
|
128
|
+
}
|
|
129
|
+
focusTarget.focus();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
function start() {
|
|
134
|
+
scan(document);
|
|
135
|
+
}
|
|
136
|
+
if (document.readyState === "loading") {
|
|
137
|
+
document.addEventListener("DOMContentLoaded", start);
|
|
138
|
+
} else {
|
|
139
|
+
start();
|
|
140
|
+
}
|
|
141
|
+
document.addEventListener("ncss-content-change", function (event) {
|
|
142
|
+
scan((event.detail && event.detail.root) || document);
|
|
143
|
+
});
|
|
144
|
+
})();
|