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

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,29 @@
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
+
62
+ const childArray = (children, out) => {
63
+ out = out || [];
64
+ if (children == undefined || typeof children == STRINGS.boolean) ; else if (Array.isArray(children)) {
65
+ children.some((child) => {
66
+ childArray(child, out);
67
+ });
68
+ } else {
69
+ out.push(children);
70
+ }
71
+ return out
72
+ };
73
+
56
74
  /**
57
75
  * The function creates a new element with the given type, props, and children.
58
76
  * @param type - The type of the element to be created, such as "div", "span", "h1", etc.
@@ -71,15 +89,20 @@
71
89
  */
72
90
 
73
91
  const createElement = (type, props, ...children) => {
92
+ children = childArray(children, []);
93
+ const key = props && props.key ? props.key : null;
94
+
95
+ const isFragment = type.isFragment || false;
96
+
74
97
  return {
75
98
  type,
99
+ isFragment,
76
100
  props: {
77
101
  ...props,
78
- children: children
79
- .flat()
80
- .map((child) =>
81
- typeof child === STRINGS.object ? child : createTextElement(child),
82
- ),
102
+ key,
103
+ children: children.map((child) =>
104
+ typeof child === STRINGS.object ? child : createTextElement(child),
105
+ ),
83
106
  },
84
107
  }
85
108
  };
@@ -301,28 +324,88 @@
301
324
  }
302
325
  };
303
326
 
