actual-css 0.18.0 → 0.19.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 +54 -0
- package/README.md +7 -5
- package/components.json +6 -2
- package/dist/actual.full.css +272 -57
- package/dist/actual.full.js +2 -2
- package/dist/actual.full.min.css +1 -1
- package/docs/design-notes/enhancement-contract.md +20 -11
- package/docs/design-notes/motion-cost.md +62 -0
- package/docs/design-notes/tokens.md +4 -0
- package/docs/navigation.json +3 -0
- package/docs/pages/components/aura.md +3 -0
- package/docs/pages/components/mark-sweep.md +42 -0
- package/docs/pages/components/rating.md +53 -22
- package/docs/pages/components/reveal.md +54 -0
- package/docs/pages/components/shimmer.md +3 -2
- package/docs/pages/enhancements/in-view.md +109 -0
- package/docs/pages/enhancements/overview.md +3 -2
- package/docs/pages/enhancements/scrollspy.md +5 -5
- package/docs/pages/examples/overview.md +5 -2
- package/docs/pages/forms/date-picker.md +3 -2
- package/docs/pages/forms/switch.md +25 -16
- package/docs/pages/foundations/tokens.md +37 -15
- package/docs/pages/foundations/typography.md +8 -2
- package/docs/pages/guides/introduction.md +1 -1
- package/docs/pages/guides/modular-import.md +20 -4
- package/docs/pages/guides/progressive-enhancement.md +2 -1
- package/docs/pages/guides/upgrading.md +1 -1
- package/docs/pages/patterns/code-block.md +1 -1
- package/docs/pages/patterns/empty-state.md +3 -3
- package/docs/pages/patterns/exclusive-accordion.md +3 -2
- package/docs/pages/patterns/hierarchical-nav.md +5 -4
- package/docs/pages/patterns/icon-input.md +1 -1
- package/docs/pages/patterns/icon-slot.md +4 -4
- package/docs/pages/patterns/intent-nesting.md +2 -3
- package/docs/pages/patterns/navigation-list.md +7 -4
- package/docs/pages/patterns/stat.md +3 -3
- package/docs/pages/patterns/structured-lists.md +1 -2
- package/llms.txt +2 -1
- package/package.json +3 -1
- package/reserved-classes.json +4 -0
- package/src/cli/actual-css.js +3 -1
- package/src/css/components/navbar.css +13 -5
- package/src/css/components/rating.css +23 -2
- package/src/css/components/scrollspy.css +4 -2
- package/src/css/core/base.css +16 -0
- package/src/css/core/focus.css +13 -12
- package/src/css/core/reset.css +10 -0
- package/src/css/core/theme.css +15 -0
- package/src/css/core/tokens.css +4 -10
- package/src/css/effects/aura.css +5 -0
- package/src/css/effects/index.css +2 -0
- package/src/css/effects/mark-sweep.css +64 -0
- package/src/css/effects/reveal.css +66 -0
- package/src/css/effects/shimmer.css +28 -10
- package/src/css/forms/choice.css +0 -7
- package/src/css/forms/switch.css +9 -9
- package/src/js/full.js +1 -0
- package/src/js/in-view.js +152 -0
- package/src/js/scrollspy.js +81 -2
- package/src/js/selectors.js +3 -0
- package/src/tooling/css-bundle.js +153 -6
- package/src/tooling/design-tokens.js +2 -0
- package/tokens.json +2 -0
package/src/css/core/focus.css
CHANGED
|
@@ -6,17 +6,11 @@
|
|
|
6
6
|
for its keyboard focus indicator; forced colors keep outlines and drop
|
|
7
7
|
shadows.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
draw the themed ring instead — a solid line in --focus: inset on fields
|
|
15
|
-
(inside their border box), offset by --focus-outline-offset on discrete
|
|
16
|
-
actions. The color never derives from an intent or a local
|
|
17
|
-
surface — the theme guarantees --focus at 3:1 against both --surface and
|
|
18
|
-
--surface-solid, so one token reads on the page, on a solid band and on
|
|
19
|
-
any nested surface.
|
|
9
|
+
All default indicators use --focus, independently of intent, selection or
|
|
10
|
+
text color. Components adapt the geometry: inset on fields (inside their
|
|
11
|
+
border box), offset by --focus-outline-offset on discrete actions. Themes
|
|
12
|
+
target 3:1 against --surface and --surface-solid; other painted backgrounds
|
|
13
|
+
still need their own contrast check.
|
|
20
14
|
|
|
21
15
|
A .segment is an action but takes the inset ring: its track's padding is
|
|
22
16
|
narrower than an offset ring, which would cover the neighbouring segment.
|
|
@@ -28,9 +22,16 @@
|
|
|
28
22
|
|
|
29
23
|
Public hooks:
|
|
30
24
|
--focus-outline (fallback-only: replaces the whole generic line)
|
|
25
|
+
--focus-outline-color (fallback-only: overrides the generic line color)
|
|
31
26
|
*/
|
|
32
27
|
:focus {
|
|
33
|
-
|
|
28
|
+
/* Resolve the default on the target: a root alias would freeze --focus
|
|
29
|
+
before a theme island or a plain region could override it. Keeping the
|
|
30
|
+
color hook unset also lets an inherited author override cross islands. */
|
|
31
|
+
outline: var(
|
|
32
|
+
--focus-outline,
|
|
33
|
+
var(--focus-ring-width) solid var(--focus-outline-color, var(--focus))
|
|
34
|
+
);
|
|
34
35
|
outline-offset: var(--focus-outline-offset);
|
|
35
36
|
}
|
|
36
37
|
|
package/src/css/core/reset.css
CHANGED
|
@@ -29,6 +29,16 @@ select {
|
|
|
29
29
|
display: none !important;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/* The UA hides a closed dialog from its own origin, so any author display
|
|
33
|
+
wins over it, even at zero specificity: `<dialog class="card">` stayed on
|
|
34
|
+
screen after its method="dialog" form closed it. Not !important, unlike
|
|
35
|
+
[hidden]: an important declaration outranks transitions, and the modal's
|
|
36
|
+
exit fade transitions display. A dialog that needs another closed display
|
|
37
|
+
says so with a more specific selector. */
|
|
38
|
+
dialog:not([open]) {
|
|
39
|
+
display: none;
|
|
40
|
+
}
|
|
41
|
+
|
|
32
42
|
:where(img, svg, video) {
|
|
33
43
|
max-inline-size: 100%;
|
|
34
44
|
block-size: auto;
|
package/src/css/core/theme.css
CHANGED
|
@@ -77,6 +77,11 @@
|
|
|
77
77
|
--text-muted: hsl(259 9% 42%);
|
|
78
78
|
--text-subtle: hsl(258 7% 57%);
|
|
79
79
|
|
|
80
|
+
/* Highlight pair for <mark> and .mark-sweep: a warm, non-warning yellow that
|
|
81
|
+
keeps the phrase legible in both schemes. */
|
|
82
|
+
--mark-bg: hsl(48 95% 68%);
|
|
83
|
+
--mark-fg: hsl(38 45% 12%);
|
|
84
|
+
|
|
80
85
|
/* Lines and focus */
|
|
81
86
|
--border: hsl(260 15% 88%);
|
|
82
87
|
/* A primary-hued mid-tone on purpose, one value for both schemes: focus
|
|
@@ -133,6 +138,16 @@
|
|
|
133
138
|
--control-default-bg: var(--surface);
|
|
134
139
|
}
|
|
135
140
|
|
|
141
|
+
/* Custom properties accept unknown functions, so guard the pair to preserve
|
|
142
|
+
the light fallback. Redeclare on islands to follow their own color-scheme. */
|
|
143
|
+
@supports (color: light-dark(red, blue)) {
|
|
144
|
+
:root,
|
|
145
|
+
[data-theme] {
|
|
146
|
+
--mark-bg: light-dark(hsl(48 95% 68%), hsl(44 55% 30%));
|
|
147
|
+
--mark-fg: light-dark(hsl(38 45% 12%), hsl(44 60% 94%));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
136
151
|
@supports (color: color-mix(in oklab, red, white)) {
|
|
137
152
|
:root,
|
|
138
153
|
[data-theme] {
|
package/src/css/core/tokens.css
CHANGED
|
@@ -82,19 +82,13 @@
|
|
|
82
82
|
--duration-fast: 100ms;
|
|
83
83
|
--duration-slow: 200ms;
|
|
84
84
|
--duration-spin: 0.75s;
|
|
85
|
-
--duration-shimmer:
|
|
85
|
+
--duration-shimmer: 2s;
|
|
86
86
|
--ease-enter: cubic-bezier(0.2, 0, 0, 1);
|
|
87
87
|
--ease-exit: cubic-bezier(0.4, 0, 1, 1);
|
|
88
88
|
|
|
89
|
-
/*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for the two contracts. Both share --focus-ring-width: they differ in
|
|
93
|
-
color only. No --focus-outline alias here: declared on :root it would be
|
|
94
|
-
inherited already computed, so a theme island or a region setting
|
|
95
|
-
--focus-ring-width would not reach it. focus.css composes the line on the
|
|
96
|
-
focused element instead. */
|
|
97
|
-
--focus-outline-color: currentColor;
|
|
89
|
+
/* Focus geometry is shared by the generic line and component rings.
|
|
90
|
+
focus.css composes the line on its target; the optional color and whole-
|
|
91
|
+
outline hooks stay unset so local theme tokens reach their fallbacks. */
|
|
98
92
|
--focus-outline-offset: 2px;
|
|
99
93
|
--focus-ring-width: 2px;
|
|
100
94
|
|
package/src/css/effects/aura.css
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
* follows the animated gradient, so a rotating aura repaints one blurred layer
|
|
11
11
|
* per frame, not two.
|
|
12
12
|
*
|
|
13
|
+
* Per-frame cost is the registered --aura-angle animation itself: style and a
|
|
14
|
+
* full repaint every frame, off screen too. Containment and a static near
|
|
15
|
+
* halo do not change it; a compositor rotation needs an extra element. Measured
|
|
16
|
+
* in docs/design-notes/motion-cost.md (bun run report:paint).
|
|
17
|
+
*
|
|
13
18
|
* Public hooks:
|
|
14
19
|
* --aura-color
|
|
15
20
|
* --aura-width
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Mark sweep — a highlight that sweeps in behind a phrase.
|
|
3
|
+
*
|
|
4
|
+
* Docs: docs/pages/components/mark-sweep.md
|
|
5
|
+
*
|
|
6
|
+
* <mark> carries the semantics of contextually relevant text and is styled by
|
|
7
|
+
* base.css. `.mark-sweep` is the effect alone and composes on any inline
|
|
8
|
+
* element. Both read the same --mark-bg / --mark-fg pair, so a theme or an
|
|
9
|
+
* intent retints the phrase and its sweep together, without a second palette.
|
|
10
|
+
*
|
|
11
|
+
* The highlight is a full-size background image at rest. `is-pending` shrinks
|
|
12
|
+
* it to zero and the transition grows it back from the reading direction's
|
|
13
|
+
* start edge. Without JavaScript, under reduced motion and in print, the full
|
|
14
|
+
* highlight is already there.
|
|
15
|
+
*
|
|
16
|
+
* Public hooks:
|
|
17
|
+
* --mark-sweep-duration
|
|
18
|
+
*/
|
|
19
|
+
.mark-sweep {
|
|
20
|
+
--mark-sweep-duration: 700ms;
|
|
21
|
+
|
|
22
|
+
/* The shorthand is deliberate: it also clears the background-color base.css
|
|
23
|
+
paints on <mark>, which would otherwise show the whole highlight while
|
|
24
|
+
the element is pending. */
|
|
25
|
+
background: linear-gradient(var(--mark-bg), var(--mark-bg)) 0 0 / 100% 100% no-repeat;
|
|
26
|
+
color: var(--mark-fg);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* The zero-width box is anchored to the reading direction's start edge. Only
|
|
30
|
+
the anchor changes under RTL; the gradient itself is symmetric. */
|
|
31
|
+
.mark-sweep:dir(rtl) {
|
|
32
|
+
background-position: 100% 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Solid intent ink needs its fill to stay legible. A sweep exposes the surface
|
|
36
|
+
until the fill arrives, so use a soft tint with ordinary theme ink instead.
|
|
37
|
+
Guard the custom property: unsupported color-mix() would invalidate the
|
|
38
|
+
background at computed time instead of preserving the theme highlight. */
|
|
39
|
+
@supports (color: color-mix(in oklab, red, white)) {
|
|
40
|
+
.mark-sweep:is(.primary, .secondary, .success, .warning, .danger, .neutral) {
|
|
41
|
+
--mark-bg: color-mix(in oklab, var(--surface) var(--soft-bg-mix), var(--intent));
|
|
42
|
+
--mark-fg: var(--text);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@media screen and (prefers-reduced-motion: no-preference) {
|
|
47
|
+
.mark-sweep {
|
|
48
|
+
/* A readable sweep needs a gentler start than surface entrance timing. */
|
|
49
|
+
transition: background-size var(--mark-sweep-duration) ease-out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.mark-sweep.is-pending {
|
|
53
|
+
background-size: 0 100%;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Forced colors drops the background image, so the system Mark pair keeps the
|
|
58
|
+
phrase distinct whether .mark-sweep sits on <mark> or a <span>. */
|
|
59
|
+
@media (forced-colors: active) {
|
|
60
|
+
.mark-sweep {
|
|
61
|
+
background: Mark;
|
|
62
|
+
color: MarkText;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Reveal — entrance motion for a block or a group of children.
|
|
3
|
+
*
|
|
4
|
+
* Docs: docs/pages/components/reveal.md
|
|
5
|
+
*
|
|
6
|
+
* The entrance is a one-shot animation, so `.reveal` alone plays it on the
|
|
7
|
+
* first render, without JavaScript. in-view.js adds the scroll trigger: it
|
|
8
|
+
* writes `is-pending` on an element that waits outside the viewport, and this
|
|
9
|
+
* file holds it hidden with the animation removed. Removing the class puts the
|
|
10
|
+
* animation back, which starts it from the beginning on the first appearance.
|
|
11
|
+
*
|
|
12
|
+
* Everything sits under `screen and (prefers-reduced-motion: no-preference)`:
|
|
13
|
+
* reduced motion and print neither animate nor hide anything.
|
|
14
|
+
*
|
|
15
|
+
* An animation rather than a transition, on purpose: the `transition`
|
|
16
|
+
* shorthand replaced the transitions of the component it sat on (a `.btn`
|
|
17
|
+
* lost its hover motion). The `animation` shorthand still replaces another
|
|
18
|
+
* animation on the same element, which is the remaining composition limit.
|
|
19
|
+
*
|
|
20
|
+
* Fill mode `backwards` holds the first keyframe through a stagger delay and
|
|
21
|
+
* leaves no animated value in the cascade once the entrance ends. A pending
|
|
22
|
+
* element revealed by focus has its new animation finished by in-view.js,
|
|
23
|
+
* because a :focus-within override lapses on blur and replays the entrance.
|
|
24
|
+
*
|
|
25
|
+
* Public hooks:
|
|
26
|
+
* --reveal-duration
|
|
27
|
+
* --reveal-distance
|
|
28
|
+
* --reveal-stagger
|
|
29
|
+
*/
|
|
30
|
+
.reveal,
|
|
31
|
+
.reveal-group {
|
|
32
|
+
--reveal-duration: 450ms;
|
|
33
|
+
--reveal-distance: 1rem;
|
|
34
|
+
--reveal-stagger: 60ms;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@media screen and (prefers-reduced-motion: no-preference) {
|
|
38
|
+
.reveal,
|
|
39
|
+
.reveal-group > * {
|
|
40
|
+
/* The gentler ease-out keeps the fade gradual; surface entrance timing
|
|
41
|
+
makes most of the content visible too early. */
|
|
42
|
+
animation: actual-reveal var(--reveal-duration) ease-out backwards;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* The cap keeps a long list from becoming an endless cascade: the ninth and
|
|
46
|
+
later items share the eighth step's delay. An engine without
|
|
47
|
+
sibling-index() drops this declaration alone and reveals the group
|
|
48
|
+
together, which is the intended degradation. */
|
|
49
|
+
.reveal-group > * {
|
|
50
|
+
animation-delay: calc(min(sibling-index() - 1, 8) * var(--reveal-stagger));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.reveal.is-pending,
|
|
54
|
+
.reveal-group.is-pending > * {
|
|
55
|
+
animation: none;
|
|
56
|
+
opacity: 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* The end keyframe is implicit: the element's own opacity and translate. */
|
|
61
|
+
@keyframes actual-reveal {
|
|
62
|
+
from {
|
|
63
|
+
opacity: 0;
|
|
64
|
+
translate: 0 var(--reveal-distance);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* Public hooks:
|
|
11
11
|
* --shimmer-color
|
|
12
12
|
* --shimmer-highlight
|
|
13
|
+
*
|
|
14
|
+
* Internal:
|
|
15
|
+
* --shimmer-band
|
|
13
16
|
*/
|
|
14
17
|
.shimmer {
|
|
15
18
|
--shimmer-color: var(--text-muted);
|
|
@@ -24,34 +27,49 @@
|
|
|
24
27
|
the fill, not `color`: a label class that sets its own color (.muted, a
|
|
25
28
|
caption style) would otherwise win the cascade and paint opaque glyphs over
|
|
26
29
|
the sweep. Reduced motion keeps the plain label — a frozen band would read
|
|
27
|
-
as a random tint.
|
|
30
|
+
as a random tint.
|
|
31
|
+
|
|
32
|
+
The band has a fixed width in em, not a share of the label: a proportional
|
|
33
|
+
band covered most of a short label like "Working…" and lit the whole word
|
|
34
|
+
instead of crossing it. */
|
|
28
35
|
@supports (background-clip: text) {
|
|
29
36
|
@media (prefers-reduced-motion: no-preference) {
|
|
30
37
|
.shimmer {
|
|
38
|
+
--shimmer-band: 1.25em;
|
|
39
|
+
|
|
31
40
|
-webkit-text-fill-color: transparent;
|
|
32
41
|
background:
|
|
33
42
|
linear-gradient(
|
|
34
43
|
90deg,
|
|
35
|
-
var(--shimmer-color)
|
|
44
|
+
var(--shimmer-color) calc(50% - var(--shimmer-band)),
|
|
36
45
|
var(--shimmer-highlight) 50%,
|
|
37
|
-
var(--shimmer-color)
|
|
46
|
+
var(--shimmer-color) calc(50% + var(--shimmer-band))
|
|
38
47
|
)
|
|
39
|
-
0 0 /
|
|
48
|
+
0 0 / calc(200% + 2 * var(--shimmer-band)) 100%;
|
|
40
49
|
background-clip: text;
|
|
41
|
-
animation: actual-shimmer var(--duration-shimmer)
|
|
50
|
+
animation: actual-shimmer var(--duration-shimmer) ease-in-out infinite;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* The sweep follows the reading direction. Reversing also moves the rest
|
|
54
|
+
to the start of the cycle, which reads the same in a loop. */
|
|
55
|
+
.shimmer:dir(rtl) {
|
|
56
|
+
animation-direction: reverse;
|
|
42
57
|
}
|
|
43
58
|
}
|
|
44
59
|
}
|
|
45
60
|
|
|
46
|
-
/*
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
/* A background of twice the label plus the band puts the band's far edge at
|
|
62
|
+
the label's start at 100% and its near edge at the label's end at 0%, so
|
|
63
|
+
every pass enters and leaves completely, whatever the label's length. The
|
|
64
|
+
last quarter rests off the label: a continuous sweep reads as a machine,
|
|
65
|
+
the rest between passes as a breath. */
|
|
49
66
|
@keyframes actual-shimmer {
|
|
50
|
-
|
|
67
|
+
0% {
|
|
51
68
|
background-position: 100% 0;
|
|
52
69
|
}
|
|
53
70
|
|
|
54
|
-
|
|
71
|
+
75%,
|
|
72
|
+
100% {
|
|
55
73
|
background-position: 0% 0;
|
|
56
74
|
}
|
|
57
75
|
}
|
package/src/css/forms/choice.css
CHANGED
|
@@ -226,13 +226,6 @@
|
|
|
226
226
|
--choice-border: var(--text-subtle);
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
/* A bare checkbox or radio (a table row selector, an application's native
|
|
230
|
-
control) is boxed by its own skin, not text-like: it takes the themed ring
|
|
231
|
-
instead of the core currentColor fallback, which paints the text ink. */
|
|
232
|
-
:where(input[type="checkbox"], input[type="radio"]) {
|
|
233
|
-
--focus-outline-color: var(--focus);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
229
|
.check:focus-visible,
|
|
237
230
|
.radio:focus-visible {
|
|
238
231
|
outline: var(--focus-ring-width) solid var(--focus);
|
package/src/css/forms/switch.css
CHANGED
|
@@ -30,11 +30,12 @@
|
|
|
30
30
|
|
|
31
31
|
.switch {
|
|
32
32
|
--switch-bg: var(--border);
|
|
33
|
-
|
|
33
|
+
/* Keep the border in the geometry without outlining the track. */
|
|
34
|
+
--switch-border: var(--switch-bg);
|
|
34
35
|
--switch-knob: var(--surface-raised);
|
|
35
36
|
--switch-block-size: calc(var(--choice-control-size) + 0.125em);
|
|
36
37
|
--switch-width: calc(var(--switch-block-size) * 1.8);
|
|
37
|
-
--switch-knob-margin: calc(var(--switch-block-size) * 0.
|
|
38
|
+
--switch-knob-margin: calc(var(--switch-block-size) * 0.1);
|
|
38
39
|
|
|
39
40
|
/* The knob is concentric in the track: --switch-block-size is a border-box
|
|
40
41
|
height, so the borders have to come out before the inset is applied on
|
|
@@ -97,16 +98,16 @@
|
|
|
97
98
|
background-color var(--duration);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
/*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
.switch:not(:checked):hover:not(:disabled) {
|
|
104
|
-
|
|
101
|
+
/* Guard the custom property so older browsers keep the resting fill rather
|
|
102
|
+
than substituting an unsupported mix into both background and border. */
|
|
103
|
+
@supports (color: color-mix(in oklab, black, white)) {
|
|
104
|
+
.switch:not(:checked):hover:not(:disabled) {
|
|
105
|
+
--switch-bg: color-mix(in oklab, var(--text) 10%, var(--border));
|
|
106
|
+
}
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
.switch:checked {
|
|
108
110
|
--switch-bg: var(--intent, var(--state-selected));
|
|
109
|
-
--switch-border: var(--intent, var(--state-selected));
|
|
110
111
|
--switch-knob: var(--intent-fg, var(--state-selected-fg));
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -137,7 +138,6 @@
|
|
|
137
138
|
|
|
138
139
|
.switch:disabled {
|
|
139
140
|
--switch-bg: var(--surface-subtle);
|
|
140
|
-
--switch-border: var(--border);
|
|
141
141
|
--switch-knob: var(--state-disabled);
|
|
142
142
|
opacity: 1;
|
|
143
143
|
cursor: not-allowed;
|
package/src/js/full.js
CHANGED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* In view — one-shot appearance trigger for reveal-style effects.
|
|
3
|
+
*
|
|
4
|
+
* Docs: docs/pages/enhancements/in-view.md
|
|
5
|
+
*
|
|
6
|
+
* The runtime names no animation. It marks an element `is-pending` while it
|
|
7
|
+
* waits outside the viewport and removes the class the first time it enters.
|
|
8
|
+
* Each effect's CSS decides what that state looks like, exactly as `is-open`
|
|
9
|
+
* lets flyout.css own the panel's presentation.
|
|
10
|
+
*
|
|
11
|
+
* `is-pending` is written only after the observer's first callback reports the
|
|
12
|
+
* element outside the viewport. An element visible at load is therefore never
|
|
13
|
+
* hidden by the runtime; whether it still enters is the effect's choice
|
|
14
|
+
* (`.reveal` plays its keyframes on first render, `.mark-sweep` stays at
|
|
15
|
+
* rest). The first callback runs before the next paint, so an off-screen
|
|
16
|
+
* element is masked before a scroll can expose it.
|
|
17
|
+
*
|
|
18
|
+
* A pending element keeps its text in the accessibility tree and in the tab
|
|
19
|
+
* order; effects hide it with opacity alone. `focusin` releases it at once and
|
|
20
|
+
* finishes the entrance it started, so keyboard focus never lands on invisible
|
|
21
|
+
* or fading content. In-page find still matches the text, because nothing is
|
|
22
|
+
* removed from the layer.
|
|
23
|
+
*
|
|
24
|
+
* One initial IntersectionObserver per document protects content already in
|
|
25
|
+
* view. Optional data-in-view-margin values share additional observers for
|
|
26
|
+
* the entrance itself, so delaying an entrance never hides visible content
|
|
27
|
+
* at registration. Without IntersectionObserver nothing is hidden.
|
|
28
|
+
*
|
|
29
|
+
* No `actual:in-view` event yet. A numeric count-up associated with the same
|
|
30
|
+
* trigger would need one; add it with that second consumer, not before.
|
|
31
|
+
*/
|
|
32
|
+
import { registerEnhancement } from "./enhance.js";
|
|
33
|
+
import { CLASSES } from "./selectors.js";
|
|
34
|
+
|
|
35
|
+
const documents = new WeakMap();
|
|
36
|
+
|
|
37
|
+
function observerFor(doc) {
|
|
38
|
+
let connection = documents.get(doc);
|
|
39
|
+
if (connection) return connection;
|
|
40
|
+
|
|
41
|
+
// Records are keyed weakly by element; the observer holds only what it
|
|
42
|
+
// observes, and every release path unobserves.
|
|
43
|
+
const records = new WeakMap();
|
|
44
|
+
const triggers = new Map();
|
|
45
|
+
const observer = new IntersectionObserver((entries) => {
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
const record = records.get(entry.target);
|
|
48
|
+
if (!record || record.done) continue;
|
|
49
|
+
if (entry.isIntersecting) reveal(record);
|
|
50
|
+
else {
|
|
51
|
+
entry.target.classList.add(CLASSES.pending);
|
|
52
|
+
if (record.observer !== observer) {
|
|
53
|
+
observer.unobserve(entry.target);
|
|
54
|
+
record.observer.observe(entry.target);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
connection = { observer, records, triggers };
|
|
61
|
+
documents.set(doc, connection);
|
|
62
|
+
return connection;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function triggerFor(connection, margin) {
|
|
66
|
+
if (!margin) return connection.observer;
|
|
67
|
+
let observer = connection.triggers.get(margin);
|
|
68
|
+
if (!observer) {
|
|
69
|
+
// Resolve options before anything is hidden: an invalid rootMargin throws
|
|
70
|
+
// through enhance.js's error reporting and leaves the content visible.
|
|
71
|
+
observer = new IntersectionObserver(
|
|
72
|
+
(entries) => {
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const record = connection.records.get(entry.target);
|
|
75
|
+
if (entry.isIntersecting && record) reveal(record);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{ rootMargin: margin },
|
|
79
|
+
);
|
|
80
|
+
connection.triggers.set(margin, observer);
|
|
81
|
+
}
|
|
82
|
+
return observer;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function reveal(record) {
|
|
86
|
+
if (record.done) return;
|
|
87
|
+
record.done = true;
|
|
88
|
+
record.element.classList.remove(CLASSES.pending);
|
|
89
|
+
record.initialObserver.unobserve(record.element);
|
|
90
|
+
record.observer.unobserve(record.element);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Focus reached a pending element: the content must be usable on this frame,
|
|
94
|
+
// not after an entrance. Only the animations that releasing the state started
|
|
95
|
+
// are finished, found by difference, so the runtime still names no effect and
|
|
96
|
+
// leaves a nested component's own motion alone. A CSS :focus-within override
|
|
97
|
+
// cannot do this: it lapses on blur and the entrance replays from the start.
|
|
98
|
+
function revealNow(record) {
|
|
99
|
+
if (record.done) return;
|
|
100
|
+
const { element } = record;
|
|
101
|
+
const running = new Set(element.getAnimations({ subtree: true }));
|
|
102
|
+
reveal(record);
|
|
103
|
+
// getAnimations() flushes style, so the entrance released above is listed.
|
|
104
|
+
for (const animation of element.getAnimations({ subtree: true })) {
|
|
105
|
+
if (running.has(animation)) continue;
|
|
106
|
+
// finish() throws on an animation that never ends.
|
|
107
|
+
if (animation.effect?.getComputedTiming().endTime === Infinity) continue;
|
|
108
|
+
animation.finish();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function cleanup(record, records) {
|
|
113
|
+
record.controller.abort();
|
|
114
|
+
record.initialObserver.unobserve(record.element);
|
|
115
|
+
record.observer.unobserve(record.element);
|
|
116
|
+
records.delete(record.element);
|
|
117
|
+
record.element.classList.remove(CLASSES.pending);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function connect(element) {
|
|
121
|
+
if (typeof IntersectionObserver === "undefined") return;
|
|
122
|
+
|
|
123
|
+
const connection = observerFor(element.ownerDocument);
|
|
124
|
+
const { observer, records } = connection;
|
|
125
|
+
const record = {
|
|
126
|
+
element,
|
|
127
|
+
initialObserver: observer,
|
|
128
|
+
observer: triggerFor(connection, element.getAttribute("data-in-view-margin")),
|
|
129
|
+
done: false,
|
|
130
|
+
controller: new AbortController(),
|
|
131
|
+
};
|
|
132
|
+
records.set(element, record);
|
|
133
|
+
|
|
134
|
+
// Focus may already sit inside the element before this registration (an
|
|
135
|
+
// autofocused control, a second runtime copy attaching late). Hiding it then
|
|
136
|
+
// would leave focus invisible until the observer's first callback.
|
|
137
|
+
if (element.contains(element.ownerDocument.activeElement)) {
|
|
138
|
+
reveal(record);
|
|
139
|
+
return () => cleanup(record, records);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Focus moves the page first, so this is the guarantee, not the observer:
|
|
143
|
+
// the element is visible by the time its descendant takes focus.
|
|
144
|
+
element.addEventListener("focusin", () => revealNow(record), {
|
|
145
|
+
signal: record.controller.signal,
|
|
146
|
+
});
|
|
147
|
+
observer.observe(element);
|
|
148
|
+
|
|
149
|
+
return () => cleanup(record, records);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
registerEnhancement("in-view", connect);
|