@unsetsoft/ryunixjs 0.4.6 → 0.4.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 ADDED
@@ -0,0 +1,672 @@
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';
6
+
7
+ const vars = {
8
+ containerRoot: null,
9
+ nextUnitOfWork: null,
10
+ currentRoot: null,
11
+ wipRoot: null,
12
+ deletions: null,
13
+ wipFiber: null,
14
+ hookIndex: null,
15
+ };
16
+
17
+ const reg = /[A-Z]/g;
18
+
19
+ const RYUNIX_TYPES = Object.freeze({
20
+ TEXT_ELEMENT: Symbol("text.element"),
21
+ RYUNIX_EFFECT: Symbol("ryunix.effect"),
22
+ RYUNIX_CONTEXT: Symbol("ryunix.context"),
23
+ });
24
+
25
+ const STRINGS = Object.freeze({
26
+ object: "object",
27
+ function: "function",
28
+ style: "style",
29
+ className: "className",
30
+ children: "children",
31
+ });
32
+
33
+ const EFFECT_TAGS = Object.freeze({
34
+ PLACEMENT: Symbol(),
35
+ UPDATE: Symbol(),
36
+ DELETION: Symbol(),
37
+ });
38
+
39
+ /**
40
+ * The function creates a new element with the given type, props, and children.
41
+ * @param type - The type of the element to be created, such as "div", "span", "h1", etc.
42
+ * @param props - The `props` parameter is an object that contains the properties or attributes of the
43
+ * element being created. These properties can include things like `className`, `id`, `style`, and any
44
+ * other custom attributes that the user wants to add to the element. The `props` object is spread
45
+ * using the spread
46
+ * @param children - The `children` parameter is a rest parameter that allows the function to accept
47
+ * any number of arguments after the `props` parameter. These arguments will be treated as children
48
+ * elements of the created element. The `map` function is used to iterate over each child and create a
49
+ * new element if it is not
50
+ * @returns A JavaScript object with a `type` property and a `props` property. The `type` property is
51
+ * set to the `type` argument passed into the function, and the `props` property is an object that
52
+ * includes any additional properties passed in the `props` argument, as well as a `children` property
53
+ * that is an array of any child elements passed in the `...children` argument
54
+ */
55
+
56
+ const createElement = (type, props, ...children) => {
57
+ return {
58
+ type,
59
+ props: {
60
+ ...props,
61
+ children: children
62
+ .flat()
63
+ .map((child) =>
64
+ typeof child === STRINGS.object ? child : createTextElement(child)
65
+ ),
66
+ },
67
+ };
68
+ };
69
+
70
+ /**
71
+ * The function creates a text element with a given text value.
72
+ * @param text - The text content that will be used to create a new text element.
73
+ * @returns A JavaScript object with a `type` property set to `"TEXT_ELEMENT"` and a `props` property
74
+ * that contains a `nodeValue` property set to the `text` parameter and an empty `children` array.
75
+ */
76
+
77
+ const createTextElement = (text) => {
78
+ return {
79
+ type: RYUNIX_TYPES.TEXT_ELEMENT,
80
+ props: {
81
+ nodeValue: text,
82
+ children: [],
83
+ },
84
+ };
85
+ };
86
+
87
+ const Fragments = (props) => {
88
+ if (props.style) {
89
+ throw new Error("The style attribute is not supported");
90
+ }
91
+ if (props.className === "") {
92
+ throw new Error("className cannot be empty.");
93
+ }
94
+ return createElement("div", props, props.children);
95
+ };
96
+
97
+ /**
98
+ * The function renders an element into a container using a work-in-progress root.
99
+ * @param element - The element parameter is the component or element that needs to be rendered in the
100
+ * container. It could be a Ryunix component or a DOM element.
101
+ * @param container - The container parameter is the DOM element where the rendered element will be
102
+ * appended to. this parameter is optional if you use createRoot().
103
+ */
104
+ const render = (element, container) => {
105
+ vars.wipRoot = {
106
+ dom: vars.containerRoot || container,
107
+ props: {
108
+ children: [element],
109
+ },
110
+ alternate: vars.currentRoot,
111
+ };
112
+ vars.deletions = [];
113
+ vars.nextUnitOfWork = vars.wipRoot;
114
+ };
115
+
116
+ /**
117
+ * @description The function creates a reference to a DOM element with the specified ID. This will be used to initialize the app.
118
+ * @example Ryunix.init("root") -> <div id="root" />
119
+ * @param root - The parameter "root" is the id of the HTML element that will serve as the container
120
+ * for the root element.
121
+ */
122
+ const init = (root) => {
123
+ const rootElement = root || "__ryunix";
124
+ vars.containerRoot = document.getElementById(rootElement);
125
+ };
126
+
127
+ const isEvent = (key) => key.startsWith("on");
128
+ const isProperty = (key) => key !== STRINGS.children && !isEvent(key);
129
+ const isNew = (prev, next) => (key) => prev[key] !== next[key];
130
+ const isGone = (next) => (key) => !(key in next);
131
+ const hasDepsChanged = (prevDeps, nextDeps) =>
132
+ !prevDeps ||
133
+ !nextDeps ||
134
+ prevDeps.length !== nextDeps.length ||
135
+ prevDeps.some((dep, index) => dep !== nextDeps[index]);
136
+
137
+ /**
138
+ * The function cancels all effect hooks in a given fiber.
139
+ * @param fiber - The "fiber" parameter is likely referring to a data structure used in React.js to
140
+ * represent a component and its state. It contains information about the component's props, state, and
141
+ * children, as well as metadata used by React to manage updates and rendering. The function
142
+ * "cancelEffects" is likely intended
143
+ */
144
+ const cancelEffects = (fiber) => {
145
+ if (fiber.hooks) {
146
+ fiber.hooks
147
+ .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.cancel)
148
+ .forEach((effectHook) => {
149
+ effectHook.cancel();
150
+ });
151
+ }
152
+ };
153
+
154
+ /**
155
+ * The function runs all effect hooks in a given fiber.
156
+ * @param fiber - The "fiber" parameter is likely referring to a data structure used in the
157
+ * implementation of a fiber-based reconciliation algorithm, such as the one used in React. A fiber
158
+ * represents a unit of work that needs to be performed by the reconciliation algorithm, and it
159
+ * contains information about a component and its children, as
160
+ */
161
+ const runEffects = (fiber) => {
162
+ if (fiber.hooks) {
163
+ fiber.hooks
164
+ .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.effect)
165
+ .forEach((effectHook) => {
166
+ effectHook.cancel = effectHook.effect();
167
+ });
168
+ }
169
+ };
170
+
171
+ /**
172
+ * @description The function creates a state.
173
+ * @param initial - The initial value of the state for the hook.
174
+ * @returns The `useStore` function returns an array with two elements: the current state value and a
175
+ * `setState` function that can be used to update the state.
176
+ */
177
+ const useStore = (initial) => {
178
+ const oldHook =
179
+ vars.wipFiber.alternate &&
180
+ vars.wipFiber.alternate.hooks &&
181
+ vars.wipFiber.alternate.hooks[vars.hookIndex];
182
+ const hook = {
183
+ state: oldHook ? oldHook.state : initial,
184
+ queue: [],
185
+ };
186
+
187
+ const actions = oldHook ? oldHook.queue : [];
188
+ actions.forEach((action) => {
189
+ hook.state =
190
+ typeof action === STRINGS.function ? action(hook.state) : action;
191
+ });
192
+
193
+ /**
194
+ * The function `setState` updates the state of a component in Ryunix by adding an action to a queue
195
+ * and setting up a new work-in-progress root.
196
+ * @param action - The `action` parameter is an object that represents a state update to be performed
197
+ * on a component. It contains information about the type of update to be performed and any new data
198
+ * that needs to be applied to the component's state.
199
+ */
200
+ const setState = (action) => {
201
+ hook.queue.push(action);
202
+ vars.wipRoot = {
203
+ dom: vars.currentRoot.dom,
204
+ props: vars.currentRoot.props,
205
+ alternate: vars.currentRoot,
206
+ };
207
+ vars.nextUnitOfWork = vars.wipRoot;
208
+ vars.deletions = [];
209
+ };
210
+
211
+ vars.wipFiber.hooks.push(hook);
212
+ vars.hookIndex++;
213
+ return [hook.state, setState];
214
+ };
215
+
216
+ /**
217
+ * This is a function that creates a hook for managing side effects in Ryunix components.
218
+ * @param effect - The effect function that will be executed after the component has rendered or when
219
+ * the dependencies have changed. It can perform side effects such as fetching data, updating the DOM,
220
+ * or subscribing to events.
221
+ * @param deps - An array of dependencies that the effect depends on. If any of the dependencies change
222
+ * between renders, the effect will be re-run. If the array is empty, the effect will only run once on
223
+ * mount and never again.
224
+ */
225
+ const useEffect = (effect, deps) => {
226
+ const oldHook =
227
+ vars.wipFiber.alternate &&
228
+ vars.wipFiber.alternate.hooks &&
229
+ vars.wipFiber.alternate.hooks[vars.hookIndex];
230
+
231
+ const hasChanged = hasDepsChanged(oldHook ? oldHook.deps : undefined, deps);
232
+
233
+ const hook = {
234
+ tag: RYUNIX_TYPES.RYUNIX_EFFECT,
235
+ effect: hasChanged ? effect : null,
236
+ cancel: hasChanged && oldHook && oldHook.cancel,
237
+ deps,
238
+ };
239
+
240
+ vars.wipFiber.hooks.push(hook);
241
+ vars.hookIndex++;
242
+ };
243
+
244
+ const useQuery = () => {
245
+ vars.hookIndex++;
246
+
247
+ const oldHook =
248
+ vars.wipFiber.alternate &&
249
+ vars.wipFiber.alternate.hooks &&
250
+ vars.wipFiber.alternate.hooks[vars.hookIndex];
251
+
252
+ const hasOld = oldHook ? oldHook : undefined;
253
+
254
+ const urlSearchParams = new URLSearchParams(window.location.search);
255
+ const params = Object.fromEntries(urlSearchParams.entries());
256
+ const Query = hasOld ? hasOld : params;
257
+
258
+ const hook = {
259
+ tag: RYUNIX_TYPES.RYUNIX_EFFECT,
260
+ query: Query,
261
+ };
262
+
263
+ vars.wipFiber.hooks.push(hook);
264
+
265
+ return hook.query;
266
+ };
267
+
268
+ const Router = ({ path, component }) => {
269
+ const [currentPath, setCurrentPath] = useStore(window.location.pathname);
270
+
271
+ useEffect(() => {
272
+ const onLocationChange = () => {
273
+ setCurrentPath(() => window.location.pathname);
274
+ };
275
+
276
+ window.addEventListener("navigate", onLocationChange);
277
+ window.addEventListener("pushsatate", onLocationChange);
278
+ window.addEventListener("popstate", onLocationChange);
279
+
280
+ return () => {
281
+ window.removeEventListener("navigate", onLocationChange);
282
+ window.removeEventListener("pushsatate", onLocationChange);
283
+ window.removeEventListener("popstate", onLocationChange);
284
+ };
285
+ }, [currentPath]);
286
+
287
+ return currentPath === path ? component() : null;
288
+ };
289
+
290
+ const Navigate = (props) => {
291
+ if (props.style) {
292
+ throw new Error(
293
+ "The style attribute is not supported on internal components, use className."
294
+ );
295
+ }
296
+ if (props.to === "") {
297
+ throw new Error("'to=' cannot be empty.");
298
+ }
299
+ if (props.className === "") {
300
+ throw new Error("className cannot be empty.");
301
+ }
302
+ if (props.label === "" && !props.children) {
303
+ throw new Error("'label=' cannot be empty.");
304
+ }
305
+
306
+ if (!props.to) {
307
+ throw new Error("Missig 'to' param.");
308
+ }
309
+ const preventReload = (event) => {
310
+ event.preventDefault();
311
+ if (window.location.pathname !== props.to) {
312
+ window.history.pushState({}, "", props.to);
313
+ const navigationEvent = new Event("pushsatate");
314
+ window.dispatchEvent(navigationEvent);
315
+ }
316
+ };
317
+
318
+ const anchor = {
319
+ href: props.to,
320
+ onClick: preventReload,
321
+ ...props,
322
+ };
323
+
324
+ const children = props.label ? props.label : props.children;
325
+
326
+ return createElement("a", anchor, children);
327
+ };
328
+
329
+ /**
330
+ * The function creates a new DOM element based on the given fiber object and updates its properties.
331
+ * @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
332
+ * contains information about the element type, props, and children of the node.
333
+ * @returns The `createDom` function returns a newly created DOM element based on the `fiber` object
334
+ * passed as an argument. If the `fiber` object represents a text element, a text node is created using
335
+ * `document.createTextNode("")`. Otherwise, a new element is created using
336
+ * `document.createElement(fiber.type)`. The function then calls the `updateDom` function to update the
337
+ * properties of the newly created
338
+ */
339
+ const createDom = (fiber) => {
340
+ const dom =
341
+ fiber.type == RYUNIX_TYPES.TEXT_ELEMENT
342
+ ? document.createTextNode("")
343
+ : document.createElement(fiber.type);
344
+
345
+ updateDom(dom, {}, fiber.props);
346
+
347
+ return dom;
348
+ };
349
+
350
+ /**
351
+ * The function updates the DOM by removing old event listeners and properties, and adding new ones
352
+ * based on the previous and next props.
353
+ * @param dom - The DOM element that needs to be updated with new props.
354
+ * @param prevProps - An object representing the previous props (properties) of a DOM element.
355
+ * @param nextProps - An object containing the new props that need to be updated in the DOM.
356
+ */
357
+ const updateDom = (dom, prevProps, nextProps) => {
358
+ Object.keys(prevProps)
359
+ .filter(isEvent)
360
+ .filter((key) => isGone(nextProps)(key) || isNew(prevProps, nextProps)(key))
361
+ .forEach((name) => {
362
+ const eventType = name.toLowerCase().substring(2);
363
+ dom.removeEventListener(eventType, prevProps[name]);
364
+ });
365
+
366
+ Object.keys(prevProps)
367
+ .filter(isProperty)
368
+ .filter(isGone(nextProps))
369
+ .forEach((name) => {
370
+ dom[name] = "";
371
+ });
372
+
373
+ Object.keys(nextProps)
374
+ .filter(isProperty)
375
+ .filter(isNew(prevProps, nextProps))
376
+ .forEach((name) => {
377
+ if (name === STRINGS.style) {
378
+ DomStyle(dom, nextProps.style);
379
+ } else if (name === STRINGS.className) {
380
+ if (nextProps.className === "") {
381
+ throw new Error("className cannot be empty.");
382
+ }
383
+ prevProps.className &&
384
+ dom.classList.remove(...prevProps.className.split(/\s+/));
385
+ dom.classList.add(...nextProps.className.split(/\s+/));
386
+ } else {
387
+ dom[name] = nextProps[name];
388
+ }
389
+ });
390
+
391
+ Object.keys(nextProps)
392
+ .filter(isEvent)
393
+ .filter(isNew(prevProps, nextProps))
394
+ .forEach((name) => {
395
+ const eventType = name.toLowerCase().substring(2);
396
+ dom.addEventListener(eventType, nextProps[name]);
397
+ });
398
+ };
399
+
400
+ const DomStyle = (dom, style) => {
401
+ dom.style = Object.keys(style).reduce((acc, styleName) => {
402
+ const key = styleName.replace(reg, function (v) {
403
+ return "-" + v.toLowerCase();
404
+ });
405
+ acc += `${key}: ${style[styleName]};`;
406
+ return acc;
407
+ }, "");
408
+ };
409
+
410
+ var Dom = /*#__PURE__*/Object.freeze({
411
+ __proto__: null,
412
+ DomStyle: DomStyle,
413
+ createDom: createDom,
414
+ updateDom: updateDom
415
+ });
416
+
417
+ /**
418
+ * The function commits changes made to the virtual DOM to the actual DOM.
419
+ */
420
+ const commitRoot = () => {
421
+ vars.deletions.forEach(commitWork);
422
+ commitWork(vars.wipRoot.child);
423
+ vars.currentRoot = vars.wipRoot;
424
+ vars.wipRoot = null;
425
+ };
426
+
427
+ /**
428
+ * The function commits changes made to the DOM based on the effect tag of the fiber.
429
+ * @param fiber - A fiber is a unit of work in Ryunix's reconciliation process. It represents a
430
+ * component and its state at a particular point in time. The `commitWork` function takes a fiber as a
431
+ * parameter to commit the changes made during the reconciliation process to the actual DOM.
432
+ * @returns The function does not return anything, it performs side effects by manipulating the DOM.
433
+ */
434
+ const commitWork = (fiber) => {
435
+ if (!fiber) {
436
+ return;
437
+ }
438
+
439
+ let domParentFiber = fiber.parent;
440
+ while (!domParentFiber.dom) {
441
+ domParentFiber = domParentFiber.parent;
442
+ }
443
+ const domParent = domParentFiber.dom;
444
+
445
+ if (fiber.effectTag === EFFECT_TAGS.PLACEMENT) {
446
+ if (fiber.dom != null) {
447
+ domParent.appendChild(fiber.dom);
448
+ }
449
+ runEffects(fiber);
450
+ } else if (fiber.effectTag === EFFECT_TAGS.UPDATE) {
451
+ cancelEffects(fiber);
452
+ if (fiber.dom != null) {
453
+ updateDom(fiber.dom, fiber.alternate.props, fiber.props);
454
+ }
455
+ runEffects(fiber);
456
+ } else if (fiber.effectTag === EFFECT_TAGS.DELETION) {
457
+ cancelEffects(fiber);
458
+ commitDeletion(fiber, domParent);
459
+ return;
460
+ }
461
+
462
+ commitWork(fiber.child);
463
+ commitWork(fiber.sibling);
464
+ };
465
+
466
+ /**
467
+ * The function removes a fiber's corresponding DOM node from its parent node or recursively removes
468
+ * its child's DOM node until it finds a node to remove.
469
+ * @param fiber - a fiber node in a fiber tree, which represents a component or an element in the Ryunix
470
+ * application.
471
+ * @param domParent - The parent DOM element from which the fiber's DOM element needs to be removed.
472
+ */
473
+ const commitDeletion = (fiber, domParent) => {
474
+ if (fiber.dom) {
475
+ domParent.removeChild(fiber.dom);
476
+ } else {
477
+ commitDeletion(fiber.child, domParent);
478
+ }
479
+ };
480
+
481
+ var Commits = /*#__PURE__*/Object.freeze({
482
+ __proto__: null,
483
+ commitDeletion: commitDeletion,
484
+ commitRoot: commitRoot,
485
+ commitWork: commitWork
486
+ });
487
+
488
+ /**
489
+ * This function reconciles the children of a fiber node with a new set of elements, creating new
490
+ * fibers for new elements, updating existing fibers for elements with the same type, and marking old
491
+ * fibers for deletion if they are not present in the new set of elements.
492
+ * @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
493
+ * DOM tree.
494
+ * @param elements - an array of elements representing the new children to be rendered in the current
495
+ * fiber's subtree
496
+ */
497
+ const reconcileChildren = (wipFiber, elements) => {
498
+ let index = 0;
499
+ let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
500
+ let prevSibling;
501
+
502
+ while (index < elements.length || oldFiber != null) {
503
+ const element = elements[index];
504
+ let newFiber;
505
+
506
+ const sameType = oldFiber && element && element.type == oldFiber.type;
507
+
508
+ if (sameType) {
509
+ newFiber = {
510
+ type: oldFiber.type,
511
+ props: element.props,
512
+ dom: oldFiber.dom,
513
+ parent: wipFiber,
514
+ alternate: oldFiber,
515
+ effectTag: EFFECT_TAGS.UPDATE,
516
+ };
517
+ }
518
+ if (element && !sameType) {
519
+ newFiber = {
520
+ type: element.type,
521
+ props: element.props,
522
+ dom: null,
523
+ parent: wipFiber,
524
+ alternate: null,
525
+ effectTag: EFFECT_TAGS.PLACEMENT,
526
+ };
527
+ }
528
+ if (oldFiber && !sameType) {
529
+ oldFiber.effectTag = EFFECT_TAGS.DELETION;
530
+ vars.deletions.push(oldFiber);
531
+ }
532
+
533
+ if (oldFiber) {
534
+ oldFiber = oldFiber.sibling;
535
+ }
536
+
537
+ if (index === 0) {
538
+ wipFiber.child = newFiber;
539
+ } else if (element) {
540
+ prevSibling.sibling = newFiber;
541
+ }
542
+
543
+ prevSibling = newFiber;
544
+ index++;
545
+ }
546
+ };
547
+
548
+ var Reconciler = /*#__PURE__*/Object.freeze({
549
+ __proto__: null,
550
+ reconcileChildren: reconcileChildren
551
+ });
552
+
553
+ /**
554
+ * This function updates a function component by setting up a work-in-progress fiber, resetting the
555
+ * hook index, creating an empty hooks array, rendering the component, and reconciling its children.
556
+ * @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
557
+ * contains information about the component, its props, state, and children. In this function, it is
558
+ * used to update the state of the component and its children.
559
+ */
560
+ const updateFunctionComponent = (fiber) => {
561
+ vars.wipFiber = fiber;
562
+ vars.hookIndex = 0;
563
+ vars.wipFiber.hooks = [];
564
+ const children = [fiber.type(fiber.props)];
565
+ reconcileChildren(fiber, children);
566
+ };
567
+
568
+ /**
569
+ * This function updates a host component's DOM element and reconciles its children.
570
+ * @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
571
+ * contains information about the component's type, props, and children, as well as pointers to other
572
+ * fibers in the tree.
573
+ */
574
+ const updateHostComponent = (fiber) => {
575
+ if (!fiber.dom) {
576
+ fiber.dom = createDom(fiber);
577
+ }
578
+ reconcileChildren(fiber, fiber.props.children.flat());
579
+ };
580
+
581
+ var Components = /*#__PURE__*/Object.freeze({
582
+ __proto__: null,
583
+ updateFunctionComponent: updateFunctionComponent,
584
+ updateHostComponent: updateHostComponent
585
+ });
586
+
587
+ /**
588
+ * This function uses requestIdleCallback to perform work on a fiber tree until it is complete or the
589
+ * browser needs to yield to other tasks.
590
+ * @param deadline - The `deadline` parameter is an object that represents the amount of time the
591
+ * browser has to perform work before it needs to handle other tasks. It has a `timeRemaining()` method
592
+ * that returns the amount of time remaining before the deadline is reached. The `shouldYield` variable
593
+ * is used to determine
594
+ */
595
+ const workLoop = (deadline) => {
596
+ let shouldYield = false;
597
+ while (vars.nextUnitOfWork && !shouldYield) {
598
+ vars.nextUnitOfWork = performUnitOfWork(vars.nextUnitOfWork);
599
+ shouldYield = deadline.timeRemaining() < 1;
600
+ }
601
+
602
+ if (!vars.nextUnitOfWork && vars.wipRoot) {
603
+ commitRoot();
604
+ }
605
+
606
+ requestIdleCallback(workLoop);
607
+ };
608
+
609
+ requestIdleCallback(workLoop);
610
+
611
+ /**
612
+ * The function performs a unit of work by updating either a function component or a host component and
613
+ * returns the next fiber to be processed.
614
+ * @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
615
+ * contains information about the component's type, props, and children, as well as pointers to its
616
+ * parent, child, and sibling fibers. The `performUnitOfWork` function takes a fiber as a parameter and
617
+ * performs work
618
+ * @returns The function `performUnitOfWork` returns the next fiber to be processed. If the current
619
+ * fiber has a child, it returns the child. Otherwise, it looks for the next sibling of the current
620
+ * fiber. If there are no more siblings, it goes up the tree to the parent and looks for the next
621
+ * sibling of the parent. The function returns `null` if there are no more fibers to process.
622
+ */
623
+ const performUnitOfWork = (fiber) => {
624
+ const isFunctionComponent = fiber.type instanceof Function;
625
+ if (isFunctionComponent) {
626
+ updateFunctionComponent(fiber);
627
+ } else {
628
+ updateHostComponent(fiber);
629
+ }
630
+ if (fiber.child) {
631
+ return fiber.child;
632
+ }
633
+ let nextFiber = fiber;
634
+ while (nextFiber) {
635
+ if (nextFiber.sibling) {
636
+ return nextFiber.sibling;
637
+ }
638
+ nextFiber = nextFiber.parent;
639
+ }
640
+ };
641
+
642
+ var Workers = /*#__PURE__*/Object.freeze({
643
+ __proto__: null,
644
+ performUnitOfWork: performUnitOfWork,
645
+ workLoop: workLoop
646
+ });
647
+
648
+ var Ryunix = {
649
+ createElement,
650
+ render,
651
+ init,
652
+ Fragments,
653
+ Dom,
654
+ Workers,
655
+ Reconciler,
656
+ Components,
657
+ Commits,
658
+ };
659
+
660
+ window.Ryunix = Ryunix;
661
+
662
+ exports.Fragments = Fragments;
663
+ exports.Navigate = Navigate;
664
+ exports.Router = Router;
665
+ exports.default = Ryunix;
666
+ exports.useEffect = useEffect;
667
+ exports.useQuery = useQuery;
668
+ exports.useStore = useStore;
669
+
670
+ Object.defineProperty(exports, '__esModule', { value: true });
671
+
672
+ }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,
package/src/lib/hooks.js CHANGED
@@ -1,31 +1,6 @@
1
1
  import { hasDepsChanged } from "./effects";
