@unsetsoft/ryunixjs 1.1.6-canary.4 → 1.1.6-canary.7

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
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Ryunix = {}));
5
- })(this, (function (exports) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Ryunix = {}, global.lodash));
5
+ })(this, (function (exports, lodash) { 'use strict';
6
6
 
7
7
  let vars = {
8
8
  containerRoot: {},
@@ -37,37 +37,31 @@
37
37
  string: 'string',
38
38
  });
39
39
 
40
+ const OLD_STRINGS = Object.freeze({
41
+ style: 'style',
42
+ className: 'className',
43
+ });
44
+
40
45
  const EFFECT_TAGS = Object.freeze({
41
46
  PLACEMENT: Symbol('ryunix.reconciler.status.placement').toString(),
42
47
  UPDATE: Symbol('ryunix.reconciler.status.update').toString(),
43
48
  DELETION: Symbol('ryunix.reconciler.status.deletion').toString(),
44
49
  });
45
50
 
46
- const shallowEqual = (arr1, arr2) => {
47
- if (!arr1 || !arr2 || arr1.length !== arr2.length) return false
48
- for (let i = 0; i < arr1.length; i++) {
49
- if (arr1[i] !== arr2[i]) return false
50
- }
51
- return true
52
- };
53
-
54
- const resolveProps = (props) => {
55
- const resolvedProps = {};
56
- for (const key in props) {
57
- resolvedProps[key] =
58
- typeof props[key] === STRINGS.function ? props[key]() : props[key];
59
- }
60
- return resolvedProps
51
+ const generateHash = (prefix) => {
52
+ return `${prefix}-${Math.random().toString(36).substring(2, 9)}`
61
53
  };
62
54
 
63
55
  const Fragment = (props) => {
64
56
  return props.children
65
57
  };
66
58
 
67
- const childArray = (children, out = []) => {
68
- if (children == null) return out
69
- if (Array.isArray(children)) {
70
- children.forEach((child) => childArray(child, out));
59
+ const childArray = (children, out) => {
60
+ out = out || [];
61
+ if (children == undefined || typeof children == STRINGS.boolean) ; else if (Array.isArray(children)) {
62
+ children.some((child) => {
63
+ childArray(child, out);
64
+ });
71
65
  } else {
72
66
  out.push(children);
73
67
  }
@@ -92,18 +86,18 @@
92
86
  */
93
87
 
94
88
  const createElement = (type, props, ...children) => {
95
- const resolvedProps = resolveProps({ ...props });
96
- resolvedProps.children = childArray(children, []);
89
+ children = childArray(children, []);
97
90
  const key =
98
- resolvedProps.key ||
99
- `${RYUNIX_TYPES.Ryunix_ELEMENT.toString()}-${Math.random().toString(36).substring(2, 9)}`;
91
+ props && props.key
92
+ ? generateHash(props.key)
93
+ : generateHash(RYUNIX_TYPES.Ryunix_ELEMENT.toString());
100
94
 
101
95
  return {
102
96
  type,
103
97
  props: {
104
- ...resolvedProps,
98
+ ...props,
105
99
  key,
106
- children: resolvedProps.children.map((child) =>
100
+ children: children.map((child) =>
107
101
  typeof child === STRINGS.object ? child : createTextElement(child),
108
102
  ),
109
103
  },
@@ -219,53 +213,77 @@
219
213
  */
220
214
 
221
215
  const useEffect = (callback, deps) => {
222
- const oldHook = vars.wipFiber.alternate?.hooks?.[vars.hookIndex];
216
+ const oldHook =
217
+ vars.wipFiber.alternate &&
218
+ vars.wipFiber.alternate.hooks &&
219
+ vars.wipFiber.alternate.hooks[vars.hookIndex];
220
+
223
221
  const hook = {
224
222
  type: RYUNIX_TYPES.RYUNIX_EFFECT,
225
223
  deps,
226
- cleanup: oldHook?.cleanup,
227
224
  };
228
225
 
229
- const hasChangedDeps = !oldHook || !shallowEqual(oldHook.deps, deps);
230
-
231
- if (hasChangedDeps && hook.cleanup) {
232
- hook.cleanup();
226
+ if (!oldHook) {
227
+ // invoke callback if this is the first time
228
+ callback();
229
+ } else {
230
+ if (!lodash.isEqual(oldHook.deps, hook.deps)) {
231
+ callback();
232
+ }
233
233
  }
234
234
 
235
- if (hasChangedDeps) {
236
- hook.cleanup = callback();
235
+ if (vars.wipFiber.hooks) {
236
+ vars.wipFiber.hooks.push(hook);
237
+ vars.hookIndex++;
237
238
  }
238
-
239
- vars.wipFiber.hooks.push(hook);
240
- vars.hookIndex++;
241
239
  };
242
240
 
243
241
  const useRef = (initial) => {
244
- const oldHook = vars.wipFiber.alternate?.hooks?.[vars.hookIndex];
242
+ const oldHook =
243
+ vars.wipFiber.alternate &&
244
+ vars.wipFiber.alternate.hooks &&
245
+ vars.wipFiber.alternate.hooks[vars.hookIndex];
246
+
245
247
  const hook = {
246
248
  type: RYUNIX_TYPES.RYUNIX_REF,
247
249
  value: oldHook ? oldHook.value : { current: initial },
248
250
  };
249
251
 
250
- vars.wipFiber.hooks.push(hook);
251
- vars.hookIndex++;
252
+ if (vars.wipFiber.hooks) {
253
+ vars.wipFiber.hooks.push(hook);
254
+ vars.hookIndex++;
255
+ }
256
+
252
257
  return hook.value
253
258
  };
254
259
 
255
- const useMemo = (computeFn, deps) => {
256
- const oldHook = vars.wipFiber.alternate?.hooks?.[vars.hookIndex];
260
+ const useMemo = (comp, deps) => {
261
+ const oldHook =
262
+ vars.wipFiber.alternate &&
263
+ vars.wipFiber.alternate.hooks &&
264
+ vars.wipFiber.alternate.hooks[vars.hookIndex];
265
+
257
266
  const hook = {
258
267
  type: RYUNIX_TYPES.RYUNIX_MEMO,
259
- value: oldHook ? oldHook.value : computeFn(),
268
+ value: null,
260
269
  deps,
261
270
  };
262
271
 
263
- if (!oldHook || !shallowEqual(oldHook.deps, deps)) {
264
- hook.value = computeFn();
272
+ if (oldHook) {
273
+ if (lodash.isEqual(oldHook.deps, hook.deps)) {
274
+ hook.value = oldHook.value;
275
+ } else {
276
+ hook.value = comp();
277
+ }
278
+ } else {
279
+ hook.value = comp();
280
+ }
281
+
282
+ if (vars.wipFiber.hooks) {
283
+ vars.wipFiber.hooks.push(hook);
284
+ vars.hookIndex++;
265
285
  }
266
286
 
267
- vars.wipFiber.hooks.push(hook);
268
- vars.hookIndex++;
269
287
  return hook.value
270
288
  };
271
289
 
@@ -462,12 +480,13 @@
462
480
  * "cancelEffects" is likely intended
463
481
  */
464
482
  const cancelEffects = (fiber) => {
465
- if (!fiber.hooks) return
466
- fiber.hooks
467
- .filter((hook) => hook.type === RYUNIX_TYPES.RYUNIX_EFFECT && hook.cancel)
468
- .forEach((effectHook) => {
469
- effectHook.cancel();
470
- });
483
+ if (fiber.hooks) {
484
+ fiber.hooks
485
+ .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.cancel)
486
+ .forEach((effectHook) => {
487
+ effectHook.cancel();
488
+ });
489
+ }
471
490
  };
472
491
 
473
492
  /**
@@ -478,12 +497,13 @@
478
497
  * contains information about a component and its children, as
479
498
  */
480
499
  const runEffects = (fiber) => {
481
- if (!fiber.hooks) return
482
- fiber.hooks
483
- .filter((hook) => hook.type === RYUNIX_TYPES.RYUNIX_EFFECT && hook.effect)
484
- .forEach((effectHook) => {
485
- effectHook.cancel = effectHook.effect();
486
- });
500
+ if (fiber.hooks) {
501
+ fiber.hooks
502
+ .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.effect)
503
+ .forEach((effectHook) => {
504
+ effectHook.cancel = effectHook.effect();
505
+ });
506
+ }
487
507
  };
488
508
 
489
509
  /**
@@ -498,14 +518,15 @@
498
518
  */
499
519
  const createDom = (fiber) => {
500
520
  const dom =
501
- fiber.type === RYUNIX_TYPES.TEXT_ELEMENT
502
- ? document.createTextNode(fiber.props.nodeValue)
521
+ fiber.type == RYUNIX_TYPES.TEXT_ELEMENT
522
+ ? document.createTextNode('')
503
523
  : document.createElement(fiber.type);
504
524
 
505
525
  updateDom(dom, {}, fiber.props);
506
526
 
507
527
  return dom
508
528
  };
529
+
509
530
  /**
510
531
  * The function updates the DOM by removing old event listeners and properties, and adding new ones
511
532
  * based on the previous and next props.
@@ -522,14 +543,6 @@
522
543
  dom.removeEventListener(eventType, prevProps[name]);
523
544
  });
524
545
 
525
- Object.keys(nextProps)
526
- .filter(isEvent)
527
- .filter(isNew(prevProps, nextProps))
528
- .forEach((name) => {
529
- const eventType = name.toLowerCase().substring(2);
530
- dom.addEventListener(eventType, nextProps[name]);
531
- });
532
-
533
546
  Object.keys(prevProps)
534
547
  .filter(isProperty)
535
548
  .filter(isGone(nextProps))
@@ -542,24 +555,47 @@
542
555
  .filter(isNew(prevProps, nextProps))
543
556
  .forEach((name) => {
544
557
  if (name === STRINGS.style) {
545
- DomStyle(dom, nextProps[name]);
558
+ DomStyle(dom, nextProps['ryunix-style']);
559
+ } else if (name === OLD_STRINGS.style) {
560
+ DomStyle(dom, nextProps.style);
546
561
  } else if (name === STRINGS.className) {
547
- if (nextProps[name] !== prevProps[name]) {
548
- dom.className = nextProps[name];
562
+ if (nextProps['ryunix-class'] === '') {
563
+ throw new Error('data-class cannot be empty.')
549
564
  }
565
+
566
+ prevProps['ryunix-class'] &&
567
+ dom.classList.remove(...prevProps['ryunix-class'].split(/\s+/));
568
+ dom.classList.add(...nextProps['ryunix-class'].split(/\s+/));
569
+ } else if (name === OLD_STRINGS.className) {
570
+ if (nextProps.className === '') {
571
+ throw new Error('className cannot be empty.')
572
+ }
573
+
574
+ prevProps.className &&
575
+ dom.classList.remove(...prevProps.className.split(/\s+/));
576
+ dom.classList.add(...nextProps.className.split(/\s+/));
550
577
  } else {
551
578
  dom[name] = nextProps[name];
552
579
  }
553
580
  });
581
+
582
+ Object.keys(nextProps)
583
+ .filter(isEvent)
584
+ .filter(isNew(prevProps, nextProps))
585
+ .forEach((name) => {
586
+ const eventType = name.toLowerCase().substring(2);
587
+ dom.addEventListener(eventType, nextProps[name]);
588
+ });
554
589
  };
555
590
 
556
591
  const DomStyle = (dom, style) => {
557
- for (const key in style) {
558
- const styleProp = key.replace(reg, (v) => '-' + v.toLowerCase());
559
- if (dom.style[styleProp] !== style[key]) {
560
- dom.style[styleProp] = style[key];
561
- }
562
- }
592
+ dom.style = Object.keys(style).reduce((acc, styleName) => {
593
+ const key = styleName.replace(reg, function (v) {
594
+ return '-' + v.toLowerCase()
595
+ });
596
+ acc += `${key}: ${style[styleName]};`;
597
+ return acc
598
+ }, '');
563
599
  };
564
600
 
565
601
  var Dom = /*#__PURE__*/Object.freeze({
@@ -578,7 +614,7 @@
578
614
  commitWork(vars.wipRoot.child);
579
615
  vars.currentRoot = vars.wipRoot;
580
616
  }
581
- vars.wipRoot = null;
617
+ vars.wipRoot = undefined;
582
618
  };
583
619
 
584
620
  /**
@@ -592,15 +628,15 @@
592
628
  if (!fiber) return
593
629
 
594
630
  let domParentFiber = fiber.parent;
595
- while (domParentFiber && !domParentFiber.dom) {
631
+ while (!domParentFiber.dom) {
596
632
  domParentFiber = domParentFiber.parent;
597
633
  }
598
- const domParent = domParentFiber?.dom;
634
+ const domParent = domParentFiber.dom;
599
635
 
600
- if (fiber.effectTag === EFFECT_TAGS.PLACEMENT && fiber.dom) {
636
+ if (fiber.effectTag === EFFECT_TAGS.PLACEMENT && fiber.dom != null) {
601
637
  domParent.appendChild(fiber.dom);
602
638
  runEffects(fiber);
603
- } else if (fiber.effectTag === EFFECT_TAGS.UPDATE && fiber.dom) {
639
+ } else if (fiber.effectTag === EFFECT_TAGS.UPDATE && fiber.dom != null) {
604
640
  cancelEffects(fiber);
605
641
  updateDom(fiber.dom, fiber.alternate.props, fiber.props);
606
642
  runEffects(fiber);
@@ -610,6 +646,7 @@
610
646
  return
611
647
  }
612
648
 
649
+ // Recorre los "fibers" hijos y hermanos
613
650
  commitWork(fiber.child);
614
651
  commitWork(fiber.sibling);
615
652
  };
@@ -624,12 +661,9 @@
624
661
  const commitDeletion = (fiber, domParent) => {
625
662
  if (fiber.dom) {
626
663
  domParent.removeChild(fiber.dom);
627
- } else if (fiber.child) {
664
+ } else {
628
665
  commitDeletion(fiber.child, domParent);
629
666
  }
630
- if (fiber.sibling) {
631
- commitDeletion(fiber.sibling, domParent);
632
- }
633
667
  };
634
668
 
635
669
  var Commits = /*#__PURE__*/Object.freeze({
@@ -648,16 +682,15 @@
648
682
  * @param elements - an array of elements representing the new children to be rendered in the current
649
683
  * fiber's subtree
650
684
  */
651
-
652
685
  const reconcileChildren = (wipFiber, elements) => {
653
686
  let index = 0;
687
+ let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
654
688
  let prevSibling = null;
655
- const oldFibersMap = new Map();
656
689
 
657
- let oldFiber = wipFiber.alternate?.child;
690
+ const oldFibersMap = new Map();
658
691
  while (oldFiber) {
659
- const key = oldFiber.props.key || oldFiber.type;
660
- oldFibersMap.set(key, oldFiber);
692
+ const oldKey = oldFiber.props.key || oldFiber.type;
693
+ oldFibersMap.set(oldKey, oldFiber);
661
694
  oldFiber = oldFiber.sibling;
662
695
  }
663
696
 
@@ -669,12 +702,13 @@
669
702
  let newFiber;
670
703
  const sameType = oldFiber && element && element.type === oldFiber.type;
671
704
 
672
- if (sameType && shallowEqual(oldFiber.props, element.props)) {
673
- newFiber = oldFiber;
674
- } else if (sameType) {
705
+ if (sameType) {
675
706
  newFiber = {
676
- ...oldFiber,
707
+ type: oldFiber.type,
677
708
  props: element.props,
709
+ dom: oldFiber.dom,
710
+ parent: wipFiber,
711
+ alternate: oldFiber,
678
712
  effectTag: EFFECT_TAGS.UPDATE,
679
713
  };
680
714
  oldFibersMap.delete(key);
@@ -682,8 +716,10 @@
682
716
  newFiber = {
683
717
  type: element.type,
684
718
  props: element.props,
685
- effectTag: EFFECT_TAGS.PLACEMENT,
719
+ dom: undefined,
686
720
  parent: wipFiber,
721
+ alternate: undefined,
722
+ effectTag: EFFECT_TAGS.PLACEMENT,
687
723
  };
688
724
  }
689
725
 
@@ -721,7 +757,9 @@
721
757
  vars.wipFiber.hooks = [];
722
758
 
723
759
  const children = fiber.type(fiber.props);
724
- reconcileChildren(fiber, Array.isArray(children) ? children : [children]);
760
+ let childArr = Array.isArray(children) ? children : [children];
761
+
762
+ reconcileChildren(fiber, childArr);
725
763
  };
726
764
 
727
765
  /**
@@ -762,9 +800,7 @@
762
800
  commitRoot();
763
801
  }
764
802
 
765
- if (vars.nextUnitOfWork || vars.wipRoot) {
766
- requestIdleCallback(workLoop);
767
- }
803
+ requestIdleCallback(workLoop);
768
804
  };
769
805
 
770
806
  requestIdleCallback(workLoop);
@@ -788,9 +824,9 @@
788
824
  } else {
789
825
  updateHostComponent(fiber);
790
826
  }
791
-
792
- if (fiber.child) return fiber.child
793
-
827
+ if (fiber.child) {
828
+ return fiber.child
829
+ }
794
830
  let nextFiber = fiber;
795
831
  while (nextFiber) {
796
832
  if (nextFiber.sibling) {
@@ -798,6 +834,7 @@
798
834
  }
799
835
  nextFiber = nextFiber.parent;
800
836
  }
837
+ return undefined
801
838
  };
802
839
 
803
840
  var Workers = /*#__PURE__*/Object.freeze({
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={})}(this,(function(e){"use strict";let t={containerRoot:{},nextUnitOfWork:{},currentRoot:{},wipRoot:{},deletions:[],wipFiber:{},hookIndex:0};const o=/[A-Z]/g,n=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")}),r=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),i=Object.freeze({PLACEMENT:Symbol("ryunix.reconciler.status.placement").toString(),UPDATE:Symbol("ryunix.reconciler.status.update").toString(),DELETION:Symbol("ryunix.reconciler.status.deletion").toString()}),s=(e,t)=>{if(!e||!t||e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0},l=(e,t=[])=>(null==e||(Array.isArray(e)?e.forEach((e=>l(e,t))):t.push(e)),t),c=(e,t,...o)=>{const i=(e=>{const t={};for(const o in e)t[o]=typeof e[o]===r.function?e[o]():e[o];return t})({...t});i.children=l(o,[]);const s=i.key||`${n.Ryunix_ELEMENT.toString()}-${Math.random().toString(36).substring(2,9)}`;return{type:e,props:{...i,key:s,children:i.children.map((e=>typeof e===r.object?e:p(e)))}}},p=e=>({type:n.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),a=(e,o)=>{t.wipRoot={dom:o,props:{children:[e]},alternate:t.currentRoot},t.deletions=[],t.nextUnitOfWork=t.wipRoot},u=e=>{const o=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],n={state:o?o.state:e,queue:o?[...o.queue]:[]};n.queue.forEach((e=>{n.state=typeof e===r.function?e(n.state):e})),n.queue=[];return t.wipFiber&&t.wipFiber.hooks&&(t.wipFiber.hooks.push(n),t.hookIndex++),[n.state,e=>{n.queue.push(e),t.wipRoot={dom:t.currentRoot.dom,props:{...t.currentRoot.props},alternate:t.currentRoot},t.nextUnitOfWork=t.wipRoot,t.deletions=[]}]},f=(e,o)=>{const r=t.wipFiber.alternate?.hooks?.[t.hookIndex],i={type:n.RYUNIX_EFFECT,deps:o,cleanup:r?.cleanup},l=!r||!s(r.deps,o);l&&i.cleanup&&i.cleanup(),l&&(i.cleanup=e()),t.wipFiber.hooks.push(i),t.hookIndex++},d=(e,o)=>{const r=t.wipFiber.alternate?.hooks?.[t.hookIndex],i={type:n.RYUNIX_MEMO,value:r?r.value:e(),deps:o};return r&&s(r.deps,o)||(i.value=e()),t.wipFiber.hooks.push(i),t.hookIndex++,i.value},h=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},m=e=>e.startsWith("on"),y=e=>e!==r.children&&!m(e),E=(e,t)=>o=>e[o]!==t[o],b=e=>t=>!(t in e),R=e=>{e.hooks&&e.hooks.filter((e=>e.type===n.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},k=e=>{e.hooks&&e.hooks.filter((e=>e.type===n.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},w=e=>{const t=e.type===n.TEXT_ELEMENT?document.createTextNode(e.props.nodeValue):document.createElement(e.type);return x(t,{},e.props),t},x=(e,t,o)=>{Object.keys(t).filter(m).filter((e=>b(o)(e)||E(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(o).filter(m).filter(E(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])})),Object.keys(t).filter(y).filter(b(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(y).filter(E(t,o)).forEach((n=>{n===r.style?_(e,o[n]):n===r.className?o[n]!==t[n]&&(e.className=o[n]):e[n]=o[n]}))},_=(e,t)=>{for(const n in t){const r=n.replace(o,(e=>"-"+e.toLowerCase()));e.style[r]!==t[n]&&(e.style[r]=t[n])}};var g=Object.freeze({__proto__:null,DomStyle:_,createDom:w,updateDom:x});const F=()=>{t.deletions.forEach(T),t.wipRoot&&t.wipRoot.child&&(T(t.wipRoot.child),t.currentRoot=t.wipRoot),t.wipRoot=null},T=e=>{if(!e)return;let t=e.parent;for(;t&&!t.dom;)t=t.parent;const o=t?.dom;if(e.effectTag===i.PLACEMENT&&e.dom)o.appendChild(e.dom),k(e);else if(e.effectTag===i.UPDATE&&e.dom)R(e),x(e.dom,e.alternate.props,e.props),k(e);else if(e.effectTag===i.DELETION)return N(e,o),void R(e);T(e.child),T(e.sibling)},N=(e,t)=>{e.dom?t.removeChild(e.dom):e.child&&N(e.child,t),e.sibling&&N(e.sibling,t)};var I=Object.freeze({__proto__:null,commitDeletion:N,commitRoot:F,commitWork:T});const O=(e,o)=>{let n=0,r=null;const l=new Map;let c=e.alternate?.child;for(;c;){const e=c.props.key||c.type;l.set(e,c),c=c.sibling}for(;n<o.length;){const t=o[n],c=t.props.key||t.type,p=l.get(c);let a;const u=p&&t&&t.type===p.type;u&&s(p.props,t.props)?a=p:u?(a={...p,props:t.props,effectTag:i.UPDATE},l.delete(c)):t&&(a={type:t.type,props:t.props,effectTag:i.PLACEMENT,parent:e}),0===n?e.child=a:r&&(r.sibling=a),r=a,n++}l.forEach((e=>{e.effectTag=i.DELETION,t.deletions.push(e)}))};var U=Object.freeze({__proto__:null,reconcileChildren:O});const v=e=>{t.wipFiber=e,t.hookIndex=0,t.wipFiber.hooks=[];const o=e.type(e.props);O(e,Array.isArray(o)?o:[o])},C=e=>{e.dom||(e.dom=w(e)),O(e,e.props.children)};var L=Object.freeze({__proto__:null,updateFunctionComponent:v,updateHostComponent:C});const S=e=>{let o=!1;for(;t.nextUnitOfWork&&!o;)t.nextUnitOfWork=j(t.nextUnitOfWork),o=e.timeRemaining()<1;!t.nextUnitOfWork&&t.wipRoot&&F(),(t.nextUnitOfWork||t.wipRoot)&&requestIdleCallback(S)};requestIdleCallback(S);const j=e=>{if(e.type instanceof Function?v(e):C(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}};var M={createElement:c,render:a,init:(e,o="__ryunix")=>{t.containerRoot=document.getElementById(o),a(e,t.containerRoot)},Fragment:e=>e.children,Dom:g,Workers:Object.freeze({__proto__:null,performUnitOfWork:j,workLoop:S}),Reconciler:U,Components:L,Commits:I};window.Ryunix=M,e.default=M,e.useCallback=(e,t)=>d((()=>e),t),e.useEffect=f,e.useMemo=d,e.useQuery=h,e.useRef=e=>{const o=t.wipFiber.alternate?.hooks?.[t.hookIndex],r={type:n.RYUNIX_REF,value:o?o.value:{current:e}};return t.wipFiber.hooks.push(r),t.hookIndex++,r.value},e.useRouter=e=>{const[t,o]=u(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},i=e=>{window.history.pushState({},"",e),s(e)},s=e=>{const t=e.split("?")[0];o(t)};f((()=>{const e=()=>s(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=h(),{route:t}=l;return t&&t.component&&typeof t.component===r.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(),i(e)},...t},t.children),navigate:i}},e.useStore=u,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:{},nextUnitOfWork:{},currentRoot:{},wipRoot:{},deletions:[],wipFiber:{},hookIndex:0};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"}),a=Object.freeze({PLACEMENT:Symbol("ryunix.reconciler.status.placement").toString(),UPDATE:Symbol("ryunix.reconciler.status.update").toString(),DELETION:Symbol("ryunix.reconciler.status.deletion").toString()}),l=e=>`${e}-${Math.random().toString(36).substring(2,9)}`,c=(e,t)=>(t=t||[],null==e||typeof e==i.boolean||(Array.isArray(e)?e.some((e=>{c(e,t)})):t.push(e)),t),p=(e,t,...o)=>{o=c(o,[]);const n=t&&t.key?l(t.key):l(r.Ryunix_ELEMENT.toString());return{type:e,props:{...t,key:n,children:o.map((e=>typeof e===i.object?e:u(e)))}}},u=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),d=(e,t)=>{o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.deletions=[],o.nextUnitOfWork=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]:[]};n.queue.forEach((e=>{n.state=typeof e===i.function?e(n.state):e})),n.queue=[];return o.wipFiber&&o.wipFiber.hooks&&(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=[]}]},m=(e,n)=>{const i=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],s={type:r.RYUNIX_EFFECT,deps:n};i&&t.isEqual(i.deps,s.deps)||e(),o.wipFiber.hooks&&(o.wipFiber.hooks.push(s),o.hookIndex++)},h=(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.wipFiber.hooks.push(s),o.hookIndex++),s.value},y=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},b=e=>e.startsWith("on"),E=e=>e!==i.children&&!b(e),w=(e,t)=>o=>e[o]!==t[o],k=e=>t=>!(t in e),R=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},x=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},F=e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return _(t,{},e.props),t},_=(e,t,o)=>{Object.keys(t).filter(b).filter((e=>k(o)(e)||w(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(E).filter(k(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(E).filter(w(t,o)).forEach((n=>{if(n===i.style)N(e,o["ryunix-style"]);else if(n===s.style)N(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(b).filter(w(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])}))},N=(e,t)=>{e.style=Object.keys(t).reduce(((e,o)=>e+=`${o.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${t[o]};`),"")};var g=Object.freeze({__proto__:null,DomStyle:N,createDom:F,updateDom:_});const T=()=>{o.deletions.forEach(v),o.wipRoot&&o.wipRoot.child&&(v(o.wipRoot.child),o.currentRoot=o.wipRoot),o.wipRoot=void 0},v=e=>{if(!e)return;let t=e.parent;for(;!t.dom;)t=t.parent;const o=t.dom;if(e.effectTag===a.PLACEMENT&&null!=e.dom)o.appendChild(e.dom),x(e);else if(e.effectTag===a.UPDATE&&null!=e.dom)R(e),_(e.dom,e.alternate.props,e.props),x(e);else if(e.effectTag===a.DELETION)return O(e,o),void R(e);v(e.child),v(e.sibling)},O=(e,t)=>{e.dom?t.removeChild(e.dom):O(e.child,t)};var I=Object.freeze({__proto__:null,commitDeletion:O,commitRoot:T,commitWork:v});const L=(e,t)=>{let n=0,r=e.alternate&&e.alternate.child,i=null;const s=new Map;for(;r;){const e=r.props.key||r.type;s.set(e,r),r=r.sibling}for(;n<t.length;){const o=t[n],r=o.props.key||o.type,l=s.get(r);let c;l&&o&&o.type===l.type?(c={type:l.type,props:o.props,dom:l.dom,parent:e,alternate:l,effectTag:a.UPDATE},s.delete(r)):o&&(c={type:o.type,props:o.props,dom:void 0,parent:e,alternate:void 0,effectTag:a.PLACEMENT}),0===n?e.child=c:i&&(i.sibling=c),i=c,n++}s.forEach((e=>{e.effectTag=a.DELETION,o.deletions.push(e)}))};var U=Object.freeze({__proto__:null,reconcileChildren:L});const C=e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];const t=e.type(e.props);let n=Array.isArray(t)?t:[t];L(e,n)},S=e=>{e.dom||(e.dom=F(e)),L(e,e.props.children)};var j=Object.freeze({__proto__:null,updateFunctionComponent:C,updateHostComponent:S});const M=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=X(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&T(),requestIdleCallback(M)};requestIdleCallback(M);const X=e=>{if(e.type instanceof Function?C(e):S(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}};var D={createElement:p,render:d,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t),d(e,o.containerRoot)},Fragment:e=>e.children,Dom:g,Workers:Object.freeze({__proto__:null,performUnitOfWork:X,workLoop:M}),Reconciler:U,Components:j,Commits:I};window.Ryunix=D,e.default=D,e.useCallback=(e,t)=>h((()=>e),t),e.useEffect=m,e.useMemo=h,e.useQuery=y,e.useRef=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.wipFiber.hooks.push(n),o.hookIndex++),n.value},e.useRouter=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)),"([^/]+)")))}$`),a=o.match(s);if(a){return{route:r,params:e.reduce(((e,t,o)=>(e[t]=a[o+1],e)),{})}}}return i},r=e=>{window.history.pushState({},"",e),s(e)},s=e=>{const t=e.split("?")[0];o(t)};m((()=>{const e=()=>s(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const a=n(e,t)||{};return{Children:()=>{const e=y(),{route:t}=a;return t&&t.component&&typeof t.component===i.function?t.component({params:a.params||{},query:e}):(console.error("Component not found for current path or the component is not a valid function:",a),null)},NavLink:({to:e,...t})=>p("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}},e.useStore=f,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.6-canary.4",
3
+ "version": "1.1.6-canary.7",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.min.js",
6
6
  "types": "./dist/Ryunix.d.ts",