( scroller: HTMLElement, marker: HTMLElement, axis: Axis, align: 'start' | 'end', smooth = false )
| 1114 | } |
| 1115 | |
| 1116 | function scrollDetentIntoView( |
| 1117 | scroller: HTMLElement, |
| 1118 | marker: HTMLElement, |
| 1119 | axis: Axis, |
| 1120 | align: 'start' | 'end', |
| 1121 | smooth = false |
| 1122 | ) { |
| 1123 | let behavior: ScrollBehavior = smooth && !reduceMotion() ? 'smooth' : 'auto'; |
| 1124 | let markerRect = marker.getBoundingClientRect(); |
| 1125 | let scrollerRect = scroller.getBoundingClientRect(); |
| 1126 | let style = getComputedStyle(marker); |
| 1127 | if (axis === 'y') { |
| 1128 | if (align === 'start') { |
| 1129 | let margin = parseFloat(style.scrollMarginTop) || 0; |
| 1130 | // Rest the marker's start edge (less its scroll-margin) at the scrollport's start. |
| 1131 | let top = markerRect.top - scrollerRect.top + scroller.scrollTop - margin; |
| 1132 | scroller.scrollTo({top, behavior}); |
| 1133 | } else { |
| 1134 | let margin = parseFloat(style.scrollMarginBottom) || 0; |
| 1135 | // Rest the marker's end edge (plus its scroll-margin) at the scrollport's end. |
| 1136 | let top = |
| 1137 | markerRect.bottom - scrollerRect.top + scroller.scrollTop + margin - scroller.clientHeight; |
| 1138 | scroller.scrollTo({top, behavior}); |
| 1139 | } |
| 1140 | } else { |
| 1141 | if (align === 'start') { |
| 1142 | let margin = parseFloat(style.scrollMarginLeft) || 0; |
| 1143 | let left = markerRect.left - scrollerRect.left + scroller.scrollLeft - margin; |
| 1144 | scroller.scrollTo({left, behavior}); |
| 1145 | } else { |
| 1146 | let margin = parseFloat(style.scrollMarginRight) || 0; |
| 1147 | let left = |
| 1148 | markerRect.right - scrollerRect.left + scroller.scrollLeft + margin - scroller.clientWidth; |
| 1149 | scroller.scrollTo({left, behavior}); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | function calcToPx(calc: string) { |
| 1155 | if (!calc.startsWith('calc(')) { |
no test coverage detected