(
nextStart: number,
nextEnd: number,
options?: { readonly emit?: boolean; readonly anchor?: { readonly center: number; readonly ratio: number } },
)
| 137 | }; |
| 138 | |
| 139 | const applyNextRange = ( |
| 140 | nextStart: number, |
| 141 | nextEnd: number, |
| 142 | options?: { readonly emit?: boolean; readonly anchor?: { readonly center: number; readonly ratio: number } }, |
| 143 | ): void => { |
| 144 | if (!Number.isFinite(nextStart) || !Number.isFinite(nextEnd)) return; |
| 145 | |
| 146 | let s = nextStart; |
| 147 | let e = nextEnd; |
| 148 | |
| 149 | if (s > e) { |
| 150 | const t = s; |
| 151 | s = e; |
| 152 | e = t; |
| 153 | } |
| 154 | |
| 155 | // Enforce span constraints by resizing around the proposed midpoint. |
| 156 | let span = e - s; |
| 157 | if (!Number.isFinite(span) || span < 0) return; |
| 158 | |
| 159 | const targetSpan = clamp(span, normalizedMinSpan, normalizedMaxSpan); |
| 160 | if (targetSpan !== span) { |
| 161 | const anchorCenter = |
| 162 | options?.anchor && Number.isFinite(options.anchor.center) |
| 163 | ? clamp(options.anchor.center, 0, 100) |
| 164 | : (s + e) * 0.5; |
| 165 | const anchorRatio = |
| 166 | options?.anchor && Number.isFinite(options.anchor.ratio) |
| 167 | ? clamp01(options.anchor.ratio) |
| 168 | : 0.5; |
| 169 | |
| 170 | // Resize around the anchor so zoom operations preserve the cursor location. |
| 171 | s = anchorCenter - anchorRatio * targetSpan; |
| 172 | e = s + targetSpan; |
| 173 | span = targetSpan; |
| 174 | } |
| 175 | |
| 176 | // If span exceeds bounds (shouldn't happen with normalizedMaxSpan <= 100), clamp to full extent. |
| 177 | if (span > 100) { |
| 178 | s = 0; |
| 179 | e = 100; |
| 180 | span = 100; |
| 181 | } |
| 182 | |
| 183 | // Shift into bounds without changing span. |
| 184 | if (s < 0) { |
| 185 | const shift = -s; |
| 186 | s += shift; |
| 187 | e += shift; |
| 188 | } |
| 189 | if (e > 100) { |
| 190 | const shift = e - 100; |
| 191 | s -= shift; |
| 192 | e -= shift; |
| 193 | } |
| 194 | |
| 195 | // Final clamp for tiny floating point drift. |
| 196 | s = clamp(s, 0, 100); |
no test coverage detected