@@ -196,23 +196,26 @@ function switchDisplayedElement(elemToDisplay) {
196
196
removeClass ( el , "hidden" ) ;
197
197
198
198
const mainHeading = elemToDisplay . querySelector ( ".main-heading" ) ;
199
- // @ts -expect-error
200
- if ( mainHeading && searchState . rustdocToolbar ) {
201
- // @ts -expect-error
202
- if ( searchState . rustdocToolbar . parentElement ) {
203
- // @ts -expect-error
204
- searchState . rustdocToolbar . parentElement . removeChild ( searchState . rustdocToolbar ) ;
199
+ if ( mainHeading && window . searchState . rustdocToolbar ) {
200
+ if ( window . searchState . rustdocToolbar . parentElement ) {
201
+ window . searchState . rustdocToolbar . parentElement . removeChild (
202
+ window . searchState . rustdocToolbar ,
203
+ ) ;
205
204
}
206
- // @ts -expect-error
207
- mainHeading . appendChild ( searchState . rustdocToolbar ) ;
205
+ mainHeading . appendChild ( window . searchState . rustdocToolbar ) ;
208
206
}
209
207
}
210
208
211
209
function browserSupportsHistoryApi ( ) {
212
210
return window . history && typeof window . history . pushState === "function" ;
213
211
}
214
212
215
- // @ts -expect-error
213
+ /**
214
+ * Download CSS from the web without making it the active stylesheet.
215
+ * We use this in the settings popover so that you don't get FOUC when switching.
216
+ *
217
+ * @param {string } cssUrl
218
+ */
216
219
function preLoadCss ( cssUrl ) {
217
220
// https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload
218
221
const link = document . createElement ( "link" ) ;
@@ -225,7 +228,11 @@ function preLoadCss(cssUrl) {
225
228
( function ( ) {
226
229
const isHelpPage = window . location . pathname . endsWith ( "/help.html" ) ;
227
230
228
- // @ts -expect-error
231
+ /**
232
+ * Run a JavaScript file asynchronously.
233
+ * @param {string } url
234
+ * @param {function(): any } errorCallback
235
+ */
229
236
function loadScript ( url , errorCallback ) {
230
237
const script = document . createElement ( "script" ) ;
231
238
script . src = url ;
@@ -235,13 +242,12 @@ function preLoadCss(cssUrl) {
235
242
document . head . append ( script ) ;
236
243
}
237
244
238
- if ( getSettingsButton ( ) ) {
239
- // @ts -expect-error
240
- getSettingsButton ( ) . onclick = event => {
245
+ const settingsButton = getSettingsButton ( ) ;
246
+ if ( settingsButton ) {
247
+ settingsButton . onclick = event => {
241
248
if ( event . ctrlKey || event . altKey || event . metaKey ) {
242
249
return ;
243
250
}
244
- // @ts -expect-error
245
251
window . hideAllModals ( false ) ;
246
252
addClass ( getSettingsButton ( ) , "rotate" ) ;
247
253
event . preventDefault ( ) ;
@@ -470,7 +476,6 @@ function preLoadCss(cssUrl) {
470
476
}
471
477
return onEachLazy ( implElem . parentElement . parentElement . querySelectorAll (
472
478
`[id^="${ assocId } "]` ) ,
473
- // @ts -expect-error
474
479
item => {
475
480
const numbered = / ^ ( .+ ?) - ( [ 0 - 9 ] + ) $ / . exec ( item . id ) ;
476
481
if ( item . id === assocId || ( numbered && numbered [ 1 ] === assocId ) ) {
@@ -522,7 +527,6 @@ function preLoadCss(cssUrl) {
522
527
ev . preventDefault ( ) ;
523
528
// @ts -expect-error
524
529
searchState . defocus ( ) ;
525
- // @ts -expect-error
526
530
window . hideAllModals ( true ) ; // true = reset focus for tooltips
527
531
}
528
532
@@ -687,7 +691,6 @@ function preLoadCss(cssUrl) {
687
691
//
688
692
// By the way, this is only used by and useful for traits implemented automatically
689
693
// (like "Send" and "Sync").
690
- // @ts -expect-error
691
694
onEachLazy ( synthetic_implementors . getElementsByClassName ( "impl" ) , el => {
692
695
const aliases = el . getAttribute ( "data-aliases" ) ;
693
696
if ( ! aliases ) {
@@ -740,7 +743,6 @@ function preLoadCss(cssUrl) {
740
743
code . innerHTML = struct [ TEXT_IDX ] ;
741
744
addClass ( code , "code-header" ) ;
742
745
743
- // @ts -expect-error
744
746
onEachLazy ( code . getElementsByTagName ( "a" ) , elem => {
745
747
const href = elem . getAttribute ( "href" ) ;
746
748
@@ -886,15 +888,13 @@ function preLoadCss(cssUrl) {
886
888
const template = document . createElement ( "template" ) ;
887
889
template . innerHTML = text ;
888
890
889
- // @ts -expect-error
890
891
onEachLazy ( template . content . querySelectorAll ( "a" ) , elem => {
891
892
const href = elem . getAttribute ( "href" ) ;
892
893
893
894
if ( href && ! href . startsWith ( "#" ) && ! / ^ (?: [ a - z + ] + : ) ? \/ \/ / . test ( href ) ) {
894
895
elem . setAttribute ( "href" , window . rootPath + href ) ;
895
896
}
896
897
} ) ;
897
- // @ts -expect-error
898
898
onEachLazy ( template . content . querySelectorAll ( "[id]" ) , el => {
899
899
let i = 0 ;
900
900
if ( idMap . has ( el . id ) ) {
@@ -912,7 +912,6 @@ function preLoadCss(cssUrl) {
912
912
const oldHref = `#${ el . id } ` ;
913
913
const newHref = `#${ el . id } -${ i } ` ;
914
914
el . id = `${ el . id } -${ i } ` ;
915
- // @ts -expect-error
916
915
onEachLazy ( template . content . querySelectorAll ( "a[href]" ) , link => {
917
916
if ( link . getAttribute ( "href" ) === oldHref ) {
918
917
link . href = newHref ;
@@ -933,7 +932,6 @@ function preLoadCss(cssUrl) {
933
932
// @ts -expect-error
934
933
sidebarTraitList . append ( li ) ;
935
934
} else {
936
- // @ts -expect-error
937
935
onEachLazy ( templateAssocItems , item => {
938
936
let block = hasClass ( item , "associatedtype" ) ? associatedTypes : (
939
937
hasClass ( item , "associatedconstant" ) ? associatedConstants : (
@@ -1040,7 +1038,6 @@ function preLoadCss(cssUrl) {
1040
1038
function expandAllDocs ( ) {
1041
1039
const innerToggle = document . getElementById ( toggleAllDocsId ) ;
1042
1040
removeClass ( innerToggle , "will-expand" ) ;
1043
- // @ts -expect-error
1044
1041
onEachLazy ( document . getElementsByClassName ( "toggle" ) , e => {
1045
1042
if ( ! hasClass ( e , "type-contents-toggle" ) && ! hasClass ( e , "more-examples-toggle" ) ) {
1046
1043
e . open = true ;
@@ -1053,7 +1050,6 @@ function preLoadCss(cssUrl) {
1053
1050
function collapseAllDocs ( ) {
1054
1051
const innerToggle = document . getElementById ( toggleAllDocsId ) ;
1055
1052
addClass ( innerToggle , "will-expand" ) ;
1056
- // @ts -expect-error
1057
1053
onEachLazy ( document . getElementsByClassName ( "toggle" ) , e => {
1058
1054
if ( e . parentNode . id !== "implementations-list" ||
1059
1055
( ! hasClass ( e , "implementors-toggle" ) &&
@@ -1092,7 +1088,6 @@ function preLoadCss(cssUrl) {
1092
1088
function setImplementorsTogglesOpen ( id , open ) {
1093
1089
const list = document . getElementById ( id ) ;
1094
1090
if ( list !== null ) {
1095
- // @ts -expect-error
1096
1091
onEachLazy ( list . getElementsByClassName ( "implementors-toggle" ) , e => {
1097
1092
e . open = open ;
1098
1093
} ) ;
@@ -1104,7 +1099,6 @@ function preLoadCss(cssUrl) {
1104
1099
setImplementorsTogglesOpen ( "blanket-implementations-list" , false ) ;
1105
1100
}
1106
1101
1107
- // @ts -expect-error
1108
1102
onEachLazy ( document . getElementsByClassName ( "toggle" ) , e => {
1109
1103
if ( ! hideLargeItemContents && hasClass ( e , "type-contents-toggle" ) ) {
1110
1104
e . open = true ;
@@ -1124,7 +1118,6 @@ function preLoadCss(cssUrl) {
1124
1118
}
1125
1119
onEachLazy ( document . querySelectorAll (
1126
1120
":not(.scraped-example) > .example-wrap > pre:not(.example-line-numbers)" ,
1127
- // @ts -expect-error
1128
1121
) , x => {
1129
1122
const parent = x . parentNode ;
1130
1123
const line_numbers = parent . querySelectorAll ( ".example-line-numbers" ) ;
@@ -1145,7 +1138,6 @@ function preLoadCss(cssUrl) {
1145
1138
1146
1139
// @ts -expect-error
1147
1140
window . rustdoc_remove_line_numbers_from_examples = ( ) => {
1148
- // @ts -expect-error
1149
1141
onEachLazy ( document . querySelectorAll ( ".example-wrap > .example-line-numbers" ) , x => {
1150
1142
x . parentNode . removeChild ( x ) ;
1151
1143
} ) ;
@@ -1157,16 +1149,13 @@ function preLoadCss(cssUrl) {
1157
1149
}
1158
1150
1159
1151
function showSidebar ( ) {
1160
- // @ts -expect-error
1161
1152
window . hideAllModals ( false ) ;
1162
1153
const sidebar = document . getElementsByClassName ( "sidebar" ) [ 0 ] ;
1163
- // @ts -expect-error
1164
1154
addClass ( sidebar , "shown" ) ;
1165
1155
}
1166
1156
1167
1157
function hideSidebar ( ) {
1168
1158
const sidebar = document . getElementsByClassName ( "sidebar" ) [ 0 ] ;
1169
- // @ts -expect-error
1170
1159
removeClass ( sidebar , "shown" ) ;
1171
1160
}
1172
1161
@@ -1193,7 +1182,6 @@ function preLoadCss(cssUrl) {
1193
1182
mainElem . addEventListener ( "click" , hideSidebar ) ;
1194
1183
}
1195
1184
1196
- // @ts -expect-error
1197
1185
onEachLazy ( document . querySelectorAll ( "a[href^='#']" ) , el => {
1198
1186
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
1199
1187
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
@@ -1204,7 +1192,6 @@ function preLoadCss(cssUrl) {
1204
1192
} ) ;
1205
1193
} ) ;
1206
1194
1207
- // @ts -expect-error
1208
1195
onEachLazy ( document . querySelectorAll ( ".toggle > summary:not(.hideme)" ) , el => {
1209
1196
// @ts -expect-error
1210
1197
el . addEventListener ( "click" , e => {
@@ -1241,7 +1228,6 @@ function preLoadCss(cssUrl) {
1241
1228
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1242
1229
return ;
1243
1230
}
1244
- // @ts -expect-error
1245
1231
window . hideAllModals ( false ) ;
1246
1232
const wrapper = document . createElement ( "div" ) ;
1247
1233
if ( notable_ty ) {
@@ -1422,7 +1408,6 @@ function preLoadCss(cssUrl) {
1422
1408
}
1423
1409
}
1424
1410
1425
- // @ts -expect-error
1426
1411
onEachLazy ( document . getElementsByClassName ( "tooltip" ) , e => {
1427
1412
e . onclick = ( ) => {
1428
1413
e . TOOLTIP_FORCE_VISIBLE = e . TOOLTIP_FORCE_VISIBLE ? false : true ;
@@ -1527,7 +1512,6 @@ function preLoadCss(cssUrl) {
1527
1512
// @ts -expect-error
1528
1513
! getSettingsButton ( ) . contains ( event . relatedTarget )
1529
1514
) {
1530
- // @ts -expect-error
1531
1515
window . hidePopoverMenus ( ) ;
1532
1516
}
1533
1517
}
@@ -1626,20 +1610,16 @@ function preLoadCss(cssUrl) {
1626
1610
*
1627
1611
* Pass "true" to reset focus for tooltip popovers.
1628
1612
*/
1629
- // @ts -expect-error
1630
1613
window . hideAllModals = switchFocus => {
1631
1614
hideSidebar ( ) ;
1632
- // @ts -expect-error
1633
1615
window . hidePopoverMenus ( ) ;
1634
1616
hideTooltip ( switchFocus ) ;
1635
1617
} ;
1636
1618
1637
1619
/**
1638
1620
* Hide all the popover menus.
1639
1621
*/
1640
- // @ts -expect-error
1641
1622
window . hidePopoverMenus = ( ) => {
1642
- // @ts -expect-error
1643
1623
onEachLazy ( document . querySelectorAll ( "rustdoc-toolbar .popover" ) , elem => {
1644
1624
elem . style . display = "none" ;
1645
1625
} ) ;
@@ -1708,7 +1688,6 @@ function preLoadCss(cssUrl) {
1708
1688
if ( shouldShowHelp ) {
1709
1689
showHelp ( ) ;
1710
1690
} else {
1711
- // @ts -expect-error
1712
1691
window . hidePopoverMenus ( ) ;
1713
1692
}
1714
1693
} ) ;
@@ -1780,30 +1759,42 @@ function preLoadCss(cssUrl) {
1780
1759
} ) ;
1781
1760
}
1782
1761
1783
- // Pointer capture.
1784
- //
1785
- // Resizing is a single-pointer gesture. Any secondary pointer is ignored
1786
- // @ts -expect-error
1762
+ /**
1763
+ * Pointer capture.
1764
+ *
1765
+ * Resizing is a single-pointer gesture. Any secondary pointer is ignored
1766
+ *
1767
+ * @type {null|number }
1768
+ */
1787
1769
let currentPointerId = null ;
1788
1770
1789
- // "Desired" sidebar size.
1790
- //
1791
- // This is stashed here for window resizing. If the sidebar gets
1792
- // shrunk to maintain BODY_MIN, and then the user grows the window again,
1793
- // it gets the sidebar to restore its size.
1794
- // @ts -expect-error
1771
+ /**
1772
+ * "Desired" sidebar size.
1773
+ *
1774
+ * This is stashed here for window resizing. If the sidebar gets
1775
+ * shrunk to maintain BODY_MIN, and then the user grows the window again,
1776
+ * it gets the sidebar to restore its size.
1777
+ *
1778
+ * @type {null|number }
1779
+ */
1795
1780
let desiredSidebarSize = null ;
1796
1781
1797
- // Sidebar resize debouncer.
1798
- //
1799
- // The sidebar itself is resized instantly, but the body HTML can be too
1800
- // big for that, causing reflow jank. To reduce this, we queue up a separate
1801
- // animation frame and throttle it.
1782
+ /**
1783
+ * Sidebar resize debouncer.
1784
+ *
1785
+ * The sidebar itself is resized instantly, but the body HTML can be too
1786
+ * big for that, causing reflow jank. To reduce this, we queue up a separate
1787
+ * animation frame and throttle it.
1788
+ *
1789
+ * @type {false|ReturnType<typeof setTimeout> }
1790
+ */
1802
1791
let pendingSidebarResizingFrame = false ;
1803
1792
1804
- // If this page has no sidebar at all, bail out.
1793
+ /** @type { HTMLElement|null } */
1805
1794
const resizer = document . querySelector ( ".sidebar-resizer" ) ;
1795
+ /** @type {HTMLElement|null } */
1806
1796
const sidebar = document . querySelector ( ".sidebar" ) ;
1797
+ // If this page has no sidebar at all, bail out.
1807
1798
if ( ! resizer || ! sidebar ) {
1808
1799
return ;
1809
1800
}
@@ -1820,11 +1811,9 @@ function preLoadCss(cssUrl) {
1820
1811
// from settings.js, which uses a separate function. It's done here because
1821
1812
// the minimum sidebar size is rather uncomfortable, and it must pass
1822
1813
// through that size when using the shrink-to-nothing gesture.
1823
- function hideSidebar ( ) {
1814
+ const hideSidebar = function ( ) {
1824
1815
if ( isSrcPage ) {
1825
- // @ts -expect-error
1826
1816
window . rustdocCloseSourceSidebar ( ) ;
1827
- // @ts -expect-error
1828
1817
updateLocalStorage ( "src-sidebar-width" , null ) ;
1829
1818
// [RUSTDOCIMPL] CSS variable fast path
1830
1819
//
@@ -1837,83 +1826,73 @@ function preLoadCss(cssUrl) {
1837
1826
//
1838
1827
// So, to clear it, we need to clear all three.
1839
1828
document . documentElement . style . removeProperty ( "--src-sidebar-width" ) ;
1840
- // @ts -expect-error
1841
1829
sidebar . style . removeProperty ( "--src-sidebar-width" ) ;
1842
- // @ts -expect-error
1843
1830
resizer . style . removeProperty ( "--src-sidebar-width" ) ;
1844
1831
} else {
1845
1832
addClass ( document . documentElement , "hide-sidebar" ) ;
1846
1833
updateLocalStorage ( "hide-sidebar" , "true" ) ;
1847
- // @ts -expect-error
1848
1834
updateLocalStorage ( "desktop-sidebar-width" , null ) ;
1849
1835
document . documentElement . style . removeProperty ( "--desktop-sidebar-width" ) ;
1850
- // @ts -expect-error
1851
1836
sidebar . style . removeProperty ( "--desktop-sidebar-width" ) ;
1852
- // @ts -expect-error
1853
1837
resizer . style . removeProperty ( "--desktop-sidebar-width" ) ;
1854
1838
}
1855
- }
1839
+ } ;
1856
1840
1857
1841
// Call this function to show the sidebar from the resize handle.
1858
1842
// On docs pages, this can only happen if the user has grabbed the resize
1859
1843
// handle, shrunk the sidebar down to nothing, and then pulls back into
1860
1844
// the visible range without releasing it. You can, however, grab the
1861
1845
// resize handle on a source page with the sidebar closed, because it
1862
1846
// remains visible all the time on there.
1863
- function showSidebar ( ) {
1847
+ const showSidebar = function ( ) {
1864
1848
if ( isSrcPage ) {
1865
- // @ts -expect-error
1866
1849
window . rustdocShowSourceSidebar ( ) ;
1867
1850
} else {
1868
1851
removeClass ( document . documentElement , "hide-sidebar" ) ;
1869
1852
updateLocalStorage ( "hide-sidebar" , "false" ) ;
1870
1853
}
1871
- }
1854
+ } ;
1872
1855
1873
1856
/**
1874
1857
* Call this to set the correct CSS variable and setting.
1875
1858
* This function doesn't enforce size constraints. Do that before calling it!
1876
1859
*
1877
1860
* @param {number } size - CSS px width of the sidebar.
1878
1861
*/
1879
- function changeSidebarSize ( size ) {
1862
+ const changeSidebarSize = function ( size ) {
1880
1863
if ( isSrcPage ) {
1881
- // @ts -expect-error
1882
- updateLocalStorage ( "src-sidebar-width" , size ) ;
1864
+ updateLocalStorage ( "src-sidebar-width" , size . toString ( ) ) ;
1883
1865
// [RUSTDOCIMPL] CSS variable fast path
1884
1866
//
1885
1867
// While this property is set on the HTML element at load time,
1886
1868
// because the sidebar isn't actually loaded yet,
1887
1869
// we scope this update to the sidebar to avoid hitting a slow
1888
1870
// path in WebKit.
1889
- // @ts -expect-error
1890
1871
sidebar . style . setProperty ( "--src-sidebar-width" , size + "px" ) ;
1891
- // @ts -expect-error
1892
1872
resizer . style . setProperty ( "--src-sidebar-width" , size + "px" ) ;
1893
1873
} else {
1894
- // @ts -expect-error
1895
- updateLocalStorage ( "desktop-sidebar-width" , size ) ;
1896
- // @ts -expect-error
1874
+ updateLocalStorage ( "desktop-sidebar-width" , size . toString ( ) ) ;
1897
1875
sidebar . style . setProperty ( "--desktop-sidebar-width" , size + "px" ) ;
1898
- // @ts -expect-error
1899
1876
resizer . style . setProperty ( "--desktop-sidebar-width" , size + "px" ) ;
1900
1877
}
1901
- }
1878
+ } ;
1902
1879
1903
1880
// Check if the sidebar is hidden. Since src pages and doc pages have
1904
1881
// different settings, this function has to check that.
1905
- function isSidebarHidden ( ) {
1882
+ const isSidebarHidden = function ( ) {
1906
1883
return isSrcPage ?
1907
1884
! hasClass ( document . documentElement , "src-sidebar-expanded" ) :
1908
1885
hasClass ( document . documentElement , "hide-sidebar" ) ;
1909
- }
1886
+ } ;
1910
1887
1911
- // Respond to the resize handle event.
1912
- // This function enforces size constraints, and implements the
1913
- // shrink-to-nothing gesture based on thresholds defined above.
1914
- // @ts -expect-error
1915
- function resize ( e ) {
1916
- // @ts -expect-error
1888
+ /**
1889
+ * Respond to the resize handle event.
1890
+ * This function enforces size constraints, and implements the
1891
+ * shrink-to-nothing gesture based on thresholds defined above.
1892
+ *
1893
+ * @param {PointerEvent } e
1894
+ */
1895
+ const resize = function ( e ) {
1917
1896
if ( currentPointerId === null || currentPointerId !== e . pointerId ) {
1918
1897
return ;
1919
1898
}
@@ -1931,106 +1910,97 @@ function preLoadCss(cssUrl) {
1931
1910
changeSidebarSize ( constrainedPos ) ;
1932
1911
desiredSidebarSize = constrainedPos ;
1933
1912
if ( pendingSidebarResizingFrame !== false ) {
1934
- // @ts -expect-error
1935
1913
clearTimeout ( pendingSidebarResizingFrame ) ;
1936
1914
}
1937
- // @ts -expect-error
1938
1915
pendingSidebarResizingFrame = setTimeout ( ( ) => {
1939
- // @ts -expect-error
1940
1916
if ( currentPointerId === null || pendingSidebarResizingFrame === false ) {
1941
1917
return ;
1942
1918
}
1943
1919
pendingSidebarResizingFrame = false ;
1944
1920
document . documentElement . style . setProperty (
1945
1921
"--resizing-sidebar-width" ,
1946
- // @ts -expect-error
1947
1922
desiredSidebarSize + "px" ,
1948
1923
) ;
1949
1924
} , 100 ) ;
1950
1925
}
1951
- }
1926
+ } ;
1952
1927
// Respond to the window resize event.
1953
1928
window . addEventListener ( "resize" , ( ) => {
1954
1929
if ( window . innerWidth < RUSTDOC_MOBILE_BREAKPOINT ) {
1955
1930
return ;
1956
1931
}
1957
1932
stopResize ( ) ;
1958
- // @ts -expect-error
1959
- if ( desiredSidebarSize >= ( window . innerWidth - BODY_MIN ) ) {
1933
+ if ( desiredSidebarSize !== null && desiredSidebarSize >= ( window . innerWidth - BODY_MIN ) ) {
1960
1934
changeSidebarSize ( window . innerWidth - BODY_MIN ) ;
1961
- // @ts -expect-error
1962
1935
} else if ( desiredSidebarSize !== null && desiredSidebarSize > SIDEBAR_MIN ) {
1963
- // @ts -expect-error
1964
1936
changeSidebarSize ( desiredSidebarSize ) ;
1965
1937
}
1966
1938
} ) ;
1967
- // @ts -expect-error
1968
- function stopResize ( e ) {
1969
- // @ts -expect-error
1939
+
1940
+ /**
1941
+ * @param {PointerEvent= } e
1942
+ */
1943
+ const stopResize = function ( e ) {
1970
1944
if ( currentPointerId === null ) {
1971
1945
return ;
1972
1946
}
1973
1947
if ( e ) {
1974
1948
e . preventDefault ( ) ;
1975
1949
}
1976
- // @ts -expect-error
1977
1950
desiredSidebarSize = sidebar . getBoundingClientRect ( ) . width ;
1978
- // @ts -expect-error
1979
1951
removeClass ( resizer , "active" ) ;
1980
1952
window . removeEventListener ( "pointermove" , resize , false ) ;
1981
1953
window . removeEventListener ( "pointerup" , stopResize , false ) ;
1982
1954
removeClass ( document . documentElement , "sidebar-resizing" ) ;
1983
1955
document . documentElement . style . removeProperty ( "--resizing-sidebar-width" ) ;
1984
- // @ts -expect-error
1985
1956
if ( resizer . releasePointerCapture ) {
1986
- // @ts -expect-error
1987
1957
resizer . releasePointerCapture ( currentPointerId ) ;
1988
1958
currentPointerId = null ;
1989
1959
}
1990
- }
1991
- // @ts -expect-error
1992
- function initResize ( e ) {
1993
- // @ts -expect-error
1960
+ } ;
1961
+
1962
+ /**
1963
+ * @param {PointerEvent } e
1964
+ */
1965
+ const initResize = function ( e ) {
1994
1966
if ( currentPointerId !== null || e . altKey || e . ctrlKey || e . metaKey || e . button !== 0 ) {
1995
1967
return ;
1996
1968
}
1997
- // @ts -expect-error
1998
1969
if ( resizer . setPointerCapture ) {
1999
- // @ts -expect-error
2000
1970
resizer . setPointerCapture ( e . pointerId ) ;
2001
- // @ts -expect-error
2002
1971
if ( ! resizer . hasPointerCapture ( e . pointerId ) ) {
2003
1972
// unable to capture pointer; something else has it
2004
1973
// on iOS, this usually means you long-clicked a link instead
2005
- // @ts -expect-error
2006
1974
resizer . releasePointerCapture ( e . pointerId ) ;
2007
1975
return ;
2008
1976
}
2009
1977
currentPointerId = e . pointerId ;
2010
1978
}
2011
- // @ts -expect-error
2012
1979
window . hideAllModals ( false ) ;
2013
1980
e . preventDefault ( ) ;
2014
1981
window . addEventListener ( "pointermove" , resize , false ) ;
2015
1982
window . addEventListener ( "pointercancel" , stopResize , false ) ;
2016
1983
window . addEventListener ( "pointerup" , stopResize , false ) ;
2017
- // @ts -expect-error
2018
1984
addClass ( resizer , "active" ) ;
2019
1985
addClass ( document . documentElement , "sidebar-resizing" ) ;
2020
- // @ts -expect-error
2021
1986
const pos = e . clientX - sidebar . offsetLeft - 3 ;
2022
1987
document . documentElement . style . setProperty ( "--resizing-sidebar-width" , pos + "px" ) ;
2023
1988
desiredSidebarSize = null ;
2024
- }
1989
+ } ;
2025
1990
resizer . addEventListener ( "pointerdown" , initResize , false ) ;
2026
1991
} ( ) ) ;
2027
1992
2028
1993
// This section handles the copy button that appears next to the path breadcrumbs
2029
1994
// and the copy buttons on the code examples.
2030
1995
( function ( ) {
2031
1996
// Common functions to copy buttons.
2032
- // @ts -expect-error
1997
+ /**
1998
+ * @param {string|null } content
1999
+ */
2033
2000
function copyContentToClipboard ( content ) {
2001
+ if ( content === null ) {
2002
+ return ;
2003
+ }
2034
2004
const el = document . createElement ( "textarea" ) ;
2035
2005
el . value = content ;
2036
2006
el . setAttribute ( "readonly" , "" ) ;
@@ -2044,15 +2014,17 @@ function preLoadCss(cssUrl) {
2044
2014
document . body . removeChild ( el ) ;
2045
2015
}
2046
2016
2047
- // @ts -expect-error
2017
+ /**
2018
+ * @param {HTMLElement & {reset_button_timeout?: ReturnType<typeof setTimeout>} } button
2019
+ */
2048
2020
function copyButtonAnimation ( button ) {
2049
2021
button . classList . add ( "clicked" ) ;
2050
2022
2051
2023
if ( button . reset_button_timeout !== undefined ) {
2052
- window . clearTimeout ( button . reset_button_timeout ) ;
2024
+ clearTimeout ( button . reset_button_timeout ) ;
2053
2025
}
2054
2026
2055
- button . reset_button_timeout = window . setTimeout ( ( ) => {
2027
+ button . reset_button_timeout = setTimeout ( ( ) => {
2056
2028
button . reset_button_timeout = undefined ;
2057
2029
button . classList . remove ( "clicked" ) ;
2058
2030
} , 1000 ) ;
@@ -2067,9 +2039,7 @@ function preLoadCss(cssUrl) {
2067
2039
// Most page titles are '<Item> in <path::to::module> - Rust', except
2068
2040
// modules (which don't have the first part) and keywords/primitives
2069
2041
// (which don't have a module path)
2070
- // @ts -expect-error
2071
- const title = document . querySelector ( "title" ) . textContent . replace ( " - Rust" , "" ) ;
2072
- const [ item , module ] = title . split ( " in " ) ;
2042
+ const [ item , module ] = document . title . split ( " in " ) ;
2073
2043
const path = [ item ] ;
2074
2044
if ( module !== undefined ) {
2075
2045
path . unshift ( module ) ;
@@ -2079,8 +2049,10 @@ function preLoadCss(cssUrl) {
2079
2049
copyButtonAnimation ( but ) ;
2080
2050
} ;
2081
2051
2082
- // Copy buttons on code examples.
2083
- // @ts -expect-error
2052
+ /**
2053
+ * Copy buttons on code examples.
2054
+ * @param {HTMLElement|null } codeElem
2055
+ */
2084
2056
function copyCode ( codeElem ) {
2085
2057
if ( ! codeElem ) {
2086
2058
// Should never happen, but the world is a dark and dangerous place.
@@ -2089,23 +2061,34 @@ function preLoadCss(cssUrl) {
2089
2061
copyContentToClipboard ( codeElem . textContent ) ;
2090
2062
}
2091
2063
2092
- // @ts -expect-error
2064
+ /**
2065
+ * @param {UIEvent } event
2066
+ * @returns {HTMLElement|null }
2067
+ */
2093
2068
function getExampleWrap ( event ) {
2094
- let elem = event . target ;
2095
- while ( ! hasClass ( elem , "example-wrap" ) ) {
2096
- if ( elem === document . body ||
2097
- elem . tagName === "A" ||
2098
- elem . tagName === "BUTTON" ||
2099
- hasClass ( elem , "docblock" )
2100
- ) {
2101
- return null ;
2069
+ const target = event . target ;
2070
+ if ( target instanceof HTMLElement ) {
2071
+ /** @type {HTMLElement|null } */
2072
+ let elem = target ;
2073
+ while ( elem !== null && ! hasClass ( elem , "example-wrap" ) ) {
2074
+ if ( elem === document . body ||
2075
+ elem . tagName === "A" ||
2076
+ elem . tagName === "BUTTON" ||
2077
+ hasClass ( elem , "docblock" )
2078
+ ) {
2079
+ return null ;
2080
+ }
2081
+ elem = elem . parentElement ;
2102
2082
}
2103
- elem = elem . parentElement ;
2083
+ return elem ;
2084
+ } else {
2085
+ return null ;
2104
2086
}
2105
- return elem ;
2106
2087
}
2107
2088
2108
- // @ts -expect-error
2089
+ /**
2090
+ * @param {UIEvent } event
2091
+ */
2109
2092
function addCopyButton ( event ) {
2110
2093
const elem = getExampleWrap ( event ) ;
2111
2094
if ( elem === null ) {
@@ -2132,15 +2115,17 @@ function preLoadCss(cssUrl) {
2132
2115
} ) ;
2133
2116
parent . appendChild ( copyButton ) ;
2134
2117
2135
- if ( ! elem . parentElement . classList . contains ( "scraped-example" ) ) {
2118
+ if ( ! elem . parentElement || ! elem . parentElement . classList . contains ( "scraped-example" ) ||
2119
+ ! window . updateScrapedExample ) {
2136
2120
return ;
2137
2121
}
2138
2122
const scrapedWrapped = elem . parentElement ;
2139
- // @ts -expect-error
2140
2123
window . updateScrapedExample ( scrapedWrapped , parent ) ;
2141
2124
}
2142
2125
2143
- // @ts -expect-error
2126
+ /**
2127
+ * @param {UIEvent } event
2128
+ */
2144
2129
function showHideCodeExampleButtons ( event ) {
2145
2130
const elem = getExampleWrap ( event ) ;
2146
2131
if ( elem === null ) {
@@ -2159,7 +2144,6 @@ function preLoadCss(cssUrl) {
2159
2144
buttons . classList . toggle ( "keep-visible" ) ;
2160
2145
}
2161
2146
2162
- // @ts -expect-error
2163
2147
onEachLazy ( document . querySelectorAll ( ".docblock .example-wrap" ) , elem => {
2164
2148
elem . addEventListener ( "mouseover" , addCopyButton ) ;
2165
2149
elem . addEventListener ( "click" , showHideCodeExampleButtons ) ;
0 commit comments