Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.

This commit is contained in:
becarta
2025-05-23 12:43:00 +02:00
parent f40db0f5c9
commit a544759a3b
11127 changed files with 1647032 additions and 0 deletions

8
node_modules/astro/dist/vite-plugin-html/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
export default function html(): {
name: string;
options(options: any): void;
transform(source: string, id: string): Promise<{
code: string;
map: import("magic-string").SourceMap;
} | undefined>;
};

16
node_modules/astro/dist/vite-plugin-html/index.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import { transform } from "./transform/index.js";
function html() {
return {
name: "astro:html",
options(options) {
options.plugins = options.plugins?.filter((p) => p.name !== "vite:build-html");
},
async transform(source, id) {
if (!id.endsWith(".html")) return;
return await transform(source, id);
}
};
}
export {
html as default
};

View File

@@ -0,0 +1,7 @@
import type { Root } from 'hast';
import type MagicString from 'magic-string';
import type { Plugin } from 'unified';
declare const rehypeEscape: Plugin<[{
s: MagicString;
}], Root>;
export default rehypeEscape;

View File

@@ -0,0 +1,30 @@
import { visit } from "unist-util-visit";
import { escapeTemplateLiteralCharacters, needsEscape, replaceAttribute } from "./utils.js";
const rehypeEscape = ({ s }) => {
return (tree) => {
visit(tree, (node) => {
if (node.type === "text" || node.type === "comment") {
if (needsEscape(node.value)) {
s.overwrite(
node.position.start.offset,
node.position.end.offset,
escapeTemplateLiteralCharacters(node.value)
);
}
} else if (node.type === "element") {
if (!node.properties) return;
for (let [key, value] of Object.entries(node.properties)) {
key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
const newKey = needsEscape(key) ? escapeTemplateLiteralCharacters(key) : key;
const newValue = needsEscape(value) ? escapeTemplateLiteralCharacters(value) : value;
if (newKey === key && newValue === value) continue;
replaceAttribute(s, node, key, value === "" ? newKey : `${newKey}="${newValue}"`);
}
}
});
};
};
var escape_default = rehypeEscape;
export {
escape_default as default
};

View File

@@ -0,0 +1,4 @@
export declare function transform(code: string, id: string): Promise<{
code: string;
map: import("magic-string").SourceMap;
}>;

View File

@@ -0,0 +1,21 @@
import MagicString from "magic-string";
import { rehype } from "rehype";
import { VFile } from "vfile";
import escape from "./escape.js";
import slots, { SLOT_PREFIX } from "./slots.js";
async function transform(code, id) {
const s = new MagicString(code, { filename: id });
const parser = rehype().data("settings", { fragment: true }).use(escape, { s }).use(slots, { s });
const vfile = new VFile({ value: code, path: id });
await parser.process(vfile);
s.prepend(`function render({ slots: ${SLOT_PREFIX} }) {
return \``);
s.append('`\n }\nrender["astro:html"] = true;\nexport default render;');
return {
code: s.toString(),
map: s.generateMap({ hires: "boundary" })
};
}
export {
transform
};

View File

@@ -0,0 +1,8 @@
import type { Root } from 'hast';
import type { Plugin } from 'unified';
import type MagicString from 'magic-string';
declare const rehypeSlots: Plugin<[{
s: MagicString;
}], Root>;
export default rehypeSlots;
export declare const SLOT_PREFIX = "___SLOTS___";

View File

@@ -0,0 +1,28 @@
import { visit } from "unist-util-visit";
import { escapeTemplateLiteralCharacters } from "./utils.js";
const rehypeSlots = ({ s }) => {
return (tree, file) => {
visit(tree, (node) => {
if (node.type === "element" && node.tagName === "slot") {
if (typeof node.properties?.["is:inline"] !== "undefined") return;
const name = node.properties?.["name"] ?? "default";
const start = node.position?.start.offset ?? 0;
const end = node.position?.end.offset ?? 0;
const first = node.children.at(0) ?? node;
const last = node.children.at(-1) ?? node;
const text = file.value.slice(first.position?.start.offset ?? 0, last.position?.end.offset ?? 0).toString();
s.overwrite(
start,
end,
`\${${SLOT_PREFIX}["${name}"] ?? \`${escapeTemplateLiteralCharacters(text).trim()}\`}`
);
}
});
};
};
var slots_default = rehypeSlots;
const SLOT_PREFIX = `___SLOTS___`;
export {
SLOT_PREFIX,
slots_default as default
};

View File

@@ -0,0 +1,5 @@
import type { Element } from 'hast';
import type MagicString from 'magic-string';
export declare function replaceAttribute(s: MagicString, node: Element, key: string, newValue: string): MagicString | undefined;
export declare function needsEscape(value: any): value is string;
export declare function escapeTemplateLiteralCharacters(value: string): string;

View File

@@ -0,0 +1,47 @@
const splitAttrsTokenizer = /([${}@\w:\-]*)\s*=\s*?(['"]?)(.*?)\2\s+/g;
function replaceAttribute(s, node, key, newValue) {
splitAttrsTokenizer.lastIndex = 0;
const text = s.original.slice(node.position?.start.offset ?? 0, node.position?.end.offset ?? 0).toString();
const offset = text.indexOf(key);
if (offset === -1) return;
const start = node.position.start.offset + offset;
const tokens = text.slice(offset).split(splitAttrsTokenizer);
const token = tokens[0].replace(/([^>])>[\s\S]*$/gm, "$1");
if (token.trim() === key) {
const end = start + key.length;
return s.overwrite(start, end, newValue, { contentOnly: true });
} else {
const length = token.length;
const end = start + length;
return s.overwrite(start, end, newValue, { contentOnly: true });
}
}
const NEEDS_ESCAPE_RE = /[`\\]|\$\{/g;
function needsEscape(value) {
NEEDS_ESCAPE_RE.lastIndex = 0;
return typeof value === "string" && NEEDS_ESCAPE_RE.test(value);
}
function escapeTemplateLiteralCharacters(value) {
NEEDS_ESCAPE_RE.lastIndex = 0;
let char;
let startIndex = 0;
let segment = "";
let text = "";
while ([char] = NEEDS_ESCAPE_RE.exec(value) ?? []) {
if (!char) {
text += value.slice(startIndex);
break;
}
const endIndex = NEEDS_ESCAPE_RE.lastIndex - char.length;
const prefix = segment === "\\" ? "" : "\\";
segment = prefix + char;
text += value.slice(startIndex, endIndex) + segment;
startIndex = NEEDS_ESCAPE_RE.lastIndex;
}
return text;
}
export {
escapeTemplateLiteralCharacters,
needsEscape,
replaceAttribute
};