Repository navigation
Major Changes
-
#938
d026dbaThanks @tembo! - Ship ESM only, with the packageexportsgenerated by tsdown.- The CommonJS build (
dist/index.cjs) is removed. On Node.js 20.19+ and 22.12+,require('compute-scroll-into-view')still works throughrequire(esm)and returns{ compute }. - TypeScript projects with CommonJS files must use
"module": "nodenext". With"module": "node16", TypeScript reports TS1479 when CommonJS files import an ES module. ESM files and"moduleResolution": "bundler"are unaffected. exportsis now{ ".": "./dist/index.js" }. Thesourceexport condition and thesourceandtypingsfields are removed.typesreplacestypings.
- The CommonJS build (
-
#953
88378bfThanks @stipsan! -compute(target, options)is spec-only. ThescrollMode,boundaryandskipOverflowHiddenElementsoptions are removed, and are middleware instead, with the same behavior. The built-in middleware are exported fromcompute-scroll-into-view/middleware, so the main entry only hascomputeand its types. Middleware can also change how scroll containers are found and measured, likescroll-marginandscroll-padding.optionsis now optional.import { compute } from 'compute-scroll-into-view' import { boundary, onlyIfNeeded, skipOverflowHiddenElements, } from 'compute-scroll-into-view/middleware' // Before: compute(node, { scrollMode: 'if-needed', boundary: list, skipOverflowHiddenElements: true }) compute(node, { middleware: [boundary(list), skipOverflowHiddenElements(), onlyIfNeeded()], })
- Put
onlyIfNeeded()after the other middleware, which is how the options combined. - The
ScrollModetype is removed.ComputeOptionsis an alias ofOptions, and theMiddleware,MiddlewareState,MiddlewareReturn,RectsandSideObjecttypes are exported fromcompute-scroll-into-view.
- Put
Minor Changes
-
#952
3a93d4cThanks @stipsan! - Add thecontaineroption from the CSSOM View spec'sScrollIntoViewOptions.container: 'nearest'only scrolls the target's nearest scroll container, or the viewport if it has none. The default,'all', scrolls every scroll container as before. -
#966
245679dThanks @stipsan! - Scroll the scroll containers and the viewport of the parent document too, when the target is in a same-origin iframe, asElement.scrollIntoView()and the CSSOM View spec do. They align the<iframe>where the scrolling inside the frame left the target, up to the top-level document. Cross-origin parents aren't reachable, and aren't scrolled. Aposition: fixedtarget in a frame doesn't move with the frame's viewport, so only the parent document is scrolled for it. This also covers scrolling a frame's target from inside the frame (#694). -
#951
520fd20Thanks @stipsan! - Respectscroll-paddingand alignscroll-marginlike browsers do.scroll-paddingon scroll containers, and on the root element for the viewport, is now part of the alignment (#831). Padding in percentages is supported.scroll-marginof the target now works withblock: 'center'and'nearest', and together withscroll-padding(#933).scrollMode: 'if-needed'only counts a target as visible when itsscroll-marginbox is within the scroll containers'scroll-padding(#817). For example, a target behind a fixed header that is covered byscroll-padding-topis scrolled into view.nearestis measured from the padding edge of scroll containers with borders, instead of the border edge.
-
#964
ed654a2Thanks @stipsan! - Land on the target's own snap position in its nearest scroll container when that's a scroll snap container, as the CSSOM View spec requires. On each axis that the container'sscroll-snap-typesnaps, the target'sscroll-snap-alignreplacesblockorinlinethere. The outer scroll containers now align the target from where the browser actually snaps the inner one. -
#970
46be135Thanks @stipsan! - Add theselection()middleware, which scrolls a text selection into view instead of the target element, like editors keep the caret in view (#902). It takes aSelectionor aRange, and defaults to the document's selection. The focus end is aligned, where the caret is: a collapsed caret is measured as the character or node next to it, so empty lines work too.align: 'bounds'aligns the whole selection instead.computestill walks the target's ancestors, so pass an element inside the editor.onlyIfNeeded()checks the selection when it runs afterselection(). -
#950
28e19bcThanks @stipsan! - Follow the target'swriting-modeanddirection, like browsers do, and support negative scroll offsets.blockandinlinenow refer to the target's block and inline axes. For example,inline: 'start'aligns to the right edge of a right-to-left target, andblock: 'start'aligns to the right edge of avertical-rltarget. Horizontal left-to-right targets work as before.- Scroll containers that overflow to the left or top, like right-to-left or
vertical-rlones, now get the negativeleftandtopoffsets browsers use for them, instead of being clamped to 0 (#821). - Scrollbars on the left side of a scroll container are accounted for.
Patch Changes
-
#960
a51675fThanks @stipsan! - Scroll the body when it's a scroll container. Its overflow only applies to the viewport when the root's overflow isvisible, so a body withoverflow: autounder a root withoverflow: hidden,autoorclipis scrolled now, likeElement.scrollIntoView()does. -
#949
76f855dThanks @stipsan! - Declare the supported browsers as Baseline 2019 in thebrowserslistfield ofpackage.json, and build for it. The bundle now also compiles away optional catch binding for legacy Edge 18, and stays free of optional chaining and nullish coalescing.dist/index.d.ts.mapis no longer published, as it pointed atsrc/, which isn't published either.dist/index.js.mapstill embeds the source. -
#957
e724874Thanks @feritcemkahraman! - Don't scrolloverflow: visibleelements inside an iframe. Only the iframe document's viewport (its root or scrolling element) is clipped by the iframe and scrolled when its content overflows it. -
#936
aaaccf9Thanks @tembo! - Check forHTMLElementandShadowRootproperties with type guards instead of type assertions. The checks are the same, so behavior is unchanged. The type declarations now use the JSDoc@defaulttag instead of TSDoc's@defaultValue. -
#958
3b64201Thanks @satouriko! - Only scroll the scroll containers in the containing block chain of the target, likeElement.scrollIntoView()does. Scroll containers that an absolutely or fixed positioned target escapes don't move it, so they aren't scrolled anymore, and the viewport isn't scrolled for a fixed positioned target either. Containing blocks followpositionand the properties that contain positioned descendants, liketransform,filterandcontain. Middleware still visit those scroll containers, withscrollable: false. -
#961
4796634Thanks @stipsan! - Scroll the viewport when the target is the scrolling element, or the root element in quirks mode. They have no ancestor that scrolls the viewport, socompute(document.body)returned no actions in quirks mode, andcompute(document.documentElement)didn't in standards mode. -
#956
9a21f0cThanks @Remiscan! - Scroll the scroll containers in a shadow tree that a slotted target is laid out in. The parent walk now goes from an element to itsassignedSlot, before its parent element, so the slot's ancestors in the shadow tree are scrolled too, likeElement.scrollIntoView()does. -
#971
f1fc35bThanks @stipsan! - Shrink the published bundle by about a fifth when minified. Measuring the four sides of a box and scrolling each axis now share one code path, andgetPropertyValue()replaces the per-side style lookups. Behavior is unchanged. -
#962
e49fb1bThanks @stipsan! - Use the target's own document and window for viewport measurements, so scrolling a target inside a frame works whencomputeis called from the parent document.