@monster-orange/den-ui 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +75 -2
- package/package.json +21 -4
- package/src/base.css +80 -0
- package/src/busy-words.js +65 -0
- package/src/busy.js +592 -0
- package/src/dialog.js +217 -0
- package/src/fonts/OFL.txt +97 -0
- package/src/fonts/rubik-latin-400-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-500-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-ext-400-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-ext-500-normal.woff2 +0 -0
- package/src/fonts/space-mono-latin-400-normal.woff2 +0 -0
- package/src/fonts/space-mono-latin-ext-400-normal.woff2 +0 -0
- package/src/fonts.css +71 -0
- package/src/time.js +242 -0
- package/src/tokens.css +150 -0
- package/src/update-pill.css +32 -0
- package/src/update-pill.js +95 -0
package/src/tokens.css
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* den-ui tokens (UK-1). The kit's defaults: a theme laid on top overrides
|
|
3
|
+
* colours (both modes), shadow, bar, type, radius, radius-button, density
|
|
4
|
+
* and fonts; never spacing, motion or layers. Every rule here has zero
|
|
5
|
+
* specificity (:where), so any theme rule wins.
|
|
6
|
+
*
|
|
7
|
+
* Mode: <html data-mode="light|dark">. With none set, light, or dark when
|
|
8
|
+
* the system asks for it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* Type, shape, space, depth, motion, layers, targets: one set, both modes. */
|
|
12
|
+
:where(:root) {
|
|
13
|
+
--sans:
|
|
14
|
+
"Rubik", -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
|
|
15
|
+
"Noto Sans JP", sans-serif;
|
|
16
|
+
--mono: "Space Mono", ui-monospace, Menlo, Consolas, monospace;
|
|
17
|
+
--display: var(--sans);
|
|
18
|
+
--ja:
|
|
19
|
+
"Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
|
|
20
|
+
--fs-xs: 12px;
|
|
21
|
+
--fs-s: 13px;
|
|
22
|
+
--fs-m: 14px;
|
|
23
|
+
--fs-l: 15px;
|
|
24
|
+
--fs-xl: 18px;
|
|
25
|
+
--fs-2xl: 22px;
|
|
26
|
+
--lh: 1.45;
|
|
27
|
+
|
|
28
|
+
--radius: 6px;
|
|
29
|
+
--radius-button: 0.2rem;
|
|
30
|
+
--r: var(--radius);
|
|
31
|
+
--r-btn: var(--radius-button);
|
|
32
|
+
|
|
33
|
+
--density: 1;
|
|
34
|
+
--space-1: calc(4px * var(--density));
|
|
35
|
+
--space-2: calc(8px * var(--density));
|
|
36
|
+
--space-3: calc(12px * var(--density));
|
|
37
|
+
--space-4: calc(16px * var(--density));
|
|
38
|
+
--space-5: calc(24px * var(--density));
|
|
39
|
+
--space-6: calc(32px * var(--density));
|
|
40
|
+
|
|
41
|
+
--shadow-menu: var(--shadow);
|
|
42
|
+
--shadow-dialog: var(--shadow);
|
|
43
|
+
--shadow-bar: 0 6px 18px color-mix(in srgb, var(--text) 14%, transparent);
|
|
44
|
+
|
|
45
|
+
--dur-fast: 120ms;
|
|
46
|
+
--dur: 200ms;
|
|
47
|
+
--dur-cue: 400ms;
|
|
48
|
+
--ease: cubic-bezier(0.2, 0, 0, 1);
|
|
49
|
+
|
|
50
|
+
--z-menu: 10;
|
|
51
|
+
--z-bar: 30;
|
|
52
|
+
--z-drawer: 35;
|
|
53
|
+
--z-dialog: 40;
|
|
54
|
+
--z-palette: 45;
|
|
55
|
+
--z-toast: 50;
|
|
56
|
+
|
|
57
|
+
--tap: 44px;
|
|
58
|
+
--tap-min: 36px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* Light: the default. */
|
|
62
|
+
:where(:root),
|
|
63
|
+
:where(:root[data-mode="light"]) {
|
|
64
|
+
color-scheme: light;
|
|
65
|
+
--bg: #fffcfc;
|
|
66
|
+
--surface: #ffffff;
|
|
67
|
+
--raised: #ffffff;
|
|
68
|
+
--sunken: #f4efee;
|
|
69
|
+
--text: hsl(220 6% 10%);
|
|
70
|
+
--muted: hsl(220 5% 34%);
|
|
71
|
+
--faint: #62656a;
|
|
72
|
+
--border: hsl(20 12% 86%);
|
|
73
|
+
--border-strong: #97867f;
|
|
74
|
+
--accent: #e16500;
|
|
75
|
+
--accent-text: #a34a00;
|
|
76
|
+
--accent-fill: #c23f00;
|
|
77
|
+
--on-accent: #ffffff;
|
|
78
|
+
--ok: #11692f;
|
|
79
|
+
--warn: #865700;
|
|
80
|
+
--bad: #af0900;
|
|
81
|
+
--info: hsl(213 22% 36%);
|
|
82
|
+
/* #0e7280 failed the pill rule over --sunken (4.20:1); 4.59:1 now. */
|
|
83
|
+
--remote: #0d6b79;
|
|
84
|
+
--violet: #6a4bc4;
|
|
85
|
+
--shadow: 0 8px 28px rgb(0 0 0 / 0.14);
|
|
86
|
+
/* The shared update pill's shadow (update-pill.css). */
|
|
87
|
+
--upd-shadow:
|
|
88
|
+
0 2px 4px rgba(32,38,29,.07), 0 10px 28px rgba(32,38,29,.10),
|
|
89
|
+
inset 0 1px 0 color-mix(in srgb, var(--text) 14%, transparent);
|
|
90
|
+
--bar: linear-gradient(90deg, #ff7300, #af0900);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* Dark: asked for, or the system's choice when no mode is set. */
|
|
94
|
+
:where(:root[data-mode="dark"]) {
|
|
95
|
+
color-scheme: dark;
|
|
96
|
+
--bg: hsl(220 6% 10%);
|
|
97
|
+
--surface: hsl(220 6% 8.5%);
|
|
98
|
+
--raised: #1f2023;
|
|
99
|
+
--sunken: hsl(220 6% 7%);
|
|
100
|
+
--text: #fffcfc;
|
|
101
|
+
--muted: #c4c4c4;
|
|
102
|
+
--faint: #a3a3a3;
|
|
103
|
+
--border: hsl(220 5% 20%);
|
|
104
|
+
--border-strong: #676a71;
|
|
105
|
+
--accent: #ff7300;
|
|
106
|
+
--accent-text: #ff8f33;
|
|
107
|
+
--accent-fill: #ff7300;
|
|
108
|
+
--on-accent: hsl(220 6% 10%);
|
|
109
|
+
--ok: #4cc777;
|
|
110
|
+
--warn: #e3a72f;
|
|
111
|
+
--bad: #ff5a4f;
|
|
112
|
+
--info: hsl(213 30% 74%);
|
|
113
|
+
--remote: #4fd1db;
|
|
114
|
+
--violet: #a993ff;
|
|
115
|
+
--shadow: 0 12px 30px rgb(0 0 0 / 0.5);
|
|
116
|
+
--upd-shadow:
|
|
117
|
+
0 2px 4px rgba(0,0,0,.35), 0 10px 28px rgba(0,0,0,.4),
|
|
118
|
+
inset 0 1px 0 color-mix(in srgb, var(--text) 14%, transparent);
|
|
119
|
+
--bar: linear-gradient(90deg, #ff7300, #af0900);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@media (prefers-color-scheme: dark) {
|
|
123
|
+
:where(:root:not([data-mode])) {
|
|
124
|
+
color-scheme: dark;
|
|
125
|
+
--bg: hsl(220 6% 10%);
|
|
126
|
+
--surface: hsl(220 6% 8.5%);
|
|
127
|
+
--raised: #1f2023;
|
|
128
|
+
--sunken: hsl(220 6% 7%);
|
|
129
|
+
--text: #fffcfc;
|
|
130
|
+
--muted: #c4c4c4;
|
|
131
|
+
--faint: #a3a3a3;
|
|
132
|
+
--border: hsl(220 5% 20%);
|
|
133
|
+
--border-strong: #676a71;
|
|
134
|
+
--accent: #ff7300;
|
|
135
|
+
--accent-text: #ff8f33;
|
|
136
|
+
--accent-fill: #ff7300;
|
|
137
|
+
--on-accent: hsl(220 6% 10%);
|
|
138
|
+
--ok: #4cc777;
|
|
139
|
+
--warn: #e3a72f;
|
|
140
|
+
--bad: #ff5a4f;
|
|
141
|
+
--info: hsl(213 30% 74%);
|
|
142
|
+
--remote: #4fd1db;
|
|
143
|
+
--violet: #a993ff;
|
|
144
|
+
--shadow: 0 12px 30px rgb(0 0 0 / 0.5);
|
|
145
|
+
--upd-shadow:
|
|
146
|
+
0 2px 4px rgba(0,0,0,.35), 0 10px 28px rgba(0,0,0,.4),
|
|
147
|
+
inset 0 1px 0 color-mix(in srgb, var(--text) 14%, transparent);
|
|
148
|
+
--bar: linear-gradient(90deg, #ff7300, #af0900);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* den-ui: the shared update pill. Over the top bar and see-through: no
|
|
2
|
+
full-width strip; the pill's own fill is the surface at 20% with a blur, so
|
|
3
|
+
the bar shows through it, and the bar beside it stays clickable.
|
|
4
|
+
Tokens it reads: --surface --text --muted --border-strong --accent
|
|
5
|
+
--accent-text, and --upd-shadow (tokens.css, per mode).
|
|
6
|
+
Two knobs, set on .den-upd:
|
|
7
|
+
--upd-pad-y : the pill's vertical padding (8px).
|
|
8
|
+
--upd-top : where the pill sits; the default centres a 50px pill on a
|
|
9
|
+
48px bar (top -1px). */
|
|
10
|
+
.den-upd { --upd-pad-y: 8px; --upd-top: calc(env(safe-area-inset-top, 0px) + (48px - 50px) / 2);
|
|
11
|
+
position: fixed; z-index: 30; top: var(--upd-top); left: 16px; right: 16px; display: flex; justify-content: center; pointer-events: none; background: none; }
|
|
12
|
+
.den-upd[hidden] { display: none; }
|
|
13
|
+
.den-upd .upd-pill { pointer-events: auto; display: flex; align-items: center; gap: 16px; width: fit-content; max-width: 100%; box-sizing: border-box;
|
|
14
|
+
padding: var(--upd-pad-y) 12px var(--upd-pad-y) 24px;
|
|
15
|
+
border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text); font-size: 14px; line-height: 1.5;
|
|
16
|
+
background: var(--surface);
|
|
17
|
+
background: color-mix(in srgb, var(--surface) 20%, transparent);
|
|
18
|
+
background-image: linear-gradient(color-mix(in srgb, var(--text) 7%, transparent), color-mix(in srgb, var(--text) 3%, transparent));
|
|
19
|
+
-webkit-backdrop-filter: blur(3px) saturate(1.4); backdrop-filter: blur(3px) saturate(1.4);
|
|
20
|
+
box-shadow: var(--upd-shadow); }
|
|
21
|
+
.den-upd .upd-icon { flex: none; display: flex; color: var(--accent-text); }
|
|
22
|
+
.den-upd .upd-msg { flex: 1 1 auto; min-width: 0; text-wrap: balance; }
|
|
23
|
+
.den-upd .upd-acts { display: flex; align-items: center; gap: 8px; flex: none; }
|
|
24
|
+
.den-upd .upd-go { flex: none; display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px; border: 0; background: none; color: var(--accent-text); font-family: inherit; font-weight: 600; font-size: 14px; line-height: 1.2; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; cursor: pointer; }
|
|
25
|
+
.den-upd .upd-dismiss { flex: none; display: flex; align-items: center; justify-content: center; min-width: 32px; min-height: 32px; padding: 0; border: 0; border-radius: 999px; background: none; color: var(--muted); font-family: inherit; font-size: 18px; line-height: 1; cursor: pointer; }
|
|
26
|
+
.den-upd .upd-dismiss.is-text { width: auto; padding: 0 8px; font-weight: 500; font-size: 14px; line-height: 1.2; white-space: nowrap; }
|
|
27
|
+
.den-upd .upd-dismiss:hover { background: color-mix(in srgb, var(--border-strong) 50%, transparent); color: var(--text); }
|
|
28
|
+
.den-upd .upd-go:focus-visible, .den-upd .upd-dismiss:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
29
|
+
.den-upd .upd-pill.card { flex-wrap: wrap; gap: 8px; padding: 8px 8px 8px 16px; border-radius: 20px; }
|
|
30
|
+
.den-upd .upd-pill.card .upd-msg { flex: 1 0 100%; line-height: 1.35; }
|
|
31
|
+
.den-upd .upd-pill.card .upd-acts { margin-left: auto; }
|
|
32
|
+
.den-upd .upd-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// den-ui: the shared update pill (see update-pill.css). No framework.
|
|
2
|
+
// - text is written only when it changes (WebKit drops a click whose
|
|
3
|
+
// mouse-down node is replaced);
|
|
4
|
+
// - the words show at once (no layout shift under a click); a hidden status,
|
|
5
|
+
// filled just after, is what a screen reader hears;
|
|
6
|
+
// - a text past one line turns the pill into a card, re-measured on resize.
|
|
7
|
+
/**
|
|
8
|
+
* @param {{ message: string, reloadLabel: string, dismissLabel: string, cancelLabel?: string,
|
|
9
|
+
* askFirst?: { message: string } | null | (() => ({ message: string } | null)),
|
|
10
|
+
* onReload?: () => void, onDismiss?: () => void, region?: string, root?: HTMLElement }} o
|
|
11
|
+
* askFirst: when it returns a message (e.g. unsaved text), Reload asks once and the × reads Cancel.
|
|
12
|
+
* @returns {{ hide(): void }}
|
|
13
|
+
*/
|
|
14
|
+
export function showUpdate(o) {
|
|
15
|
+
const box = document.createElement("div");
|
|
16
|
+
box.className = "den-upd";
|
|
17
|
+
box.setAttribute("role", "region");
|
|
18
|
+
box.setAttribute("aria-label", o.region || "Update");
|
|
19
|
+
const pill = document.createElement("div");
|
|
20
|
+
pill.className = "upd-pill";
|
|
21
|
+
const icon = document.createElement("span");
|
|
22
|
+
icon.className = "upd-icon";
|
|
23
|
+
icon.setAttribute("aria-hidden", "true");
|
|
24
|
+
icon.innerHTML =
|
|
25
|
+
'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>';
|
|
26
|
+
const msg = document.createElement("span");
|
|
27
|
+
msg.className = "upd-msg";
|
|
28
|
+
msg.setAttribute("aria-hidden", "true");
|
|
29
|
+
const said = document.createElement("span");
|
|
30
|
+
said.className = "upd-sr";
|
|
31
|
+
said.setAttribute("role", "status");
|
|
32
|
+
const btn = (cls) =>
|
|
33
|
+
Object.assign(document.createElement("button"), {
|
|
34
|
+
type: "button",
|
|
35
|
+
className: cls,
|
|
36
|
+
});
|
|
37
|
+
const go = btn("upd-go");
|
|
38
|
+
const other = btn("upd-dismiss");
|
|
39
|
+
const acts = document.createElement("span");
|
|
40
|
+
acts.className = "upd-acts";
|
|
41
|
+
acts.append(go, other);
|
|
42
|
+
pill.append(icon, msg, said, acts);
|
|
43
|
+
box.append(pill);
|
|
44
|
+
let asking = null;
|
|
45
|
+
const put = (el, t) => {
|
|
46
|
+
if (el.textContent !== t) el.textContent = t;
|
|
47
|
+
};
|
|
48
|
+
const fit = () => {
|
|
49
|
+
if (!box.isConnected || box.hidden) return;
|
|
50
|
+
pill.classList.remove("card");
|
|
51
|
+
const r = document.createRange();
|
|
52
|
+
r.selectNodeContents(msg);
|
|
53
|
+
if (new Set([...r.getClientRects()].map((x) => Math.round(x.top))).size > 1)
|
|
54
|
+
pill.classList.add("card");
|
|
55
|
+
};
|
|
56
|
+
const render = () => {
|
|
57
|
+
const text = asking ? asking.message : o.message;
|
|
58
|
+
put(msg, text);
|
|
59
|
+
put(said, text);
|
|
60
|
+
put(go, o.reloadLabel);
|
|
61
|
+
put(other, asking ? o.cancelLabel || "Cancel" : "×");
|
|
62
|
+
other.classList.toggle("is-text", Boolean(asking));
|
|
63
|
+
if (asking) other.removeAttribute("aria-label");
|
|
64
|
+
else other.setAttribute("aria-label", o.dismissLabel);
|
|
65
|
+
fit();
|
|
66
|
+
};
|
|
67
|
+
const hide = () => {
|
|
68
|
+
window.removeEventListener("resize", fit);
|
|
69
|
+
box.remove();
|
|
70
|
+
};
|
|
71
|
+
go.addEventListener("click", () => {
|
|
72
|
+
const ask = typeof o.askFirst === "function" ? o.askFirst() : o.askFirst;
|
|
73
|
+
if (!asking && ask) {
|
|
74
|
+
asking = ask;
|
|
75
|
+
render();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
(o.onReload || (() => location.reload()))();
|
|
79
|
+
});
|
|
80
|
+
other.addEventListener("click", () => {
|
|
81
|
+
if (asking) {
|
|
82
|
+
asking = null;
|
|
83
|
+
render();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
hide();
|
|
87
|
+
o.onDismiss?.();
|
|
88
|
+
});
|
|
89
|
+
window.addEventListener("resize", fit);
|
|
90
|
+
(o.root || document.body).append(box);
|
|
91
|
+
render();
|
|
92
|
+
said.textContent = "";
|
|
93
|
+
setTimeout(render, 50);
|
|
94
|
+
return { hide };
|
|
95
|
+
}
|