@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,477 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - <ncss-command-palette>: Befehlspalette (siehe components/command-palette.css für
|
|
3
|
+
* Markup). Light-DOM-Custom-Element ohne Shadow Root um einen <dialog class="ncss-command">.
|
|
4
|
+
* Filtert die .ncss-command-item-Einträge im Markup (Text + data-keywords, Groß-/Klein-
|
|
5
|
+
* schreibung und Akzente egal, alle Begriffe müssen vorkommen), blendet leere Gruppen aus,
|
|
6
|
+
* zeigt .ncss-command-empty bei 0 Treffern und sagt die Trefferzahl per Live-Region an.
|
|
7
|
+
*
|
|
8
|
+
* WAI-ARIA Combobox + Listbox (wie js/livesearch.js): Fokus bleibt im Eingabefeld,
|
|
9
|
+
* aria-activedescendant zeigt auf die gewählte Option.
|
|
10
|
+
* Tastatur: Pfeil runter/hoch (springt am Ende um), Pos1/Ende mit Strg, Enter führt die
|
|
11
|
+
* gewählte Option aus (Link folgt seinem href, Button wird geklickt), Esc schließt (nativer
|
|
12
|
+
* <dialog>). Mausbewegung über die Liste wählt mit.
|
|
13
|
+
*
|
|
14
|
+
* Attribute am Element:
|
|
15
|
+
* shortcut="k" opt-in Tastenkürzel: ⌘K auf Apple-Geräten, sonst Strg+K (öffnet/schließt)
|
|
16
|
+
* slash zusätzlich "/" als Kürzel (nur wenn gerade kein Eingabefeld Fokus hat)
|
|
17
|
+
* status-text="{n} Treffer" Ansage der Trefferzahl, Default nach <html lang>
|
|
18
|
+
* src="suche.json" opt-in SUCHMODUS für große Listen: die Einträge kommen aus einer
|
|
19
|
+
* JSON-Datei (beim ersten Öffnen geladen, kein Server nötig) und werden
|
|
20
|
+
* erst beim Tippen gerendert - gerankt, je Gruppe begrenzt, Treffer mit
|
|
21
|
+
* <mark> hervorgehoben. Format:
|
|
22
|
+
* { "groups": [{ "id": "pages", "label": "Seiten" }, ...],
|
|
23
|
+
* "items": [{ "g": "pages", "t": "Titel", "u": "de/seite.html#anker",
|
|
24
|
+
* "h": "Hinweis rechts", "s": "Textauszug", "k": "Stichwörter" }] }
|
|
25
|
+
* "u" gilt relativ zur JSON-Datei (dieselbe Liste funktioniert von jeder
|
|
26
|
+
* Seite aus). Einträge im Markup bleiben erhalten (z.B. als Vorschläge bei
|
|
27
|
+
* leerem Feld und als Inhalt ohne JS).
|
|
28
|
+
* limit="8" Suchmodus: höchstens so viele Treffer je Gruppe (Default 8)
|
|
29
|
+
* Elemente mit [data-ncss-command-key] (z.B. das <kbd> im Öffnen-Button) bekommen den
|
|
30
|
+
* passenden Kürzel-Text ("⌘K" bzw. "Strg K"/"Ctrl K").
|
|
31
|
+
*
|
|
32
|
+
* Events (am Element, bubbeln):
|
|
33
|
+
* ncss-command-select { item } cancelable - preventDefault() hält die Palette offen und
|
|
34
|
+
* unterdrückt die Standardaktion (Link/Button)
|
|
35
|
+
* ncss-command-show / ncss-command-hide
|
|
36
|
+
* Öffentlich: el.show(), el.hide(), el.toggle(), el.filter(text)
|
|
37
|
+
*
|
|
38
|
+
* Abhängigkeiten: keine anderen ncss-Scripts. Öffnet den Dialog bei fehlendem nativen
|
|
39
|
+
* command/commandfor selbst (eigener Klick-Listener, nur für Buttons, die auf DIESEN
|
|
40
|
+
* Dialog zeigen) - js/command-fallback.js ist dafür nicht nötig. Ohne customElements oder
|
|
41
|
+
* HTMLDialogElement wird nichts registriert (Element bleibt :not(:defined), alle Einträge
|
|
42
|
+
* bleiben normale Links/Buttons).
|
|
43
|
+
*/
|
|
44
|
+
(function () {
|
|
45
|
+
"use strict";
|
|
46
|
+
|
|
47
|
+
if (!window.customElements || typeof window.HTMLDialogElement !== "function" ||
|
|
48
|
+
customElements.get("ncss-command-palette")) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var TEXTS = {
|
|
53
|
+
de: { status: "{n} Treffer, mit Pfeiltasten auswählen", list: "Befehle", ctrl: "Strg" },
|
|
54
|
+
en: { status: "{n} results, use arrow keys to choose", list: "Commands", ctrl: "Ctrl" }
|
|
55
|
+
};
|
|
56
|
+
var lang = (document.documentElement.getAttribute("lang") || "de").slice(0, 2) === "en" ? "en" : "de";
|
|
57
|
+
var isApple = /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
58
|
+
var counter = 0;
|
|
59
|
+
|
|
60
|
+
function norm(value) {
|
|
61
|
+
return String(value).normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
|
|
62
|
+
}
|
|
63
|
+
function esc(value) {
|
|
64
|
+
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
65
|
+
}
|
|
66
|
+
// Markiert jedes Vorkommen der Suchbegriffe (Groß-/Kleinschreibung egal) mit <mark>.
|
|
67
|
+
function highlight(text, terms) {
|
|
68
|
+
var html = esc(text);
|
|
69
|
+
terms.forEach(function (t) {
|
|
70
|
+
if (t.length < 2) return;
|
|
71
|
+
var re = new RegExp("(" + esc(t).replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + ")", "gi");
|
|
72
|
+
html = html.replace(/(<[^>]*>)|([^<]+)/g, function (m, tag, txt) {
|
|
73
|
+
return tag || txt.replace(re, "<mark>$1</mark>");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return html;
|
|
77
|
+
}
|
|
78
|
+
function ensureId(el, prefix) {
|
|
79
|
+
if (!el.id) {
|
|
80
|
+
el.id = prefix + "-" + ++counter;
|
|
81
|
+
}
|
|
82
|
+
return el.id;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
customElements.define(
|
|
86
|
+
"ncss-command-palette",
|
|
87
|
+
class extends HTMLElement {
|
|
88
|
+
connectedCallback() {
|
|
89
|
+
if (this._ready) {
|
|
90
|
+
// Erneut verbunden (per JS verschoben, z.B. REDAXO-Slice nach oben/unten, htmx
|
|
91
|
+
// hx-preserve): disconnectedCallback() hat die document-Listener entfernt - hier
|
|
92
|
+
// wieder anhängen statt die Palette tot zurückzulassen.
|
|
93
|
+
if (this._onContent) document.addEventListener("ncss-content-change", this._onContent);
|
|
94
|
+
if (this._onKey) document.addEventListener("keydown", this._onKey);
|
|
95
|
+
if (this._onDocClick) document.addEventListener("click", this._onDocClick);
|
|
96
|
+
if (this._mo && this._dialog) this._mo.observe(this._dialog, { attributes: true, attributeFilter: ["open"] });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
var dialog = this.querySelector("dialog");
|
|
100
|
+
var input = dialog && dialog.querySelector(".ncss-command-input");
|
|
101
|
+
var list = dialog && dialog.querySelector(".ncss-command-list");
|
|
102
|
+
if (!input || !list) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
this._ready = true;
|
|
106
|
+
this._dialog = dialog;
|
|
107
|
+
this._input = input;
|
|
108
|
+
this._list = list;
|
|
109
|
+
this._empty = dialog.querySelector(".ncss-command-empty");
|
|
110
|
+
this._active = null;
|
|
111
|
+
var self = this;
|
|
112
|
+
|
|
113
|
+
ensureId(dialog, "ncss-command");
|
|
114
|
+
ensureId(list, "ncss-command-list");
|
|
115
|
+
list.setAttribute("role", "listbox");
|
|
116
|
+
if (!list.hasAttribute("aria-label") && !list.hasAttribute("aria-labelledby")) {
|
|
117
|
+
list.setAttribute("aria-label", TEXTS[lang].list);
|
|
118
|
+
}
|
|
119
|
+
input.setAttribute("role", "combobox");
|
|
120
|
+
input.setAttribute("aria-controls", list.id);
|
|
121
|
+
input.setAttribute("aria-expanded", "true");
|
|
122
|
+
input.setAttribute("aria-autocomplete", "list");
|
|
123
|
+
input.setAttribute("autocomplete", "off");
|
|
124
|
+
input.setAttribute("spellcheck", "false");
|
|
125
|
+
|
|
126
|
+
this._status = document.createElement("p");
|
|
127
|
+
this._status.className = "ncss-command-status";
|
|
128
|
+
this._status.setAttribute("role", "status");
|
|
129
|
+
dialog.appendChild(this._status);
|
|
130
|
+
|
|
131
|
+
list.querySelectorAll(".ncss-command-group").forEach(function (group) {
|
|
132
|
+
group.setAttribute("role", "group");
|
|
133
|
+
var label = group.querySelector(".ncss-command-group-label");
|
|
134
|
+
if (label && !group.hasAttribute("aria-label")) {
|
|
135
|
+
group.setAttribute("aria-labelledby", ensureId(label, "ncss-command-label"));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this._items().forEach(function (item) {
|
|
139
|
+
self._prepare(item);
|
|
140
|
+
});
|
|
141
|
+
// Tastenkürzel-Beschriftungen (auch außerhalb der Palette, z.B. im Such-Button der
|
|
142
|
+
// Kopfleiste) - beim Start UND für später eingefügte Beschriftungen nach einem
|
|
143
|
+
// "ncss-content-change"-Event (htmx, fetch+innerHTML, siehe js/content-observer.js).
|
|
144
|
+
this._labelKeys = function (root) {
|
|
145
|
+
if (!root || !root.querySelectorAll) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
var key = (self.getAttribute("shortcut") || "k").toUpperCase();
|
|
149
|
+
var els = Array.prototype.slice.call(root.querySelectorAll("[data-ncss-command-key]"));
|
|
150
|
+
if (root.matches && root.matches("[data-ncss-command-key]")) {
|
|
151
|
+
els.unshift(root);
|
|
152
|
+
}
|
|
153
|
+
els.forEach(function (el) {
|
|
154
|
+
el.textContent = isApple ? "⌘" + key : TEXTS[lang].ctrl + " " + key;
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
this._labelKeys(document);
|
|
158
|
+
this._onContent = function (event) {
|
|
159
|
+
self._labelKeys((event.detail && event.detail.root) || document);
|
|
160
|
+
};
|
|
161
|
+
document.addEventListener("ncss-content-change", this._onContent);
|
|
162
|
+
|
|
163
|
+
input.addEventListener("input", function () {
|
|
164
|
+
self.filter(input.value);
|
|
165
|
+
});
|
|
166
|
+
input.addEventListener("keydown", function (event) {
|
|
167
|
+
if (event.isComposing) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
var visible = self._visible();
|
|
171
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
if (!visible.length) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
var i = visible.indexOf(self._active) + (event.key === "ArrowDown" ? 1 : -1);
|
|
177
|
+
self._select(visible[(i + visible.length) % visible.length], true);
|
|
178
|
+
} else if ((event.key === "Home" || event.key === "End") && event.ctrlKey) {
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
self._select(event.key === "Home" ? visible[0] : visible[visible.length - 1], true);
|
|
181
|
+
} else if (event.key === "Enter" && self._active) {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
self._active.click();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
list.addEventListener("pointermove", function (event) {
|
|
187
|
+
var item = event.target.closest(".ncss-command-item");
|
|
188
|
+
if (item && item !== self._active) {
|
|
189
|
+
self._select(item, false);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
// Klick auf einen Eintrag nimmt dem Eingabefeld nicht den Fokus
|
|
193
|
+
list.addEventListener("mousedown", function (event) {
|
|
194
|
+
if (event.target.closest(".ncss-command-item")) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
// Ausführen: Standardaktion (Link/Button) läuft weiter, die Palette schließt -
|
|
199
|
+
// gilt für Maus-Klick UND für Enter (das ein .click() auslöst).
|
|
200
|
+
list.addEventListener("click", function (event) {
|
|
201
|
+
var item = event.target.closest(".ncss-command-item");
|
|
202
|
+
if (!item) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
var ok = self.dispatchEvent(new CustomEvent("ncss-command-select", {
|
|
206
|
+
bubbles: true, cancelable: true, detail: { item: item }
|
|
207
|
+
}));
|
|
208
|
+
if (!ok) {
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
dialog.close();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Öffnen erkennen (egal ob über command, Script oder Kürzel) - MutationObserver auf
|
|
216
|
+
// [open] statt "toggle"-Event, das ältere Engines am <dialog> noch nicht feuern.
|
|
217
|
+
this._mo = new MutationObserver(function () {
|
|
218
|
+
if (dialog.open) {
|
|
219
|
+
input.value = "";
|
|
220
|
+
self._load();
|
|
221
|
+
self.filter("");
|
|
222
|
+
input.focus();
|
|
223
|
+
self.dispatchEvent(new CustomEvent("ncss-command-show", { bubbles: true }));
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
this._mo.observe(dialog, { attributes: true, attributeFilter: ["open"] });
|
|
227
|
+
dialog.addEventListener("close", function () {
|
|
228
|
+
self.dispatchEvent(new CustomEvent("ncss-command-hide", { bubbles: true }));
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Klick auf den Backdrop schließt - dort, wo closedby="any" noch nicht greift.
|
|
232
|
+
dialog.addEventListener("click", function (event) {
|
|
233
|
+
if (event.target !== dialog) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
var r = dialog.getBoundingClientRect();
|
|
237
|
+
if (event.clientX < r.left || event.clientX > r.right || event.clientY < r.top || event.clientY > r.bottom) {
|
|
238
|
+
dialog.close();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Eigener command/commandfor-Ersatz NUR für diesen Dialog (siehe Kopfkommentar).
|
|
243
|
+
if (!("command" in HTMLButtonElement.prototype)) {
|
|
244
|
+
this._onDocClick = function (event) {
|
|
245
|
+
var btn = event.target.closest && event.target.closest("button[commandfor]");
|
|
246
|
+
if (!btn || btn.getAttribute("commandfor") !== dialog.id) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
var command = btn.getAttribute("command");
|
|
250
|
+
if (command === "show-modal") {
|
|
251
|
+
self.show();
|
|
252
|
+
} else if (command === "close") {
|
|
253
|
+
self.hide();
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
document.addEventListener("click", this._onDocClick);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
this._onKey = function (event) {
|
|
260
|
+
if (event.key === "/" && self.hasAttribute("slash") && !dialog.open && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
261
|
+
var t = event.target;
|
|
262
|
+
if (!(t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)))) {
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
self.show();
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
var key = self.getAttribute("shortcut");
|
|
269
|
+
if (!key || !event.key || event.key.toLowerCase() !== key.toLowerCase() || event.altKey || event.shiftKey) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (!(isApple ? event.metaKey : event.ctrlKey)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
event.preventDefault();
|
|
276
|
+
self.toggle();
|
|
277
|
+
};
|
|
278
|
+
document.addEventListener("keydown", this._onKey);
|
|
279
|
+
|
|
280
|
+
this.filter("");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
disconnectedCallback() {
|
|
284
|
+
if (this._onContent) {
|
|
285
|
+
document.removeEventListener("ncss-content-change", this._onContent);
|
|
286
|
+
}
|
|
287
|
+
if (this._mo) {
|
|
288
|
+
this._mo.disconnect();
|
|
289
|
+
}
|
|
290
|
+
if (this._onKey) {
|
|
291
|
+
document.removeEventListener("keydown", this._onKey);
|
|
292
|
+
}
|
|
293
|
+
if (this._onDocClick) {
|
|
294
|
+
document.removeEventListener("click", this._onDocClick);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
show() {
|
|
299
|
+
if (this._dialog && !this._dialog.open) {
|
|
300
|
+
this._dialog.showModal();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
hide() {
|
|
304
|
+
if (this._dialog && this._dialog.open) {
|
|
305
|
+
this._dialog.close();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
toggle() {
|
|
309
|
+
if (this._dialog && this._dialog.open) {
|
|
310
|
+
this.hide();
|
|
311
|
+
} else {
|
|
312
|
+
this.show();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
filter(query) {
|
|
317
|
+
if (!this._list) {
|
|
318
|
+
return 0;
|
|
319
|
+
}
|
|
320
|
+
var terms = norm(query || "").trim().split(/\s+/).filter(Boolean);
|
|
321
|
+
this._renderResults(query || "", terms);
|
|
322
|
+
this._items().forEach(function (item) {
|
|
323
|
+
item.hidden = !terms.every(function (t) { return item._ncssText.indexOf(t) !== -1; });
|
|
324
|
+
});
|
|
325
|
+
this._list.querySelectorAll(".ncss-command-group").forEach(function (group) {
|
|
326
|
+
group.hidden = !group.querySelector(".ncss-command-item:not([hidden])");
|
|
327
|
+
});
|
|
328
|
+
this._list.hidden = false;
|
|
329
|
+
var visible = this._visible();
|
|
330
|
+
if (this._empty) {
|
|
331
|
+
this._empty.hidden = visible.length > 0;
|
|
332
|
+
}
|
|
333
|
+
this._list.hidden = visible.length === 0;
|
|
334
|
+
this._input.setAttribute("aria-expanded", String(visible.length > 0));
|
|
335
|
+
this._select(visible[0], false);
|
|
336
|
+
this._list.scrollTop = 0;
|
|
337
|
+
// Ansage erst bei echter Eingabe, nicht schon beim Öffnen (dort liest der
|
|
338
|
+
// Screenreader ohnehin Dialog + Feld vor).
|
|
339
|
+
this._status.textContent = terms.length
|
|
340
|
+
? (this.getAttribute("status-text") || TEXTS[lang].status).replace("{n}", visible.length)
|
|
341
|
+
: "";
|
|
342
|
+
return visible.length;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
_prepare(item) {
|
|
346
|
+
ensureId(item, "ncss-command-item");
|
|
347
|
+
item.setAttribute("role", "option");
|
|
348
|
+
item.setAttribute("aria-selected", "false");
|
|
349
|
+
item.tabIndex = -1;
|
|
350
|
+
item._ncssText = norm(item.textContent + " " + (item.getAttribute("data-keywords") || ""));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Suchmodus: JSON einmalig laden, danach die aktuelle Eingabe neu filtern.
|
|
354
|
+
_load() {
|
|
355
|
+
var src = this.getAttribute("src");
|
|
356
|
+
if (!src || this._data || this._loading || !window.fetch) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
var self = this;
|
|
360
|
+
var url = new URL(src, document.baseURI);
|
|
361
|
+
this._loading = true;
|
|
362
|
+
fetch(url)
|
|
363
|
+
.then(function (r) {
|
|
364
|
+
if (!r.ok) throw new Error("HTTP " + r.status);
|
|
365
|
+
return r.json();
|
|
366
|
+
})
|
|
367
|
+
.then(function (data) {
|
|
368
|
+
data.items.forEach(function (it) {
|
|
369
|
+
// Titel ohne führenden Punkt/spitze Klammern: ".ncss-card" und "<ncss-x>"
|
|
370
|
+
// zählen bei der Eingabe "ncss-card" als exakter Treffer.
|
|
371
|
+
it._n = norm(it.t).replace(/^[.<]+|>$/g, "");
|
|
372
|
+
it._all = norm(it.t + " " + (it.k || "") + " " + (it.h || "") + " " + (it.s || ""));
|
|
373
|
+
it._url = new URL(it.u, url).href;
|
|
374
|
+
});
|
|
375
|
+
self._data = data;
|
|
376
|
+
if (self._dialog.open) self.filter(self._input.value);
|
|
377
|
+
})
|
|
378
|
+
.catch(function (err) {
|
|
379
|
+
if (window.console) window.console.error("[ncss-command-palette]", err);
|
|
380
|
+
})
|
|
381
|
+
.then(function () {
|
|
382
|
+
self._loading = false;
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Trefferliste aus den JSON-Einträgen: Rang = Titel beginnt mit Begriff > Titel
|
|
387
|
+
// enthält ihn > nur Stichwörter/Text; je Gruppe höchstens "limit" Einträge.
|
|
388
|
+
_renderResults(query, terms) {
|
|
389
|
+
if (!this._data) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (!this._results) {
|
|
393
|
+
this._results = document.createElement("div");
|
|
394
|
+
this._results.className = "ncss-command-results";
|
|
395
|
+
this._list.insertBefore(this._results, this._list.firstChild);
|
|
396
|
+
}
|
|
397
|
+
this._results.textContent = "";
|
|
398
|
+
if (!terms.length) {
|
|
399
|
+
this._results.hidden = true;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
this._results.hidden = false;
|
|
403
|
+
var limit = parseInt(this.getAttribute("limit"), 10) || 8;
|
|
404
|
+
var rawTerms = query.trim().split(/\s+/).filter(Boolean);
|
|
405
|
+
var self = this;
|
|
406
|
+
var boxes = [];
|
|
407
|
+
this._data.groups.forEach(function (group, order) {
|
|
408
|
+
var hits = [];
|
|
409
|
+
self._data.items.forEach(function (it) {
|
|
410
|
+
if (it.g !== group.id) return;
|
|
411
|
+
if (!terms.every(function (t) { return it._all.indexOf(t) !== -1; })) return;
|
|
412
|
+
var score = 0;
|
|
413
|
+
terms.forEach(function (t) {
|
|
414
|
+
t = t.replace(/^[.<]+|>$/g, "");
|
|
415
|
+
if (it._n.indexOf(t) === 0) score += 4;
|
|
416
|
+
else if (it._n.indexOf(t) !== -1) score += 2;
|
|
417
|
+
});
|
|
418
|
+
if (it._n === terms.join(" ").replace(/^[.<]+|>$/g, "")) score += 6;
|
|
419
|
+
hits.push({ it: it, score: score });
|
|
420
|
+
});
|
|
421
|
+
if (!hits.length) return;
|
|
422
|
+
hits.sort(function (a, b) { return b.score - a.score || a.it.t.length - b.it.t.length; });
|
|
423
|
+
var best = hits[0].score;
|
|
424
|
+
var box = document.createElement("div");
|
|
425
|
+
box.className = "ncss-command-group";
|
|
426
|
+
box.setAttribute("role", "group");
|
|
427
|
+
var label = document.createElement("p");
|
|
428
|
+
label.className = "ncss-command-group-label";
|
|
429
|
+
label.textContent = group.label;
|
|
430
|
+
box.setAttribute("aria-labelledby", ensureId(label, "ncss-command-label"));
|
|
431
|
+
box.appendChild(label);
|
|
432
|
+
hits.slice(0, limit).forEach(function (h) {
|
|
433
|
+
var a = document.createElement("a");
|
|
434
|
+
a.className = "ncss-command-item";
|
|
435
|
+
a.href = h.it._url;
|
|
436
|
+
a.innerHTML =
|
|
437
|
+
'<span class="ncss-command-item-body"><span class="ncss-command-item-title">' + highlight(h.it.t, rawTerms) + "</span>" +
|
|
438
|
+
(h.it.s ? '<span class="ncss-command-item-snippet">' + highlight(h.it.s, rawTerms) + "</span>" : "") +
|
|
439
|
+
"</span>" + (h.it.h ? '<span class="ncss-command-item-hint">' + esc(h.it.h) + "</span>" : "");
|
|
440
|
+
box.appendChild(a);
|
|
441
|
+
self._prepare(a);
|
|
442
|
+
a._ncssText = h.it._all;
|
|
443
|
+
});
|
|
444
|
+
boxes.push({ box: box, best: best, order: order });
|
|
445
|
+
});
|
|
446
|
+
// Gruppe mit dem besten Treffer zuerst (z.B. "ncss-card" -> Klassen vor Abschnitten),
|
|
447
|
+
// bei Gleichstand die Reihenfolge aus der JSON-Datei.
|
|
448
|
+
boxes.sort(function (a, b) { return b.best - a.best || a.order - b.order; });
|
|
449
|
+
boxes.forEach(function (b) { self._results.appendChild(b.box); });
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
_items() {
|
|
453
|
+
return Array.prototype.slice.call(this._list.querySelectorAll(".ncss-command-item"));
|
|
454
|
+
}
|
|
455
|
+
_visible() {
|
|
456
|
+
return this._items().filter(function (item) {
|
|
457
|
+
return !item.hidden && !item.closest("[hidden]");
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
_select(item, scroll) {
|
|
461
|
+
if (this._active) {
|
|
462
|
+
this._active.setAttribute("aria-selected", "false");
|
|
463
|
+
}
|
|
464
|
+
this._active = item || null;
|
|
465
|
+
if (this._active) {
|
|
466
|
+
this._active.setAttribute("aria-selected", "true");
|
|
467
|
+
this._input.setAttribute("aria-activedescendant", this._active.id);
|
|
468
|
+
if (scroll) {
|
|
469
|
+
this._active.scrollIntoView({ block: "nearest" });
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
this._input.removeAttribute("aria-activedescendant");
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
);
|
|
477
|
+
})();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - <ncss-compare>: Vorher/Nachher-Vergleich (siehe components/compare.css für
|
|
3
|
+
* Markup). Light-DOM-Custom-Element ohne Shadow Root - der native
|
|
4
|
+
* <input type="range"> darin erledigt Maus, Touch, Tastatur und Screenreader, dieses
|
|
5
|
+
* Script kopiert nur den Wert nach --ncss-compare-position und setzt aria-valuetext.
|
|
6
|
+
*
|
|
7
|
+
* Attribute:
|
|
8
|
+
* value-text="{n} % vorher" gesprochener Wert ({n} = Prozent), Default nach <html lang>
|
|
9
|
+
*
|
|
10
|
+
* Events (bubbeln): ncss-compare-change { value } - bei jeder Bewegung des Reglers.
|
|
11
|
+
* Öffentlich: el.value (lesen/setzen, 0-100 bzw. min-max des Reglers).
|
|
12
|
+
*
|
|
13
|
+
* Abhängigkeiten: keine anderen ncss-Scripts. Ohne customElements (sehr alte Browser)
|
|
14
|
+
* wird gar nichts registriert - das Element bleibt :not(:defined), CSS zeigt den
|
|
15
|
+
* statischen 50/50-Vergleich ohne Regler (siehe SKILL.md-Regel zu define()-Guards).
|
|
16
|
+
*/
|
|
17
|
+
(function () {
|
|
18
|
+
"use strict";
|
|
19
|
+
|
|
20
|
+
if (!window.customElements || customElements.get("ncss-compare")) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var TEXTS = { de: "{n} % vorher", en: "{n}% before" };
|
|
25
|
+
var lang = (document.documentElement.getAttribute("lang") || "de").slice(0, 2) === "en" ? "en" : "de";
|
|
26
|
+
|
|
27
|
+
customElements.define(
|
|
28
|
+
"ncss-compare",
|
|
29
|
+
class extends HTMLElement {
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
this._range = this.querySelector(".ncss-compare-range, input[type=\"range\"]");
|
|
32
|
+
if (!this._range || this._onInput) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this._onInput = this._sync.bind(this, true);
|
|
36
|
+
this._range.addEventListener("input", this._onInput);
|
|
37
|
+
this._sync(false);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
disconnectedCallback() {
|
|
41
|
+
if (this._range && this._onInput) {
|
|
42
|
+
this._range.removeEventListener("input", this._onInput);
|
|
43
|
+
this._onInput = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get value() {
|
|
48
|
+
return this._range ? Number(this._range.value) : NaN;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set value(v) {
|
|
52
|
+
if (!this._range) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this._range.value = v;
|
|
56
|
+
this._sync(true);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
_sync(notify) {
|
|
60
|
+
var r = this._range;
|
|
61
|
+
var min = Number(r.min || 0);
|
|
62
|
+
var max = Number(r.max || 100);
|
|
63
|
+
var pct = ((Number(r.value) - min) / (max - min)) * 100;
|
|
64
|
+
this.style.setProperty("--ncss-compare-position", pct + "%");
|
|
65
|
+
var text = this.getAttribute("value-text") || TEXTS[lang];
|
|
66
|
+
r.setAttribute("aria-valuetext", text.replace("{n}", Math.round(pct)));
|
|
67
|
+
if (notify) {
|
|
68
|
+
this.dispatchEvent(new CustomEvent("ncss-compare-change", { bubbles: true, detail: { value: pct } }));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
})();
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ncss - Content-Observer (opt-in): meldet neu eingefügtes Markup automatisch per
|
|
3
|
+
* "ncss-content-change"-Event, damit die Attribut-Scripts aus js/ (count-up, reveal,
|
|
4
|
+
* marquee, sparkline, downloads, events, code-block, combobox, livesearch, ...) es
|
|
5
|
+
* initialisieren - ohne dass der Host-Code (htmx, eigenes fetch+innerHTML, REDAXO-
|
|
6
|
+
* Frontend-Editing) selbst etwas dispatchen muss.
|
|
7
|
+
*
|
|
8
|
+
* PRIMÄRER Weg bleibt das explizite Event - billiger, präzise und ohne Beobachter:
|
|
9
|
+
* document.dispatchEvent(new CustomEvent("ncss-content-change", { detail: { root: el } }));
|
|
10
|
+
* Dieses Script ist nur für Umgebungen gedacht, in denen sich der Einfüge-Code nicht
|
|
11
|
+
* anpassen lässt. Es ist komplett eigenständig - jedes ncss-Script funktioniert auch
|
|
12
|
+
* ohne es, und es funktioniert ohne jedes andere ncss-Script (dann feuert es nur Events,
|
|
13
|
+
* auf die niemand hört).
|
|
14
|
+
*
|
|
15
|
+
* Mechanik: EIN MutationObserver (childList + subtree auf <html>). Eingefügte ELEMENT-
|
|
16
|
+
* Knoten werden pro Animation-Frame gesammelt (eine htmx-Antwort mit 200 Karten ergibt
|
|
17
|
+
* EIN Event pro oberstem eingefügten Knoten, nicht 200 Events pro Frame-Fragment), Knoten,
|
|
18
|
+
* die in einem anderen Knoten desselben Schubs stecken oder inzwischen wieder entfernt
|
|
19
|
+
* wurden, fallen heraus. Pro übrig gebliebenem Wurzel-Knoten ein Event mit
|
|
20
|
+
* detail.root = Knoten und detail.source = "observer" (zur Unterscheidung vom
|
|
21
|
+
* expliziten Aufruf, falls Host-Code beides kombiniert).
|
|
22
|
+
*
|
|
23
|
+
* Doppelte Meldung (expliziter Dispatch UND Observer) ist unschädlich - jedes ncss-Script
|
|
24
|
+
* merkt sich bereits verarbeitete Elemente (WeakSet) und initialisiert nie doppelt.
|
|
25
|
+
* Markup, das ncss-Scripts SELBST erzeugen (Marquee-Kopie, Sparkline-Tabelle, ...), löst
|
|
26
|
+
* ebenfalls ein Event aus - die Scripts finden darin nichts Neues, kein Endlos-Kreislauf.
|
|
27
|
+
*
|
|
28
|
+
* Opt-out für einzelne Bereiche (z.B. ein häufig neu gerendertes Live-Widget):
|
|
29
|
+
* data-ncss-observe="off" auf einem Vorfahren - Einfügungen darin werden ignoriert.
|
|
30
|
+
*
|
|
31
|
+
* Einbindung: <script src="ncss/js/content-observer.js" defer></script>
|
|
32
|
+
*/
|
|
33
|
+
(function () {
|
|
34
|
+
"use strict";
|
|
35
|
+
|
|
36
|
+
if (typeof MutationObserver === "undefined" || typeof window.CustomEvent !== "function" ||
|
|
37
|
+
typeof window.requestAnimationFrame !== "function" || !document.documentElement) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var pending = [];
|
|
42
|
+
var scheduled = false;
|
|
43
|
+
|
|
44
|
+
function flush() {
|
|
45
|
+
scheduled = false;
|
|
46
|
+
var batch = pending;
|
|
47
|
+
pending = [];
|
|
48
|
+
var roots = batch.filter(function (node, index) {
|
|
49
|
+
if (!node.isConnected || batch.indexOf(node) !== index) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (node.closest && node.closest('[data-ncss-observe="off"]')) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
// Steckt der Knoten in einem anderen Knoten desselben Schubs, deckt dessen Event ihn ab.
|
|
56
|
+
for (var i = 0; i < batch.length; i++) {
|
|
57
|
+
if (batch[i] !== node && batch[i].contains(node)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
});
|
|
63
|
+
roots.forEach(function (root) {
|
|
64
|
+
document.dispatchEvent(new CustomEvent("ncss-content-change", { detail: { root: root, source: "observer" } }));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
new MutationObserver(function (records) {
|
|
69
|
+
for (var r = 0; r < records.length; r++) {
|
|
70
|
+
var added = records[r].addedNodes;
|
|
71
|
+
for (var n = 0; n < added.length; n++) {
|
|
72
|
+
if (added[n].nodeType === 1) {
|
|
73
|
+
pending.push(added[n]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (pending.length && !scheduled) {
|
|
78
|
+
scheduled = true;
|
|
79
|
+
requestAnimationFrame(flush);
|
|
80
|
+
}
|
|
81
|
+
}).observe(document.documentElement, { childList: true, subtree: true });
|
|
82
|
+
})();
|