Spaces:
Runtime error
Runtime error
| import { c as create_ssr_component, s as setContext, v as validate_component, m as missing_component } from "./chunks/index-445fd704.js"; | |
| import { s as set_paths, b as base, a as assets } from "./chunks/paths-396f020f.js"; | |
| function afterUpdate() { | |
| } | |
| const Root = create_ssr_component(($$result, $$props, $$bindings, slots) => { | |
| let { stores } = $$props; | |
| let { page } = $$props; | |
| let { components } = $$props; | |
| let { props_0 = null } = $$props; | |
| let { props_1 = null } = $$props; | |
| let { props_2 = null } = $$props; | |
| setContext("__svelte__", stores); | |
| afterUpdate(stores.page.notify); | |
| if ($$props.stores === void 0 && $$bindings.stores && stores !== void 0) | |
| $$bindings.stores(stores); | |
| if ($$props.page === void 0 && $$bindings.page && page !== void 0) | |
| $$bindings.page(page); | |
| if ($$props.components === void 0 && $$bindings.components && components !== void 0) | |
| $$bindings.components(components); | |
| if ($$props.props_0 === void 0 && $$bindings.props_0 && props_0 !== void 0) | |
| $$bindings.props_0(props_0); | |
| if ($$props.props_1 === void 0 && $$bindings.props_1 && props_1 !== void 0) | |
| $$bindings.props_1(props_1); | |
| if ($$props.props_2 === void 0 && $$bindings.props_2 && props_2 !== void 0) | |
| $$bindings.props_2(props_2); | |
| { | |
| stores.page.set(page); | |
| } | |
| return ` | |
| ${components[1] ? `${validate_component(components[0] || missing_component, "svelte:component").$$render($$result, Object.assign(props_0 || {}), {}, { | |
| default: () => { | |
| return `${components[2] ? `${validate_component(components[1] || missing_component, "svelte:component").$$render($$result, Object.assign(props_1 || {}), {}, { | |
| default: () => { | |
| return `${validate_component(components[2] || missing_component, "svelte:component").$$render($$result, Object.assign(props_2 || {}), {}, {})}`; | |
| } | |
| })}` : `${validate_component(components[1] || missing_component, "svelte:component").$$render($$result, Object.assign(props_1 || {}), {}, {})}`}`; | |
| } | |
| })}` : `${validate_component(components[0] || missing_component, "svelte:component").$$render($$result, Object.assign(props_0 || {}), {}, {})}`} | |
| ${``}`; | |
| }); | |
| function to_headers(object) { | |
| const headers = new Headers(); | |
| if (object) { | |
| for (const key2 in object) { | |
| const value = object[key2]; | |
| if (!value) | |
| continue; | |
| if (Array.isArray(value)) { | |
| value.forEach((value2) => { | |
| headers.append(key2, value2); | |
| }); | |
| } else { | |
| headers.set(key2, value); | |
| } | |
| } | |
| } | |
| return headers; | |
| } | |
| 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); | |
| } | |
| function lowercase_keys(obj) { | |
| const clone = {}; | |
| for (const key2 in obj) { | |
| clone[key2.toLowerCase()] = obj[key2]; | |
| } | |
| return clone; | |
| } | |
| function decode_params(params) { | |
| for (const key2 in params) { | |
| params[key2] = params[key2].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 is_pojo(body) { | |
| if (typeof body !== "object") | |
| return false; | |
| if (body) { | |
| if (body instanceof Uint8Array) | |
| return false; | |
| if (body instanceof ReadableStream) | |
| return false; | |
| if (body._readableState && typeof body.pipe === "function") { | |
| throw new Error("Node streams are no longer supported \u2014 use a ReadableStream instead"); | |
| } | |
| } | |
| return true; | |
| } | |
| function normalize_request_method(event) { | |
| const method = event.request.method.toLowerCase(); | |
| return method === "delete" ? "del" : method; | |
| } | |
| function error(body) { | |
| return new Response(body, { | |
| status: 500 | |
| }); | |
| } | |
| function is_string(s2) { | |
| return typeof s2 === "string" || s2 instanceof String; | |
| } | |
| const text_types = /* @__PURE__ */ new Set([ | |
| "application/xml", | |
| "application/json", | |
| "application/x-www-form-urlencoded", | |
| "multipart/form-data" | |
| ]); | |
| const bodyless_status_codes = /* @__PURE__ */ new Set([101, 204, 205, 304]); | |
| 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(event, mod) { | |
| const method = normalize_request_method(event); | |
| let handler = mod[method]; | |
| if (!handler && method === "head") { | |
| handler = mod.get; | |
| } | |
| if (!handler) { | |
| const allowed = []; | |
| for (const method2 in ["get", "post", "put", "patch"]) { | |
| if (mod[method2]) | |
| allowed.push(method2.toUpperCase()); | |
| } | |
| if (mod.del) | |
| allowed.push("DELETE"); | |
| if (mod.get || mod.head) | |
| allowed.push("HEAD"); | |
| return event.request.headers.get("x-sveltekit-load") ? new Response(void 0, { | |
| status: 204 | |
| }) : new Response(`${event.request.method} method not allowed`, { | |
| status: 405, | |
| headers: { | |
| allow: allowed.join(", ") | |
| } | |
| }); | |
| } | |
| const response = await handler(event); | |
| const preface = `Invalid response from route ${event.url.pathname}`; | |
| if (typeof response !== "object") { | |
| return error(`${preface}: expected an object, got ${typeof response}`); | |
| } | |
| if (response.fallthrough) { | |
| throw new Error("fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching"); | |
| } | |
| const { status = 200, body = {} } = response; | |
| const headers = response.headers instanceof Headers ? new Headers(response.headers) : to_headers(response.headers); | |
| const type = headers.get("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 (is_pojo(body) && (!type || type.startsWith("application/json"))) { | |
| headers.set("content-type", "application/json; charset=utf-8"); | |
| normalized_body = JSON.stringify(body); | |
| } else { | |
| normalized_body = body; | |
| } | |
| if ((typeof normalized_body === "string" || normalized_body instanceof Uint8Array) && !headers.has("etag")) { | |
| const cache_control = headers.get("cache-control"); | |
| if (!cache_control || !/(no-store|immutable)/.test(cache_control)) { | |
| headers.set("etag", `"${hash(normalized_body)}"`); | |
| } | |
| } | |
| return new Response(method !== "head" && !bodyless_status_codes.has(status) ? normalized_body : void 0, { | |
| status, | |
| headers | |
| }); | |
| } | |
| var chars$1 = "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 = /* @__PURE__ */ 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(key2) { | |
| return walk(thing[key2]); | |
| }); | |
| } | |
| } | |
| } | |
| walk(value); | |
| var names = /* @__PURE__ */ 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(key2) { | |
| return safeKey(key2) + ":" + stringify(thing[key2]); | |
| }).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(key2) { | |
| statements_1.push("" + name + safeProp(key2) + "=" + stringify(thing[key2])); | |
| }); | |
| } | |
| }); | |
| 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$1[num % chars$1.length] + name; | |
| num = ~~(num / chars$1.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(key2) { | |
| return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key2) ? key2 : escapeUnsafeChars(JSON.stringify(key2)); | |
| } | |
| function safeProp(key2) { | |
| return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key2) ? "." + key2 : "[" + escapeUnsafeChars(JSON.stringify(key2)) + "]"; | |
| } | |
| 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 readable(value, start) { | |
| return { | |
| subscribe: writable(value, start).subscribe | |
| }; | |
| } | |
| function writable(value, start = noop) { | |
| let stop; | |
| const subscribers = /* @__PURE__ */ 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)); | |
| } | |
| const render_json_payload_script_dict = { | |
| "<": "\\u003C", | |
| "\u2028": "\\u2028", | |
| "\u2029": "\\u2029" | |
| }; | |
| const render_json_payload_script_regex = new RegExp(`[${Object.keys(render_json_payload_script_dict).join("")}]`, "g"); | |
| function render_json_payload_script(attrs, payload) { | |
| const safe_payload = JSON.stringify(payload).replace(render_json_payload_script_regex, (match) => render_json_payload_script_dict[match]); | |
| let safe_attrs = ""; | |
| for (const [key2, value] of Object.entries(attrs)) { | |
| if (value === void 0) | |
| continue; | |
| safe_attrs += ` sveltekit:data-${key2}=${escape_html_attr(value)}`; | |
| } | |
| return `<script type="application/json"${safe_attrs}>${safe_payload}<\/script>`; | |
| } | |
| const escape_html_attr_dict = { | |
| "&": "&", | |
| '"': """ | |
| }; | |
| const escape_html_attr_regex = new RegExp(`[${Object.keys(escape_html_attr_dict).join("")}]|[\\ud800-\\udbff](?![\\udc00-\\udfff])|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\udc00-\\udfff]`, "g"); | |
| function escape_html_attr(str) { | |
| const escaped_str = str.replace(escape_html_attr_regex, (match) => { | |
| if (match.length === 2) { | |
| return match; | |
| } | |
| return escape_html_attr_dict[match] ?? `&#${match.charCodeAt(0)};`; | |
| }); | |
| return `"${escaped_str}"`; | |
| } | |
| const s = JSON.stringify; | |
| const encoder = new TextEncoder(); | |
| function sha256(data) { | |
| if (!key[0]) | |
| precompute(); | |
| const out = init.slice(0); | |
| const array2 = encode$1(data); | |
| for (let i = 0; i < array2.length; i += 16) { | |
| const w = array2.subarray(i, i + 16); | |
| let tmp; | |
| let a; | |
| let b; | |
| let out0 = out[0]; | |
| let out1 = out[1]; | |
| let out2 = out[2]; | |
| let out3 = out[3]; | |
| let out4 = out[4]; | |
| let out5 = out[5]; | |
| let out6 = out[6]; | |
| let out7 = out[7]; | |
| for (let i2 = 0; i2 < 64; i2++) { | |
| if (i2 < 16) { | |
| tmp = w[i2]; | |
| } else { | |
| a = w[i2 + 1 & 15]; | |
| b = w[i2 + 14 & 15]; | |
| tmp = w[i2 & 15] = (a >>> 7 ^ a >>> 18 ^ a >>> 3 ^ a << 25 ^ a << 14) + (b >>> 17 ^ b >>> 19 ^ b >>> 10 ^ b << 15 ^ b << 13) + w[i2 & 15] + w[i2 + 9 & 15] | 0; | |
| } | |
| tmp = tmp + out7 + (out4 >>> 6 ^ out4 >>> 11 ^ out4 >>> 25 ^ out4 << 26 ^ out4 << 21 ^ out4 << 7) + (out6 ^ out4 & (out5 ^ out6)) + key[i2]; | |
| out7 = out6; | |
| out6 = out5; | |
| out5 = out4; | |
| out4 = out3 + tmp | 0; | |
| out3 = out2; | |
| out2 = out1; | |
| out1 = out0; | |
| out0 = tmp + (out1 & out2 ^ out3 & (out1 ^ out2)) + (out1 >>> 2 ^ out1 >>> 13 ^ out1 >>> 22 ^ out1 << 30 ^ out1 << 19 ^ out1 << 10) | 0; | |
| } | |
| out[0] = out[0] + out0 | 0; | |
| out[1] = out[1] + out1 | 0; | |
| out[2] = out[2] + out2 | 0; | |
| out[3] = out[3] + out3 | 0; | |
| out[4] = out[4] + out4 | 0; | |
| out[5] = out[5] + out5 | 0; | |
| out[6] = out[6] + out6 | 0; | |
| out[7] = out[7] + out7 | 0; | |
| } | |
| const bytes = new Uint8Array(out.buffer); | |
| reverse_endianness(bytes); | |
| return base64(bytes); | |
| } | |
| const init = new Uint32Array(8); | |
| const key = new Uint32Array(64); | |
| function precompute() { | |
| function frac(x) { | |
| return (x - Math.floor(x)) * 4294967296; | |
| } | |
| let prime = 2; | |
| for (let i = 0; i < 64; prime++) { | |
| let is_prime = true; | |
| for (let factor = 2; factor * factor <= prime; factor++) { | |
| if (prime % factor === 0) { | |
| is_prime = false; | |
| break; | |
| } | |
| } | |
| if (is_prime) { | |
| if (i < 8) { | |
| init[i] = frac(prime ** (1 / 2)); | |
| } | |
| key[i] = frac(prime ** (1 / 3)); | |
| i++; | |
| } | |
| } | |
| } | |
| function reverse_endianness(bytes) { | |
| for (let i = 0; i < bytes.length; i += 4) { | |
| const a = bytes[i + 0]; | |
| const b = bytes[i + 1]; | |
| const c = bytes[i + 2]; | |
| const d = bytes[i + 3]; | |
| bytes[i + 0] = d; | |
| bytes[i + 1] = c; | |
| bytes[i + 2] = b; | |
| bytes[i + 3] = a; | |
| } | |
| } | |
| function encode$1(str) { | |
| const encoded = encoder.encode(str); | |
| const length = encoded.length * 8; | |
| const size = 512 * Math.ceil((length + 65) / 512); | |
| const bytes = new Uint8Array(size / 8); | |
| bytes.set(encoded); | |
| bytes[encoded.length] = 128; | |
| reverse_endianness(bytes); | |
| const words = new Uint32Array(bytes.buffer); | |
| words[words.length - 2] = Math.floor(length / 4294967296); | |
| words[words.length - 1] = length; | |
| return words; | |
| } | |
| const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""); | |
| function base64(bytes) { | |
| const l = bytes.length; | |
| let result = ""; | |
| let i; | |
| for (i = 2; i < l; i += 3) { | |
| result += chars[bytes[i - 2] >> 2]; | |
| result += chars[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; | |
| result += chars[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6]; | |
| result += chars[bytes[i] & 63]; | |
| } | |
| if (i === l + 1) { | |
| result += chars[bytes[i - 2] >> 2]; | |
| result += chars[(bytes[i - 2] & 3) << 4]; | |
| result += "=="; | |
| } | |
| if (i === l) { | |
| result += chars[bytes[i - 2] >> 2]; | |
| result += chars[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; | |
| result += chars[(bytes[i - 1] & 15) << 2]; | |
| result += "="; | |
| } | |
| return result; | |
| } | |
| let csp_ready; | |
| const array = new Uint8Array(16); | |
| function generate_nonce() { | |
| crypto.getRandomValues(array); | |
| return base64(array); | |
| } | |
| const quoted = /* @__PURE__ */ new Set([ | |
| "self", | |
| "unsafe-eval", | |
| "unsafe-hashes", | |
| "unsafe-inline", | |
| "none", | |
| "strict-dynamic", | |
| "report-sample" | |
| ]); | |
| const crypto_pattern = /^(nonce|sha\d\d\d)-/; | |
| class Csp { | |
| #use_hashes; | |
| #dev; | |
| #script_needs_csp; | |
| #style_needs_csp; | |
| #directives; | |
| #script_src; | |
| #style_src; | |
| constructor({ mode, directives }, { dev, prerender, needs_nonce }) { | |
| this.#use_hashes = mode === "hash" || mode === "auto" && prerender; | |
| this.#directives = dev ? { ...directives } : directives; | |
| this.#dev = dev; | |
| const d = this.#directives; | |
| if (dev) { | |
| const effective_style_src2 = d["style-src"] || d["default-src"]; | |
| if (effective_style_src2 && !effective_style_src2.includes("unsafe-inline")) { | |
| d["style-src"] = [...effective_style_src2, "unsafe-inline"]; | |
| } | |
| } | |
| this.#script_src = []; | |
| this.#style_src = []; | |
| const effective_script_src = d["script-src"] || d["default-src"]; | |
| const effective_style_src = d["style-src"] || d["default-src"]; | |
| this.#script_needs_csp = !!effective_script_src && effective_script_src.filter((value) => value !== "unsafe-inline").length > 0; | |
| this.#style_needs_csp = !dev && !!effective_style_src && effective_style_src.filter((value) => value !== "unsafe-inline").length > 0; | |
| this.script_needs_nonce = this.#script_needs_csp && !this.#use_hashes; | |
| this.style_needs_nonce = this.#style_needs_csp && !this.#use_hashes; | |
| if (this.script_needs_nonce || this.style_needs_nonce || needs_nonce) { | |
| this.nonce = generate_nonce(); | |
| } | |
| } | |
| add_script(content) { | |
| if (this.#script_needs_csp) { | |
| if (this.#use_hashes) { | |
| this.#script_src.push(`sha256-${sha256(content)}`); | |
| } else if (this.#script_src.length === 0) { | |
| this.#script_src.push(`nonce-${this.nonce}`); | |
| } | |
| } | |
| } | |
| add_style(content) { | |
| if (this.#style_needs_csp) { | |
| if (this.#use_hashes) { | |
| this.#style_src.push(`sha256-${sha256(content)}`); | |
| } else if (this.#style_src.length === 0) { | |
| this.#style_src.push(`nonce-${this.nonce}`); | |
| } | |
| } | |
| } | |
| get_header(is_meta = false) { | |
| const header = []; | |
| const directives = { ...this.#directives }; | |
| if (this.#style_src.length > 0) { | |
| directives["style-src"] = [ | |
| ...directives["style-src"] || directives["default-src"] || [], | |
| ...this.#style_src | |
| ]; | |
| } | |
| if (this.#script_src.length > 0) { | |
| directives["script-src"] = [ | |
| ...directives["script-src"] || directives["default-src"] || [], | |
| ...this.#script_src | |
| ]; | |
| } | |
| for (const key2 in directives) { | |
| if (is_meta && (key2 === "frame-ancestors" || key2 === "report-uri" || key2 === "sandbox")) { | |
| continue; | |
| } | |
| const value = directives[key2]; | |
| if (!value) | |
| continue; | |
| const directive = [key2]; | |
| if (Array.isArray(value)) { | |
| value.forEach((value2) => { | |
| if (quoted.has(value2) || crypto_pattern.test(value2)) { | |
| directive.push(`'${value2}'`); | |
| } else { | |
| directive.push(value2); | |
| } | |
| }); | |
| } | |
| header.push(directive.join(" ")); | |
| } | |
| return header.join("; "); | |
| } | |
| get_meta() { | |
| const content = escape_html_attr(this.get_header(true)); | |
| return `<meta http-equiv="content-security-policy" content=${content}>`; | |
| } | |
| } | |
| const absolute = /^([a-z]+:)?\/?\//; | |
| const scheme = /^[a-z]+:/; | |
| function resolve(base2, path) { | |
| if (scheme.test(path)) | |
| return path; | |
| const base_match = absolute.exec(base2); | |
| const path_match = absolute.exec(path); | |
| if (!base_match) { | |
| throw new Error(`bad base path: "${base2}"`); | |
| } | |
| const baseparts = path_match ? [] : base2.slice(base_match[0].length).split("/"); | |
| const pathparts = path_match ? path.slice(path_match[0].length).split("/") : path.split("/"); | |
| baseparts.pop(); | |
| for (let i = 0; i < pathparts.length; i += 1) { | |
| const part = pathparts[i]; | |
| if (part === ".") | |
| continue; | |
| else if (part === "..") | |
| baseparts.pop(); | |
| else | |
| baseparts.push(part); | |
| } | |
| const prefix = path_match && path_match[0] || base_match && base_match[0] || ""; | |
| return `${prefix}${baseparts.join("/")}`; | |
| } | |
| function is_root_relative(path) { | |
| return path[0] === "/" && path[1] !== "/"; | |
| } | |
| function normalize_path(path, trailing_slash) { | |
| if (path === "/" || trailing_slash === "ignore") | |
| return path; | |
| if (trailing_slash === "never") { | |
| return path.endsWith("/") ? path.slice(0, -1) : path; | |
| } else if (trailing_slash === "always" && !path.endsWith("/")) { | |
| return path + "/"; | |
| } | |
| return path; | |
| } | |
| class LoadURL extends URL { | |
| get hash() { | |
| throw new Error("url.hash is inaccessible from load. Consider accessing hash from the page store within the script tag of your component."); | |
| } | |
| } | |
| class PrerenderingURL extends URL { | |
| get search() { | |
| throw new Error("Cannot access url.search on a page with prerendering enabled"); | |
| } | |
| get searchParams() { | |
| throw new Error("Cannot access url.searchParams on a page with prerendering enabled"); | |
| } | |
| } | |
| const updated = { | |
| ...readable(false), | |
| check: () => false | |
| }; | |
| async function render_response({ | |
| branch, | |
| options, | |
| state, | |
| $session, | |
| page_config, | |
| status, | |
| error: error2 = null, | |
| event, | |
| resolve_opts, | |
| stuff | |
| }) { | |
| if (state.prerendering) { | |
| if (options.csp.mode === "nonce") { | |
| throw new Error('Cannot use prerendering if config.kit.csp.mode === "nonce"'); | |
| } | |
| if (options.template_contains_nonce) { | |
| throw new Error("Cannot use prerendering if page template contains %sveltekit.nonce%"); | |
| } | |
| } | |
| const stylesheets = new Set(options.manifest._.entry.css); | |
| const modulepreloads = new Set(options.manifest._.entry.js); | |
| const styles = /* @__PURE__ */ new Map(); | |
| const serialized_data = []; | |
| let shadow_props; | |
| let rendered; | |
| let is_private = false; | |
| let cache; | |
| if (error2) { | |
| error2.stack = options.get_stack(error2); | |
| } | |
| if (resolve_opts.ssr) { | |
| branch.forEach(({ node, props: props2, loaded, fetched, uses_credentials }) => { | |
| if (node.css) | |
| node.css.forEach((url) => stylesheets.add(url)); | |
| if (node.js) | |
| node.js.forEach((url) => modulepreloads.add(url)); | |
| if (node.styles) | |
| Object.entries(node.styles).forEach(([k, v]) => styles.set(k, v)); | |
| if (fetched && page_config.hydrate) | |
| serialized_data.push(...fetched); | |
| if (props2) | |
| shadow_props = props2; | |
| cache = loaded == null ? void 0 : loaded.cache; | |
| is_private = (cache == null ? void 0 : cache.private) ?? uses_credentials; | |
| }); | |
| const session = writable($session); | |
| const props = { | |
| stores: { | |
| page: writable(null), | |
| navigating: writable(null), | |
| session: { | |
| ...session, | |
| subscribe: (fn) => { | |
| is_private = (cache == null ? void 0 : cache.private) ?? true; | |
| return session.subscribe(fn); | |
| } | |
| }, | |
| updated | |
| }, | |
| page: { | |
| error: error2, | |
| params: event.params, | |
| routeId: event.routeId, | |
| status, | |
| stuff, | |
| url: state.prerendering ? new PrerenderingURL(event.url) : event.url | |
| }, | |
| 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; | |
| } | |
| rendered = options.root.render(props); | |
| } else { | |
| rendered = { head: "", html: "", css: { code: "", map: null } }; | |
| } | |
| let { head, html: body } = rendered; | |
| const inlined_style = Array.from(styles.values()).join("\n"); | |
| await csp_ready; | |
| const csp = new Csp(options.csp, { | |
| dev: options.dev, | |
| prerender: !!state.prerendering, | |
| needs_nonce: options.template_contains_nonce | |
| }); | |
| const target = hash(body); | |
| const init_app = ` | |
| import { start } from ${s(options.prefix + options.manifest._.entry.file)}; | |
| start({ | |
| target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode, | |
| paths: ${s(options.paths)}, | |
| session: ${try_serialize($session, (error3) => { | |
| throw new Error(`Failed to serialize session data: ${error3.message}`); | |
| })}, | |
| route: ${!!page_config.router}, | |
| spa: ${!resolve_opts.ssr}, | |
| trailing_slash: ${s(options.trailing_slash)}, | |
| hydrate: ${resolve_opts.ssr && page_config.hydrate ? `{ | |
| status: ${status}, | |
| error: ${serialize_error(error2)}, | |
| nodes: [${branch.map(({ node }) => node.index).join(", ")}], | |
| params: ${devalue(event.params)}, | |
| routeId: ${s(event.routeId)} | |
| }` : "null"} | |
| }); | |
| `; | |
| const init_service_worker = ` | |
| if ('serviceWorker' in navigator) { | |
| addEventListener('load', () => { | |
| navigator.serviceWorker.register('${options.service_worker}'); | |
| }); | |
| } | |
| `; | |
| if (inlined_style) { | |
| const attributes = []; | |
| if (options.dev) | |
| attributes.push(" data-sveltekit"); | |
| if (csp.style_needs_nonce) | |
| attributes.push(` nonce="${csp.nonce}"`); | |
| csp.add_style(inlined_style); | |
| head += ` | |
| <style${attributes.join("")}>${inlined_style}</style>`; | |
| } | |
| head += Array.from(stylesheets).map((dep) => { | |
| const attributes = [ | |
| 'rel="stylesheet"', | |
| `href="${options.prefix + dep}"` | |
| ]; | |
| if (csp.style_needs_nonce) { | |
| attributes.push(`nonce="${csp.nonce}"`); | |
| } | |
| if (styles.has(dep)) { | |
| attributes.push("disabled", 'media="(max-width: 0)"'); | |
| } | |
| return ` | |
| <link ${attributes.join(" ")}>`; | |
| }).join(""); | |
| if (page_config.router || page_config.hydrate) { | |
| head += Array.from(modulepreloads).map((dep) => ` | |
| <link rel="modulepreload" href="${options.prefix + dep}">`).join(""); | |
| const attributes = ['type="module"', `data-sveltekit-hydrate="${target}"`]; | |
| csp.add_script(init_app); | |
| if (csp.script_needs_nonce) { | |
| attributes.push(`nonce="${csp.nonce}"`); | |
| } | |
| body += ` | |
| <script ${attributes.join(" ")}>${init_app}<\/script>`; | |
| body += serialized_data.map(({ url, body: body2, response }) => render_json_payload_script({ type: "data", url, body: typeof body2 === "string" ? hash(body2) : void 0 }, response)).join("\n "); | |
| if (shadow_props) { | |
| body += render_json_payload_script({ type: "props" }, shadow_props); | |
| } | |
| } | |
| if (options.service_worker) { | |
| csp.add_script(init_service_worker); | |
| head += ` | |
| <script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>${init_service_worker}<\/script>`; | |
| } | |
| if (state.prerendering) { | |
| const http_equiv = []; | |
| const csp_headers = csp.get_meta(); | |
| if (csp_headers) { | |
| http_equiv.push(csp_headers); | |
| } | |
| if (cache) { | |
| http_equiv.push(`<meta http-equiv="cache-control" content="max-age=${cache.maxage}">`); | |
| } | |
| if (http_equiv.length > 0) { | |
| head = http_equiv.join("\n") + head; | |
| } | |
| } | |
| const segments = event.url.pathname.slice(options.paths.base.length).split("/").slice(2); | |
| const assets2 = options.paths.assets || (segments.length > 0 ? segments.map(() => "..").join("/") : "."); | |
| const html = await resolve_opts.transformPage({ | |
| html: options.template({ head, body, assets: assets2, nonce: csp.nonce }) | |
| }); | |
| const headers = new Headers({ | |
| "content-type": "text/html", | |
| etag: `"${hash(html)}"` | |
| }); | |
| if (cache) { | |
| headers.set("cache-control", `${is_private ? "private" : "public"}, max-age=${cache.maxage}`); | |
| } | |
| if (!options.floc) { | |
| headers.set("permissions-policy", "interest-cohort=()"); | |
| } | |
| if (!state.prerendering) { | |
| const csp_header = csp.get_header(); | |
| if (csp_header) { | |
| headers.set("content-security-policy", csp_header); | |
| } | |
| } | |
| return new Response(html, { | |
| status, | |
| headers | |
| }); | |
| } | |
| function try_serialize(data, fail) { | |
| try { | |
| return devalue(data); | |
| } catch (err) { | |
| if (fail) | |
| fail(coalesce_to_error(err)); | |
| return null; | |
| } | |
| } | |
| function serialize_error(error2) { | |
| if (!error2) | |
| return null; | |
| let serialized = try_serialize(error2); | |
| if (!serialized) { | |
| const { name, message, stack } = error2; | |
| serialized = try_serialize({ ...error2, name, message, stack }); | |
| } | |
| if (!serialized) { | |
| serialized = "{}"; | |
| } | |
| return serialized; | |
| } | |
| /*! | |
| * cookie | |
| * Copyright(c) 2012-2014 Roman Shtylman | |
| * Copyright(c) 2015 Douglas Christopher Wilson | |
| * MIT Licensed | |
| */ | |
| var parse_1 = parse$1; | |
| var serialize_1 = serialize; | |
| var __toString = Object.prototype.toString; | |
| var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; | |
| function parse$1(str, options) { | |
| if (typeof str !== "string") { | |
| throw new TypeError("argument str must be a string"); | |
| } | |
| var obj = {}; | |
| var opt = options || {}; | |
| var dec = opt.decode || decode; | |
| var index = 0; | |
| while (index < str.length) { | |
| var eqIdx = str.indexOf("=", index); | |
| if (eqIdx === -1) { | |
| break; | |
| } | |
| var endIdx = str.indexOf(";", index); | |
| if (endIdx === -1) { | |
| endIdx = str.length; | |
| } else if (endIdx < eqIdx) { | |
| index = str.lastIndexOf(";", eqIdx - 1) + 1; | |
| continue; | |
| } | |
| var key2 = str.slice(index, eqIdx).trim(); | |
| if (obj[key2] === void 0) { | |
| var val = str.slice(eqIdx + 1, endIdx).trim(); | |
| if (val.charCodeAt(0) === 34) { | |
| val = val.slice(1, -1); | |
| } | |
| obj[key2] = tryDecode(val, dec); | |
| } | |
| index = endIdx + 1; | |
| } | |
| return obj; | |
| } | |
| function serialize(name, val, options) { | |
| var opt = options || {}; | |
| var enc = opt.encode || encode; | |
| if (typeof enc !== "function") { | |
| throw new TypeError("option encode is invalid"); | |
| } | |
| if (!fieldContentRegExp.test(name)) { | |
| throw new TypeError("argument name is invalid"); | |
| } | |
| var value = enc(val); | |
| if (value && !fieldContentRegExp.test(value)) { | |
| throw new TypeError("argument val is invalid"); | |
| } | |
| var str = name + "=" + value; | |
| if (opt.maxAge != null) { | |
| var maxAge = opt.maxAge - 0; | |
| if (isNaN(maxAge) || !isFinite(maxAge)) { | |
| throw new TypeError("option maxAge is invalid"); | |
| } | |
| str += "; Max-Age=" + Math.floor(maxAge); | |
| } | |
| if (opt.domain) { | |
| if (!fieldContentRegExp.test(opt.domain)) { | |
| throw new TypeError("option domain is invalid"); | |
| } | |
| str += "; Domain=" + opt.domain; | |
| } | |
| if (opt.path) { | |
| if (!fieldContentRegExp.test(opt.path)) { | |
| throw new TypeError("option path is invalid"); | |
| } | |
| str += "; Path=" + opt.path; | |
| } | |
| if (opt.expires) { | |
| var expires = opt.expires; | |
| if (!isDate(expires) || isNaN(expires.valueOf())) { | |
| throw new TypeError("option expires is invalid"); | |
| } | |
| str += "; Expires=" + expires.toUTCString(); | |
| } | |
| if (opt.httpOnly) { | |
| str += "; HttpOnly"; | |
| } | |
| if (opt.secure) { | |
| str += "; Secure"; | |
| } | |
| if (opt.priority) { | |
| var priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority; | |
| switch (priority) { | |
| case "low": | |
| str += "; Priority=Low"; | |
| break; | |
| case "medium": | |
| str += "; Priority=Medium"; | |
| break; | |
| case "high": | |
| str += "; Priority=High"; | |
| break; | |
| default: | |
| throw new TypeError("option priority is invalid"); | |
| } | |
| } | |
| if (opt.sameSite) { | |
| var sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite; | |
| switch (sameSite) { | |
| case true: | |
| str += "; SameSite=Strict"; | |
| break; | |
| case "lax": | |
| str += "; SameSite=Lax"; | |
| break; | |
| case "strict": | |
| str += "; SameSite=Strict"; | |
| break; | |
| case "none": | |
| str += "; SameSite=None"; | |
| break; | |
| default: | |
| throw new TypeError("option sameSite is invalid"); | |
| } | |
| } | |
| return str; | |
| } | |
| function decode(str) { | |
| return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str; | |
| } | |
| function encode(val) { | |
| return encodeURIComponent(val); | |
| } | |
| function isDate(val) { | |
| return __toString.call(val) === "[object Date]" || val instanceof Date; | |
| } | |
| function tryDecode(str, decode2) { | |
| try { | |
| return decode2(str); | |
| } catch (e) { | |
| return str; | |
| } | |
| } | |
| var setCookie = { exports: {} }; | |
| var defaultParseOptions = { | |
| decodeValues: true, | |
| map: false, | |
| silent: false | |
| }; | |
| function isNonEmptyString(str) { | |
| return typeof str === "string" && !!str.trim(); | |
| } | |
| function parseString(setCookieValue, options) { | |
| var parts = setCookieValue.split(";").filter(isNonEmptyString); | |
| var nameValue = parts.shift().split("="); | |
| var name = nameValue.shift(); | |
| var value = nameValue.join("="); | |
| options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions; | |
| try { | |
| value = options.decodeValues ? decodeURIComponent(value) : value; | |
| } catch (e) { | |
| console.error("set-cookie-parser encountered an error while decoding a cookie with value '" + value + "'. Set options.decodeValues to false to disable this feature.", e); | |
| } | |
| var cookie = { | |
| name, | |
| value | |
| }; | |
| parts.forEach(function(part) { | |
| var sides = part.split("="); | |
| var key2 = sides.shift().trimLeft().toLowerCase(); | |
| var value2 = sides.join("="); | |
| if (key2 === "expires") { | |
| cookie.expires = new Date(value2); | |
| } else if (key2 === "max-age") { | |
| cookie.maxAge = parseInt(value2, 10); | |
| } else if (key2 === "secure") { | |
| cookie.secure = true; | |
| } else if (key2 === "httponly") { | |
| cookie.httpOnly = true; | |
| } else if (key2 === "samesite") { | |
| cookie.sameSite = value2; | |
| } else { | |
| cookie[key2] = value2; | |
| } | |
| }); | |
| return cookie; | |
| } | |
| function parse(input, options) { | |
| options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions; | |
| if (!input) { | |
| if (!options.map) { | |
| return []; | |
| } else { | |
| return {}; | |
| } | |
| } | |
| if (input.headers && input.headers["set-cookie"]) { | |
| input = input.headers["set-cookie"]; | |
| } else if (input.headers) { | |
| var sch = input.headers[Object.keys(input.headers).find(function(key2) { | |
| return key2.toLowerCase() === "set-cookie"; | |
| })]; | |
| if (!sch && input.headers.cookie && !options.silent) { | |
| console.warn("Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."); | |
| } | |
| input = sch; | |
| } | |
| if (!Array.isArray(input)) { | |
| input = [input]; | |
| } | |
| options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions; | |
| if (!options.map) { | |
| return input.filter(isNonEmptyString).map(function(str) { | |
| return parseString(str, options); | |
| }); | |
| } else { | |
| var cookies = {}; | |
| return input.filter(isNonEmptyString).reduce(function(cookies2, str) { | |
| var cookie = parseString(str, options); | |
| cookies2[cookie.name] = cookie; | |
| return cookies2; | |
| }, cookies); | |
| } | |
| } | |
| function splitCookiesString(cookiesString) { | |
| if (Array.isArray(cookiesString)) { | |
| return cookiesString; | |
| } | |
| if (typeof cookiesString !== "string") { | |
| return []; | |
| } | |
| var cookiesStrings = []; | |
| var pos = 0; | |
| var start; | |
| var ch; | |
| var lastComma; | |
| var nextStart; | |
| var cookiesSeparatorFound; | |
| function skipWhitespace() { | |
| while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) { | |
| pos += 1; | |
| } | |
| return pos < cookiesString.length; | |
| } | |
| function notSpecialChar() { | |
| ch = cookiesString.charAt(pos); | |
| return ch !== "=" && ch !== ";" && ch !== ","; | |
| } | |
| while (pos < cookiesString.length) { | |
| start = pos; | |
| cookiesSeparatorFound = false; | |
| while (skipWhitespace()) { | |
| ch = cookiesString.charAt(pos); | |
| if (ch === ",") { | |
| lastComma = pos; | |
| pos += 1; | |
| skipWhitespace(); | |
| nextStart = pos; | |
| while (pos < cookiesString.length && notSpecialChar()) { | |
| pos += 1; | |
| } | |
| if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") { | |
| cookiesSeparatorFound = true; | |
| pos = nextStart; | |
| cookiesStrings.push(cookiesString.substring(start, lastComma)); | |
| start = pos; | |
| } else { | |
| pos = lastComma + 1; | |
| } | |
| } else { | |
| pos += 1; | |
| } | |
| } | |
| if (!cookiesSeparatorFound || pos >= cookiesString.length) { | |
| cookiesStrings.push(cookiesString.substring(start, cookiesString.length)); | |
| } | |
| } | |
| return cookiesStrings; | |
| } | |
| setCookie.exports = parse; | |
| setCookie.exports.parse = parse; | |
| var parseString_1 = setCookie.exports.parseString = parseString; | |
| var splitCookiesString_1 = setCookie.exports.splitCookiesString = splitCookiesString; | |
| function normalize(loaded) { | |
| if (loaded.fallthrough) { | |
| throw new Error("fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching"); | |
| } | |
| if ("maxage" in loaded) { | |
| throw new Error("maxage should be replaced with cache: { maxage }"); | |
| } | |
| const has_error_status = loaded.status && loaded.status >= 400 && loaded.status <= 599 && !loaded.redirect; | |
| if (loaded.error || has_error_status) { | |
| const status = loaded.status; | |
| if (!loaded.error && has_error_status) { | |
| return { status: status || 500, error: new Error() }; | |
| } | |
| const error2 = typeof loaded.error === "string" ? new Error(loaded.error) : loaded.error; | |
| if (!(error2 instanceof Error)) { | |
| return { | |
| status: 500, | |
| error: new Error(`"error" property returned from load() must be a string or instance of Error, received type "${typeof error2}"`) | |
| }; | |
| } | |
| if (!status || status < 400 || status > 599) { | |
| console.warn('"error" returned from load() without a valid status code \u2014 defaulting to 500'); | |
| return { status: 500, error: error2 }; | |
| } | |
| return { status, error: error2 }; | |
| } | |
| if (loaded.redirect) { | |
| if (!loaded.status || Math.floor(loaded.status / 100) !== 3) { | |
| throw new Error('"redirect" property returned from load() must be accompanied by a 3xx status code'); | |
| } | |
| if (typeof loaded.redirect !== "string") { | |
| throw new Error('"redirect" property returned from load() must be a string'); | |
| } | |
| } | |
| if (loaded.dependencies) { | |
| if (!Array.isArray(loaded.dependencies) || loaded.dependencies.some((dep) => typeof dep !== "string")) { | |
| throw new Error('"dependencies" property returned from load() must be of type string[]'); | |
| } | |
| } | |
| if (loaded.context) { | |
| throw new Error('You are returning "context" from a load function. "context" was renamed to "stuff", please adjust your code accordingly.'); | |
| } | |
| return loaded; | |
| } | |
| function domain_matches(hostname, constraint) { | |
| if (!constraint) | |
| return true; | |
| const normalized = constraint[0] === "." ? constraint.slice(1) : constraint; | |
| if (hostname === normalized) | |
| return true; | |
| return hostname.endsWith("." + normalized); | |
| } | |
| function path_matches(path, constraint) { | |
| if (!constraint) | |
| return true; | |
| const normalized = constraint.endsWith("/") ? constraint.slice(0, -1) : constraint; | |
| if (path === normalized) | |
| return true; | |
| return path.startsWith(normalized + "/"); | |
| } | |
| async function load_node({ | |
| event, | |
| options, | |
| state, | |
| route, | |
| node, | |
| $session, | |
| stuff, | |
| is_error, | |
| is_leaf, | |
| status, | |
| error: error2 | |
| }) { | |
| const { module } = node; | |
| let uses_credentials = false; | |
| const fetched = []; | |
| const cookies = parse_1(event.request.headers.get("cookie") || ""); | |
| const new_cookies = []; | |
| let loaded; | |
| const should_prerender = node.module.prerender ?? options.prerender.default; | |
| const shadow = is_leaf ? await load_shadow_data(route, event, options, should_prerender) : {}; | |
| if (shadow.cookies) { | |
| shadow.cookies.forEach((header) => { | |
| new_cookies.push(parseString_1(header)); | |
| }); | |
| } | |
| if (shadow.error) { | |
| loaded = { | |
| status: shadow.status, | |
| error: shadow.error | |
| }; | |
| } else if (shadow.redirect) { | |
| loaded = { | |
| status: shadow.status, | |
| redirect: shadow.redirect | |
| }; | |
| } else if (module.load) { | |
| const load_input = { | |
| url: state.prerendering ? new PrerenderingURL(event.url) : new LoadURL(event.url), | |
| params: event.params, | |
| props: shadow.body || {}, | |
| routeId: event.routeId, | |
| get session() { | |
| if (node.module.prerender ?? options.prerender.default) { | |
| throw Error("Attempted to access session from a prerendered page. Session would never be populated."); | |
| } | |
| uses_credentials = true; | |
| return $session; | |
| }, | |
| fetch: async (resource, opts = {}) => { | |
| let requested; | |
| if (typeof resource === "string") { | |
| requested = resource; | |
| } else { | |
| requested = resource.url; | |
| opts = { | |
| method: resource.method, | |
| headers: resource.headers, | |
| body: resource.body, | |
| mode: resource.mode, | |
| credentials: resource.credentials, | |
| cache: resource.cache, | |
| redirect: resource.redirect, | |
| referrer: resource.referrer, | |
| integrity: resource.integrity, | |
| ...opts | |
| }; | |
| } | |
| opts.headers = new Headers(opts.headers); | |
| for (const [key2, value] of event.request.headers) { | |
| if (key2 !== "authorization" && key2 !== "cookie" && key2 !== "host" && key2 !== "if-none-match" && !opts.headers.has(key2)) { | |
| opts.headers.set(key2, value); | |
| } | |
| } | |
| const resolved = resolve(event.url.pathname, requested.split("?")[0]); | |
| let response; | |
| let dependency; | |
| const prefix = options.paths.assets || options.paths.base; | |
| const filename = decodeURIComponent(resolved.startsWith(prefix) ? resolved.slice(prefix.length) : resolved).slice(1); | |
| const filename_html = `${filename}/index.html`; | |
| const is_asset = options.manifest.assets.has(filename); | |
| const is_asset_html = options.manifest.assets.has(filename_html); | |
| if (is_asset || is_asset_html) { | |
| const file = is_asset ? filename : filename_html; | |
| if (options.read) { | |
| const type = is_asset ? options.manifest.mimeTypes[filename.slice(filename.lastIndexOf("."))] : "text/html"; | |
| response = new Response(options.read(file), { | |
| headers: type ? { "content-type": type } : {} | |
| }); | |
| } else { | |
| response = await fetch(`${event.url.origin}/${file}`, opts); | |
| } | |
| } else if (is_root_relative(resolved)) { | |
| if (opts.credentials !== "omit") { | |
| uses_credentials = true; | |
| const authorization = event.request.headers.get("authorization"); | |
| const combined_cookies = { ...cookies }; | |
| for (const cookie2 of new_cookies) { | |
| if (!domain_matches(event.url.hostname, cookie2.domain)) | |
| continue; | |
| if (!path_matches(resolved, cookie2.path)) | |
| continue; | |
| combined_cookies[cookie2.name] = cookie2.value; | |
| } | |
| const cookie = Object.entries(combined_cookies).map(([name, value]) => `${name}=${value}`).join("; "); | |
| if (cookie) { | |
| opts.headers.set("cookie", cookie); | |
| } | |
| if (authorization && !opts.headers.has("authorization")) { | |
| opts.headers.set("authorization", authorization); | |
| } | |
| } | |
| if (opts.body && typeof opts.body !== "string") { | |
| throw new Error("Request body must be a string"); | |
| } | |
| response = await respond(new Request(new URL(requested, event.url).href, { ...opts }), options, { | |
| ...state, | |
| initiator: route | |
| }); | |
| if (state.prerendering) { | |
| dependency = { response, body: null }; | |
| state.prerendering.dependencies.set(resolved, dependency); | |
| } | |
| } else { | |
| if (resolved.startsWith("//")) { | |
| requested = event.url.protocol + requested; | |
| } | |
| if (`.${new URL(requested).hostname}`.endsWith(`.${event.url.hostname}`) && opts.credentials !== "omit") { | |
| uses_credentials = true; | |
| const cookie = event.request.headers.get("cookie"); | |
| if (cookie) | |
| opts.headers.set("cookie", cookie); | |
| } | |
| opts.headers.delete("connection"); | |
| const external_request = new Request(requested, opts); | |
| response = await options.hooks.externalFetch.call(null, external_request); | |
| } | |
| const set_cookie = response.headers.get("set-cookie"); | |
| if (set_cookie) { | |
| new_cookies.push(...splitCookiesString_1(set_cookie).map((str) => parseString_1(str))); | |
| } | |
| const proxy = new Proxy(response, { | |
| get(response2, key2, _receiver) { | |
| async function text() { | |
| const body = await response2.text(); | |
| const headers = {}; | |
| for (const [key3, value] of response2.headers) { | |
| if (key3 !== "set-cookie" && key3 !== "etag") { | |
| headers[key3] = value; | |
| } | |
| } | |
| if (!opts.body || typeof opts.body === "string") { | |
| const status_number = Number(response2.status); | |
| if (isNaN(status_number)) { | |
| throw new Error(`response.status is not a number. value: "${response2.status}" type: ${typeof response2.status}`); | |
| } | |
| fetched.push({ | |
| url: requested, | |
| body: opts.body, | |
| response: { | |
| status: status_number, | |
| statusText: response2.statusText, | |
| headers, | |
| body | |
| } | |
| }); | |
| } | |
| if (dependency) { | |
| dependency.body = body; | |
| } | |
| return body; | |
| } | |
| if (key2 === "arrayBuffer") { | |
| return async () => { | |
| const buffer = await response2.arrayBuffer(); | |
| if (dependency) { | |
| dependency.body = new Uint8Array(buffer); | |
| } | |
| return buffer; | |
| }; | |
| } | |
| if (key2 === "text") { | |
| return text; | |
| } | |
| if (key2 === "json") { | |
| return async () => { | |
| return JSON.parse(await text()); | |
| }; | |
| } | |
| return Reflect.get(response2, key2, response2); | |
| } | |
| }); | |
| return proxy; | |
| }, | |
| stuff: { ...stuff }, | |
| status: is_error ? status ?? null : null, | |
| error: is_error ? error2 ?? null : null | |
| }; | |
| if (options.dev) { | |
| Object.defineProperty(load_input, "page", { | |
| get: () => { | |
| throw new Error("`page` in `load` functions has been replaced by `url` and `params`"); | |
| } | |
| }); | |
| } | |
| loaded = await module.load.call(null, load_input); | |
| if (!loaded) { | |
| throw new Error(`load function must return a value${options.dev ? ` (${node.entry})` : ""}`); | |
| } | |
| } else if (shadow.body) { | |
| loaded = { | |
| props: shadow.body | |
| }; | |
| } else { | |
| loaded = {}; | |
| } | |
| if (shadow.body && state.prerendering) { | |
| const pathname = `${event.url.pathname.replace(/\/$/, "")}/__data.json`; | |
| const dependency = { | |
| response: new Response(void 0), | |
| body: JSON.stringify(shadow.body) | |
| }; | |
| state.prerendering.dependencies.set(pathname, dependency); | |
| } | |
| return { | |
| node, | |
| props: shadow.body, | |
| loaded: normalize(loaded), | |
| stuff: loaded.stuff || stuff, | |
| fetched, | |
| set_cookie_headers: new_cookies.map((new_cookie) => { | |
| const { name, value, ...options2 } = new_cookie; | |
| return serialize_1(name, value, options2); | |
| }), | |
| uses_credentials | |
| }; | |
| } | |
| async function load_shadow_data(route, event, options, prerender) { | |
| if (!route.shadow) | |
| return {}; | |
| try { | |
| const mod = await route.shadow(); | |
| if (prerender && (mod.post || mod.put || mod.del || mod.patch)) { | |
| throw new Error("Cannot prerender pages that have endpoints with mutative methods"); | |
| } | |
| const method = normalize_request_method(event); | |
| const is_get = method === "head" || method === "get"; | |
| const handler = method === "head" ? mod.head || mod.get : mod[method]; | |
| if (!handler && !is_get) { | |
| return { | |
| status: 405, | |
| error: new Error(`${method} method not allowed`) | |
| }; | |
| } | |
| const data = { | |
| status: 200, | |
| cookies: [], | |
| body: {} | |
| }; | |
| if (!is_get) { | |
| const result = await handler(event); | |
| if (result.fallthrough) { | |
| throw new Error("fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching"); | |
| } | |
| const { status, headers, body } = validate_shadow_output(result); | |
| data.status = status; | |
| add_cookies(data.cookies, headers); | |
| if (status >= 300 && status < 400) { | |
| data.redirect = headers instanceof Headers ? headers.get("location") : headers.location; | |
| return data; | |
| } | |
| data.body = body; | |
| } | |
| const get = method === "head" && mod.head || mod.get; | |
| if (get) { | |
| const result = await get(event); | |
| if (result.fallthrough) { | |
| throw new Error("fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching"); | |
| } | |
| const { status, headers, body } = validate_shadow_output(result); | |
| add_cookies(data.cookies, headers); | |
| data.status = status; | |
| if (status >= 400) { | |
| data.error = new Error("Failed to load data"); | |
| return data; | |
| } | |
| if (status >= 300) { | |
| data.redirect = headers instanceof Headers ? headers.get("location") : headers.location; | |
| return data; | |
| } | |
| data.body = { ...body, ...data.body }; | |
| } | |
| return data; | |
| } catch (e) { | |
| const error2 = coalesce_to_error(e); | |
| options.handle_error(error2, event); | |
| return { | |
| status: 500, | |
| error: error2 | |
| }; | |
| } | |
| } | |
| function add_cookies(target, headers) { | |
| const cookies = headers["set-cookie"]; | |
| if (cookies) { | |
| if (Array.isArray(cookies)) { | |
| target.push(...cookies); | |
| } else { | |
| target.push(cookies); | |
| } | |
| } | |
| } | |
| function validate_shadow_output(result) { | |
| const { status = 200, body = {} } = result; | |
| let headers = result.headers || {}; | |
| if (headers instanceof Headers) { | |
| if (headers.has("set-cookie")) { | |
| throw new Error("Endpoint request handler cannot use Headers interface with Set-Cookie headers"); | |
| } | |
| } else { | |
| headers = lowercase_keys(headers); | |
| } | |
| if (!is_pojo(body)) { | |
| throw new Error("Body returned from endpoint request handler must be a plain object"); | |
| } | |
| return { status, headers, body }; | |
| } | |
| async function respond_with_error({ | |
| event, | |
| options, | |
| state, | |
| $session, | |
| status, | |
| error: error2, | |
| resolve_opts | |
| }) { | |
| try { | |
| const branch = []; | |
| let stuff = {}; | |
| if (resolve_opts.ssr) { | |
| const default_layout = await options.manifest._.nodes[0](); | |
| const default_error = await options.manifest._.nodes[1](); | |
| const layout_loaded = await load_node({ | |
| event, | |
| options, | |
| state, | |
| route: null, | |
| node: default_layout, | |
| $session, | |
| stuff: {}, | |
| is_error: false, | |
| is_leaf: false | |
| }); | |
| const error_loaded = await load_node({ | |
| event, | |
| options, | |
| state, | |
| route: null, | |
| node: default_error, | |
| $session, | |
| stuff: layout_loaded ? layout_loaded.stuff : {}, | |
| is_error: true, | |
| is_leaf: false, | |
| status, | |
| error: error2 | |
| }); | |
| branch.push(layout_loaded, error_loaded); | |
| stuff = error_loaded.stuff; | |
| } | |
| return await render_response({ | |
| options, | |
| state, | |
| $session, | |
| page_config: { | |
| hydrate: options.hydrate, | |
| router: options.router | |
| }, | |
| stuff, | |
| status, | |
| error: error2, | |
| branch, | |
| event, | |
| resolve_opts | |
| }); | |
| } catch (err) { | |
| const error3 = coalesce_to_error(err); | |
| options.handle_error(error3, event); | |
| return new Response(error3.stack, { | |
| status: 500 | |
| }); | |
| } | |
| } | |
| async function respond$1(opts) { | |
| const { event, options, state, $session, route, resolve_opts } = opts; | |
| let nodes; | |
| if (!resolve_opts.ssr) { | |
| return await render_response({ | |
| ...opts, | |
| branch: [], | |
| page_config: { | |
| hydrate: true, | |
| router: true | |
| }, | |
| status: 200, | |
| error: null, | |
| event, | |
| stuff: {} | |
| }); | |
| } | |
| try { | |
| nodes = await Promise.all(route.a.map((n) => n == void 0 ? n : options.manifest._.nodes[n]())); | |
| } catch (err) { | |
| const error3 = coalesce_to_error(err); | |
| options.handle_error(error3, event); | |
| return await respond_with_error({ | |
| event, | |
| options, | |
| state, | |
| $session, | |
| status: 500, | |
| error: error3, | |
| resolve_opts | |
| }); | |
| } | |
| const leaf = nodes[nodes.length - 1].module; | |
| let page_config = get_page_config(leaf, options); | |
| if (state.prerendering) { | |
| const should_prerender = leaf.prerender ?? options.prerender.default; | |
| if (!should_prerender) { | |
| return new Response(void 0, { | |
| status: 204 | |
| }); | |
| } | |
| } | |
| let branch = []; | |
| let status = 200; | |
| let error2 = null; | |
| let set_cookie_headers = []; | |
| let stuff = {}; | |
| ssr: { | |
| for (let i = 0; i < nodes.length; i += 1) { | |
| const node = nodes[i]; | |
| let loaded; | |
| if (node) { | |
| try { | |
| loaded = await load_node({ | |
| ...opts, | |
| node, | |
| stuff, | |
| is_error: false, | |
| is_leaf: i === nodes.length - 1 | |
| }); | |
| set_cookie_headers = set_cookie_headers.concat(loaded.set_cookie_headers); | |
| if (loaded.loaded.redirect) { | |
| return with_cookies(new Response(void 0, { | |
| status: loaded.loaded.status, | |
| headers: { | |
| location: loaded.loaded.redirect | |
| } | |
| }), set_cookie_headers); | |
| } | |
| if (loaded.loaded.error) { | |
| ({ status, error: error2 } = loaded.loaded); | |
| } | |
| } catch (err) { | |
| const e = coalesce_to_error(err); | |
| options.handle_error(e, event); | |
| status = 500; | |
| error2 = e; | |
| } | |
| if (loaded && !error2) { | |
| branch.push(loaded); | |
| } | |
| if (error2) { | |
| while (i--) { | |
| if (route.b[i]) { | |
| const index = route.b[i]; | |
| const error_node = await options.manifest._.nodes[index](); | |
| let node_loaded; | |
| let j = i; | |
| while (!(node_loaded = branch[j])) { | |
| j -= 1; | |
| } | |
| try { | |
| const error_loaded = await load_node({ | |
| ...opts, | |
| node: error_node, | |
| stuff: node_loaded.stuff, | |
| is_error: true, | |
| is_leaf: false, | |
| status, | |
| error: error2 | |
| }); | |
| if (error_loaded.loaded.error) { | |
| continue; | |
| } | |
| page_config = get_page_config(error_node.module, options); | |
| branch = branch.slice(0, j + 1).concat(error_loaded); | |
| stuff = { ...node_loaded.stuff, ...error_loaded.stuff }; | |
| break ssr; | |
| } catch (err) { | |
| const e = coalesce_to_error(err); | |
| options.handle_error(e, event); | |
| continue; | |
| } | |
| } | |
| } | |
| return with_cookies(await respond_with_error({ | |
| event, | |
| options, | |
| state, | |
| $session, | |
| status, | |
| error: error2, | |
| resolve_opts | |
| }), set_cookie_headers); | |
| } | |
| } | |
| if (loaded && loaded.loaded.stuff) { | |
| stuff = { | |
| ...stuff, | |
| ...loaded.loaded.stuff | |
| }; | |
| } | |
| } | |
| } | |
| try { | |
| return with_cookies(await render_response({ | |
| ...opts, | |
| stuff, | |
| event, | |
| page_config, | |
| status, | |
| error: error2, | |
| branch: branch.filter(Boolean) | |
| }), set_cookie_headers); | |
| } catch (err) { | |
| const error3 = coalesce_to_error(err); | |
| options.handle_error(error3, event); | |
| return with_cookies(await respond_with_error({ | |
| ...opts, | |
| status: 500, | |
| error: error3 | |
| }), set_cookie_headers); | |
| } | |
| } | |
| function get_page_config(leaf, options) { | |
| if ("ssr" in leaf) { | |
| throw new Error("`export const ssr` has been removed \u2014 use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle"); | |
| } | |
| return { | |
| router: "router" in leaf ? !!leaf.router : options.router, | |
| hydrate: "hydrate" in leaf ? !!leaf.hydrate : options.hydrate | |
| }; | |
| } | |
| function with_cookies(response, set_cookie_headers) { | |
| if (set_cookie_headers.length) { | |
| set_cookie_headers.forEach((value) => { | |
| response.headers.append("set-cookie", value); | |
| }); | |
| } | |
| return response; | |
| } | |
| async function render_page(event, route, options, state, resolve_opts) { | |
| if (state.initiator === route) { | |
| return new Response(`Not found: ${event.url.pathname}`, { | |
| status: 404 | |
| }); | |
| } | |
| if (route.shadow) { | |
| const type = negotiate(event.request.headers.get("accept") || "text/html", [ | |
| "text/html", | |
| "application/json" | |
| ]); | |
| if (type === "application/json") { | |
| return render_endpoint(event, await route.shadow()); | |
| } | |
| } | |
| const $session = await options.hooks.getSession(event); | |
| return respond$1({ | |
| event, | |
| options, | |
| state, | |
| $session, | |
| resolve_opts, | |
| route | |
| }); | |
| } | |
| function negotiate(accept, types) { | |
| const parts = accept.split(",").map((str, i) => { | |
| const match = /([^/]+)\/([^;]+)(?:;q=([0-9.]+))?/.exec(str); | |
| if (match) { | |
| const [, type, subtype, q = "1"] = match; | |
| return { type, subtype, q: +q, i }; | |
| } | |
| throw new Error(`Invalid Accept header: ${accept}`); | |
| }).sort((a, b) => { | |
| if (a.q !== b.q) { | |
| return b.q - a.q; | |
| } | |
| if (a.subtype === "*" !== (b.subtype === "*")) { | |
| return a.subtype === "*" ? 1 : -1; | |
| } | |
| if (a.type === "*" !== (b.type === "*")) { | |
| return a.type === "*" ? 1 : -1; | |
| } | |
| return a.i - b.i; | |
| }); | |
| let accepted; | |
| let min_priority = Infinity; | |
| for (const mimetype of types) { | |
| const [type, subtype] = mimetype.split("/"); | |
| const priority = parts.findIndex((part) => (part.type === type || part.type === "*") && (part.subtype === subtype || part.subtype === "*")); | |
| if (priority !== -1 && priority < min_priority) { | |
| accepted = mimetype; | |
| min_priority = priority; | |
| } | |
| } | |
| return accepted; | |
| } | |
| function exec(match, names, types, matchers) { | |
| const params = {}; | |
| for (let i = 0; i < names.length; i += 1) { | |
| const name = names[i]; | |
| const type = types[i]; | |
| const value = match[i + 1] || ""; | |
| if (type) { | |
| const matcher = matchers[type]; | |
| if (!matcher) | |
| throw new Error(`Missing "${type}" param matcher`); | |
| if (!matcher(value)) | |
| return; | |
| } | |
| params[name] = value; | |
| } | |
| return params; | |
| } | |
| const DATA_SUFFIX = "/__data.json"; | |
| const default_transform = ({ html }) => html; | |
| async function respond(request, options, state) { | |
| var _a, _b, _c, _d; | |
| let url = new URL(request.url); | |
| const { parameter, allowed } = options.method_override; | |
| const method_override = (_a = url.searchParams.get(parameter)) == null ? void 0 : _a.toUpperCase(); | |
| if (method_override) { | |
| if (request.method === "POST") { | |
| if (allowed.includes(method_override)) { | |
| request = new Proxy(request, { | |
| get: (target, property, _receiver) => { | |
| if (property === "method") | |
| return method_override; | |
| return Reflect.get(target, property, target); | |
| } | |
| }); | |
| } else { | |
| const verb = allowed.length === 0 ? "enabled" : "allowed"; | |
| const body = `${parameter}=${method_override} is not ${verb}. See https://kit.svelte.dev/docs/configuration#methodoverride`; | |
| return new Response(body, { | |
| status: 400 | |
| }); | |
| } | |
| } else { | |
| throw new Error(`${parameter}=${method_override} is only allowed with POST requests`); | |
| } | |
| } | |
| let decoded; | |
| try { | |
| decoded = decodeURI(url.pathname); | |
| } catch { | |
| return new Response("Malformed URI", { status: 400 }); | |
| } | |
| let route = null; | |
| let params = {}; | |
| if (options.paths.base && !((_b = state.prerendering) == null ? void 0 : _b.fallback)) { | |
| if (!decoded.startsWith(options.paths.base)) { | |
| return new Response("Not found", { status: 404 }); | |
| } | |
| decoded = decoded.slice(options.paths.base.length) || "/"; | |
| } | |
| const is_data_request = decoded.endsWith(DATA_SUFFIX); | |
| if (is_data_request) { | |
| const data_suffix_length = DATA_SUFFIX.length - (options.trailing_slash === "always" ? 1 : 0); | |
| decoded = decoded.slice(0, -data_suffix_length) || "/"; | |
| url = new URL(url.origin + url.pathname.slice(0, -data_suffix_length) + url.search); | |
| } | |
| if (!((_c = state.prerendering) == null ? void 0 : _c.fallback)) { | |
| const matchers = await options.manifest._.matchers(); | |
| for (const candidate of options.manifest._.routes) { | |
| const match = candidate.pattern.exec(decoded); | |
| if (!match) | |
| continue; | |
| const matched = exec(match, candidate.names, candidate.types, matchers); | |
| if (matched) { | |
| route = candidate; | |
| params = decode_params(matched); | |
| break; | |
| } | |
| } | |
| } | |
| if (route) { | |
| if (route.type === "page") { | |
| const normalized = normalize_path(url.pathname, options.trailing_slash); | |
| if (normalized !== url.pathname && !((_d = state.prerendering) == null ? void 0 : _d.fallback)) { | |
| return new Response(void 0, { | |
| status: 301, | |
| headers: { | |
| "x-sveltekit-normalize": "1", | |
| location: (normalized.startsWith("//") ? url.origin + normalized : normalized) + (url.search === "?" ? "" : url.search) | |
| } | |
| }); | |
| } | |
| } else if (is_data_request) { | |
| return new Response(void 0, { | |
| status: 404 | |
| }); | |
| } | |
| } | |
| const event = { | |
| get clientAddress() { | |
| if (!state.getClientAddress) { | |
| throw new Error(`${"@sveltejs/adapter-static"} does not specify getClientAddress. Please raise an issue`); | |
| } | |
| Object.defineProperty(event, "clientAddress", { | |
| value: state.getClientAddress() | |
| }); | |
| return event.clientAddress; | |
| }, | |
| locals: {}, | |
| params, | |
| platform: state.platform, | |
| request, | |
| routeId: route && route.id, | |
| url | |
| }; | |
| const removed = (property, replacement, suffix = "") => ({ | |
| get: () => { | |
| throw new Error(`event.${property} has been replaced by event.${replacement}` + suffix); | |
| } | |
| }); | |
| const details = ". See https://github.com/sveltejs/kit/pull/3384 for details"; | |
| const body_getter = { | |
| get: () => { | |
| throw new Error("To access the request body use the text/json/arrayBuffer/formData methods, e.g. `body = await request.json()`" + details); | |
| } | |
| }; | |
| Object.defineProperties(event, { | |
| method: removed("method", "request.method", details), | |
| headers: removed("headers", "request.headers", details), | |
| origin: removed("origin", "url.origin"), | |
| path: removed("path", "url.pathname"), | |
| query: removed("query", "url.searchParams"), | |
| body: body_getter, | |
| rawBody: body_getter | |
| }); | |
| let resolve_opts = { | |
| ssr: true, | |
| transformPage: default_transform | |
| }; | |
| try { | |
| const response = await options.hooks.handle({ | |
| event, | |
| resolve: async (event2, opts) => { | |
| var _a2; | |
| if (opts) { | |
| resolve_opts = { | |
| ssr: opts.ssr !== false, | |
| transformPage: opts.transformPage || default_transform | |
| }; | |
| } | |
| if ((_a2 = state.prerendering) == null ? void 0 : _a2.fallback) { | |
| return await render_response({ | |
| event: event2, | |
| options, | |
| state, | |
| $session: await options.hooks.getSession(event2), | |
| page_config: { router: true, hydrate: true }, | |
| stuff: {}, | |
| status: 200, | |
| error: null, | |
| branch: [], | |
| resolve_opts: { | |
| ...resolve_opts, | |
| ssr: false | |
| } | |
| }); | |
| } | |
| if (route) { | |
| let response2; | |
| if (is_data_request && route.type === "page" && route.shadow) { | |
| response2 = await render_endpoint(event2, await route.shadow()); | |
| if (request.headers.has("x-sveltekit-load")) { | |
| if (response2.status >= 300 && response2.status < 400) { | |
| const location = response2.headers.get("location"); | |
| if (location) { | |
| const headers = new Headers(response2.headers); | |
| headers.set("x-sveltekit-location", location); | |
| response2 = new Response(void 0, { | |
| status: 204, | |
| headers | |
| }); | |
| } | |
| } | |
| } | |
| } else { | |
| response2 = route.type === "endpoint" ? await render_endpoint(event2, await route.load()) : await render_page(event2, route, options, state, resolve_opts); | |
| } | |
| if (response2) { | |
| if (response2.status === 200 && response2.headers.has("etag")) { | |
| let if_none_match_value = request.headers.get("if-none-match"); | |
| if (if_none_match_value == null ? void 0 : if_none_match_value.startsWith('W/"')) { | |
| if_none_match_value = if_none_match_value.substring(2); | |
| } | |
| const etag = response2.headers.get("etag"); | |
| if (if_none_match_value === etag) { | |
| const headers = new Headers({ etag }); | |
| for (const key2 of [ | |
| "cache-control", | |
| "content-location", | |
| "date", | |
| "expires", | |
| "vary" | |
| ]) { | |
| const value = response2.headers.get(key2); | |
| if (value) | |
| headers.set(key2, value); | |
| } | |
| return new Response(void 0, { | |
| status: 304, | |
| headers | |
| }); | |
| } | |
| } | |
| return response2; | |
| } | |
| } | |
| if (!state.initiator) { | |
| const $session = await options.hooks.getSession(event2); | |
| return await respond_with_error({ | |
| event: event2, | |
| options, | |
| state, | |
| $session, | |
| status: 404, | |
| error: new Error(`Not found: ${event2.url.pathname}`), | |
| resolve_opts | |
| }); | |
| } | |
| if (state.prerendering) { | |
| return new Response("not found", { status: 404 }); | |
| } | |
| return await fetch(request); | |
| }, | |
| get request() { | |
| throw new Error("request in handle has been replaced with event" + details); | |
| } | |
| }); | |
| if (response && !(response instanceof Response)) { | |
| throw new Error("handle must return a Response object" + details); | |
| } | |
| return response; | |
| } catch (e) { | |
| const error2 = coalesce_to_error(e); | |
| options.handle_error(error2, event); | |
| try { | |
| const $session = await options.hooks.getSession(event); | |
| return await respond_with_error({ | |
| event, | |
| options, | |
| state, | |
| $session, | |
| status: 500, | |
| error: error2, | |
| resolve_opts | |
| }); | |
| } catch (e2) { | |
| const error3 = coalesce_to_error(e2); | |
| return new Response(options.dev ? error3.stack : error3.message, { | |
| status: 500 | |
| }); | |
| } | |
| } | |
| } | |
| function set_prerendering(value) { | |
| } | |
| const template = ({ head, body, assets: assets2, nonce }) => '<!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <link rel="icon" href="' + assets2 + '/favicon.png" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n <script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"><\/script>\n ' + head + '\n </head>\n <body class="">\n ' + body + "\n </body> \n</html>\n"; | |
| let read = null; | |
| set_paths({ "base": "/static", "assets": "" }); | |
| let default_protocol = "https"; | |
| function override(settings) { | |
| default_protocol = settings.protocol || default_protocol; | |
| set_paths(settings.paths); | |
| set_prerendering(settings.prerendering); | |
| read = settings.read; | |
| } | |
| class Server { | |
| constructor(manifest) { | |
| this.options = { | |
| csp: { "mode": "auto", "directives": { "upgrade-insecure-requests": false, "block-all-mixed-content": false } }, | |
| dev: false, | |
| floc: false, | |
| get_stack: (error2) => String(error2), | |
| handle_error: (error2, event) => { | |
| this.options.hooks.handleError({ | |
| error: error2, | |
| event, | |
| get request() { | |
| throw new Error("request in handleError has been replaced with event. See https://github.com/sveltejs/kit/pull/3384 for details"); | |
| } | |
| }); | |
| error2.stack = this.options.get_stack(error2); | |
| }, | |
| hooks: null, | |
| hydrate: true, | |
| manifest, | |
| method_override: { "parameter": "_method", "allowed": [] }, | |
| paths: { base, assets }, | |
| prefix: assets + "/_app/immutable/", | |
| prerender: { | |
| default: true, | |
| enabled: true | |
| }, | |
| read, | |
| root: Root, | |
| service_worker: null, | |
| router: true, | |
| template, | |
| template_contains_nonce: false, | |
| trailing_slash: "never" | |
| }; | |
| } | |
| async respond(request, options = {}) { | |
| if (!(request instanceof Request)) { | |
| throw new Error("The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details"); | |
| } | |
| if (!this.options.hooks) { | |
| const module = await import("./chunks/hooks-1c45ba0b.js"); | |
| this.options.hooks = { | |
| getSession: module.getSession || (() => ({})), | |
| handle: module.handle || (({ event, resolve: resolve2 }) => resolve2(event)), | |
| handleError: module.handleError || (({ error: error2 }) => console.error(error2.stack)), | |
| externalFetch: module.externalFetch || fetch | |
| }; | |
| } | |
| return respond(request, this.options, options); | |
| } | |
| } | |
| export { Server, override }; | |