@birdycom/omniaui 0.12.6 → 0.14.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/bin/lib/copy-js.mjs +5 -1
- package/dist/components.css +1194 -45
- package/dist/components.min.css +1 -1
- package/dist/contact-form.d.ts +5 -0
- package/dist/contact-form.js +138 -0
- package/dist/fly.d.ts +4 -0
- package/dist/fly.js +80 -0
- package/dist/form-extras.d.ts +3 -1
- package/dist/form-extras.js +21 -3
- package/dist/oc-theme.css +3 -1
- package/dist/particles.d.ts +14 -0
- package/dist/particles.js +133 -0
- package/dist/parts/app-accordion-accent.css +18 -1
- package/dist/parts/app-callout.css +20 -0
- package/dist/parts/app-group.css +36 -0
- package/dist/parts/app-result.css +39 -0
- package/dist/parts/data-graph.css +132 -0
- package/dist/parts/data-meter-row.css +56 -3
- package/dist/parts/data-reading.css +26 -0
- package/dist/parts/forms-form.css +76 -0
- package/dist/parts/forms-language-select.css +18 -0
- package/dist/parts/media-lightbox.css +4 -0
- package/dist/parts/nav-menu-static.css +50 -0
- package/dist/parts/site-backgrounds.css +68 -0
- package/dist/parts/site-base.css +33 -0
- package/dist/parts/site-brand-mark.css +56 -0
- package/dist/parts/site-cards.css +184 -0
- package/dist/parts/site-fly.css +40 -0
- package/dist/parts/site-layout.css +69 -0
- package/dist/parts/site-neon.css +33 -0
- package/dist/parts/site-panel.css +29 -0
- package/dist/parts/site-prose.css +12 -0
- package/dist/parts/utility-hover.css +44 -0
- package/dist/showcase.css +83 -19
- package/manifest.json +136 -0
- package/package.json +5 -2
- package/snippets/accordion-accent.html +22 -0
- package/snippets/backgrounds.html +18 -0
- package/snippets/brand-mark.html +41 -0
- package/snippets/callout.html +17 -0
- package/snippets/feature-card.html +52 -0
- package/snippets/fly-in.html +30 -0
- package/snippets/graph.html +41 -0
- package/snippets/group.html +34 -0
- package/snippets/hover-effects.html +19 -0
- package/snippets/icon-list.html +28 -0
- package/snippets/language-select.html +11 -0
- package/snippets/lazy.html +7 -7
- package/snippets/menu-static.html +36 -0
- package/snippets/meter-row.html +22 -0
- package/snippets/name-card.html +4 -4
- package/snippets/neon.html +18 -0
- package/snippets/page-sections.html +50 -0
- package/snippets/panel.html +18 -0
- package/snippets/particle-field.html +14 -0
- package/snippets/reading.html +25 -0
- package/snippets/result.html +31 -0
- package/snippets/ribbon.html +8 -8
- package/snippets/shot-grid.html +27 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// File: packages/ui/src/contact-form.js
|
|
2
|
+
// Map: messages -> field errors -> busy -> send (fetch, JSON) -> result / errors -> "send another" -> boot
|
|
3
|
+
// Contact form without a page reload. The form keeps working without this script (POST + redirect); with it, it sends
|
|
4
|
+
// with fetch and shows the result or the errors in place.
|
|
5
|
+
// Protocol: POST the FormData to form.action with "Accept: application/json"; the server answers
|
|
6
|
+
// { sent: true } (200) or { sent: false, errors: { field: "message", form?: "message" } } (422); a list per field
|
|
7
|
+
// (Laravel: { errors: { email: ["…"] } }) shows its first message.
|
|
8
|
+
// Markup (data attributes, all inside [data-contact-root] or the document):
|
|
9
|
+
// form[data-contact-form] the form (novalidate); [data-contact-submit] its button, [data-contact-label] the text
|
|
10
|
+
// [data-contact-body] what hides after sending (title, intro, alert, form)
|
|
11
|
+
// [data-contact-success] the .oc-result that shows after sending (hidden, role="status", tabindex="-1")
|
|
12
|
+
// [data-contact-alert] the .oc-alert above the form (hidden), for errors.form or the general message
|
|
13
|
+
// [data-contact-again] the "Send another message" link or button in the result
|
|
14
|
+
// Field errors: aria-invalid="true" + aria-describedby on the field and <p class="oc-field-error" id="err-<name>">.
|
|
15
|
+
// Texts: data-busy-label, data-error-fields, data-error-network on the form (English by default).
|
|
16
|
+
|
|
17
|
+
const TEXT = {
|
|
18
|
+
busy: "Sending…",
|
|
19
|
+
fields: "Please check the fields in red.",
|
|
20
|
+
network: "Sending failed. Check your connection, or mail or call us directly.",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function clearFieldError(field) {
|
|
24
|
+
field.removeAttribute("aria-invalid");
|
|
25
|
+
field.removeAttribute("aria-describedby");
|
|
26
|
+
field.ownerDocument.getElementById(`err-${field.name}`)?.remove();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function setFieldError(field, message) {
|
|
30
|
+
const error = field.ownerDocument.createElement("p");
|
|
31
|
+
error.className = "oc-field-error";
|
|
32
|
+
error.id = `err-${field.name}`;
|
|
33
|
+
error.textContent = message;
|
|
34
|
+
field.setAttribute("aria-invalid", "true");
|
|
35
|
+
field.setAttribute("aria-describedby", error.id);
|
|
36
|
+
field.insertAdjacentElement("afterend", error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Send one form[data-contact-form] with fetch and show the result or the errors in place. */
|
|
40
|
+
export function initContactForm(form) {
|
|
41
|
+
if (!form || form.dataset.ocBound !== undefined || typeof fetch === "undefined") return;
|
|
42
|
+
form.dataset.ocBound = "";
|
|
43
|
+
const root = form.closest("[data-contact-root]") || form.ownerDocument;
|
|
44
|
+
const body = root.querySelector("[data-contact-body]");
|
|
45
|
+
const success = root.querySelector("[data-contact-success]");
|
|
46
|
+
const alertBox = root.querySelector("[data-contact-alert]");
|
|
47
|
+
const button = form.querySelector("[data-contact-submit]") || form.querySelector('[type="submit"]');
|
|
48
|
+
const label = form.querySelector("[data-contact-label]");
|
|
49
|
+
const idleLabel = label?.textContent ?? "";
|
|
50
|
+
const text = {
|
|
51
|
+
busy: form.dataset.busyLabel || TEXT.busy,
|
|
52
|
+
fields: form.dataset.errorFields || TEXT.fields,
|
|
53
|
+
network: form.dataset.errorNetwork || TEXT.network,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const showAlert = (message) => {
|
|
57
|
+
if (!alertBox) return;
|
|
58
|
+
alertBox.textContent = message;
|
|
59
|
+
alertBox.hidden = message === "";
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const setBusy = (busy) => {
|
|
63
|
+
if (button) button.disabled = busy;
|
|
64
|
+
form.setAttribute("aria-busy", String(busy));
|
|
65
|
+
if (label) label.textContent = busy ? text.busy : idleLabel;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// A field you change loses its error at once.
|
|
69
|
+
form.addEventListener("input", (event) => {
|
|
70
|
+
if (event.target.name) clearFieldError(event.target);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
form.addEventListener("submit", async (event) => {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
form.querySelectorAll("[aria-invalid]").forEach(clearFieldError);
|
|
76
|
+
showAlert("");
|
|
77
|
+
setBusy(true);
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(form.action, {
|
|
80
|
+
method: (form.getAttribute("method") || "POST").toUpperCase(),
|
|
81
|
+
body: new FormData(form),
|
|
82
|
+
headers: { Accept: "application/json" },
|
|
83
|
+
});
|
|
84
|
+
const result = await response.json();
|
|
85
|
+
if (result.sent) {
|
|
86
|
+
form.reset();
|
|
87
|
+
if (body) body.hidden = true;
|
|
88
|
+
if (success) {
|
|
89
|
+
success.hidden = false;
|
|
90
|
+
success.focus({ preventScroll: true });
|
|
91
|
+
success.scrollIntoView?.({ behavior: "smooth", block: "center" });
|
|
92
|
+
}
|
|
93
|
+
form.dispatchEvent(new CustomEvent("oc-contact-sent", { bubbles: true }));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Laravel sends a list per field ({ email: ["…"] }): the first message is shown.
|
|
97
|
+
const first = (message) => (Array.isArray(message) ? message[0] : message);
|
|
98
|
+
const errors = result.errors || {};
|
|
99
|
+
for (const [name, message] of Object.entries(errors)) {
|
|
100
|
+
const field = form.elements.namedItem(name);
|
|
101
|
+
if (field instanceof HTMLElement && "name" in field) setFieldError(field, first(message));
|
|
102
|
+
}
|
|
103
|
+
showAlert(first(errors.form) || text.fields);
|
|
104
|
+
(form.querySelector('[aria-invalid="true"]') || alertBox)?.focus?.();
|
|
105
|
+
} catch {
|
|
106
|
+
showAlert(text.network);
|
|
107
|
+
} finally {
|
|
108
|
+
setBusy(false);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// "Send another message": the form comes back without a reload.
|
|
113
|
+
root.querySelector("[data-contact-again]")?.addEventListener("click", (event) => {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
if (success) success.hidden = true;
|
|
116
|
+
if (body) body.hidden = false;
|
|
117
|
+
form.querySelector("input:not([type=hidden]):not([tabindex='-1']), textarea, select")?.focus();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Bind every contact form under scope. */
|
|
122
|
+
export function initContactForms(scope = document) {
|
|
123
|
+
scope.querySelectorAll("form[data-contact-form]").forEach(initContactForm);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Starts on its own as /js/oc-contact-form.js (`npx omniaui copy-js`), with ?auto in the URL or data-oc-auto on the tag.
|
|
127
|
+
function autoStart() {
|
|
128
|
+
if (typeof document === "undefined") return false;
|
|
129
|
+
const url = String(import.meta.url);
|
|
130
|
+
if (url.includes("oc-contact-form") || /[?&]auto(=|&|$)/.test(url)) return true;
|
|
131
|
+
const file = url.split(/[?#]/)[0];
|
|
132
|
+
return [...document.querySelectorAll("script[data-oc-auto][src]")].some((s) => s.src.split(/[?#]/)[0] === file);
|
|
133
|
+
}
|
|
134
|
+
if (autoStart()) {
|
|
135
|
+
const boot = () => initContactForms(document);
|
|
136
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", boot);
|
|
137
|
+
else boot();
|
|
138
|
+
}
|
package/dist/fly.d.ts
ADDED
package/dist/fly.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// File: packages/ui/src/fly.js
|
|
2
|
+
// Map: row of a card (index, count) -> start offset -> delay -> observe (once or both ways) -> boot
|
|
3
|
+
// Cards that fly in (.oc-reveal--fly): each card starts from the middle of its row (--oc-fly-x) and flies to its place
|
|
4
|
+
// when it scrolls into view (.is-visible). Adds .oc-fly-ready on <html> first, so without this script, or with
|
|
5
|
+
// "reduce motion", nothing is hidden.
|
|
6
|
+
// Options (CSS custom properties on a card or a parent, and one attribute):
|
|
7
|
+
// --oc-fly-step: 45px start offset per column from the middle of the row (instead of the full distance)
|
|
8
|
+
// --oc-fly-stagger: 90ms delay per column, so a row lands from left to right
|
|
9
|
+
// data-oc-fly-repeat the cards fly out again when they leave the view (both scroll directions)
|
|
10
|
+
|
|
11
|
+
/** Index of the card in its row (cards with the same top in the same parent) and the number of cards in that row. */
|
|
12
|
+
function rowOf(card) {
|
|
13
|
+
const top = card.offsetTop;
|
|
14
|
+
const row = [...(card.parentElement?.children ?? [])].filter((el) => el.classList.contains("oc-reveal--fly") && el.offsetTop === top);
|
|
15
|
+
return { index: Math.max(0, row.indexOf(card)), count: row.length || 1 };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Horizontal distance from the card to the middle of its parent, so the row opens from the center. */
|
|
19
|
+
function flyOffset(card, step, index, count) {
|
|
20
|
+
if (step) return Math.round(((count - 1) / 2 - index) * step);
|
|
21
|
+
const box = card.getBoundingClientRect();
|
|
22
|
+
const parent = card.parentElement?.getBoundingClientRect();
|
|
23
|
+
if (!parent || !box.width) return 0;
|
|
24
|
+
return Math.round(parent.left + parent.width / 2 - (box.left + box.width / 2));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** "90ms", "0.09s" or "45px" -> number (ms or px); 0 when empty. */
|
|
28
|
+
function num(value, unitS = false) {
|
|
29
|
+
const v = String(value).trim();
|
|
30
|
+
const n = parseFloat(v);
|
|
31
|
+
if (!v || Number.isNaN(n)) return 0;
|
|
32
|
+
return unitS && /\ds$/.test(v) ? n * 1000 : n;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Let every .oc-reveal--fly under scope fly in once it comes into view. Returns a function that stops watching. */
|
|
36
|
+
export function initFly(scope = document) {
|
|
37
|
+
const doc = scope.ownerDocument || scope;
|
|
38
|
+
const win = doc.defaultView;
|
|
39
|
+
const cards = [...scope.querySelectorAll(".oc-reveal--fly:not(.is-visible)")];
|
|
40
|
+
if (!cards.length || !win) return () => {};
|
|
41
|
+
if (!("IntersectionObserver" in win) || win.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
|
|
42
|
+
cards.forEach((c) => c.classList.add("is-visible"));
|
|
43
|
+
return () => {};
|
|
44
|
+
}
|
|
45
|
+
for (const card of cards) {
|
|
46
|
+
const style = win.getComputedStyle(card);
|
|
47
|
+
const { index, count } = rowOf(card);
|
|
48
|
+
card.style.setProperty("--oc-fly-x", `${flyOffset(card, num(style.getPropertyValue("--oc-fly-step")), index, count)}px`);
|
|
49
|
+
const stagger = num(style.getPropertyValue("--oc-fly-stagger"), true);
|
|
50
|
+
if (stagger) card.style.setProperty("--oc-fly-delay", `${index * stagger}ms`);
|
|
51
|
+
}
|
|
52
|
+
doc.documentElement.classList.add("oc-fly-ready");
|
|
53
|
+
const io = new win.IntersectionObserver((entries) => {
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
const repeat = entry.target.closest("[data-oc-fly-repeat]");
|
|
56
|
+
if (entry.isIntersecting) {
|
|
57
|
+
entry.target.classList.add("is-visible");
|
|
58
|
+
if (!repeat) io.unobserve(entry.target);
|
|
59
|
+
} else if (repeat) {
|
|
60
|
+
entry.target.classList.remove("is-visible");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, { rootMargin: "0px 0px -10% 0px", threshold: 0.12 });
|
|
64
|
+
cards.forEach((c) => io.observe(c));
|
|
65
|
+
return () => io.disconnect();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Starts on its own as /js/oc-fly.js (`npx omniaui copy-js`), with ?auto in the URL or data-oc-auto on the tag.
|
|
69
|
+
function autoStart() {
|
|
70
|
+
if (typeof document === "undefined") return false;
|
|
71
|
+
const url = String(import.meta.url);
|
|
72
|
+
if (url.includes("oc-fly") || /[?&]auto(=|&|$)/.test(url)) return true;
|
|
73
|
+
const file = url.split(/[?#]/)[0];
|
|
74
|
+
return [...document.querySelectorAll("script[data-oc-auto][src]")].some((s) => s.src.split(/[?#]/)[0] === file);
|
|
75
|
+
}
|
|
76
|
+
if (autoStart()) {
|
|
77
|
+
const boot = () => initFly(document);
|
|
78
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", boot);
|
|
79
|
+
else boot();
|
|
80
|
+
}
|
package/dist/form-extras.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// File: packages/ui/src/form-extras.d.ts
|
|
2
|
-
// Types for the date field (ISO week), name card (rename), avatar picker (preview)
|
|
2
|
+
// Types for the date field (ISO week), name card (rename), avatar picker (preview), quantity (step) and language code helpers.
|
|
3
3
|
|
|
4
4
|
export function isoWeek(date: Date): { week: number; year: number };
|
|
5
5
|
export function bindDateField(root: HTMLElement): void;
|
|
@@ -8,4 +8,6 @@ export function acceptsFile(file: { type?: string; name?: string } | null | unde
|
|
|
8
8
|
export function bindAvatarPicker(root: HTMLElement): void;
|
|
9
9
|
export function stepQuantity(value: number, direction: -1 | 1, limits?: { min?: number; max?: number; step?: number }): number;
|
|
10
10
|
export function bindQuantity(root: HTMLElement): void;
|
|
11
|
+
export function languageCode(select: HTMLSelectElement): string;
|
|
12
|
+
export function bindLanguageCode(root: HTMLElement): void;
|
|
11
13
|
export function initFormExtras(scope?: ParentNode): void;
|
package/dist/form-extras.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// File: packages/ui/src/form-extras.js
|
|
2
2
|
// Map: ISO week -> date field (week label) -> name card (rename) -> avatar picker (preview, drop, remove) -> quantity
|
|
3
|
-
// (step buttons) -> init -> boot
|
|
4
|
-
// Small behaviour for
|
|
3
|
+
// (step buttons) -> language code (the closed code select) -> init -> boot
|
|
4
|
+
// Small behaviour for five CSS components; each works without it (native date input, <details>, file input, number input,
|
|
5
|
+
// native select).
|
|
5
6
|
// Events on the component root: oc-namecard-rename { name }, oc-avatar-change { file } (null when removed),
|
|
6
7
|
// oc-avatar-invalid { file, reason } (wrong type or too large).
|
|
7
8
|
|
|
@@ -191,12 +192,29 @@ export function bindQuantity(root) {
|
|
|
191
192
|
sync();
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
/**
|
|
195
|
+
/** The code shown by a closed .oc-language-select--code: the chosen option's data-code, else its value, upper case. */
|
|
196
|
+
export function languageCode(select) {
|
|
197
|
+
const option = select.selectedOptions?.[0] ?? select.options?.[select.selectedIndex];
|
|
198
|
+
return String(option?.dataset.code || select.value || "").toUpperCase();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** .oc-language-select--code: keep data-code on the wrapper in step with the select. */
|
|
202
|
+
export function bindLanguageCode(root) {
|
|
203
|
+
const select = root.querySelector("select");
|
|
204
|
+
if (!select || root.dataset.ocBound) return;
|
|
205
|
+
root.dataset.ocBound = "";
|
|
206
|
+
const sync = () => { root.dataset.code = languageCode(select); };
|
|
207
|
+
select.addEventListener("change", sync);
|
|
208
|
+
sync();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Wire every date field, name card, avatar picker, quantity field and code language select under scope. */
|
|
195
212
|
export function initFormExtras(scope = document) {
|
|
196
213
|
scope.querySelectorAll(".oc-date-field").forEach(bindDateField);
|
|
197
214
|
scope.querySelectorAll(".oc-name-card").forEach(bindNameCard);
|
|
198
215
|
scope.querySelectorAll(".oc-avatar-picker").forEach(bindAvatarPicker);
|
|
199
216
|
scope.querySelectorAll(".oc-quantity").forEach(bindQuantity);
|
|
217
|
+
scope.querySelectorAll(".oc-language-select--code").forEach(bindLanguageCode);
|
|
200
218
|
}
|
|
201
219
|
|
|
202
220
|
// Starts on its own as /js/oc-form-extras.js (`npx omniaui copy-js`), with ?auto in the URL or data-oc-auto on the tag.
|
package/dist/oc-theme.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* File: oc-theme.css — generated from tokens/semantic.json by @birdycom/omniacss 0.
|
|
1
|
+
/* File: oc-theme.css — generated from tokens/semantic.json by @birdycom/omniacss 0.14.0. Do not edit. */
|
|
2
2
|
/* Semantic theme tokens: every color is light-dark() of an Omnia palette token (oc-colors.css). */
|
|
3
3
|
/* Same source as the desktop export: npx omniacss tokens --format json|dtcg|python */
|
|
4
4
|
:root {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
--oc-foreground: light-dark(var(--color-duskblue-60), var(--color-frostblue-10));
|
|
15
15
|
--oc-muted: light-dark(var(--color-frostblue-60), var(--color-shallowblue-50));
|
|
16
16
|
--oc-muted-foreground: light-dark(var(--color-stormblue-40), var(--color-mistblue-70));
|
|
17
|
+
--oc-subtle-foreground: light-dark(var(--color-stormblue-10), var(--color-mistblue-95));
|
|
17
18
|
--oc-card: light-dark(var(--color-white-50), var(--color-shallowblue-70));
|
|
18
19
|
--oc-popover: light-dark(var(--color-white-50), var(--color-shallowblue-60));
|
|
19
20
|
--oc-popover-foreground: var(--oc-foreground);
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
--oc-transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
59
60
|
--oc-font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Cantarell, "Helvetica Neue", sans-serif;
|
|
60
61
|
--oc-font-mono: "Cascadia Code", "JetBrains Mono", Consolas, ui-monospace, monospace;
|
|
62
|
+
--oc-font-display: system-ui, -apple-system, "Segoe UI", Roboto, Cantarell, "Helvetica Neue", sans-serif;
|
|
61
63
|
|
|
62
64
|
/* Shadows (x y blur spread; color + alpha per mode in --oc-shadow-<name>-color) */
|
|
63
65
|
--oc-shadow-sm-color: light-dark(oklch(from var(--color-stormblue-50) l c h / 0.08), oklch(from var(--color-black-50) l c h / 0.4));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// File: packages/ui/src/particles.d.ts
|
|
2
|
+
// Types for the particle field script (canvas.oc-particles).
|
|
3
|
+
|
|
4
|
+
export interface ParticleOptions {
|
|
5
|
+
/** Number of points (110). */
|
|
6
|
+
count?: number;
|
|
7
|
+
/** Speed of the drift (0.35). */
|
|
8
|
+
speed?: number;
|
|
9
|
+
/** Distance in px under which two points get a line (115). */
|
|
10
|
+
link?: number;
|
|
11
|
+
}
|
|
12
|
+
export function particleOptions(canvas: HTMLCanvasElement): Required<ParticleOptions>;
|
|
13
|
+
export function initParticles(canvas: HTMLCanvasElement, options?: ParticleOptions): () => void;
|
|
14
|
+
export function initParticleFields(scope?: ParentNode): () => void;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// File: packages/ui/src/particles.js
|
|
2
|
+
// Map: options (data attributes) -> colors from CSS (re-read on a theme change) -> size (the canvas box x device pixels)
|
|
3
|
+
// -> particles -> frame (move, dot, lines to close neighbours) -> pause when hidden -> boot
|
|
4
|
+
// Particle field (canvas.oc-particles): slowly drifting points with thin lines between points that are close together.
|
|
5
|
+
// Colors come from the canvas's CSS: color (points and lines) and border-color (a second point color), so a theme
|
|
6
|
+
// switch (data-theme or a class on <html>, or the OS setting) recolors it. With "reduce motion" it draws one still frame.
|
|
7
|
+
// Options (data attributes on the canvas): data-count (110), data-speed (0.35), data-link (115, the line distance in px).
|
|
8
|
+
|
|
9
|
+
/** Numbers from the canvas's data attributes, with the defaults. */
|
|
10
|
+
export function particleOptions(canvas) {
|
|
11
|
+
const num = (name, fallback) => {
|
|
12
|
+
const n = parseFloat(canvas.dataset?.[name] ?? "");
|
|
13
|
+
return Number.isFinite(n) && n >= 0 ? n : fallback;
|
|
14
|
+
};
|
|
15
|
+
return { count: Math.round(num("count", 110)), speed: num("speed", 0.35), link: num("link", 115) };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Start the field on one canvas (once). Returns a function that stops it. */
|
|
19
|
+
export function initParticles(canvas, options = {}) {
|
|
20
|
+
if (!canvas || canvas.dataset.ocBound !== undefined) return () => {};
|
|
21
|
+
const ctx = canvas.getContext?.("2d");
|
|
22
|
+
const win = canvas.ownerDocument?.defaultView;
|
|
23
|
+
if (!ctx || !win) return () => {};
|
|
24
|
+
canvas.dataset.ocBound = "";
|
|
25
|
+
const { count, speed, link } = { ...particleOptions(canvas), ...options };
|
|
26
|
+
const still = win.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
27
|
+
|
|
28
|
+
let width = 0, height = 0;
|
|
29
|
+
const resize = () => {
|
|
30
|
+
const ratio = win.devicePixelRatio || 1;
|
|
31
|
+
width = canvas.clientWidth || win.innerWidth;
|
|
32
|
+
height = canvas.clientHeight || win.innerHeight;
|
|
33
|
+
canvas.width = Math.round(width * ratio);
|
|
34
|
+
canvas.height = Math.round(height * ratio);
|
|
35
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
36
|
+
};
|
|
37
|
+
resize();
|
|
38
|
+
|
|
39
|
+
let lineColor = "", colors = [];
|
|
40
|
+
const readColors = () => {
|
|
41
|
+
const cs = win.getComputedStyle(canvas);
|
|
42
|
+
lineColor = cs.color;
|
|
43
|
+
colors = [cs.color, cs.borderTopColor, cs.color];
|
|
44
|
+
};
|
|
45
|
+
readColors();
|
|
46
|
+
|
|
47
|
+
const particles = Array.from({ length: count }, (_, i) => ({
|
|
48
|
+
x: Math.random() * width,
|
|
49
|
+
y: Math.random() * height,
|
|
50
|
+
vx: (Math.random() - 0.5) * speed,
|
|
51
|
+
vy: (Math.random() - 0.5) * speed,
|
|
52
|
+
r: Math.random() * 1.8 + 0.4,
|
|
53
|
+
alpha: Math.random() * 0.55 + 0.1,
|
|
54
|
+
tone: i % 3,
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
const frame = (move) => {
|
|
58
|
+
ctx.clearRect(0, 0, width, height);
|
|
59
|
+
particles.forEach((p, i) => {
|
|
60
|
+
if (move) {
|
|
61
|
+
p.x += p.vx; p.y += p.vy;
|
|
62
|
+
if (p.x < 0 || p.x > width) p.vx *= -1;
|
|
63
|
+
if (p.y < 0 || p.y > height) p.vy *= -1;
|
|
64
|
+
}
|
|
65
|
+
ctx.beginPath();
|
|
66
|
+
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
|
|
67
|
+
ctx.fillStyle = colors[p.tone];
|
|
68
|
+
ctx.globalAlpha = p.alpha;
|
|
69
|
+
ctx.fill();
|
|
70
|
+
// Lines only to the next few points: cheap, and enough to look like a network.
|
|
71
|
+
for (let j = i + 1; j < Math.min(i + 5, particles.length); j++) {
|
|
72
|
+
const q = particles[j];
|
|
73
|
+
const d = Math.hypot(p.x - q.x, p.y - q.y);
|
|
74
|
+
if (d >= link) continue;
|
|
75
|
+
ctx.beginPath();
|
|
76
|
+
ctx.moveTo(p.x, p.y);
|
|
77
|
+
ctx.lineTo(q.x, q.y);
|
|
78
|
+
ctx.strokeStyle = lineColor;
|
|
79
|
+
ctx.globalAlpha = (1 - d / link) * 0.1;
|
|
80
|
+
ctx.lineWidth = 0.5;
|
|
81
|
+
ctx.stroke();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
ctx.globalAlpha = 1;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
let raf = 0;
|
|
88
|
+
const loop = () => { frame(true); raf = win.requestAnimationFrame(loop); };
|
|
89
|
+
const start = () => { if (!still && !raf) raf = win.requestAnimationFrame(loop); };
|
|
90
|
+
const pause = () => { win.cancelAnimationFrame(raf); raf = 0; };
|
|
91
|
+
const onVisibility = () => (canvas.ownerDocument.hidden ? pause() : start());
|
|
92
|
+
const onResize = () => { resize(); if (still) frame(false); };
|
|
93
|
+
const recolor = () => { readColors(); if (still) frame(false); };
|
|
94
|
+
|
|
95
|
+
const themeObserver = new win.MutationObserver(recolor);
|
|
96
|
+
themeObserver.observe(canvas.ownerDocument.documentElement, { attributes: true, attributeFilter: ["data-theme", "class", "style"] });
|
|
97
|
+
const scheme = win.matchMedia?.("(prefers-color-scheme: dark)");
|
|
98
|
+
scheme?.addEventListener?.("change", recolor);
|
|
99
|
+
const sizeObserver = typeof win.ResizeObserver === "function" ? new win.ResizeObserver(onResize) : null;
|
|
100
|
+
if (sizeObserver) sizeObserver.observe(canvas); else win.addEventListener("resize", onResize);
|
|
101
|
+
canvas.ownerDocument.addEventListener("visibilitychange", onVisibility);
|
|
102
|
+
|
|
103
|
+
if (still) frame(false); else start();
|
|
104
|
+
return () => {
|
|
105
|
+
pause();
|
|
106
|
+
themeObserver.disconnect();
|
|
107
|
+
scheme?.removeEventListener?.("change", recolor);
|
|
108
|
+
sizeObserver?.disconnect();
|
|
109
|
+
win.removeEventListener("resize", onResize);
|
|
110
|
+
canvas.ownerDocument.removeEventListener("visibilitychange", onVisibility);
|
|
111
|
+
delete canvas.dataset.ocBound;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Start every canvas.oc-particles under scope. Returns a function that stops them all. */
|
|
116
|
+
export function initParticleFields(scope = document) {
|
|
117
|
+
const stops = [...scope.querySelectorAll("canvas.oc-particles")].map((c) => initParticles(c));
|
|
118
|
+
return () => stops.forEach((stop) => stop());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Starts on its own as /js/oc-particles.js (`npx omniaui copy-js`), with ?auto in the URL or data-oc-auto on the tag.
|
|
122
|
+
function autoStart() {
|
|
123
|
+
if (typeof document === "undefined") return false;
|
|
124
|
+
const url = String(import.meta.url);
|
|
125
|
+
if (url.includes("oc-particles") || /[?&]auto(=|&|$)/.test(url)) return true;
|
|
126
|
+
const file = url.split(/[?#]/)[0];
|
|
127
|
+
return [...document.querySelectorAll("script[data-oc-auto][src]")].some((s) => s.src.split(/[?#]/)[0] === file);
|
|
128
|
+
}
|
|
129
|
+
if (autoStart()) {
|
|
130
|
+
const boot = () => initParticleFields(document);
|
|
131
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", boot);
|
|
132
|
+
else boot();
|
|
133
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* File: packages/ui/src/parts/app-accordion-accent.css | Map: accent accordion (separate cards) -> item card + left accent -> trigger -> open state -> color modifiers (presets) -> flush combination */
|
|
1
|
+
/* File: packages/ui/src/parts/app-accordion-accent.css | Map: accent accordion (separate cards) -> item card + left accent -> trigger -> open state -> color modifiers (presets) -> status (data-status) -> status dot -> flush combination */
|
|
2
2
|
/* Accordion accent: every item becomes its own card with a colored accent on the start edge.
|
|
3
3
|
Add .oc-accordion--accent to an .oc-accordion. The color comes from --oc-accordion-accent:
|
|
4
4
|
primary by default, or an existing .oc-accent--* preset (blue, cyan, green, orange, red, violet, yellow)
|
|
@@ -52,6 +52,23 @@
|
|
|
52
52
|
.oc-accordion--accent .oc-accordion-item--danger,
|
|
53
53
|
.oc-accordion--accent.oc-accordion--danger .oc-accordion-item { --oc-accordion-accent: var(--oc-destructive); }
|
|
54
54
|
|
|
55
|
+
/* Info and muted (not checked, skipped). */
|
|
56
|
+
.oc-accordion--accent .oc-accordion-item--info { --oc-accordion-accent: var(--oc-info, light-dark(var(--color-deepskyblue-70), var(--color-skyblue-50))); }
|
|
57
|
+
.oc-accordion--accent .oc-accordion-item--muted { --oc-accordion-accent: var(--oc-muted-foreground); }
|
|
58
|
+
|
|
59
|
+
/* Status of a check (one row per check): data-status="ok|warn|error|skip|pending" on the item. Pending is primary. */
|
|
60
|
+
.oc-accordion--accent .oc-accordion-item[data-status="ok"] { --oc-accordion-accent: var(--oc-success); }
|
|
61
|
+
.oc-accordion--accent .oc-accordion-item[data-status="warn"] { --oc-accordion-accent: var(--oc-warning); }
|
|
62
|
+
.oc-accordion--accent .oc-accordion-item[data-status="error"] { --oc-accordion-accent: var(--oc-destructive); }
|
|
63
|
+
.oc-accordion--accent .oc-accordion-item[data-status="skip"] { --oc-accordion-accent: var(--oc-muted-foreground); }
|
|
64
|
+
.oc-accordion--accent .oc-accordion-item[data-status="pending"] { --oc-accordion-accent: var(--oc-primary); }
|
|
65
|
+
.oc-accordion--accent .oc-accordion-item[data-status="skip"] > .oc-accordion-trigger { color: var(--oc-muted-foreground); }
|
|
66
|
+
|
|
67
|
+
/* A dot in the status color at the start of the trigger (hollow while pending). */
|
|
68
|
+
.oc-accordion-accent-dot { flex-shrink: 0; inline-size: 0.5rem; block-size: 0.5rem; border-radius: 50%; background: var(--oc-accordion-accent); }
|
|
69
|
+
.oc-accordion-trigger:has(> .oc-accordion-accent-dot) { justify-content: flex-start; gap: 0.6rem; }
|
|
70
|
+
.oc-accordion-item[data-status="pending"] .oc-accordion-accent-dot { background: transparent; border: 1.5px solid var(--oc-accordion-accent); }
|
|
71
|
+
|
|
55
72
|
/* Accent + flush: no frame around each card except the accent edge. */
|
|
56
73
|
.oc-accordion--accent.oc-accordion--flush .oc-accordion-item { border-block: 0; border-inline-end: 0; border-radius: 0; }
|
|
57
74
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* File: packages/ui/src/parts/app-callout.css | Map: card row (text + action) -> text -> action -> narrow: action under the text */
|
|
2
|
+
/* Callout: a small card with a text on the left and one action on the right ("Like the app? Support it" + a button).
|
|
3
|
+
Centred vertically; when the card is narrower than about 300px the action moves under the text. */
|
|
4
|
+
|
|
5
|
+
.oc-callout {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-wrap: wrap;
|
|
8
|
+
align-items: center;
|
|
9
|
+
gap: 0.5rem 0.75rem;
|
|
10
|
+
padding: 11px 13px;
|
|
11
|
+
color: var(--oc-card-foreground, var(--oc-foreground));
|
|
12
|
+
background: var(--oc-card-background, var(--oc-card));
|
|
13
|
+
border: 1px solid var(--oc-card-border, var(--oc-border));
|
|
14
|
+
border-radius: var(--oc-radius);
|
|
15
|
+
}
|
|
16
|
+
/* 12rem basis: next to a button the text wraps under it at about 300px. */
|
|
17
|
+
.oc-callout__text { flex: 1 1 12rem; min-inline-size: 0; margin: 0; font-size: 0.85rem; line-height: 1.45; }
|
|
18
|
+
.oc-callout__text strong { display: block; color: var(--oc-foreground); }
|
|
19
|
+
.oc-callout__text > :is(p, span):not(:first-child) { color: var(--oc-muted-foreground); }
|
|
20
|
+
.oc-callout__action { flex-shrink: 0; display: flex; gap: 0.5rem; }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* File: packages/ui/src/parts/app-group.css | Map: group -> head (title + aside) -> meta line -> hairline between groups */
|
|
2
|
+
/* Group: one section inside a panel or widget (a service, an account), with a title, a short status on the right
|
|
3
|
+
("2 busy") and a muted line under it. Consecutive groups get a hairline between them.
|
|
4
|
+
<section class="oc-group"><header class="oc-group__head"><h2 class="oc-group__title">…</h2><span class="oc-group__aside">…</span></header>
|
|
5
|
+
<p class="oc-group__meta">…</p> … </section> The aside takes a color from data-tone="busy|ok|warn|error". */
|
|
6
|
+
|
|
7
|
+
.oc-group { padding: 14px 0 6px; }
|
|
8
|
+
.oc-group + .oc-group { border-block-start: 1px solid var(--oc-group-line, var(--oc-glass-hairline, var(--oc-border))); }
|
|
9
|
+
.oc-group__head {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: baseline;
|
|
12
|
+
justify-content: space-between;
|
|
13
|
+
gap: 0.75rem;
|
|
14
|
+
margin-block-end: 0.25rem;
|
|
15
|
+
}
|
|
16
|
+
.oc-group__title {
|
|
17
|
+
min-inline-size: 0;
|
|
18
|
+
margin: 0;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
font-size: 0.875rem;
|
|
21
|
+
font-weight: 600;
|
|
22
|
+
text-overflow: ellipsis;
|
|
23
|
+
white-space: nowrap;
|
|
24
|
+
}
|
|
25
|
+
.oc-group__aside {
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
font-size: 0.75rem;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
font-variant-numeric: tabular-nums;
|
|
30
|
+
color: var(--oc-group-tone, var(--oc-muted-foreground));
|
|
31
|
+
}
|
|
32
|
+
.oc-group__aside[data-tone="busy"] { --oc-group-tone: var(--oc-primary); }
|
|
33
|
+
.oc-group__aside[data-tone="ok"] { --oc-group-tone: var(--oc-success); }
|
|
34
|
+
.oc-group__aside[data-tone="warn"] { --oc-group-tone: var(--oc-warning); }
|
|
35
|
+
.oc-group__aside[data-tone="error"] { --oc-group-tone: var(--oc-destructive); }
|
|
36
|
+
.oc-group__meta { margin: 0 0 0.625rem; font-size: 0.75rem; color: var(--oc-muted-foreground); }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* File: packages/ui/src/parts/app-result.css */
|
|
2
|
+
/* Map: result -> icon tile -> title -> text -> actions */
|
|
3
|
+
/* The outcome of an action in the place where the form was: "Thank you, your message was sent" with an icon tile, a
|
|
4
|
+
short text and a button ("Send another message"). Give it role="status" and tabindex="-1" and move the focus to it.
|
|
5
|
+
--center centers it; the tile takes its color from an .oc-accent--* preset. */
|
|
6
|
+
|
|
7
|
+
.oc-result {
|
|
8
|
+
display: grid;
|
|
9
|
+
justify-items: start;
|
|
10
|
+
gap: 0.75rem;
|
|
11
|
+
}
|
|
12
|
+
.oc-result:focus { outline: none; }
|
|
13
|
+
.oc-result[hidden] { display: none; }
|
|
14
|
+
.oc-result > .oc-icon-tile { margin-block-end: 0.35rem; }
|
|
15
|
+
.oc-result__title {
|
|
16
|
+
margin: 0;
|
|
17
|
+
font-size: 1.2rem;
|
|
18
|
+
line-height: 1.25;
|
|
19
|
+
}
|
|
20
|
+
.oc-result__text {
|
|
21
|
+
margin: 0;
|
|
22
|
+
color: var(--oc-muted-foreground);
|
|
23
|
+
}
|
|
24
|
+
.oc-result__text a {
|
|
25
|
+
color: var(--oc-primary);
|
|
26
|
+
text-decoration: underline;
|
|
27
|
+
text-underline-offset: 3px;
|
|
28
|
+
}
|
|
29
|
+
.oc-result__actions {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-wrap: wrap;
|
|
32
|
+
gap: 0.75rem;
|
|
33
|
+
margin-block-start: 0.5rem;
|
|
34
|
+
}
|
|
35
|
+
.oc-result--center {
|
|
36
|
+
justify-items: center;
|
|
37
|
+
text-align: center;
|
|
38
|
+
}
|
|
39
|
+
.oc-result--center .oc-result__actions { justify-content: center; }
|