{"version":3,"file":"NProgress.cjs","names":[],"sources":["../../../src/components/NProgress/NProgress.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { CSSProperties } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./NProgress.module.css\";\n\n/** Snapshot of the progress controller state delivered to subscribers. */\nexport interface NProgressState {\n    /** Current progress, `0` (empty) to `1` (complete). */\n    value: number;\n    /** Whether the bar should be visible. */\n    active: boolean;\n}\n\n/** Listener invoked whenever the progress state changes. */\nexport type NProgressListener = (state: NProgressState) => void;\n\n/** Imperative top-loading-bar controller. */\nexport interface NProgressController {\n    /** Show the bar and start trickling toward ~0.9. */\n    start: () => void;\n    /** Complete to `1`, then hide the bar shortly after. */\n    done: () => void;\n    /** Set the progress explicitly. Values are clamped to `0..1`. */\n    set: (n: number) => void;\n    /** Increment progress by `amount` (default a small trickle step). */\n    inc: (amount?: number) => void;\n    /** Subscribe to state changes. Returns an unsubscribe function. */\n    subscribe: (listener: NProgressListener) => () => void;\n}\n\nconst TRICKLE_INTERVAL_MS = 300;\nconst TRICKLE_CEILING = 0.9;\nconst DONE_HIDE_DELAY_MS = 300;\n\nfunction clamp(n: number): number {\n    if (n < 0) return 0;\n    if (n > 1) return 1;\n    return n;\n}\n\nfunction createNProgress(): NProgressController {\n    let state: NProgressState = { value: 0, active: false };\n    const listeners = new Set<NProgressListener>();\n    let trickleTimer: ReturnType<typeof setInterval> | null = null;\n    let hideTimer: ReturnType<typeof setTimeout> | null = null;\n\n    const emit = (): void => {\n        for (const listener of listeners) listener(state);\n    };\n\n    const update = (next: Partial<NProgressState>): void => {\n        state = { ...state, ...next };\n        emit();\n    };\n\n    const stopTrickle = (): void => {\n        if (trickleTimer !== null) {\n            clearInterval(trickleTimer);\n            trickleTimer = null;\n        }\n    };\n\n    const clearHide = (): void => {\n        if (hideTimer !== null) {\n            clearTimeout(hideTimer);\n            hideTimer = null;\n        }\n    };\n\n    const inc = (amount?: number): void => {\n        const current = state.value;\n        if (current >= TRICKLE_CEILING) return;\n        const step = amount ?? (1 - current) * 0.1 + 0.01;\n        update({ value: Math.min(clamp(current + step), TRICKLE_CEILING) });\n    };\n\n    const start = (): void => {\n        clearHide();\n        if (state.active) return;\n        update({ active: true, value: state.value > 0 ? state.value : 0.08 });\n        stopTrickle();\n        trickleTimer = setInterval(() => inc(), TRICKLE_INTERVAL_MS);\n    };\n\n    const done = (): void => {\n        stopTrickle();\n        clearHide();\n        update({ value: 1, active: true });\n        hideTimer = setTimeout(() => {\n            update({ active: false, value: 0 });\n            hideTimer = null;\n        }, DONE_HIDE_DELAY_MS);\n    };\n\n    const set = (n: number): void => {\n        clearHide();\n        const value = clamp(n);\n        update({ value, active: value < 1 ? true : state.active });\n    };\n\n    const subscribe = (listener: NProgressListener): (() => void) => {\n        listeners.add(listener);\n        listener(state);\n        return () => {\n            listeners.delete(listener);\n        };\n    };\n\n    return { start, done, set, inc, subscribe };\n}\n\n/**\n * Module-level singleton progress controller. Drive it imperatively from\n * anywhere (router transitions, fetch interceptors) and render the visual bar\n * with {@link NProgressBar}.\n *\n * @example\n * nprogress.start();\n * await loadData();\n * nprogress.done();\n */\nexport const nprogress: NProgressController = createNProgress();\n\n/** Props for {@link NProgressBar}. */\nexport interface NProgressBarProps {\n    /** Bar color. Defaults to `var(--tempest-primary)`. */\n    color?: string;\n    /** Bar height in pixels. Default `3`. */\n    height?: number;\n    /** Extra class applied to the bar element. */\n    className?: string;\n}\n\n/**\n * Fixed top loading bar bound to the {@link nprogress} singleton. Mount once\n * near the app root; it renders nothing while inactive.\n *\n * @example\n * <NProgressBar />\n */\nexport function NProgressBar({ color, height = 3, className }: NProgressBarProps) {\n    const [state, setState] = useState<NProgressState>({ value: 0, active: false });\n\n    useEffect(() => nprogress.subscribe(setState), []);\n\n    if (!state.active) return null;\n\n    const style: CSSProperties = {\n        width: `${Math.round(state.value * 100)}%`,\n        height: `${height}px`,\n        background: color ?? \"var(--tempest-primary)\",\n    };\n\n    return (\n        <div\n            className={cn(styles.bar, className)}\n            style={style}\n            role=\"progressbar\"\n            aria-valuemin={0}\n            aria-valuemax={100}\n            aria-valuenow={Math.round(state.value * 100)}\n        />\n    );\n}\n"],"mappings":"gIA8BA,IAAM,EAAsB,IACtB,EAAkB,GAClB,EAAqB,IAE3B,SAAS,EAAM,EAAmB,CAG9B,OAFI,EAAI,EAAU,EACd,EAAI,EAAU,EACX,CACX,CAEA,SAAS,GAAuC,CAC5C,IAAI,EAAwB,CAAE,MAAO,EAAG,OAAQ,EAAM,EAChD,EAAY,IAAI,IAClB,EAAsD,KACtD,EAAkD,KAEhD,MAAmB,CACrB,IAAK,IAAM,KAAY,EAAW,EAAS,CAAK,CACpD,EAEM,EAAU,GAAwC,CACpD,EAAQ,CAAE,GAAG,EAAO,GAAG,CAAK,EAC5B,EAAK,CACT,EAEM,MAA0B,CACxB,IAAiB,OACjB,cAAc,CAAY,EAC1B,EAAe,KAEvB,EAEM,MAAwB,CACtB,IAAc,OACd,aAAa,CAAS,EACtB,EAAY,KAEpB,EAEM,EAAO,GAA0B,CACnC,IAAM,EAAU,EAAM,MACtB,GAAI,GAAW,EAAiB,OAChC,IAAM,EAAO,IAAW,EAAI,GAAW,GAAM,IAC7C,EAAO,CAAE,MAAO,KAAK,IAAI,EAAM,EAAU,CAAI,EAAG,CAAe,CAAE,CAAC,CACtE,EAkCA,MAAO,CAAE,UAhCiB,CACtB,EAAU,EACN,GAAM,SACV,EAAO,CAAE,OAAQ,GAAM,MAAO,EAAM,MAAQ,EAAI,EAAM,MAAQ,GAAK,CAAC,EACpE,EAAY,EACZ,EAAe,gBAAkB,EAAI,EAAG,CAAmB,EAC/D,EA0BgB,SAxBS,CACrB,EAAY,EACZ,EAAU,EACV,EAAO,CAAE,MAAO,EAAG,OAAQ,EAAK,CAAC,EACjC,EAAY,eAAiB,CACzB,EAAO,CAAE,OAAQ,GAAO,MAAO,CAAE,CAAC,EAClC,EAAY,IAChB,EAAG,CAAkB,CACzB,EAgBsB,IAdT,GA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