327
+ /**
328
+ * This function reconciles the children of a fiber node with a new set of elements, creating new
329
+ * fibers for new elements, updating existing fibers for elements with the same type, and marking old
330
+ * fibers for deletion if they are not present in the new set of elements.
331
+ * @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
332
+ * DOM tree.
333
+ * @param elements - an array of elements representing the new children to be rendered in the current
334
+ * fiber's subtree
335
+ */
336
+ const shouldComponentUpdate = (oldProps, newProps) => {
337
+ // Comparar las propiedades antiguas y nuevas
338
+ return (
339
+ !oldProps ||
340
+ !newProps ||
341
+ Object.keys(oldProps).length !== Object.keys(newProps).length ||
342
+ Object.keys(newProps).some((key) => oldProps[key] !== newProps[key])
343
+ )
344
+ };
345
+
304
346
  const reconcileChildren = (wipFiber, elements) => {
305
347
  let index = 0;
306
348
  let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
307
- let prevSibling;
349
+ let prevSibling = null;
308
350
 
309
- while (index < elements.length || oldFiber != null) {
310
- const element = elements[index];
311
- let newFiber;
351
+ const isDynamicList = elements.some((el) => el?.props?.key !== undefined);
352
+
353
+ const oldFibersMap = new Map();
354
+ let keyIndex = 0;
355
+
356
+ if (isDynamicList) {
357
+ while (oldFiber) {
358
+ const key = oldFiber.props?.key || `__index__${keyIndex++}`;
359
+ oldFibersMap.set(key, oldFiber);
360
+ oldFiber = oldFiber.sibling;
361
+ }
362
+ }
312
363
 
313
- const sameType = oldFiber && element && element.type == oldFiber.type;
364
+ index = 0;
365
+ while (index < elements.length) {
366
+ let element = elements[index];
367
+
368
+ if (element.isFragment) {
369
+ const fragmentChildren = element.props.children || [];
370
+
371
+ if (Array.isArray(fragmentChildren)) {
372
+ if (fragmentChildren.length > 1 && !element.props?.key) {
373
+ console.warn(
374
+ `⚠️ Fragment at index ${index} is missing a key and has multiple children.`,
375
+ );
376
+ }
377
+
378
+ elements.splice(index, 1, ...fragmentChildren);
379
+ continue
380
+ } else {
381
+ element = fragmentChildren;
382
+ }
383
+ }
384
+
385
+ const key = element?.props?.key ?? `__index__${index}`;
386
+ const matchedOldFiber = isDynamicList ? oldFibersMap.get(key) : oldFiber;
387
+
388
+ let newFiber;
389
+ const sameType =
390
+ matchedOldFiber && element && element.type === matchedOldFiber.type;
314
391
 
315
392
  if (sameType) {
393
+ const shouldUpdate = shouldComponentUpdate(
394
+ matchedOldFiber.props,
395
+ element.props,
396
+ );
397
+
316
398
  newFiber = {
317
- type: oldFiber.type,
399
+ type: matchedOldFiber.type,
318
400
  props: element.props,
319
- dom: oldFiber.dom,
401
+ dom: matchedOldFiber.dom,
320
402
  parent: wipFiber,
321
- alternate: oldFiber,
322
- effectTag: EFFECT_TAGS.UPDATE,
403
+ alternate: matchedOldFiber,
404
+ effectTag: shouldUpdate ? EFFECT_TAGS.UPDATE : EFFECT_TAGS.NO_EFFECT,
323
405
  };
324
- }
325
- if (element && !sameType) {
406
+
407
+ if (isDynamicList) oldFibersMap.delete(key);
408
+ } else if (element) {
326
409
  newFiber = {
327
410
  type: element.type,
328
411
  props: element.props,
@@ -331,25 +414,35 @@
331
414
  alternate: null,
332
415
  effectTag: EFFECT_TAGS.PLACEMENT,
333
416
  };
334
- }
335
- if (oldFiber && !sameType) {
336
- oldFiber.effectTag = EFFECT_TAGS.DELETION;
337
- vars.deletions.push(oldFiber);
338
- }
339
417
 
340
- if (oldFiber) {
341
- oldFiber = oldFiber.sibling;
418
+ if (matchedOldFiber) {
419
+ matchedOldFiber.effectTag = EFFECT_TAGS.DELETION;
420
+ vars.deletions.push(matchedOldFiber);
421
+ if (isDynamicList) oldFibersMap.delete(key);
422
+ }
342
423
  }
343
424
 
344
- if (index === 0) {
345
- wipFiber.child = newFiber;
346
- } else if (element) {
347
- prevSibling.sibling = newFiber;
425
+ if (oldFiber && !isDynamicList) oldFiber = oldFiber.sibling;
426
+
427
+ if (newFiber) {
428
+ if (index === 0) {
429
+ wipFiber.child = newFiber;
430
+ } else if (prevSibling) {
431
+ prevSibling.sibling = newFiber;
432
+ }
433
+
434
+ prevSibling = newFiber;
348
435
  }
349
436
 
350
- prevSibling = newFiber;
351
437
  index++;
352
438
  }
439
+
440
+ if (isDynamicList) {
441
+ oldFibersMap.forEach((remainingFiber) => {
442
+ remainingFiber.effectTag = EFFECT_TAGS.DELETION;
443
+ vars.deletions.push(remainingFiber);
444
+ });
445
+ }
353
446
  };
354
447
 
355
448
  /**
@@ -584,6 +677,8 @@
584
677
  };
585
678
  vars.nextUnitOfWork = vars.wipRoot;
586
679
  vars.deletions = [];
680
+
681
+ scheduleWork(vars.wipRoot);
587
682
  };
588
683
 
589
684
  vars.wipFiber.hooks.push(hook);
@@ -838,10 +933,14 @@
838
933
  return null
839
934
  }
840
935
 
841
- return route.component({
842
- params: currentRouteData.params || {},
843
- query,
844
- })
936
+ return createElement(
937
+ Fragment,
938
+ null,
939
+ createElement(route.component, {
940
+ params: currentRouteData.params || {},
941
+ query,
942
+ }),
943
+ )
845
944
  };
846
945
 
847
946
  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)=>(t=t||[],null==e||typeof e==i.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?t.key:null;return{type:e,isFragment:e.isFragment||!1,props:{...t,key:n,children:o.map((e=>typeof e===i.object?e:p(e)))}}},p=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),f=e=>e.startsWith("on"),d=e=>e!==i.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===i.style)b(e,o["ryunix-style"]);else if(n===s.style)b(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(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)},x=(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=t.some((e=>void 0!==e?.props?.key)),a=new Map;let c=0;if(s)for(;r;){const e=r.props?.key||"__index__"+c++;a.set(e,r),r=r.sibling}for(n=0;n<t.length;){let c=t[n];if(c.isFragment){const e=c.props.children||[];if(Array.isArray(e)){e.length>1&&!c.props?.key&&console.warn(`⚠️ Fragment at index ${n} is missing a key and has multiple children.`),t.splice(n,1,...e);continue}c=e}const u=c?.props?.key??`__index__${n}`,p=s?a.get(u):r;let f;if(p&&c&&c.type===p.type){const t=x(p.props,c.props);f={type:p.type,props:c.props,dom:p.dom,parent:e,alternate:p,effectTag:t?l.UPDATE:l.NO_EFFECT},s&&a.delete(u)}else c&&(f={type:c.type,props:c.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT},p&&(p.effectTag=l.DELETION,o.deletions.push(p),s&&a.delete(u)));r&&!s&&(r=r.sibling),f&&(0===n?e.child=f:i&&(i.sibling=f),i=f),n++}s&&a.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)),R(e,e.props.children)},N=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=T(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(N)},T=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):F(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(N)},_=(e,t)=>(o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],I(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=[],I(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},v=(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)=>v((()=>e),t),C=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},j=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=C(),{route:t}=l;return t&&t.component&&typeof t.component===i.function?u(a,null,u(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 M={createElement:u,render:_,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return _(e,o.containerRoot)},Fragment:a,Hooks:Object.freeze({__proto__:null,useCallback:L,useEffect:O,useMemo:v,useQuery:C,useRef:U,useRouter:j,useStore:S})};window.Ryunix=M,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 u("img",{src:o,props:t},null)},e.default=M,e.useCallback=L,e.useEffect=O,e.useMemo=v,e.useQuery=C,e.useRef=U,e.useRouter=j,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.41",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.min.js",
6
6
  "types": "./dist/Ryunix.d.ts",