{"version":3,"file":"length.mjs","names":["_total: number","_view: number","_viewOffset: number","scrollbarLengthNext: number","result: OnSetLengthResult | undefined","length: number"],"sources":["../../../../src/hooks/content/functions/length.ts"],"sourcesContent":["import type { Axis, OnSetLengthResult, Plugin } from \"#/@types/options\";\n\nimport { tryPlugin } from \"#/functions/plugin\";\n\ntype SetLengthOptions = {\n    axis: Axis;\n    disabled: boolean;\n    animated: boolean;\n    plugins: Plugin[];\n    hvTrack: boolean;\n    hvThumb: boolean;\n    total: React.RefObject<number>;\n    view: React.RefObject<number>;\n    viewOffset: React.RefObject<number>;\n    scrollbarLength: number;\n    setScrollbarLength: React.Dispatch<React.SetStateAction<number>>;\n};\n\nconst setLengthFn = ({\n    axis,\n    disabled,\n    animated,\n    plugins,\n    hvTrack,\n    hvThumb,\n    total,\n    view,\n    viewOffset,\n    scrollbarLength,\n    setScrollbarLength,\n}: SetLengthOptions): (() => void) => {\n    return (): void => {\n        const _total: number = total.current;\n        const _view: number = view.current;\n        const _viewOffset: number = viewOffset.current;\n\n        const scrollbarLengthNext: number = (_view / _total) * _view;\n\n        let result: OnSetLengthResult | undefined;\n\n        for (const plugin of plugins) {\n            if (!plugin.onSetLength) continue;\n\n            result =\n                tryPlugin(plugin, plugin.onSetLength, {\n                    axis,\n                    isDisabled: disabled,\n                    isAnimated: animated,\n                    isDefined: hvTrack && hvThumb,\n                    total: _total,\n                    view: _view,\n                    viewOffset: _viewOffset,\n                    scrollbarLengthPrev: scrollbarLength,\n                    scrollbarLengthNext:\n                        result?.scrollbarLength ?? scrollbarLengthNext,\n                }) ?? result;\n        }\n\n        let length: number;\n\n        if (result?.scrollbarLength) {\n            length = result.scrollbarLength;\n        } else {\n            length = scrollbarLengthNext;\n        }\n\n        // check if the scrollbar is needed\n        if (_view >= _total) {\n            setScrollbarLength(0);\n        } else {\n            setScrollbarLength(length);\n        }\n    };\n};\n\nexport type { SetLengthOptions };\nexport { setLengthFn };\n"],"mappings":";;AAkBA,MAAM,cAAc,CAAC,EACjB,MACA,UACA,UACA,SACA,SACA,SACA,OACA,MACA,YACA,iBACA,oBACe,KAAmB;AAClC,QAAO,MAAY;EACf,MAAMA,SAAiB,MAAM;EAC7B,MAAMC,QAAgB,KAAK;EAC3B,MAAMC,cAAsB,WAAW;EAEvC,MAAMC,sBAA+B,QAAQ,SAAU;EAEvD,IAAIC;AAEJ,OAAK,MAAM,UAAU,SAAS;AAC1B,OAAI,CAAC,OAAO,YAAa;GAEzB,SACI,UAAU,QAAQ,OAAO,aAAa;IAClC;IACA,YAAY;IACZ,YAAY;IACZ,WAAW,WAAW;IACtB,OAAO;IACP,MAAM;IACN,YAAY;IACZ,qBAAqB;IACrB,qBACI,QAAQ,mBAAmB;GAClC,EAAC,IAAI;EACb;EAED,IAAIC;AAEJ,MAAI,QAAQ,iBACR,SAAS,OAAO;OAEhB,SAAS;AAIb,MAAI,SAAS,QACT,mBAAmB,EAAE;OAErB,mBAAmB,OAAO;CAEjC;AACJ"}