@repobit/dex-system-design 2.5.1 → 2.7.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 +91 -0
- package/README.md +2 -1
- package/package.json +14 -27
- package/schemas/component-manifest.json +233 -33
- package/schemas/manifest-omissions.json +23 -0
- package/src/components/accordion/accordion-bg.css.js +39 -30
- package/src/components/accordion/accordion-bg.js +17 -28
- package/src/components/accordion/accordion-bg.stories.js +5 -0
- package/src/components/accordion/accordion-panel.js +24 -0
- package/src/components/accordion/accordion.css.js +105 -111
- package/src/components/accordion/accordion.js +23 -37
- package/src/components/accordion/accordion.stories.js +5 -1
- package/src/components/anchor/anchor-nav.css.js +131 -53
- package/src/components/anchor/anchor-nav.js +276 -201
- package/src/components/annotation/annotation.css.js +7 -4
- package/src/components/architecture.stories.js +8 -7
- package/src/components/audience-card/audience-card.css.js +30 -4
- package/src/components/audience-card/audience-card.js +8 -13
- package/src/components/awards/awards-flex.css.js +23 -6
- package/src/components/awards/awards-flex.js +21 -6
- package/src/components/awards/awards-spotlight.css.js +25 -5
- package/src/components/awards/awards-spotlight.js +19 -7
- package/src/components/awards/awards.css.js +20 -8
- package/src/components/awards/awards.js +30 -91
- package/src/components/awards/awards.stories.js +5 -5
- package/src/components/awards/scroll-slides.js +128 -0
- package/src/components/back/back.css.js +2 -0
- package/src/components/badge/badge.css.js +15 -0
- package/src/components/bento-grid/bento-grid.css.js +105 -11
- package/src/components/bento-grid/bento-grid.js +37 -124
- package/src/components/bento-grid/bento-grid.stories.js +3 -2
- package/src/components/bento-grid/bento-item.css.js +71 -32
- package/src/components/bento-grid/bento-item.js +1 -30
- package/src/components/blockquote/blockquote.css.js +2 -2
- package/src/components/breadcrumb/breadcrumb.css.js +10 -9
- package/src/components/breadcrumb/breadcrumb.js +35 -34
- package/src/components/button/button.css.js +42 -17
- package/src/components/button/button.js +84 -3
- package/src/components/button/button.stories.js +17 -0
- package/src/components/card-features/card-features.css.js +23 -2
- package/src/components/card-features/card-features.js +6 -48
- package/src/components/cards/card.css.js +43 -14
- package/src/components/cards/card.js +43 -177
- package/src/components/cards/card.stories.js +8 -10
- package/src/components/carousel/carousel.css.js +101 -70
- package/src/components/carousel/carousel.js +107 -71
- package/src/components/carousel/carousel.stories.js +18 -16
- package/src/components/checkbox/checkbox.css.js +26 -9
- package/src/components/checkbox/checkbox.js +73 -39
- package/src/components/checkbox/checkbox.stories.js +35 -18
- package/src/components/compare/compare.css.js +68 -10
- package/src/components/compare/compare.js +40 -103
- package/src/components/compare/compare.stories.js +1 -1
- package/src/components/compatibility-table/compatibility-table.css.js +70 -37
- package/src/components/compatibility-table/compatibility-table.js +47 -40
- package/src/components/compatibility-table/compatibility-table.stories.js +78 -1
- package/src/components/display/display.css.js +7 -0
- package/src/components/dropdown/dropdown.css.js +20 -3
- package/src/components/dropdown/dropdown.js +57 -21
- package/src/components/dropdown/dropdown.stories.js +31 -9
- package/src/components/features/features.css.js +56 -21
- package/src/components/features/features.js +7 -117
- package/src/components/fieldset/fieldset.stories.js +68 -0
- package/src/components/footer/footer-images.js +34 -0
- package/src/components/footer/footer-links-group.css.js +10 -10
- package/src/components/footer/footer-locale.js +47 -0
- package/src/components/footer/footer-lp.js +27 -114
- package/src/components/footer/footer-lp.stories.js +2 -2
- package/src/components/footer/footer-nav-menu.css.js +2 -2
- package/src/components/footer/footer-nav-menu.js +8 -3
- package/src/components/footer/footer.css.js +228 -197
- package/src/components/footer/footer.js +109 -187
- package/src/components/footer/footer.stories.js +14 -4
- package/src/components/grid/grid.css.js +56 -20
- package/src/components/grid/grid.js +20 -15
- package/src/components/grid/grid.stories.js +39 -11
- package/src/components/header/header-code.css.js +20 -11
- package/src/components/header/header-code.js +1 -1
- package/src/components/header/header.css.js +20 -14
- package/src/components/header/header.js +6 -7
- package/src/components/header/header.stories.js +29 -24
- package/src/components/heading/heading.css.js +11 -0
- package/src/components/hero/hero.js +10 -2
- package/src/components/highlight/highlight.css.js +30 -6
- package/src/components/icons/arrow-icon.js +4 -1
- package/src/components/icons/arrow-right-icon.js +5 -1
- package/src/components/icons/icon-element.js +18 -0
- package/src/components/image/image.js +29 -9
- package/src/components/image/image.stories.js +38 -2
- package/src/components/input/custom-form.stories.js +38 -7
- package/src/components/input/input-clipboard.css.js +15 -1
- package/src/components/input/input-clipboard.js +84 -21
- package/src/components/input/input.js +27 -7
- package/src/components/install-options/install-options.css.js +26 -6
- package/src/components/install-options/install-options.js +32 -8
- package/src/components/label/label.css.js +1 -1
- package/src/components/light-carousel/light-carousel.css.js +100 -48
- package/src/components/light-carousel/light-carousel.js +43 -5
- package/src/components/link/link.css.js +15 -15
- package/src/components/link/link.js +17 -1
- package/src/components/link/link.stories.js +20 -7
- package/src/components/list/list.css.js +3 -3
- package/src/components/logo-marquee/logo-marquee.css.js +12 -1
- package/src/components/logo-marquee/logo-marquee.js +33 -8
- package/src/components/logo-marquee/logo-marquee.stories.js +10 -4
- package/src/components/modal/modal.css.js +74 -40
- package/src/components/modal/modal.js +85 -74
- package/src/components/modal/modal.stories.js +27 -14
- package/src/components/motion-art/motion-art.js +67 -1
- package/src/components/page-switcher/page-switcher.css.js +27 -9
- package/src/components/page-switcher/page-switcher.js +11 -8
- package/src/components/partner-banner/partner-banner.css.js +2 -0
- package/src/components/picture/picture.css.js +4 -4
- package/src/components/picture/picture.js +13 -3
- package/src/components/picture/picture.stories.js +28 -2
- package/src/components/post-card/post-card.css.js +18 -3
- package/src/components/pricing-cards/adopt-styles.js +16 -0
- package/src/components/pricing-cards/new-pricing-card.js +2 -4
- package/src/components/pricing-cards/new-pricing-card.stories.js +20 -22
- package/src/components/pricing-cards/pricing-card-actions.css.js +8 -12
- package/src/components/pricing-cards/pricing-card-actions.js +26 -13
- package/src/components/pricing-cards/pricing-card-container.css.js +4 -3
- package/src/components/pricing-cards/pricing-card-container.js +10 -4
- package/src/components/pricing-cards/pricing-card-header.css.js +5 -4
- package/src/components/pricing-cards/pricing-card-header.js +18 -31
- package/src/components/pricing-cards/pricing-card-pricing.css.js +84 -61
- package/src/components/pricing-cards/pricing-card-pricing.js +38 -24
- package/src/components/pricing-cards/pricing-card-show-more.js +8 -3
- package/src/components/pricing-cards/pricing-card.css.js +75 -41
- package/src/components/pricing-cards/pricing-card.js +356 -308
- package/src/components/progress/progress.css.js +58 -13
- package/src/components/progress/progress.js +13 -10
- package/src/components/progress/progress.stories.js +9 -7
- package/src/components/radio/radio-group.css.js +42 -0
- package/src/components/radio/radio-group.js +89 -0
- package/src/components/radio/radio.css.js +63 -6
- package/src/components/radio/radio.js +173 -140
- package/src/components/radio/radio.stories.js +99 -44
- package/src/components/radio/toggle-radio.js +44 -0
- package/src/components/review/review-grid.css.js +5 -1
- package/src/components/review/review-grid.js +2 -0
- package/src/components/review/review.js +13 -0
- package/src/components/shared/announcer.js +37 -0
- package/src/components/shared/fill-width.css.js +29 -0
- package/src/components/shared/form-control.js +194 -0
- package/src/components/shared/form-field.css.js +31 -3
- package/src/components/shared/token-scales.js +75 -26
- package/src/components/spotlight-section/spotlight-section.js +2 -2
- package/src/components/stat/stat-highlight.js +1 -1
- package/src/components/stat/stat.css.js +18 -3
- package/src/components/switch/switch.css.js +58 -5
- package/src/components/switch/switch.js +53 -5
- package/src/components/switch/switch.stories.js +30 -8
- package/src/components/tab-list/tab-list.css.js +51 -13
- package/src/components/tab-list/tab-list.js +7 -2
- package/src/components/tab-list/tab-list.stories.js +2 -2
- package/src/components/tabs/tabs.css.js +18 -1
- package/src/components/tabs/tabs.js +119 -41
- package/src/components/terminal/terminal-message.css.js +6 -1
- package/src/components/termsOfUse/terms.css.js +4 -2
- package/src/components/textarea/textarea.js +22 -7
- package/src/components/textarea/textarea.stories.js +12 -9
- package/src/components/trust-panel/trust-panel.css.js +13 -3
- package/src/components/ultimate-security-demo.stories.js +5 -5
- package/src/components/video/video.css.js +5 -0
- package/src/components/video/video.js +5 -0
- package/src/components/video/video.stories.js +12 -0
- package/src/components/video-player/video-player.css.js +20 -8
- package/src/components/video-player/video-player.js +74 -20
- package/src/components/video-player/video-player.stories.js +17 -3
- package/src/tokens/brands.stories.js +1 -1
- package/src/tokens/themes/index.js +2 -2
- package/src/tokens/typography.stories.js +4 -3
- package/src/vendor/motion-art/README.md +4 -1
- package/src/components/footer/footer-lp.css.js +0 -159
|
@@ -19,6 +19,21 @@ function parseLengthToPx(value) {
|
|
|
19
19
|
return parseFloat(s) || 0;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const sectionIdOf = (href, n) => (href || "").replace(/^#/, "") || `anchor-${n}-section`;
|
|
23
|
+
|
|
24
|
+
/* "The rest of the page" as a root margin: a hundred viewports. Each observer
|
|
25
|
+
below watches one edge, and a jump only registers if it carries a section
|
|
26
|
+
across that edge while still inside the root -- so the root reaches this far
|
|
27
|
+
past the edge, beyond any jump a real page makes. */
|
|
28
|
+
const FAR = "10000%";
|
|
29
|
+
|
|
30
|
+
/* The dropdown panel is a popover only where it can also be anchored to its
|
|
31
|
+
toggle: in the top layer it leaves the toggle's box, and without anchor
|
|
32
|
+
positioning it would sit in the middle of the viewport. Both are newer than
|
|
33
|
+
the Widely available target, so elsewhere the panel keeps its z-index and
|
|
34
|
+
the document listeners close it. */
|
|
35
|
+
const NATIVE_POPOVER = "popover" in HTMLElement.prototype && CSS.supports("anchor-name: --a");
|
|
36
|
+
|
|
22
37
|
class BdAnchorNavItem extends HTMLElement {
|
|
23
38
|
constructor() {
|
|
24
39
|
super();
|
|
@@ -56,16 +71,25 @@ class BdAnchorNav extends LitElement {
|
|
|
56
71
|
this.stickyTop = "0px";
|
|
57
72
|
this._panelId = `bd-anchor-nav-panel-${Math.random().toString(36)
|
|
58
73
|
.slice(2, 11)}`;
|
|
59
|
-
this._onScrollSpy = this._onScrollSpy.bind(this);
|
|
60
74
|
this._onDocumentPointerDown = this._onDocumentPointerDown.bind(this);
|
|
61
75
|
this._onKeydown = this._onKeydown.bind(this);
|
|
62
|
-
this.
|
|
76
|
+
this._onSectionsCrossLine = this._onSectionsCrossLine.bind(this);
|
|
77
|
+
this._onFirstSectionCross = this._onFirstSectionCross.bind(this);
|
|
78
|
+
this._scheduleSpy = this._scheduleSpy.bind(this);
|
|
79
|
+
this._spyFrame = 0;
|
|
80
|
+
this._spyObserver = null;
|
|
81
|
+
this._ctaObserver = null;
|
|
82
|
+
this._layoutObserver = null;
|
|
83
|
+
this._sections = [];
|
|
84
|
+
this._spyLine = 0;
|
|
85
|
+
this._spyViewport = 0;
|
|
86
|
+
this._passed = new Map();
|
|
87
|
+
this._firstSectionBehind = false;
|
|
63
88
|
this._programmaticScrollTargetId = null;
|
|
64
89
|
this._unlockScrollSpyTimer = null;
|
|
65
90
|
this._scrollEndUnlockHandler = null;
|
|
66
|
-
this._stickyOriginalTop = null;
|
|
67
|
-
this._stickyPlaceholder = null;
|
|
68
91
|
this._onStickyScroll = null;
|
|
92
|
+
this._restoreScrollBehavior = null;
|
|
69
93
|
this._handleResize = this._handleResize.bind(this);
|
|
70
94
|
this._indicatorReady = false;
|
|
71
95
|
this._indicatorResizeObserver = null;
|
|
@@ -73,25 +97,37 @@ class BdAnchorNav extends LitElement {
|
|
|
73
97
|
|
|
74
98
|
connectedCallback() {
|
|
75
99
|
super.connectedCallback();
|
|
76
|
-
window.addEventListener("scroll", this._onScrollSpy, { passive: true });
|
|
77
|
-
window.addEventListener("resize", this._onScrollSpy, { passive: true });
|
|
78
100
|
window.addEventListener("resize", this._handleResize);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
101
|
+
if (!NATIVE_POPOVER) {
|
|
102
|
+
document.addEventListener("pointerdown", this._onDocumentPointerDown, true);
|
|
103
|
+
document.addEventListener("keydown", this._onKeydown, true);
|
|
104
|
+
}
|
|
82
105
|
this._initSticky();
|
|
106
|
+
/* The bar's height moves the line the sections are read against, and the
|
|
107
|
+
page growing may bring a section that was not there yet. */
|
|
108
|
+
this._layoutObserver = new ResizeObserver(this._scheduleSpy);
|
|
109
|
+
this._layoutObserver.observe(this);
|
|
110
|
+
this._layoutObserver.observe(document.documentElement);
|
|
83
111
|
}
|
|
84
112
|
|
|
85
113
|
disconnectedCallback() {
|
|
86
114
|
super.disconnectedCallback();
|
|
87
115
|
this._cancelScrollSpyUnlock();
|
|
88
|
-
|
|
89
|
-
window.removeEventListener("resize", this._onScrollSpy);
|
|
116
|
+
this._restoreScrollBehavior?.();
|
|
90
117
|
window.removeEventListener("resize", this._handleResize);
|
|
91
118
|
document.removeEventListener("pointerdown", this._onDocumentPointerDown, true);
|
|
92
119
|
document.removeEventListener("keydown", this._onKeydown, true);
|
|
93
120
|
this._destroySticky();
|
|
94
121
|
this._indicatorResizeObserver?.disconnect();
|
|
122
|
+
this._unobserveSections();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* The first item is active before the first render, not after it: state set
|
|
126
|
+
in firstUpdated or updated starts a second render, the one Lit warns about
|
|
127
|
+
as change-in-update. */
|
|
128
|
+
willUpdate(changedProperties) {
|
|
129
|
+
super.willUpdate(changedProperties);
|
|
130
|
+
if (!this.hasUpdated && !this.activeId && this._resolvedItems().length) this.activeId = "anchor-1";
|
|
95
131
|
}
|
|
96
132
|
|
|
97
133
|
updated(changedProperties) {
|
|
@@ -99,7 +135,10 @@ class BdAnchorNav extends LitElement {
|
|
|
99
135
|
|
|
100
136
|
if (changedProperties.has("stickyTop")) {
|
|
101
137
|
this.style.setProperty("--sticky-top", this.stickyTop || "0px");
|
|
102
|
-
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (changedProperties.has("stickyTop") || changedProperties.has("items")) {
|
|
141
|
+
this._scheduleSpy();
|
|
103
142
|
}
|
|
104
143
|
|
|
105
144
|
if (changedProperties.has("activeId") || changedProperties.has("items")) {
|
|
@@ -114,17 +153,10 @@ class BdAnchorNav extends LitElement {
|
|
|
114
153
|
}
|
|
115
154
|
|
|
116
155
|
firstUpdated() {
|
|
117
|
-
const resolved = this._resolvedItems();
|
|
118
|
-
if (resolved.length) {
|
|
119
|
-
this.activeId = "anchor-1";
|
|
120
|
-
this.requestUpdate();
|
|
121
|
-
}
|
|
122
|
-
queueMicrotask(() => this._runScrollSpy());
|
|
123
|
-
this._handleMobileFullWidth();
|
|
124
156
|
requestAnimationFrame(() => this._updateIndicator("firstUpdated"));
|
|
125
157
|
|
|
126
158
|
const links = this.renderRoot?.querySelector(".anchor-links--desktop");
|
|
127
|
-
if (links
|
|
159
|
+
if (links) {
|
|
128
160
|
this._indicatorResizeObserver = new ResizeObserver(() => {
|
|
129
161
|
this._updateIndicator("ResizeObserver");
|
|
130
162
|
});
|
|
@@ -133,137 +165,83 @@ class BdAnchorNav extends LitElement {
|
|
|
133
165
|
}
|
|
134
166
|
}
|
|
135
167
|
|
|
168
|
+
/* The indicator spans the link row and is moved and sized on the
|
|
169
|
+
compositor: translate to the current link's corner, scale to its width.
|
|
170
|
+
It used to animate top and width, which laid the bar out again on every
|
|
171
|
+
frame of the slide. The offsets are physical -- offsetLeft is -- so the
|
|
172
|
+
indicator is anchored at the row's physical left, on a right-to-left
|
|
173
|
+
page too. */
|
|
136
174
|
_updateIndicator() {
|
|
137
175
|
const indicator = this.renderRoot?.querySelector(".anchor-indicator");
|
|
138
176
|
const activeLink = this.renderRoot?.querySelector(
|
|
139
|
-
".anchor-links--desktop .anchor-link
|
|
177
|
+
".anchor-links--desktop .anchor-link[current]"
|
|
140
178
|
);
|
|
141
179
|
if (!indicator || !activeLink) return;
|
|
142
180
|
|
|
143
|
-
const
|
|
144
|
-
const
|
|
181
|
+
const row = indicator.offsetWidth;
|
|
182
|
+
const scale = row ? activeLink.offsetWidth / row : 0;
|
|
145
183
|
// The bar's bottom edge is the inner's padding-bottom below the link.
|
|
146
184
|
const inner = this.renderRoot.querySelector(".bd-anchor-nav__inner");
|
|
147
185
|
const gap = inner ? parseFloat(getComputedStyle(inner).paddingBottom) || 0 : 0;
|
|
148
186
|
const top = activeLink.offsetTop + activeLink.offsetHeight + gap;
|
|
149
187
|
|
|
188
|
+
const place = () => {
|
|
189
|
+
indicator.style.translate = `${activeLink.offsetLeft}px ${top}px`;
|
|
190
|
+
indicator.style.scale = `${scale} 1`;
|
|
191
|
+
};
|
|
192
|
+
|
|
150
193
|
if (!this._indicatorReady) {
|
|
151
194
|
indicator.style.transition = "none";
|
|
152
|
-
|
|
153
|
-
indicator.style.top = `${top}px`;
|
|
154
|
-
indicator.style.width = `${width}px`;
|
|
195
|
+
place();
|
|
155
196
|
void indicator.offsetWidth;
|
|
156
197
|
indicator.style.transition = "";
|
|
157
198
|
this._indicatorReady = true;
|
|
158
199
|
return;
|
|
159
200
|
}
|
|
160
201
|
|
|
161
|
-
|
|
162
|
-
indicator.style.top = `${top}px`;
|
|
163
|
-
indicator.style.width = `${width}px`;
|
|
202
|
+
place();
|
|
164
203
|
}
|
|
165
204
|
|
|
166
205
|
_handleResize() {
|
|
167
|
-
this._handleMobileFullWidth();
|
|
168
206
|
this._updateIndicator("windowResize");
|
|
207
|
+
// The viewport's height places the spy's line inside its root.
|
|
208
|
+
this._scheduleSpy();
|
|
169
209
|
}
|
|
170
210
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
buttonLink.removeAttribute('fullwidth');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
211
|
+
/* The bar sticks with position: sticky, which keeps its own place in the
|
|
212
|
+
flow and lets go at the end of its parent, so nothing here positions it.
|
|
213
|
+
It used to: past its top it switched to position: fixed at the
|
|
214
|
+
viewport's width, measured its parent to know when to let go, and left a
|
|
215
|
+
placeholder behind to hold its space.
|
|
216
|
+
|
|
217
|
+
While stuck it draws a shadow. A scroll-state container query says when
|
|
218
|
+
that is, and it is newer than the Widely available target; where it is
|
|
219
|
+
missing, this tells instead: the bar sits at its sticky top -- read as
|
|
220
|
+
the browser resolved it, as _stickyOffsetPx() reads it, so calc(), em
|
|
221
|
+
and custom properties count -- and the page has scrolled. A bar that
|
|
222
|
+
merely rests at that line on an unscrolled page is not stuck, as the
|
|
223
|
+
query would not call it. */
|
|
189
224
|
_initSticky() {
|
|
190
|
-
this._stickyOriginalTop = null;
|
|
191
225
|
this.style.setProperty("--sticky-top", this.stickyTop || "0px");
|
|
226
|
+
if (CSS.supports("container-type: scroll-state")) return;
|
|
192
227
|
|
|
193
228
|
this._onStickyScroll = () => {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const parentRect = parent.getBoundingClientRect();
|
|
198
|
-
const navHeight = this._stickyPlaceholder
|
|
199
|
-
? this._stickyPlaceholder.offsetHeight
|
|
200
|
-
: this.offsetHeight;
|
|
201
|
-
const stickyTopPx = parseLengthToPx(
|
|
202
|
-
this.style.getPropertyValue("--sticky-top") || this.stickyTop
|
|
203
|
-
) || 0;
|
|
204
|
-
|
|
205
|
-
if (this._stickyOriginalTop === null) {
|
|
206
|
-
const rect = this.getBoundingClientRect();
|
|
207
|
-
this._stickyOriginalTop = rect.top + window.scrollY - stickyTopPx;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const passedTop = window.scrollY >= this._stickyOriginalTop;
|
|
211
|
-
const parentExited = parentRect.bottom <= navHeight + stickyTopPx;
|
|
212
|
-
|
|
213
|
-
if (passedTop && !parentExited) {
|
|
214
|
-
if (!this.classList.contains("is-sticky")) {
|
|
215
|
-
if (!this._stickyPlaceholder) {
|
|
216
|
-
this._stickyPlaceholder = document.createElement("div");
|
|
217
|
-
this._stickyPlaceholder.style.height = `${this.offsetHeight}px`;
|
|
218
|
-
this._stickyPlaceholder.style.display = "block";
|
|
219
|
-
this.parentNode.insertBefore(this._stickyPlaceholder, this);
|
|
220
|
-
}
|
|
221
|
-
this.classList.add("is-sticky");
|
|
222
|
-
}
|
|
223
|
-
this.style.setProperty("--sticky-left", "0px");
|
|
224
|
-
this.style.setProperty("--sticky-width", `${document.documentElement.clientWidth}px`);
|
|
225
|
-
} else {
|
|
226
|
-
if (this.classList.contains("is-sticky")) {
|
|
227
|
-
this.classList.remove("is-sticky");
|
|
228
|
-
this.style.removeProperty("--sticky-left");
|
|
229
|
-
this.style.removeProperty("--sticky-width");
|
|
230
|
-
if (this._stickyPlaceholder) {
|
|
231
|
-
this._stickyPlaceholder.remove();
|
|
232
|
-
this._stickyPlaceholder = null;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
this._onStickyResize = () => {
|
|
239
|
-
this._stickyOriginalTop = null;
|
|
240
|
-
if (this.classList.contains("is-sticky")) {
|
|
241
|
-
this.style.setProperty("--sticky-left", "0px");
|
|
242
|
-
this.style.setProperty("--sticky-width", `${document.documentElement.clientWidth}px`);
|
|
243
|
-
}
|
|
244
|
-
this._onStickyScroll();
|
|
229
|
+
const top = parseFloat(getComputedStyle(this).top) || 0;
|
|
230
|
+
const atTop = Math.abs(this.getBoundingClientRect().top - top) < 1;
|
|
231
|
+
this.classList.toggle("is-sticky", atTop && window.scrollY > 0);
|
|
245
232
|
};
|
|
246
|
-
|
|
247
233
|
window.addEventListener("scroll", this._onStickyScroll, { passive: true });
|
|
248
|
-
window.addEventListener("resize", this.
|
|
249
|
-
|
|
234
|
+
window.addEventListener("resize", this._onStickyScroll, { passive: true });
|
|
235
|
+
/* Removed within a frame of connecting, the bar has torn this down. */
|
|
236
|
+
requestAnimationFrame(() => this._onStickyScroll?.());
|
|
250
237
|
}
|
|
251
238
|
|
|
252
239
|
_destroySticky() {
|
|
253
240
|
if (this._onStickyScroll) {
|
|
254
241
|
window.removeEventListener("scroll", this._onStickyScroll);
|
|
242
|
+
window.removeEventListener("resize", this._onStickyScroll);
|
|
255
243
|
this._onStickyScroll = null;
|
|
256
244
|
}
|
|
257
|
-
if (this._onStickyResize) {
|
|
258
|
-
window.removeEventListener("resize", this._onStickyResize);
|
|
259
|
-
this._onStickyResize = null;
|
|
260
|
-
}
|
|
261
|
-
if (this._stickyPlaceholder) {
|
|
262
|
-
this._stickyPlaceholder.remove();
|
|
263
|
-
this._stickyPlaceholder = null;
|
|
264
|
-
}
|
|
265
|
-
this.style.removeProperty("--sticky-left");
|
|
266
|
-
this.style.removeProperty("--sticky-width");
|
|
267
245
|
this.classList.remove("is-sticky");
|
|
268
246
|
}
|
|
269
247
|
|
|
@@ -278,31 +256,30 @@ class BdAnchorNav extends LitElement {
|
|
|
278
256
|
}
|
|
279
257
|
}
|
|
280
258
|
|
|
259
|
+
/* The click's item stays active until the scroll is over. scrollend says so
|
|
260
|
+
where the browser has it. The timer is for a click that scrolls nothing,
|
|
261
|
+
which no scrollend follows, and for browsers without the event: it ends
|
|
262
|
+
the lock once the page has stopped moving. It used to end it after a
|
|
263
|
+
fixed second, and a long smooth scroll outlasts that -- measured 1.3s
|
|
264
|
+
from the first section to the third on the playground at 1280, with the
|
|
265
|
+
second item lit for the last 250ms of it. */
|
|
281
266
|
_scheduleScrollSpyUnlock() {
|
|
282
267
|
this._cancelScrollSpyUnlock();
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
this._unlockScrollSpyTimer = null;
|
|
287
|
-
}
|
|
288
|
-
window.removeEventListener("scrollend", onScrollEnd);
|
|
289
|
-
this._scrollEndUnlockHandler = null;
|
|
268
|
+
const unlock = () => {
|
|
269
|
+
this._cancelScrollSpyUnlock();
|
|
270
|
+
this._restoreScrollBehavior?.();
|
|
290
271
|
this._programmaticScrollTargetId = null;
|
|
291
272
|
this._runScrollSpy();
|
|
292
273
|
};
|
|
293
|
-
this._scrollEndUnlockHandler =
|
|
294
|
-
window.addEventListener("scrollend",
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this._programmaticScrollTargetId = null;
|
|
303
|
-
this._runScrollSpy();
|
|
304
|
-
}
|
|
305
|
-
}, 1000);
|
|
274
|
+
this._scrollEndUnlockHandler = unlock;
|
|
275
|
+
window.addEventListener("scrollend", unlock, { passive: true });
|
|
276
|
+
let lastY = window.scrollY;
|
|
277
|
+
const unlockOnceStill = () => {
|
|
278
|
+
if (window.scrollY === lastY) return unlock();
|
|
279
|
+
lastY = window.scrollY;
|
|
280
|
+
this._unlockScrollSpyTimer = window.setTimeout(unlockOnceStill, 250);
|
|
281
|
+
};
|
|
282
|
+
this._unlockScrollSpyTimer = window.setTimeout(unlockOnceStill, 250);
|
|
306
283
|
}
|
|
307
284
|
|
|
308
285
|
_onKeydown(e) {
|
|
@@ -322,15 +299,99 @@ class BdAnchorNav extends LitElement {
|
|
|
322
299
|
this.requestUpdate();
|
|
323
300
|
}
|
|
324
301
|
|
|
325
|
-
|
|
326
|
-
if (this.
|
|
327
|
-
this.
|
|
328
|
-
|
|
329
|
-
this.
|
|
330
|
-
this._runScrollSpy();
|
|
302
|
+
_scheduleSpy() {
|
|
303
|
+
if (this._spyFrame) return;
|
|
304
|
+
this._spyFrame = requestAnimationFrame(() => {
|
|
305
|
+
this._spyFrame = 0;
|
|
306
|
+
this._observeSections();
|
|
331
307
|
});
|
|
332
308
|
}
|
|
333
309
|
|
|
310
|
+
/* Scroll-spy, without reading the page on every scroll. The active item is
|
|
311
|
+
the last section whose top has reached a line just under the stuck bar,
|
|
312
|
+
and two IntersectionObservers say when an edge crosses:
|
|
313
|
+
|
|
314
|
+
- the spy's root ends at that line and reaches FAR above it, so a section
|
|
315
|
+
is inside it exactly while its top is past the line;
|
|
316
|
+
- the CTA's root starts at the top of the viewport and reaches FAR below,
|
|
317
|
+
so the first section leaves it exactly when its bottom scrolls off.
|
|
318
|
+
|
|
319
|
+
Each entry carries the target's box, so the callbacks read nothing. The
|
|
320
|
+
line depends on the bar's height, the sticky top and the viewport, and a
|
|
321
|
+
root margin cannot change, so the observers are rebuilt when one moves. */
|
|
322
|
+
_observeSections() {
|
|
323
|
+
const sections = this._resolvedItems()
|
|
324
|
+
.map(({ href }, i) => document.getElementById(sectionIdOf(href, i + 1)));
|
|
325
|
+
const offset = this._stickyOffsetPx();
|
|
326
|
+
// 2px under where a click leaves the section, so a section the bar has just
|
|
327
|
+
// scrolled to counts as reached.
|
|
328
|
+
const line = offset + 2;
|
|
329
|
+
const viewport = document.documentElement.clientHeight;
|
|
330
|
+
|
|
331
|
+
if (line === this._spyLine && viewport === this._spyViewport &&
|
|
332
|
+
sections.length === this._sections.length &&
|
|
333
|
+
sections.every((el, i) => el === this._sections[i])) return;
|
|
334
|
+
|
|
335
|
+
/* A section a click scrolls to stops under the bar, not behind it, and so
|
|
336
|
+
does one the URL's hash or the back button brings into view. */
|
|
337
|
+
for (const el of this._sections) {
|
|
338
|
+
if (el && !sections.includes(el)) el.style.removeProperty("scroll-margin-top");
|
|
339
|
+
}
|
|
340
|
+
for (const el of sections) el?.style.setProperty("scroll-margin-top", `${offset}px`);
|
|
341
|
+
|
|
342
|
+
this._spyObserver?.disconnect();
|
|
343
|
+
this._ctaObserver?.disconnect();
|
|
344
|
+
this._spyObserver = this._ctaObserver = null;
|
|
345
|
+
if (sections[0] !== this._sections[0]) this._firstSectionBehind = false;
|
|
346
|
+
this._passed = new Map(sections.filter((el) => this._passed.has(el))
|
|
347
|
+
.map((el) => [el, this._passed.get(el)]));
|
|
348
|
+
this._sections = sections;
|
|
349
|
+
this._spyLine = line;
|
|
350
|
+
this._spyViewport = viewport;
|
|
351
|
+
|
|
352
|
+
const found = sections.filter(Boolean);
|
|
353
|
+
if (found.length) {
|
|
354
|
+
this._spyObserver = new IntersectionObserver(this._onSectionsCrossLine, {
|
|
355
|
+
root : document,
|
|
356
|
+
rootMargin: `${FAR} 0px ${line - viewport}px 0px`
|
|
357
|
+
});
|
|
358
|
+
found.forEach((el) => this._spyObserver.observe(el));
|
|
359
|
+
}
|
|
360
|
+
if (sections[0]) {
|
|
361
|
+
this._ctaObserver = new IntersectionObserver(this._onFirstSectionCross, {
|
|
362
|
+
root : document,
|
|
363
|
+
rootMargin: `0px 0px ${FAR} 0px`
|
|
364
|
+
});
|
|
365
|
+
this._ctaObserver.observe(sections[0]);
|
|
366
|
+
}
|
|
367
|
+
this._runScrollSpy();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
_unobserveSections() {
|
|
371
|
+
cancelAnimationFrame(this._spyFrame);
|
|
372
|
+
this._spyFrame = 0;
|
|
373
|
+
this._layoutObserver?.disconnect();
|
|
374
|
+
this._spyObserver?.disconnect();
|
|
375
|
+
this._ctaObserver?.disconnect();
|
|
376
|
+
this._layoutObserver = this._spyObserver = this._ctaObserver = null;
|
|
377
|
+
for (const el of this._sections) el?.style.removeProperty("scroll-margin-top");
|
|
378
|
+
this._sections = [];
|
|
379
|
+
this._passed = new Map();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
_onSectionsCrossLine(entries) {
|
|
383
|
+
for (const { target, boundingClientRect, rootBounds } of entries) {
|
|
384
|
+
this._passed.set(target, boundingClientRect.top <= rootBounds.bottom);
|
|
385
|
+
}
|
|
386
|
+
this._runScrollSpy();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
_onFirstSectionCross(entries) {
|
|
390
|
+
const { boundingClientRect, rootBounds } = entries[entries.length - 1];
|
|
391
|
+
this._firstSectionBehind = boundingClientRect.bottom <= rootBounds.top;
|
|
392
|
+
this._runScrollSpy();
|
|
393
|
+
}
|
|
394
|
+
|
|
334
395
|
_resolvedItems() {
|
|
335
396
|
if (this.items && this.items.length) {
|
|
336
397
|
return this.items.map((item, i) => ({
|
|
@@ -348,36 +409,22 @@ class BdAnchorNav extends LitElement {
|
|
|
348
409
|
}));
|
|
349
410
|
}
|
|
350
411
|
|
|
412
|
+
/* Read off what the observers last reported; while a click's scroll runs,
|
|
413
|
+
the item it chose stays active. The CTA flag is set at every width, since
|
|
414
|
+
only the stylesheet below md hides the CTA until the first section is
|
|
415
|
+
behind the reader. */
|
|
351
416
|
_runScrollSpy() {
|
|
352
|
-
|
|
353
|
-
const count = resolved.length;
|
|
354
|
-
let next = this.activeId;
|
|
417
|
+
let next = this.activeId;
|
|
355
418
|
|
|
356
|
-
if (
|
|
357
|
-
const y = window.scrollY + this._stickyOffsetPx() + 2;
|
|
419
|
+
if (this._sections.length && !this._programmaticScrollTargetId) {
|
|
358
420
|
next = "anchor-1";
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (!el) continue;
|
|
363
|
-
const top = el.getBoundingClientRect().top + window.scrollY;
|
|
364
|
-
if (top <= y) next = `anchor-${i + 1}`;
|
|
365
|
-
}
|
|
421
|
+
this._sections.forEach((el, i) => {
|
|
422
|
+
if (el && this._passed.get(el)) next = `anchor-${i + 1}`;
|
|
423
|
+
});
|
|
366
424
|
}
|
|
367
425
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const first = document.getElementById(firstHref);
|
|
371
|
-
let nextCta;
|
|
372
|
-
if (!isMobile) nextCta = true;
|
|
373
|
-
else if (!first) nextCta = true;
|
|
374
|
-
else nextCta = first.getBoundingClientRect().bottom <= 0;
|
|
375
|
-
|
|
376
|
-
if (this.activeId !== next || this._mobileCtaRevealed !== nextCta) {
|
|
377
|
-
this.activeId = next;
|
|
378
|
-
this._mobileCtaRevealed = nextCta;
|
|
379
|
-
this.requestUpdate();
|
|
380
|
-
}
|
|
426
|
+
this.activeId = next;
|
|
427
|
+
this._mobileCtaRevealed = !this._sections[0] || this._firstSectionBehind;
|
|
381
428
|
}
|
|
382
429
|
|
|
383
430
|
_playMobileDropdownLabelSwap() {
|
|
@@ -396,58 +443,84 @@ class BdAnchorNav extends LitElement {
|
|
|
396
443
|
);
|
|
397
444
|
}
|
|
398
445
|
|
|
446
|
+
/* Where a section stops under the bar: the sticky top, the bar, and a gap.
|
|
447
|
+
The sticky top is read as the browser resolved it, so any length
|
|
448
|
+
sticky-top accepts -- rem, calc(), a custom property -- counts. */
|
|
399
449
|
_stickyOffsetPx() {
|
|
400
|
-
const barPx
|
|
401
|
-
const stickyTopPx =
|
|
402
|
-
const insetRaw
|
|
450
|
+
const barPx = this.offsetHeight;
|
|
451
|
+
const stickyTopPx = parseFloat(getComputedStyle(this).top) || 0;
|
|
452
|
+
const insetRaw = getComputedStyle(this).getPropertyValue("--spacing-8")
|
|
403
453
|
.trim();
|
|
404
|
-
const insetPx
|
|
454
|
+
const insetPx = parseLengthToPx(insetRaw) || 8;
|
|
405
455
|
if (barPx > 0) return barPx + insetPx + stickyTopPx;
|
|
406
456
|
const fallback = getComputedStyle(this).getPropertyValue("--spacing-128")
|
|
407
457
|
.trim();
|
|
408
458
|
return parseLengthToPx(fallback) || 128;
|
|
409
459
|
}
|
|
410
460
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
461
|
+
/* A section link is an ordinary fragment link, and the browser follows it:
|
|
462
|
+
the hash goes into the URL as a history entry, :target moves to the
|
|
463
|
+
section, and the next Tab starts from there. This used to stop the
|
|
464
|
+
click and scroll by hand -- pushState and scrollIntoView -- which kept
|
|
465
|
+
the URL but left :target and the Tab position behind, so a keyboard
|
|
466
|
+
reader who chose "Pricing" tabbed on through the nav. The section's own
|
|
467
|
+
scroll-margin-top keeps it clear of the bar.
|
|
468
|
+
|
|
469
|
+
The click's item stays current until the scroll is over, so the spy
|
|
470
|
+
does not light the sections it passes on the way. A click with a
|
|
471
|
+
modifier, or on an item whose section is not on this page, is left to
|
|
472
|
+
the browser as an ordinary link. */
|
|
424
473
|
handleClick(event, id, href) {
|
|
425
|
-
event.
|
|
474
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
426
475
|
this._cancelScrollSpyUnlock();
|
|
427
|
-
this._programmaticScrollTargetId =
|
|
476
|
+
this._programmaticScrollTargetId = null;
|
|
428
477
|
this.activeId = id;
|
|
429
|
-
const sectionId = (href
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
478
|
+
const sectionId = sectionIdOf(href, id.replace(/^anchor-/, ""));
|
|
479
|
+
if (!document.getElementById(sectionId)) return;
|
|
480
|
+
|
|
481
|
+
this._programmaticScrollTargetId = id;
|
|
482
|
+
this._smoothFragmentScroll();
|
|
483
|
+
this._scheduleScrollSpyUnlock();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/* Fragment navigation scrolls with the root's scroll-behavior, and the
|
|
487
|
+
page's <html> is not this component's to style. So for a reader who has
|
|
488
|
+
not asked for less motion, the click sets it to smooth for the length of
|
|
489
|
+
this one scroll -- before the navigation runs, which is after the click
|
|
490
|
+
listeners -- and gives back whatever the page had when the scroll ends. */
|
|
491
|
+
_smoothFragmentScroll() {
|
|
492
|
+
if (this._restoreScrollBehavior) return;
|
|
493
|
+
if (!window.matchMedia("(prefers-reduced-motion: no-preference)").matches) return;
|
|
494
|
+
const root = document.documentElement;
|
|
495
|
+
const before = root.style.scrollBehavior;
|
|
496
|
+
root.style.scrollBehavior = "smooth";
|
|
497
|
+
this._restoreScrollBehavior = () => {
|
|
498
|
+
root.style.scrollBehavior = before;
|
|
499
|
+
this._restoreScrollBehavior = null;
|
|
500
|
+
};
|
|
438
501
|
}
|
|
439
502
|
|
|
503
|
+
/* With a native popover, popovertarget opens and closes the panel and the
|
|
504
|
+
toggle event reports it; this handler is the fallback's. */
|
|
440
505
|
_toggleDropdown(e) {
|
|
506
|
+
if (NATIVE_POPOVER) return;
|
|
441
507
|
e.preventDefault();
|
|
442
508
|
e.stopPropagation();
|
|
443
509
|
this._dropdownOpen = !this._dropdownOpen;
|
|
444
|
-
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
_onPanelToggle(e) {
|
|
513
|
+
this._dropdownOpen = e.newState === "open";
|
|
445
514
|
}
|
|
446
515
|
|
|
447
516
|
_selectFromDropdown(e, id, href) {
|
|
517
|
+
if (NATIVE_POPOVER) {
|
|
518
|
+
const panel = this.renderRoot.querySelector(".bd-anchor-nav__dropdown-panel");
|
|
519
|
+
if (panel?.matches(":popover-open")) panel.hidePopover();
|
|
520
|
+
} else {
|
|
521
|
+
this._dropdownOpen = false;
|
|
522
|
+
}
|
|
448
523
|
this.handleClick(e, id, href);
|
|
449
|
-
this._dropdownOpen = false;
|
|
450
|
-
this.requestUpdate();
|
|
451
524
|
}
|
|
452
525
|
|
|
453
526
|
_activeLabel(resolved) {
|
|
@@ -470,9 +543,8 @@ class BdAnchorNav extends LitElement {
|
|
|
470
543
|
href="${href}"
|
|
471
544
|
variant="primary"
|
|
472
545
|
no-underline
|
|
473
|
-
class="anchor-link
|
|
474
|
-
|
|
475
|
-
aria-current=${isActive ? "location" : nothing}
|
|
546
|
+
class="anchor-link"
|
|
547
|
+
current=${isActive ? "location" : nothing}
|
|
476
548
|
@click=${(e) => this.handleClick(e, id, href)}
|
|
477
549
|
>${title}</bd-link>
|
|
478
550
|
`;
|
|
@@ -499,6 +571,7 @@ class BdAnchorNav extends LitElement {
|
|
|
499
571
|
class="bd-anchor-nav__dropdown-toggle"
|
|
500
572
|
aria-expanded=${this._dropdownOpen ? "true" : "false"}
|
|
501
573
|
aria-controls=${this._panelId}
|
|
574
|
+
popovertarget=${NATIVE_POPOVER ? this._panelId : nothing}
|
|
502
575
|
@click=${this._toggleDropdown}
|
|
503
576
|
>
|
|
504
577
|
<span class="bd-anchor-nav__dropdown-label">${dropdownLabel}</span>
|
|
@@ -509,7 +582,9 @@ class BdAnchorNav extends LitElement {
|
|
|
509
582
|
<div
|
|
510
583
|
class="bd-anchor-nav__dropdown-panel"
|
|
511
584
|
id=${this._panelId}
|
|
512
|
-
|
|
585
|
+
popover=${NATIVE_POPOVER ? "auto" : nothing}
|
|
586
|
+
?hidden=${!NATIVE_POPOVER && !this._dropdownOpen}
|
|
587
|
+
@toggle=${this._onPanelToggle}
|
|
513
588
|
>
|
|
514
589
|
<ul class="bd-anchor-nav__dropdown-list">
|
|
515
590
|
${resolved.map(({ id, title, href }) => {
|
|
@@ -518,7 +593,7 @@ class BdAnchorNav extends LitElement {
|
|
|
518
593
|
<li>
|
|
519
594
|
<a
|
|
520
595
|
href="${href}"
|
|
521
|
-
class="bd-anchor-nav__dropdown-option
|
|
596
|
+
class="bd-anchor-nav__dropdown-option"
|
|
522
597
|
aria-current=${isActive ? "location" : nothing}
|
|
523
598
|
@click=${(e) => this._selectFromDropdown(e, id, href)}
|
|
524
599
|
>${title}</a>
|
|
@@ -530,7 +605,7 @@ class BdAnchorNav extends LitElement {
|
|
|
530
605
|
</div>
|
|
531
606
|
|
|
532
607
|
<div class="bd-cta">
|
|
533
|
-
<slot name="cta"></slot>
|
|
608
|
+
<div class="bd-cta__inner"><slot name="cta"></slot></div>
|
|
534
609
|
</div>
|
|
535
610
|
</div>
|
|
536
611
|
</nav>
|