2
2
  import { RYUNIX_TYPES, STRINGS, vars } from "../utils/index";
3
3
 
4
- /**
5
- * The function `useContext` is used to read and subscribe to context from your component.
6
- * @param ref - The `ref` parameter is a reference to a context object.
7
- * @returns The `Value` property of the `hook` object is being returned.
8
- * @deprecated
9
- */
10
- const useContext = (ref) => {
11
- throw Error("useContext is bugged and will be removed");
12
- vars.hookIndex++;
13
-
14
- const oldHook =
15
- vars.wipFiber.alternate &&
16
- vars.wipFiber.alternate.hooks &&
17
- vars.wipFiber.alternate.hooks[vars.hookIndex];
18
-
19
- const hasOld = oldHook ? oldHook : undefined;
20
- const Context = hasOld ? hasOld : ref;
21
- const hook = {
22
- ...Context,
23
- };
24
-
25
- vars.wipFiber.hooks.push(hook);
26
-
27
- return hook.Value;
28
- };
29
4
 
30
5
  /**
31
6
  * @description The function creates a state.
@@ -124,4 +99,4 @@ const useQuery = () => {
124
99
  return hook.query;
125
100
  };
126
101
 
127
- export { useContext, useStore, useEffect, useQuery };
102
+ export { useStore, useEffect, useQuery };
package/src/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { createElement, Fragments } from "./createElement";
2
2
  import { render, init } from "./render";
3
- import { useContext, useStore, useEffect, useQuery } from "./hooks";
4
- import { createContext } from "./createContext";
3
+ import { useStore, useEffect, useQuery } from "./hooks";
5
4
  import { Router, Navigate } from "./navigation";
6
5
  import * as Dom from "./dom";
7
6
  import * as Workers from "./workers";
@@ -9,16 +8,7 @@ import * as Reconciler from "./reconciler";
9
8
  import * as Components from "./components";
10
9
  import * as Commits from "./commits";
11
10
 
12
- export {
13
- useStore,
14
- useEffect,
15
- useQuery,
16
- createContext,
17
- useContext,
18
- Fragments,
19
- Router,
20
- Navigate,
21
- };
11
+ export { useStore, useEffect, useQuery, Fragments, Router, Navigate };
22
12
 
23
13
  export default {
24
14
  createElement,
package/src/main.js CHANGED
@@ -2,9 +2,7 @@ import Ryunix from "./lib/index.js";
2
2
  export {
3
3
  useStore,
4
4
  useEffect,
5
- createContext,
6
5
  useQuery,
7
- useContext,
8
6
  Fragments,
9
7
  Navigate,
10
8
  Router,
@@ -1,26 +0,0 @@
1
- import { RYUNIX_TYPES } from "../utils/index";
2
-
3
- /**
4
- * The function createContext creates a context object with a default value and methods to set and get
5
- * the context value.
6
- * @param defaultValue - The `defaultValue` parameter is the initial value that will be assigned to the
7
- * `contextValue` variable if no value is provided when creating the context.
8
- * @returns a context object.
9
- * @deprecated
10
- */
11
- const createContext = (defaultValue) => {
12
- throw Error("createContext is bugged and will be removed");
13
- let contextValue = defaultValue || null;
14
-
15
- const context = {
16
- tag: RYUNIX_TYPES.RYUNIX_CONTEXT,
17
- Value: contextValue,
18
- Provider(props) {
19
- this.Value = props.value;
20
- },
21
- };
22
-
23
- return context;
24
- };
25
-
26
- export { createContext };