{
  "version": 3,
  "sources": ["../../../../../node_modules/use-subscription/cjs/use-subscription.development.js", "../../../../../node_modules/use-subscription/index.js", "../../src/web/lib/useLocalStorage.ts"],
  "sourcesContent": ["/**\n * @license React\n * use-subscription.development.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n'use strict';\n\nif (process.env.NODE_ENV !== \"production\") {\n  (function() {\n\n          'use strict';\n\n/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===\n    'function'\n) {\n  __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());\n}\n          var shim = require('use-sync-external-store/shim');\n\n//\n// In order to avoid removing and re-adding subscriptions each time this hook is called,\n// the parameters passed to this hook should be memoized in some way\u2013\n// either by wrapping the entire params object with useMemo()\n// or by wrapping the individual callbacks with useCallback().\n\nfunction useSubscription(_ref) {\n  var getCurrentValue = _ref.getCurrentValue,\n      subscribe = _ref.subscribe;\n  return shim.useSyncExternalStore(subscribe, getCurrentValue);\n}\n\nexports.useSubscription = useSubscription;\n          /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===\n    'function'\n) {\n  __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());\n}\n        \n  })();\n}\n", "'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n  module.exports = require('./cjs/use-subscription.production.min.js');\n} else {\n  module.exports = require('./cjs/use-subscription.development.js');\n}\n", "import { useCallback, useMemo } from \"react\"\nimport type { Subscription } from \"use-subscription\"\nimport { useSubscription } from \"use-subscription\"\nimport { isFunction } from \"utils/typeChecks.ts\"\n\ntype Cache = Map<string, unknown>\n\nconst valueCache: Cache = new Map()\nconst listeners = new Set<(key: string) => void>()\n\nwindow.addEventListener(\"storage\", event => {\n\tif (event.storageArea !== localStorage || event.key === null) {\n\t\treturn\n\t}\n\n\ttry {\n\t\tif (event.newValue === null) {\n\t\t\tvalueCache.set(event.key, null)\n\t\t} else if (event.oldValue !== event.newValue) {\n\t\t\tconst value = JSON.parse(event.newValue)\n\t\t\tvalueCache.set(event.key, value)\n\t\t}\n\n\t\tfor (const notify of listeners) {\n\t\t\tnotify(event.key)\n\t\t}\n\t} catch {\n\t\t// Ignore error\n\t}\n})\n\n/**\n * Reads the current cached/localStorage value without subscribing React to updates.\n *\n * Only use this in synchronous callbacks where the value is consumed immediately.\n * Do not use it for render-time data flow or memoized reactive state, because it will\n * not cause a re-render when the underlying localStorage value changes.\n */\nexport function getLocalStorageValue<Value>(key: string): Value | null {\n\tif (valueCache.has(key)) {\n\t\treturn (valueCache.get(key) as Value) ?? null\n\t}\n\n\tconst serialized = localStorage.getItem(key)\n\n\tif (serialized) {\n\t\ttry {\n\t\t\tconst value = JSON.parse(serialized) as Value\n\t\t\tvalueCache.set(key, value)\n\t\t\treturn value\n\t\t} catch {\n\t\t\t// Fall through\n\t\t}\n\t}\n\n\treturn null\n}\n\n/**\n * Sets the value within local storage and makes sure all `useLocalStorage` hooks are updated.\n */\nexport function setLocalStorageAndUpdateListeners(key: string, value: unknown) {\n\t// Remove the value if it's null\n\tif (value === null) {\n\t\tvalueCache.set(key, null)\n\t\tlocalStorage.removeItem(key)\n\t} else {\n\t\tvalueCache.set(key, value)\n\t\tconst serialized = JSON.stringify(value)\n\t\tlocalStorage.setItem(key, serialized)\n\t}\n\n\tfor (const notify of listeners) {\n\t\tnotify(key)\n\t}\n}\n\n// This hook will not update if you call localStorage.setItem() directly, because the native storage\n// event only triggers when the update is done in another browser window. We would probably need to\n// monkey patch the localStorage object to do that.\nexport function useLocalStorage<Value>(key: string, defaultValue: Value) {\n\tconst subscription = useMemo<Subscription<Value | null>>(() => {\n\t\tfunction subscribe(callback: () => void) {\n\t\t\t// Only notify the callback when the right key is updated.\n\t\t\tfunction listener(updatedKey: string) {\n\t\t\t\tif (updatedKey === key) {\n\t\t\t\t\tcallback()\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlisteners.add(listener)\n\t\t\treturn () => listeners.delete(listener)\n\t\t}\n\n\t\treturn {\n\t\t\tgetCurrentValue: () => getLocalStorageValue<Value>(key),\n\t\t\tsubscribe,\n\t\t}\n\t}, [key])\n\n\t// Fallback to the defaultValue if the value in the localStorage is null.\n\tconst localStorageValue: Value = useSubscription(subscription) ?? defaultValue\n\n\tconst setValue = useCallback(\n\t\t(value: ((currentValue: Value) => Value) | Value | null) => {\n\t\t\ttry {\n\t\t\t\tif (isFunction(value)) {\n\t\t\t\t\tconst previousValue = subscription.getCurrentValue() ?? defaultValue\n\t\t\t\t\tconst newValue = value(previousValue)\n\t\t\t\t\tsetLocalStorageAndUpdateListeners(key, newValue)\n\t\t\t\t} else {\n\t\t\t\t\tsetLocalStorageAndUpdateListeners(key, value)\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Ignore error\n\t\t\t}\n\t\t},\n\t\t[key, defaultValue, subscription.getCurrentValue],\n\t)\n\n\treturn [localStorageValue, setValue] as const\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAYA,QAAI,MAAuC;AACzC,OAAC,WAAW;AAEJ;AAGV,YACE,OAAO,mCAAmC,eAC1C,OAAO,+BAA+B,gCACpC,YACF;AACA,yCAA+B,4BAA4B,IAAI,MAAM,CAAC;AAAA,QACxE;AACU,YAAI,OAAO;AAQrB,iBAASA,iBAAgB,MAAM;AAC7B,cAAI,kBAAkB,KAAK,iBACvB,YAAY,KAAK;AACrB,iBAAO,KAAK,qBAAqB,WAAW,eAAe;AAAA,QAC7D;AAEA,gBAAQ,kBAAkBA;AAE1B,YACE,OAAO,mCA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