@unsetsoft/ryunixjs 1.1.7-canary.7 → 1.1.7-canary.71

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,16 @@
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(),
30
+ RYUNIX_CONTEXT: Symbol('ryunix.context').toString(),
29
31
  });
30
32
 
31
33
  const STRINGS = Object.freeze({
@@ -47,12 +49,9 @@
47
49
  PLACEMENT: Symbol('ryunix.reconciler.status.placement').toString(),
48
50
  UPDATE: Symbol('ryunix.reconciler.status.update').toString(),
49
51
  DELETION: Symbol('ryunix.reconciler.status.deletion').toString(),
52
+ NO_EFFECT: Symbol('ryunix.reconciler.status.no_efect').toString(),
50
53
  });
51
54
 
52
- const Fragment = (props) => {
53
- return props.children
54
- };
55
-
56
55
  /**
57
56
  * The function creates a new element with the given type, props, and children.
58
57
  * @param type - The type of the element to be created, such as "div", "span", "h1", etc.
@@ -101,6 +100,9 @@
101
100
  }
102
101
  };
103
102
 
103
+ const Fragment = (props) =>
104
+ createElement(RYUNIX_TYPES.RYUNIX_FRAGMENT, {}, ...props.children);
105
+
104
106
  const isEvent = (key) => key.startsWith('on');
105
107
  const isProperty = (key) => key !== STRINGS.children && !isEvent(key);
106
108
  const isNew = (prev, next) => (key) => prev[key] !== next[key];
@@ -237,18 +239,8 @@
237
239
  */
238
240
  const commitRoot = () => {
239
241
  vars.deletions.forEach(commitWork);
240
- if (vars.wipRoot && vars.wipRoot.child) {
241
- commitWork(vars.wipRoot.child);
242
- vars.currentRoot = vars.wipRoot;
243
- }
244
- vars.effects.forEach((effect) => {
245
- try {
246
- effect();
247
- } catch (err) {
248
- console.error('Error in effect:', err);
249
- }
250
- });
251
- vars.effects = [];
242
+ commitWork(vars.wipRoot.child);
243
+ vars.currentRoot = vars.wipRoot;
252
244
  vars.wipRoot = null;
253
245
  };
254
246
 
@@ -260,7 +252,9 @@
260
252
  * @returns The function does not return anything, it performs side effects by manipulating the DOM.
261
253
  */
