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AI,CAAC,GAAG;AACjD;AAAA,QACF;AAAA,MAIF;AACA,cAAQ,SAAS,IAAI,IAAI,OAAO;AAChC,wBAAkB,gBAAgB,OAAO,GAAG,MAAM,OAAO,OAAO,IAAI;AAAA,IACtE;AACA,UAAM,SAAS,QAAQ,MAAM,SAAS,gBAAgB,qBAAqB;AAC3E,YAAQ,MAAM,SAAS,aAAa,MAAM;AACxC,aAAA;AACA,aAAO,sBAAA;AAAA,IACT,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAYA,SAAS,eAAe,OAAO,IAAI;AACT;AACtB,WAAO,MAAM,iBAAiB,gBAAA,GAAmB,QAAQ,KAAK,IAAI,IAAI;AAAA,EACxE;AAGF;AAYA,SAAS,kBAAkB,OAAO,MAAM,OAAO,OAAO,CAAA,GAAI;AACxD,MAAI,OAAO;AACT,QAAI,UAAU,QAAQ,UAAU,QAAQ;AACtC,aAAO,UAAU,OAAO,MAAM,OAAO,IAAI;AAAA,IAC3C;AACA,QAAI,UAAU,OAAO,IAAI,MAAM,QAAQ;AACrC,aAAO,aAAa,OAAO,MAAM,IAAI;AAAA,IACvC;AAAA,EACF;AACF;","names":[],"sources":["../../../../node_modules/nuxt/dist/app/composables/ssr.js","../../../../node_modules/nuxt/dist/app/composables/cookie.js"],"sourcesContent":["import { setResponseStatus as _setResponseStatus, appendHeader, getRequestHeader, getRequestHeaders, getResponseHeader, removeResponseHeader, setResponseHeader } from \"h3\";\nimport { computed, getCurrentInstance, ref } from \"vue\";\nimport { useNuxtApp } from \"../nuxt.js\";\nimport { toArray } from \"../utils.js\";\nimport { useHead } from \"./head.js\";\nexport function useRequestEvent(nuxtApp) {\n if (import.meta.client) {\n return;\n }\n nuxtApp ||= useNuxtApp();\n return nuxtApp.ssrContext?.event;\n}\nexport function useRequestHeaders(include) {\n if (import.meta.client) {\n return {};\n }\n const event = useRequestEvent();\n const _headers = event ? getRequestHeaders(event) : {};\n if (!include || !event) {\n return _headers;\n }\n const headers = /* @__PURE__ */ Object.create(null);\n for (const _key of include) {\n const key = _key.toLowerCase();\n const header = _headers[key];\n if (header) {\n headers[key] = header;\n }\n }\n return headers;\n}\nexport function useRequestHeader(header) {\n if (import.meta.client) {\n return void 0;\n }\n const event = useRequestEvent();\n return event ? getRequestHeader(event, header) : void 0;\n}\nexport function useRequestFetch() {\n if (import.meta.client) {\n return globalThis.$fetch;\n }\n return useRequestEvent()?.$fetch || globalThis.$fetch;\n}\nexport function setResponseStatus(arg1, arg2, arg3) {\n if (import.meta.client) {\n return;\n }\n if (arg1 && typeof arg1 !== \"number\") {\n return _setResponseStatus(arg1, arg2, arg3);\n }\n const event = useRequestEvent();\n if (event) {\n return _setResponseStatus(event, arg1, arg2);\n }\n}\nexport function useResponseHeader(header) {\n if (import.meta.client) {\n if (import.meta.dev) {\n return computed({\n get: () => void 0,\n set: () => console.warn(\"[nuxt] Setting response headers is not supported in the browser.\")\n });\n }\n return ref();\n }\n const event = useRequestEvent();\n return computed({\n get() {\n return getResponseHeader(event, header);\n },\n set(newValue) {\n if (!newValue) {\n return removeResponseHeader(event, header);\n }\n return setResponseHeader(event, header, newValue);\n }\n });\n}\nexport function prerenderRoutes(path) {\n if (!import.meta.server || !import.meta.prerender) {\n return;\n }\n const paths = toArray(path);\n appendHeader(useRequestEvent(), \"x-nitro-prerender\", paths.map((p) => encodeURIComponent(p)).join(\", \"));\n}\nconst PREHYDRATE_ATTR_KEY = \"data-prehydrate-id\";\nexport function onPrehydrate(callback, key) {\n if (import.meta.client) {\n return;\n }\n if (typeof callback !== \"string\") {\n throw new TypeError(\"[nuxt] To transform a callback into a string, `onPrehydrate` must be processed by the Nuxt build pipeline. If it is called in a third-party library, make sure to add the library to `build.transpile`.\");\n }\n const vm = getCurrentInstance();\n if (vm && key) {\n vm.attrs[PREHYDRATE_ATTR_KEY] ||= \"\";\n key = \":\" + key + \":\";\n if (!vm.attrs[PREHYDRATE_ATTR_KEY].includes(key)) {\n vm.attrs[PREHYDRATE_ATTR_KEY] += key;\n }\n }\n const code = vm && key ? `document.querySelectorAll('[${PREHYDRATE_ATTR_KEY}*=${JSON.stringify(key)}]').forEach` + callback : callback + \"()\";\n useHead({\n script: [{\n key: vm && key ? key : void 0,\n tagPosition: \"bodyClose\",\n tagPriority: \"critical\",\n innerHTML: code\n }]\n });\n return vm && key ? vm.attrs[PREHYDRATE_ATTR_KEY] : void 0;\n}\n","import { customRef, getCurrentScope, nextTick, onScopeDispose, ref, watch } from \"vue\";\nimport { parse, serialize } from \"cookie-es\";\nimport { deleteCookie, getCookie, getRequestHeader, setCookie } from \"h3\";\nimport destr from \"destr\";\nimport { isEqual } from \"ohash\";\nimport { klona } from \"klona\";\nimport { useNuxtApp } from \"../nuxt.js\";\nimport { useRequestEvent } from \"./ssr.js\";\nimport { cookieStore } from \"#build/nuxt.config.mjs\";\nconst CookieDefaults = {\n path: \"/\",\n watch: true,\n decode: (val) => {\n const decoded = decodeURIComponent(val);\n const parsed = destr(decoded);\n if (typeof parsed === \"number\" && (!Number.isFinite(parsed) || String(parsed) !== decoded)) {\n return decoded;\n }\n return parsed;\n },\n encode: (val) => encodeURIComponent(typeof val === \"string\" ? val : JSON.stringify(val))\n};\nconst store = import.meta.client && cookieStore ? globalThis.cookieStore : void 0;\nexport function useCookie(name, _opts) {\n const opts = { ...CookieDefaults, ..._opts };\n opts.filter ??= (key) => key === name;\n const cookies = readRawCookies(opts) || {};\n let delay;\n if (opts.maxAge !== void 0) {\n delay = opts.maxAge * 1e3;\n } else if (opts.expires) {\n delay = opts.expires.getTime() - Date.now();\n }\n const hasExpired = delay !== void 0 && delay <= 0;\n const shouldSetInitialClientCookie = import.meta.client && (hasExpired || cookies[name] === void 0 || cookies[name] === null);\n const cookieValue = klona(hasExpired ? void 0 : cookies[name] ?? opts.default?.());\n const cookie = import.meta.client && delay && !hasExpired ? cookieRef(cookieValue, delay, opts.watch && opts.watch !== \"shallow\") : ref(cookieValue);\n if (import.meta.dev && hasExpired) {\n console.warn(`[nuxt] not setting cookie \\`${name}\\` as it has already expired.`);\n }\n if (import.meta.client) {\n let channel = null;\n try {\n if (!store && typeof BroadcastChannel !== \"undefined\") {\n channel = new BroadcastChannel(`nuxt:cookies:${name}`);\n }\n } catch {\n }\n const callback = (force = false) => {\n if (!force) {\n if (opts.readonly || isEqual(cookie.value, cookies[name])) {\n return;\n }\n }\n writeClientCookie(name, cookie.value, opts);\n cookies[name] = klona(cookie.value);\n channel?.postMessage({ value: opts.encode(cookie.value) });\n };\n const handleChange = (data) => {\n const value = data.refresh ? readRawCookies(opts)?.[name] : opts.decode(data.value);\n watchPaused = true;\n cookie.value = value;\n cookies[name] = klona(value);\n nextTick(() => {\n watchPaused = false;\n });\n };\n let watchPaused = false;\n const hasScope = !!getCurrentScope();\n if (hasScope) {\n onScopeDispose(() => {\n watchPaused = true;\n callback();\n channel?.close();\n });\n }\n if (store) {\n const changeHandler = (event) => {\n const changedCookie = event.changed.find((c) => c.name === name);\n const removedCookie = event.deleted.find((c) => c.name === name);\n if (changedCookie) {\n handleChange({ value: changedCookie.value });\n }\n if (removedCookie) {\n handleChange({ value: null });\n }\n };\n store.addEventListener(\"change\", changeHandler);\n if (hasScope) {\n onScopeDispose(() => store.removeEventListener(\"change\", changeHandler));\n }\n } else if (channel) {\n channel.onmessage = ({ data }) => handleChange(data);\n }\n if (opts.watch) {\n watch(\n cookie,\n () => {\n if (watchPaused) {\n return;\n }\n callback();\n },\n { deep: opts.watch !== \"shallow\" }\n );\n }\n if (shouldSetInitialClientCookie) {\n callback(shouldSetInitialClientCookie);\n }\n } else if (import.meta.server) {\n const nuxtApp = useNuxtApp();\n const writeFinalCookieValue = () => {\n if (opts.readonly || isEqual(cookie.value, cookies[name])) {\n return;\n }\n nuxtApp._cookies ||= {};\n if (name in nuxtApp._cookies) {\n if (isEqual(cookie.value, nuxtApp._cookies[name])) {\n return;\n }\n if (import.meta.dev) {\n console.warn(`[nuxt] cookie \\`${name}\\` was previously set to \\`${opts.encode(nuxtApp._cookies[name])}\\` and is being overridden to \\`${opts.encode(cookie.value)}\\`. This may cause unexpected issues.`);\n }\n }\n nuxtApp._cookies[name] = cookie.value;\n writeServerCookie(useRequestEvent(nuxtApp), name, cookie.value, opts);\n };\n const unhook = nuxtApp.hooks.hookOnce(\"app:rendered\", writeFinalCookieValue);\n nuxtApp.hooks.hookOnce(\"app:error\", () => {\n unhook();\n return writeFinalCookieValue();\n });\n }\n return cookie;\n}\nexport function refreshCookie(name) {\n if (import.meta.server || store || typeof BroadcastChannel === \"undefined\") {\n return;\n }\n try {\n const channel = new BroadcastChannel(`nuxt:cookies:${name}`);\n channel.postMessage({ refresh: true });\n channel.close();\n } catch {\n }\n}\nfunction readRawCookies(opts = {}) {\n if (import.meta.server) {\n return parse(getRequestHeader(useRequestEvent(), \"cookie\") || \"\", opts);\n } else if (import.meta.client) {\n return parse(document.cookie, opts);\n }\n}\nfunction serializeCookie(name, value, opts = {}) {\n if (value === null || value === void 0) {\n return serialize(name, value, { ...opts, maxAge: -1 });\n }\n return serialize(name, value, opts);\n}\nfunction writeClientCookie(name, value, opts = {}) {\n if (import.meta.client) {\n document.cookie = serializeCookie(name, value, opts);\n }\n}\nfunction writeServerCookie(event, name, value, opts = {}) {\n if (event) {\n if (value !== null && value !== void 0) {\n return setCookie(event, name, value, opts);\n }\n if (getCookie(event, name) !== void 0) {\n return deleteCookie(event, name, opts);\n }\n }\n}\nconst MAX_TIMEOUT_DELAY = 2147483647;\nfunction cookieRef(value, delay, shouldWatch) {\n let timeout;\n let unsubscribe;\n let elapsed = 0;\n const internalRef = shouldWatch ? ref(value) : { value };\n if (getCurrentScope()) {\n onScopeDispose(() => {\n unsubscribe?.();\n clearTimeout(timeout);\n });\n }\n return customRef((track, trigger) => {\n if (shouldWatch) {\n unsubscribe = watch(internalRef, trigger);\n }\n function scheduleTimeout() {\n const timeRemaining = delay - elapsed;\n const timeoutLength = timeRemaining < MAX_TIMEOUT_DELAY ? timeRemaining : MAX_TIMEOUT_DELAY;\n timeout = setTimeout(() => {\n elapsed += timeoutLength;\n if (elapsed < delay) {\n return scheduleTimeout();\n }\n internalRef.value = void 0;\n trigger();\n }, timeoutLength);\n }\n function createExpirationTimeout() {\n elapsed = 0;\n clearTimeout(timeout);\n scheduleTimeout();\n }\n return {\n get() {\n track();\n return internalRef.value;\n },\n set(newValue) {\n createExpirationTimeout();\n internalRef.value = newValue;\n trigger();\n }\n };\n });\n}\n"],"version":3} |