# JS: Auto Adjust


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## generate_auto_adjust_js

Overflow-based feedback loop that dynamically determines how many cards
fit in the viewport. Uses transparency-based growth validation: new
cards are added with `opacity: 0`, measured for overflow, then revealed
if they fit or reverted if they overflow. Shrink path removes
overflowing cards reactively.

Growth is not capped at total items — when all real items fit, the loop
continues adding placeholder cards until the viewport is full. This
ensures consistent use of available space regardless of item count.

Depends on `_isAutoMode()` and `ns._autoUpdateCount()` being defined
earlier in the IIFE by the card count management fragment.

``` python
# Test auto-adjust JS generation
ids = CardStackHtmlIds(prefix="cs0")
config = CardStackConfig(prefix="cs0")
urls = CardStackUrls(update_viewport="/cs/update_viewport")

js = _generate_auto_adjust_js(ids, config, urls)
assert "Auto Visible Count Adjustment" in js
assert "_autoAdjusting" in js
assert "_autoGrowing" in js
assert "_preGrowthItemIds" in js
assert "_preGrowthCount" in js
assert "_snapshotItemIds" in js
assert "_hideNewItems" in js
assert "_revealNewItems" in js
assert "_validateGrowth" in js
assert "ns._runAutoAdjust" in js
assert "ns.triggerAutoAdjust" in js
assert "ns._cancelAutoGrowth" in js
assert "ns._autoUpdateCount" in js
# Default focus_position=None → JS null, step=2
assert "const _AUTO_FOCUS_POS = null;" in js
assert "(_AUTO_FOCUS_POS === null) ? 2 : 1" in js
# Verify growth is NOT capped at totalItems (fills viewport with placeholders)
assert "Math.min(totalItems" not in js
assert "currentCount >= totalItems" not in js
print("Auto-adjust JS basic tests passed!")
```

``` python
# Test focus_position parameter variations
js_bottom = _generate_auto_adjust_js(ids, config, urls, focus_position=-1)
assert "const _AUTO_FOCUS_POS = -1;" in js_bottom

js_top = _generate_auto_adjust_js(ids, config, urls, focus_position=0)
assert "const _AUTO_FOCUS_POS = 0;" in js_top

js_custom = _generate_auto_adjust_js(ids, config, urls, focus_position=2)
assert "const _AUTO_FOCUS_POS = 2;" in js_custom
print("Auto-adjust focus_position tests passed!")
```

    Auto-adjust focus_position tests passed!
