@birdycom/omniaui 0.15.1 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/copy-js.mjs +3 -0
- package/bin/lib/webicons.mjs +120 -0
- package/bin/omniaui.mjs +10 -1
- package/dist/carousel.d.ts +2 -0
- package/dist/carousel.js +38 -2
- package/dist/combobox.d.ts +13 -0
- package/dist/combobox.js +143 -0
- package/dist/components-extra.css +7 -3
- package/dist/components.css +1260 -153
- package/dist/components.min.css +1 -1
- package/dist/docs-ui.css +1 -1
- package/dist/fly.js +13 -2
- package/dist/logo.d.ts +14 -0
- package/dist/logo.js +98 -0
- package/dist/oc-theme.css +1 -1
- package/dist/parts/app-0160-apps.css +141 -0
- package/dist/parts/app-accordion-accent.css +1 -1
- package/dist/parts/app-busy-overlay.css +1 -1
- package/dist/parts/app-confirm-dialog.css +4 -18
- package/dist/parts/app-cookie-consent.css +1 -1
- package/dist/parts/app-data-table-rich.css +1 -1
- package/dist/parts/app-mode-badge.css +130 -0
- package/dist/parts/app-name-card.css +10 -0
- package/dist/parts/app-severity-card.css +4 -3
- package/dist/parts/app-sheet-options.css +70 -0
- package/dist/parts/app-sidebar-dark.css +1 -1
- package/dist/parts/app-sidebar-meta.css +40 -0
- package/dist/parts/app-stat-card.css +2 -2
- package/dist/parts/app-upgrade-banner.css +1 -1
- package/dist/parts/data-chart-line.css +5 -2
- package/dist/parts/data-reading.css +2 -1
- package/dist/parts/data-stock.css +1 -1
- package/dist/parts/forms-affix-input.css +7 -0
- package/dist/parts/forms-barcode-input.css +2 -1
- package/dist/parts/forms-combobox-icons.css +78 -0
- package/dist/parts/forms-language-menu.css +89 -0
- package/dist/parts/forms-language-select.css +3 -2
- package/dist/parts/forms-phone-input.css +3 -0
- package/dist/parts/media-art.css +7 -5
- package/dist/parts/media-doc-viewer.css +1 -1
- package/dist/parts/media-flip-card.css +1 -1
- package/dist/parts/media-glass-liquid.css +14 -0
- package/dist/parts/media-glass.css +8 -0
- package/dist/parts/media-live-frame.css +58 -0
- package/dist/parts/media-logo.css +48 -0
- package/dist/parts/media-terminal-log.css +4 -3
- package/dist/parts/media-thumb.css +1 -1
- package/dist/parts/site-backgrounds.css +1 -1
- package/dist/parts/site-base.css +14 -7
- package/dist/parts/site-brand-mark.css +1 -1
- package/dist/parts/site-cards.css +4 -1
- package/dist/parts/site-fact-list.css +1 -1
- package/dist/parts/site-fly.css +1 -0
- package/dist/parts/site-header-variants.css +6 -1
- package/dist/parts/site-layout.css +1 -1
- package/dist/parts/site-link-arrow.css +1 -1
- package/dist/parts/site-link-row.css +1 -1
- package/dist/parts/site-next-teaser.css +2 -2
- package/dist/parts/site-paper.css +189 -0
- package/dist/parts/site-price-card.css +4 -3
- package/dist/parts/site-product-mark.css +1 -1
- package/dist/parts/site-project-card.css +13 -8
- package/dist/parts/site-stack-list.css +1 -1
- package/dist/parts/site-timeline.css +1 -1
- package/dist/parts/utility-hover.css +4 -3
- package/dist/showcase.css +74 -28
- package/dist/theme.js +130 -0
- package/manifest.json +40 -0
- package/package.json +5 -2
- package/snippets/card.html +4 -1
- package/snippets/code-plate.html +10 -0
- package/snippets/collapsible.html +2 -2
- package/snippets/combobox.html +19 -0
- package/snippets/context-menu.html +5 -2
- package/snippets/definition-list.html +1 -1
- package/snippets/dropdown-menu.html +1 -0
- package/snippets/language-select.html +15 -0
- package/snippets/live-frame.html +3 -1
- package/snippets/logo.html +10 -0
- package/snippets/mode-badge.html +12 -0
- package/snippets/next-teaser.html +1 -1
- package/snippets/page-sections.html +1 -1
- package/snippets/paper.html +32 -0
- package/snippets/project-card.html +4 -4
- package/snippets/sheet.html +4 -0
- package/snippets/shot-grid.html +2 -2
- package/snippets/sidebar.html +2 -0
- package/snippets/timeline.html +1 -1
- package/snippets/webicon.html +11 -0
package/bin/lib/copy-js.mjs
CHANGED
|
@@ -17,6 +17,9 @@ const SCRIPTS = [
|
|
|
17
17
|
["@birdycom/omniaui", "dist/fly.js", "oc-fly.js", "cards that fly in from the middle of their row on scroll (.oc-reveal--fly)"],
|
|
18
18
|
["@birdycom/omniaui", "dist/particles.js", "oc-particles.js", "particle field: drifting points with lines on a background canvas (canvas.oc-particles)"],
|
|
19
19
|
["@birdycom/omniaui", "dist/language-select.js", "oc-language-select.js", "language select: go to the chosen language's page, keeping the #hash ([data-oc-language-select])"],
|
|
20
|
+
["@birdycom/omniaui", "dist/combobox.js", "oc-combobox.js", "combobox: filter while typing, arrow keys, choose with Enter or a click ([data-oc-combobox])"],
|
|
21
|
+
["@birdycom/omniaui", "dist/logo.js", "oc-logo.js", "logo: a neutral plate only in the theme where the logo would disappear (.oc-logo[data-plate=auto])"],
|
|
22
|
+
["@birdycom/omniaui", "dist/theme.js","oc-theme.js", "theme: remember the choice of a .oc-theme-switch, data-theme on <html>, a light/dark toggle button"],
|
|
20
23
|
["@birdycom/omniaui", "dist/toc.js", "oc-toc.js", "table of contents: highlight the heading you are reading where :target-current is missing (.oc-toc)"],
|
|
21
24
|
["@birdycom/omniaui", "dist/form-extras.js", "oc-form-extras.js", "ISO week in date fields, name card rename, avatar picker preview, quantity steps, language code"],
|
|
22
25
|
["@birdycom/omniaui-pro", "dist/spotlight.js", "oc-spotlight.js", "spotlight cards (Pro)"],
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// File: packages/ui/bin/lib/webicons.mjs
|
|
2
|
+
// `omniaui webicons`: a small JSON file with only the webicons an app uses, read from the Iconify sets installed in
|
|
3
|
+
// node_modules (@iconify-json/<set>/icons.json). Nothing is fetched. The app imports the file and passes it to
|
|
4
|
+
// addWebicons() (React / Vue); Blade reads it through config('omniacss.webicons.files').
|
|
5
|
+
// Map: names (arguments and/or --scan of the source) -> resolve per set (aliases) -> write --out (or print) -> report
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import { cwd } from "./project.mjs";
|
|
11
|
+
|
|
12
|
+
/** The webicon sets (Iconify prefixes). */
|
|
13
|
+
export const WEBICON_SETS = ["mdi", "mdi-light", "material-symbols", "svg-spinners", "flag", "vscode-icons"];
|
|
14
|
+
const NAME = new RegExp(`(?<![\\w-])(${WEBICON_SETS.join("|")}):([a-z0-9]+(?:-[a-z0-9]+)*)`, "g");
|
|
15
|
+
const SCAN_EXT = new Set([".js", ".jsx", ".ts", ".tsx", ".vue", ".svelte", ".astro", ".php", ".html", ".md", ".mdx", ".json"]);
|
|
16
|
+
const SKIP_DIR = new Set(["node_modules", "vendor", "dist", "build", ".git", ".next", ".nuxt", "storage", "coverage"]);
|
|
17
|
+
|
|
18
|
+
/** Every webicon name in the files under `dir`. */
|
|
19
|
+
export async function scanNames(dir, skip = new Set()) {
|
|
20
|
+
const found = new Set();
|
|
21
|
+
async function walk(d) {
|
|
22
|
+
for (const entry of await fs.readdir(d, { withFileTypes: true })) {
|
|
23
|
+
const full = path.join(d, entry.name);
|
|
24
|
+
if (entry.isDirectory()) {
|
|
25
|
+
if (!SKIP_DIR.has(entry.name) && !entry.name.startsWith(".")) await walk(full);
|
|
26
|
+
} else if (SCAN_EXT.has(path.extname(entry.name)) && !skip.has(path.resolve(full))) {
|
|
27
|
+
for (const m of (await fs.readFile(full, "utf8")).matchAll(NAME)) found.add(`${m[1]}:${m[2]}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await walk(dir);
|
|
32
|
+
return [...found].sort();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** One icon of an Iconify JSON set with its aliases resolved, or null. */
|
|
36
|
+
export function resolveIcon(set, name) {
|
|
37
|
+
let extra = {};
|
|
38
|
+
let rotate = 0;
|
|
39
|
+
let hFlip = false;
|
|
40
|
+
let vFlip = false;
|
|
41
|
+
for (let n = name, depth = 0; depth < 6; depth++) {
|
|
42
|
+
const icon = set.icons[n];
|
|
43
|
+
if (icon) {
|
|
44
|
+
const out = { ...icon, ...extra, body: icon.body };
|
|
45
|
+
out.width ??= set.width ?? 16;
|
|
46
|
+
out.height ??= set.height ?? 16;
|
|
47
|
+
if (set.left && out.left == null) out.left = set.left;
|
|
48
|
+
if (set.top && out.top == null) out.top = set.top;
|
|
49
|
+
const r = ((icon.rotate ?? 0) + rotate) % 4;
|
|
50
|
+
const h = !!icon.hFlip !== hFlip;
|
|
51
|
+
const v = !!icon.vFlip !== vFlip;
|
|
52
|
+
delete out.rotate; delete out.hFlip; delete out.vFlip;
|
|
53
|
+
if (r) out.rotate = r;
|
|
54
|
+
if (h) out.hFlip = true;
|
|
55
|
+
if (v) out.vFlip = true;
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
const alias = set.aliases?.[n];
|
|
59
|
+
if (!alias) return null;
|
|
60
|
+
const { parent, rotate: ar = 0, hFlip: ah = false, vFlip: av = false, ...rest } = alias;
|
|
61
|
+
extra = { ...rest, ...extra };
|
|
62
|
+
rotate += ar;
|
|
63
|
+
hFlip = hFlip !== ah;
|
|
64
|
+
vFlip = vFlip !== av;
|
|
65
|
+
n = parent;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** { icons: { "mdi:home": {...} }, missing: [names], noSet: [prefixes] } for the given names. */
|
|
71
|
+
export async function buildSubset(names, from = cwd) {
|
|
72
|
+
const require = createRequire(path.join(from, "package.json"));
|
|
73
|
+
const sets = new Map();
|
|
74
|
+
const icons = {};
|
|
75
|
+
const missing = [];
|
|
76
|
+
const noSet = new Set();
|
|
77
|
+
for (const full of [...new Set(names)].sort()) {
|
|
78
|
+
const i = full.indexOf(":");
|
|
79
|
+
const prefix = full.slice(0, i);
|
|
80
|
+
if (i < 1) { missing.push(full); continue; }
|
|
81
|
+
if (!sets.has(prefix)) {
|
|
82
|
+
try {
|
|
83
|
+
sets.set(prefix, JSON.parse(await fs.readFile(require.resolve(`@iconify-json/${prefix}/icons.json`), "utf8")));
|
|
84
|
+
} catch {
|
|
85
|
+
sets.set(prefix, null);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const set = sets.get(prefix);
|
|
89
|
+
if (!set) { noSet.add(prefix); missing.push(full); continue; }
|
|
90
|
+
const icon = resolveIcon(set, full.slice(i + 1));
|
|
91
|
+
if (icon) icons[full] = icon;
|
|
92
|
+
else missing.push(full);
|
|
93
|
+
}
|
|
94
|
+
return { icons, missing, noSet: [...noSet] };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** `omniaui webicons [name...] [--scan <dir>] [--out <file>]` */
|
|
98
|
+
export async function cmdWebicons(names, values) {
|
|
99
|
+
const out = values.out ?? values.to;
|
|
100
|
+
const list = [...names];
|
|
101
|
+
if (values.scan) {
|
|
102
|
+
const skip = new Set(out ? [path.resolve(cwd, out)] : []);
|
|
103
|
+
list.push(...(await scanNames(path.resolve(cwd, values.scan), skip)));
|
|
104
|
+
}
|
|
105
|
+
if (!list.length) throw new Error('name the icons ("mdi:home flag:nl-4x3") or scan the source with --scan src');
|
|
106
|
+
const { icons, missing, noSet } = await buildSubset(list);
|
|
107
|
+
const json = JSON.stringify(icons, null, 1) + "\n";
|
|
108
|
+
if (out && !values["dry-run"]) {
|
|
109
|
+
await fs.mkdir(path.dirname(path.resolve(cwd, out)), { recursive: true });
|
|
110
|
+
await fs.writeFile(path.resolve(cwd, out), json);
|
|
111
|
+
} else if (!out) {
|
|
112
|
+
process.stdout.write(json);
|
|
113
|
+
}
|
|
114
|
+
const log = out ? console.log : console.error;
|
|
115
|
+
if (out) log(`omniaui: ${Object.keys(icons).length} webicons -> ${out} (${(json.length / 1024).toFixed(1)} KB)`);
|
|
116
|
+
for (const p of noSet) log(WEBICON_SETS.includes(p) ? ` set ${p} is not installed: npm i -D @iconify-json/${p}` : ` ${p}: not a webicon set (${WEBICON_SETS.join(", ")})`);
|
|
117
|
+
const unknown = missing.filter((m) => !noSet.includes(m.slice(0, m.indexOf(":"))));
|
|
118
|
+
if (unknown.length) log(` not found: ${unknown.join(", ")}`);
|
|
119
|
+
if (out) log(` React/Vue: import icons from "./${path.basename(out)}"; addWebicons(icons)`);
|
|
120
|
+
}
|
package/bin/omniaui.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// File: packages/ui/bin/omniaui.mjs
|
|
3
3
|
// OmniaUI CLI — copy components and blocks into your project (css | vue | react | blade), list the registry.
|
|
4
|
-
// Map: args -> commands (add | list | copy-js | help | version) -> lib/add.mjs (lib/catalog.mjs, lib/project.mjs),
|
|
4
|
+
// Map: args -> commands (add | list | copy-js | webicons | help | version) -> lib/add.mjs (lib/catalog.mjs, lib/project.mjs),
|
|
5
|
+
// lib/copy-js.mjs, lib/webicons.mjs
|
|
5
6
|
// Author: Serge Cools | Framework: OmniaUI (on OmniaCSS)
|
|
6
7
|
//
|
|
7
8
|
// These commands used to be "omniacss add/list" (moved here in October 2026). The CSS build stays in
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
import { parseArgs } from "node:util";
|
|
11
12
|
import { cmdAdd, cmdList } from "./lib/add.mjs";
|
|
12
13
|
import { cmdCopyJs } from "./lib/copy-js.mjs";
|
|
14
|
+
import { cmdWebicons } from "./lib/webicons.mjs";
|
|
13
15
|
import { readJson } from "./lib/project.mjs";
|
|
14
16
|
|
|
15
17
|
const HELP = `
|
|
@@ -21,6 +23,10 @@ OmniaUI CLI
|
|
|
21
23
|
omniaui list [blocks|components] [-f vue] show what can be added in a flavour
|
|
22
24
|
omniaui copy-js [name...] [--to public/js] copy the scripts (data table, carousel, barcode; Pro: spotlight, ecosystem map,
|
|
23
25
|
infinite carousel, barcode maker …) as oc-<name>.js, which start on their own from a script tag
|
|
26
|
+
omniaui webicons [name...] [--scan src] [--out src/webicons.json]
|
|
27
|
+
a small JSON file with only the webicons you use (mdi:, mdi-light:, material-symbols:,
|
|
28
|
+
svg-spinners:, flag:, vscode-icons:), read from @iconify-json/<set> in node_modules;
|
|
29
|
+
no network. React/Vue: addWebicons(json). Blade: config omniacss.webicons.files
|
|
24
30
|
|
|
25
31
|
Options:
|
|
26
32
|
-f, --framework <fw> css | vue | react | blade (default: "framework" in omnia.config.json, else detected
|
|
@@ -44,6 +50,8 @@ async function main() {
|
|
|
44
50
|
allowPositionals: true,
|
|
45
51
|
options: {
|
|
46
52
|
to: { type: "string" },
|
|
53
|
+
out: { type: "string", short: "o" },
|
|
54
|
+
scan: { type: "string" },
|
|
47
55
|
dir: { type: "string" },
|
|
48
56
|
framework: { type: "string", short: "f" },
|
|
49
57
|
kind: { type: "string", short: "k" },
|
|
@@ -64,6 +72,7 @@ async function main() {
|
|
|
64
72
|
case "add": return cmdAdd(rest, values);
|
|
65
73
|
case "list": return cmdList(rest[0], values);
|
|
66
74
|
case "copy-js": return cmdCopyJs(rest, values);
|
|
75
|
+
case "webicons": return cmdWebicons(rest, values);
|
|
67
76
|
default: console.log(HELP);
|
|
68
77
|
}
|
|
69
78
|
}
|
package/dist/carousel.d.ts
CHANGED
|
@@ -3,4 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
export function loopTarget(position: number, max: number, step: number, direction: 1 | -1): number;
|
|
5
5
|
export function bindCarousel(root: HTMLElement): void;
|
|
6
|
+
export function currentIndex(centres: number[], viewportCentre: number): number;
|
|
7
|
+
export function bindDots(root: HTMLElement): void;
|
|
6
8
|
export function initCarousels(scope?: ParentNode): void;
|
package/dist/carousel.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// File: packages/ui/src/carousel.js
|
|
2
|
-
// Map: next scroll position (wraps at the ends) -> bind one .oc-carousel--loop (prev/next buttons) ->
|
|
2
|
+
// Map: next scroll position (wraps at the ends) -> bind one .oc-carousel--loop (prev/next buttons) -> fallback dots
|
|
3
|
+
// -> boot
|
|
3
4
|
// Loop for the CSS carousel: the browser's ::scroll-button arrows stop at the first and last slide, so a looping
|
|
4
5
|
// carousel has two real buttons (.oc-carousel-prev / .oc-carousel-next) and this script moves it one slide, from the
|
|
5
6
|
// last slide back to the first and from the first to the last. Swipe, snap, dots and keyboard stay CSS.
|
|
7
|
+
// Where the browser has no ::scroll-marker (Firefox, Safari) the .oc-carousel-dot links are the dots: this script
|
|
8
|
+
// makes them scroll only the track (a plain #slide link also scrolls the page) and marks the current one.
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Where to scroll for one step. `position` and `max` are distances from the start edge (positive, also in RTL),
|
|
@@ -33,9 +36,42 @@ export function bindCarousel(root) {
|
|
|
33
36
|
root.setAttribute("data-oc-loop", "");
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
/**
|
|
39
|
+
/** Index of the slide whose centre is closest to the centre of the track. */
|
|
40
|
+
export function currentIndex(centres, viewportCentre) {
|
|
41
|
+
let best = 0;
|
|
42
|
+
centres.forEach((c, i) => { if (Math.abs(c - viewportCentre) < Math.abs(centres[best] - viewportCentre)) best = i; });
|
|
43
|
+
return best;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Fallback dots (once): a click scrolls only the track to its slide, the dot of the slide in view gets aria-current. */
|
|
47
|
+
export function bindDots(root) {
|
|
48
|
+
if (root.hasAttribute("data-oc-dots")) return;
|
|
49
|
+
const viewport = root.querySelector(".oc-carousel-viewport");
|
|
50
|
+
const dots = [...root.querySelectorAll(".oc-carousel-dot[href^='#']")];
|
|
51
|
+
if (!viewport || !dots.length) return;
|
|
52
|
+
const slides = dots.map((dot) => document.getElementById(decodeURIComponent(dot.getAttribute("href").slice(1))));
|
|
53
|
+
dots.forEach((dot, i) => dot.addEventListener("click", (event) => {
|
|
54
|
+
const slide = slides[i];
|
|
55
|
+
if (!slide || !viewport.contains(slide)) return;
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
slide.scrollIntoView({ block: "nearest", inline: "center" });
|
|
58
|
+
}));
|
|
59
|
+
const mark = () => {
|
|
60
|
+
const box = viewport.getBoundingClientRect();
|
|
61
|
+
const centres = slides.map((s) => (s ? s.getBoundingClientRect().left + s.offsetWidth / 2 : Infinity));
|
|
62
|
+
const current = currentIndex(centres, box.left + box.width / 2);
|
|
63
|
+
dots.forEach((dot, i) => (i === current ? dot.setAttribute("aria-current", "true") : dot.removeAttribute("aria-current")));
|
|
64
|
+
};
|
|
65
|
+
let frame = 0;
|
|
66
|
+
viewport.addEventListener("scroll", () => { cancelAnimationFrame(frame); frame = requestAnimationFrame(mark); }, { passive: true });
|
|
67
|
+
mark();
|
|
68
|
+
root.setAttribute("data-oc-dots", "");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Wire every looping carousel and every set of fallback dots under scope that is not wired yet. */
|
|
37
72
|
export function initCarousels(scope = document) {
|
|
38
73
|
scope.querySelectorAll(".oc-carousel--loop").forEach((root) => bindCarousel(root));
|
|
74
|
+
scope.querySelectorAll(".oc-carousel").forEach((root) => bindDots(root));
|
|
39
75
|
}
|
|
40
76
|
|
|
41
77
|
// Starts on its own when loaded straight from a <script type="module"> tag: as /js/oc-carousel.js (the docs site,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// File: packages/ui/src/combobox.d.ts
|
|
2
|
+
// Types for the combobox behaviour (filter, keyboard, choose) of the CSS combobox.
|
|
3
|
+
|
|
4
|
+
/** Text label of an option (without its icon). */
|
|
5
|
+
export function optionLabel(option: Element): string;
|
|
6
|
+
/** data-value of an option, else its label. */
|
|
7
|
+
export function optionValue(option: HTMLElement): string;
|
|
8
|
+
/** True when the label contains the query (case and accents ignored). */
|
|
9
|
+
export function matches(label: string, query: string): boolean;
|
|
10
|
+
/** Starts one .oc-combobox; returns a function that stops it. Event: oc-combobox-change { value, label }. */
|
|
11
|
+
export function bindCombobox(root: HTMLElement): () => void;
|
|
12
|
+
/** Starts every .oc-combobox[data-oc-combobox] in scope; returns a function that stops them. */
|
|
13
|
+
export function initCombobox(scope?: ParentNode): () => void;
|
package/dist/combobox.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// File: packages/ui/src/combobox.js
|
|
2
|
+
// Map: label/value of an option -> filter -> active option (arrows, Home/End) -> choose (Enter, click) -> open/close
|
|
3
|
+
// -> bind one .oc-combobox -> init every [data-oc-combobox] -> boot
|
|
4
|
+
// Behaviour for the CSS combobox (.oc-combobox) in plain HTML and Blade: typing filters the list, the arrow keys move
|
|
5
|
+
// the active option (aria-activedescendant), Enter or a click chooses, Escape closes. The chosen option gets
|
|
6
|
+
// aria-selected, its label goes into the field and its icon (.oc-combobox-option-icon) into the field's .oc-combobox-icon.
|
|
7
|
+
// A hidden input in the wrapper (input[type=hidden]) gets the option's data-value, for forms.
|
|
8
|
+
// Event on the wrapper: oc-combobox-change { value, label }.
|
|
9
|
+
|
|
10
|
+
const OPTION = ".oc-combobox-option";
|
|
11
|
+
|
|
12
|
+
/** Text label of an option (without the icon). */
|
|
13
|
+
export function optionLabel(option) {
|
|
14
|
+
const icon = option.querySelector(".oc-combobox-option-icon");
|
|
15
|
+
return [...option.childNodes].filter((n) => n !== icon).map((n) => n.textContent).join("").trim();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Value of an option: data-value, else its label. */
|
|
19
|
+
export function optionValue(option) {
|
|
20
|
+
return option.dataset.value ?? optionLabel(option);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** True when the label contains the query (case and accents ignored). */
|
|
24
|
+
export function matches(label, query) {
|
|
25
|
+
const fold = (s) => String(s).normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
|
|
26
|
+
return fold(label).includes(fold(query).trim());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let uid = 0;
|
|
30
|
+
|
|
31
|
+
/** Starts one .oc-combobox. Returns a function that stops it. */
|
|
32
|
+
export function bindCombobox(root) {
|
|
33
|
+
const input = root.querySelector(".oc-combobox-input");
|
|
34
|
+
const list = root.querySelector(".oc-combobox-list");
|
|
35
|
+
if (!input || !list || root.dataset.ocBound != null) return () => {};
|
|
36
|
+
root.dataset.ocBound = "";
|
|
37
|
+
const slot = root.querySelector(":scope > .oc-combobox-icon");
|
|
38
|
+
const placeholderIcon = slot ? slot.innerHTML : "";
|
|
39
|
+
const hidden = root.querySelector(':scope > input[type="hidden"]');
|
|
40
|
+
const empty = list.querySelector(".oc-combobox-empty");
|
|
41
|
+
const options = () => [...list.querySelectorAll(OPTION)];
|
|
42
|
+
const enabled = () => options().filter((o) => !o.hidden && o.getAttribute("aria-disabled") !== "true");
|
|
43
|
+
options().forEach((o) => { if (!o.id) o.id = `oc-combobox-option-${++uid}`; });
|
|
44
|
+
|
|
45
|
+
const setOpen = (open) => {
|
|
46
|
+
if (open) root.removeAttribute("data-open");
|
|
47
|
+
else root.dataset.open = "false";
|
|
48
|
+
input.setAttribute("aria-expanded", String(open && root.contains(root.ownerDocument.activeElement)));
|
|
49
|
+
};
|
|
50
|
+
const setActive = (option) => {
|
|
51
|
+
options().forEach((o) => o.toggleAttribute("data-active", o === option));
|
|
52
|
+
if (option) {
|
|
53
|
+
input.setAttribute("aria-activedescendant", option.id);
|
|
54
|
+
option.scrollIntoView?.({ block: "nearest" });
|
|
55
|
+
} else input.removeAttribute("aria-activedescendant");
|
|
56
|
+
};
|
|
57
|
+
const filter = () => {
|
|
58
|
+
const q = input.value;
|
|
59
|
+
let shown = 0;
|
|
60
|
+
options().forEach((o) => { o.hidden = !matches(optionLabel(o), q); if (!o.hidden) shown++; });
|
|
61
|
+
if (empty) empty.hidden = shown > 0;
|
|
62
|
+
if (slot && !q) slot.innerHTML = placeholderIcon;
|
|
63
|
+
setActive(enabled()[0] ?? null);
|
|
64
|
+
};
|
|
65
|
+
const choose = (option) => {
|
|
66
|
+
if (!option || option.getAttribute("aria-disabled") === "true") return;
|
|
67
|
+
options().forEach((o) => o.setAttribute("aria-selected", String(o === option)));
|
|
68
|
+
const label = optionLabel(option);
|
|
69
|
+
const value = optionValue(option);
|
|
70
|
+
input.value = label;
|
|
71
|
+
if (hidden) hidden.value = value;
|
|
72
|
+
if (slot) slot.innerHTML = option.querySelector(".oc-combobox-option-icon")?.innerHTML ?? placeholderIcon;
|
|
73
|
+
options().forEach((o) => { o.hidden = false; });
|
|
74
|
+
if (empty) empty.hidden = true;
|
|
75
|
+
setOpen(false);
|
|
76
|
+
root.dispatchEvent(new CustomEvent("oc-combobox-change", { bubbles: true, detail: { value, label } }));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const onInput = () => { setOpen(true); filter(); };
|
|
80
|
+
const onKey = (e) => {
|
|
81
|
+
const items = enabled();
|
|
82
|
+
const at = items.findIndex((o) => o.hasAttribute("data-active"));
|
|
83
|
+
const move = (i) => { setOpen(true); setActive(items[(i + items.length) % items.length] ?? null); e.preventDefault(); };
|
|
84
|
+
if (e.key === "ArrowDown") move(root.dataset.open === "false" ? Math.max(at, 0) : at + 1);
|
|
85
|
+
else if (e.key === "ArrowUp") move(at <= 0 ? items.length - 1 : at - 1);
|
|
86
|
+
else if (e.key === "Home" && root.dataset.open !== "false") move(0);
|
|
87
|
+
else if (e.key === "End" && root.dataset.open !== "false") move(items.length - 1);
|
|
88
|
+
else if (e.key === "Enter" && at >= 0 && root.dataset.open !== "false") { e.preventDefault(); choose(items[at]); }
|
|
89
|
+
else if (e.key === "Escape" && root.dataset.open !== "false") { e.preventDefault(); setOpen(false); }
|
|
90
|
+
};
|
|
91
|
+
const onClickInput = () => { if (root.dataset.open === "false") setOpen(true); };
|
|
92
|
+
// A click on an option keeps the focus in the field (tabindex="-1" on the options does the rest).
|
|
93
|
+
const onDown = (e) => { if (e.target.closest(OPTION)) e.preventDefault(); };
|
|
94
|
+
const onClick = (e) => choose(e.target.closest(OPTION));
|
|
95
|
+
const onFocus = () => input.setAttribute("aria-expanded", String(root.dataset.open !== "false"));
|
|
96
|
+
const onBlur = (e) => {
|
|
97
|
+
if (root.contains(e.relatedTarget)) return;
|
|
98
|
+
input.setAttribute("aria-expanded", "false");
|
|
99
|
+
root.removeAttribute("data-open");
|
|
100
|
+
setActive(null);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
input.addEventListener("input", onInput);
|
|
104
|
+
input.addEventListener("keydown", onKey);
|
|
105
|
+
input.addEventListener("click", onClickInput);
|
|
106
|
+
list.addEventListener("mousedown", onDown);
|
|
107
|
+
list.addEventListener("click", onClick);
|
|
108
|
+
root.addEventListener("focusin", onFocus);
|
|
109
|
+
root.addEventListener("focusout", onBlur);
|
|
110
|
+
const chosen = options().find((o) => o.getAttribute("aria-selected") === "true");
|
|
111
|
+
if (chosen && slot) slot.innerHTML = chosen.querySelector(".oc-combobox-option-icon")?.innerHTML ?? placeholderIcon;
|
|
112
|
+
return () => {
|
|
113
|
+
input.removeEventListener("input", onInput);
|
|
114
|
+
input.removeEventListener("keydown", onKey);
|
|
115
|
+
input.removeEventListener("click", onClickInput);
|
|
116
|
+
list.removeEventListener("mousedown", onDown);
|
|
117
|
+
list.removeEventListener("click", onClick);
|
|
118
|
+
root.removeEventListener("focusin", onFocus);
|
|
119
|
+
root.removeEventListener("focusout", onBlur);
|
|
120
|
+
delete root.dataset.ocBound;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Starts every .oc-combobox[data-oc-combobox] in scope. Returns a function that stops them. */
|
|
125
|
+
export function initCombobox(scope = document) {
|
|
126
|
+
const stops = [...scope.querySelectorAll(".oc-combobox[data-oc-combobox]")].map(bindCombobox);
|
|
127
|
+
return () => stops.forEach((stop) => stop());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Starts on its own as /js/oc-combobox.js (`npx omniaui copy-js combobox`), with ?auto in the URL or data-oc-auto on
|
|
131
|
+
// the tag.
|
|
132
|
+
function autoStart() {
|
|
133
|
+
if (typeof document === "undefined") return false;
|
|
134
|
+
const url = String(import.meta.url);
|
|
135
|
+
if (url.includes("oc-combobox") || /[?&]auto(=|&|$)/.test(url)) return true;
|
|
136
|
+
const file = url.split(/[?#]/)[0];
|
|
137
|
+
return [...document.querySelectorAll("script[data-oc-auto][src]")].some((s) => s.src.split(/[?#]/)[0] === file);
|
|
138
|
+
}
|
|
139
|
+
if (autoStart()) {
|
|
140
|
+
const boot = () => initCombobox(document);
|
|
141
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", boot);
|
|
142
|
+
else boot();
|
|
143
|
+
}
|
|
@@ -456,12 +456,15 @@ a.oc-item:focus-visible { outline: 2px solid var(--oc-ring); outline-offset: 1px
|
|
|
456
456
|
.oc-carousel-dot {
|
|
457
457
|
inline-size: 0.5rem;
|
|
458
458
|
block-size: 0.5rem;
|
|
459
|
-
border-radius:
|
|
459
|
+
border-radius: 999px;
|
|
460
460
|
background: var(--oc-border-strong);
|
|
461
|
-
transition: background var(--oc-transition-fast);
|
|
461
|
+
transition: background var(--oc-transition-fast), inline-size var(--oc-transition-fast);
|
|
462
462
|
}
|
|
463
463
|
.oc-carousel-dot:hover,
|
|
464
464
|
.oc-carousel-dot:focus-visible { background: var(--oc-primary); }
|
|
465
|
+
.oc-carousel-dot:focus-visible { outline: 2px solid var(--oc-ring); outline-offset: 2px; }
|
|
466
|
+
/* the slide in view (set by carousel.js), the same look as the ::scroll-marker dots */
|
|
467
|
+
.oc-carousel-dot[aria-current="true"] { inline-size: 1.25rem; background: var(--oc-primary); }
|
|
465
468
|
@supports (scroll-marker-group: after) {
|
|
466
469
|
.oc-carousel-dots { display: none; }
|
|
467
470
|
.oc-carousel-viewport { scroll-marker-group: after; }
|
|
@@ -883,7 +886,8 @@ input.oc-input[type="month"] { inline-size: auto; min-inline-size: 11rem; }
|
|
|
883
886
|
padding: 0 0 0.25rem;
|
|
884
887
|
list-style: none;
|
|
885
888
|
border-block-end: 1px solid var(--oc-chart-grid);
|
|
886
|
-
|
|
889
|
+
/* one 1px line at the top of each quarter (a repeating gradient with calc(% - px) stops renders as solid bands in Firefox) */
|
|
890
|
+
background: linear-gradient(to bottom, var(--oc-chart-grid) 1px, transparent 1px) 0 0 / 100% 25% repeat-y;
|
|
887
891
|
}
|
|
888
892
|
.oc-chart-bars > * {
|
|
889
893
|
--oc-bar: 50%;
|