( scroller: HTMLElement, marker: HTMLElement, axis: Axis, align: 'start' | 'end', smooth = false )
| 1156 | } |
| 1157 | |
| 1158 | function scrollDetentIntoView( |
| 1159 | scroller: HTMLElement, |
| 1160 | marker: HTMLElement, |
| 1161 | axis: Axis, |
| 1162 | align: 'start' | 'end', |
| 1163 | smooth = false |
| 1164 | ) { |
| 1165 | let behavior: ScrollBehavior = smooth && !reduceMotion() ? 'smooth' : 'auto'; |
| 1166 | let markerRect = marker.getBoundingClientRect(); |
| 1167 | let scrollerRect = scroller.getBoundingClientRect(); |
| 1168 | let style = getComputedStyle(marker); |
| 1169 | if (axis === 'y') { |
| 1170 | if (align === 'start') { |
| 1171 | let margin = parseFloat(style.scrollMarginTop) || 0; |
| 1172 | // Rest the marker's start edge (less its scroll-margin) at the scrollport's start. |
| 1173 | let top = markerRect.top - scrollerRect.top + scroller.scrollTop - margin; |
| 1174 | scroller.scrollTo({top, behavior}); |
| 1175 | } else { |
| 1176 | let margin = parseFloat(style.scrollMarginBottom) || 0; |
| 1177 | // Rest the marker's end edge (plus its scroll-margin) at the scrollport's end. |
| 1178 | let top = |
| 1179 | markerRect.bottom - scrollerRect.top + scroller.scrollTop + margin - scroller.clientHeight; |
| 1180 | scroller.scrollTo({top, behavior}); |
| 1181 | } |
| 1182 | } else { |
| 1183 | if (align === 'start') { |
| 1184 | let margin = parseFloat(style.scrollMarginLeft) || 0; |
| 1185 | let left = markerRect.left - scrollerRect.left + scroller.scrollLeft - margin; |
| 1186 | scroller.scrollTo({left, behavior}); |
| 1187 | } else { |
| 1188 | let margin = parseFloat(style.scrollMarginRight) || 0; |
| 1189 | let left = |
| 1190 | markerRect.right - scrollerRect.left + scroller.scrollLeft + margin - scroller.clientWidth; |
| 1191 | scroller.scrollTo({left, behavior}); |
| 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | function calcToPx(calc: string) { |
| 1197 | if (!calc.startsWith('calc(')) { |
no test coverage detected