{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import {useMemo, useRef} from \"react\";\nimport {isEqual} from \"lodash-es\";\nimport {FinalOptions, RequiredOptions, UrlOptions, Value} from \"./types\";\n\nexport const getRenderingType = () =>  {\n    const isBrowser = (typeof window != 'undefined' && window.document)\n    return isBrowser ? \"client\" : \"server\";\n};\n\nexport const getValue = <T,>(value: Value<T>): T => {\n    if (typeof value === \"function\") {\n        // @ts-ignore\n        return value();\n    }\n    return value;\n}\n\n\nexport const isClient = getRenderingType() === \"client\";\nexport const isServer = getRenderingType() === \"server\";\n\nexport const paramsTransitioning = \"__ParamsTransitioning\";\n\nexport const isParamsTransition = (state: unknown) => state != null && typeof state === \"object\" && paramsTransitioning in state;\n\nexport const useSmartValue = <T,>(value: T) => {\n    const ref = useRef<T>(undefined);\n    if (ref.current === undefined) {\n        ref.current = value;\n    }\n    if (isEqual(ref.current, value)) {\n        return ref.current;\n    } else {\n        ref.current = value;\n        return value;\n    }\n};\n\nexport const useMemoOptions = <T,>(options: RequiredOptions<T>, options2?: UrlOptions, options3?: FinalOptions<T>) => {\n    const smartOptions1 = useSmartValue(options);\n    const smartOptions2 = useSmartValue(options2);\n    const smartOptions3 = useSmartValue(options3);\n    return useMemo(() => mergeOptions<RequiredOptions<T>>(smartOptions1, smartOptions2, smartOptions3), [smartOptions1, smartOptions2, smartOptions3]);\n}\n\nexport const mergeOptions = <T,>(...options: any[]) => {\n    return Object.assign({}, ...options) as T\n};\n\nexport const camelCaseToKebab =\n    (str: string): string => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? \"-\" : \"\") + $.toLowerCase());\n"],"names":["useRef","isEqual","useMemo"],"mappings":";;;;AAIO,MAAM,mBAAmB,MAAO;AACnC,QAAM,YAAa,OAAO,UAAU,eAAe,OAAO;AAC1D,SAAO,YAAY,WAAW;AAClC;AAEa,MAAA,WAAW,CAAK,UAAuB;AAC5C,MAAA,OAAO,UAAU,YAAY;AAE7B,WAAO,MAAM;AAAA,EAAA;AAEV,SAAA;AACX;AAGa,MAAA,WAAW,uBAAuB;AAClC,MAAA,WAAW,uBAAuB;AAExC,MAAM,sBAAsB;AAEtB,MAAA,qBAAqB,CAAC,UAAmB,SAAS,QAAQ,OAAO,UAAU,YAAY,uBAAuB;AAE9G,MAAA,gBAAgB,CAAK,UAAa;AACrC,QAAA,MAAMA,aAAU,MAAS;AAC3B,MAAA,IAAI,YAAY,QAAW;AAC3B,QAAI,UAAU;AAAA,EAAA;AAElB,MAAIC,iBAAQ,IAAI,SAAS,KAAK,GAAG;AAC7B,WAAO,IAAI;AAAA,EAAA,OACR;AACH,QAAI,UAAU;AACP,WAAA;AAAA,EAAA;AAEf;AAEO,MAAM,iBAAiB,CAAK,SAA6B,UAAuB,aAA+B;AAC5G,QAAA,gBAAgB,cAAc,OAAO;AACrC,QAAA,gBAAgB,cAAc,QAAQ;AACtC,QAAA,gBAAgB,cAAc,QAAQ;AACrC,SAAAC,cAAQ,MAAM,aAAiC,eAAe,eAAe,aAAa,GAAG,CAAC,eAAe,eAAe,aAAa,CAAC;AACrJ;AAEa,MAAA,eAAe,IAAQ,YAAmB;AACnD,SAAO,OAAO,OAAO,CAAC,GAAG,GAAG,OAAO;AACvC;AAEO,MAAM,mBACT,CAAC,QAAwB,IAAI,QAAQ,0BAA0B,CAAC,GAAG,SAAS,MAAM,MAAM,MAAM,EAAE,YAAa,CAAA;;;;;;;;;;;"}