crossroad 3.0.6 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,151 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import React$1 from "react";
4
+ import { ReactElement, ReactNode } from "react";
5
+
6
+ export interface RouterProps {
7
+ scrollUp?: boolean;
8
+ url?: string;
9
+ children?: React$1.ReactNode;
10
+ }
11
+ declare const _default: ({
12
+ scrollUp,
13
+ url: baseUrl,
14
+ children,
15
+ }: RouterProps) => import("react/jsx-runtime").JSX.Element;
16
+ export type ParseParamType<T extends string> =
17
+ T extends `${infer Name}<${infer Type}>`
18
+ ? Type extends "number"
19
+ ? {
20
+ [K in Name]: number;
21
+ }
22
+ : Type extends "string"
23
+ ? {
24
+ [K in Name]: string;
25
+ }
26
+ : Type extends "date"
27
+ ? {
28
+ [K in Name]: Date;
29
+ }
30
+ : Type extends "boolean"
31
+ ? {
32
+ [K in Name]: boolean;
33
+ }
34
+ : {
35
+ [K in Name]: string;
36
+ }
37
+ : {
38
+ [K in T]: string;
39
+ };
40
+ export type ExtractParams<T extends string> =
41
+ T extends `${infer _Prefix}/:${infer Param}/${infer Rest}`
42
+ ? ParseParamType<Param> & ExtractParams<`/${Rest}`>
43
+ : T extends `${infer _Prefix}/:${infer Param}`
44
+ ? ParseParamType<Param>
45
+ : {};
46
+ export type InferParamsFromPath<T extends string> =
47
+ T extends `${string}/:${string}` ? ExtractParams<T> : {};
48
+ export interface RoutePropsBase {
49
+ path?: string;
50
+ scrollUp?: boolean;
51
+ children?: React$1.ReactNode;
52
+ }
53
+ export type RouteProps<
54
+ T extends Record<string, string | number | boolean | Date> = {},
55
+ > = RoutePropsBase &
56
+ (
57
+ | {
58
+ component: React$1.FunctionComponent<T>;
59
+ render?: never;
60
+ }
61
+ | {
62
+ render: (params: T) => React$1.ReactNode;
63
+ component?: never;
64
+ }
65
+ | {
66
+ component?: never;
67
+ render?: never;
68
+ }
69
+ );
70
+ export type RouteType = <P extends string = string>(
71
+ props: RouteProps<InferParamsFromPath<P>> & {
72
+ path?: P;
73
+ },
74
+ ) => React$1.ReactNode;
75
+ declare const _default$1: RouteType;
76
+ export type Query = Record<string, string | string[]>;
77
+ export type Url = {
78
+ path: string;
79
+ query: Query;
80
+ hash?: string;
81
+ params?: Params;
82
+ };
83
+ export type UrlSet = {
84
+ path?: string;
85
+ query?: Query;
86
+ hash?: string;
87
+ };
88
+ export type Params = Record<string, string | number | boolean | Date>;
89
+ export type SetUrlOptions = {
90
+ mode?: "push" | "replace";
91
+ };
92
+ export type NewUrlValue = Url | UrlSet | string;
93
+ export type SetUrl = (
94
+ newUrl: NewUrlValue | ((prev: Url) => NewUrlValue),
95
+ opts?: SetUrlOptions,
96
+ ) => void;
97
+ export interface SwitchProps {
98
+ redirect?:
99
+ | string
100
+ | {
101
+ path: string;
102
+ }
103
+ | ((url: Url) => string);
104
+ children?: React$1.ReactNode;
105
+ }
106
+ declare const _default$2: ({
107
+ redirect,
108
+ children,
109
+ }: SwitchProps) => React$1.ReactElement | null;
110
+ declare const _default$3: import("react").Context<[Url, SetUrl] | undefined>;
111
+ declare const _default$4: () => [Url, SetUrl];
112
+ export type PathUpdater = (path: string) => string;
113
+ export type SetPath = (
114
+ path: string | PathUpdater,
115
+ opts?: SetUrlOptions,
116
+ ) => void;
117
+ declare const _default$5: () => [string, SetPath];
118
+ export type QueryValue = string | string[] | undefined;
119
+ export type SetQueryProp = (
120
+ value: string | ((prev: QueryValue) => string),
121
+ opts?: SetUrlOptions,
122
+ ) => void;
123
+ export type QueryUpdater = (query: Query) => Query | string;
124
+ export type SetQuery = (
125
+ newQuery: Query | string | QueryUpdater,
126
+ opts?: SetUrlOptions,
127
+ ) => void;
128
+ export declare function useQuery(key: string): [QueryValue, SetQueryProp];
129
+ export declare function useQuery(): [Query, SetQuery];
130
+ export type HashUpdater = (hash: string | undefined) => string;
131
+ export type SetHash = (
132
+ hash: string | HashUpdater,
133
+ opts?: SetUrlOptions,
134
+ ) => void;
135
+ declare const _default$6: () => [string | undefined, SetHash];
136
+ export declare function useParams(): Params;
137
+ export declare function useParams<T = string | number | boolean | Date>(
138
+ key: string,
139
+ ): T;
140
+
141
+ export {
142
+ _default as default,
143
+ _default$1 as Route,
144
+ _default$2 as Switch,
145
+ _default$3 as Context,
146
+ _default$4 as useUrl,
147
+ _default$5 as usePath,
148
+ _default$6 as useHash,
149
+ };
150
+
151
+ export {};
package/index.min.js ADDED
@@ -0,0 +1,2 @@
1
+ import{createContext as e,useCallback as r,useContext as t,useEffect as n,useRef as o,useState as a}from"react";var i=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),s=/* @__PURE__ */(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,r)=>("undefined"!=typeof require?require:e)[r]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.")}),c=e(void 0),u=e=>e.length>1?e:e[0],l=e=>{if("string"!=typeof e)return e;const r={query:{}},t=new URL(e,"http://localhost:3000/");r.path=(t.pathname.replace(/\/$/,"")||"/").replaceAll("%3C","<").replaceAll("%3E",">"),r.query={};for(const[n]of t.searchParams)r.query[n]=u(t.searchParams.getAll(n));return t.hash&&(r.hash=t.hash.replace(/^#/,"")),r},f=e=>{if("string"==typeof e)return e;const{path:r,query:t={},hash:n}=e||{};let o=r||"/";const a=new URLSearchParams(Object.entries(t).map(([e,r])=>(Array.isArray(r)?r:[r]).map(r=>[e,r])).flat().filter(([e,r])=>r)).toString();return a&&(o+="?"+a),n&&(o+="#"+n),o},p=()=>"undefined"==typeof window,y=/* @__PURE__ */i(e=>{var r=s("react"),t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c(e,r,n){var s,c={},u=null,l=null;for(s in void 0!==n&&(u=""+n),void 0!==r.key&&(u=""+r.key),void 0!==r.ref&&(l=r.ref),r)o.call(r,s)&&!i.hasOwnProperty(s)&&(c[s]=r[s]);if(e&&e.defaultProps)for(s in r=e.defaultProps)void 0===c[s]&&(c[s]=r[s]);return{$$typeof:t,type:e,key:u,ref:l,props:c,_owner:a.current}}e.Fragment=n,e.jsx=c,e.jsxs=c}),d=/* @__PURE__ */i(e=>{"production"!==process.env.NODE_ENV&&function(){var r=s("react"),t=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),u=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),d=Symbol.for("react.lazy"),h=Symbol.for("react.offscreen"),v=Symbol.iterator;var m=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function g(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=m.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map(function(e){return String(e)});o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}var b=Symbol.for("react.module.reference");function w(e){return e.displayName||"Context"}function _(e){if(null==e)return null;if("number"==typeof e.tag&&g("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case n:return"Portal";case i:return"Profiler";case a:return"StrictMode";case f:return"Suspense";case p:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return w(e)+".Consumer";case c:return w(e._context)+".Provider";case l:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case y:var r=e.displayName||null;return null!==r?r:_(e.type)||"Memo";case d:var t=e,s=t._payload,h=t._init;try{return _(h(s))}catch(v){return null}}return null}var k,S,j,O,R,E,P,x=Object.assign,q=0;function T(){}T.__reactDisabledLog=!0;var $,N=m.ReactCurrentDispatcher;function C(e,r,t){if(void 0===$)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);$=n&&n[1]||""}return"\n"+$+e}var D=!1,A=new("function"==typeof WeakMap?WeakMap:Map);function F(e,r){if(!e||D)return"";var t,n=A.get(e);if(void 0!==n)return n;D=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var a=N.current;N.current=null,function(){if(0===q){k=console.log,S=console.info,j=console.warn,O=console.error,R=console.group,E=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:T,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}q++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(d){t=d}Reflect.construct(e,[],i)}else{try{i.call()}catch(d){t=d}e.call(i.prototype)}}else{try{throw Error()}catch(d){t=d}e()}}catch(h){if(h&&t&&"string"==typeof h.stack){for(var s=h.stack.split("\n"),c=t.stack.split("\n"),u=s.length-1,l=c.length-1;u>=1&&l>=0&&s[u]!==c[l];)l--;for(;u>=1&&l>=0;u--,l--)if(s[u]!==c[l]){if(1!==u||1!==l)do{if(u--,--l<0||s[u]!==c[l]){var f="\n"+s[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&A.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{D=!1,N.current=a,function(){if(0===--q){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:x({},e,{value:k}),info:x({},e,{value:S}),warn:x({},e,{value:j}),error:x({},e,{value:O}),group:x({},e,{value:R}),groupCollapsed:x({},e,{value:E}),groupEnd:x({},e,{value:P})})}q<0&&g("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=o}var p=e?e.displayName||e.name:"",y=p?C(p):"";return"function"==typeof e&&A.set(e,y),y}function I(e,r,t){if(null==e)return"";if("function"==typeof e)return F(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return C(e);switch(e){case f:return C("Suspense");case p:return C("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case l:return F(e.render,!1);case y:return I(e.type,r,t);case d:var o=e,a=o._payload,i=o._init;try{return I(i(a),r,t)}catch(s){}}return""}var L=Object.prototype.hasOwnProperty,U={},W=m.ReactDebugCurrentFrame;function z(e){if(e){var r=e._owner,t=I(e.type,e._source,r?r.type:null);W.setExtraStackFrame(t)}else W.setExtraStackFrame(null)}var J=Array.isArray;function M(e){return J(e)}function Y(e){return""+e}function B(e){if(function(e){try{return Y(e),!1}catch(r){return!0}}(e))return g("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),Y(e)}var V,K,X=m.ReactCurrentOwner,H={key:!0,ref:!0,__self:!0,__source:!0},Z={};function G(e,r,n,o,a){var i,s={},c=null,u=null;for(i in void 0!==n&&(B(n),c=""+n),function(e){if(L.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(B(r.key),c=""+r.key),function(e){if(L.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(u=r.ref,function(e,r){if("string"==typeof e.ref&&X.current&&r&&X.current.stateNode!==r){var t=_(X.current.type);Z[t]||(g('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',_(X.current.type),e.ref),Z[t]=!0)}}(r,a)),r)L.call(r,i)&&!H.hasOwnProperty(i)&&(s[i]=r[i]);if(e&&e.defaultProps){var l=e.defaultProps;for(i in l)void 0===s[i]&&(s[i]=l[i])}if(c||u){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){V||(V=!0,g("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(s,f),u&&function(e,r){var t=function(){K||(K=!0,g("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(s,f)}return function(e,r,n,o,a,i,s){var c={$$typeof:t,type:e,key:r,ref:n,props:s,_owner:i,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(e,c,u,a,o,X.current,s)}var Q=m.ReactCurrentOwner,ee=m.ReactDebugCurrentFrame;function re(e){if(e){var r=e._owner,t=I(e.type,e._source,r?r.type:null);ee.setExtraStackFrame(t)}else ee.setExtraStackFrame(null)}var te=!1;function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===t}function oe(){if(Q.current){var e=_(Q.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}var ae={};function ie(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==Q.current&&(n=" It was passed a child from "+_(e._owner.type)+"."),re(e),g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),re(null)}}}function se(e,r){if("object"==typeof e)if(M(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&ie(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)ne(a.value)&&ie(a.value,r)}}function ce(e){var r=e.type;if(null!=r&&"string"!=typeof r){var t;if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==l&&r.$$typeof!==y)return;t=r.propTypes}if(t){var n=_(r);!function(e,r,t,n,o){var a=Function.call.bind(L);for(var i in e)if(a(e,i)){var s=void 0;try{if("function"!=typeof e[i]){var c=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}s=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(u){s=u}!s||s instanceof Error||(z(o),g("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof s),z(null)),s instanceof Error&&!(s.message in U)&&(U[s.message]=!0,z(o),g("Failed %s type: %s",t,s.message),z(null))}}(t,e.props,"prop",n,e)}else void 0===r.PropTypes||te||(te=!0,g("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",_(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||g("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ue={};function le(e,r,n,s,v,m){var w=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===f||e===p||e===h||"object"==typeof e&&null!==e&&(e.$$typeof===d||e.$$typeof===y||e.$$typeof===c||e.$$typeof===u||e.$$typeof===l||e.$$typeof===b||void 0!==e.getModuleId)}(e);if(!w){var k="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(k+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var S,j=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(v);k+=j||oe(),null===e?S="null":M(e)?S="array":void 0!==e&&e.$$typeof===t?(S="<"+(_(e.type)||"Unknown")+" />",k=" Did you accidentally export a JSX literal instead of a component?"):S=typeof e,g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",S,k)}var O=G(e,r,n,v,m);if(null==O)return O;if(w){var R=r.children;if(void 0!==R)if(s)if(M(R)){for(var E=0;E<R.length;E++)se(R[E],e);Object.freeze&&Object.freeze(R)}else g("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else se(R,e)}if(L.call(r,"key")){var P=_(e),x=Object.keys(r).filter(function(e){return"key"!==e}),q=x.length>0?"{key: someKey, "+x.join(": ..., ")+": ...}":"{key: someKey}";ue[P+q]||(g('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',q,P,x.length>0?"{"+x.join(": ..., ")+": ...}":"{}",P),ue[P+q]=!0)}return e===o?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){re(e),g("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),re(null);break}}null!==e.ref&&(re(e),g("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(O):ce(O),O}var fe=function(e,r,t){return le(e,r,t,!1)},pe=function(e,r,t){return le(e,r,t,!0)};e.Fragment=o,e.jsx=fe,e.jsxs=pe}()}),h=/* @__PURE__ */i((e,r)=>{"production"===process.env.NODE_ENV?r.exports=y():r.exports=d()})();function v(e,r,t={}){let n=JSON.parse(JSON.stringify(l(e))),o=JSON.parse(JSON.stringify(l(r)));if(o.path=o.path.replace(/\/$/,"")||"/",n.path=n.path.replace(/\/$/,"")||"/",n.path.endsWith("*")){n.path=n.path.replace(/\/?\*/,"")||"/";const e=n.path.split("/").filter(Boolean).length;o.path="/"+o.path.slice(1).split("/").slice(0,e).join("/")}if(Object.entries(n.query).length)for(const s in n.query){if(!(s in o.query))return!1;if(n.query[s]&&n.query[s]!==o.query[s])return!1}if(!n.path.includes(":"))return n.path===o.path&&t;if(n.path.split("/").length!==o.path.split("/").length)return!1;const a={},i=n.path.split("/").every((e,r)=>{const n=o.path.split("/")[r];if(e.startsWith(":")){let r=e.slice(1),o="string";r.includes("<")&&([r,o]=r.split("<"),o=o.slice(0,-1));const i=decodeURIComponent(n);return a[r]="number"===o?Number(i):"date"===o?new Date(/^\d+$/.test(i)?Number(i):i):"boolean"===o?"true"===i:i,t}return n===e});return i&&Object.assign(t,a),i&&t}var m=()=>{const e=t(c);if(!e)throw new Error("Wrap your App with <Router>");return e},g=({path:e="*",scrollUp:r,component:t,render:n,children:o})=>{const a=m(),i=v(e,a[0]);if(!i)return null;if(r&&window.scrollTo(0,0),t)o=/* @__PURE__ */ /* @__PURE__ */(0,h.jsx)(t,{...i});else if(n)o=n(i);else if(!o)throw new Error("Route needs prop `component`, `render` or `children`");/* @__PURE__ */ /* @__PURE__ */
2
+ return(0,h.jsx)(c.Provider,{value:[{...a[0],params:i},a[1]],children:o})},b=({redirect:e,children:r})=>{const[t,o]=m(),a=(e=>(Array.isArray(e)?e:[e]).filter(e=>null!=e&&"object"==typeof e&&"props"in e))(r).find(e=>v(e.props.path||"*",t))||null;return n(()=>{e&&(a||o(f("function"==typeof e?e(t):e)))},[e,a]),a},w=()=>{const[e,t]=m(),n=r((e,r)=>{t(r=>{const t="function"==typeof e?e(r.path):e;return{...r,path:"string"==typeof t?t:"/"}},r)},[]);return[e.path,n]},_=e=>f({query:e});function k(e){return e?(e=>{const[t,n]=m(),o=r((r,t)=>{n(t=>{const n=t.query[e],o="function"==typeof r?r(n):r;if(o===n)return t;if(o)return{...t,query:{...t.query,[e]:o}};{const{[e]:r,...n}=t.query;return{...t,query:n}}},t)},[]);return[t.query[e],o]})(e):(()=>{const[e,t]=m(),n=r((e,r)=>{t(r=>{let t="function"==typeof e?e(r.query):e;"string"==typeof t&&(t=l("/?"+t.replace(/^\?/,"")).query);const n=l(_(t)).query;return _(n)===_(r.query)?r:{...r,query:n}},r)},[]);return[e.query,n]})()}var S=()=>{const[e,t]=m(),n=r((e,r)=>{t(r=>{const t="function"==typeof e?e(r.hash):e,n="string"!=typeof t?"":t.replace(/^#/,"");return{...r,hash:n}},r)},[]);return[e.hash,n]};function j(e){const[{params:r}]=t(c);return e?e in r?r[e]:"":r||{}}var O=({scrollUp:e,url:t,children:i})=>{const s=t||(p()?"/":window.location.href),[u,y]=a(()=>l(s)),d=o(u),v=r((r,{mode:t="push"}={})=>{if(!history[t+"State"])throw new Error(`Invalid mode "${t}"`);y(e=>{const t="function"==typeof r?r(e):r;return f(e)===f(t)?e:l(t)});const n=d.current,o="function"==typeof r?r(n):r;if(f(n)!==f(o)){const r=l(o);d.current=r,history[t+"State"]({},null,f(r)),e&&window.scrollTo(0,0)}},[]);return n(()=>{d.current=u},[u]),n(()=>{if(p())return;const e=()=>y(l(window.location.href)),r=e=>{const r=e.target,t=(e=>{if(!e)return null;const r=e.getAttribute("href");if(!r)return null;const t=r.trim();return/^[a-zA-Z][a-zA-Z0-9+\-.]*:/.test(t)||null!==e.getAttribute("target")?null:t})(r?.closest("a")??null);if(!t)return!1;e.preventDefault();const[n,o]=t.split("#");n?v(t):o&&(window.location.hash="#"+o)};return window.addEventListener("popstate",e),document.addEventListener("click",r),()=>{window.removeEventListener("popstate",e),document.removeEventListener("click",r)}},[v]),/* @__PURE__ */ /* @__PURE__ */(0,h.jsx)(c.Provider,{value:[u,v],children:i})};export{c as Context,g as Route,b as Switch,O as default,S as useHash,j as useParams,w as usePath,k as useQuery,m as useUrl};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crossroad",
3
- "version": "3.0.6",
3
+ "version": "3.0.8",
4
4
  "description": "A React library to handle navigation easily in your WebApp",
5
5
  "homepage": "https://crossroad.page/",
6
6
  "repository": "github:franciscop/crossroad",
@@ -24,35 +24,39 @@
24
24
  }
25
25
  },
26
26
  "scripts": {
27
- "build": "vite build && npm run build:prettier",
27
+ "build": "vite build && mv dist/index.min.js . && dts-bundle-generator --out-file index.d.ts src/index.ts && rm -rf dist && npm run build:prettier",
28
28
  "build:prettier": "prettier src *.ts *.json --write",
29
29
  "lint": "tsc",
30
- "size": "echo $(gzip -c dist/index.min.js | wc -c) bytes",
30
+ "size": "echo $(gzip -c index.min.js | wc -c) bytes",
31
31
  "start": "vitest",
32
32
  "test": "vitest run --coverage"
33
33
  },
34
- "main": "dist/index.min.js",
34
+ "main": "index.min.js",
35
35
  "type": "module",
36
- "types": "dist/src/index.d.ts",
36
+ "types": "index.d.ts",
37
37
  "files": [
38
- "dist"
38
+ "index.min.js",
39
+ "index.d.ts"
39
40
  ],
40
41
  "devDependencies": {
41
42
  "@types/node": "^25.5.2",
42
43
  "@types/react": "^18.3.4",
43
44
  "@vitejs/plugin-react": "^6.0.1",
44
- "@vitest/coverage-v8": "^3.2.4",
45
- "jsdom": "^26.1.0",
45
+ "@vitest/coverage-v8": "^4.1.2",
46
+ "dts-bundle-generator": "^9.5.1",
47
+ "esbuild": "^0.27.7",
48
+ "jsdom": "^29.0.1",
46
49
  "prettier": "^3.8.1",
47
50
  "react": "^18.3.1",
48
51
  "react-dom": "^18.3.1",
49
- "react-test": "^0.23.3",
52
+ "react-test": "^0.24.2",
53
+ "terser": "^5.46.1",
50
54
  "typescript": "^6.0.2",
51
55
  "vite": "^8.0.3",
52
56
  "vite-plugin-dts": "^4.5.4",
53
- "vitest": "^3.2.4"
57
+ "vitest": "^4.1.2"
54
58
  },
55
59
  "peerDependencies": {
56
- "react": ">=16.8.0"
60
+ "react": ">=18.0.0"
57
61
  }
58
62
  }
package/dist/index.min.js DELETED
@@ -1,687 +0,0 @@
1
- import { createContext as hr, useCallback as U, useContext as xe, useEffect as re, useRef as gr, useState as mr } from "react";
2
- var ne = (n, a) => () => (a || n((a = { exports: {} }).exports, a), a.exports), Ae = /* @__PURE__ */ ((n) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(n, { get: (a, f) => (typeof require < "u" ? require : a)[f] }) : n)(function(n) {
3
- if (typeof require < "u") return require.apply(this, arguments);
4
- throw Error('Calling `require` for "' + n + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
5
- }), B = hr(void 0), br = (n) => n.length > 1 ? n : n[0], j = (n) => {
6
- if (typeof n != "string") return n;
7
- const a = { query: {} }, f = new URL(n, "http://localhost:3000/");
8
- a.path = (f.pathname.replace(/\/$/, "") || "/").replaceAll("%3C", "<").replaceAll("%3E", ">"), a.query = {};
9
- for (const [s] of f.searchParams) a.query[s] = br(f.searchParams.getAll(s));
10
- return f.hash && (a.hash = f.hash.replace(/^#/, "")), a;
11
- }, q = (n) => {
12
- if (typeof n == "string") return n;
13
- const { path: a, query: f = {}, hash: s } = n || {};
14
- let o = a || "/";
15
- const p = new URLSearchParams(Object.entries(f).map(([u, l]) => (Array.isArray(l) ? l : [l]).map((y) => [u, y])).flat().filter(([u, l]) => l)).toString();
16
- return p && (o += "?" + p), s && (o += "#" + s), o;
17
- }, _r = (n) => {
18
- if (!n) return null;
19
- const a = n.getAttribute("href");
20
- if (!a) return null;
21
- const f = a.trim();
22
- return /^[a-zA-Z][a-zA-Z0-9+\-.]*:/.test(f) || n.getAttribute("target") !== null ? null : f;
23
- }, ke = () => typeof window > "u", Er = /* @__PURE__ */ ne(((n) => {
24
- var a = Ae("react"), f = /* @__PURE__ */ Symbol.for("react.element"), s = /* @__PURE__ */ Symbol.for("react.fragment"), o = Object.prototype.hasOwnProperty, p = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, u = {
25
- key: !0,
26
- ref: !0,
27
- __self: !0,
28
- __source: !0
29
- };
30
- function l(y, g, R) {
31
- var m, h = {}, P = null, k = null;
32
- R !== void 0 && (P = "" + R), g.key !== void 0 && (P = "" + g.key), g.ref !== void 0 && (k = g.ref);
33
- for (m in g) o.call(g, m) && !u.hasOwnProperty(m) && (h[m] = g[m]);
34
- if (y && y.defaultProps) for (m in g = y.defaultProps, g) h[m] === void 0 && (h[m] = g[m]);
35
- return {
36
- $$typeof: f,
37
- type: y,
38
- key: P,
39
- ref: k,
40
- props: h,
41
- _owner: p.current
42
- };
43
- }
44
- n.Fragment = s, n.jsx = l, n.jsxs = l;
45
- })), Rr = /* @__PURE__ */ ne(((n) => {
46
- process.env.NODE_ENV !== "production" && (function() {
47
- "use strict";
48
- var a = Ae("react"), f = /* @__PURE__ */ Symbol.for("react.element"), s = /* @__PURE__ */ Symbol.for("react.portal"), o = /* @__PURE__ */ Symbol.for("react.fragment"), p = /* @__PURE__ */ Symbol.for("react.strict_mode"), u = /* @__PURE__ */ Symbol.for("react.profiler"), l = /* @__PURE__ */ Symbol.for("react.provider"), y = /* @__PURE__ */ Symbol.for("react.context"), g = /* @__PURE__ */ Symbol.for("react.forward_ref"), R = /* @__PURE__ */ Symbol.for("react.suspense"), m = /* @__PURE__ */ Symbol.for("react.suspense_list"), h = /* @__PURE__ */ Symbol.for("react.memo"), P = /* @__PURE__ */ Symbol.for("react.lazy"), k = /* @__PURE__ */ Symbol.for("react.offscreen"), ae = Symbol.iterator, De = "@@iterator";
49
- function Fe(e) {
50
- if (e === null || typeof e != "object") return null;
51
- var r = ae && e[ae] || e[De];
52
- return typeof r == "function" ? r : null;
53
- }
54
- var D = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
55
- function w(e) {
56
- for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), i = 1; i < r; i++) t[i - 1] = arguments[i];
57
- Ie("error", e, t);
58
- }
59
- function Ie(e, r, t) {
60
- var i = D.ReactDebugCurrentFrame.getStackAddendum();
61
- i !== "" && (r += "%s", t = t.concat([i]));
62
- var d = t.map(function(b) {
63
- return String(b);
64
- });
65
- d.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, d);
66
- }
67
- var Ne = !1, We = !1, $e = !1, Le = !1, Ue = !1, Ye = /* @__PURE__ */ Symbol.for("react.module.reference");
68
- function Me(e) {
69
- return !!(typeof e == "string" || typeof e == "function" || e === o || e === u || Ue || e === p || e === R || e === m || Le || e === k || Ne || We || $e || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === h || e.$$typeof === l || e.$$typeof === y || e.$$typeof === g || e.$$typeof === Ye || e.getModuleId !== void 0));
70
- }
71
- function Ve(e, r, t) {
72
- var i = e.displayName;
73
- if (i) return i;
74
- var d = r.displayName || r.name || "";
75
- return d !== "" ? t + "(" + d + ")" : t;
76
- }
77
- function oe(e) {
78
- return e.displayName || "Context";
79
- }
80
- function C(e) {
81
- if (e == null) return null;
82
- if (typeof e.tag == "number" && w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null;
83
- if (typeof e == "string") return e;
84
- switch (e) {
85
- case o:
86
- return "Fragment";
87
- case s:
88
- return "Portal";
89
- case u:
90
- return "Profiler";
91
- case p:
92
- return "StrictMode";
93
- case R:
94
- return "Suspense";
95
- case m:
96
- return "SuspenseList";
97
- }
98
- if (typeof e == "object") switch (e.$$typeof) {
99
- case y:
100
- return oe(e) + ".Consumer";
101
- case l:
102
- return oe(e._context) + ".Provider";
103
- case g:
104
- return Ve(e, e.render, "ForwardRef");
105
- case h:
106
- var r = e.displayName || null;
107
- return r !== null ? r : C(e.type) || "Memo";
108
- case P:
109
- var t = e, i = t._payload, d = t._init;
110
- try {
111
- return C(d(i));
112
- } catch {
113
- return null;
114
- }
115
- }
116
- return null;
117
- }
118
- var x = Object.assign, W = 0, ie, se, ue, le, fe, ce, pe;
119
- function ve() {
120
- }
121
- ve.__reactDisabledLog = !0;
122
- function Be() {
123
- if (W === 0) {
124
- ie = console.log, se = console.info, ue = console.warn, le = console.error, fe = console.group, ce = console.groupCollapsed, pe = console.groupEnd;
125
- var e = {
126
- configurable: !0,
127
- enumerable: !0,
128
- value: ve,
129
- writable: !0
130
- };
131
- Object.defineProperties(console, {
132
- info: e,
133
- log: e,
134
- warn: e,
135
- error: e,
136
- group: e,
137
- groupCollapsed: e,
138
- groupEnd: e
139
- });
140
- }
141
- W++;
142
- }
143
- function Ke() {
144
- if (W--, W === 0) {
145
- var e = {
146
- configurable: !0,
147
- enumerable: !0,
148
- writable: !0
149
- };
150
- Object.defineProperties(console, {
151
- log: x({}, e, { value: ie }),
152
- info: x({}, e, { value: se }),
153
- warn: x({}, e, { value: ue }),
154
- error: x({}, e, { value: le }),
155
- group: x({}, e, { value: fe }),
156
- groupCollapsed: x({}, e, { value: ce }),
157
- groupEnd: x({}, e, { value: pe })
158
- });
159
- }
160
- W < 0 && w("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
161
- }
162
- var K = D.ReactCurrentDispatcher, H;
163
- function Y(e, r, t) {
164
- if (H === void 0) try {
165
- throw Error();
166
- } catch (d) {
167
- var i = d.stack.trim().match(/\n( *(at )?)/);
168
- H = i && i[1] || "";
169
- }
170
- return `
171
- ` + H + e;
172
- }
173
- var J = !1, z = new (typeof WeakMap == "function" ? WeakMap : Map)();
174
- function de(e, r) {
175
- if (!e || J) return "";
176
- var t = z.get(e);
177
- if (t !== void 0) return t;
178
- var i;
179
- J = !0;
180
- var d = Error.prepareStackTrace;
181
- Error.prepareStackTrace = void 0;
182
- var b = K.current;
183
- K.current = null, Be();
184
- try {
185
- if (r) {
186
- var v = function() {
187
- throw Error();
188
- };
189
- if (Object.defineProperty(v.prototype, "props", { set: function() {
190
- throw Error();
191
- } }), typeof Reflect == "object" && Reflect.construct) {
192
- try {
193
- Reflect.construct(v, []);
194
- } catch (S) {
195
- i = S;
196
- }
197
- Reflect.construct(e, [], v);
198
- } else {
199
- try {
200
- v.call();
201
- } catch (S) {
202
- i = S;
203
- }
204
- e.call(v.prototype);
205
- }
206
- } else {
207
- try {
208
- throw Error();
209
- } catch (S) {
210
- i = S;
211
- }
212
- e();
213
- }
214
- } catch (S) {
215
- if (S && i && typeof S.stack == "string") {
216
- for (var c = S.stack.split(`
217
- `), T = i.stack.split(`
218
- `), _ = c.length - 1, E = T.length - 1; _ >= 1 && E >= 0 && c[_] !== T[E]; ) E--;
219
- for (; _ >= 1 && E >= 0; _--, E--) if (c[_] !== T[E]) {
220
- if (_ !== 1 || E !== 1) do
221
- if (_--, E--, E < 0 || c[_] !== T[E]) {
222
- var O = `
223
- ` + c[_].replace(" at new ", " at ");
224
- return e.displayName && O.includes("<anonymous>") && (O = O.replace("<anonymous>", e.displayName)), typeof e == "function" && z.set(e, O), O;
225
- }
226
- while (_ >= 1 && E >= 0);
227
- break;
228
- }
229
- }
230
- } finally {
231
- J = !1, K.current = b, Ke(), Error.prepareStackTrace = d;
232
- }
233
- var I = e ? e.displayName || e.name : "", A = I ? Y(I) : "";
234
- return typeof e == "function" && z.set(e, A), A;
235
- }
236
- function He(e, r, t) {
237
- return de(e, !1);
238
- }
239
- function Je(e) {
240
- var r = e.prototype;
241
- return !!(r && r.isReactComponent);
242
- }
243
- function M(e, r, t) {
244
- if (e == null) return "";
245
- if (typeof e == "function") return de(e, Je(e));
246
- if (typeof e == "string") return Y(e);
247
- switch (e) {
248
- case R:
249
- return Y("Suspense");
250
- case m:
251
- return Y("SuspenseList");
252
- }
253
- if (typeof e == "object") switch (e.$$typeof) {
254
- case g:
255
- return He(e.render);
256
- case h:
257
- return M(e.type, r, t);
258
- case P:
259
- var i = e, d = i._payload, b = i._init;
260
- try {
261
- return M(b(d), r, t);
262
- } catch {
263
- }
264
- }
265
- return "";
266
- }
267
- var $ = Object.prototype.hasOwnProperty, ye = {}, he = D.ReactDebugCurrentFrame;
268
- function V(e) {
269
- if (e) {
270
- var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
271
- he.setExtraStackFrame(t);
272
- } else he.setExtraStackFrame(null);
273
- }
274
- function ze(e, r, t, i, d) {
275
- var b = Function.call.bind($);
276
- for (var v in e) if (b(e, v)) {
277
- var c = void 0;
278
- try {
279
- if (typeof e[v] != "function") {
280
- var T = Error((i || "React class") + ": " + t + " type `" + v + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[v] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
281
- throw T.name = "Invariant Violation", T;
282
- }
283
- c = e[v](r, v, i, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
284
- } catch (_) {
285
- c = _;
286
- }
287
- c && !(c instanceof Error) && (V(d), w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", i || "React class", t, v, typeof c), V(null)), c instanceof Error && !(c.message in ye) && (ye[c.message] = !0, V(d), w("Failed %s type: %s", t, c.message), V(null));
288
- }
289
- }
290
- var Ge = Array.isArray;
291
- function G(e) {
292
- return Ge(e);
293
- }
294
- function Qe(e) {
295
- return typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
296
- }
297
- function Xe(e) {
298
- try {
299
- return ge(e), !1;
300
- } catch {
301
- return !0;
302
- }
303
- }
304
- function ge(e) {
305
- return "" + e;
306
- }
307
- function me(e) {
308
- if (Xe(e))
309
- return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Qe(e)), ge(e);
310
- }
311
- var L = D.ReactCurrentOwner, Ze = {
312
- key: !0,
313
- ref: !0,
314
- __self: !0,
315
- __source: !0
316
- }, be, _e, Ee = {};
317
- function er(e) {
318
- if ($.call(e, "ref")) {
319
- var r = Object.getOwnPropertyDescriptor(e, "ref").get;
320
- if (r && r.isReactWarning) return !1;
321
- }
322
- return e.ref !== void 0;
323
- }
324
- function rr(e) {
325
- if ($.call(e, "key")) {
326
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
327
- if (r && r.isReactWarning) return !1;
328
- }
329
- return e.key !== void 0;
330
- }
331
- function tr(e, r) {
332
- if (typeof e.ref == "string" && L.current && r && L.current.stateNode !== r) {
333
- var t = C(L.current.type);
334
- Ee[t] || (w('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', C(L.current.type), e.ref), Ee[t] = !0);
335
- }
336
- }
337
- function nr(e, r) {
338
- var t = function() {
339
- be || (be = !0, w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
340
- };
341
- t.isReactWarning = !0, Object.defineProperty(e, "key", {
342
- get: t,
343
- configurable: !0
344
- });
345
- }
346
- function ar(e, r) {
347
- var t = function() {
348
- _e || (_e = !0, w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
349
- };
350
- t.isReactWarning = !0, Object.defineProperty(e, "ref", {
351
- get: t,
352
- configurable: !0
353
- });
354
- }
355
- var or = function(e, r, t, i, d, b, v) {
356
- var c = {
357
- $$typeof: f,
358
- type: e,
359
- key: r,
360
- ref: t,
361
- props: v,
362
- _owner: b
363
- };
364
- return c._store = {}, Object.defineProperty(c._store, "validated", {
365
- configurable: !1,
366
- enumerable: !1,
367
- writable: !0,
368
- value: !1
369
- }), Object.defineProperty(c, "_self", {
370
- configurable: !1,
371
- enumerable: !1,
372
- writable: !1,
373
- value: i
374
- }), Object.defineProperty(c, "_source", {
375
- configurable: !1,
376
- enumerable: !1,
377
- writable: !1,
378
- value: d
379
- }), Object.freeze && (Object.freeze(c.props), Object.freeze(c)), c;
380
- };
381
- function ir(e, r, t, i, d) {
382
- var b, v = {}, c = null, T = null;
383
- t !== void 0 && (me(t), c = "" + t), rr(r) && (me(r.key), c = "" + r.key), er(r) && (T = r.ref, tr(r, d));
384
- for (b in r) $.call(r, b) && !Ze.hasOwnProperty(b) && (v[b] = r[b]);
385
- if (e && e.defaultProps) {
386
- var _ = e.defaultProps;
387
- for (b in _) v[b] === void 0 && (v[b] = _[b]);
388
- }
389
- if (c || T) {
390
- var E = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
391
- c && nr(v, E), T && ar(v, E);
392
- }
393
- return or(e, c, T, d, i, L.current, v);
394
- }
395
- var Q = D.ReactCurrentOwner, Re = D.ReactDebugCurrentFrame;
396
- function F(e) {
397
- if (e) {
398
- var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
399
- Re.setExtraStackFrame(t);
400
- } else Re.setExtraStackFrame(null);
401
- }
402
- var we = !1;
403
- function X(e) {
404
- return typeof e == "object" && e !== null && e.$$typeof === f;
405
- }
406
- function Te() {
407
- if (Q.current) {
408
- var e = C(Q.current.type);
409
- if (e) return `
410
-
411
- Check the render method of \`` + e + "`.";
412
- }
413
- return "";
414
- }
415
- function sr(e) {
416
- if (e !== void 0) {
417
- var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
418
- return `
419
-
420
- Check your code at ` + r + ":" + t + ".";
421
- }
422
- return "";
423
- }
424
- var Se = {};
425
- function ur(e) {
426
- var r = Te();
427
- if (!r) {
428
- var t = typeof e == "string" ? e : e.displayName || e.name;
429
- t && (r = `
430
-
431
- Check the top-level render call using <` + t + ">.");
432
- }
433
- return r;
434
- }
435
- function Pe(e, r) {
436
- if (!(!e._store || e._store.validated || e.key != null)) {
437
- e._store.validated = !0;
438
- var t = ur(r);
439
- if (!Se[t]) {
440
- Se[t] = !0;
441
- var i = "";
442
- e && e._owner && e._owner !== Q.current && (i = " It was passed a child from " + C(e._owner.type) + "."), F(e), w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, i), F(null);
443
- }
444
- }
445
- }
446
- function Oe(e, r) {
447
- if (typeof e == "object") {
448
- if (G(e)) for (var t = 0; t < e.length; t++) {
449
- var i = e[t];
450
- X(i) && Pe(i, r);
451
- }
452
- else if (X(e))
453
- e._store && (e._store.validated = !0);
454
- else if (e) {
455
- var d = Fe(e);
456
- if (typeof d == "function" && d !== e.entries)
457
- for (var b = d.call(e), v; !(v = b.next()).done; ) X(v.value) && Pe(v.value, r);
458
- }
459
- }
460
- }
461
- function lr(e) {
462
- var r = e.type;
463
- if (!(r == null || typeof r == "string")) {
464
- var t;
465
- if (typeof r == "function") t = r.propTypes;
466
- else if (typeof r == "object" && (r.$$typeof === g || r.$$typeof === h)) t = r.propTypes;
467
- else return;
468
- if (t) {
469
- var i = C(r);
470
- ze(t, e.props, "prop", i, e);
471
- } else r.PropTypes !== void 0 && !we && (we = !0, w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", C(r) || "Unknown"));
472
- typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
473
- }
474
- }
475
- function fr(e) {
476
- for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
477
- var i = r[t];
478
- if (i !== "children" && i !== "key") {
479
- F(e), w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", i), F(null);
480
- break;
481
- }
482
- }
483
- e.ref !== null && (F(e), w("Invalid attribute `ref` supplied to `React.Fragment`."), F(null));
484
- }
485
- var Ce = {};
486
- function je(e, r, t, i, d, b) {
487
- var v = Me(e);
488
- if (!v) {
489
- var c = "";
490
- (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (c += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
491
- var T = sr(d);
492
- T ? c += T : c += Te();
493
- var _;
494
- e === null ? _ = "null" : G(e) ? _ = "array" : e !== void 0 && e.$$typeof === f ? (_ = "<" + (C(e.type) || "Unknown") + " />", c = " Did you accidentally export a JSX literal instead of a component?") : _ = typeof e, w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", _, c);
495
- }
496
- var E = ir(e, r, t, d, b);
497
- if (E == null) return E;
498
- if (v) {
499
- var O = r.children;
500
- if (O !== void 0) if (i) if (G(O)) {
501
- for (var I = 0; I < O.length; I++) Oe(O[I], e);
502
- Object.freeze && Object.freeze(O);
503
- } else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
504
- else Oe(O, e);
505
- }
506
- if ($.call(r, "key")) {
507
- var A = C(e), S = Object.keys(r).filter(function(yr) {
508
- return yr !== "key";
509
- }), Z = S.length > 0 ? "{key: someKey, " + S.join(": ..., ") + ": ...}" : "{key: someKey}";
510
- Ce[A + Z] || (w(`A props object containing a "key" prop is being spread into JSX:
511
- let props = %s;
512
- <%s {...props} />
513
- React keys must be passed directly to JSX without using spread:
514
- let props = %s;
515
- <%s key={someKey} {...props} />`, Z, A, S.length > 0 ? "{" + S.join(": ..., ") + ": ...}" : "{}", A), Ce[A + Z] = !0);
516
- }
517
- return e === o ? fr(E) : lr(E), E;
518
- }
519
- function cr(e, r, t) {
520
- return je(e, r, t, !0);
521
- }
522
- function pr(e, r, t) {
523
- return je(e, r, t, !1);
524
- }
525
- var vr = pr, dr = cr;
526
- n.Fragment = o, n.jsx = vr, n.jsxs = dr;
527
- })();
528
- })), wr = /* @__PURE__ */ ne(((n, a) => {
529
- process.env.NODE_ENV === "production" ? a.exports = Er() : a.exports = Rr();
530
- })), te = wr(), Tr = ({ scrollUp: n, url: a, children: f }) => {
531
- const s = a || (ke() ? "/" : window.location.href), [o, p] = mr(() => j(s)), u = gr(o), l = U((y, { mode: g = "push" } = {}) => {
532
- if (!history[g + "State"]) throw new Error(`Invalid mode "${g}"`);
533
- p((h) => {
534
- const P = typeof y == "function" ? y(h) : y;
535
- return q(h) === q(P) ? h : j(P);
536
- });
537
- const R = u.current, m = typeof y == "function" ? y(R) : y;
538
- if (q(R) !== q(m)) {
539
- const h = j(m);
540
- u.current = h, history[g + "State"]({}, null, q(h)), n && window.scrollTo(0, 0);
541
- }
542
- }, []);
543
- return re(() => {
544
- u.current = o;
545
- }, [o]), re(() => {
546
- if (ke()) return;
547
- const y = () => p(j(window.location.href)), g = (R) => {
548
- const m = R.target, h = _r(m?.closest("a") ?? null);
549
- if (!h) return !1;
550
- R.preventDefault();
551
- const [P, k] = h.split("#");
552
- P ? l(h) : k && (window.location.hash = "#" + k);
553
- };
554
- return window.addEventListener("popstate", y), document.addEventListener("click", g), () => {
555
- window.removeEventListener("popstate", y), document.removeEventListener("click", g);
556
- };
557
- }, [l]), /* @__PURE__ */ (0, te.jsx)(B.Provider, {
558
- value: [o, l],
559
- children: f
560
- });
561
- };
562
- function qe(n, a, f = {}) {
563
- let s = JSON.parse(JSON.stringify(j(n))), o = JSON.parse(JSON.stringify(j(a)));
564
- if (o.path = o.path.replace(/\/$/, "") || "/", s.path = s.path.replace(/\/$/, "") || "/", s.path.endsWith("*")) {
565
- s.path = s.path.replace(/\/?\*/, "") || "/";
566
- const l = s.path.split("/").filter(Boolean).length;
567
- o.path = "/" + o.path.slice(1).split("/").slice(0, l).join("/");
568
- }
569
- if (Object.entries(s.query).length) {
570
- for (const l in s.query)
571
- if (!(l in o.query) || s.query[l] && s.query[l] !== o.query[l]) return !1;
572
- }
573
- if (!s.path.includes(":")) return s.path === o.path && f;
574
- if (s.path.split("/").length !== o.path.split("/").length) return !1;
575
- const p = {}, u = s.path.split("/").every((l, y) => {
576
- const g = o.path.split("/")[y];
577
- if (l.startsWith(":")) {
578
- let R = l.slice(1), m = "string";
579
- R.includes("<") && ([R, m] = R.split("<"), m = m.slice(0, -1));
580
- const h = decodeURIComponent(g);
581
- return p[R] = m === "number" ? Number(h) : m === "date" ? new Date(/^\d+$/.test(h) ? Number(h) : h) : m === "boolean" ? h === "true" : h, f;
582
- }
583
- return g === l;
584
- });
585
- return u && Object.assign(f, p), u && f;
586
- }
587
- var N = () => {
588
- const n = xe(B);
589
- if (!n) throw new Error("Wrap your App with <Router>");
590
- return n;
591
- }, jr = ({ path: n = "*", scrollUp: a, component: f, render: s, children: o }) => {
592
- const p = N(), u = qe(n, p[0]);
593
- if (!u) return null;
594
- if (a && window.scrollTo(0, 0), f) o = /* @__PURE__ */ (0, te.jsx)(f, { ...u });
595
- else if (s) o = s(u);
596
- else if (!o) throw new Error("Route needs prop `component`, `render` or `children`");
597
- return /* @__PURE__ */ (0, te.jsx)(B.Provider, {
598
- value: [{
599
- ...p[0],
600
- params: u
601
- }, p[1]],
602
- children: o
603
- });
604
- }, Sr = (n) => (Array.isArray(n) ? n : [n]).filter((a) => a != null && typeof a == "object" && "props" in a), kr = ({ redirect: n, children: a }) => {
605
- const [f, s] = N(), o = (u) => qe(u.props.path || "*", f), p = Sr(a).find(o) || null;
606
- return re(() => {
607
- n && (p || s(q(typeof n == "function" ? n(f) : n)));
608
- }, [n, p]), p;
609
- }, xr = () => {
610
- const [n, a] = N(), s = U((o, p) => {
611
- a((u) => {
612
- const l = typeof o == "function" ? o(u.path) : o;
613
- return {
614
- ...u,
615
- path: typeof l == "string" ? l : "/"
616
- };
617
- }, p);
618
- }, []);
619
- return [n.path, s];
620
- }, ee = (n) => q({ query: n }), Pr = (n) => {
621
- const [a, f] = N(), s = U((o, p) => {
622
- f((u) => {
623
- const l = u.query[n], y = typeof o == "function" ? o(l) : o;
624
- if (y === l) return u;
625
- if (y)
626
- return {
627
- ...u,
628
- query: {
629
- ...u.query,
630
- [n]: y
631
- }
632
- };
633
- {
634
- const { [n]: g, ...R } = u.query;
635
- return {
636
- ...u,
637
- query: R
638
- };
639
- }
640
- }, p);
641
- }, []);
642
- return [a.query[n], s];
643
- }, Or = () => {
644
- const [n, a] = N(), f = U((s, o) => {
645
- a((p) => {
646
- let u = typeof s == "function" ? s(p.query) : s;
647
- typeof u == "string" && (u = j("/?" + u.replace(/^\?/, "")).query);
648
- const l = j(ee(u)).query;
649
- return ee(l) === ee(p.query) ? p : {
650
- ...p,
651
- query: l
652
- };
653
- }, o);
654
- }, []);
655
- return [n.query, f];
656
- };
657
- function Ar(n) {
658
- return n ? Pr(n) : Or();
659
- }
660
- var qr = () => {
661
- const [n, a] = N(), s = U((o, p) => {
662
- a((u) => {
663
- const l = typeof o == "function" ? o(u.hash) : o, y = typeof l != "string" ? "" : l.replace(/^#/, "");
664
- return {
665
- ...u,
666
- hash: y
667
- };
668
- }, p);
669
- }, []);
670
- return [n.hash, s];
671
- };
672
- function Dr(n) {
673
- const [{ params: a }] = xe(B);
674
- return n ? n in a ? a[n] : "" : a || {};
675
- }
676
- var Fr = Tr;
677
- export {
678
- B as Context,
679
- jr as Route,
680
- kr as Switch,
681
- Fr as default,
682
- qr as useHash,
683
- Dr as useParams,
684
- xr as usePath,
685
- Ar as useQuery,
686
- N as useUrl
687
- };
@@ -1,3 +0,0 @@
1
- import { Url, SetUrl } from './types';
2
- declare const _default: import('react').Context<[Url, SetUrl] | undefined>;
3
- export default _default;
@@ -1,36 +0,0 @@
1
- import { default as React } from 'react';
2
- type ParseParamType<T extends string> = T extends `${infer Name}<${infer Type}>` ? Type extends "number" ? {
3
- [K in Name]: number;
4
- } : Type extends "string" ? {
5
- [K in Name]: string;
6
- } : Type extends "date" ? {
7
- [K in Name]: Date;
8
- } : Type extends "boolean" ? {
9
- [K in Name]: boolean;
10
- } : {
11
- [K in Name]: string;
12
- } : {
13
- [K in T]: string;
14
- };
15
- type ExtractParams<T extends string> = T extends `${infer _Prefix}/:${infer Param}/${infer Rest}` ? ParseParamType<Param> & ExtractParams<`/${Rest}`> : T extends `${infer _Prefix}/:${infer Param}` ? ParseParamType<Param> : {};
16
- type InferParamsFromPath<T extends string> = T extends `${string}/:${string}` ? ExtractParams<T> : {};
17
- interface RoutePropsBase {
18
- path?: string;
19
- scrollUp?: boolean;
20
- children?: React.ReactNode;
21
- }
22
- type RouteProps<T extends Record<string, string | number | boolean | Date> = {}> = RoutePropsBase & ({
23
- component: React.FunctionComponent<T>;
24
- render?: never;
25
- } | {
26
- render: (params: T) => React.ReactNode;
27
- component?: never;
28
- } | {
29
- component?: never;
30
- render?: never;
31
- });
32
- type RouteType = <P extends string = string>(props: RouteProps<InferParamsFromPath<P>> & {
33
- path?: P;
34
- }) => React.ReactNode;
35
- declare const _default: RouteType;
36
- export default _default;
@@ -1,8 +0,0 @@
1
- import { default as React } from 'react';
2
- interface RouterProps {
3
- scrollUp?: boolean;
4
- url?: string;
5
- children?: React.ReactNode;
6
- }
7
- declare const _default: ({ scrollUp, url: baseUrl, children }: RouterProps) => import("react/jsx-runtime").JSX.Element;
8
- export default _default;
@@ -1,10 +0,0 @@
1
- import { ReactElement, ReactNode } from 'react';
2
- import { Url } from './types';
3
- interface SwitchProps {
4
- redirect?: string | {
5
- path: string;
6
- } | ((url: Url) => string);
7
- children?: ReactNode;
8
- }
9
- declare const _default: ({ redirect, children }: SwitchProps) => ReactElement | null;
10
- export default _default;
@@ -1,3 +0,0 @@
1
- import { Url, UrlSet } from '../types';
2
- export declare const parse: (base: string | Url | UrlSet) => Url;
3
- export declare const stringify: (url: string | Url | UrlSet | null | undefined) => string;
@@ -1,2 +0,0 @@
1
- declare const _default: (el: Element | null) => string | null;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare const _default: () => boolean;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { Url, UrlSet, Params } from '../types';
2
- export default function samePath(ref: string | Url | UrlSet, url: string | Url | UrlSet, params?: Params): Params | false;
@@ -1,5 +0,0 @@
1
- import { SetUrlOptions } from '../types';
2
- type HashUpdater = (hash: string | undefined) => string;
3
- type SetHash = (hash: string | HashUpdater, opts?: SetUrlOptions) => void;
4
- declare const _default: () => [string | undefined, SetHash];
5
- export default _default;
@@ -1,4 +0,0 @@
1
- import { Params } from '../types';
2
- declare function useParams(): Params;
3
- declare function useParams<T = string | number | boolean | Date>(key: string): T;
4
- export default useParams;
@@ -1,5 +0,0 @@
1
- import { SetUrlOptions } from '../types';
2
- type PathUpdater = (path: string) => string;
3
- type SetPath = (path: string | PathUpdater, opts?: SetUrlOptions) => void;
4
- declare const _default: () => [string, SetPath];
5
- export default _default;
@@ -1,8 +0,0 @@
1
- import { Query, SetUrlOptions } from '../types';
2
- type QueryValue = string | string[] | undefined;
3
- type SetQueryProp = (value: string | ((prev: QueryValue) => string), opts?: SetUrlOptions) => void;
4
- type QueryUpdater = (query: Query) => Query | string;
5
- type SetQuery = (newQuery: Query | string | QueryUpdater, opts?: SetUrlOptions) => void;
6
- declare function useQuery(key: string): [QueryValue, SetQueryProp];
7
- declare function useQuery(): [Query, SetQuery];
8
- export default useQuery;
@@ -1,3 +0,0 @@
1
- import { Url, SetUrl } from '../types';
2
- declare const _default: () => [Url, SetUrl];
3
- export default _default;
@@ -1,11 +0,0 @@
1
- import { default as Router } from './Router';
2
- import { default as Route } from './Route';
3
- import { default as Switch } from './Switch';
4
- import { default as Context } from './Context';
5
- import { default as useUrl } from './hooks/useUrl';
6
- import { default as usePath } from './hooks/usePath';
7
- import { default as useQuery } from './hooks/useQuery';
8
- import { default as useHash } from './hooks/useHash';
9
- import { default as useParams } from './hooks/useParams';
10
- export default Router;
11
- export { Route, Switch, useUrl, usePath, useQuery, useHash, useParams, Context, };
@@ -1,18 +0,0 @@
1
- export type Query = Record<string, string | string[]>;
2
- export type Url = {
3
- path: string;
4
- query: Query;
5
- hash?: string;
6
- params?: Params;
7
- };
8
- export type UrlSet = {
9
- path?: string;
10
- query?: Query;
11
- hash?: string;
12
- };
13
- export type Params = Record<string, string | number | boolean | Date>;
14
- export type SetUrlOptions = {
15
- mode?: "push" | "replace";
16
- };
17
- export type NewUrlValue = Url | UrlSet | string;
18
- export type SetUrl = (newUrl: NewUrlValue | ((prev: Url) => NewUrlValue), opts?: SetUrlOptions) => void;