@scrolia/vanilla
Version:
A headless scrollbar component
1 lines • 1.8 kB
Source Map (JSON)
{"version":3,"file":"scrollcore.mjs","names":["ScrollCoreContext: Context<ScrollCore | null>","core: ScrollCore | null"],"sources":["../../src/contexts/scrollcore.ts"],"sourcesContent":["import type { Context } from \"atomico/types/context\";\n\nimport type { CompleteOptions } from \"#/@types/options\";\n\nimport * as Atom from \"atomico\";\n\n/** Options for the `ScrollCore` context. */\ntype ScrollCoreOptions = CompleteOptions;\n\n/** States for the `ScrollCore` context. */\ntype ScrollCoreStates = {\n hvTrack: boolean;\n setHvTrack: Atom.SetState<boolean>;\n hvThumb: boolean;\n setHvThumb: Atom.SetState<boolean>;\n total: Atom.Ref<number>;\n view: Atom.Ref<number>;\n viewOffset: Atom.Ref<number>;\n scrollbarLength: number;\n setScrollbarLength: Atom.SetState<number>;\n scrollbarOffset: number;\n setScrollbarOffset: Atom.SetState<number>;\n};\n\n/** Core for internal logic. */\ntype ScrollCore = {\n options: ScrollCoreOptions;\n contentRef: Atom.Ref<HTMLElement | null>;\n x: ScrollCoreStates;\n y: ScrollCoreStates;\n};\n\n/** `ScrollCore` context. */\nconst ScrollCoreContext: Context<ScrollCore | null> =\n Atom.createContext<ScrollCore | null>(null);\n\n/** Hook for using the `ScrollCore` context. */\nconst useScrollCore = (): ScrollCore => {\n const core: ScrollCore | null = Atom.useContext(ScrollCoreContext);\n\n if (core === null) {\n throw new Error(\"useScrollCore must be used within a provider\");\n }\n\n return core;\n};\n\nexport type { ScrollCoreOptions, ScrollCoreStates, ScrollCore };\nexport { ScrollCoreContext, useScrollCore };\n"],"mappings":";;;AAiCA,MAAMA,oBACF,KAAK,cAAiC,KAAK;;AAG/C,MAAM,gBAAgB,MAAkB;CACpC,MAAMC,OAA0B,KAAK,WAAW,kBAAkB;AAElE,KAAI,SAAS,KACT,OAAM,IAAI,MAAM;AAGpB,QAAO;AACV"}