var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => { __accessCheck(obj, member, "read from private field"); return getter ? getter.call(obj) : member.get(obj); }; var __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; var __privateSet = (obj, member, value, setter) => { __accessCheck(obj, member, "write to private field"); setter ? setter.call(obj, value) : member.set(obj, value); return value; }; var _map; import { c as create_ssr_component, s as setContext, v as validate_component, m as missing_component } from "./chunks/index-c7a03ab5.js"; import cookie from "cookie"; import { v4 } from "@lukeed/uuid"; function get_single_valued_header(headers, key) { const value = headers[key]; if (Array.isArray(value)) { if (value.length === 0) { return void 0; } if (value.length > 1) { throw new Error(`Multiple headers provided for ${key}. Multiple may be provided only for set-cookie`); } return value[0]; } return value; } function lowercase_keys(obj) { const clone = {}; for (const key in obj) { clone[key.toLowerCase()] = obj[key]; } return clone; } function decode_params(params) { for (const key in params) { params[key] = params[key].replace(/%23/g, "#").replace(/%3[Bb]/g, ";").replace(/%2[Cc]/g, ",").replace(/%2[Ff]/g, "/").replace(/%3[Ff]/g, "?").replace(/%3[Aa]/g, ":").replace(/%40/g, "@").replace(/%26/g, "&").replace(/%3[Dd]/g, "=").replace(/%2[Bb]/g, "+").replace(/%24/g, "$"); } return params; } function error(body) { return { status: 500, body, headers: {} }; } function is_string(s2) { return typeof s2 === "string" || s2 instanceof String; } const text_types = new Set([ "application/xml", "application/json", "application/x-www-form-urlencoded", "multipart/form-data" ]); function is_text(content_type) { if (!content_type) return true; const type = content_type.split(";")[0].toLowerCase(); return type.startsWith("text/") || type.endsWith("+xml") || text_types.has(type); } async function render_endpoint(request, route, match) { const mod = await route.load(); const handler = mod[request.method.toLowerCase().replace("delete", "del")]; if (!handler) { return; } request.params = route.params ? decode_params(route.params(match)) : {}; const response = await handler(request); const preface = `Invalid response from route ${request.url.pathname}`; if (!response) { return; } if (typeof response !== "object") { return error(`${preface}: expected an object, got ${typeof response}`); } let { status = 200, body, headers = {} } = response; headers = lowercase_keys(headers); const type = get_single_valued_header(headers, "content-type"); if (!is_text(type) && !(body instanceof Uint8Array || is_string(body))) { return error(`${preface}: body must be an instance of string or Uint8Array if content-type is not a supported textual content-type`); } let normalized_body; if ((typeof body === "object" || typeof body === "undefined") && !(body instanceof Uint8Array) && (!type || type.startsWith("application/json"))) { headers = { ...headers, "content-type": "application/json; charset=utf-8" }; normalized_body = JSON.stringify(typeof body === "undefined" ? {} : body); } else { normalized_body = body; } return { status, body: normalized_body, headers }; } var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"; var unsafeChars = /[<>\b\f\n\r\t\0\u2028\u2029]/g; var reserved = /^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/; var escaped = { "<": "\\u003C", ">": "\\u003E", "/": "\\u002F", "\\": "\\\\", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", " ": "\\t", "\0": "\\0", "\u2028": "\\u2028", "\u2029": "\\u2029" }; var objectProtoOwnPropertyNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0"); function devalue(value) { var counts = new Map(); function walk(thing) { if (typeof thing === "function") { throw new Error("Cannot stringify a function"); } if (counts.has(thing)) { counts.set(thing, counts.get(thing) + 1); return; } counts.set(thing, 1); if (!isPrimitive(thing)) { var type = getType(thing); switch (type) { case "Number": case "String": case "Boolean": case "Date": case "RegExp": return; case "Array": thing.forEach(walk); break; case "Set": case "Map": Array.from(thing).forEach(walk); break; default: var proto = Object.getPrototypeOf(thing); if (proto !== Object.prototype && proto !== null && Object.getOwnPropertyNames(proto).sort().join("\0") !== objectProtoOwnPropertyNames) { throw new Error("Cannot stringify arbitrary non-POJOs"); } if (Object.getOwnPropertySymbols(thing).length > 0) { throw new Error("Cannot stringify POJOs with symbolic keys"); } Object.keys(thing).forEach(function(key) { return walk(thing[key]); }); } } } walk(value); var names = new Map(); Array.from(counts).filter(function(entry) { return entry[1] > 1; }).sort(function(a, b) { return b[1] - a[1]; }).forEach(function(entry, i) { names.set(entry[0], getName(i)); }); function stringify(thing) { if (names.has(thing)) { return names.get(thing); } if (isPrimitive(thing)) { return stringifyPrimitive(thing); } var type = getType(thing); switch (type) { case "Number": case "String": case "Boolean": return "Object(" + stringify(thing.valueOf()) + ")"; case "RegExp": return "new RegExp(" + stringifyString(thing.source) + ', "' + thing.flags + '")'; case "Date": return "new Date(" + thing.getTime() + ")"; case "Array": var members = thing.map(function(v, i) { return i in thing ? stringify(v) : ""; }); var tail = thing.length === 0 || thing.length - 1 in thing ? "" : ","; return "[" + members.join(",") + tail + "]"; case "Set": case "Map": return "new " + type + "([" + Array.from(thing).map(stringify).join(",") + "])"; default: var obj = "{" + Object.keys(thing).map(function(key) { return safeKey(key) + ":" + stringify(thing[key]); }).join(",") + "}"; var proto = Object.getPrototypeOf(thing); if (proto === null) { return Object.keys(thing).length > 0 ? "Object.assign(Object.create(null)," + obj + ")" : "Object.create(null)"; } return obj; } } var str = stringify(value); if (names.size) { var params_1 = []; var statements_1 = []; var values_1 = []; names.forEach(function(name, thing) { params_1.push(name); if (isPrimitive(thing)) { values_1.push(stringifyPrimitive(thing)); return; } var type = getType(thing); switch (type) { case "Number": case "String": case "Boolean": values_1.push("Object(" + stringify(thing.valueOf()) + ")"); break; case "RegExp": values_1.push(thing.toString()); break; case "Date": values_1.push("new Date(" + thing.getTime() + ")"); break; case "Array": values_1.push("Array(" + thing.length + ")"); thing.forEach(function(v, i) { statements_1.push(name + "[" + i + "]=" + stringify(v)); }); break; case "Set": values_1.push("new Set"); statements_1.push(name + "." + Array.from(thing).map(function(v) { return "add(" + stringify(v) + ")"; }).join(".")); break; case "Map": values_1.push("new Map"); statements_1.push(name + "." + Array.from(thing).map(function(_a) { var k = _a[0], v = _a[1]; return "set(" + stringify(k) + ", " + stringify(v) + ")"; }).join(".")); break; default: values_1.push(Object.getPrototypeOf(thing) === null ? "Object.create(null)" : "{}"); Object.keys(thing).forEach(function(key) { statements_1.push("" + name + safeProp(key) + "=" + stringify(thing[key])); }); } }); statements_1.push("return " + str); return "(function(" + params_1.join(",") + "){" + statements_1.join(";") + "}(" + values_1.join(",") + "))"; } else { return str; } } function getName(num) { var name = ""; do { name = chars[num % chars.length] + name; num = ~~(num / chars.length) - 1; } while (num >= 0); return reserved.test(name) ? name + "_" : name; } function isPrimitive(thing) { return Object(thing) !== thing; } function stringifyPrimitive(thing) { if (typeof thing === "string") return stringifyString(thing); if (thing === void 0) return "void 0"; if (thing === 0 && 1 / thing < 0) return "-0"; var str = String(thing); if (typeof thing === "number") return str.replace(/^(-)?0\./, "$1."); return str; } function getType(thing) { return Object.prototype.toString.call(thing).slice(8, -1); } function escapeUnsafeChar(c) { return escaped[c] || c; } function escapeUnsafeChars(str) { return str.replace(unsafeChars, escapeUnsafeChar); } function safeKey(key) { return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escapeUnsafeChars(JSON.stringify(key)); } function safeProp(key) { return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? "." + key : "[" + escapeUnsafeChars(JSON.stringify(key)) + "]"; } function stringifyString(str) { var result = '"'; for (var i = 0; i < str.length; i += 1) { var char = str.charAt(i); var code = char.charCodeAt(0); if (char === '"') { result += '\\"'; } else if (char in escaped) { result += escaped[char]; } else if (code >= 55296 && code <= 57343) { var next = str.charCodeAt(i + 1); if (code <= 56319 && (next >= 56320 && next <= 57343)) { result += char + str[++i]; } else { result += "\\u" + code.toString(16).toUpperCase(); } } else { result += char; } } result += '"'; return result; } function noop() { } function safe_not_equal(a, b) { return a != a ? b == b : a !== b || (a && typeof a === "object" || typeof a === "function"); } Promise.resolve(); const subscriber_queue = []; function writable(value, start = noop) { let stop; const subscribers = new Set(); function set(new_value) { if (safe_not_equal(value, new_value)) { value = new_value; if (stop) { const run_queue = !subscriber_queue.length; for (const subscriber of subscribers) { subscriber[1](); subscriber_queue.push(subscriber, value); } if (run_queue) { for (let i = 0; i < subscriber_queue.length; i += 2) { subscriber_queue[i][0](subscriber_queue[i + 1]); } subscriber_queue.length = 0; } } } } function update(fn) { set(fn(value)); } function subscribe(run, invalidate = noop) { const subscriber = [run, invalidate]; subscribers.add(subscriber); if (subscribers.size === 1) { stop = start(set) || noop; } run(value); return () => { subscribers.delete(subscriber); if (subscribers.size === 0) { stop(); stop = null; } }; } return { set, update, subscribe }; } function coalesce_to_error(err) { return err instanceof Error || err && err.name && err.message ? err : new Error(JSON.stringify(err)); } function hash(value) { let hash2 = 5381; let i = value.length; if (typeof value === "string") { while (i) hash2 = hash2 * 33 ^ value.charCodeAt(--i); } else { while (i) hash2 = hash2 * 33 ^ value[--i]; } return (hash2 >>> 0).toString(36); } const escape_json_string_in_html_dict = { '"': '\\"', "<": "\\u003C", ">": "\\u003E", "/": "\\u002F", "\\": "\\\\", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", " ": "\\t", "\0": "\\0", "\u2028": "\\u2028", "\u2029": "\\u2029" }; function escape_json_string_in_html(str) { return escape(str, escape_json_string_in_html_dict, (code) => `\\u${code.toString(16).toUpperCase()}`); } const escape_html_attr_dict = { "<": "<", ">": ">", '"': """ }; function escape_html_attr(str) { return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"'; } function escape(str, dict, unicode_encoder) { let result = ""; for (let i = 0; i < str.length; i += 1) { const char = str.charAt(i); const code = char.charCodeAt(0); if (char in dict) { result += dict[char]; } else if (code >= 55296 && code <= 57343) { const next = str.charCodeAt(i + 1); if (code <= 56319 && next >= 56320 && next <= 57343) { result += char + str[++i]; } else { result += unicode_encoder(code); } } else { result += char; } } return result; } const s = JSON.stringify; async function render_response({ branch, options, $session, page_config, status, error: error2, url, params }) { const css2 = new Set(options.manifest._.entry.css); const js = new Set(options.manifest._.entry.js); const styles = new Set(); const serialized_data = []; let rendered; let is_private = false; let maxage; if (error2) { error2.stack = options.get_stack(error2); } if (page_config.ssr) { branch.forEach(({ node, loaded, fetched, uses_credentials }) => { if (node.css) node.css.forEach((url2) => css2.add(url2)); if (node.js) node.js.forEach((url2) => js.add(url2)); if (node.styles) node.styles.forEach((content) => styles.add(content)); if (fetched && page_config.hydrate) serialized_data.push(...fetched); if (uses_credentials) is_private = true; maxage = loaded.maxage; }); const session = writable($session); const props = { stores: { page: writable(null), navigating: writable(null), session }, page: { url, params, status, error: error2 }, components: branch.map(({ node }) => node.module.default) }; const print_error = (property, replacement) => { Object.defineProperty(props.page, property, { get: () => { throw new Error(`$page.${property} has been replaced by $page.url.${replacement}`); } }); }; print_error("origin", "origin"); print_error("path", "pathname"); print_error("query", "searchParams"); for (let i = 0; i < branch.length; i += 1) { props[`props_${i}`] = await branch[i].loaded.props; } let session_tracking_active = false; const unsubscribe = session.subscribe(() => { if (session_tracking_active) is_private = true; }); session_tracking_active = true; try { rendered = options.root.render(props); } finally { unsubscribe(); } } else { rendered = { head: "", html: "", css: { code: "", map: null } }; } const include_js = page_config.router || page_config.hydrate; if (!include_js) js.clear(); const links = options.amp ? styles.size > 0 || rendered.css.code.length > 0 ? `` : "" : [ ...Array.from(css2).map((dep) => ``), ...Array.from(js).map((dep) => ``) ].join("\n "); let init = ""; if (options.amp) { init = `