262
254
  const commitWork = (fiber) => {
263
- if (!fiber) return
255
+ if (!fiber) {
256
+ return
257
+ }
264
258
 
265
259
  let domParentFiber = fiber.parent;
266
260
  while (!domParentFiber.dom) {
@@ -268,20 +262,23 @@
268
262
  }
269
263
  const domParent = domParentFiber.dom;
270
264
 
271
- if (fiber.effectTag === EFFECT_TAGS.PLACEMENT && fiber.dom != null) {
272
- domParent.appendChild(fiber.dom);
265
+ if (fiber.effectTag === EFFECT_TAGS.PLACEMENT) {
266
+ if (fiber.dom != null) {
267
+ domParent.appendChild(fiber.dom);
268
+ }
273
269
  runEffects(fiber);
274
- } else if (fiber.effectTag === EFFECT_TAGS.UPDATE && fiber.dom != null) {
270
+ } else if (fiber.effectTag === EFFECT_TAGS.UPDATE) {
275
271
  cancelEffects(fiber);
276
- updateDom(fiber.dom, fiber.alternate.props, fiber.props);
272
+ if (fiber.dom != null) {
273
+ updateDom(fiber.dom, fiber.alternate.props, fiber.props);
274
+ }
277
275
  runEffects(fiber);
278
276
  } else if (fiber.effectTag === EFFECT_TAGS.DELETION) {
279
- commitDeletion(fiber, domParent);
280
277
  cancelEffects(fiber);
278
+ commitDeletion(fiber, domParent);
281
279
  return
282
280
  }
283
281
 
284
- // Recorre los "fibers" hijos y hermanos
285
282
  commitWork(fiber.child);
286
283
  commitWork(fiber.sibling);
287
284
  };
@@ -310,38 +307,18 @@
310
307
  * @param elements - an array of elements representing the new children to be rendered in the current
311
308
  * fiber's subtree
312
309
  */
313
- const shouldComponentUpdate = (oldProps, newProps) => {
314
- // Comparar las propiedades antiguas y nuevas
315
- return (
316
- !oldProps ||
317
- !newProps ||
318
- Object.keys(oldProps).length !== Object.keys(newProps).length ||
319
- Object.keys(newProps).some((key) => oldProps[key] !== newProps[key])
320
- )
321
- };
322
-
323
310
  const reconcileChildren = (wipFiber, elements) => {
324
311
  let index = 0;
325
312
  let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
326
- let prevSibling = null;
327
-
328
- const oldFibersMap = new Map();
329
-
330
- while (oldFiber) {
331
- const oldKey = oldFiber.props.key || oldFiber.type;
332
- oldFibersMap.set(oldKey, oldFiber);
333
- oldFiber = oldFiber.sibling;
334
- }
313
+ let prevSibling;
335
314
 
336
- while (index < elements.length) {
315
+ while (index < elements.length || oldFiber != null) {
337
316
  const element = elements[index];
338
- const key = element.props.key || element.type;
339
- const oldFiber = oldFibersMap.get(key);
340
317
  let newFiber;
341
318
 
342
319
  const sameType = oldFiber && element && element.type == oldFiber.type;
343
320
 
344
- if (sameType && !shouldComponentUpdate(oldFiber.props, element.props)) {
321
+ if (sameType) {
345
322
  newFiber = {
346
323
  type: oldFiber.type,
347
324
  props: element.props,
@@ -361,10 +338,8 @@
361
338
  effectTag: EFFECT_TAGS.PLACEMENT,
362
339
  };
363
340
  }
364
-
365
341
  if (oldFiber && !sameType) {
366
342
  oldFiber.effectTag = EFFECT_TAGS.DELETION;
367
- wipFiber.effects = wipFiber.effects || [];
368
343
  vars.deletions.push(oldFiber);
369
344
  }
370
345
 
@@ -381,11 +356,6 @@
381
356
  prevSibling = newFiber;
382
357
  index++;
383
358
  }
384
-
385
- oldFibersMap.forEach((oldFiber) => {
386
- oldFiber.effectTag = EFFECT_TAGS.DELETION;
387
- vars.deletions.push(oldFiber);
388
- });
389
359
  };
390
360
 
391
361
  /**
@@ -399,11 +369,15 @@
399
369
  vars.wipFiber = fiber;
400
370
  vars.hookIndex = 0;
401
371
  vars.wipFiber.hooks = [];
372
+ const children = [fiber.type(fiber.props)];
402
373
 
403
- const children = fiber.type(fiber.props);
404
- let childArr = Array.isArray(children) ? children : [children];
374
+ // Aquí detectamos si es Provider para guardar contexto y valor en fiber
375
+ if (fiber.type._contextId && fiber.props.value !== undefined) {
376
+ fiber._contextId = fiber.type._contextId;
377
+ fiber._contextValue = fiber.props.value;
378
+ }
405
379
 
406
- reconcileChildren(fiber, childArr);
380
+ reconcileChildren(fiber, children);
407
381
  };
408
382
 
409
383
  /**
@@ -413,10 +387,14 @@
413
387
  * fibers in the tree.
414
388
  */
415
389
  const updateHostComponent = (fiber) => {
416
- if (!fiber.dom) {
417
- fiber.dom = createDom(fiber);
390
+ if (fiber.type === RYUNIX_TYPES.RYUNIX_FRAGMENT) {
391
+ reconcileChildren(fiber, fiber.props.children.flat());
392
+ } else {
393
+ if (!fiber.dom) {
394
+ fiber.dom = createDom(fiber);
395
+ }
396
+ reconcileChildren(fiber, fiber.props.children.flat());
418
397
  }
419
- reconcileChildren(fiber, fiber.props.children);
420
398
  };
421
399
 
422
400
  /* Internal components*/
@@ -505,7 +483,7 @@
505
483
  requestIdleCallback(workLoop);
506
484
  };
507
485
 
508
- //requestIdleCallback(workLoop)
486
+ requestIdleCallback(workLoop);
509
487
 
510
488
  /**
511
489
  * The function performs a unit of work by updating either a function component or a host component and
@@ -517,7 +495,7 @@
517
495
  * @returns The function `performUnitOfWork` returns the next fiber to be processed. If the current
518
496
  * fiber has a child, it returns the child. Otherwise, it looks for the next sibling of the current
519
497
  * fiber. If there are no more siblings, it goes up the tree to the parent and looks for the next
520
- * sibling of the parent. The function returns `undefined` if there are no more fibers to process.
498
+ * sibling of the parent. The function returns `null` if there are no more fibers to process.
521
499
  */
522
500
  const performUnitOfWork = (fiber) => {
523
501
  const isFunctionComponent = fiber.type instanceof Function;
@@ -594,37 +572,51 @@
594
572
  * @returns The `useStore` function returns an array with two elements: the current state value and a
595
573
  * `setState` function that can be used to update the state.
596
574
  */
597
- const useStore = (initial) => {
575
+ const useStore = (initialState, init) => {
576
+ const reducer = (state, action) =>
577
+ typeof action === 'function' ? action(state) : action;
578
+
579
+ return useReducer(reducer, initialState, init)
580
+ };
581
+
582
+ const useReducer = (reducer, initialState, init) => {
598
583
  const oldHook =
599
584
  vars.wipFiber.alternate &&
600
585
  vars.wipFiber.alternate.hooks &&
601
586
  vars.wipFiber.alternate.hooks[vars.hookIndex];
602
587
 
603
588
  const hook = {
604
- state: oldHook ? oldHook.state : initial,
605
- queue: [],
589
+ state: oldHook ? oldHook.state : init ? init(initialState) : initialState,
590
+ queue: oldHook && Array.isArray(oldHook.queue) ? oldHook.queue.slice() : [],
606
591
  };
607
592
 
608
- const actions = oldHook ? oldHook.queue : [];
609
- actions.forEach((action) => {
610
- hook.state =
611
- typeof action === STRINGS.function ? action(hook.state) : action;
612
- });
593
+ if (oldHook && Array.isArray(oldHook.queue)) {
594
+ oldHook.queue.forEach((action) => {
595
+ hook.state = reducer(hook.state, action);
596
+ });
597
+ }
613
598
 
614
- const setState = (action) => {
599
+ const dispatch = (action) => {
615
600
  hook.queue.push(action);
601
+
616
602
  vars.wipRoot = {
617
603
  dom: vars.currentRoot.dom,
618
604
  props: vars.currentRoot.props,
619
605
  alternate: vars.currentRoot,
620
606
  };
621
- vars.nextUnitOfWork = vars.wipRoot;
622
607
  vars.deletions = [];
608
+ vars.hookIndex = 0;
609
+ scheduleWork(vars.wipRoot);
623
610
  };
624
611
 
625
- vars.wipFiber.hooks.push(hook);
612
+ hook.queue.forEach((action) => {
613
+ hook.state = reducer(hook.state, action);
614
+ });
615
+
616
+ vars.wipFiber.hooks[vars.hookIndex] = hook;
626
617
  vars.hookIndex++;
627
- return [hook.state, setState]
618
+
619
+ return [hook.state, dispatch]
628
620
  };
629
621
 
630
622
  /**
@@ -670,6 +662,15 @@
670
662
  vars.hookIndex++;
671
663
  };
672
664
 
665
+ /**
666
+ * The useRef function in JavaScript is used to create a reference object that persists between renders
667
+ * in a functional component.
668
+ * @param initial - The `initial` parameter in the `useRef` function represents the initial value that
669
+ * will be assigned to the `current` property of the reference object. This initial value will be used
670
+ * if there is no previous value stored in the hook.
671
+ * @returns The `useRef` function is returning the `current` property of the `hook.value` object. This
672
+ * property contains the current value of the reference being managed by the `useRef` hook.
673
+ */
673
674
  const useRef = (initial) => {
674
675
  const oldHook =
675
676
  vars.wipFiber.alternate &&
@@ -687,6 +688,19 @@
687
688
  return hook.value
688
689
  };
689
690
 
691
+ /**
692
+ * The useMemo function in JavaScript is used to memoize the result of a computation based on the
693
+ * dependencies provided.
694
+ * @param comp - The `comp` parameter in the `useMemo` function is a function that represents the
695
+ * computation that needs to be memoized. This function will be executed to calculate the memoized
696
+ * value based on the dependencies provided.
697
+ * @param deps - The `deps` parameter in the `useMemo` function stands for dependencies. It is an array
698
+ * of values that the function depends on. The `useMemo` function will only recompute the memoized
699
+ * value when one of the dependencies has changed.
700
+ * @returns The `useMemo` function returns the `value` property of the `hook` object, which is either
701
+ * the memoized value from the previous render if the dependencies have not changed, or the result of
702
+ * calling the `comp` function if the dependencies have changed.
703
+ */
690
704
  const useMemo = (comp, deps) => {
691
705
  const oldHook =
692
706
  vars.wipFiber.alternate &&
@@ -715,6 +729,16 @@
715
729
  return hook.value
716
730
  };
717
731
 
732
+ /**
733
+ * The useCallback function in JavaScript returns a memoized version of the callback function that only
734
+ * changes if one of the dependencies has changed.
735
+ * @param callback - The `callback` parameter is a function that you want to memoize using
736
+ * `useCallback`. This function will only be re-created if any of the dependencies specified in the
737
+ * `deps` array change.
738
+ * @param deps - Dependencies array that the callback function depends on.
739
+ * @returns The useCallback function is returning a memoized version of the callback function. It is
740
+ * using the useMemo hook to memoize the callback function based on the provided dependencies (deps).
741
+ */
718
742
  const useCallback = (callback, deps) => {
719
743
  return useMemo(() => callback, deps)
720
744
  };
@@ -733,6 +757,39 @@
733
757
  return query
734
758
  };
735
759
 
760
+ const createContext = (defaultValue) => {
761
+ const contextId = RYUNIX_TYPES.RYUNIX_CONTEXT;
762
+
763
+ const Provider = ({ value, children }) => {
764
+ // Solo devuelve children, Ryunix creará el fiber automáticamente con props
765
+ return Fragment({
766
+ children: children,
767
+ })
768
+ };
769
+
770
+ Provider._contextId = contextId;
771
+
772
+ const useContext = () => {
773
+ let fiber = vars.wipFiber;
774
+ while (fiber) {
775
+ if (fiber.type && fiber.type._contextId === contextId) {
776
+ // Protegemos el acceso a props.value
777
+ if (fiber.props && 'value' in fiber.props) {
778
+ return fiber.props.value
779
+ }
780
+ return undefined
781
+ }
782
+ fiber = fiber.parent;
783
+ }
784
+ return defaultValue
785
+ };
786
+
787
+ return {
788
+ Provider,
789
+ useContext,
790
+ }
791
+ };
792
+
736
793
  /**
737
794
  * `useRouter` is a routing function to manage navigation, nested routes, and route pre-loading.
738
795
  *
@@ -841,6 +898,7 @@
841
898
 
842
899
  const navigate = (path) => {
843
900
  window.history.pushState({}, '', path);
901
+
844
902
  updateRoute(path);
845
903
  };
846
904
 
@@ -874,7 +932,8 @@
874
932
  return null
875
933
  }
876
934
 
877
- return route.component({
935
+ return createElement(route.component, {
936
+ key: location,
878
937
  params: currentRouteData.params || {},
879
938
  query,
880
939
  })
@@ -897,6 +956,7 @@
897
956
 
898
957
  var Hooks = /*#__PURE__*/Object.freeze({
899
958
  __proto__: null,
959
+ createContext: createContext,
900
960
  useCallback: useCallback,
901
961
  useEffect: useEffect,
902
962
  useMemo: useMemo,
@@ -917,6 +977,7 @@
917
977
  window.Ryunix = Ryunix;
918
978
 
919
979
  exports.Image = Image;
980
+ exports.createContext = createContext;
920
981
  exports.default = Ryunix;
921
982
  exports.useCallback = useCallback;
922
983
  exports.useEffect = useEffect;
@@ -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()}))},y=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},m=(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),y(e);else if(e.effectTag===l.UPDATE&&null!=e.dom)h(e),m(e.dom,e.alternate.props,e.props),y(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)=>!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,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 r=t[n],a=r.props.key||r.type,c=i.get(a);let u;const p=c&&r&&r.type==c.type;p&&!k(c.props,r.props)&&(u={type:c.type,props:r.props,dom:c.dom,parent:e,alternate:c,effectTag:l.UPDATE}),r&&!p&&(u={type:r.type,props:r.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT}),c&&!p&&(c.effectTag=l.DELETION,e.effects=e.effects||[],o.deletions.push(c)),c&&(c=c.sibling),0===n?e.child=u:r&&(s.sibling=u),s=u,n++}i.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 m(t,{},e.props),t})(e)),R(e,e.props.children)},g=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=N(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(g)},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}},F=(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(g),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=[]}]},T=(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++},O=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},_=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)};T((()=>{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 S={createElement:a,render:F,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return F(e,o.containerRoot)},Fragment:e=>e.children,Hooks:Object.freeze({__proto__:null,useCallback:v,useEffect:T,useMemo:U,useQuery:L,useRef:O,useRouter:_,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 a("img",{src:o,props:t},null)},e.default=S,e.useCallback=v,e.useEffect=T,e.useMemo=U,e.useQuery=L,e.useRef=O,e.useRouter=_,e.useStore=I,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(),RYUNIX_CONTEXT:Symbol("ryunix.context").toString()}),i=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),s=Object.freeze({style:"style",className:"className"}),l=Object.freeze({PLACEMENT:Symbol("ryunix.reconciler.status.placement").toString(),UPDATE:Symbol("ryunix.reconciler.status.update").toString(),DELETION:Symbol("ryunix.reconciler.status.deletion").toString(),NO_EFFECT:Symbol("ryunix.reconciler.status.no_efect").toString()}),a=(e,t,...o)=>({type:e,props:{...t,children:o.flat().map((e=>typeof e===i.object?e:c(e)))}}),c=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),u=e=>a(r.RYUNIX_FRAGMENT,{},...e.children),p=e=>e.startsWith("on"),d=e=>e!==i.children&&!p(e),f=(e,t)=>o=>e[o]!==t[o],h=e=>t=>!(t in e),y=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},m=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},E=(e,t,o)=>{Object.keys(t).filter(p).filter((e=>h(o)(e)||f(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(d).filter(h(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(d).filter(f(t,o)).forEach((n=>{if(n===i.style)w(e,o["ryunix-style"]);else if(n===s.style)w(e,o.style);else if(n===i.className){if(""===o["ryunix-class"])throw new Error("data-class cannot be empty.");t["ryunix-class"]&&e.classList.remove(...t["ryunix-class"].split(/\s+/)),e.classList.add(...o["ryunix-class"].split(/\s+/))}else if(n===s.className){if(""===o.className)throw new Error("className cannot be empty.");t.className&&e.classList.remove(...t.className.split(/\s+/)),e.classList.add(...o.className.split(/\s+/))}else e[n]=o[n]})),Object.keys(o).filter(p).filter(f(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])}))},w=(e,t)=>{e.style=Object.keys(t).reduce(((e,o)=>e+=`${o.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${t[o]};`),"")},b=e=>{if(!e)return;let t=e.parent;for(;!t.dom;)t=t.parent;const o=t.dom;if(e.effectTag===l.PLACEMENT)null!=e.dom&&o.appendChild(e.dom),m(e);else if(e.effectTag===l.UPDATE)y(e),null!=e.dom&&E(e.dom,e.alternate.props,e.props),m(e);else if(e.effectTag===l.DELETION)return y(e),void x(e,o);b(e.child),b(e.sibling)},x=(e,t)=>{e.dom?t.removeChild(e.dom):x(e.child,t)},R=(e,t)=>{let n,r=0,i=e.alternate&&e.alternate.child;for(;r<t.length||null!=i;){const s=t[r];let a;const c=i&&s&&s.type==i.type;c&&(a={type:i.type,props:s.props,dom:i.dom,parent:e,alternate:i,effectTag:l.UPDATE}),s&&!c&&(a={type:s.type,props:s.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT}),i&&!c&&(i.effectTag=l.DELETION,o.deletions.push(i)),i&&(i=i.sibling),0===r?e.child=a:s&&(n.sibling=a),n=a,r++}},g=e=>{e.type===r.RYUNIX_FRAGMENT||e.dom||(e.dom=(e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return E(t,{},e.props),t})(e)),R(e,e.props.children.flat())},k=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=N(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&(o.deletions.forEach(b),b(o.wipRoot.child),o.currentRoot=o.wipRoot,o.wipRoot=null),requestIdleCallback(k)};requestIdleCallback(k);const N=e=>{if(e.type instanceof Function?(e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];const t=[e.type(e.props)];e.type._contextId&&void 0!==e.props.value&&(e._contextId=e.type._contextId,e._contextValue=e.props.value),R(e,t)})(e):g(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}},I=e=>{o.nextUnitOfWork=e,o.wipRoot=e,o.deletions=[],o.hookIndex=0,o.effects=[],requestIdleCallback(k)},F=(e,t)=>(o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],I(o.wipRoot),o.wipRoot),T=(e,t)=>_(((e,t)=>"function"==typeof t?t(e):t),e,t),_=(e,t,n)=>{const r=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],i={state:r?r.state:n?n(t):t,queue:r&&Array.isArray(r.queue)?r.queue.slice():[]};r&&Array.isArray(r.queue)&&r.queue.forEach((t=>{i.state=e(i.state,t)}));return i.queue.forEach((t=>{i.state=e(i.state,t)})),o.wipFiber.hooks[o.hookIndex]=i,o.hookIndex++,[i.state,e=>{i.queue.push(e),o.wipRoot={dom:o.currentRoot.dom,props:o.currentRoot.props,alternate:o.currentRoot},o.deletions=[],o.hookIndex=0,I(o.wipRoot)}]},S=(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++},v=e=>{const t=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],n={type:r.RYUNIX_REF,value:t?t.value:{current:e}};return o.wipFiber.hooks[o.hookIndex]=n,o.hookIndex++,n.value},U=(e,n)=>{const i=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],s={type:r.RYUNIX_MEMO,value:null,deps:n};return i&&t.isEqual(i.deps,s.deps)?s.value=i.value:s.value=e(),o.wipFiber.hooks[o.hookIndex]=s,o.hookIndex++,s.value},C=(e,t)=>U((()=>e),t),O=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},L=e=>{const t=r.RYUNIX_CONTEXT,n=({value:e,children:t})=>u({children:t});n._contextId=t;return{Provider:n,useContext:()=>{let n=o.wipFiber;for(;n;){if(n.type&&n.type._contextId===t)return n.props&&"value"in n.props?n.props.value:void 0;n=n.parent}return e}}},X=e=>{const[t,o]=T(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)};S((()=>{const e=()=>s(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=O(),{route:o}=l;return o&&o.component&&typeof o.component===i.function?a(o.component,{key:t,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 q={createElement:a,render:F,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return F(e,o.containerRoot)},Fragment:u,Hooks:Object.freeze({__proto__:null,createContext:L,useCallback:C,useEffect:S,useMemo:U,useQuery:O,useRef:v,useRouter:X,useStore:T})};window.Ryunix=q,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.createContext=L,e.default=q,e.useCallback=C,e.useEffect=S,e.useMemo=U,e.useQuery=O,e.useRef=v,e.useRouter=X,e.useStore=T,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.7",
3
+ "version": "1.1.7-canary.71",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.min.js",
6
6
  "types": "./dist/Ryunix.d.ts",