Initial commit

This commit is contained in:
mats committed 2026-09-22 08:41:20 +02:00
commit 89053153cc
8152 files changed
+2086461

No files matched your search

+259
View File
@@ -0,0 +1,259 @@
import { r as __toESM } from "./rolldown-runtime-DC62tzP2.js";
import { t as require_react } from "./react.js";
import { t as require_shim } from "./shim-BX6a9SD7.js";
//#region node_modules/regexparam/dist/index.mjs
/**
* @param {string|RegExp} input The route pattern
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
*/
function parse(input, loose) {
if (input instanceof RegExp) return {
keys: false,
pattern: input
};
var c, o, tmp, ext, keys = [], pattern = "", arr = input.split("/");
arr[0] || arr.shift();
while (tmp = arr.shift()) {
c = tmp[0];
if (c === "*") {
keys.push(c);
pattern += tmp[1] === "?" ? "(?:/(.*))?" : "/(.*)";
} else if (c === ":") {
o = tmp.indexOf("?", 1);
ext = tmp.indexOf(".", 1);
keys.push(tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length));
pattern += !!~o && !~ext ? "(?:/([^/]+?))?" : "/([^/]+?)";
if (!!~ext) pattern += (!!~o ? "?" : "") + "\\" + tmp.substring(ext);
} else pattern += "/" + tmp;
}
return {
keys,
pattern: new RegExp("^" + pattern + (loose ? "(?=$|/)" : "/?$"), "i")
};
}
//#endregion
//#region node_modules/wouter/src/use-sync-external-store.js
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
var import_shim = require_shim();
//#endregion
//#region node_modules/wouter/src/react-deps.js
var useBuiltinInsertionEffect = import_react.useInsertionEffect;
var useIsomorphicLayoutEffect = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined") ? import_react.useLayoutEffect : import_react.useEffect;
var useInsertionEffect = useBuiltinInsertionEffect || useIsomorphicLayoutEffect;
var useEvent = (fn) => {
const ref = import_react.useRef([fn, (...args) => ref[0](...args)]).current;
useInsertionEffect(() => {
ref[0] = fn;
});
return ref[1];
};
//#endregion
//#region node_modules/wouter/src/use-browser-location.js
/**
* History API docs @see https://developer.mozilla.org/en-US/docs/Web/API/History
*/
var events = [
"popstate",
"pushState",
"replaceState",
"hashchange"
];
var listeners = [];
var onLocationChange = () => listeners.forEach((callback) => callback());
var subscribeToLocationUpdates = (callback) => {
if (listeners.push(callback) === 1) events.forEach((event) => addEventListener(event, onLocationChange));
return () => {
listeners = listeners.filter((listener) => listener !== callback);
if (!listeners.length) events.forEach((event) => removeEventListener(event, onLocationChange));
};
};
var useLocationProperty = (fn, ssrFn) => (0, import_shim.useSyncExternalStore)(subscribeToLocationUpdates, fn, ssrFn);
var currentSearch = () => location.search;
var useSearch$1 = ({ ssrSearch } = {}) => useLocationProperty(currentSearch, ssrSearch != null ? () => ssrSearch : currentSearch);
var currentPathname = () => location.pathname;
var usePathname = ({ ssrPath } = {}) => useLocationProperty(currentPathname, ssrPath != null ? () => ssrPath : currentPathname);
var navigate = (to, { replace = false, state = null } = {}) => history[replace ? "replaceState" : "pushState"](state, "", to);
var useBrowserLocation = (opts) => [usePathname(opts), navigate];
var patchKey = Symbol.for("wouter_v3");
if (typeof history !== "undefined" && typeof window[patchKey] === "undefined") {
for (const type of ["pushState", "replaceState"]) {
const original = history[type];
history[type] = function() {
const result = original.apply(this, arguments);
const event = new Event(type);
event.arguments = arguments;
dispatchEvent(event);
return result;
};
}
Object.defineProperty(window, patchKey, { value: true });
}
//#endregion
//#region node_modules/wouter/src/paths.js
/**
* When basepath is `undefined` or '/' it is ignored (we assume it's empty string)
*/
var baseDefaults = (base = "") => base === "/" ? "" : base;
var absolutePath = (to, base) => to[0] === "~" ? to.slice(1) : baseDefaults(base) + to;
var relativePath = (base, path) => {
base = unescape(baseDefaults(base));
path = unescape(path);
return !base || !path.toLowerCase().indexOf(base.toLowerCase()) ? path.slice(base.length) || "/" : "~" + path;
};
var unescape = (str) => {
try {
return str.includes("%") ? decodeURI(str) : str;
} catch (_e) {
return str;
}
};
var sanitizeSearch = (search) => unescape(search[0] === "?" ? search.slice(1) : search);
//#endregion
//#region node_modules/wouter/src/index.js
var defaultRouter = {
hook: useBrowserLocation,
searchHook: useSearch$1,
parser: parse,
base: "",
ssrPath: void 0,
ssrSearch: void 0,
ssrContext: void 0,
hrefs: (x) => x,
aroundNav: (n, t, o) => n(t, o)
};
var RouterCtx = (0, import_react.createContext)(defaultRouter);
var useRouter = () => (0, import_react.useContext)(RouterCtx);
/**
* Parameters context. Used by `useParams()` to get the
* matched params from the innermost `Route` component.
*/
var Params0 = {};
var ParamsCtx = (0, import_react.createContext)(Params0);
var useParams = () => (0, import_react.useContext)(ParamsCtx);
var usePathnameFromRouter = (router, base = router.base) => relativePath(base, router.hook(router)[0]);
var useLocationFromRouter = (router) => {
const [location, navigate] = router.hook(router);
return [relativePath(router.base, location), useEvent((to, opts) => router.aroundNav(navigate, absolutePath(to, router.base), opts))];
};
var useLocation = () => useLocationFromRouter(useRouter());
var useSearch = () => {
const router = useRouter();
return sanitizeSearch(router.searchHook(router));
};
var matchRoute = (parser, route, path, loose) => {
const { pattern, keys } = route instanceof RegExp ? { pattern: route } : parser(route || "*", loose);
const result = pattern.exec(path);
if (!result) return [false, null];
const params = {};
for (let i = 1; i < result.length; i++) params[i - 1] = result[i];
if (keys) for (let i = 0; i < keys.length; i++) params[keys[i]] = result[i + 1];
else Object.assign(params, result.groups);
return loose ? [
true,
params,
result[0]
] : [true, params];
};
var useRoute = (pattern) => {
const router = useRouter();
const absolute = /^~\//.test(pattern);
return matchRoute(router.parser, absolute ? pattern.slice(1) : pattern, usePathnameFromRouter(router, absolute ? "" : router.base));
};
var Router = ({ children, ...props }) => {
const parent_ = useRouter();
const parent = props.hook ? defaultRouter : parent_;
let value = parent;
if (props.ssrPath) {
const [path, search = props.ssrSearch ?? ""] = props.ssrPath.split("?");
if (path) props.ssrSearch = search, props.ssrPath = path;
}
props.hrefs = props.hrefs ?? props.hook?.hrefs;
props.searchHook = props.searchHook ?? props.hook?.searchHook;
let ref = (0, import_react.useRef)(parent), prev = ref.current, next = prev;
for (let k in parent) {
const option = k === "base" ? parent[k] + (props[k] ?? "") : props[k] ?? parent[k];
if (option !== next[k]) {
if (prev === next) ref.current = next = { ...next };
next[k] = option;
}
if (option !== parent[k] || option !== value[k]) value = next;
}
return (0, import_react.createElement)(RouterCtx.Provider, { value }, children);
};
var h_route = ({ children, component }, params) => {
if (component) return (0, import_react.createElement)(component, { params });
return typeof children === "function" ? children(params) : children;
};
var useCachedParams = (value) => {
let prev = (0, import_react.useRef)(Params0);
const curr = prev.current, keys = Object.keys(value);
return prev.current = keys.length !== Object.keys(curr).length || keys.some((k) => value[k] !== curr[k]) ? value : curr;
};
function useSearchParams() {
const [location, navigate] = useLocation();
const search = useSearch();
const searchParams = (0, import_react.useMemo)(() => new URLSearchParams(search), [search]);
let tempSearchParams = searchParams;
return [searchParams, useEvent((nextInit, options) => {
tempSearchParams = new URLSearchParams(typeof nextInit === "function" ? nextInit(tempSearchParams) : nextInit);
const paramsStr = tempSearchParams.toString();
navigate(location + (paramsStr ? "?" + paramsStr : ""), options);
})];
}
var Route = ({ path, nest, match, ...renderProps }) => {
const router = useRouter();
const location = usePathnameFromRouter(router);
const [matches, routeParams, base] = match ?? matchRoute(router.parser, path, location, nest);
const params = useCachedParams({
...useParams(),
...routeParams
});
if (!matches) return null;
const children = h_route(renderProps, params);
return (0, import_react.createElement)(ParamsCtx.Provider, { value: params }, base ? (0, import_react.createElement)(Router, { base }, children) : children);
};
var Link = (0, import_react.forwardRef)((props, ref) => {
const router = useRouter();
const [currentPath, navigate] = useLocationFromRouter(router);
const { to = "", href: targetPath = to, onClick: _onClick, asChild, children, className: cls, replace, state, transition, ...linkProps } = props;
linkProps.onClick = useEvent((event) => {
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || event.button !== 0) return;
_onClick?.(event);
if (!event.defaultPrevented) {
event.preventDefault();
navigate(targetPath, props);
}
});
linkProps.href = router.hrefs(targetPath[0] === "~" ? targetPath.slice(1) : router.base + targetPath, router);
if (cls !== void 0) linkProps.className = cls?.call ? cls(currentPath === targetPath) : cls;
if (ref) linkProps.ref = ref;
return asChild && (0, import_react.isValidElement)(children) ? (0, import_react.cloneElement)(children, linkProps) : (0, import_react.createElement)("a", linkProps, children);
});
var flattenChildren = (children, result = []) => {
if (Array.isArray(children)) for (const c of children) flattenChildren(c && c.type === import_react.Fragment ? c.props.children : c, result);
else result.push(children);
return result;
};
var Switch = ({ children, location }) => {
const router = useRouter();
const originalLocation = usePathnameFromRouter(router);
for (const element of flattenChildren(children)) {
let match = 0;
if ((0, import_react.isValidElement)(element) && (match = matchRoute(router.parser, element.props.path, location || originalLocation, element.props.nest))[0]) return (0, import_react.cloneElement)(element, { match });
}
return null;
};
var Redirect = (props) => {
const { to, href = to } = props;
const router = useRouter();
const [, navigate] = useLocationFromRouter(router);
const redirect = useEvent(() => navigate(to || href, props));
const { ssrContext } = router;
useIsomorphicLayoutEffect(() => {
redirect();
}, []);
if (ssrContext) ssrContext.redirectTo = to;
return null;
};
//#endregion
export { Link, Redirect, Route, Router, Switch, matchRoute, useLocation, useParams, useRoute, useRouter, useSearch, useSearchParams };