@unsetsoft/ryunixjs 1.1.7-canary.2 → 1.1.7-canary.20

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
@@ -44,11 +44,15 @@
44
44
  });
45
45
 
46
46
  const EFFECT_TAGS = Object.freeze({
47
- PLACEMENT: Symbol('ryunix.reconciler.status.placement').toString(),
48
- UPDATE: Symbol('ryunix.reconciler.status.update').toString(),
49
- DELETION: Symbol('ryunix.reconciler.status.deletion').toString(),
47
+ PLACEMENT: Symbol('ryunix.reconciler.status.placement'),
48
+ UPDATE: Symbol('ryunix.reconciler.status.update'),
49
+ DELETION: Symbol('ryunix.reconciler.status.deletion'),
50
50
  });
51
51
 
52
+ const generateHash = (prefix) => {
53
+ return `${prefix}-${Math.random().toString(36).substring(2, 9)}`
54
+ };
55
+
52
56
  const Fragment = (props) => {
53
57
  return props.children
54
58
  };
@@ -71,10 +75,16 @@
71
75
  */
72
76
 
73
77
  const createElement = (type, props, ...children) => {
78
+ const key =
79
+ props && props.key
80
+ ? generateHash(props.key)
81
+ : generateHash(RYUNIX_TYPES.Ryunix_ELEMENT.toString());
82
+
74
83
  return {
75
84
  type,
76
85
  props: {
77
86
  ...props,
87
+ key,
78
88
  children: children
79
89
  .flat()
80
90
  .map((child) =>
@@ -237,9 +247,10 @@
237
247
  */
238
248
  const commitRoot = () => {
239
249
  vars.deletions.forEach(commitWork);
240
- commitWork(vars.wipRoot.child);
241
- vars.currentRoot = vars.wipRoot;
242
- vars.wipRoot = null;
250
+ if (vars.wipRoot && vars.wipRoot.child) {
251
+ commitWork(vars.wipRoot.child);
252
+ vars.currentRoot = vars.wipRoot;
253
+ }
243
254
  vars.effects.forEach((effect) => {
244
255
  try {
245
256
  effect();
@@ -247,8 +258,8 @@
247
258
  console.error('Error in effect:', err);
248
259
  }
249
260
  });
250
-
251
261
  vars.effects = [];
262
+ vars.wipRoot = null;
252
263
  };
253
264
 
254
265
  /**
@@ -267,12 +278,10 @@
267
278
  }
268
279
  const domParent = domParentFiber.dom;
269
280
 
270
- if (fiber.effectTag === EFFECT_TAGS.PLACEMENT) {
271
- if (fiber.dom != null) {
272
- domParent.appendChild(fiber.dom);
273
- }
281
+ if (fiber.effectTag === EFFECT_TAGS.PLACEMENT && fiber.dom != null) {
282
+ domParent.appendChild(fiber.dom);
274
283
  runEffects(fiber);
275
- } else if (fiber.effectTag === EFFECT_TAGS.UPDATE) {
284
+ } else if (fiber.effectTag === EFFECT_TAGS.UPDATE && fiber.dom != null) {
276
285
  cancelEffects(fiber);
277
286
  updateDom(fiber.dom, fiber.alternate.props, fiber.props);
278
287
  runEffects(fiber);
@@ -302,28 +311,64 @@
302
311
  }
303
312
  };
304
313
 
314
+ /**
315
+ * This function reconciles the children of a fiber node with a new set of elements, creating new
316
+ * fibers for new elements, updating existing fibers for elements with the same type, and marking old
317
+ * fibers for deletion if they are not present in the new set of elements.
318
+ * @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
319
+ * DOM tree.
320
+ * @param elements - an array of elements representing the new children to be rendered in the current
321
+ * fiber's subtree
322
+ */
323
+ const shouldComponentUpdate = (oldProps, newProps) => {
324
+ // Comparar las propiedades antiguas y nuevas
325
+ return (
326
+ !oldProps ||
327
+ !newProps ||
328
+ Object.keys(oldProps).length !== Object.keys(newProps).length ||
329
+ Object.keys(newProps).some((key) => oldProps[key] !== newProps[key])
330
+ )
331
+ };
332
+
305
333
  const reconcileChildren = (wipFiber, elements) => {
306
334
  let index = 0;
307
335
  let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
308
- let prevSibling;
336
+ let prevSibling = null;
309
337
 
310
- while (index < elements.length || oldFiber != null) {
338
+ const oldFibersMap = new Map();
339
+ while (oldFiber) {
340
+ const key = oldFiber.props?.key || oldFiber.type + '-' + index;
341
+ oldFibersMap.set(key, oldFiber);
342
+ oldFiber = oldFiber.sibling;
343
+ }
344
+
345
+ while (index < elements.length) {
311
346
  const element = elements[index];
347
+ const key = element.props?.key || element.type + '-' + index;
348
+ const matchedOldFiber = oldFibersMap.get(key);
349
+
312
350
  let newFiber;
313
351
 
314
- const sameType = oldFiber && element && element.type == oldFiber.type;
352
+ const sameType =
353
+ matchedOldFiber && element && element.type === matchedOldFiber.type;
315
354
 
316
355
  if (sameType) {
356
+ const shouldUpdate = shouldComponentUpdate(
357
+ matchedOldFiber.props,
358
+ element.props,
359
+ );
360
+
317
361
  newFiber = {
318
- type: oldFiber.type,
362
+ type: matchedOldFiber.type,
319
363
  props: element.props,
320
- dom: oldFiber.dom,
364
+ dom: matchedOldFiber.dom,
321
365
  parent: wipFiber,
322
- alternate: oldFiber,
323
- effectTag: EFFECT_TAGS.UPDATE,
366
+ alternate: matchedOldFiber,
367
+ effectTag: shouldUpdate ? EFFECT_TAGS.UPDATE : EFFECT_TAGS.NO_EFFECT, // NO_EFFECT: puedes definirlo si deseas
324
368
  };
325
- }
326
- if (element && !sameType) {
369
+
370
+ oldFibersMap.delete(key);
371
+ } else if (element) {
327
372
  newFiber = {
328
373
  type: element.type,
329
374
  props: element.props,
@@ -332,25 +377,32 @@
332
377
  alternate: null,
333
378
  effectTag: EFFECT_TAGS.PLACEMENT,
334
379
  };
335
- }
336
- if (oldFiber && !sameType) {
337
- oldFiber.effectTag = EFFECT_TAGS.DELETION;
338
- vars.deletions.push(oldFiber);
339
- }
340
380
 
341
- if (oldFiber) {
342
- oldFiber = oldFiber.sibling;
381
+ if (matchedOldFiber) {
382
+ matchedOldFiber.effectTag = EFFECT_TAGS.DELETION;
383
+ vars.deletions.push(matchedOldFiber);
384
+ oldFibersMap.delete(key);
385
+ }
343
386
  }
344
387
 
345
- if (index === 0) {
346
- wipFiber.child = newFiber;
347
- } else if (element) {
348
- prevSibling.sibling = newFiber;
388
+ if (newFiber) {
389
+ if (index === 0) {
390
+ wipFiber.child = newFiber;
391
+ } else if (prevSibling) {
392
+ prevSibling.sibling = newFiber;
393
+ }
394
+
395
+ prevSibling = newFiber;
349
396
  }
350
397
 
351
- prevSibling = newFiber;
352
398
  index++;
353
399
  }
400
+
401
+ // Delete any remaining old fibers
402
+ oldFibersMap.forEach((remainingFiber) => {
403
+ remainingFiber.effectTag = EFFECT_TAGS.DELETION;
404
+ vars.deletions.push(remainingFiber);
405
+ });
354
406
  };
355
407
 
356
408
  /**
@@ -365,8 +417,10 @@
365
417
  vars.hookIndex = 0;
366
418
  vars.wipFiber.hooks = [];
367
419
 
368
- const children = [fiber.type(fiber.props)];
369
- reconcileChildren(fiber, children);
420
+ const children = fiber.type(fiber.props);
421
+ let childArr = Array.isArray(children) ? children : [children];
422
+
423
+ reconcileChildren(fiber, childArr);
370
424
  };
371
425
 
372
426
  /**
@@ -379,7 +433,7 @@
379
433
  if (!fiber.dom) {
380
434
  fiber.dom = createDom(fiber);
381
435
  }
382
- reconcileChildren(fiber, fiber.props.children.flat());
436
+ reconcileChildren(fiber, fiber.props.children);
383
437
  };
384
438
 
385
439
  /* Internal components*/
@@ -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)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.flat())},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)];k(e,t)})(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"),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"),UPDATE:Symbol("ryunix.reconciler.status.update"),DELETION:Symbol("ryunix.reconciler.status.deletion")}),a=e=>`${e}-${Math.random().toString(36).substring(2,9)}`,c=(e,t,...o)=>{const n=t&&t.key?a(t.key):a(r.Ryunix_ELEMENT.toString());return{type:e,props:{...t,key:n,children:o.flat().map((e=>typeof e===s.object?e:u(e)))}}},u=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),p=e=>e.startsWith("on"),f=e=>e!==s.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===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(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 k(e,o),void y(e);b(e.child),b(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)=>{let n=0,r=e.alternate&&e.alternate.child,s=null;const i=new Map;for(;r;){const e=r.props?.key||r.type+"-"+n;i.set(e,r),r=r.sibling}for(;n<t.length;){const r=t[n],a=r.props?.key||r.type+"-"+n,c=i.get(a);let u;if(c&&r&&r.type===c.type){const t=R(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},i.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),i.delete(a)));u&&(0===n?e.child=u:s&&(s.sibling=u),s=u),n++}i.forEach((e=>{e.effectTag=l.DELETION,o.deletions.push(e)}))},g=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)),x(e,e.props.children)},N=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=F(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(N)},F=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];x(e,n)})(e):g(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}},T=(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(N),o.wipRoot},I=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=[]}]},O=(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++},L=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),_=()=>{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]=I(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)};O((()=>{const e=()=>i(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=_(),{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})=>c("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}};var S={createElement:c,render:T,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return T(e,o.containerRoot)},Fragment:e=>e.children,Hooks:Object.freeze({__proto__:null,useCallback:v,useEffect:O,useMemo:U,useQuery:_,useRef:L,useRouter:C,useStore:I})};window.Ryunix=S,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 c("img",{src:o,props:t},null)},e.default=S,e.useCallback=v,e.useEffect=O,e.useMemo=U,e.useQuery=_,e.useRef=L,e.useRouter=C,e.useStore=I,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.2",
3
+ "version": "1.1.7-canary.20",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.min.js",
6
6
  "types": "./dist/Ryunix.d.ts",