{"version":3,"file":"index.cjs","names":["defaultOptionsProgressBar","defaultPropsInitRzlNextProgressBar","RzlProgress"],"sources":["../../src/progress-bar/events/actions.ts"],"sourcesContent":["import {\n  enableUserInteraction,\n  disableUserInteraction,\n  removeElementFocus\n} from \"@rzl-zone/utils-js/events\";\nimport {\n  isBoolean,\n  isNonEmptyString,\n  isNumber,\n  isPlainObject,\n  isUndefined\n} from \"@rzl-zone/utils-js/predicates\";\n\nimport { RzlProgress } from \"../utils/rzlProgress\";\nimport {\n  defaultOptionsProgressBar,\n  defaultPropsInitRzlNextProgressBar\n} from \"../constants\";\n\nimport type { RzlNextProgressBarProps, RzlProgressType } from \"../types\";\nimport type { Prettify } from \"@rzl-zone/ts-types-plus\";\n\ntype ClassNameIfLoading = Pick<RzlNextProgressBarProps, \"classNameIfLoading\">;\n\ntype StartRzlProgressProps = Prettify<\n  {\n    /** * Disabled and prevent any actions.\n     *\n     * @default true\n     */\n    withDisableAnyAction?: boolean;\n    /** * Remove focus (blur) from all element actions.\n     *\n     * @default true\n     */\n    withRemoveAllFocusElement?: boolean;\n    optionsProgressBar?: RzlProgressType;\n    withStopDelay?: {\n      /**\n       * @default false\n       */\n      enable?: boolean;\n      /**\n       * @default 1000\n       */\n      delayStop?: number;\n    };\n  } & ClassNameIfLoading\n>;\n\ntype StopRzlProgressProps = Prettify<\n  {\n    /**\n     * @default false\n     */\n    force?: boolean;\n  } & ClassNameIfLoading\n>;\n\nconst defaultWithStopDelay = {\n  enable: false,\n  delayStop: 1000\n} as const satisfies Required<StartRzlProgressProps[\"withStopDelay\"]>;\n\n/** ----------------------------------------------------------\n * * ***Utility: `startRzlProgress`.***\n * ----------------------------------------------------------\n * **Starts the `RzlProgress` (bar-loader) with optional configurations.**\n *\n * - **⚠️ Important Usage Requirement:**\n *    - This utility **only works if your Next.js layout has one of the Rzl progress bar components mounted**:\n *      - **App Router** ➔ Must include `RzlNextAppProgressBar` in your root layout.\n *      - **Pages Router** ➔ Must include `RzlNextPagesProgressBar` in `_app.tsx`.\n *\n * - **Features**:\n *    - Automatically disables user interaction and removes focus from elements if enabled.\n *    - Configures and starts the progress bar according to provided options.\n *    - Optionally auto-stops the progress bar after a delay.\n * - All options have strict fallback/default values if invalid or missing.\n * @param {StartRzlProgressProps} [props] - Optional settings for starting the progress bar.\n * @param {boolean} [props.withDisableAnyAction=true] - If `true`, disables all user interactions while progress is running.\n * @param {boolean} [props.withRemoveAllFocusElement=true] - If `true`, removes focus from all actionable elements.\n * @param {RzlProgressType} [props.optionsProgressBar=defaultOptionsProgressBar] - Configuration object for the progress bar.\n * @param {ClassNameIfLoading[\"classNameIfLoading\"]} [props.classNameIfLoading] - Optional CSS class applied during loading.\n * @param {StartRzlProgressProps[\"withStopDelay\"]} [props.withStopDelay] - Optional auto-stop settings.\n * @param {boolean} [props.withStopDelay.enable=false] - If `true`, automatically stops the progress bar after delay.\n * @param {number} [props.withStopDelay.delayStop=1000] - Delay (ms) before automatically stopping the progress bar. Must be ≥ 0.\n * @returns {(forceStop?: boolean) => void} Returns a function to force stop the progress bar immediately.\n * @example\n * // ✅ Valid usage:\n * startRzlProgress();\n * startRzlProgress({ withDisableAnyAction: false });\n * startRzlProgress({ withStopDelay: { enable: true, delayStop: 2000 } });\n *\n * // ❌ Invalid usage (fallback applied):\n * startRzlProgress({ withDisableAnyAction: \"yes\" as any, withStopDelay: { enable: \"true\" as any, delayStop: -50 } });\n * // ➔ Fallback to: withDisableAnyAction=true, withStopDelay.enable=false, delayStop=1000\n */\nexport const startRzlProgress = (\n  props: StartRzlProgressProps = {}\n): ((forceStop?: boolean) => void) => {\n  if (!isPlainObject(props)) props = {};\n\n  const {\n    withDisableAnyAction = true,\n    optionsProgressBar = defaultOptionsProgressBar,\n    withRemoveAllFocusElement = true\n  } = props;\n\n  let { classNameIfLoading, withStopDelay = defaultWithStopDelay } = props;\n\n  if (!isUndefined(classNameIfLoading) && !isNonEmptyString(classNameIfLoading))\n    classNameIfLoading =\n      defaultPropsInitRzlNextProgressBar[\"classNameIfLoading\"];\n\n  if (!isPlainObject(props)) withStopDelay = defaultWithStopDelay;\n  let { delayStop, enable } = withStopDelay;\n\n  if (!isBoolean(enable)) enable = defaultWithStopDelay.enable;\n  if (!isNumber(delayStop)) delayStop = defaultWithStopDelay.delayStop;\n\n  let timeOut: NodeJS.Timeout | null = null;\n\n  if (!RzlProgress.isRendered() || !RzlProgress.isStarted()) {\n    RzlProgress.configure(optionsProgressBar);\n\n    if (withRemoveAllFocusElement) {\n      removeElementFocus();\n    }\n\n    if (withDisableAnyAction) {\n      disableUserInteraction(\n        classNameIfLoading || RzlProgress.getClassNameIfLoading() || undefined\n      );\n    }\n\n    RzlProgress.start();\n\n    if (enable) {\n      if (timeOut) clearTimeout(timeOut);\n\n      timeOut = setTimeout(() => {\n        stopRzlProgress();\n      }, delayStop);\n    }\n  }\n\n  // ✅ return stop function\n  return (forceStop?: boolean) => {\n    if (timeOut) clearTimeout(timeOut);\n\n    if (forceStop) stopRzlProgress();\n  };\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `stopRzlProgress`.***\n * ----------------------------------------------------------\n * **Stops the `RzlProgress` (bar-loader) and re-enables user interactions.**\n *\n * - **⚠️ Important Usage Requirement:**\n *    - This utility **only works if your Next.js layout has one of the Rzl progress bar components mounted**:\n *      - **App Router** ➔ Must include `RzlNextAppProgressBar` in your root layout.\n *      - **Pages Router** ➔ Must include `RzlNextPagesProgressBar` in `_app.tsx`.\n *\n * - **Features**:\n *    - Stops the progress bar immediately or with force.\n *    - Re-enables user interactions on elements disabled during loading.\n * - Invalid or missing class names are automatically replaced with defaults.\n * @param {StopRzlProgressProps} [props] - Optional settings for stopping the progress bar.\n * @param {boolean} [props.force=false] - If `true`, forces immediate completion of progress bar.\n * @param {ClassNameIfLoading[\"classNameIfLoading\"]} [props.classNameIfLoading] - Optional CSS class applied during loading.\n * @returns {void} Does not return anything.\n * @example\n * stopRzlProgress();\n * stopRzlProgress({ force: true });\n */\nexport const stopRzlProgress = (props: StopRzlProgressProps = {}): void => {\n  if (!isPlainObject(props)) props = {};\n\n  if (RzlProgress.isRendered() || RzlProgress.isStarted()) {\n    RzlProgress.done(props.force);\n  }\n\n  if (\n    !isUndefined(props.classNameIfLoading) &&\n    !isNonEmptyString(props.classNameIfLoading)\n  ) {\n    props.classNameIfLoading =\n      defaultPropsInitRzlNextProgressBar[\"classNameIfLoading\"];\n  }\n\n  enableUserInteraction(\n    props.classNameIfLoading || RzlProgress.getClassNameIfLoading() || undefined\n  );\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `isStartedRzlProgress`.***\n * ----------------------------------------------------------\n * **Checks if the `RzlProgress` is currently started.**\n *\n * - **⚠️ Important Usage Requirement:**\n *    - This utility **only works if your Next.js layout has one of the Rzl progress bar components mounted**:\n *      - **App Router** ➔ Must include `RzlNextAppProgressBar` in your root layout.\n *      - **Pages Router** ➔ Must include `RzlNextPagesProgressBar` in `_app.tsx`.\n *\n * @returns {boolean} `true` if progress bar is started, `false` otherwise.\n * @example\n * if (isStartedRzlProgress()) { console.log(\"Progress is running\"); }\n */\nexport const isStartedRzlProgress = (): boolean => {\n  return RzlProgress.isStarted();\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `isRenderedRzlProgress`.***\n * ----------------------------------------------------------\n * **Checks if the `RzlProgress` is rendered in the DOM.**\n *\n * - **⚠️ Important Usage Requirement:**\n *    - This utility **only works if your Next.js layout has one of the Rzl progress bar components mounted**:\n *      - **App Router** ➔ Must include `RzlNextAppProgressBar` in your root layout.\n *      - **Pages Router** ➔ Must include `RzlNextPagesProgressBar` in `_app.tsx`.\n *\n * @returns {boolean} `true` if progress bar exists in the DOM, `false` otherwise.\n * @example\n * if (isRenderedRzlProgress()) { console.log(\"Progress is in DOM\"); }\n */\nexport const isRenderedRzlProgress = (): boolean => {\n  return RzlProgress.isRendered();\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `pauseRzlProgress`.***\n * ----------------------------------------------------------\n * **Pauses the `RzlProgress` bar temporarily.**\n *\n * Can be resumed later using `resumeRzlProgress`.\n *\n * - **⚠️ Important Usage Requirement:**\n *    - This utility **only works if your Next.js layout has one of the Rzl progress bar components mounted**:\n *      - **App Router** ➔ Must include `RzlNextAppProgressBar` in your root layout.\n *      - **Pages Router** ➔ Must include `RzlNextPagesProgressBar` in `_app.tsx`.\n *\n * @returns {void} Does not return anything.\n * @example\n * pauseRzlProgress();\n */\nexport const pauseRzlProgress = (): void => {\n  RzlProgress.pause();\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `resumeRzlProgress`.***\n * ----------------------------------------------------------\n * **Resumes the `RzlProgress` bar if it was paused.**\n *\n * - **⚠️ Important Usage Requirement:**\n *    - This utility **only works if your Next.js layout has one of the Rzl progress bar components mounted**:\n *      - **App Router** ➔ Must include `RzlNextAppProgressBar` in your root layout.\n *      - **Pages Router** ➔ Must include `RzlNextPagesProgressBar` in `_app.tsx`.\n *\n * @returns {void} Does not return anything.\n * @example\n * resumeRzlProgress();\n */\nexport const resumeRzlProgress = (): void => {\n  RzlProgress.resume();\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA2DA,MAAM,uBAAuB;CAC3B,QAAQ;CACR,WAAW;AACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,oBACX,QAA+B,CAAC,MACI;CACpC,IAAI,kDAAe,KAAK,GAAG,QAAQ,CAAC;CAEpC,MAAM,EACJ,uBAAuB,MACvB,qBAAqBA,+CACrB,4BAA4B,SAC1B;CAEJ,IAAI,EAAE,oBAAoB,gBAAgB,yBAAyB;CAEnE,IAAI,gDAAa,kBAAkB,KAAK,qDAAkB,kBAAkB,GAC1E,qBACEC,uDAAmC;CAEvC,IAAI,kDAAe,KAAK,GAAG,gBAAgB;CAC3C,IAAI,EAAE,WAAW,WAAW;CAE5B,IAAI,8CAAW,MAAM,GAAG,SAAS,qBAAqB;CACtD,IAAI,6CAAU,SAAS,GAAG,YAAY,qBAAqB;CAE3D,IAAI,UAAiC;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