@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,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - Backdrop: wechselt die Bilder von [data-ncss-backdrop] im Intervall
|
|
3
|
+
* (data-interval in ms, Default 6000). Kleines Opt-in-Enhancement zu
|
|
4
|
+
* components/backdrop.css - ohne dieses Script bleibt das erste Bild stehen.
|
|
5
|
+
*
|
|
6
|
+
* - lädt das jeweils nächste Bild vor (loading="lazy" -> "eager"), blendet erst ein,
|
|
7
|
+
* wenn es geladen ist - kein Überblenden auf eine leere Fläche
|
|
8
|
+
* - pausiert in Hintergrund-Tabs (visibilitychange) statt Bilder ungesehen zu laden
|
|
9
|
+
* - bei prefers-reduced-motion: kein automatischer Wechsel, nur das erste Bild
|
|
10
|
+
* - setzt --ncss-backdrop-duration passend zum Intervall (Zoom läuft über die Überblendung
|
|
11
|
+
* hinaus weiter, sonst "springt" der Zoom beim Wechsel)
|
|
12
|
+
*/
|
|
13
|
+
(function () {
|
|
14
|
+
"use strict";
|
|
15
|
+
// Bewegung reduzieren? Systemeinstellung ODER ausdrückliche Wahl am <html>
|
|
16
|
+
// (data-motion="reduce"/"full", gesetzt von js/preferences.js) - "full" hebt ein
|
|
17
|
+
// System-"reduce" nur als bewusste Nutzerwahl auf, nie von selbst.
|
|
18
|
+
function ncssReducedMotion() {
|
|
19
|
+
var choice = document.documentElement.getAttribute("data-motion");
|
|
20
|
+
if (choice === "reduce") return true;
|
|
21
|
+
if (choice === "full") return false;
|
|
22
|
+
return !!(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function init(root) {
|
|
26
|
+
var items = Array.prototype.slice.call(root.querySelectorAll(".ncss-backdrop-item"));
|
|
27
|
+
if (items.length === 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Per innerHTML kopiertes, bereits laufendes Markup kann einen veralteten Zustand
|
|
31
|
+
// mitbringen (is-active auf einem späteren Bild) - immer vom ersten Bild aus starten.
|
|
32
|
+
items.forEach(function (item) { item.classList.remove("is-active"); });
|
|
33
|
+
var interval = parseInt(root.getAttribute("data-interval"), 10) || 6000;
|
|
34
|
+
root.style.setProperty("--ncss-backdrop-duration", interval + 2000 + "ms");
|
|
35
|
+
root.setAttribute("data-ready", "");
|
|
36
|
+
items[0].classList.add("is-active");
|
|
37
|
+
|
|
38
|
+
if (items.length < 2 || ncssReducedMotion()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var index = 0;
|
|
43
|
+
var timer = null;
|
|
44
|
+
|
|
45
|
+
function preload(item) {
|
|
46
|
+
if (item.loading === "lazy") {
|
|
47
|
+
item.loading = "eager";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
preload(items[1]);
|
|
51
|
+
|
|
52
|
+
function next() {
|
|
53
|
+
// Element wurde entfernt (htmx-Swap, Frontend-Editing) - Timer nicht ewig weiterlaufen lassen.
|
|
54
|
+
if (!root.isConnected) {
|
|
55
|
+
stop();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
var current = items[index];
|
|
59
|
+
index = (index + 1) % items.length;
|
|
60
|
+
var upcoming = items[index];
|
|
61
|
+
function show() {
|
|
62
|
+
upcoming.classList.add("is-active");
|
|
63
|
+
current.classList.remove("is-active");
|
|
64
|
+
preload(items[(index + 1) % items.length]);
|
|
65
|
+
}
|
|
66
|
+
if (upcoming.complete) {
|
|
67
|
+
show();
|
|
68
|
+
} else {
|
|
69
|
+
upcoming.addEventListener("load", show, { once: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function start() {
|
|
73
|
+
if (!timer) {
|
|
74
|
+
timer = window.setInterval(next, interval);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function stop() {
|
|
78
|
+
window.clearInterval(timer);
|
|
79
|
+
timer = null;
|
|
80
|
+
}
|
|
81
|
+
document.addEventListener("visibilitychange", function () {
|
|
82
|
+
if (document.hidden) {
|
|
83
|
+
stop();
|
|
84
|
+
} else {
|
|
85
|
+
start();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
start();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Dynamische Inhalte (htmx, fetch+innerHTML, REDAXO-Frontend-Editing): scan() ist
|
|
92
|
+
// idempotent - bereits verarbeitete Elemente merkt sich ein WeakSet, bewusst KEIN
|
|
93
|
+
// data-Attribut (per innerHTML kopiertes Markup trüge sonst eine veraltete Markierung
|
|
94
|
+
// mit). Läuft beim Laden und bei jedem "ncss-content-change"-Event (detail.root = neu
|
|
95
|
+
// eingefügtes Element, ohne Angabe das ganze Dokument), siehe js/content-observer.js.
|
|
96
|
+
var SELECTOR = "[data-ncss-backdrop]";
|
|
97
|
+
var seen = new WeakSet();
|
|
98
|
+
function scan(root) {
|
|
99
|
+
if (!root || !root.querySelectorAll) return;
|
|
100
|
+
var list = Array.prototype.slice.call(root.querySelectorAll(SELECTOR));
|
|
101
|
+
if (root.matches && root.matches(SELECTOR)) list.unshift(root);
|
|
102
|
+
list.forEach(function (el) {
|
|
103
|
+
if (seen.has(el)) return;
|
|
104
|
+
seen.add(el);
|
|
105
|
+
init(el);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
document.addEventListener("ncss-content-change", function (event) {
|
|
109
|
+
scan((event.detail && event.detail.root) || document);
|
|
110
|
+
});
|
|
111
|
+
function scanDocument() {
|
|
112
|
+
scan(document);
|
|
113
|
+
}
|
|
114
|
+
if (document.readyState === "loading") {
|
|
115
|
+
document.addEventListener("DOMContentLoaded", scanDocument);
|
|
116
|
+
} else {
|
|
117
|
+
scanDocument();
|
|
118
|
+
}
|
|
119
|
+
})();
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - Code-Block: ruft das self-hosted Prism.js (vendor/prismjs/) einmal
|
|
3
|
+
* kontrolliert auf (statt Prisms eigenem, unkontrolliertem DOMContentLoaded-Autostart -
|
|
4
|
+
* siehe code-block.css für die dafür nötige "window.Prism = { manual: true }"-Zeile VOR
|
|
5
|
+
* dem Laden von prism-core) und ergänzt jeden gefundenen Code-Block danach um einen
|
|
6
|
+
* Copy-to-Clipboard-Button. Läuft auch ohne Prism (z.B. falls nur der Copy-Button
|
|
7
|
+
* gebraucht wird, ohne die Prism-Scripts einzubinden) - Highlighting wird dann einfach
|
|
8
|
+
* übersprungen, der Rohtext bleibt unhighlighted, aber kopierbar.
|
|
9
|
+
*
|
|
10
|
+
* deepQueryAll() statt document.querySelectorAll(): ein Code-Block INNERHALB eines
|
|
11
|
+
* <ncss-container> (siehe ncss-container.js) liegt in dessen Shadow Root -
|
|
12
|
+
* querySelectorAll() durchquert Shadow-Grenzen nicht. Aus demselben Grund wird
|
|
13
|
+
* Prism.highlightElement() PRO Block aufgerufen statt des document-globalen
|
|
14
|
+
* Prism.highlightAll() - highlightElement() arbeitet direkt auf dem übergebenen Element,
|
|
15
|
+
* unabhängig davon, wo es im DOM (oder Shadow-DOM-Baum) sitzt.
|
|
16
|
+
*/
|
|
17
|
+
(function () {
|
|
18
|
+
"use strict";
|
|
19
|
+
|
|
20
|
+
function deepQueryAll(selector, root) {
|
|
21
|
+
root = root || document;
|
|
22
|
+
var found = Array.prototype.slice.call(root.querySelectorAll(selector));
|
|
23
|
+
var all = root.querySelectorAll("*");
|
|
24
|
+
for (var i = 0; i < all.length; i++) {
|
|
25
|
+
if (all[i].shadowRoot) {
|
|
26
|
+
found = found.concat(deepQueryAll(selector, all[i].shadowRoot));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Prism erst beim jeweiligen Aufruf prüfen (nicht einmalig beim Laden) - ein später
|
|
33
|
+
// eingefügter Block soll auch dann hervorgehoben werden, wenn Prism nach diesem Script
|
|
34
|
+
// fertig geladen wurde.
|
|
35
|
+
function highlight(codeEl) {
|
|
36
|
+
if (window.Prism && typeof window.Prism.highlightElement === "function") {
|
|
37
|
+
window.Prism.highlightElement(codeEl);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Dynamische Inhalte (htmx, fetch+innerHTML, REDAXO-Frontend-Editing): scan() ist
|
|
42
|
+
// idempotent - bereits verarbeitete Elemente merkt sich ein WeakSet, bewusst KEIN
|
|
43
|
+
// data-Attribut (per innerHTML kopiertes Markup trüge sonst eine veraltete Markierung
|
|
44
|
+
// mit). Läuft beim Laden und bei jedem "ncss-content-change"-Event (detail.root = neu
|
|
45
|
+
// eingefügtes Element, ohne Angabe das ganze Dokument), siehe js/content-observer.js.
|
|
46
|
+
var SELECTOR = "pre > code[class*=\"language-\"]";
|
|
47
|
+
var seen = new WeakSet();
|
|
48
|
+
function scan(root) {
|
|
49
|
+
if (!root || !root.querySelectorAll) return;
|
|
50
|
+
var list = deepQueryAll(SELECTOR, root);
|
|
51
|
+
if (root.matches && root.matches(SELECTOR)) list.unshift(root);
|
|
52
|
+
list.forEach(function (el) {
|
|
53
|
+
if (seen.has(el)) return;
|
|
54
|
+
seen.add(el);
|
|
55
|
+
highlight(el);
|
|
56
|
+
addCopyButton(el);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Sprache der Beschriftung: nächstes lang-Attribut (Seite oder Abschnitt), Deutsch oder
|
|
61
|
+
// sonst Englisch.
|
|
62
|
+
function texts(el) {
|
|
63
|
+
var host = el.closest("[lang]");
|
|
64
|
+
var lang = ((host && host.getAttribute("lang")) || document.documentElement.lang || "en").toLowerCase();
|
|
65
|
+
return lang.indexOf("de") === 0
|
|
66
|
+
? { label: "Code kopieren", done: "Kopiert" }
|
|
67
|
+
: { label: "Copy code", done: "Copied" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Wählt den Platz-Modus (siehe code-block.css): ragt die breiteste Zeile in die
|
|
71
|
+
// Button-Fläche, bekommt der Button eine eigene Zeile über dem Code (.is-stacked). Die
|
|
72
|
+
// Entscheidung hängt nur an Zeilenbreite vs. verfügbarer Breite OHNE Reserve - nicht am
|
|
73
|
+
// aktuellen Modus, sonst könnte das Umschalten selbst wieder zurückschalten (Flattern).
|
|
74
|
+
var range = document.createRange ? document.createRange() : null;
|
|
75
|
+
function layout(pre, codeEl) {
|
|
76
|
+
var cs = getComputedStyle(pre);
|
|
77
|
+
var padStart = parseFloat(cs.paddingInlineStart || cs.paddingLeft) || 0;
|
|
78
|
+
var reserve = parseFloat(cs.getPropertyValue("--ncss-code-reserve")) || 0;
|
|
79
|
+
var probe = pre.querySelector(".ncss-code-copy");
|
|
80
|
+
if (probe) {
|
|
81
|
+
reserve = probe.offsetWidth + (parseFloat(getComputedStyle(probe).insetInlineEnd) || 0) * 2;
|
|
82
|
+
}
|
|
83
|
+
var avail = pre.clientWidth - padStart * 2;
|
|
84
|
+
var need = codeEl.scrollWidth;
|
|
85
|
+
if (range) {
|
|
86
|
+
range.selectNodeContents(codeEl);
|
|
87
|
+
need = range.getBoundingClientRect().width;
|
|
88
|
+
}
|
|
89
|
+
pre.classList.toggle("is-stacked", need > avail - reserve);
|
|
90
|
+
var scrollable = codeEl.scrollWidth > codeEl.clientWidth;
|
|
91
|
+
pre.classList.toggle("is-scrollable", scrollable);
|
|
92
|
+
// Scrollbarer Code muss per Tastatur erreichbar sein (WCAG 2.1.1, axe
|
|
93
|
+
// scrollable-region-focusable) - eigenes tabindex des Autors nie überschreiben.
|
|
94
|
+
if (scrollable && !codeEl.hasAttribute("tabindex")) {
|
|
95
|
+
codeEl.setAttribute("tabindex", "0");
|
|
96
|
+
codeEl.setAttribute("data-ncss-code-tabindex", "");
|
|
97
|
+
} else if (!scrollable && codeEl.hasAttribute("data-ncss-code-tabindex")) {
|
|
98
|
+
codeEl.removeAttribute("tabindex");
|
|
99
|
+
codeEl.removeAttribute("data-ncss-code-tabindex");
|
|
100
|
+
}
|
|
101
|
+
edges(pre, codeEl);
|
|
102
|
+
}
|
|
103
|
+
function edges(pre, codeEl) {
|
|
104
|
+
var max = codeEl.scrollWidth - codeEl.clientWidth;
|
|
105
|
+
var pos = Math.abs(codeEl.scrollLeft);
|
|
106
|
+
pre.classList.toggle("is-at-start", pos <= 1);
|
|
107
|
+
pre.classList.toggle("is-at-end", pos >= max - 1);
|
|
108
|
+
}
|
|
109
|
+
// Nur auf echte Breitenänderungen reagieren und erst im nächsten Frame umschalten: der
|
|
110
|
+
// Moduswechsel ändert selbst Padding/Höhe des <pre> - direkt im Callback umgesetzt, meldet
|
|
111
|
+
// WebKit sonst "ResizeObserver loop completed with undelivered notifications".
|
|
112
|
+
var widths = new WeakMap();
|
|
113
|
+
var observer = typeof ResizeObserver === "function" ? new ResizeObserver(function (entries) {
|
|
114
|
+
entries.forEach(function (entry) {
|
|
115
|
+
var pre = entry.target;
|
|
116
|
+
var w = pre.offsetWidth;
|
|
117
|
+
if (widths.get(pre) === w) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
widths.set(pre, w);
|
|
121
|
+
window.requestAnimationFrame(function () {
|
|
122
|
+
var codeEl = pre.querySelector(":scope > code");
|
|
123
|
+
if (codeEl) {
|
|
124
|
+
layout(pre, codeEl);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}) : null;
|
|
129
|
+
|
|
130
|
+
function addCopyButton(codeEl) {
|
|
131
|
+
var pre = codeEl.parentElement;
|
|
132
|
+
if (!pre) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Ein vorhandener Button stammt aus per innerHTML kopiertem Markup (ohne Listener) -
|
|
136
|
+
// ersetzen statt übernehmen. addCopyButton() läuft pro <code> nur einmal (siehe scan()).
|
|
137
|
+
Array.prototype.forEach.call(pre.querySelectorAll(":scope > .ncss-code-copy, :scope > .ncss-code-status"), function (old) {
|
|
138
|
+
old.remove();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
var t = texts(pre);
|
|
142
|
+
var button = document.createElement("button");
|
|
143
|
+
button.type = "button";
|
|
144
|
+
button.className = "ncss-code-copy";
|
|
145
|
+
button.setAttribute("aria-label", t.label);
|
|
146
|
+
button.innerHTML = '<span class="ncss-icon ncss-icon-copy" aria-hidden="true"></span>';
|
|
147
|
+
var status = document.createElement("span");
|
|
148
|
+
status.className = "ncss-code-status";
|
|
149
|
+
status.setAttribute("role", "status");
|
|
150
|
+
pre.classList.add("ncss-code-block");
|
|
151
|
+
pre.appendChild(button);
|
|
152
|
+
pre.appendChild(status);
|
|
153
|
+
|
|
154
|
+
button.addEventListener("click", function () {
|
|
155
|
+
copyText(codeEl.textContent, button, status, t);
|
|
156
|
+
});
|
|
157
|
+
codeEl.addEventListener("scroll", function () {
|
|
158
|
+
edges(pre, codeEl);
|
|
159
|
+
}, { passive: true });
|
|
160
|
+
layout(pre, codeEl);
|
|
161
|
+
if (observer) {
|
|
162
|
+
observer.observe(pre);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Webfonts ändern die Zeilenbreite nach dem ersten Layout - einmal neu messen.
|
|
167
|
+
if (document.fonts && document.fonts.ready) {
|
|
168
|
+
document.fonts.ready.then(function () {
|
|
169
|
+
relayoutAll();
|
|
170
|
+
});
|
|
171
|
+
// Später nachgeladene Schriften (z.B. eine per Darstellungs-Einstellung gewählte).
|
|
172
|
+
if (document.fonts.addEventListener) {
|
|
173
|
+
document.fonts.addEventListener("loadingdone", function () {
|
|
174
|
+
relayoutAll();
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function copyText(text, button, status, t) {
|
|
180
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
181
|
+
navigator.clipboard.writeText(text).then(function () {
|
|
182
|
+
showCopied(button, status, t);
|
|
183
|
+
}, function () {
|
|
184
|
+
fallbackCopy(text, button, status, t);
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
fallbackCopy(text, button, status, t);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function fallbackCopy(text, button, status, t) {
|
|
192
|
+
|
|
193
|
+
var textarea = document.createElement("textarea");
|
|
194
|
+
textarea.value = text;
|
|
195
|
+
textarea.style.position = "fixed";
|
|
196
|
+
textarea.style.opacity = "0";
|
|
197
|
+
document.body.appendChild(textarea);
|
|
198
|
+
textarea.select();
|
|
199
|
+
try {
|
|
200
|
+
document.execCommand("copy");
|
|
201
|
+
showCopied(button, status, t);
|
|
202
|
+
} finally {
|
|
203
|
+
document.body.removeChild(textarea);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function showCopied(button, status, t) {
|
|
208
|
+
button.setAttribute("data-copied", "true");
|
|
209
|
+
// Ansage über die eigene Status-Region (role="status") - Text erst leeren, dann
|
|
210
|
+
// setzen, damit auch ein zweites Kopieren direkt hintereinander angesagt wird.
|
|
211
|
+
status.textContent = "";
|
|
212
|
+
window.setTimeout(function () { status.textContent = t.done; }, 50);
|
|
213
|
+
button.innerHTML = '<span class="ncss-icon ncss-icon-check" aria-hidden="true"></span>';
|
|
214
|
+
window.setTimeout(function () {
|
|
215
|
+
button.removeAttribute("data-copied");
|
|
216
|
+
button.innerHTML = '<span class="ncss-icon ncss-icon-copy" aria-hidden="true"></span>';
|
|
217
|
+
status.textContent = "";
|
|
218
|
+
}, 1500);
|
|
219
|
+
}
|
|
220
|
+
// Darstellungs-Einstellungen (js/preferences.js: Schriftgröße, Textabstände, Schrift)
|
|
221
|
+
// ändern die Zeilenbreite, ohne dass sich die Breite des <pre> ändert - neu messen.
|
|
222
|
+
function relayoutAll() {
|
|
223
|
+
deepQueryAll("pre.ncss-code-block > code").forEach(function (codeEl) {
|
|
224
|
+
layout(codeEl.parentElement, codeEl);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
document.addEventListener("ncss-preferences-change", function () {
|
|
228
|
+
window.requestAnimationFrame(relayoutAll);
|
|
229
|
+
window.setTimeout(relayoutAll, 400);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Erst am Ende starten: range/observer oben sind var-Zuweisungen, die beim Hoisting noch
|
|
233
|
+
// undefined wären.
|
|
234
|
+
scan(document);
|
|
235
|
+
document.addEventListener("ncss-content-change", function (event) {
|
|
236
|
+
scan((event.detail && event.detail.root) || document);
|
|
237
|
+
});
|
|
238
|
+
})();
|