@unsetsoft/ryunixjs 1.1.16 → 1.1.17-canary.2
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/dist/Ryunix.js +51 -186
- package/dist/Ryunix.min.js +1 -1
- package/package.json +1 -1
package/dist/Ryunix.js
CHANGED
|
@@ -471,7 +471,7 @@
|
|
|
471
471
|
|
|
472
472
|
const ImageProps = {
|
|
473
473
|
src: url,
|
|
474
|
-
props,
|
|
474
|
+
...props,
|
|
475
475
|
};
|
|
476
476
|
|
|
477
477
|
return createElement('img', ImageProps, null)
|
|
@@ -764,14 +764,6 @@
|
|
|
764
764
|
* @returns An object containing key-value pairs of the query parameters from the URLSearchParams in
|
|
765
765
|
* the current window's URL is being returned.
|
|
766
766
|
*/
|
|
767
|
-
const useQuery = () => {
|
|
768
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
769
|
-
const query = {};
|
|
770
|
-
for (let [key, value] of searchParams.entries()) {
|
|
771
|
-
query[key] = value;
|
|
772
|
-
}
|
|
773
|
-
return query
|
|
774
|
-
};
|
|
775
767
|
|
|
776
768
|
const createContext = (defaultValue) => {
|
|
777
769
|
const contextId = RYUNIX_TYPES.RYUNIX_CONTEXT;
|
|
@@ -804,184 +796,36 @@
|
|
|
804
796
|
}
|
|
805
797
|
};
|
|
806
798
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
* @example
|
|
827
|
-
* // Define nested routes
|
|
828
|
-
* const routes = [
|
|
829
|
-
* {
|
|
830
|
-
* path: "/",
|
|
831
|
-
* component: HomePage,
|
|
832
|
-
* subRoutes: [
|
|
833
|
-
* {
|
|
834
|
-
* path: "/settings",
|
|
835
|
-
* component: SettingsPage,
|
|
836
|
-
* },
|
|
837
|
-
* ],
|
|
838
|
-
* },
|
|
839
|
-
* {
|
|
840
|
-
* path: "/user/:id",
|
|
841
|
-
* component: UserProfile,
|
|
842
|
-
* },
|
|
843
|
-
* {
|
|
844
|
-
* path: "*",
|
|
845
|
-
* NotFound: NotFoundPage,
|
|
846
|
-
* },
|
|
847
|
-
* ];
|
|
848
|
-
*
|
|
849
|
-
* // Use the routing function
|
|
850
|
-
* const { Children, NavLink } = useRouter(routes);
|
|
851
|
-
*
|
|
852
|
-
* // Render the matched component
|
|
853
|
-
* const App = () => (
|
|
854
|
-
* <>
|
|
855
|
-
* <NavLink to="/">Home</NavLink>
|
|
856
|
-
* <NavLink to="/settings">Settings</NavLink>
|
|
857
|
-
* <NavLink to="/user/123">User Profile</NavLink>
|
|
858
|
-
* <Children />
|
|
859
|
-
* </>
|
|
860
|
-
* );
|
|
861
|
-
*/
|
|
862
|
-
// const useRouter = (routes) => {
|
|
863
|
-
// const [location, setLocation] = useStore(window.location.pathname)
|
|
864
|
-
|
|
865
|
-
// const findRoute = (routes, path) => {
|
|
866
|
-
// const pathname = path.split('?')[0]
|
|
867
|
-
|
|
868
|
-
// const notFoundRoute = routes.find((route) => route.NotFound)
|
|
869
|
-
// const notFound = notFoundRoute
|
|
870
|
-
// ? { route: { component: notFoundRoute.NotFound }, params: {} }
|
|
871
|
-
// : { route: { component: null }, params: {} }
|
|
872
|
-
|
|
873
|
-
// for (const route of routes) {
|
|
874
|
-
// if (route.subRoutes) {
|
|
875
|
-
// const childRoute = findRoute(route.subRoutes, path)
|
|
876
|
-
// if (childRoute) return childRoute
|
|
877
|
-
// }
|
|
878
|
-
|
|
879
|
-
// if (route.path === '*') {
|
|
880
|
-
// return notFound
|
|
881
|
-
// }
|
|
882
|
-
|
|
883
|
-
// if (!route.path || typeof route.path !== 'string') {
|
|
884
|
-
// console.warn('Invalid route detected:', route)
|
|
885
|
-
// console.info(
|
|
886
|
-
// "if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }",
|
|
887
|
-
// )
|
|
888
|
-
// continue
|
|
889
|
-
// }
|
|
890
|
-
|
|
891
|
-
// const keys = []
|
|
892
|
-
// const pattern = new RegExp(
|
|
893
|
-
// `^${route.path.replace(/:\w+/g, (match) => {
|
|
894
|
-
// keys.push(match.substring(1))
|
|
895
|
-
// return '([^/]+)'
|
|
896
|
-
// })}$`,
|
|
897
|
-
// )
|
|
898
|
-
|
|
899
|
-
// const match = pathname.match(pattern)
|
|
900
|
-
// if (match) {
|
|
901
|
-
// const params = keys.reduce((acc, key, index) => {
|
|
902
|
-
// acc[key] = match[index + 1]
|
|
903
|
-
// return acc
|
|
904
|
-
// }, {})
|
|
905
|
-
|
|
906
|
-
// return { route, params }
|
|
907
|
-
// }
|
|
908
|
-
// }
|
|
909
|
-
|
|
910
|
-
// return notFound
|
|
911
|
-
// }
|
|
912
|
-
|
|
913
|
-
// const navigate = (path) => {
|
|
914
|
-
// window.history.pushState({}, '', path)
|
|
915
|
-
|
|
916
|
-
// updateRoute(path)
|
|
917
|
-
// }
|
|
918
|
-
|
|
919
|
-
// const updateRoute = (path) => {
|
|
920
|
-
// const cleanedPath = path.split('?')[0]
|
|
921
|
-
// setLocation(cleanedPath)
|
|
922
|
-
// }
|
|
923
|
-
|
|
924
|
-
// useEffect(() => {
|
|
925
|
-
// const onPopState = () => updateRoute(window.location.pathname)
|
|
926
|
-
// window.addEventListener('popstate', onPopState)
|
|
927
|
-
|
|
928
|
-
// return () => window.removeEventListener('popstate', onPopState)
|
|
929
|
-
// }, [])
|
|
930
|
-
|
|
931
|
-
// const currentRouteData = findRoute(routes, location) || {}
|
|
932
|
-
|
|
933
|
-
// const Children = () => {
|
|
934
|
-
// const query = useQuery()
|
|
935
|
-
// const { route } = currentRouteData
|
|
936
|
-
|
|
937
|
-
// if (
|
|
938
|
-
// !route ||
|
|
939
|
-
// !route.component ||
|
|
940
|
-
// typeof route.component !== STRINGS.function
|
|
941
|
-
// ) {
|
|
942
|
-
// console.error(
|
|
943
|
-
// 'Component not found for current path or the component is not a valid function:',
|
|
944
|
-
// currentRouteData,
|
|
945
|
-
// )
|
|
946
|
-
// return null
|
|
947
|
-
// }
|
|
948
|
-
|
|
949
|
-
// const WrappedComponent = () =>
|
|
950
|
-
// createElement(route.component, {
|
|
951
|
-
// key: location,
|
|
952
|
-
// params: currentRouteData.params || {},
|
|
953
|
-
// query,
|
|
954
|
-
// })
|
|
955
|
-
|
|
956
|
-
// return createElement(WrappedComponent)
|
|
957
|
-
// }
|
|
958
|
-
|
|
959
|
-
// const NavLink = ({ to, ...props }) => {
|
|
960
|
-
// const handleClick = (e) => {
|
|
961
|
-
// e.preventDefault()
|
|
962
|
-
// navigate(to)
|
|
963
|
-
// }
|
|
964
|
-
// return createElement(
|
|
965
|
-
// 'a',
|
|
966
|
-
// { href: to, onClick: handleClick, ...props },
|
|
967
|
-
// props.children,
|
|
968
|
-
// )
|
|
969
|
-
// }
|
|
970
|
-
|
|
971
|
-
// return { Children, NavLink, navigate }
|
|
972
|
-
// }
|
|
973
|
-
|
|
974
|
-
// Crear contexto para Router
|
|
799
|
+
const useQuery = () => {
|
|
800
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
801
|
+
const query = {};
|
|
802
|
+
for (let [key, value] of searchParams.entries()) {
|
|
803
|
+
query[key] = value;
|
|
804
|
+
}
|
|
805
|
+
return query
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
const useHash = () => {
|
|
809
|
+
return window.location.hash
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
const getLocation = () => ({
|
|
813
|
+
pathname: window.location.pathname,
|
|
814
|
+
search: window.location.search,
|
|
815
|
+
hash: window.location.hash,
|
|
816
|
+
});
|
|
817
|
+
|
|
975
818
|
const RouterContext = createContext({
|
|
976
819
|
location: '/',
|
|
977
820
|
params: {},
|
|
978
821
|
query: {},
|
|
822
|
+
hash: '',
|
|
979
823
|
navigate: (path) => {},
|
|
980
824
|
route: null,
|
|
981
825
|
});
|
|
982
826
|
|
|
983
827
|
const findRoute = (routes, path) => {
|
|
984
|
-
const pathname = path.split('?')[0];
|
|
828
|
+
const pathname = path.split('?')[0].split('#')[0];
|
|
985
829
|
|
|
986
830
|
const notFoundRoute = routes.find((route) => route.NotFound);
|
|
987
831
|
const notFound = notFoundRoute
|
|
@@ -1029,26 +873,32 @@
|
|
|
1029
873
|
};
|
|
1030
874
|
|
|
1031
875
|
const RouterProvider = ({ routes, children }) => {
|
|
1032
|
-
const [location, setLocation] = useStore(
|
|
876
|
+
const [location, setLocation] = useStore(getLocation());
|
|
1033
877
|
|
|
1034
878
|
useEffect(() => {
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
879
|
+
const update = () => setLocation(getLocation());
|
|
880
|
+
|
|
881
|
+
window.addEventListener('popstate', update);
|
|
882
|
+
window.addEventListener('hashchange', update);
|
|
883
|
+
return () => {
|
|
884
|
+
window.removeEventListener('popstate', update);
|
|
885
|
+
window.removeEventListener('hashchange', update);
|
|
886
|
+
}
|
|
1038
887
|
}, []);
|
|
1039
888
|
|
|
1040
889
|
const navigate = (path) => {
|
|
1041
890
|
window.history.pushState({}, '', path);
|
|
1042
|
-
setLocation(
|
|
891
|
+
setLocation(getLocation());
|
|
1043
892
|
};
|
|
1044
893
|
|
|
1045
|
-
const currentRouteData = findRoute(routes, location) || {};
|
|
894
|
+
const currentRouteData = findRoute(routes, location.pathname) || {};
|
|
1046
895
|
const query = useQuery();
|
|
1047
896
|
|
|
1048
897
|
const contextValue = {
|
|
1049
898
|
location,
|
|
1050
899
|
params: currentRouteData.params || {},
|
|
1051
900
|
query,
|
|
901
|
+
hash: location.hash,
|
|
1052
902
|
navigate,
|
|
1053
903
|
route: currentRouteData.route,
|
|
1054
904
|
};
|
|
@@ -1067,11 +917,24 @@
|
|
|
1067
917
|
};
|
|
1068
918
|
|
|
1069
919
|
const Children = () => {
|
|
1070
|
-
const { route, params, query, location } = useRouter();
|
|
920
|
+
const { route, params, query, hash, location } = useRouter();
|
|
1071
921
|
|
|
1072
922
|
if (!route || !route.component) return null
|
|
1073
923
|
|
|
1074
|
-
|
|
924
|
+
useEffect(() => {
|
|
925
|
+
if (hash) {
|
|
926
|
+
const id = hash.slice(1);
|
|
927
|
+
const el = document.getElementById(id);
|
|
928
|
+
if (el) el.scrollIntoView({ behavior: 'smooth' });
|
|
929
|
+
}
|
|
930
|
+
}, [hash]);
|
|
931
|
+
|
|
932
|
+
return createElement(route.component, {
|
|
933
|
+
key: location.pathname,
|
|
934
|
+
params,
|
|
935
|
+
query,
|
|
936
|
+
hash,
|
|
937
|
+
})
|
|
1075
938
|
};
|
|
1076
939
|
|
|
1077
940
|
// Componente NavLink para navegación interna
|
|
@@ -1098,6 +961,7 @@
|
|
|
1098
961
|
createContext: createContext,
|
|
1099
962
|
useCallback: useCallback,
|
|
1100
963
|
useEffect: useEffect,
|
|
964
|
+
useHash: useHash,
|
|
1101
965
|
useMemo: useMemo,
|
|
1102
966
|
useQuery: useQuery,
|
|
1103
967
|
useRef: useRef,
|
|
@@ -1123,6 +987,7 @@
|
|
|
1123
987
|
exports.default = Ryunix;
|
|
1124
988
|
exports.useCallback = useCallback;
|
|
1125
989
|
exports.useEffect = useEffect;
|
|
990
|
+
exports.useHash = useHash;
|
|
1126
991
|
exports.useMemo = useMemo;
|
|
1127
992
|
exports.useQuery = useQuery;
|
|
1128
993
|
exports.useRef = useRef;
|
package/dist/Ryunix.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,t){"use strict";let o={containerRoot:null,nextUnitOfWork:null,currentRoot:null,wipRoot:null,deletions:null,wipFiber:null,hookIndex:null,effects:null};const n=/[A-Z]/g,r=Object.freeze({TEXT_ELEMENT:Symbol("text.element").toString(),Ryunix_ELEMENT:Symbol("ryunix.element").toString(),RYUNIX_EFFECT:Symbol("ryunix.effect").toString(),RYUNIX_MEMO:Symbol("ryunix.memo").toString(),RYUNIX_URL_QUERY:Symbol("ryunix.urlQuery").toString(),RYUNIX_REF:Symbol("ryunix.ref").toString(),RYUNIX_STORE:Symbol("ryunix.store").toString(),RYUNIX_REDUCE:Symbol("ryunix.reduce").toString(),RYUNIX_FRAGMENT:Symbol("ryunix.fragment").toString(),RYUNIX_CONTEXT:Symbol("ryunix.context").toString()}),i=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),s=Object.freeze({style:"style",className:"className"}),
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,t){"use strict";let o={containerRoot:null,nextUnitOfWork:null,currentRoot:null,wipRoot:null,deletions:null,wipFiber:null,hookIndex:null,effects:null};const n=/[A-Z]/g,r=Object.freeze({TEXT_ELEMENT:Symbol("text.element").toString(),Ryunix_ELEMENT:Symbol("ryunix.element").toString(),RYUNIX_EFFECT:Symbol("ryunix.effect").toString(),RYUNIX_MEMO:Symbol("ryunix.memo").toString(),RYUNIX_URL_QUERY:Symbol("ryunix.urlQuery").toString(),RYUNIX_REF:Symbol("ryunix.ref").toString(),RYUNIX_STORE:Symbol("ryunix.store").toString(),RYUNIX_REDUCE:Symbol("ryunix.reduce").toString(),RYUNIX_FRAGMENT:Symbol("ryunix.fragment").toString(),RYUNIX_CONTEXT:Symbol("ryunix.context").toString()}),i=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),s=Object.freeze({style:"style",className:"className"}),a=Object.freeze({PLACEMENT:Symbol("ryunix.reconciler.status.placement").toString(),UPDATE:Symbol("ryunix.reconciler.status.update").toString(),DELETION:Symbol("ryunix.reconciler.status.deletion").toString(),NO_EFFECT:Symbol("ryunix.reconciler.status.no_efect").toString()}),l=(e,t,...o)=>({type:e,props:{...t,children:o.flat().map((e=>typeof e===i.object?e:c(e)))}}),c=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),u=e=>{const t=Array.isArray(e.children)?e.children:[e.children];return l(r.RYUNIX_FRAGMENT,{},...t)},p=e=>e.startsWith("on"),d=e=>e!==i.children&&!p(e),h=(e,t)=>o=>e[o]!==t[o],f=e=>t=>!(t in e),y=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},m=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},E=(e,t,o)=>{Object.keys(t).filter(p).filter((e=>f(o)(e)||h(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(d).filter(f(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(d).filter(h(t,o)).forEach((n=>{if(n===i.style)w(e,o["ryunix-style"]);else if(n===s.style)w(e,o.style);else if(n===i.className){if(""===o["ryunix-class"])throw new Error("data-class cannot be empty.");t["ryunix-class"]&&e.classList.remove(...t["ryunix-class"].split(/\s+/)),e.classList.add(...o["ryunix-class"].split(/\s+/))}else if(n===s.className){if(""===o.className)throw new Error("className cannot be empty.");t.className&&e.classList.remove(...t.className.split(/\s+/)),e.classList.add(...o.className.split(/\s+/))}else e[n]=o[n]})),Object.keys(o).filter(p).filter(h(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])}))},w=(e,t)=>{e.style=Object.keys(t).reduce(((e,o)=>e+=`${o.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${t[o]};`),"")},b=e=>{if(!e)return;let t=e.parent;for(;!t.dom;)t=t.parent;const o=t.dom;if(e.effectTag===a.PLACEMENT)null!=e.dom&&o.appendChild(e.dom),m(e);else if(e.effectTag===a.UPDATE)y(e),null!=e.dom&&E(e.dom,e.alternate.props,e.props),m(e);else if(e.effectTag===a.DELETION)return y(e),void x(e,o);b(e.child),b(e.sibling)},x=(e,t)=>{if(e.dom)t.removeChild(e.dom);else{let o=e.child;for(;o;)x(o,t),o=o.sibling}},R=(e,t)=>{let n,r=0,i=e.alternate&&e.alternate.child;for(;r<t.length||null!=i;){const s=t[r];let l;const c=i&&s&&s.type==i.type;c&&(l={type:i.type,props:s.props,dom:i.dom,parent:e,alternate:i,effectTag:a.UPDATE}),s&&!c&&(l={type:s.type,props:s.props,dom:null,parent:e,alternate:null,effectTag:a.PLACEMENT}),i&&!c&&(i.effectTag=a.DELETION,o.deletions.push(i)),i&&(i=i.sibling),0===r?e.child=l:s&&(n.sibling=l),n=l,r++}},g=e=>{const t=Array.isArray(e.props.children)?e.props.children.flat():[e.props.children];e.type===r.RYUNIX_FRAGMENT||e.dom||(e.dom=(e=>{if(e.type===r.RYUNIX_FRAGMENT)return null;const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return E(t,{},e.props),t})(e)),R(e,t)},k=({src:e,props:t})=>{const o=new URLSearchParams,n=!e.startsWith("http")||!e.startsWith("https");t.width&&o.set("width",t.width),t.height&&o.set("height",t.height),t.quality&&o.set("quality",t.quality);const r=t.extension?`@${t.extension}`:"";return n?(()=>{const{hostname:e}=window.location;return"localhost"===e||"127.0.0.1"===e})()?(console.warn("Image optimizations only work with full links and must not contain localhost."),e):`${window.location.origin}/${e}`:`https://image.unsetsoft.com/image/${e}${r}?${o.toString()}`},N=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=I(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&(o.deletions.forEach(b),b(o.wipRoot.child),o.currentRoot=o.wipRoot,o.wipRoot=null),requestIdleCallback(N)};requestIdleCallback(N);const I=e=>{if(e.type instanceof Function?(e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];const t=[e.type(e.props)];e.type._contextId&&void 0!==e.props.value&&(e._contextId=e.type._contextId,e._contextValue=e.props.value),R(e,t)})(e):g(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}},F=e=>{o.nextUnitOfWork=e,o.wipRoot=e,o.deletions=[],o.hookIndex=0,o.effects=[],requestIdleCallback(N)},v=(e,t)=>(o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],F(o.wipRoot),o.wipRoot),T=(e,t)=>_(((e,t)=>"function"==typeof t?t(e):t),e,t),_=(e,t,n)=>{const r=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],i={state:r?r.state:n?n(t):t,queue:r&&Array.isArray(r.queue)?r.queue.slice():[]};r&&Array.isArray(r.queue)&&r.queue.forEach((t=>{i.state=e(i.state,t)}));return i.queue.forEach((t=>{i.state=e(i.state,t)})),o.wipFiber.hooks[o.hookIndex]=i,o.hookIndex++,[i.state,e=>{i.queue.push(e),o.wipRoot={dom:o.currentRoot.dom,props:o.currentRoot.props,alternate:o.currentRoot},o.deletions=[],o.hookIndex=0,F(o.wipRoot)}]},S=(e,n)=>{const i=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],s={type:r.RYUNIX_EFFECT,deps:n,cleanup:i?.cleanup};(!i||!t.isEqual(i.deps,n))&&o.effects.push((()=>{"function"==typeof s.cleanup&&s.cleanup();const t=e();"function"==typeof t&&(s.cleanup=t)})),o.wipFiber.hooks[o.hookIndex]=s,o.hookIndex++},U=e=>{const t=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],n={type:r.RYUNIX_REF,value:t?t.value:{current:e}};return o.wipFiber.hooks[o.hookIndex]=n,o.hookIndex++,n.value},C=(e,n)=>{const i=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],s={type:r.RYUNIX_MEMO,value:null,deps:n};return i&&t.isEqual(i.deps,s.deps)?s.value=i.value:s.value=e(),o.wipFiber.hooks[o.hookIndex]=s,o.hookIndex++,s.value},L=(e,t)=>C((()=>e),t),O=e=>{const t=r.RYUNIX_CONTEXT,n=({value:e,children:t})=>u({children:t});n._contextId=t;return{Provider:n,useContext:()=>{let n=o.wipFiber;for(;n;){if(n.type&&n.type._contextId===t)return n.props&&"value"in n.props?n.props.value:void 0;n=n.parent}return e}}},X=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},q=()=>window.location.hash,A=()=>({pathname:window.location.pathname,search:window.location.search,hash:window.location.hash}),M=O({location:"/",params:{},query:{},hash:"",navigate:e=>{},route:null}),Y=(e,t)=>{const o=t.split("?")[0].split("#")[0],n=e.find((e=>e.NotFound)),r=n?{route:{component:n.NotFound},params:{}}:{route:{component:null},params:{}};for(const n of e){if(n.subRoutes){const e=Y(n.subRoutes,t);if(e)return e}if("*"===n.path)return r;if(!n.path||"string"!=typeof n.path){console.warn("Invalid route detected:",n),console.info("if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }");continue}const e=[],i=new RegExp(`^${n.path.replace(/:\w+/g,(t=>(e.push(t.substring(1)),"([^/]+)")))}$`),s=o.match(i);if(s){return{route:n,params:e.reduce(((e,t,o)=>(e[t]=s[o+1],e)),{})}}}return r},j=({routes:e,children:t})=>{const[o,n]=T(A());S((()=>{const e=()=>n(A());return window.addEventListener("popstate",e),window.addEventListener("hashchange",e),()=>{window.removeEventListener("popstate",e),window.removeEventListener("hashchange",e)}}),[]);const r=Y(e,o.pathname)||{},i=X(),s={location:o,params:r.params||{},query:i,hash:o.hash,navigate:e=>{window.history.pushState({},"",e),n(A())},route:r.route};return l(M.Provider,{value:s},u({children:t}))},P=()=>M.useContext(),W=()=>{const{route:e,params:t,query:o,hash:n,location:r}=P();return e&&e.component?(S((()=>{if(n){const e=n.slice(1),t=document.getElementById(e);t&&t.scrollIntoView({behavior:"smooth"})}}),[n]),l(e.component,{key:r.pathname,params:t,query:o,hash:n})):null},$=({to:e,...t})=>{const{navigate:o}=P();return l("a",{href:e,onClick:t=>{t.preventDefault(),o(e)},...t},t.children)};var D={createElement:l,render:v,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return v(e,o.containerRoot)},Fragment:u,Hooks:Object.freeze({__proto__:null,Children:W,NavLink:$,RouterProvider:j,createContext:O,useCallback:L,useEffect:S,useHash:q,useMemo:C,useQuery:X,useRef:U,useRouter:P,useStore:T})};window.Ryunix=D,e.Children=W,e.Image=({src:e,...t})=>{const o={src:"true"===t.optimization?k({src:e,props:t}):e,...t};return l("img",o,null)},e.NavLink=$,e.RouterProvider=j,e.createContext=O,e.default=D,e.useCallback=L,e.useEffect=S,e.useHash=q,e.useMemo=C,e.useQuery=X,e.useRef=U,e.useRouter=P,e.useStore=T,Object.defineProperty(e,"__esModule",{value:!0})}));
|