@unsetsoft/ryunixjs 1.1.7-canary.71 → 1.1.7-canary.74
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 +210 -86
- package/dist/Ryunix.min.js +1 -1
- package/package.json +1 -1
package/dist/Ryunix.js
CHANGED
|
@@ -761,7 +761,6 @@
|
|
|
761
761
|
const contextId = RYUNIX_TYPES.RYUNIX_CONTEXT;
|
|
762
762
|
|
|
763
763
|
const Provider = ({ value, children }) => {
|
|
764
|
-
// Solo devuelve children, Ryunix creará el fiber automáticamente con props
|
|
765
764
|
return Fragment({
|
|
766
765
|
children: children,
|
|
767
766
|
})
|
|
@@ -773,7 +772,6 @@
|
|
|
773
772
|
let fiber = vars.wipFiber;
|
|
774
773
|
while (fiber) {
|
|
775
774
|
if (fiber.type && fiber.type._contextId === contextId) {
|
|
776
|
-
// Protegemos el acceso a props.value
|
|
777
775
|
if (fiber.props && 'value' in fiber.props) {
|
|
778
776
|
return fiber.props.value
|
|
779
777
|
}
|
|
@@ -845,117 +843,240 @@
|
|
|
845
843
|
* </>
|
|
846
844
|
* );
|
|
847
845
|
*/
|
|
848
|
-
const useRouter = (routes) => {
|
|
849
|
-
|
|
846
|
+
// const useRouter = (routes) => {
|
|
847
|
+
// const [location, setLocation] = useStore(window.location.pathname)
|
|
848
|
+
|
|
849
|
+
// const findRoute = (routes, path) => {
|
|
850
|
+
// const pathname = path.split('?')[0]
|
|
851
|
+
|
|
852
|
+
// const notFoundRoute = routes.find((route) => route.NotFound)
|
|
853
|
+
// const notFound = notFoundRoute
|
|
854
|
+
// ? { route: { component: notFoundRoute.NotFound }, params: {} }
|
|
855
|
+
// : { route: { component: null }, params: {} }
|
|
856
|
+
|
|
857
|
+
// for (const route of routes) {
|
|
858
|
+
// if (route.subRoutes) {
|
|
859
|
+
// const childRoute = findRoute(route.subRoutes, path)
|
|
860
|
+
// if (childRoute) return childRoute
|
|
861
|
+
// }
|
|
862
|
+
|
|
863
|
+
// if (route.path === '*') {
|
|
864
|
+
// return notFound
|
|
865
|
+
// }
|
|
866
|
+
|
|
867
|
+
// if (!route.path || typeof route.path !== 'string') {
|
|
868
|
+
// console.warn('Invalid route detected:', route)
|
|
869
|
+
// console.info(
|
|
870
|
+
// "if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }",
|
|
871
|
+
// )
|
|
872
|
+
// continue
|
|
873
|
+
// }
|
|
874
|
+
|
|
875
|
+
// const keys = []
|
|
876
|
+
// const pattern = new RegExp(
|
|
877
|
+
// `^${route.path.replace(/:\w+/g, (match) => {
|
|
878
|
+
// keys.push(match.substring(1))
|
|
879
|
+
// return '([^/]+)'
|
|
880
|
+
// })}$`,
|
|
881
|
+
// )
|
|
882
|
+
|
|
883
|
+
// const match = pathname.match(pattern)
|
|
884
|
+
// if (match) {
|
|
885
|
+
// const params = keys.reduce((acc, key, index) => {
|
|
886
|
+
// acc[key] = match[index + 1]
|
|
887
|
+
// return acc
|
|
888
|
+
// }, {})
|
|
889
|
+
|
|
890
|
+
// return { route, params }
|
|
891
|
+
// }
|
|
892
|
+
// }
|
|
893
|
+
|
|
894
|
+
// return notFound
|
|
895
|
+
// }
|
|
896
|
+
|
|
897
|
+
// const navigate = (path) => {
|
|
898
|
+
// window.history.pushState({}, '', path)
|
|
899
|
+
|
|
900
|
+
// updateRoute(path)
|
|
901
|
+
// }
|
|
902
|
+
|
|
903
|
+
// const updateRoute = (path) => {
|
|
904
|
+
// const cleanedPath = path.split('?')[0]
|
|
905
|
+
// setLocation(cleanedPath)
|
|
906
|
+
// }
|
|
907
|
+
|
|
908
|
+
// useEffect(() => {
|
|
909
|
+
// const onPopState = () => updateRoute(window.location.pathname)
|
|
910
|
+
// window.addEventListener('popstate', onPopState)
|
|
911
|
+
|
|
912
|
+
// return () => window.removeEventListener('popstate', onPopState)
|
|
913
|
+
// }, [])
|
|
914
|
+
|
|
915
|
+
// const currentRouteData = findRoute(routes, location) || {}
|
|
916
|
+
|
|
917
|
+
// const Children = () => {
|
|
918
|
+
// const query = useQuery()
|
|
919
|
+
// const { route } = currentRouteData
|
|
920
|
+
|
|
921
|
+
// if (
|
|
922
|
+
// !route ||
|
|
923
|
+
// !route.component ||
|
|
924
|
+
// typeof route.component !== STRINGS.function
|
|
925
|
+
// ) {
|
|
926
|
+
// console.error(
|
|
927
|
+
// 'Component not found for current path or the component is not a valid function:',
|
|
928
|
+
// currentRouteData,
|
|
929
|
+
// )
|
|
930
|
+
// return null
|
|
931
|
+
// }
|
|
932
|
+
|
|
933
|
+
// const WrappedComponent = () =>
|
|
934
|
+
// createElement(route.component, {
|
|
935
|
+
// key: location,
|
|
936
|
+
// params: currentRouteData.params || {},
|
|
937
|
+
// query,
|
|
938
|
+
// })
|
|
939
|
+
|
|
940
|
+
// return createElement(WrappedComponent)
|
|
941
|
+
// }
|
|
942
|
+
|
|
943
|
+
// const NavLink = ({ to, ...props }) => {
|
|
944
|
+
// const handleClick = (e) => {
|
|
945
|
+
// e.preventDefault()
|
|
946
|
+
// navigate(to)
|
|
947
|
+
// }
|
|
948
|
+
// return createElement(
|
|
949
|
+
// 'a',
|
|
950
|
+
// { href: to, onClick: handleClick, ...props },
|
|
951
|
+
// props.children,
|
|
952
|
+
// )
|
|
953
|
+
// }
|
|
954
|
+
|
|
955
|
+
// return { Children, NavLink, navigate }
|
|
956
|
+
// }
|
|
957
|
+
|
|
958
|
+
// Crear contexto para Router
|
|
959
|
+
const RouterContext = createContext({
|
|
960
|
+
location: '/',
|
|
961
|
+
params: {},
|
|
962
|
+
query: {},
|
|
963
|
+
navigate: (path) => {},
|
|
964
|
+
route: null,
|
|
965
|
+
});
|
|
850
966
|
|
|
851
|
-
|
|
852
|
-
|
|
967
|
+
const findRoute = (routes, path) => {
|
|
968
|
+
const pathname = path.split('?')[0];
|
|
853
969
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
970
|
+
const notFoundRoute = routes.find((route) => route.NotFound);
|
|
971
|
+
const notFound = notFoundRoute
|
|
972
|
+
? { route: { component: notFoundRoute.NotFound }, params: {} }
|
|
973
|
+
: { route: { component: null }, params: {} };
|
|
858
974
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
if (route.path === '*') {
|
|
866
|
-
return notFound
|
|
867
|
-
}
|
|
975
|
+
for (const route of routes) {
|
|
976
|
+
if (route.subRoutes) {
|
|
977
|
+
const childRoute = findRoute(route.subRoutes, path);
|
|
978
|
+
if (childRoute) return childRoute
|
|
979
|
+
}
|
|
868
980
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
"if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }",
|
|
873
|
-
);
|
|
874
|
-
continue
|
|
875
|
-
}
|
|
981
|
+
if (route.path === '*') {
|
|
982
|
+
return notFound
|
|
983
|
+
}
|
|
876
984
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
return '([^/]+)'
|
|
882
|
-
})}$`,
|
|
985
|
+
if (!route.path || typeof route.path !== 'string') {
|
|
986
|
+
console.warn('Invalid route detected:', route);
|
|
987
|
+
console.info(
|
|
988
|
+
"if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }",
|
|
883
989
|
);
|
|
990
|
+
continue
|
|
991
|
+
}
|
|
884
992
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
993
|
+
const keys = [];
|
|
994
|
+
const pattern = new RegExp(
|
|
995
|
+
`^${route.path.replace(/:\w+/g, (match) => {
|
|
996
|
+
keys.push(match.substring(1));
|
|
997
|
+
return '([^/]+)'
|
|
998
|
+
})}$`,
|
|
999
|
+
);
|
|
1000
|
+
|
|
1001
|
+
const match = pathname.match(pattern);
|
|
1002
|
+
if (match) {
|
|
1003
|
+
const params = keys.reduce((acc, key, index) => {
|
|
1004
|
+
acc[key] = match[index + 1];
|
|
1005
|
+
return acc
|
|
1006
|
+
}, {});
|
|
1007
|
+
|
|
1008
|
+
return { route, params }
|
|
894
1009
|
}
|
|
1010
|
+
}
|
|
895
1011
|
|
|
896
|
-
|
|
897
|
-
|
|
1012
|
+
return notFound
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
const RouterProvider = ({ routes, children }) => {
|
|
1016
|
+
const [location, setLocation] = useStore(window.location.pathname);
|
|
1017
|
+
|
|
1018
|
+
useEffect(() => {
|
|
1019
|
+
const onPopState = () => setLocation(window.location.pathname);
|
|
1020
|
+
window.addEventListener('popstate', onPopState);
|
|
1021
|
+
return () => window.removeEventListener('popstate', onPopState)
|
|
1022
|
+
}, []);
|
|
898
1023
|
|
|
899
1024
|
const navigate = (path) => {
|
|
900
1025
|
window.history.pushState({}, '', path);
|
|
901
|
-
|
|
902
|
-
updateRoute(path);
|
|
1026
|
+
setLocation(path);
|
|
903
1027
|
};
|
|
904
1028
|
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
|
|
1029
|
+
const currentRouteData = findRoute(routes, location) || {};
|
|
1030
|
+
const query = useQuery();
|
|
1031
|
+
|
|
1032
|
+
const contextValue = {
|
|
1033
|
+
location,
|
|
1034
|
+
params: currentRouteData.params || {},
|
|
1035
|
+
query,
|
|
1036
|
+
navigate,
|
|
1037
|
+
route: currentRouteData.route,
|
|
908
1038
|
};
|
|
909
1039
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1040
|
+
return createElement(
|
|
1041
|
+
RouterContext.Provider,
|
|
1042
|
+
{ value: contextValue },
|
|
1043
|
+
children,
|
|
1044
|
+
)
|
|
1045
|
+
};
|
|
913
1046
|
|
|
914
|
-
|
|
915
|
-
|
|
1047
|
+
const useRouter = () => {
|
|
1048
|
+
return RouterContext.useContext()
|
|
1049
|
+
};
|
|
916
1050
|
|
|
917
|
-
|
|
1051
|
+
const Children = () => {
|
|
1052
|
+
const { route, params, query, location } = useRouter();
|
|
918
1053
|
|
|
919
|
-
|
|
920
|
-
const query = useQuery();
|
|
921
|
-
const { route } = currentRouteData;
|
|
922
|
-
|
|
923
|
-
if (
|
|
924
|
-
!route ||
|
|
925
|
-
!route.component ||
|
|
926
|
-
typeof route.component !== STRINGS.function
|
|
927
|
-
) {
|
|
928
|
-
console.error(
|
|
929
|
-
'Component not found for current path or the component is not a valid function:',
|
|
930
|
-
currentRouteData,
|
|
931
|
-
);
|
|
932
|
-
return null
|
|
933
|
-
}
|
|
1054
|
+
if (!route || !route.component) return null
|
|
934
1055
|
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
params: currentRouteData.params || {},
|
|
938
|
-
query,
|
|
939
|
-
})
|
|
940
|
-
};
|
|
1056
|
+
return createElement(route.component, { key: location, params, query })
|
|
1057
|
+
};
|
|
941
1058
|
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
{ href: to, onClick: handleClick, ...props },
|
|
950
|
-
props.children,
|
|
951
|
-
)
|
|
1059
|
+
// Componente NavLink para navegación interna
|
|
1060
|
+
const NavLink = ({ to, ...props }) => {
|
|
1061
|
+
const { navigate } = useRouter();
|
|
1062
|
+
|
|
1063
|
+
const handleClick = (e) => {
|
|
1064
|
+
e.preventDefault();
|
|
1065
|
+
navigate(to);
|
|
952
1066
|
};
|
|
953
1067
|
|
|
954
|
-
return
|
|
1068
|
+
return createElement(
|
|
1069
|
+
'a',
|
|
1070
|
+
{ href: to, onClick: handleClick, ...props },
|
|
1071
|
+
props.children,
|
|
1072
|
+
)
|
|
955
1073
|
};
|
|
956
1074
|
|
|
957
1075
|
var Hooks = /*#__PURE__*/Object.freeze({
|
|
958
1076
|
__proto__: null,
|
|
1077
|
+
Children: Children,
|
|
1078
|
+
NavLink: NavLink,
|
|
1079
|
+
RouterProvider: RouterProvider,
|
|
959
1080
|
createContext: createContext,
|
|
960
1081
|
useCallback: useCallback,
|
|
961
1082
|
useEffect: useEffect,
|
|
@@ -976,7 +1097,10 @@
|
|
|
976
1097
|
|
|
977
1098
|
window.Ryunix = Ryunix;
|
|
978
1099
|
|
|
1100
|
+
exports.Children = Children;
|
|
979
1101
|
exports.Image = Image;
|
|
1102
|
+
exports.NavLink = NavLink;
|
|
1103
|
+
exports.RouterProvider = RouterProvider;
|
|
980
1104
|
exports.createContext = createContext;
|
|
981
1105
|
exports.default = Ryunix;
|
|
982
1106
|
exports.useCallback = useCallback;
|
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"}),l=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()}),a=(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=>a(r.RYUNIX_FRAGMENT,{},...e.children),p=e=>e.startsWith("on"),d=e=>e!==i.children&&!p(e),f=(e,t)=>o=>e[o]!==t[o],h=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=>h(o)(e)||f(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(d).filter(h(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(d).filter(f(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(f(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===l.PLACEMENT)null!=e.dom&&o.appendChild(e.dom),m(e);else if(e.effectTag===l.UPDATE)y(e),null!=e.dom&&E(e.dom,e.alternate.props,e.props),m(e);else if(e.effectTag===l.DELETION)return y(e),void x(e,o);b(e.child),b(e.sibling)},x=(e,t)=>{e.dom?t.removeChild(e.dom):x(e.child,t)},R=(e,t)=>{let n,r=0,i=e.alternate&&e.alternate.child;for(;r<t.length||null!=i;){const s=t[r];let a;const c=i&&s&&s.type==i.type;c&&(a={type:i.type,props:s.props,dom:i.dom,parent:e,alternate:i,effectTag:l.UPDATE}),s&&!c&&(a={type:s.type,props:s.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT}),i&&!c&&(i.effectTag=l.DELETION,o.deletions.push(i)),i&&(i=i.sibling),0===r?e.child=a:s&&(n.sibling=a),n=a,r++}},g=e=>{e.type===r.RYUNIX_FRAGMENT||e.dom||(e.dom=(e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return E(t,{},e.props),t})(e)),R(e,e.props.children.flat())},k=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=N(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(k)};requestIdleCallback(k);const N=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}},I=e=>{o.nextUnitOfWork=e,o.wipRoot=e,o.deletions=[],o.hookIndex=0,o.effects=[],requestIdleCallback(k)},F=(e,t)=>(o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],I(o.wipRoot),o.wipRoot),T=(e,t)=>
|
|
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"}),l=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()}),a=(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=>a(r.RYUNIX_FRAGMENT,{},...e.children),p=e=>e.startsWith("on"),d=e=>e!==i.children&&!p(e),f=(e,t)=>o=>e[o]!==t[o],h=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=>h(o)(e)||f(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(d).filter(h(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(d).filter(f(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(f(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===l.PLACEMENT)null!=e.dom&&o.appendChild(e.dom),m(e);else if(e.effectTag===l.UPDATE)y(e),null!=e.dom&&E(e.dom,e.alternate.props,e.props),m(e);else if(e.effectTag===l.DELETION)return y(e),void x(e,o);b(e.child),b(e.sibling)},x=(e,t)=>{e.dom?t.removeChild(e.dom):x(e.child,t)},R=(e,t)=>{let n,r=0,i=e.alternate&&e.alternate.child;for(;r<t.length||null!=i;){const s=t[r];let a;const c=i&&s&&s.type==i.type;c&&(a={type:i.type,props:s.props,dom:i.dom,parent:e,alternate:i,effectTag:l.UPDATE}),s&&!c&&(a={type:s.type,props:s.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT}),i&&!c&&(i.effectTag=l.DELETION,o.deletions.push(i)),i&&(i=i.sibling),0===r?e.child=a:s&&(n.sibling=a),n=a,r++}},g=e=>{e.type===r.RYUNIX_FRAGMENT||e.dom||(e.dom=(e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return E(t,{},e.props),t})(e)),R(e,e.props.children.flat())},k=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=N(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(k)};requestIdleCallback(k);const N=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}},I=e=>{o.nextUnitOfWork=e,o.wipRoot=e,o.deletions=[],o.hookIndex=0,o.effects=[],requestIdleCallback(k)},F=(e,t)=>(o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],I(o.wipRoot),o.wipRoot),T=(e,t)=>v(((e,t)=>"function"==typeof t?t(e):t),e,t),v=(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,I(o.wipRoot)}]},_=(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++},S=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},U=(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},C=(e,t)=>U((()=>e),t),O=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},L=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=L({location:"/",params:{},query:{},navigate:e=>{},route:null}),q=(e,t)=>{const o=t.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=q(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},M=({routes:e,children:t})=>{const[o,n]=T(window.location.pathname);_((()=>{const e=()=>n(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const r=q(e,o)||{},i=O(),s={location:o,params:r.params||{},query:i,navigate:e=>{window.history.pushState({},"",e),n(e)},route:r.route};return a(X.Provider,{value:s},t)},Y=()=>X.useContext(),j=()=>{const{route:e,params:t,query:o,location:n}=Y();return e&&e.component?a(e.component,{key:n,params:t,query:o}):null},A=({to:e,...t})=>{const{navigate:o}=Y();return a("a",{href:e,onClick:t=>{t.preventDefault(),o(e)},...t},t.children)};var P={createElement:a,render:F,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return F(e,o.containerRoot)},Fragment:u,Hooks:Object.freeze({__proto__:null,Children:j,NavLink:A,RouterProvider:M,createContext:L,useCallback:C,useEffect:_,useMemo:U,useQuery:O,useRef:S,useRouter:Y,useStore:T})};window.Ryunix=P,e.Children=j,e.Image=({src:e,...t})=>{const o="true"===t.optimization?(({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("width",t.height),t.quality&&o.set("quality",t.quality);const r=t.extension?`@${t.extension}`:"",i="http://localhost:3000"===window.location.origin||"http://localhost:5173"===window.location.origin||"http://localhost:4173"===window.location.origin;return n?i?(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()}`})({src:e,props:t}):e;return a("img",{src:o,props:t},null)},e.NavLink=A,e.RouterProvider=M,e.createContext=L,e.default=P,e.useCallback=C,e.useEffect=_,e.useMemo=U,e.useQuery=O,e.useRef=S,e.useRouter=Y,e.useStore=T,Object.defineProperty(e,"__esModule",{value:!0})}));
|