@unsetsoft/ryunixjs 1.1.7-canary.3 → 1.1.7-canary.30

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,10 +48,25 @@
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
- const Fragment = (props) => {
53
- return props.children
54
+ const generateHash = (prefix) => {
55
+ return `${prefix}-${Math.random().toString(36).substring(2, 9)}`
56
+ };
57
+
58
+ const Fragment = (props) => RYUNIX_TYPES.RYUNIX_FRAGMENT;
59
+
60
+ const childArray = (children, out) => {
61
+ out = out || [];
62
+ if (children == undefined || typeof children == STRINGS.boolean) ; else if (Array.isArray(children)) {
63
+ children.some((child) => {
64
+ childArray(child, out);
65
+ });
66
+ } else {
67
+ out.push(children);
68
+ }
69
+ return out
54
70
  };
55
71
 
56
72
  /**
@@ -71,15 +87,20 @@
71
87
  */
72
88
 
73
89
  const createElement = (type, props, ...children) => {
90
+ children = childArray(children, []);
91
+ const key =
92
+ props && props.key
93
+ ? generateHash(props.key)
94
+ : generateHash(RYUNIX_TYPES.Ryunix_ELEMENT.toString());
95
+
74
96
  return {
75
97
  type,
76
98
  props: {
77
99
  ...props,
78
- children: children
79
- .flat()
80
- .map((child) =>
81
- typeof child === STRINGS.object ? child : createTextElement(child),
82
- ),
100
+ key,
101
+ children: children.map((child) =>
102
+ typeof child === STRINGS.object ? child : createTextElement(child),
103
+ ),
83
104
  },
84
105
  }
85
106
  };
@@ -237,9 +258,10 @@
237
258
  */
238
259
  const commitRoot = () => {
239
260
  vars.deletions.forEach(commitWork);
240
- commitWork(vars.wipRoot.child);
241
- vars.currentRoot = vars.wipRoot;
242
- vars.wipRoot = null;
261
+ if (vars.wipRoot && vars.wipRoot.child) {
262
+ commitWork(vars.wipRoot.child);
263
+ vars.currentRoot = vars.wipRoot;
264
+ }
243
265
  vars.effects.forEach((effect) => {
244
266
  try {
245
267
  effect();
@@ -247,8 +269,8 @@
247
269
  console.error('Error in effect:', err);
248
270
  }
249
271
  });
250
-
251
272
  vars.effects = [];
273
+ vars.wipRoot = null;
252
274
  };
253
275
 
254
276
  /**
@@ -300,28 +322,62 @@
300
322
  }
301
323
  };
302
324
 
325
+ /**
326
+ * This function reconciles the children of a fiber node with a new set of elements, creating new
327
+ * fibers for new elements, updating existing fibers for elements with the same type, and marking old
328
+ * fibers for deletion if they are not present in the new set of elements.
329
+ * @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
330
+ * DOM tree.
331
+ * @param elements - an array of elements representing the new children to be rendered in the current
332
+ * fiber's subtree
333
+ */
334
+ const shouldComponentUpdate = (oldProps, newProps) => {
335
+ // Comparar las propiedades antiguas y nuevas
336
+ return (
337
+ !oldProps ||
338
+ !newProps ||
339
+ Object.keys(oldProps).length !== Object.keys(newProps).length ||
340
+ Object.keys(newProps).some((key) => oldProps[key] !== newProps[key])
341
+ )
342
+ };
343
+
344
+ const recycleFiber = (oldFiber, newProps) => {
345
+ return {
346
+ ...oldFiber,
347
+ props: newProps,
348
+ alternate: oldFiber,
349
+ effectTag: EFFECT_TAGS.UPDATE,
350
+ }
351
+ };
352
+
303
353
  const reconcileChildren = (wipFiber, elements) => {
304
354
  let index = 0;
305
355
  let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
306
- let prevSibling;
356
+ let prevSibling = null;
307
357
 
308
- while (index < elements.length || oldFiber != null) {
358
+ const oldFibersMap = new Map();
359
+ while (oldFiber) {
360
+ const oldKey = oldFiber.props.key || oldFiber.type;
361
+ oldFibersMap.set(oldKey, oldFiber);
362
+ oldFiber = oldFiber.sibling;
363
+ }
364
+
365
+ while (index < elements.length) {
309
366
  const element = elements[index];
310
- let newFiber;
367
+ const key = element.props.key || element.type;
368
+ const oldFiber = oldFibersMap.get(key);
311
369
 
312
- const sameType = oldFiber && element && element.type == oldFiber.type;
370
+ let newFiber;
371
+ const sameType = oldFiber && element && element.type === oldFiber.type;
313
372
 
314
- if (sameType) {
315
- newFiber = {
316
- type: oldFiber.type,
317
- props: element.props,
318
- dom: oldFiber.dom,
319
- parent: wipFiber,
320
- alternate: oldFiber,
321
- effectTag: EFFECT_TAGS.UPDATE,
322
- };
373
+ if (sameType && !shouldComponentUpdate(oldFiber.props, element.props)) {
374
+ // Reutilizar fibra existente si no hay cambios
375
+ newFiber = recycleFiber(oldFiber, element.props);
376
+ oldFibersMap.delete(key);
323
377
  }
378
+
324
379
  if (element && !sameType) {
380
+ // Crear nueva fibra
325
381
  newFiber = {
326
382
  type: element.type,
327
383
  props: element.props,
@@ -331,24 +387,28 @@
331
387
  effectTag: EFFECT_TAGS.PLACEMENT,
332
388
  };
333
389
  }
390
+
334
391
  if (oldFiber && !sameType) {
335
392
  oldFiber.effectTag = EFFECT_TAGS.DELETION;
336
- vars.deletions.push(oldFiber);
337
- }
338
-
339
- if (oldFiber) {
340
- oldFiber = oldFiber.sibling;
393
+ wipFiber.effects = wipFiber.effects || [];
394
+ wipFiber.effects.push(oldFiber);
341
395
  }
342
396
 
343
397
  if (index === 0) {
344
398
  wipFiber.child = newFiber;
345
- } else if (element) {
399
+ } else if (prevSibling) {
346
400
  prevSibling.sibling = newFiber;
347
401
  }
348
402
 
349
403
  prevSibling = newFiber;
404
+
350
405
  index++;
351
406
  }
407
+
408
+ oldFibersMap.forEach((oldFiber) => {
409
+ oldFiber.effectTag = EFFECT_TAGS.DELETION;
410
+ vars.deletions.push(oldFiber);
411
+ });
352
412
  };
353
413
 
354
414
  /**
@@ -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")}),s=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),i=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===s.object?e:c(e)))}}),c=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),u=e=>e.startsWith("on"),p=e=>e!==s.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===s.style)w(e,o["ryunix-style"]);else if(n===i.style)w(e,o.style);else if(n===s.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===i.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,s=e.alternate&&e.alternate.child;for(;r<t.length||null!=s;){const i=t[r];let a;const c=s&&i&&i.type==s.type;c&&(a={type:s.type,props:i.props,dom:s.dom,parent:e,alternate:s,effectTag:l.UPDATE}),i&&!c&&(a={type:i.type,props:i.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT}),s&&!c&&(s.effectTag=l.DELETION,o.deletions.push(s)),s&&(s=s.sibling),0===r?e.child=a:i&&(n.sibling=a),n=a,r++}},x=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)},R=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),E(o.wipRoot.child),o.currentRoot=o.wipRoot,o.wipRoot=null,o.effects.forEach((e=>{try{e()}catch(e){console.error("Error in effect:",e)}})),o.effects=[]),requestIdleCallback(R)},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):x(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(R),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===s.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 s=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],i={type:r.RYUNIX_EFFECT,deps:n,cleanup:s?.cleanup};(!s||!t.isEqual(s.deps,n))&&o.effects.push((()=>{"function"==typeof i.cleanup&&i.cleanup();const t=e();"function"==typeof t&&(i.cleanup=t)})),o.wipFiber.hooks[o.hookIndex]=i,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 s=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],i={type:r.RYUNIX_MEMO,value:null,deps:n};return s&&t.isEqual(s.deps,i.deps)?i.value=s.value:i.value=e(),o.wipFiber.hooks[o.hookIndex]=i,o.hookIndex++,i.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)),s=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 s;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=[],i=new RegExp(`^${r.path.replace(/:\w+/g,(t=>(e.push(t.substring(1)),"([^/]+)")))}$`),l=o.match(i);if(l){return{route:r,params:e.reduce(((e,t,o)=>(e[t]=l[o+1],e)),{})}}}return s},r=e=>{window.history.pushState({},"",e),i(e)},i=e=>{const t=e.split("?")[0];o(t)};I((()=>{const e=()=>i(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===s.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}`:"",s="http://localhost:3000"===window.location.origin||"http://localhost:5173"===window.location.origin||"http://localhost:4173"===window.location.origin;return n?s?(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()}),s=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),i=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=>`${e}-${Math.random().toString(36).substring(2,9)}`,c=(e,t)=>(t=t||[],null==e||typeof e==s.boolean||(Array.isArray(e)?e.some((e=>{c(e,t)})):t.push(e)),t),u=(e,t,...o)=>{o=c(o,[]);const n=t&&t.key?a(t.key):a(r.Ryunix_ELEMENT.toString());return{type:e,props:{...t,key:n,children:o.map((e=>typeof e===s.object?e:p(e)))}}},p=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),f=e=>e.startsWith("on"),d=e=>e!==s.children&&!f(e),h=(e,t)=>o=>e[o]!==t[o],y=e=>t=>!(t in e),m=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},E=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},w=(e,t,o)=>{Object.keys(t).filter(f).filter((e=>y(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(y(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(d).filter(h(t,o)).forEach((n=>{if(n===s.style)b(e,o["ryunix-style"]);else if(n===i.style)b(e,o.style);else if(n===s.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===i.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(f).filter(h(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])}))},b=(e,t)=>{e.style=Object.keys(t).reduce(((e,o)=>e+=`${o.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${t[o]};`),"")},g=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),E(e);else if(e.effectTag===l.UPDATE&&null!=e.dom)m(e),w(e.dom,e.alternate.props,e.props),E(e);else if(e.effectTag===l.DELETION)return k(e,o),void m(e);g(e.child),g(e.sibling)},k=(e,t)=>{e.dom?t.removeChild(e.dom):k(e.child,t)},R=(e,t)=>!e||!t||Object.keys(e).length!==Object.keys(t).length||Object.keys(t).some((o=>e[o]!==t[o])),x=(e,t)=>({...e,props:t,alternate:e,effectTag:l.UPDATE}),N=(e,t)=>{let n=0,r=e.alternate&&e.alternate.child,s=null;const i=new Map;for(;r;){const e=r.props.key||r.type;i.set(e,r),r=r.sibling}for(;n<t.length;){const o=t[n],r=o.props.key||o.type,a=i.get(r);let c;const u=a&&o&&o.type===a.type;u&&!R(a.props,o.props)&&(c=x(a,o.props),i.delete(r)),o&&!u&&(c={type:o.type,props:o.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT}),a&&!u&&(a.effectTag=l.DELETION,e.effects=e.effects||[],e.effects.push(a)),0===n?e.child=c:s&&(s.sibling=c),s=c,n++}i.forEach((e=>{e.effectTag=l.DELETION,o.deletions.push(e)}))},F=e=>{e.dom||(e.dom=(e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return w(t,{},e.props),t})(e)),N(e,e.props.children)},T=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=I(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&(o.deletions.forEach(g),o.wipRoot&&o.wipRoot.child&&(g(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(T)},I=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];N(e,n)})(e):F(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}},S=(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(T),o.wipRoot},O=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===s.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=[]}]},U=(e,n)=>{const s=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],i={type:r.RYUNIX_EFFECT,deps:n,cleanup:s?.cleanup};(!s||!t.isEqual(s.deps,n))&&o.effects.push((()=>{"function"==typeof i.cleanup&&i.cleanup();const t=e();"function"==typeof t&&(i.cleanup=t)})),o.wipFiber.hooks[o.hookIndex]=i,o.hookIndex++},_=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},L=(e,n)=>{const s=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],i={type:r.RYUNIX_MEMO,value:null,deps:n};return s&&t.isEqual(s.deps,i.deps)?i.value=s.value:i.value=e(),o.wipFiber.hooks[o.hookIndex]=i,o.hookIndex++,i.value},v=(e,t)=>L((()=>e),t),C=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},M=e=>{const[t,o]=O(window.location.pathname),n=(e,t)=>{const o=t.split("?")[0],r=e.find((e=>e.NotFound)),s=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 s;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=[],i=new RegExp(`^${r.path.replace(/:\w+/g,(t=>(e.push(t.substring(1)),"([^/]+)")))}$`),l=o.match(i);if(l){return{route:r,params:e.reduce(((e,t,o)=>(e[t]=l[o+1],e)),{})}}}return s},r=e=>{window.history.pushState({},"",e),i(e)},i=e=>{const t=e.split("?")[0];o(t)};U((()=>{const e=()=>i(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=C(),{route:t}=l;return t&&t.component&&typeof t.component===s.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})=>u("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}};var j={createElement:u,render:S,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return S(e,o.containerRoot)},Fragment:e=>r.RYUNIX_FRAGMENT,Hooks:Object.freeze({__proto__:null,useCallback:v,useEffect:U,useMemo:L,useQuery:C,useRef:_,useRouter:M,useStore:O})};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}`:"",s="http://localhost:3000"===window.location.origin||"http://localhost:5173"===window.location.origin||"http://localhost:4173"===window.location.origin;return n?s?(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 u("img",{src:o,props:t},null)},e.default=j,e.useCallback=v,e.useEffect=U,e.useMemo=L,e.useQuery=C,e.useRef=_,e.useRouter=M,e.useStore=O,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.3",
3
+ "version": "1.1.7-canary.30",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.min.js",
6
6
  "types": "./dist/Ryunix.d.ts",