@unsetsoft/ryunixjs 1.1.7-canary.4 → 1.1.7-canary.40

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 CHANGED
@@ -18,14 +18,15 @@
18
18
  const reg = /[A-Z]/g;
19
19
 
20
20
  const RYUNIX_TYPES = Object.freeze({
21
- TEXT_ELEMENT: Symbol('text.element'),
22
- Ryunix_ELEMENT: Symbol('ryunix.element'),
23
- RYUNIX_EFFECT: Symbol('ryunix.effect'),
24
- RYUNIX_MEMO: Symbol('ryunix.memo'),
25
- RYUNIX_URL_QUERY: Symbol('ryunix.urlQuery'),
26
- RYUNIX_REF: Symbol('ryunix.ref'),
27
- RYUNIX_STORE: Symbol('ryunix.store'),
28
- RYUNIX_REDUCE: Symbol('ryunix.reduce'),
21
+ TEXT_ELEMENT: Symbol('text.element').toString(),
22
+ Ryunix_ELEMENT: Symbol('ryunix.element').toString(),
23
+ RYUNIX_EFFECT: Symbol('ryunix.effect').toString(),
24
+ RYUNIX_MEMO: Symbol('ryunix.memo').toString(),
25
+ RYUNIX_URL_QUERY: Symbol('ryunix.urlQuery').toString(),
26
+ RYUNIX_REF: Symbol('ryunix.ref').toString(),
27
+ RYUNIX_STORE: Symbol('ryunix.store').toString(),
28
+ RYUNIX_REDUCE: Symbol('ryunix.reduce').toString(),
29
+ RYUNIX_FRAGMENT: Symbol('ryunix.fragment').toString(),
29
30
  });
30
31
 
31
32
  const STRINGS = Object.freeze({
@@ -47,12 +48,17 @@
47
48
  PLACEMENT: Symbol('ryunix.reconciler.status.placement').toString(),
48
49
  UPDATE: Symbol('ryunix.reconciler.status.update').toString(),
49
50
  DELETION: Symbol('ryunix.reconciler.status.deletion').toString(),
51
+ NO_EFFECT: Symbol('ryunix.reconciler.status.no_efect').toString(),
50
52
  });
51
53
 
52
54
  const Fragment = (props) => {
55
+ console.log(props);
56
+
53
57
  return props.children
54
58
  };
55
59
 
60
+ Fragment.isFragment = true;
61
+
56
62
  /**
57
63
  * The function creates a new element with the given type, props, and children.
58
64
  * @param type - The type of the element to be created, such as "div", "span", "h1", etc.
@@ -71,15 +77,18 @@
71
77
  */
72
78
 
73
79
  const createElement = (type, props, ...children) => {
80
+ const key = props && props.key ? props.key : null;
81
+ const isFragment = type.isFragment || false;
82
+
74
83
  return {
75
84
  type,
85
+ isFragment,
76
86
  props: {
77
87
  ...props,
78
- children: children
79
- .flat()
80
- .map((child) =>
81
- typeof child === STRINGS.object ? child : createTextElement(child),
82
- ),
88
+ key,
89
+ children: children.map((child) =>
90
+ typeof child === STRINGS.object ? child : createTextElement(child),
91
+ ),
83
92
  },
84
93
  }
85
94
  };
@@ -301,28 +310,87 @@
301
310
  }
302
311
  };
303
312
 
