{"version":3,"names":["clamp","SCROLL_EDGE_TOLERANCE_PX","getMaxScrollOffset","scrollSize","clientSize","Math","max","normalizeScrollOffset","value","clamped","startDistance","endDistance","withinStartTolerance","withinEndTolerance"],"sources":["scroll-edges.ts"],"sourcesContent":["import { clamp } from \"../slider-utils/clamp\";\n\n/**\n * Sub-pixel tolerance around each edge. Scroll offsets within one pixel of\n * 0 or the maximum are treated as \"at the edge\" — browsers occasionally\n * report fractional offsets due to device-pixel rounding even when the\n * user perceives the content to be fully scrolled.\n */\nexport const SCROLL_EDGE_TOLERANCE_PX = 1;\n\n/**\n * Maximum scroll offset available for the given scroll and client sizes.\n * Guards against negative values — when content is smaller than the\n * viewport, the max is 0, not a negative number.\n */\nexport function getMaxScrollOffset(\n\tscrollSize: number,\n\tclientSize: number,\n): number {\n\treturn Math.max(0, scrollSize - clientSize);\n}\n\n/**\n * Clamps `value` into `[0, max]` and snaps to whichever edge is within\n * {@link SCROLL_EDGE_TOLERANCE_PX}. When both edges are within tolerance\n * (i.e. `max <= SCROLL_EDGE_TOLERANCE_PX`) the closer edge wins, with ties\n * going to the start.\n */\nexport function normalizeScrollOffset(value: number, max: number): number {\n\tif (max <= 0) {\n\t\treturn 0;\n\t}\n\n\tconst clamped = clamp(value, 0, max);\n\tconst startDistance = clamped;\n\tconst endDistance = max - clamped;\n\tconst withinStartTolerance = startDistance <= SCROLL_EDGE_TOLERANCE_PX;\n\tconst withinEndTolerance = endDistance <= SCROLL_EDGE_TOLERANCE_PX;\n\n\tif (withinStartTolerance && withinEndTolerance) {\n\t\treturn startDistance <= endDistance ? 0 : max;\n\t}\n\n\tif (withinStartTolerance) {\n\t\treturn 0;\n\t}\n\n\tif (withinEndTolerance) {\n\t\treturn max;\n\t}\n\n\treturn clamped;\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,GAAG,CAAC;;AAEzC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CACjCC,UAAkB,EAClBC,UAAkB,EACT;EACT,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEH,UAAU,GAAGC,UAAU,CAAC;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,qBAAqBA,CAACC,KAAa,EAAEF,GAAW,EAAU;EACzE,IAAIA,GAAG,IAAI,CAAC,EAAE;IACb,OAAO,CAAC;EACT;EAEA,MAAMG,OAAO,GAAGT,KAAK,CAACQ,KAAK,EAAE,CAAC,EAAEF,GAAG,CAAC;EACpC,MAAMI,aAAa,GAAGD,OAAO;EAC7B,MAAME,WAAW,GAAGL,GAAG,GAAGG,OAAO;EACjC,MAAMG,oBAAoB,GAAGF,aAAa,IAAIT,wBAAwB;EACtE,MAAMY,kBAAkB,GAAGF,WAAW,IAAIV,wBAAwB;EAElE,IAAIW,oBAAoB,IAAIC,kBAAkB,EAAE;IAC/C,OAAOH,aAAa,IAAIC,WAAW,GAAG,CAAC,GAAGL,GAAG;EAC9C;EAEA,IAAIM,oBAAoB,EAAE;IACzB,OAAO,CAAC;EACT;EAEA,IAAIC,kBAAkB,EAAE;IACvB,OAAOP,GAAG;EACX;EAEA,OAAOG,OAAO;AACf","ignoreList":[]}