starlight-cannoli-plugins 2.10.2 → 2.10.3
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.
|
@@ -146,7 +146,11 @@ function tabbedH2Content() {
|
|
|
146
146
|
contentContainer.appendChild(tabbedWrapper);
|
|
147
147
|
contentContainer.appendChild(paginationBar);
|
|
148
148
|
let activeTabIndex = 0;
|
|
149
|
-
function
|
|
149
|
+
function isTabNavVisible() {
|
|
150
|
+
const rect = tabNav.getBoundingClientRect();
|
|
151
|
+
return rect.top < window.innerHeight && rect.bottom > 0;
|
|
152
|
+
}
|
|
153
|
+
function activateTab(targetIndex, updateHash = true, scrollToNav = false) {
|
|
150
154
|
activeTabIndex = targetIndex;
|
|
151
155
|
tabButtons.forEach((tabButton, buttonIndex) => {
|
|
152
156
|
tabButton.dataset.active = String(buttonIndex === targetIndex);
|
|
@@ -156,6 +160,15 @@ function tabbedH2Content() {
|
|
|
156
160
|
});
|
|
157
161
|
prevTabButton.disabled = targetIndex === 0;
|
|
158
162
|
nextTabButton.disabled = targetIndex === allSections.length - 1;
|
|
163
|
+
const scrollBehavior = getComputedStyle(document.documentElement).scrollBehavior;
|
|
164
|
+
tabButtons[targetIndex].scrollIntoView({
|
|
165
|
+
behavior: scrollBehavior,
|
|
166
|
+
block: "nearest",
|
|
167
|
+
inline: "nearest"
|
|
168
|
+
});
|
|
169
|
+
if (scrollToNav) {
|
|
170
|
+
tabNav.scrollIntoView({ behavior: scrollBehavior, block: "nearest" });
|
|
171
|
+
}
|
|
159
172
|
if (updateHash) {
|
|
160
173
|
const targetHeadingId = allSections[targetIndex].headingId;
|
|
161
174
|
if (targetHeadingId) {
|
|
@@ -169,12 +182,19 @@ function tabbedH2Content() {
|
|
|
169
182
|
}
|
|
170
183
|
}
|
|
171
184
|
}
|
|
185
|
+
function findPanelIndexForHash(urlHash) {
|
|
186
|
+
const targetHeadingId = urlHash.startsWith("#") ? urlHash.slice(1) : urlHash;
|
|
187
|
+
return tabPanels.findIndex(
|
|
188
|
+
(tabPanel) => tabPanel.querySelector(`#${CSS.escape(targetHeadingId)}`)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
172
191
|
function setEnabled(enabled) {
|
|
173
192
|
tabbedWrapper.dataset.enabled = String(enabled);
|
|
174
193
|
tabNav.hidden = !enabled;
|
|
175
194
|
paginationBar.hidden = !enabled;
|
|
176
195
|
if (enabled) {
|
|
177
|
-
|
|
196
|
+
const hashPanelIndex = window.location.hash ? findPanelIndexForHash(window.location.hash) : -1;
|
|
197
|
+
activateTab(hashPanelIndex >= 0 ? hashPanelIndex : activeTabIndex, false);
|
|
178
198
|
} else {
|
|
179
199
|
tabPanels.forEach((tabPanel) => {
|
|
180
200
|
tabPanel.hidden = false;
|
|
@@ -183,19 +203,22 @@ function tabbedH2Content() {
|
|
|
183
203
|
}
|
|
184
204
|
function navigateToHash(urlHash) {
|
|
185
205
|
if (!urlHash || tabbedWrapper.dataset.enabled !== "true") return;
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
activateTab(panelIndex, false);
|
|
190
|
-
});
|
|
206
|
+
const targetPanelIndex = findPanelIndexForHash(urlHash);
|
|
207
|
+
if (targetPanelIndex >= 0 && targetPanelIndex !== activeTabIndex)
|
|
208
|
+
activateTab(targetPanelIndex, false);
|
|
191
209
|
}
|
|
192
210
|
function wireInteractions(viewToggleCheckbox2) {
|
|
193
211
|
prevTabButton.addEventListener("click", () => {
|
|
194
|
-
if (activeTabIndex > 0)
|
|
212
|
+
if (activeTabIndex > 0) {
|
|
213
|
+
const scrollToNav = !isTabNavVisible();
|
|
214
|
+
activateTab(activeTabIndex - 1, true, scrollToNav);
|
|
215
|
+
}
|
|
195
216
|
});
|
|
196
217
|
nextTabButton.addEventListener("click", () => {
|
|
197
|
-
if (activeTabIndex < allSections.length - 1)
|
|
198
|
-
|
|
218
|
+
if (activeTabIndex < allSections.length - 1) {
|
|
219
|
+
const scrollToNav = !isTabNavVisible();
|
|
220
|
+
activateTab(activeTabIndex + 1, true, scrollToNav);
|
|
221
|
+
}
|
|
199
222
|
});
|
|
200
223
|
tabButtons.forEach((tabButton, buttonIndex) => {
|
|
201
224
|
tabButton.addEventListener("click", () => {
|
package/package.json
CHANGED