{"version":3,"file":"scroll-into-view.mjs","sources":["../../../../packages/utils/scroll-into-view.ts"],"sourcesContent":["import isServer from './isServer'\n\nexport default function scrollIntoView(\n  container: HTMLElement,\n  selected: HTMLElement\n): void {\n  if (isServer) return\n\n  if (!selected) {\n    container.scrollTop = 0\n    return\n  }\n\n  const offsetParents = []\n  let pointer = selected.offsetParent\n  while (\n    pointer !== null &&\n    container !== pointer &&\n    container.contains(pointer)\n  ) {\n    offsetParents.push(pointer)\n    pointer = (pointer as HTMLElement).offsetParent\n  }\n  const top =\n    selected.offsetTop +\n    offsetParents.reduce((prev, curr) => prev + curr.offsetTop, 0)\n  const bottom = top + selected.offsetHeight\n  const viewRectTop = container.scrollTop\n  const viewRectBottom = viewRectTop + container.clientHeight\n\n  if (top < viewRectTop) {\n    container.scrollTop = top\n  } else if (bottom > viewRectBottom) {\n    container.scrollTop = bottom - container.clientHeight\n  }\n}\n"],"names":[],"mappings":";;wBAGE,WACA,UACM;AACN,MAAI;AAAU;AAEd,MAAI,CAAC,UAAU;AACb,cAAU,YAAY;AACtB;AAAA;AAGF,QAAM,gBAAgB;AACtB,MAAI,UAAU,SAAS;AACvB,SACE,YAAY,QACZ,cAAc,WACd,UAAU,SAAS,UACnB;AACA,kBAAc,KAAK;AACnB,cAAW,QAAwB;AAAA;AAErC,QAAM,MACJ,SAAS,YACT,cAAc,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,WAAW;AAC9D,QAAM,SAAS,MAAM,SAAS;AAC9B,QAAM,cAAc,UAAU;AAC9B,QAAM,iBAAiB,cAAc,UAAU;AAE/C,MAAI,MAAM,aAAa;AACrB,cAAU,YAAY;AAAA,aACb,SAAS,gBAAgB;AAClC,cAAU,YAAY,SAAS,UAAU;AAAA;AAAA;;;;"}