actual-css 0.18.0 → 0.19.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/CHANGELOG.md +48 -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 +1 -1
- 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/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/design-tokens.js +2 -0
- package/tokens.json +2 -0
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);
|
package/src/js/scrollspy.js
CHANGED
|
@@ -11,9 +11,13 @@
|
|
|
11
11
|
* share the viewport — and guesses wrong for sections shorter than the band.
|
|
12
12
|
*
|
|
13
13
|
* activation line = root top + offset (default 20% of the root's height)
|
|
14
|
+
* near scroll end = line advances to the root bottom over the last viewport
|
|
14
15
|
* active section = last section whose top <= activation line
|
|
15
16
|
* scrolled to end = last section, whatever the line says
|
|
16
17
|
* above the first = no active section
|
|
18
|
+
* followed link = its section, until the next scroll input
|
|
19
|
+
* (wheel, touch, key, pointer); the line then starts
|
|
20
|
+
* between that heading and the next and fades back
|
|
17
21
|
*
|
|
18
22
|
* Optional root: data-scrollspy-root="#scroll-container" measures against a
|
|
19
23
|
* scroll container instead of the viewport.
|
|
@@ -106,6 +110,10 @@ function setupNav(nav) {
|
|
|
106
110
|
let sections = [];
|
|
107
111
|
let frame = 0;
|
|
108
112
|
let current;
|
|
113
|
+
// A followed link bends the activation line to sit between its heading and
|
|
114
|
+
// the next: { section, held, scrollTop, remaining, floor, delta }. Held until
|
|
115
|
+
// the next scroll input, then faded; floor is where the upward fade ends.
|
|
116
|
+
let anchor = null;
|
|
109
117
|
|
|
110
118
|
function activate(section) {
|
|
111
119
|
if (section === current) return;
|
|
@@ -126,15 +134,55 @@ function setupNav(nav) {
|
|
|
126
134
|
|
|
127
135
|
const root = rootFor(nav);
|
|
128
136
|
const { top, height, scrollTop, scrollHeight } = measureRoot(nav, root);
|
|
137
|
+
const offset = activationOffset(nav, height);
|
|
138
|
+
// A fixed line followed by an end-of-scroll jump can skip whole sections
|
|
139
|
+
// on a tall viewport. Advance continuously through the final viewport of
|
|
140
|
+
// scroll travel so each intervening heading can become current first.
|
|
141
|
+
const remaining = scrollHeight - height - scrollTop;
|
|
142
|
+
const progress = height > 0 ? Math.max(0, Math.min(1, 1 - remaining / height)) : 0;
|
|
143
|
+
let line = top + offset + Math.max(0, height - offset) * progress;
|
|
144
|
+
|
|
145
|
+
// A followed link names its section outright. Near the end of the page
|
|
146
|
+
// the browser cannot scroll that heading up to the line, so geometry
|
|
147
|
+
// alone would keep a later section. While held (through a smooth scroll
|
|
148
|
+
// on the way there), the bend is recomputed at each position.
|
|
149
|
+
if (anchor?.held) {
|
|
150
|
+
const index = sections.findIndex(({ section }) => section === anchor.section);
|
|
151
|
+
const next = sections[index + 1]?.section;
|
|
152
|
+
const low = anchor.section.getBoundingClientRect().top;
|
|
153
|
+
const high = next ? next.getBoundingClientRect().top - 1 : Infinity;
|
|
154
|
+
Object.assign(anchor, {
|
|
155
|
+
scrollTop,
|
|
156
|
+
remaining,
|
|
157
|
+
floor: Math.max(0, scrollTop - height),
|
|
158
|
+
delta: Math.min(Math.max(line, low), high) - line,
|
|
159
|
+
});
|
|
160
|
+
line += anchor.delta;
|
|
161
|
+
} else if (anchor) {
|
|
162
|
+
// Released, the bend fades over the scroll travel left in each
|
|
163
|
+
// direction: down to the end of the content, up to one viewport above
|
|
164
|
+
// the release. Scrolling on then walks the neighbouring sections in
|
|
165
|
+
// order instead of jumping to whatever the unbent line picks there.
|
|
166
|
+
// Re-based on every measure, so it only ever shrinks: coming back to the
|
|
167
|
+
// release position does not bend the line again.
|
|
168
|
+
const travel = scrollTop - anchor.scrollTop;
|
|
169
|
+
const span = travel > 0 ? anchor.remaining : anchor.scrollTop - anchor.floor;
|
|
170
|
+
const delta = span > 0 ? anchor.delta * Math.max(0, 1 - Math.abs(travel) / span) : 0;
|
|
171
|
+
// Negated so NaN drops too: a pin released before its first measure.
|
|
172
|
+
if (!(Math.abs(delta) >= 0.5)) anchor = null;
|
|
173
|
+
else {
|
|
174
|
+
line += delta;
|
|
175
|
+
anchor = { ...anchor, scrollTop, remaining, delta };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
129
178
|
|
|
130
179
|
// Scrolled to the end: the last section wins even when its top never
|
|
131
180
|
// crosses the line. This is the case IntersectionObserver cannot express.
|
|
132
|
-
if (scrollHeight > height &&
|
|
181
|
+
if (!anchor && scrollHeight > height && remaining <= 1) {
|
|
133
182
|
activate(sections.at(-1).section);
|
|
134
183
|
return;
|
|
135
184
|
}
|
|
136
185
|
|
|
137
|
-
const line = top + activationOffset(nav, height);
|
|
138
186
|
let active = null;
|
|
139
187
|
for (const { section } of sections) {
|
|
140
188
|
if (section.getBoundingClientRect().top <= line) active = section;
|
|
@@ -151,9 +199,17 @@ function setupNav(nav) {
|
|
|
151
199
|
function rebuild() {
|
|
152
200
|
sections = sectionsFor(nav);
|
|
153
201
|
current = undefined;
|
|
202
|
+
anchor = null;
|
|
154
203
|
measure();
|
|
155
204
|
}
|
|
156
205
|
|
|
206
|
+
function pin(link) {
|
|
207
|
+
const entry = sections.find((candidate) => candidate.link === link);
|
|
208
|
+
if (!entry) return;
|
|
209
|
+
anchor = { section: entry.section, held: true };
|
|
210
|
+
schedule();
|
|
211
|
+
}
|
|
212
|
+
|
|
157
213
|
// The scroll root is resolved once when the enhancement connects, and the
|
|
158
214
|
// scroll listener stays on it. Changing data-scrollspy-root or replacing its
|
|
159
215
|
// target is outside the connection contract; recreate the enhancement with
|
|
@@ -168,6 +224,29 @@ function setupNav(nav) {
|
|
|
168
224
|
signal: controller.signal,
|
|
169
225
|
});
|
|
170
226
|
|
|
227
|
+
const doc = nav.ownerDocument;
|
|
228
|
+
nav.addEventListener("click", (event) => pin(event.target.closest?.("a[href^='#']")), {
|
|
229
|
+
signal: controller.signal,
|
|
230
|
+
});
|
|
231
|
+
// Another in-page link, or history navigation, to one of the sections.
|
|
232
|
+
doc.defaultView?.addEventListener(
|
|
233
|
+
"hashchange",
|
|
234
|
+
() => pin(sections.find(({ link }) => link.hash === doc.location.hash)?.link),
|
|
235
|
+
{ signal: controller.signal },
|
|
236
|
+
);
|
|
237
|
+
// Scroll input, not the scroll event: the navigation itself scrolls. Capture
|
|
238
|
+
// runs before the click that may pin again (pointerdown, Enter on a link).
|
|
239
|
+
for (const type of ["wheel", "touchstart", "keydown", "pointerdown"]) {
|
|
240
|
+
doc.addEventListener(
|
|
241
|
+
type,
|
|
242
|
+
() => {
|
|
243
|
+
// No measure here: the scroll this input causes runs it.
|
|
244
|
+
if (anchor) anchor.held = false;
|
|
245
|
+
},
|
|
246
|
+
{ capture: true, passive: true, signal: controller.signal },
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
171
250
|
// Observer is scoped to the nav subtree — link injection is caught;
|
|
172
251
|
// section-only DOM mutations elsewhere need an explicit refreshScrollspy().
|
|
173
252
|
const mo = new MutationObserver(() => schedule(rebuild));
|
package/src/js/selectors.js
CHANGED
|
@@ -35,6 +35,9 @@ export const CLASSES = {
|
|
|
35
35
|
// surface.js — state class on the open flyout/menu/dialog surface.
|
|
36
36
|
// status.js writes the same class on the status bar while a message shows.
|
|
37
37
|
open: "is-open",
|
|
38
|
+
// in-view.js — transient state on an element that waits outside the viewport
|
|
39
|
+
// for its first appearance. Each effect's CSS decides how to hide it.
|
|
40
|
+
pending: "is-pending",
|
|
38
41
|
// dialog.js — transient class for the "can't dismiss" shake animation.
|
|
39
42
|
static: "is-static",
|
|
40
43
|
// dialog.js — written on <html> while any modal dialog is open.
|