313
+ /**
314
+ * This function reconciles the children of a fiber node with a new set of elements, creating new
315
+ * fibers for new elements, updating existing fibers for elements with the same type, and marking old
316
+ * fibers for deletion if they are not present in the new set of elements.
317
+ * @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
318
+ * DOM tree.
319
+ * @param elements - an array of elements representing the new children to be rendered in the current
320
+ * fiber's subtree
321
+ */
322
+ const shouldComponentUpdate = (oldProps, newProps) => {
323
+ // Comparar las propiedades antiguas y nuevas
324
+ return (
325
+ !oldProps ||
326
+ !newProps ||
327
+ Object.keys(oldProps).length !== Object.keys(newProps).length ||
328
+ Object.keys(newProps).some((key) => oldProps[key] !== newProps[key])
329
+ )
330
+ };
331
+
304
332
  const reconcileChildren = (wipFiber, elements) => {
305
333
  let index = 0;
306
334
  let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
307
- let prevSibling;
335
+ let prevSibling = null;
308
336
 
309
- while (index < elements.length || oldFiber != null) {
310
- const element = elements[index];
311
- let newFiber;
337
+ const oldFibersMap = new Map();
338
+
339
+ // Index para generar claves en ausencia de key
340
+ let keyIndex = 0;
341
+
342
+ while (oldFiber) {
343
+ const key = oldFiber.props?.key || oldFiber.type + '-' + keyIndex++;
344
+ oldFibersMap.set(key, oldFiber);
345
+ oldFiber = oldFiber.sibling;
346
+ }
347
+
348
+ index = 0;
349
+ while (index < elements.length) {
350
+ let element = elements[index];
351
+
352
+ // Si es fragmento, expandimos sus hijos
353
+ if (element.isFragment) {
354
+ const fragmentChildren = element.props.children || [];
355
+
356
+ if (Array.isArray(fragmentChildren)) {
357
+ if (fragmentChildren.length > 1 && !element.props?.key) {
358
+ console.warn(
359
+ `⚠️ Warning: Fragment at index ${index} is missing a key and has multiple children. Esto puede causar errores en reconciliación.`,
360
+ );
361
+ }
362
+
363
+ elements.splice(index, 1, ...fragmentChildren);
364
+ continue // Volvemos a iterar desde el mismo index
365
+ } else {
366
+ element = fragmentChildren;
367
+ }
368
+ }
312
369
 
313
- const sameType = oldFiber && element && element.type == oldFiber.type;
370
+ const key = element.props?.key ?? index;
371
+ const matchedOldFiber = oldFibersMap.get(key);
372
+
373
+ let newFiber;
374
+ const sameType =
375
+ matchedOldFiber && element && element.type === matchedOldFiber.type;
314
376
 
315
377
  if (sameType) {
378
+ const shouldUpdate = shouldComponentUpdate(
379
+ matchedOldFiber.props,
380
+ element.props,
381
+ );
382
+
316
383
  newFiber = {
317
- type: oldFiber.type,
384
+ type: matchedOldFiber.type,
318
385
  props: element.props,
319
- dom: oldFiber.dom,
386
+ dom: matchedOldFiber.dom,
320
387
  parent: wipFiber,
321
- alternate: oldFiber,
322
- effectTag: EFFECT_TAGS.UPDATE,
388
+ alternate: matchedOldFiber,
389
+ effectTag: shouldUpdate ? EFFECT_TAGS.UPDATE : EFFECT_TAGS.NO_EFFECT,
323
390
  };
324
- }
325
- if (element && !sameType) {
391
+
392
+ oldFibersMap.delete(key);
393
+ } else if (element) {
326
394
  newFiber = {
327
395
  type: element.type,
328
396
  props: element.props,
@@ -331,25 +399,31 @@
331
399
  alternate: null,
332
400
  effectTag: EFFECT_TAGS.PLACEMENT,
333
401
  };
334
- }
335
- if (oldFiber && !sameType) {
336
- oldFiber.effectTag = EFFECT_TAGS.DELETION;
337
- vars.deletions.push(oldFiber);
338
- }
339
402
 
340
- if (oldFiber) {
341
- oldFiber = oldFiber.sibling;
403
+ if (matchedOldFiber) {
404
+ matchedOldFiber.effectTag = EFFECT_TAGS.DELETION;
405
+ vars.deletions.push(matchedOldFiber);
406
+ oldFibersMap.delete(key);
407
+ }
342
408
  }
343
409
 
344
- if (index === 0) {
345
- wipFiber.child = newFiber;
346
- } else if (element) {
347
- prevSibling.sibling = newFiber;
410
+ if (newFiber) {
411
+ if (index === 0) {
412
+ wipFiber.child = newFiber;
413
+ } else if (prevSibling) {
414
+ prevSibling.sibling = newFiber;
415
+ }
416
+
417
+ prevSibling = newFiber;
348
418
  }
349
419
 
350
- prevSibling = newFiber;
351
420
  index++;
352
421
  }
422
+
423
+ oldFibersMap.forEach((remainingFiber) => {
424
+ remainingFiber.effectTag = EFFECT_TAGS.DELETION;
425
+ vars.deletions.push(remainingFiber);
426
+ });
353
427
  };
354
428
 
355
429
  /**
@@ -584,6 +658,8 @@
584
658
  };
585
659
  vars.nextUnitOfWork = vars.wipRoot;
586
660
  vars.deletions = [];
661
+
662
+ scheduleWork(vars.wipRoot);
587
663
  };
588
664
 
589
665
  vars.wipFiber.hooks.push(hook);
@@ -838,10 +914,14 @@
838
914
  return null
839
915
  }
840
916
 
841
- return route.component({
842
- params: currentRouteData.params || {},
843
- query,
844
- })
917
+ return createElement(
918
+ Fragment,
919
+ null,
920
+ createElement(route.component, {
921
+ params: currentRouteData.params || {},
922
+ query,
923
+ }),
924
+ )
845
925
  };
846
926
 
847
927
  const NavLink = ({ to, ...props }) => {
@@ -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"),Ryunix_ELEMENT:Symbol("ryunix.element"),RYUNIX_EFFECT:Symbol("ryunix.effect"),RYUNIX_MEMO:Symbol("ryunix.memo"),RYUNIX_URL_QUERY:Symbol("ryunix.urlQuery"),RYUNIX_REF:Symbol("ryunix.ref"),RYUNIX_STORE:Symbol("ryunix.store"),RYUNIX_REDUCE:Symbol("ryunix.reduce")}),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()}),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=>e.startsWith("on"),p=e=>e!==i.children&&!u(e),f=(e,t)=>o=>e[o]!==t[o],d=e=>t=>!(t in e),h=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()}))},y=(e,t,o)=>{Object.keys(t).filter(u).filter((e=>d(o)(e)||f(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(p).filter(d(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(p).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(u).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]};`),"")},E=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&&null!=e.dom)h(e),y(e.dom,e.alternate.props,e.props),m(e);else if(e.effectTag===l.DELETION)return b(e,o),void h(e);E(e.child),E(e.sibling)},b=(e,t)=>{e.dom?t.removeChild(e.dom):b(e.child,t)},k=(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++}},R=e=>{e.dom||(e.dom=(e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return y(t,{},e.props),t})(e)),k(e,e.props.children)},x=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=g(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&(o.deletions.forEach(E),o.wipRoot&&o.wipRoot.child&&(E(o.wipRoot.child),o.currentRoot=o.wipRoot),o.effects.forEach((e=>{try{e()}catch(e){console.error("Error in effect:",e)}})),o.effects=[],o.wipRoot=null),requestIdleCallback(x)},g=e=>{if(e.type instanceof Function?(e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];const t=e.type(e.props);let n=Array.isArray(t)?t:[t];k(e,n)})(e):R(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}},N=(e,t)=>{var n;return o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],n=o.wipRoot,o.nextUnitOfWork=n,o.wipRoot=n,o.deletions=[],o.hookIndex=0,o.effects=[],requestIdleCallback(x),o.wipRoot},F=e=>{const t=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],n={state:t?t.state:e,queue:[]};(t?t.queue:[]).forEach((e=>{n.state=typeof e===i.function?e(n.state):e}));return o.wipFiber.hooks.push(n),o.hookIndex++,[n.state,e=>{n.queue.push(e),o.wipRoot={dom:o.currentRoot.dom,props:o.currentRoot.props,alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[]}]},I=(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++},T=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},v=(e,t)=>U((()=>e),t),L=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},O=e=>{const[t,o]=F(window.location.pathname),n=(e,t)=>{const o=t.split("?")[0],r=e.find((e=>e.NotFound)),i=r?{route:{component:r.NotFound},params:{}}:{route:{component:null},params:{}};for(const r of e){if(r.subRoutes){const e=n(r.subRoutes,t);if(e)return e}if("*"===r.path)return i;if(!r.path||"string"!=typeof r.path){console.warn("Invalid route detected:",r),console.info("if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }");continue}const e=[],s=new RegExp(`^${r.path.replace(/:\w+/g,(t=>(e.push(t.substring(1)),"([^/]+)")))}$`),l=o.match(s);if(l){return{route:r,params:e.reduce(((e,t,o)=>(e[t]=l[o+1],e)),{})}}}return i},r=e=>{window.history.pushState({},"",e),s(e)},s=e=>{const t=e.split("?")[0];o(t)};I((()=>{const e=()=>s(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=L(),{route:t}=l;return t&&t.component&&typeof t.component===i.function?t.component({params:l.params||{},query:e}):(console.error("Component not found for current path or the component is not a valid function:",l),null)},NavLink:({to:e,...t})=>a("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}};var _={createElement:a,render:N,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return N(e,o.containerRoot)},Fragment:e=>e.children,Hooks:Object.freeze({__proto__:null,useCallback:v,useEffect:I,useMemo:U,useQuery:L,useRef:T,useRouter:O,useStore:F})};window.Ryunix=_,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.default=_,e.useCallback=v,e.useEffect=I,e.useMemo=U,e.useQuery=L,e.useRef=T,e.useRouter=O,e.useStore=F,Object.defineProperty(e,"__esModule",{value:!0})}));
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()}),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=>(console.log(e),e.children);a.isFragment=!0;const c=(e,t,...o)=>{const n=t&&t.key?t.key:null;return{type:e,isFragment:e.isFragment||!1,props:{...t,key:n,children:o.map((e=>typeof e===i.object?e:u(e)))}}},u=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),p=e=>e.startsWith("on"),f=e=>e!==i.children&&!p(e),d=(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)||d(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(f).filter(h(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(f).filter(d(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(d(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&&null!=e.dom)y(e),E(e.dom,e.alternate.props,e.props),m(e);else if(e.effectTag===l.DELETION)return g(e,o),void y(e);b(e.child),b(e.sibling)},g=(e,t)=>{e.dom?t.removeChild(e.dom):g(e.child,t)},k=(e,t)=>!e||!t||Object.keys(e).length!==Object.keys(t).length||Object.keys(t).some((o=>e[o]!==t[o])),R=(e,t)=>{let n=0,r=e.alternate&&e.alternate.child,i=null;const s=new Map;let a=0;for(;r;){const e=r.props?.key||r.type+"-"+a++;s.set(e,r),r=r.sibling}for(n=0;n<t.length;){let r=t[n];if(r.isFragment){const e=r.props.children||[];if(Array.isArray(e)){e.length>1&&!r.props?.key&&console.warn(`⚠️ Warning: Fragment at index ${n} is missing a key and has multiple children. Esto puede causar errores en reconciliación.`),t.splice(n,1,...e);continue}r=e}const a=r.props?.key??n,c=s.get(a);let u;if(c&&r&&r.type===c.type){const t=k(c.props,r.props);u={type:c.type,props:r.props,dom:c.dom,parent:e,alternate:c,effectTag:t?l.UPDATE:l.NO_EFFECT},s.delete(a)}else r&&(u={type:r.type,props:r.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT},c&&(c.effectTag=l.DELETION,o.deletions.push(c),s.delete(a)));u&&(0===n?e.child=u:i&&(i.sibling=u),i=u),n++}s.forEach((e=>{e.effectTag=l.DELETION,o.deletions.push(e)}))},x=e=>{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)},F=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),o.wipRoot&&o.wipRoot.child&&(b(o.wipRoot.child),o.currentRoot=o.wipRoot),o.effects.forEach((e=>{try{e()}catch(e){console.error("Error in effect:",e)}})),o.effects=[],o.wipRoot=null),requestIdleCallback(F)},N=e=>{if(e.type instanceof Function?(e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];const t=e.type(e.props);let n=Array.isArray(t)?t:[t];R(e,n)})(e):x(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}},T=e=>{o.nextUnitOfWork=e,o.wipRoot=e,o.deletions=[],o.hookIndex=0,o.effects=[],requestIdleCallback(F)},I=(e,t)=>(o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],T(o.wipRoot),o.wipRoot),S=e=>{const t=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],n={state:t?t.state:e,queue:[]};(t?t.queue:[]).forEach((e=>{n.state=typeof e===i.function?e(n.state):e}));return o.wipFiber.hooks.push(n),o.hookIndex++,[n.state,e=>{n.queue.push(e),o.wipRoot={dom:o.currentRoot.dom,props:o.currentRoot.props,alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],T(o.wipRoot)}]},O=(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},_=(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)=>_((()=>e),t),v=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},C=e=>{const[t,o]=S(window.location.pathname),n=(e,t)=>{const o=t.split("?")[0],r=e.find((e=>e.NotFound)),i=r?{route:{component:r.NotFound},params:{}}:{route:{component:null},params:{}};for(const r of e){if(r.subRoutes){const e=n(r.subRoutes,t);if(e)return e}if("*"===r.path)return i;if(!r.path||"string"!=typeof r.path){console.warn("Invalid route detected:",r),console.info("if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }");continue}const e=[],s=new RegExp(`^${r.path.replace(/:\w+/g,(t=>(e.push(t.substring(1)),"([^/]+)")))}$`),l=o.match(s);if(l){return{route:r,params:e.reduce(((e,t,o)=>(e[t]=l[o+1],e)),{})}}}return i},r=e=>{window.history.pushState({},"",e),s(e)},s=e=>{const t=e.split("?")[0];o(t)};O((()=>{const e=()=>s(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=v(),{route:t}=l;return t&&t.component&&typeof t.component===i.function?c(a,null,c(t.component,{params:l.params||{},query:e})):(console.error("Component not found for current path or the component is not a valid function:",l),null)},NavLink:({to:e,...t})=>c("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}};var j={createElement:c,render:I,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return I(e,o.containerRoot)},Fragment:a,Hooks:Object.freeze({__proto__:null,useCallback:L,useEffect:O,useMemo:_,useQuery:v,useRef:U,useRouter:C,useStore:S})};window.Ryunix=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 c("img",{src:o,props:t},null)},e.default=j,e.useCallback=L,e.useEffect=O,e.useMemo=_,e.useQuery=v,e.useRef=U,e.useRouter=C,e.useStore=S,Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "1.1.7-canary.4",
3
+ "version": "1.1.7-canary.40",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.min.js",
6
6
  "types": "./dist/Ryunix.d.ts",