UNPKG

@rzl-zone/utils-js

Version:

A modern, lightweight set of JavaScript utility functions with TypeScript support for everyday development, crafted to enhance code readability and maintainability.

60 lines (54 loc) 2.24 kB
/*! * ==================================================== * Rzl Utils-JS. * ---------------------------------------------------- * Version: 3.11.0. * Author: Rizalvin Dwiky. * Repository: https://github.com/rzl-zone/utils-js. * ==================================================== */ import { isServer } from './chunk-L5RDAVVH.js'; import { assertIsString } from './chunk-3T6VSWYX.js'; import { isPlainObject, hasOwnProp, isNonEmptyString, isNumber } from './chunk-MSUW5VHZ.js'; var disableUserInteraction = (className = "on_processing") => { if (isServer()) return; assertIsString(className, { message({ validType, currentType }) { return `First parameter \`className\` must be of type \`${validType}\`, but received: \`${currentType}\`.`; } }); const { documentElement } = document; if (documentElement && !documentElement.classList.contains(className)) { documentElement.classList.add(className); } }; var enableUserInteraction = (className = "on_processing") => { if (isServer()) return; assertIsString(className, { message({ validType, currentType }) { return `First parameter \`className\` must be of type \`${validType}\`, but received: \`${currentType}\`.`; } }); const { documentElement } = document; if (documentElement && documentElement.classList.contains(className)) { documentElement.classList.remove(className); } }; var removeElementFocus = () => { if (isServer()) return; const activeElement = document.activeElement; if (activeElement instanceof HTMLElement) { activeElement.blur(); } }; var scrollToTop = (options) => { if (isServer()) return; if (!isPlainObject(options)) { options = {}; } const behavior = hasOwnProp(options, "behavior") && isNonEmptyString(options.behavior) && ["auto", "instant", "smooth"].includes(options.behavior) ? options.behavior : "smooth"; let timeout = hasOwnProp(options, "timeout") && isNumber(options.timeout) && options.timeout >= 1 ? options.timeout : 1; timeout = timeout > 2147483647 ? 2147483647 : timeout; setTimeout(() => window.scrollTo({ top: 0, left: 0, behavior }), timeout); }; export { disableUserInteraction, enableUserInteraction, removeElementFocus, scrollToTop };