@lyonph/preact-hooks
Version:
Collection of useful Preact Hooks
4 lines • 75.7 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/index.ts", "../../../src/useAsyncMemo.ts", "../../../src/useConditionalCallback.tsx", "../../../src/useDependencyChanged.tsx", "../../../src/useFreshState.tsx", "../../../src/useConstant.ts", "../../../src/useLazyRef.ts", "../../../src/useConstantCallback.ts", "../../../src/useForceUpdate.ts", "../../../src/useFreshLazyRef.tsx", "../../../src/useMountedState.ts", "../../../src/useIsomorphicEffect.ts", "../../../src/utils/is-client.ts", "../../../src/useConditionalEffect.tsx", "../../../src/useDependencyVersion.tsx", "../../../src/useConditionalLayoutEffect.tsx", "../../../src/useConditionalMemo.tsx", "../../../src/useFullscreenElement.tsx", "../../../src/useSubscription.ts", "../../../src/useMediaQuery.tsx", "../../../src/useOnlineStatus.ts", "../../../src/usePageVisibility.ts", "../../../src/usePartialState.tsx", "../../../src/usePrefersDarkTheme.tsx", "../../../src/usePrefersLightTheme.tsx", "../../../src/usePrefersReducedMotion.tsx", "../../../src/useReadyState.tsx", "../../../src/useReactiveObject.tsx", "../../../src/useReactiveRef.ts", "../../../src/useRenderCount.ts", "../../../src/useWindowScroll.tsx", "../../../src/useWindowSize.ts"],
"sourcesContent": ["/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { ShouldUpdate } from './useDependencyChanged';\n\nexport { default as useAsyncMemo, AsyncMemoResult } from './useAsyncMemo';\nexport { default as useConstant } from './useConstant';\nexport { default as useConstantCallback } from './useConstantCallback';\nexport { default as useConditionalCallback } from './useConditionalCallback';\nexport { default as useConditionalEffect } from './useConditionalEffect';\nexport { default as useConditionalLayoutEffect } from './useConditionalLayoutEffect';\nexport { default as useConditionalMemo } from './useConditionalMemo';\nexport { default as useDependencyChanged, ShouldUpdate, defaultCompare } from './useDependencyChanged';\nexport { default as useDependencyVersion } from './useDependencyVersion';\nexport { default as useForceUpdate } from './useForceUpdate';\nexport { default as useFreshLazyRef } from './useFreshLazyRef';\nexport { default as useFreshState } from './useFreshState';\nexport { default as useFullscreenElement } from './useFullscreenElement';\nexport { default as useIsomorphicEffect } from './useIsomorphicEffect';\nexport { default as useLazyRef } from './useLazyRef';\nexport { default as useMediaQuery } from './useMediaQuery';\nexport { default as useMountedState } from './useMountedState';\nexport { default as useOnlineStatus } from './useOnlineStatus';\nexport { default as usePageVisibility } from './usePageVisibility';\nexport { default as usePartialState, SetPartialState } from './usePartialState';\nexport { default as usePrefersDarkTheme } from './usePrefersDarkTheme';\nexport { default as usePrefersLightTheme } from './usePrefersLightTheme';\nexport { default as usePrefersReducedMotion } from './usePrefersReducedMotion';\nexport { default as useReadyState } from './useReadyState';\nexport { default as useReactiveObject } from './useReactiveObject';\nexport { default as useReactiveRef } from './useReactiveRef';\nexport { default as useRenderCount } from './useRenderCount';\nexport { default as useSubscription, Subscription } from './useSubscription';\nexport { default as useWindowScroll, WindowScroll } from './useWindowScroll';\nexport { default as useWindowSize, WindowSize } from './useWindowSize';\n\n/**\n * @deprecated use useConditionalEffect\n */\nexport { default as useCallbackCondition } from './useConditionalCallback';\n\n/**\n * @deprecated use useConditionalEffect\n */\nexport { default as useEffectCondition } from './useConditionalEffect';\n\n/**\n * @deprecated use useConditionalEffect\n */\nexport { default as useMemoCondition } from './useConditionalMemo';\n\n/**\n * @deprecated prefer to use ShouldUpdate<T>\n */\nexport type MemoCompare<T> = ShouldUpdate<T>;\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the 'Software'), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useEffect } from 'preact/hooks';\nimport useConditionalCallback from './useConditionalCallback';\nimport { defaultCompare, ShouldUpdate } from './useDependencyChanged';\nimport useFreshState from './useFreshState';\n\ninterface Pending {\n status: 'pending';\n}\n\ninterface Success<T> {\n status: 'success';\n value: T;\n}\n\ninterface Failure<F = any> {\n status: 'failure';\n value: F;\n}\n\nexport type AsyncMemoResult<S, F = any> =\n | Pending\n | Success<S>\n | Failure<F>;\n\nexport default function useAsyncMemo<S, R, F = any>(\n supplier: () => Promise<S>,\n dependency: R,\n shouldUpdate: ShouldUpdate<R> = defaultCompare,\n): AsyncMemoResult<S, F> {\n const [state, setState] = useFreshState<AsyncMemoResult<S, F>, R>(\n () => ({\n status: 'pending',\n }),\n dependency,\n shouldUpdate,\n );\n\n const request = useConditionalCallback(supplier, dependency, shouldUpdate);\n\n useEffect(() => {\n let mounted = true;\n\n request().then((value) => {\n if (mounted) {\n setState({\n status: 'success',\n value,\n });\n }\n }, (value) => {\n if (mounted) {\n setState({\n status: 'failure',\n value,\n });\n }\n });\n\n return () => {\n mounted = false;\n };\n }, [request, setState]);\n\n return state;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useRef } from 'preact/hooks';\nimport useDependencyChanged, { defaultCompare, ShouldUpdate } from './useDependencyChanged';\n\ntype AnyCallback = (...args: any[]) => any;\n\nexport default function useConditionalCallback<T extends AnyCallback, R>(\n supplier: T,\n dependency: R,\n shouldUpdate: ShouldUpdate<R> = defaultCompare,\n): T {\n const value = useRef(supplier);\n const dependencyChanged = useDependencyChanged(dependency, shouldUpdate);\n\n if (dependencyChanged) {\n value.current = supplier;\n }\n\n return value.current;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useDebugValue, useRef } from 'preact/hooks';\n\nexport function defaultCompare<R>(a: R, b: R): boolean {\n return !Object.is(a, b);\n}\n\nexport type ShouldUpdate<R> = (a: R, b: R) => boolean;\n\nexport default function useDependencyChanged<R>(\n dependency: R,\n shouldUpdate: ShouldUpdate<R> = defaultCompare,\n): boolean {\n const prevDeps = useRef(dependency);\n\n const result = shouldUpdate(prevDeps.current, dependency);\n\n if (result) {\n prevDeps.current = dependency;\n }\n\n useDebugValue(result);\n\n return result;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useDebugValue } from 'preact/hooks';\nimport useConstantCallback from './useConstantCallback';\nimport { defaultCompare, ShouldUpdate } from './useDependencyChanged';\nimport useForceUpdate from './useForceUpdate';\nimport useFreshLazyRef from './useFreshLazyRef';\nimport useMountedState from './useMountedState';\n\nexport type RefreshStateInitialAction<T> = () => T;\nexport type RefreshStateInitial<T> = T | RefreshStateInitialAction<T>;\n\nfunction isRefreshStateInitialAction<T>(\n initial: RefreshStateInitial<T>,\n): initial is RefreshStateInitialAction<T> {\n return typeof initial === 'function';\n}\n\nexport type RefreshStateAction<T> = (prev: T) => T;\nexport type RefreshStateSetState<T> = T | RefreshStateAction<T>;\nexport type RefreshStateDispatch<T> = (action: RefreshStateSetState<T>) => void;\n\nfunction isRefreshStateAction<T>(\n state: RefreshStateSetState<T>,\n): state is RefreshStateAction<T> {\n return typeof state === 'function';\n}\n\nexport default function useFreshState<T, R>(\n initialState: RefreshStateInitial<T>,\n dependencies: R,\n shouldUpdate: ShouldUpdate<R> = defaultCompare,\n): [T, RefreshStateDispatch<T>] {\n const stateRef = useFreshLazyRef<T, R>(\n () => (\n isRefreshStateInitialAction(initialState)\n ? initialState()\n : initialState\n ),\n dependencies,\n shouldUpdate,\n );\n\n const forceUpdate = useForceUpdate();\n const isMounted = useMountedState();\n\n const setState: RefreshStateDispatch<T> = useConstantCallback(\n (action) => {\n if (isMounted()) {\n const { current } = stateRef;\n const newState = (\n isRefreshStateAction(action)\n ? action(current)\n : action\n );\n\n if (!Object.is(current, newState)) {\n stateRef.current = newState;\n forceUpdate();\n }\n }\n },\n );\n\n useDebugValue(stateRef.current);\n\n return [stateRef.current, setState];\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useDebugValue } from 'preact/hooks';\nimport useLazyRef from './useLazyRef';\n\nexport default function useConstant<T>(supplier: () => T): T {\n const { current } = useLazyRef(supplier);\n useDebugValue(current);\n return current;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { MutableRef, useDebugValue, useRef } from 'preact/hooks';\n\n/**\n * a variant of `useRef` that accepts an initializer function instead of\n * the actual initial value.\n * @param supplier A function that supplies the initial state\n */\nexport default function useLazyRef<T>(supplier: () => T): MutableRef<T> {\n const ref = useRef<MutableRef<T> | null>();\n\n if (!ref.current) {\n ref.current = {\n current: supplier(),\n };\n }\n\n useDebugValue(ref.current);\n\n return ref.current;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport useConstant from './useConstant';\n\n/**\n * Creates a component-level constant function reference\n * @param cb a function reference that will be memoized\n */\nexport default function useConstantCallback<T extends((...args: any[]) => any)>(cb: T): T {\n return useConstant(() => cb);\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useReducer } from 'preact/hooks';\n\n/**\n * Returns a callback that force updates the component.\n */\nexport default function useForceUpdate(): () => void {\n return useReducer<never[], void>(() => [], [])[1];\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { MutableRef } from 'preact/hooks';\nimport useDependencyChanged, { defaultCompare, ShouldUpdate } from './useDependencyChanged';\nimport useLazyRef from './useLazyRef';\n\nexport default function useFreshLazyRef<T, R>(\n supplier: () => T,\n dependency: R,\n shouldUpdate: ShouldUpdate<R> = defaultCompare,\n): MutableRef<T> {\n const value = useLazyRef(supplier);\n const dependencyChanged = useDependencyChanged(dependency, shouldUpdate);\n\n if (dependencyChanged) {\n value.current = supplier();\n }\n\n return value;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useRef } from 'preact/hooks';\nimport useConstantCallback from './useConstantCallback';\nimport useIsomorphicEffect from './useIsomorphicEffect';\n\nexport default function useMountedState(): () => boolean {\n const alive = useRef(false);\n\n useIsomorphicEffect(() => {\n alive.current = true;\n return () => {\n alive.current = false;\n };\n }, []);\n\n return useConstantCallback(() => alive.current);\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\n\nimport { useEffect, useLayoutEffect } from 'preact/hooks';\nimport IS_CLIENT from './utils/is-client';\n\n// React currently throws a warning when using useLayoutEffect on the server.\n// To get around it, we can conditionally useEffect on the server (no-op) and\n// useLayoutEffect in the browser. We need useLayoutEffect to ensure the store\n// subscription callback always has the selector from the latest render commit\n// available, otherwise a store update may happen between render and the effect,\n// which may cause missed updates; we also must ensure the store subscription\n// is created synchronously, otherwise a store update may occur before the\n// subscription is created and an inconsistent state may be observed\n\nconst useIsomorphicEffect = IS_CLIENT\n ? useLayoutEffect\n : useEffect;\n\nexport default useIsomorphicEffect;\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nconst IS_CLIENT = typeof window !== 'undefined'\n && typeof window.document !== 'undefined'\n && typeof window.document.createElement !== 'undefined';\n\nexport default IS_CLIENT;\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { EffectCallback, useEffect } from 'preact/hooks';\nimport { defaultCompare, ShouldUpdate } from './useDependencyChanged';\nimport useDependencyVersion from './useDependencyVersion';\n\nexport default function useConditionalEffect<D>(\n supplier: EffectCallback,\n dependency: D,\n shouldUpdate: ShouldUpdate<D> = defaultCompare,\n): void {\n const version = useDependencyVersion(dependency, shouldUpdate);\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(supplier, [version]);\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useDebugValue, useRef } from 'preact/hooks';\nimport useDependencyChanged, { defaultCompare, ShouldUpdate } from './useDependencyChanged';\n\nexport default function useDependencyVersion<R>(\n dependency: R,\n shouldUpdate: ShouldUpdate<R> = defaultCompare,\n): number {\n const dependencyChanged = useDependencyChanged(dependency, shouldUpdate);\n const version = useRef(0);\n\n if (dependencyChanged) {\n version.current += 1;\n }\n\n useDebugValue(version.current);\n\n return version.current;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { EffectCallback, useLayoutEffect } from 'preact/hooks';\nimport { defaultCompare, ShouldUpdate } from './useDependencyChanged';\nimport useDependencyVersion from './useDependencyVersion';\n\nexport default function useConditionalLayoutEffect<D>(\n supplier: EffectCallback,\n dependency: D,\n shouldUpdate: ShouldUpdate<D> = defaultCompare,\n): void {\n const version = useDependencyVersion(dependency, shouldUpdate);\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(supplier, [version]);\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useDebugValue } from 'preact/hooks';\nimport { defaultCompare, ShouldUpdate } from './useDependencyChanged';\nimport useFreshLazyRef from './useFreshLazyRef';\n\nexport default function useConditionalMemo<T, R>(\n supplier: () => T,\n dependency: R,\n shouldUpdate: ShouldUpdate<R> = defaultCompare,\n): T {\n const value = useFreshLazyRef(\n supplier,\n dependency,\n shouldUpdate,\n ).current;\n\n useDebugValue(value);\n\n return value;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\n\nimport { useDebugValue } from 'preact/hooks';\nimport useSubscription, { Subscription } from './useSubscription';\nimport IS_CLIENT from './utils/is-client';\n\nconst SUBSCRIPTION: Subscription<Element | undefined> = {\n read: () => {\n if (IS_CLIENT && document.fullscreenElement) {\n return document.fullscreenElement;\n }\n return undefined;\n },\n subscribe: (callback) => {\n if (IS_CLIENT) {\n document.addEventListener('fullscreenchange', callback);\n\n return () => {\n document.removeEventListener('fullscreenchange', callback);\n };\n }\n return undefined;\n },\n};\n\nexport default function useFullscreenElement(): Element | undefined {\n const value = useSubscription(SUBSCRIPTION);\n\n useDebugValue(value);\n\n return value;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useDebugValue, useEffect, useState } from 'preact/hooks';\nimport { defaultCompare, ShouldUpdate } from './useDependencyChanged';\n\ntype ReadSource<T> = () => T;\ntype Subscribe = (callback: () => void) => (() => void) | undefined | void;\n\nexport interface Subscription<T> {\n read: ReadSource<T>;\n subscribe: Subscribe;\n shouldUpdate?: ShouldUpdate<T>;\n}\n\nexport default function useSubscription<T>({\n read, subscribe, shouldUpdate = defaultCompare,\n}: Subscription<T>): T {\n const [state, setState] = useState(() => ({\n read,\n subscribe,\n shouldUpdate,\n value: read(),\n }));\n\n let currentValue = state.value;\n\n if (\n state.read !== read\n || state.subscribe !== subscribe\n || state.shouldUpdate !== shouldUpdate\n ) {\n currentValue = read();\n\n setState({\n read,\n subscribe,\n shouldUpdate,\n value: currentValue,\n });\n }\n\n useDebugValue(currentValue);\n\n useEffect(() => {\n let mounted = true;\n\n const readCurrent = () => {\n if (mounted) {\n const nextValue = read();\n setState((prev) => {\n if (\n prev.read !== read\n || prev.subscribe !== subscribe\n || prev.shouldUpdate !== shouldUpdate\n ) {\n return prev;\n }\n if (!shouldUpdate(prev.value, nextValue)) {\n return prev;\n }\n return { ...prev, value: nextValue };\n });\n }\n };\n\n const unsubscribe = subscribe(readCurrent);\n\n readCurrent();\n\n return () => {\n mounted = false;\n if (unsubscribe) {\n unsubscribe();\n }\n };\n }, [read, subscribe, shouldUpdate]);\n\n return currentValue;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { useDebugValue } from 'preact/hooks';\nimport useConditionalMemo from './useConditionalMemo';\nimport useSubscription from './useSubscription';\nimport IS_CLIENT from './utils/is-client';\n\nconst MEDIA = new Map<string, MediaQueryList>();\n\nfunction getMediaMatcher(query: string): MediaQueryList {\n const media = MEDIA.get(query);\n if (media) {\n return media;\n }\n const newMedia = window.matchMedia(query);\n MEDIA.set(query, newMedia);\n return newMedia;\n}\n\nexport default function useMediaQuery(query: string): boolean {\n const media = useConditionalMemo(() => {\n if (IS_CLIENT) {\n return getMediaMatcher(query);\n }\n return undefined;\n }, query);\n\n const subscription = useConditionalMemo(() => ({\n read: () => !!media?.matches,\n subscribe: (callback: () => void) => {\n if (media) {\n media.addEventListener('change', callback);\n return () => {\n media.removeEventListener('change', callback);\n };\n }\n return undefined;\n },\n }), media);\n\n const value = useSubscription(subscription);\n\n useDebugValue(value);\n\n return value;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\n\nimport { useDebugValue } from 'preact/hooks';\nimport useSubscription, { Subscription } from './useSubscription';\nimport IS_CLIENT from './utils/is-client';\n\nconst SUBSCRIPTION: Subscription<boolean> = {\n read: () => {\n if (IS_CLIENT) {\n return navigator.onLine;\n }\n return true;\n },\n subscribe: (callback) => {\n if (IS_CLIENT) {\n window.addEventListener('online', callback, false);\n window.addEventListener('offline', callback, false);\n return () => {\n window.removeEventListener('online', callback, false);\n window.removeEventListener('offline', callback, false);\n };\n }\n return undefined;\n },\n};\n\nexport default function useOnlineStatus(): boolean {\n const value = useSubscription(SUBSCRIPTION);\n\n useDebugValue(value);\n\n return value;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\n\nimport { useDebugValue } from 'preact/hooks';\nimport useSubscription, { Subscription } from './useSubscription';\nimport IS_CLIENT from './utils/is-client';\n\nconst SUBSCRIPTION: Subscription<boolean> = {\n read: () => {\n if (IS_CLIENT) {\n return document.visibilityState === 'visible';\n }\n return true;\n },\n subscribe: (callback) => {\n if (IS_CLIENT) {\n document.addEventListener('visibilitychange', callback, false);\n return () => {\n document.removeEventListener('visibilitychange', callback, false);\n };\n }\n return undefined;\n },\n};\n\nexport default function usePageVisibility(): boolean {\n const value = useSubscription(SUBSCRIPTION);\n\n useDebugValue(value);\n\n return value;\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n *\n * @author Lyon Software Technologies, Inc.\n * @copyright Lyon Software Technologies, Inc. 2021\n */\nimport { StateUpdater, useState } from 'preact/hooks';\nimport useConstantCallback from './useConstantCallback';\n\ninterface AnyObject {\n [key: string]: any;\n}\n\ntype SetState<T> = ((prev: T) => T) | T;\n\nexport type SetPartialState<T extends AnyObject = AnyObject> = StateUpdater<T>;\n\nfunction isActionFunc<T>(action: SetState<T>): action is (prev: T) => T {\n return typeof action === 'function';\n}\n\nexport default function usePartialState<T extends AnyObject = AnyObject>(\n initialState: () => T,\n): [T, SetPartialState<T>] {\n const [state, setState] = useState(initialState);\n\n const setPartialState = useConstantCallback<SetPartialState<T>>((action) => {\n setState((current) => {\n const newValue = isActionFunc(action)\n ? action(current)\n : action;\n\n return {\n ...current,\n ...newValue,\n };\n });\n });\n\n return [state, setPartialState];\n}\n", "/**\n * @license\n * MIT License\n *\n * Copyright (c) 2021 Lyon Software Technologies, Inc.\n * Permission