{"version":3,"sources":["cookies.ts"],"sourcesContent":["import { getCookies as getHeaderCookies, setCookie as setHeaderCookie } from \"../lib/cookie/cookie.ts\";\n\n// @ts-ignore\n// from \"datex-core-legacy/utils/constants.ts\"\nconst is_worker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);\nexport const client_type = is_worker ? 'worker' : (\"Deno\" in globalThis && !(globalThis.Deno as any).isPolyfill ? 'deno' : 'browser')\n\nconst portPrefix = client_type == \"browser\" ? globalThis.location.port : undefined;\n\nexport const UIX_COOKIE = {\n\tendpoint: \"datex-endpoint\",\n\tendpointValidation: \"datex-endpoint-validation\",\n\tendpointNonce: \"datex-endpoint-nonce\",\n\n\tsession: \"uix-session\",\n\tunverifiedSession: \"uix-session-unverified\",\n\tlanguage: \"uix-language\",\n\tthemeDark: \"uix-theme-dark\",\n\tthemeLight: \"uix-theme-light\",\n\tcolorMode: \"uix-color-mode\",\n\tinitialColorMode: \"uix-initial-color-mode\",\n\tsharedData: \"uix-shared-data\"\n} as const;\nexport type UIX_COOKIE = typeof UIX_COOKIE[keyof typeof UIX_COOKIE];\n\nconst browserIsSafariLocalhost = (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) && (\n\tglobalThis.location?.hostname == \"localhost\" ||\n\tglobalThis.location?.hostname.startsWith(\"127.\") ||\n\tglobalThis.location?.hostname.startsWith(\"192.\")\n);\n\nexport function deleteCookie(name: UIX_COOKIE | string, headers?: Headers, port?:string, isSafariLocalhost = false) {\n\n\tport ??= portPrefix\n\tif (port) name += \"/\" + port;\n\n\tif (headers) {\n\t\tsetHeaderCookie!(headers, {\n\t\t\tname,\n\t\t\tvalue: \"\",\n\t\t\tsameSite: \"None\",\n\t\t\tsecure: !isSafariLocalhost,\n\t\t\tpath: '/',\n\t\t\texpires: new Date(0)\n\t\t})\n\t}\n    else document.cookie = name +'=; Path=/; SameSite=None; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' + (browserIsSafariLocalhost ? \"\" :\" Secure;\")\n}\n\nexport function setCookie(name: UIX_COOKIE | string, value:string, expDays?:number, headers?: Headers, port?:string, isSafariLocalhost = false) {\n\n\tport ??= portPrefix\n\tif (port) name += \"/\" + port;\n\n\tvalue = encodeURIComponent(value)\n\n\tlet expiryDate = new Date(\"Fri, 31 Dec 9999 21:10:10 GMT\");\n\tif (expDays) {\n\t\texpiryDate = new Date();\n\t\texpiryDate.setTime(expiryDate.getTime() + (expDays * 24 * 60 * 60 * 1000));\n\t}\n\n\tif (headers) {\n\t\tsetHeaderCookie!(headers, {\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tsameSite: \"None\",\n\t\t\tsecure: !isSafariLocalhost,\n\t\t\tpath: '/',\n\t\t\texpires: expiryDate\n\t\t})\n\t}\n\n\telse {\n\t\tconst expires = \"expires=\" + expiryDate.toUTCString() + \";\";\n\t\t// SameSite none leads to errors (in combination with Secure/Not secure)\n\t\tdocument.cookie = name + \"=\" + value + \"; \" + expires + \" path=/; SameSite=None;\" + (browserIsSafariLocalhost ? \"\" :\" Secure;\")\n\t}\n\t\n}\n\nexport function getCookie(name: UIX_COOKIE | string, headers?: Headers, port?:string) {\n\n\tport ??= portPrefix\n\tif (port) name += \"/\" + port;\n\n\tif (headers) {\n\t\tconst cookie = getHeaderCookies!(headers)?.[name];\n\t\treturn cookie ? decodeURIComponent(cookie) : null;\n\t}\n\n\telse {\n\t\tconst cname = name + \"=\";\n\t\tconst cookies = decodeURIComponent(document.cookie);\n\t\tconst cookieArray = cookies.split('; ');\n\t\tlet res: string|undefined;\n\t\tcookieArray.forEach(val => {\n\t\t\tif (val.indexOf(cname) === 0) res = val.substring(cname.length);\n\t\t})\n\t\treturn res;\n\t}\n}"],"names":["getCookies","getHeaderCookies","setCookie","setHeaderCookie","is_worker","WorkerGlobalScope","self","client_type","globalThis","Deno","isPolyfill","portPrefix","location","port","undefined","UIX_COOKIE","endpoint","endpointValidation","endpointNonce","session","unverifiedSession","language","themeDark","themeLight","colorMode","initialColorMode","sharedData","browserIsSafariLocalhost","test","navigator","userAgent","hostname","startsWith","deleteCookie","name","headers","isSafariLocalhost","value","sameSite","secure","path","expires","Date","document","cookie","expDays","encodeURIComponent","expiryDate","setTime","getTime","toUTCString","getCookie","decodeURIComponent","res","cname","cookieArray","cookies","split","forEach","val","indexOf","substring","length"],"mappings":"AAAA,SAASA,cAAcC,gBAAgB,EAAEC,aAAaC,eAAe,QAAQ,0BAA0B;AAIvG,IAAMC,YAAa,AAA6B,eAA7B,OAAOC,qBAAqCC,gBAAgBD;AAC/E,OAAO,MAAME,cAAcH,YAAY,WAAY,UAAUI,cAAc,CAAC,AAACA,WAAWC,IAAI,CAASC,UAAU,GAAG,SAAS,UAAU;AAErI,IAAMC,aAAaJ,AAAe,aAAfA,cAA2BC,WAAWI,QAAQ,CAACC,IAAI,GAAGC,KAAAA;AAEzE,OAAO,MAAMC,aAAa;IACzBC,UAAU;IACVC,oBAAoB;IACpBC,eAAe;IAEfC,SAAS;IACTC,mBAAmB;IACnBC,UAAU;IACVC,WAAW;IACXC,YAAY;IACZC,WAAW;IACXC,kBAAkB;IAClBC,YAAY;AACb,EAAW;AAGX,IAAMC,2BAA2B,AAAC,iCAAiCC,IAAI,CAACC,UAAUC,SAAS,KAC1FtB,CAAAA,WAAWI,QAAQ,EAAEmB,YAAY,eACjCvB,WAAWI,QAAQ,EAAEmB,SAASC,WAAW,WACzCxB,WAAWI,QAAQ,EAAEmB,SAASC,WAAW,OAAM;AAGhD,OAAO,SAASC,aAAaC,IAAyB,EAAEC,OAAiB,EAAEtB,IAAY,EAAEuB,oBAAoB,CAAA,CAAK;IAEjHvB,CAAAA,SAASF,UAAS,KACRuB,CAAAA,QAAQ,MAAMrB,IAAG,GAEvBsB,UACHhC,gBAAiBgC,SAAS;QACzBD;QACAG,OAAO;QACPC,UAAU;QACVC,QAAQ,CAACH;QACTI,MAAM;QACNC,SAAS,IAAIC,KAAK;IACnB,KAEOC,SAASC,MAAM,GAAGV,OAAM,qEAAsEP,CAAA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