actual-css 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/CHANGELOG.md +45 -0
- package/README.md +10 -7
- package/components.json +46 -2
- package/dist/actual.full.css +129 -13
- package/dist/actual.full.js +1 -1
- package/dist/actual.full.min.css +1 -1
- package/docs/design-notes/enhancement-contract.md +11 -3
- package/docs/design-notes/tokens.md +2 -0
- package/docs/pages/components/accordion.md +5 -0
- package/docs/pages/components/avatar.md +10 -0
- package/docs/pages/components/bleed.md +4 -0
- package/docs/pages/components/card.md +6 -0
- package/docs/pages/components/chat.md +20 -0
- package/docs/pages/components/dialog.md +26 -0
- package/docs/pages/components/rating.md +29 -5
- package/docs/pages/components/steps.md +5 -3
- package/docs/pages/enhancements/status-bar.md +1 -0
- package/docs/pages/examples/overview.md +2 -0
- package/docs/pages/forms/choice-cards.md +2 -1
- package/docs/pages/forms/date-picker.md +6 -0
- package/docs/pages/forms/overview.md +1 -0
- package/docs/pages/forms/sticky-actions.md +2 -0
- package/docs/pages/foundations/theming.md +19 -3
- package/docs/pages/guides/introduction.md +1 -1
- package/docs/pages/guides/progressive-enhancement.md +22 -0
- package/docs/pages/guides/upgrading.md +2 -2
- package/docs/pages/layout/choosing.md +18 -4
- package/docs/pages/layout/scroll-snap.md +69 -2
- package/llms.txt +2 -1
- package/package.json +5 -3
- package/skills/actual-css/SKILL.md +5 -4
- package/skills/actual-css/references/api-and-vocabulary.md +2 -1
- package/src/css/components/avatar.css +4 -2
- package/src/css/components/card.css +1 -1
- package/src/css/components/chat.css +5 -1
- package/src/css/components/menu.css +2 -0
- package/src/css/components/rating.css +66 -0
- package/src/css/components/status-bar.css +4 -2
- package/src/css/core/theme.css +4 -1
- package/src/css/core/tokens.css +8 -2
- package/src/css/forms/choice-card.css +5 -2
- package/src/css/forms/form.css +17 -1
- package/src/css/forms/range.css +11 -1
- package/src/css/layout/measure.css +2 -0
- package/src/js/dialog.js +40 -9
- package/src/js/enhance.js +16 -3
- package/src/js/selectors.js +10 -2
- package/src/js/status.js +71 -10
- package/tokens.json +117 -0
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Public hooks:
|
|
7
7
|
* --chat-gap
|
|
8
8
|
* --chat-max-size
|
|
9
|
+
* --chat-avatar-align
|
|
9
10
|
*
|
|
10
11
|
* Internal:
|
|
11
12
|
* --chat-bubble-bg
|
|
@@ -15,6 +16,9 @@
|
|
|
15
16
|
.chat {
|
|
16
17
|
--chat-gap: var(--space-30);
|
|
17
18
|
--chat-max-size: min(85%, 40rem);
|
|
19
|
+
/* end: the avatar sits beside the last line, as in messaging. start sets it
|
|
20
|
+
beside the header, for long answers or comment threads with a footer. */
|
|
21
|
+
--chat-avatar-align: end;
|
|
18
22
|
|
|
19
23
|
display: grid;
|
|
20
24
|
grid-auto-rows: min-content;
|
|
@@ -33,7 +37,7 @@
|
|
|
33
37
|
|
|
34
38
|
.chat-avatar {
|
|
35
39
|
grid-row: 1 / span 3;
|
|
36
|
-
align-self:
|
|
40
|
+
align-self: var(--chat-avatar-align);
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
.chat-start > .chat-avatar {
|
|
@@ -7,12 +7,22 @@
|
|
|
7
7
|
* fills preceding stars without reversing DOM or keyboard order. Forced
|
|
8
8
|
* colors restores the platform radio presentation.
|
|
9
9
|
*
|
|
10
|
+
* Read-only display: .rating[role="img"] is one element with no inputs, named
|
|
11
|
+
* by its aria-label. role="img" is the switch on purpose: an unnamed display
|
|
12
|
+
* draws nothing rather than stars no assistive technology can read.
|
|
13
|
+
*
|
|
10
14
|
* Public hooks:
|
|
11
15
|
* --rating-size
|
|
12
16
|
* --rating-gap
|
|
13
17
|
* --rating-color
|
|
14
18
|
* --rating-empty
|
|
15
19
|
* --rating-star
|
|
20
|
+
* --rating-value (display: the shown value, fractions allowed)
|
|
21
|
+
* --rating-max (display: the number of stars)
|
|
22
|
+
*
|
|
23
|
+
* Internal:
|
|
24
|
+
* --rating-fill
|
|
25
|
+
* --rating-direction
|
|
16
26
|
*/
|
|
17
27
|
:where(.rating) {
|
|
18
28
|
--intent: initial;
|
|
@@ -82,6 +92,49 @@
|
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
|
|
95
|
+
/* Each star takes the same size + gap cell as a radio, so a display and an
|
|
96
|
+
input of the same size line up. The fill is a share of the whole row, which
|
|
97
|
+
makes a fractional value a partial star. */
|
|
98
|
+
.rating[role="img"] {
|
|
99
|
+
--rating-value: 0;
|
|
100
|
+
--rating-max: 5;
|
|
101
|
+
--rating-fill: calc(var(--rating-value) / var(--rating-max) * 100%);
|
|
102
|
+
--rating-direction: to right;
|
|
103
|
+
|
|
104
|
+
inline-size: calc(var(--rating-max) * (var(--rating-size) + var(--rating-gap)));
|
|
105
|
+
block-size: var(--rating-size);
|
|
106
|
+
vertical-align: middle;
|
|
107
|
+
background: linear-gradient(
|
|
108
|
+
var(--rating-direction),
|
|
109
|
+
var(--rating-color) var(--rating-fill),
|
|
110
|
+
var(--rating-empty) var(--rating-fill)
|
|
111
|
+
);
|
|
112
|
+
-webkit-mask:
|
|
113
|
+
var(--rating-star) left center / calc(var(--rating-size) + var(--rating-gap)) var(--rating-size)
|
|
114
|
+
repeat-x;
|
|
115
|
+
mask:
|
|
116
|
+
var(--rating-star) left center / calc(var(--rating-size) + var(--rating-gap)) var(--rating-size)
|
|
117
|
+
repeat-x;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* The fill starts at the inline start; only the direction changes, so the
|
|
121
|
+
forced-colors gradient below follows it too. Safari before 16.4 has no
|
|
122
|
+
:dir(); the attribute path is its fallback, as in avatar.css. Each selector
|
|
123
|
+
is its own rule: a browser that rejects :dir() drops the whole rule, and the
|
|
124
|
+
:dir() rules come after the fallback so a nested LTR island beats an outer
|
|
125
|
+
[dir="rtl"] at equal specificity. */
|
|
126
|
+
[dir="rtl"] .rating[role="img"] {
|
|
127
|
+
--rating-direction: to left;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.rating[role="img"]:dir(ltr) {
|
|
131
|
+
--rating-direction: to right;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.rating[role="img"]:dir(rtl) {
|
|
135
|
+
--rating-direction: to left;
|
|
136
|
+
}
|
|
137
|
+
|
|
85
138
|
.rating.sm {
|
|
86
139
|
--rating-size: 1rem;
|
|
87
140
|
}
|
|
@@ -100,4 +153,17 @@
|
|
|
100
153
|
mask: none;
|
|
101
154
|
opacity: 1;
|
|
102
155
|
}
|
|
156
|
+
|
|
157
|
+
/* why: forced colors drops the gradient, and the filled share is the value
|
|
158
|
+
itself, so the display would vanish. It keeps the gradient, painted in the
|
|
159
|
+
user's own system colors only: Highlight for the value, as progress and
|
|
160
|
+
range do, GrayText for the empty stars. */
|
|
161
|
+
.rating[role="img"] {
|
|
162
|
+
forced-color-adjust: none;
|
|
163
|
+
background: linear-gradient(
|
|
164
|
+
var(--rating-direction),
|
|
165
|
+
Highlight var(--rating-fill),
|
|
166
|
+
GrayText var(--rating-fill)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
103
169
|
}
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* Internal:
|
|
23
23
|
* --status-bg
|
|
24
24
|
* --status-fg
|
|
25
|
-
* --status-viewport-offset (written by status.js while the bar is open
|
|
25
|
+
* --status-viewport-offset (written by status.js while the bar is open: the
|
|
26
|
+
* keyboard band plus any docked .form-actions.sticky bar)
|
|
26
27
|
*/
|
|
27
28
|
|
|
28
29
|
/* Intent boundary — inherited intents do not tint this component.
|
|
@@ -38,7 +39,8 @@
|
|
|
38
39
|
|
|
39
40
|
position: fixed;
|
|
40
41
|
/* Fixed positioning tracks the layout viewport, which the mobile software
|
|
41
|
-
keyboard covers
|
|
42
|
+
keyboard covers, and a docked .form-actions.sticky bar shares its bottom
|
|
43
|
+
edge. status.js writes both occluded bands into the offset. */
|
|
42
44
|
inset-block-end: calc(var(--space-40) + var(--status-viewport-offset, 0px));
|
|
43
45
|
inset-inline: var(--space-40);
|
|
44
46
|
z-index: var(--z-status);
|
package/src/css/core/theme.css
CHANGED
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
* translucent surfaces overrides them with opaque values. --border-control is
|
|
12
12
|
* public too: the resting edge of a neutral control, apart from structural
|
|
13
13
|
* separators. --control-default-bg is the inherited resting field fill.
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* Internal:
|
|
16
|
+
* --hgroup-gap
|
|
17
|
+
* --surface-link (link ink relay a painted surface sets; reset at boundaries)
|
|
15
18
|
*/
|
|
16
19
|
:root {
|
|
17
20
|
color-scheme: light dark;
|
package/src/css/core/tokens.css
CHANGED
|
@@ -8,8 +8,14 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Derived: "Theme-derived aliases" and "State tokens" reference intent and
|
|
10
10
|
* surface tokens and follow the theme; do not hard-code values into them.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Every token declared here is listed in tokens.json except these, which
|
|
13
|
+
* components consume but authors do not set:
|
|
14
|
+
*
|
|
15
|
+
* Internal:
|
|
16
|
+
* --indicator-offset
|
|
17
|
+
* --indicator-ring
|
|
18
|
+
* --disabled-opacity
|
|
13
19
|
*
|
|
14
20
|
* Component-local hooks and internal state relays live with their
|
|
15
21
|
* components. See docs/pages/foundations/tokens.md for the public/internal
|
|
@@ -104,8 +104,11 @@
|
|
|
104
104
|
cursor: not-allowed;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
/* Touch can retain :hover after a tap; hover must never mask selection. */
|
|
108
|
+
@media (hover: hover) {
|
|
109
|
+
.choice-card:hover:not(:has(:disabled, :checked)) {
|
|
110
|
+
--choice-card-border: var(--text-subtle);
|
|
111
|
+
}
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
/* Checked border — shared by radio and checkbox */
|
package/src/css/forms/form.css
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* component cannot know whether its siblings are stacked or gridded.
|
|
12
12
|
*
|
|
13
13
|
* Public API: .field, .field-label, .field-help, .field-error, .field-group,
|
|
14
|
-
* .required-mark.
|
|
14
|
+
* .field-group.flush, .required-mark.
|
|
15
15
|
*
|
|
16
16
|
* Public hooks:
|
|
17
17
|
* --fieldset-legend-padding-inline
|
|
@@ -49,6 +49,22 @@
|
|
|
49
49
|
font-size: var(--font-size-xs);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/* Flush — the frame removed, for a group that already sits in a card or a
|
|
53
|
+
form section. With no border to notch, the legend is a plain label above
|
|
54
|
+
the options: no gutter, the .field label-to-control gap below it, and the
|
|
55
|
+
.field label size — the small size only suits a legend set in a frame. */
|
|
56
|
+
.field-group.flush {
|
|
57
|
+
padding: 0;
|
|
58
|
+
border: 0;
|
|
59
|
+
border-radius: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.field-group.flush > legend {
|
|
63
|
+
margin-block-end: var(--space-10);
|
|
64
|
+
padding-inline: 0;
|
|
65
|
+
font-size: var(--control-font-size);
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
.field-help {
|
|
53
69
|
color: var(--text-muted);
|
|
54
70
|
font-size: 0.875em;
|
package/src/css/forms/range.css
CHANGED
|
@@ -46,7 +46,17 @@
|
|
|
46
46
|
cursor: pointer;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
:
|
|
49
|
+
/* Separate rules: a browser without :dir() drops a whole rule that names it,
|
|
50
|
+
which took the [dir="rtl"] fallback with it. The :dir() pair outranks the
|
|
51
|
+
fallback, so an LTR island inside an RTL region keeps filling from the left. */
|
|
52
|
+
:where([dir="rtl"]) .range {
|
|
53
|
+
--range-fill-from: to left;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.range:dir(ltr) {
|
|
57
|
+
--range-fill-from: to right;
|
|
58
|
+
}
|
|
59
|
+
|
|
50
60
|
.range:dir(rtl) {
|
|
51
61
|
--range-fill-from: to left;
|
|
52
62
|
}
|
package/src/js/dialog.js
CHANGED
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import { registerCommands, targetFor } from "./command.js";
|
|
31
|
-
import enhance from "./enhance.js";
|
|
31
|
+
import enhance, { registerEnhancement } from "./enhance.js";
|
|
32
32
|
import { EVENTS } from "./events.js";
|
|
33
33
|
import { CLASSES } from "./selectors.js";
|
|
34
34
|
|
|
35
35
|
const dialogMap = new WeakMap();
|
|
36
36
|
const wiredDialogs = new Set();
|
|
37
|
+
const delegatedDialogs = new WeakSet();
|
|
37
38
|
// HTML has no non-modal dialog keyword, so non-modal opening is the custom
|
|
38
39
|
// `--show` command.
|
|
39
40
|
const DIALOG_COMMANDS = ["show-modal", "--show", "request-close", "close"];
|
|
@@ -46,6 +47,18 @@ function isDialogElement(el) {
|
|
|
46
47
|
return el?.nodeType === 1 && el.localName === "dialog";
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
function allowsDialogEnhancement(dialog) {
|
|
51
|
+
if (delegatedDialogs.has(dialog) || dialog.matches('[data-enhance~="dialog"]')) return true;
|
|
52
|
+
|
|
53
|
+
// Shadow roots and light-DOM custom elements own their dialogs, including
|
|
54
|
+
// hosts that have not upgraded yet. Avoid realm-dependent instanceof checks.
|
|
55
|
+
if (dialog.getRootNode().host) return false;
|
|
56
|
+
for (let parent = dialog.parentElement; parent; parent = parent.parentElement) {
|
|
57
|
+
if (parent.localName.includes("-")) return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
49
62
|
function boolData(el, name) {
|
|
50
63
|
return el.hasAttribute(name) && el.getAttribute(name) !== "false";
|
|
51
64
|
}
|
|
@@ -270,7 +283,7 @@ function finishClose(dialog, returnValue = "") {
|
|
|
270
283
|
export function closeDialog(dialog, returnValue = "") {
|
|
271
284
|
if (!isDialogElement(dialog) || !dialog.open) return;
|
|
272
285
|
|
|
273
|
-
const state =
|
|
286
|
+
const state = ensureDelegatedDialog(dialog);
|
|
274
287
|
if (state.closing) return;
|
|
275
288
|
|
|
276
289
|
const trigger = state.restoreFocusTo;
|
|
@@ -299,7 +312,7 @@ export function closeDialog(dialog, returnValue = "") {
|
|
|
299
312
|
export function requestDialogClose(dialog, returnValue = "") {
|
|
300
313
|
if (!isDialogElement(dialog) || !dialog.open) return;
|
|
301
314
|
|
|
302
|
-
const state =
|
|
315
|
+
const state = ensureDelegatedDialog(dialog);
|
|
303
316
|
state.returnValue = returnValue;
|
|
304
317
|
state.requestingClose = true;
|
|
305
318
|
try {
|
|
@@ -317,7 +330,7 @@ export function requestDialogClose(dialog, returnValue = "") {
|
|
|
317
330
|
export function openDialog(dialog, trigger = null, forcedModal = null) {
|
|
318
331
|
if (!isDialogElement(dialog) || dialog.open || !dialog.isConnected) return;
|
|
319
332
|
|
|
320
|
-
const state =
|
|
333
|
+
const state = ensureDelegatedDialog(dialog);
|
|
321
334
|
const modal = resolveModalMode(dialog, forcedModal);
|
|
322
335
|
syncDialogSemantics(dialog, state, modal);
|
|
323
336
|
|
|
@@ -497,6 +510,18 @@ function ensureDialogWired(dialog) {
|
|
|
497
510
|
|
|
498
511
|
function connectDialog(dialog) {
|
|
499
512
|
ensureDialogWired(dialog);
|
|
513
|
+
return () => disconnectDialog(dialog);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function ensureDelegatedDialog(dialog) {
|
|
517
|
+
const state = ensureDialogWired(dialog);
|
|
518
|
+
if (!allowsDialogEnhancement(dialog)) {
|
|
519
|
+
delegatedDialogs.add(dialog);
|
|
520
|
+
// Direct API calls delegate ownership too. Enroll light DOM dialogs in
|
|
521
|
+
// document cleanup; shadow-root lifecycles remain application-owned.
|
|
522
|
+
if (dialog.getRootNode() === dialog.ownerDocument) dialogRuntime.refresh(dialog);
|
|
523
|
+
}
|
|
524
|
+
return state;
|
|
500
525
|
}
|
|
501
526
|
|
|
502
527
|
function disconnectDialog(dialog) {
|
|
@@ -512,6 +537,7 @@ function disconnectDialog(dialog) {
|
|
|
512
537
|
restoreOwnedAttributes(state);
|
|
513
538
|
state.modalOpen = false;
|
|
514
539
|
dialogMap.delete(dialog);
|
|
540
|
+
delegatedDialogs.delete(dialog);
|
|
515
541
|
wiredDialogs.delete(dialog);
|
|
516
542
|
syncModalOpenClass(dialog.ownerDocument);
|
|
517
543
|
}
|
|
@@ -519,7 +545,7 @@ function disconnectDialog(dialog) {
|
|
|
519
545
|
registerCommands(DIALOG_COMMANDS, {
|
|
520
546
|
resolve: (trigger) => {
|
|
521
547
|
const dialog = targetFor(trigger);
|
|
522
|
-
return isDialogElement(dialog) ? dialog : null;
|
|
548
|
+
return isDialogElement(dialog) && allowsDialogEnhancement(dialog) ? dialog : null;
|
|
523
549
|
},
|
|
524
550
|
handle: (_event, trigger, dialog, command) => {
|
|
525
551
|
// A dialog inserted since the last enhance() pass is wired on first use.
|
|
@@ -541,9 +567,14 @@ registerCommands(DIALOG_COMMANDS, {
|
|
|
541
567
|
},
|
|
542
568
|
});
|
|
543
569
|
|
|
544
|
-
enhance(
|
|
545
|
-
|
|
546
|
-
connectDialog
|
|
547
|
-
return () => disconnectDialog(dialog);
|
|
570
|
+
const dialogRuntime = enhance(
|
|
571
|
+
{
|
|
572
|
+
[DIALOG_SELECTOR]: connectDialog,
|
|
548
573
|
},
|
|
574
|
+
undefined,
|
|
575
|
+
{ accept: allowsDialogEnhancement },
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
registerEnhancement("dialog", (dialog) => {
|
|
579
|
+
if (isDialogElement(dialog)) return connectDialog(dialog);
|
|
549
580
|
});
|
package/src/js/enhance.js
CHANGED
|
@@ -73,6 +73,12 @@ function createRegistry(root) {
|
|
|
73
73
|
let discovery = "";
|
|
74
74
|
|
|
75
75
|
function start(record, el) {
|
|
76
|
+
// Shared discovery also visits the scan root and other records' matches.
|
|
77
|
+
if (record.accept && !record.keys.some((key) => el.matches(key))) return;
|
|
78
|
+
if (record.accept && !record.accept(el)) {
|
|
79
|
+
stop(record, el);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
76
82
|
let active = record.instances.get(el);
|
|
77
83
|
for (const key of record.keys) {
|
|
78
84
|
if (active?.has(key) || !el.matches(key)) continue;
|
|
@@ -115,7 +121,9 @@ function createRegistry(root) {
|
|
|
115
121
|
function sweepDisconnected() {
|
|
116
122
|
for (const record of records) {
|
|
117
123
|
for (const el of Array.from(record.instances.keys())) {
|
|
118
|
-
if (!el.isConnected || !root.contains(el)
|
|
124
|
+
if (!el.isConnected || !root.contains(el) || (record.accept && !record.accept(el))) {
|
|
125
|
+
stop(record, el);
|
|
126
|
+
}
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
}
|
|
@@ -254,9 +262,14 @@ export function registerEnhancement(name, init, root) {
|
|
|
254
262
|
/**
|
|
255
263
|
* @param {Record<string, (el: Element) => (() => void) | void>} enhancers
|
|
256
264
|
* @param {Document | Element | DocumentFragment} [root]
|
|
265
|
+
* @param {object} [options]
|
|
266
|
+
* @param {(el: Element) => boolean} [options.accept] Lifecycle eligibility, rechecked on moves.
|
|
257
267
|
* @returns {{ refresh: (node: Node) => void, disconnect: () => void }}
|
|
258
268
|
*/
|
|
259
|
-
export default function enhance(enhancers, root) {
|
|
269
|
+
export default function enhance(enhancers, root, { accept } = {}) {
|
|
270
|
+
if (accept !== undefined && typeof accept !== "function") {
|
|
271
|
+
throw new TypeError("enhance() requires a function accept predicate.");
|
|
272
|
+
}
|
|
260
273
|
if (typeof document === "undefined") return noopRuntime();
|
|
261
274
|
|
|
262
275
|
root ??= document.documentElement;
|
|
@@ -272,5 +285,5 @@ export default function enhance(enhancers, root) {
|
|
|
272
285
|
});
|
|
273
286
|
if (!keys.length) return noopRuntime();
|
|
274
287
|
|
|
275
|
-
return registryFor(root).add({ keys, enhancers, query: keys.join(",") });
|
|
288
|
+
return registryFor(root).add({ keys, enhancers, query: keys.join(","), accept });
|
|
276
289
|
}
|
package/src/js/selectors.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Selectors — the state-class vocabulary the runtime writes.
|
|
3
3
|
*
|
|
4
4
|
* The file lists the class names modules write as state (is-open,
|
|
5
|
-
* was-validated, …) and
|
|
6
|
-
*
|
|
5
|
+
* was-validated, …) and the classes they only read as presentation adapters:
|
|
6
|
+
* validation's field and fieldError, status's formActions + sticky pair.
|
|
7
|
+
* Behavior discovery is not listed here: it uses
|
|
7
8
|
* data-enhance tokens. To run this runtime against a different CSS
|
|
8
9
|
* framework, edit this file (or alias it in a bundler).
|
|
9
10
|
*
|
|
@@ -24,6 +25,13 @@ export const CLASSES = {
|
|
|
24
25
|
// validation.js — read-side presentation adapter: ancestor container
|
|
25
26
|
// for aria-invalid/danger state. Optional — degrades to no-op.
|
|
26
27
|
field: "field",
|
|
28
|
+
// status.js — read-side presentation adapter, first half of the compound
|
|
29
|
+
// .form-actions.sticky: the docked action bar the status bar rises above
|
|
30
|
+
// instead of covering its submit button.
|
|
31
|
+
formActions: "form-actions",
|
|
32
|
+
// status.js — read-side presentation adapter, second half of the same
|
|
33
|
+
// compound. Read only, never written: the runtime sets no sticky state.
|
|
34
|
+
sticky: "sticky",
|
|
27
35
|
// surface.js — state class on the open flyout/menu/dialog surface.
|
|
28
36
|
// status.js writes the same class on the status bar while a message shows.
|
|
29
37
|
open: "is-open",
|
package/src/js/status.js
CHANGED
|
@@ -58,6 +58,7 @@ import { waitForTransitions } from "./transition.js";
|
|
|
58
58
|
const STATUS_SELECTOR = '[data-status][role="status"]';
|
|
59
59
|
const STATUS_CLASSES_ATTR = "statusClasses";
|
|
60
60
|
const VIEWPORT_OFFSET_PROPERTY = "--status-viewport-offset";
|
|
61
|
+
const DOCKED_ACTIONS_SELECTOR = `.${CLASSES.formActions}.${CLASSES.sticky}`;
|
|
61
62
|
const DEFAULT_DURATION_MS = 3000;
|
|
62
63
|
|
|
63
64
|
let statusTimer;
|
|
@@ -116,34 +117,94 @@ function mountStatusTarget(target, source) {
|
|
|
116
117
|
mountedStatusTarget = target;
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
function dockedActionsBars(target) {
|
|
121
|
+
const root = target.closest("dialog[open]") ?? target.ownerDocument;
|
|
122
|
+
return root.querySelectorAll(DOCKED_ACTIONS_SELECTOR);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// A sticky action bar docks to the same bottom edge as the status bar. The
|
|
126
|
+
// validation docs pair the two, so an invalid submit would otherwise show its
|
|
127
|
+
// message on top of the submit button it is about. Any message is lifted, not
|
|
128
|
+
// only one from that form: the bar must not hide the page's primary actions
|
|
129
|
+
// whatever it says. A bar counts as docked when its bottom sits at its sticky
|
|
130
|
+
// offset from the visible bottom edge (above a bottom navigation, for one); a
|
|
131
|
+
// bar at rest higher up the page is not in the way. Detection assumes the
|
|
132
|
+
// bar's scrollport reaches the viewport bottom: a bar docked in a scroll
|
|
133
|
+
// container that ends higher (.app-main above an .app-nav row) is not seen.
|
|
134
|
+
function dockedActionsBand(target, view, visibleBottom) {
|
|
135
|
+
let band = 0;
|
|
136
|
+
for (const actions of dockedActionsBars(target)) {
|
|
137
|
+
const rect = actions.getBoundingClientRect();
|
|
138
|
+
const offset = Number.parseFloat(view.getComputedStyle(actions).bottom) || 0;
|
|
139
|
+
if (rect.height > 0 && rect.top < visibleBottom && rect.bottom >= visibleBottom - offset - 1) {
|
|
140
|
+
band = Math.max(band, visibleBottom - rect.top);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return band;
|
|
144
|
+
}
|
|
145
|
+
|
|
119
146
|
// The bar is fixed to the layout viewport, so the mobile software keyboard
|
|
120
|
-
// covers it
|
|
121
|
-
//
|
|
147
|
+
// covers it, and a docked sticky action bar sits where it would show.
|
|
148
|
+
// visualViewport reports the keyboard band; the docked bar's height is added on
|
|
149
|
+
// top; the CSS adds the sum to the bottom inset. Tracking runs only while a
|
|
150
|
+
// message is on screen.
|
|
122
151
|
function trackViewport(target) {
|
|
123
152
|
if (viewportTracker?.target === target) return;
|
|
124
153
|
releaseViewport();
|
|
125
154
|
|
|
126
155
|
const view = target.ownerDocument?.defaultView;
|
|
127
|
-
|
|
128
|
-
|
|
156
|
+
if (!view) return;
|
|
157
|
+
const viewport = view.visualViewport;
|
|
129
158
|
|
|
130
159
|
const controller = new AbortController();
|
|
160
|
+
let frame = 0;
|
|
161
|
+
let written = null;
|
|
131
162
|
const update = () => {
|
|
163
|
+
frame = 0;
|
|
132
164
|
// Self-heal: an app that drops the bar while a message is up never reaches
|
|
133
165
|
// the clear() path, so the tracker would outlive its element.
|
|
134
166
|
if (!target.isConnected) {
|
|
135
167
|
releaseViewport();
|
|
136
168
|
return;
|
|
137
169
|
}
|
|
138
|
-
const
|
|
139
|
-
|
|
170
|
+
const keyboard = viewport
|
|
171
|
+
? Math.max(0, view.innerHeight - viewport.height - viewport.offsetTop)
|
|
172
|
+
: 0;
|
|
173
|
+
const docked = dockedActionsBand(target, view, view.innerHeight - keyboard);
|
|
174
|
+
const value = `${keyboard + docked}px`;
|
|
175
|
+
if (value === written) return;
|
|
176
|
+
written = value;
|
|
177
|
+
target.style.setProperty(VIEWPORT_OFFSET_PROPERTY, value);
|
|
178
|
+
};
|
|
179
|
+
// Scroll fires per frame and per scroll container; one layout read per frame
|
|
180
|
+
// is enough.
|
|
181
|
+
const schedule = () => {
|
|
182
|
+
if (!frame) frame = view.requestAnimationFrame(update);
|
|
140
183
|
};
|
|
141
184
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
185
|
+
// Installed before the first update, so a target already detached there is
|
|
186
|
+
// released instead of leaving a tracker behind.
|
|
187
|
+
const observer = view.ResizeObserver ? new view.ResizeObserver(schedule) : null;
|
|
188
|
+
viewportTracker = {
|
|
189
|
+
target,
|
|
190
|
+
stop: () => {
|
|
191
|
+
controller.abort();
|
|
192
|
+
observer?.disconnect();
|
|
193
|
+
if (frame) view.cancelAnimationFrame(frame);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
145
196
|
|
|
146
|
-
|
|
197
|
+
const options = { signal: controller.signal, passive: true };
|
|
198
|
+
viewport?.addEventListener("resize", schedule, options);
|
|
199
|
+
viewport?.addEventListener("scroll", schedule, options);
|
|
200
|
+
// Scrolling docks and releases the action bar. Capture also hears the scroll
|
|
201
|
+
// containers (.app-main) whose scroll events do not bubble.
|
|
202
|
+
view.addEventListener("scroll", schedule, { ...options, capture: true });
|
|
203
|
+
view.addEventListener("resize", schedule, options);
|
|
204
|
+
// A docked bar can change height without any scroll: a wrapping button, a
|
|
205
|
+
// spinner, an error line above the actions.
|
|
206
|
+
for (const actions of dockedActionsBars(target)) observer?.observe(actions);
|
|
207
|
+
update();
|
|
147
208
|
}
|
|
148
209
|
|
|
149
210
|
function releaseViewport() {
|