@unsetsoft/ryunixjs 0.2.12 → 0.2.14-nightly.0

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/.babelrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "presets": ["@babel/preset-env"],
3
+ "plugins": [
4
+ [
5
+ "@babel/plugin-transform-react-jsx",
6
+ {
7
+ "pragma": "Ryunix.createElement"
8
+ }
9
+ ]
10
+ ]
11
+ }
package/README.md CHANGED
@@ -1,20 +1,29 @@
1
1
  # RyunixJS
2
2
 
3
+ [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FUnSetSoft%2FRyunixjs%2Ftree%2Fmaster%2Fvercel%2Fryunix-jsx&project-name=ryunix-jsx-project&repository-name=ryunix-jsx-project)
4
+
5
+
3
6
  ## What is RyunixJS?
4
7
 
5
8
  Is a ReactJS Clone! Even lighter, however, at a very early stage for production use.
6
9
 
7
- ## Install & Usage
10
+ ## Usage
8
11
 
9
- `npm install @unsetsoft/create-ryunix-app -g`
12
+ `npx @unsetsoft/create-ryunix-app get`
10
13
 
11
- ### Obtain and download the template
14
+ ### Rename your final folder
12
15
 
13
- `create-ryunix-app get`
16
+ `npx @unsetsoft/create-ryunix-app get --dirname awasome-ryunix-app`
14
17
 
15
- ### Rename your final folder
18
+ ### Templates
19
+
20
+ `npx @unsetsoft/create-ryunix-app get --template ryunix-jsx`
21
+
22
+ Supported templates [ryunix-js|ryunix-jsx|ryunix-ryx]
23
+
24
+ ### Branch (Not recomended and only works with create-ryunix-app 1.0.1)
16
25
 
17
- `create-ryunix-app get --dirname awasome-ryunix-app`
26
+ `npx @unsetsoft/create-ryunix-app get --branch <github branch>`
18
27
 
19
28
  ## Bugs?
20
29
 
@@ -22,4 +31,4 @@ You can create an issue on GitHub.
22
31
 
23
32
  ## Do you want to contribute?
24
33
 
25
- Fork a send a pull request!
34
+ Fork a send a pull request!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.2.12",
3
+ "version": "0.2.14-nightly.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,
@@ -10,7 +10,8 @@
10
10
  "homepage": "https://github.com/UnSetSoft/Ryunixjs#readme",
11
11
  "scripts": {
12
12
  "build": "rollup ./lib/main.js --file ./dist/Ryunix.js --format umd --name Ryunix",
13
- "postinstall": "yarn build"
13
+ "cp:build": "babel lib/components --out-dir ./dist/components --copy-files",
14
+ "postinstall": "yarn build && yarn cp:build"
14
15
  },
15
16
  "bin": {
16
17
  "ryunix": "./bin/index.js"
@@ -21,7 +22,9 @@
21
22
  "url-loader": "^4.1.1",
22
23
  "rollup": "3.24.0",
23
24
  "yargs": "^17.7.2",
25
+ "@babel/cli": "7.19.3",
24
26
  "@babel/core": "^7.22.11",
27
+ "@babel/polyfill": "7.12.1",
25
28
  "@babel/plugin-proposal-class-properties": "^7.18.6",
26
29
  "@babel/plugin-transform-react-jsx": "^7.22.5",
27
30
  "@babel/preset-env": "^7.22.14",
@@ -42,4 +45,4 @@
42
45
  "engines": {
43
46
  "node": ">=18.16.0"
44
47
  }
45
- }
48
+ }
package/lib/dom.js DELETED
@@ -1,525 +0,0 @@
1
- /**
2
- * The function creates a new element with the given type, props, and children.
3
- * @param type - The type of the element to be created, such as "div", "span", "h1", etc.
4
- * @param props - The `props` parameter is an object that contains the properties or attributes of the
5
- * element being created. These properties can include things like `className`, `id`, `style`, and any
6
- * other custom attributes that the user wants to add to the element. The `props` object is spread
7
- * using the spread
8
- * @param children - The `children` parameter is a rest parameter that allows the function to accept
9
- * any number of arguments after the `props` parameter. These arguments will be treated as children
10
- * elements of the created element. The `map` function is used to iterate over each child and create a
11
- * new element if it is not
12
- * @returns A JavaScript object with a `type` property and a `props` property. The `type` property is
13
- * set to the `type` argument passed into the function, and the `props` property is an object that
14
- * includes any additional properties passed in the `props` argument, as well as a `children` property
15
- * that is an array of any child elements passed in the `...children` argument
16
- */
17
- function createElement(type, props, ...children) {
18
- return {
19
- type,
20
- props: {
21
- ...props,
22
- children: children
23
- .flat()
24
- .map((child) =>
25
- typeof child === "object" ? child : createTextElement(child)
26
- ),
27
- },
28
- };
29
- }
30
-
31
- /**
32
- * The function creates a text element with a given text value.
33
- * @param text - The text content that will be used to create a new text element.
34
- * @returns A JavaScript object with a `type` property set to `"TEXT_ELEMENT"` and a `props` property
35
- * that contains a `nodeValue` property set to the `text` parameter and an empty `children` array.
36
- */
37
- function createTextElement(text) {
38
- return {
39
- type: "TEXT_ELEMENT",
40
- props: {
41
- nodeValue: text,
42
- children: [],
43
- },
44
- };
45
- }
46
-
47
- /**
48
- * The function creates a new DOM element based on the given fiber object and updates its properties.
49
- * @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
50
- * contains information about the element type, props, and children of the node.
51
- * @returns The `createDom` function returns a newly created DOM element based on the `fiber` object
52
- * passed as an argument. If the `fiber` object represents a text element, a text node is created using
53
- * `document.createTextNode("")`. Otherwise, a new element is created using
54
- * `document.createElement(fiber.type)`. The function then calls the `updateDom` function to update the
55
- * properties of the newly created
56
- */
57
- function createDom(fiber) {
58
- const dom =
59
- fiber.type == "TEXT_ELEMENT"
60
- ? document.createTextNode("")
61
- : document.createElement(fiber.type);
62
-
63
- updateDom(dom, {}, fiber.props);
64
-
65
- return dom;
66
- }
67
-
68
- const isEvent = (key) => key.startsWith("on");
69
- const isProperty = (key) => key !== "children" && !isEvent(key);
70
- const isNew = (prev, next) => (key) => prev[key] !== next[key];
71
- const isGone = (next) => (key) => !(key in next);
72
-
73
- /**
74
- * The function updates the DOM by removing old event listeners and properties, and adding new ones
75
- * based on the previous and next props.
76
- * @param dom - The DOM element that needs to be updated with new props.
77
- * @param prevProps - An object representing the previous props (properties) of a DOM element.
78
- * @param nextProps - An object containing the new props that need to be updated in the DOM.
79
- */
80
- function updateDom(dom, prevProps, nextProps) {
81
- Object.keys(prevProps)
82
- .filter(isEvent)
83
- .filter((key) => isGone(nextProps)(key) || isNew(prevProps, nextProps)(key))
84
- .forEach((name) => {
85
- const eventType = name.toLowerCase().substring(2);
86
- dom.removeEventListener(eventType, prevProps[name]);
87
- });
88
-
89
- Object.keys(prevProps)
90
- .filter(isProperty)
91
- .filter(isGone(nextProps))
92
- .forEach((name) => {
93
- dom[name] = "";
94
- });
95
-
96
- Object.keys(nextProps)
97
- .filter(isProperty)
98
- .filter(isNew(prevProps, nextProps))
99
- .forEach((name) => {
100
- if (name === "style") {
101
- DomStyle(dom, nextProps.style);
102
- } else if (name === "className") {
103
- prevProps.className &&
104
- dom.classList.remove(...prevProps.className.split(/\s+/));
105
- dom.classList.add(...nextProps.className.split(/\s+/));
106
- } else {
107
- dom[name] = nextProps[name];
108
- }
109
- });
110
-
111
- Object.keys(nextProps)
112
- .filter(isEvent)
113
- .filter(isNew(prevProps, nextProps))
114
- .forEach((name) => {
115
- const eventType = name.toLowerCase().substring(2);
116
- dom.addEventListener(eventType, nextProps[name]);
117
- });
118
- }
119
-
120
- const reg = /[A-Z]/g;
121
- function DomStyle(dom, style) {
122
- dom.style = Object.keys(style).reduce((acc, styleName) => {
123
- const key = styleName.replace(reg, function (v) {
124
- return "-" + v.toLowerCase();
125
- });
126
- acc += `${key}: ${style[styleName]};`;
127
- return acc;
128
- }, "");
129
- }
130
-
131
-
132
- /**
133
- * The function commits changes made to the virtual DOM to the actual DOM.
134
- */
135
- function commitRoot() {
136
- deletions.forEach(commitWork);
137
- commitWork(wipRoot.child);
138
- currentRoot = wipRoot;
139
- wipRoot = null;
140
- }
141
-
142
- /**
143
- * The function cancels all effect hooks in a given fiber.
144
- * @param fiber - The "fiber" parameter is likely referring to a data structure used in React.js to
145
- * represent a component and its state. It contains information about the component's props, state, and
146
- * children, as well as metadata used by React to manage updates and rendering. The function
147
- * "cancelEffects" is likely intended
148
- */
149
- function cancelEffects(fiber) {
150
- if (fiber.hooks) {
151
- fiber.hooks
152
- .filter((hook) => hook.tag === "effect" && hook.cancel)
153
- .forEach((effectHook) => {
154
- effectHook.cancel();
155
- });
156
- }
157
- }
158
-
159
- /**
160
- * The function runs all effect hooks in a given fiber.
161
- * @param fiber - The "fiber" parameter is likely referring to a data structure used in the
162
- * implementation of a fiber-based reconciliation algorithm, such as the one used in React. A fiber
163
- * represents a unit of work that needs to be performed by the reconciliation algorithm, and it
164
- * contains information about a component and its children, as
165
- */
166
- function runEffects(fiber) {
167
- if (fiber.hooks) {
168
- fiber.hooks
169
- .filter((hook) => hook.tag === "effect" && hook.effect)
170
- .forEach((effectHook) => {
171
- effectHook.cancel = effectHook.effect();
172
- });
173
- }
174
- }
175
-
176
- /**
177
- * The function commits changes made to the DOM based on the effect tag of the fiber.
178
- * @param fiber - A fiber is a unit of work in Ryunix's reconciliation process. It represents a
179
- * component and its state at a particular point in time. The `commitWork` function takes a fiber as a
180
- * parameter to commit the changes made during the reconciliation process to the actual DOM.
181
- * @returns The function does not return anything, it performs side effects by manipulating the DOM.
182
- */
183
- function commitWork(fiber) {
184
- if (!fiber) {
185
- return;
186
- }
187
-
188
- let domParentFiber = fiber.parent;
189
- while (!domParentFiber.dom) {
190
- domParentFiber = domParentFiber.parent;
191
- }
192
- const domParent = domParentFiber.dom;
193
-
194
- if (fiber.effectTag === "PLACEMENT") {
195
- if (fiber.dom != null) {
196
- domParent.appendChild(fiber.dom);
197
- }
198
- runEffects(fiber);
199
- } else if (fiber.effectTag === "UPDATE") {
200
- cancelEffects(fiber);
201
- if (fiber.dom != null) {
202
- updateDom(fiber.dom, fiber.alternate.props, fiber.props);
203
- }
204
- runEffects(fiber);
205
- } else if (fiber.effectTag === "DELETION") {
206
- cancelEffects(fiber);
207
- commitDeletion(fiber, domParent);
208
- return;
209
- }
210
-
211
- commitWork(fiber.child);
212
- commitWork(fiber.sibling);
213
- }
214
-
215
- /**
216
- * The function removes a fiber's corresponding DOM node from its parent node or recursively removes
217
- * its child's DOM node until it finds a node to remove.
218
- * @param fiber - a fiber node in a fiber tree, which represents a component or an element in the Ryunix
219
- * application.
220
- * @param domParent - The parent DOM element from which the fiber's DOM element needs to be removed.
221
- */
222
- function commitDeletion(fiber, domParent) {
223
- if (fiber.dom) {
224
- domParent.removeChild(fiber.dom);
225
- } else {
226
- commitDeletion(fiber.child, domParent);
227
- }
228
- }
229
-
230
- let containerRoot = null;
231
-
232
- /**
233
- * @deprecated use Ryunix.init(root) instead.
234
- *
235
- * @description The function creates a root container for a web application.
236
- * @example Ryunix.createRoot(document.getElementById("root")) -> <div id="root" />
237
- * @param root - The parameter `root` is likely referring to an HTML element that will serve as the
238
- * root or container for a web application or component. The `createRoot` function takes this element
239
- * as an argument and assigns it to a variable called `containerRoot`. This variable can then be used
240
- * to manipulate the contents
241
- *
242
- */
243
- function createRoot(root) {
244
- containerRoot = root;
245
- }
246
-
247
-
248
- /**
249
- * @description The function creates a reference to a DOM element with the specified ID. This will be used to initialize the app.
250
- * @example Ryunix.init("root") -> <div id="root" />
251
- * @param root - The parameter "root" is the id of the HTML element that will serve as the container
252
- * for the root element.
253
- */
254
- function init(root) {
255
- containerRoot = document.getElementById(root);
256
- }
257
-
258
- /**
259
- * The function renders an element into a container using a work-in-progress root.
260
- * @param element - The element parameter is the component or element that needs to be rendered in the
261
- * container. It could be a Ryunix component or a DOM element.
262
- * @param container - The container parameter is the DOM element where the rendered element will be
263
- * appended to. this parameter is optional if you use createRoot().
264
- */
265
- function render(element, container) {
266
- wipRoot = {
267
- dom: containerRoot || container,
268
- props: {
269
- children: [element],
270
- },
271
- alternate: currentRoot,
272
- };
273
- deletions = [];
274
- nextUnitOfWork = wipRoot;
275
- }
276
-
277
- let nextUnitOfWork = null;
278
- let currentRoot = null;
279
- let wipRoot = null;
280
- let deletions = null;
281
-
282
- /**
283
- * This function uses requestIdleCallback to perform work on a fiber tree until it is complete or the
284
- * browser needs to yield to other tasks.
285
- * @param deadline - The `deadline` parameter is an object that represents the amount of time the
286
- * browser has to perform work before it needs to handle other tasks. It has a `timeRemaining()` method
287
- * that returns the amount of time remaining before the deadline is reached. The `shouldYield` variable
288
- * is used to determine
289
- */
290
- function workLoop(deadline) {
291
- let shouldYield = false;
292
- while (nextUnitOfWork && !shouldYield) {
293
- nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
294
- shouldYield = deadline.timeRemaining() < 1;
295
- }
296
-
297
- if (!nextUnitOfWork && wipRoot) {
298
- commitRoot();
299
- }
300
-
301
- requestIdleCallback(workLoop);
302
- }
303
-
304
- requestIdleCallback(workLoop);
305
-
306
- /**
307
- * The function performs a unit of work by updating either a function component or a host component and
308
- * returns the next fiber to be processed.
309
- * @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
310
- * contains information about the component's type, props, and children, as well as pointers to its
311
- * parent, child, and sibling fibers. The `performUnitOfWork` function takes a fiber as a parameter and
312
- * performs work
313
- * @returns The function `performUnitOfWork` returns the next fiber to be processed. If the current
314
- * fiber has a child, it returns the child. Otherwise, it looks for the next sibling of the current
315
- * fiber. If there are no more siblings, it goes up the tree to the parent and looks for the next
316
- * sibling of the parent. The function returns `null` if there are no more fibers to process.
317
- */
318
- function performUnitOfWork(fiber) {
319
- const isFunctionComponent = fiber.type instanceof Function;
320
- if (isFunctionComponent) {
321
- updateFunctionComponent(fiber);
322
- } else {
323
- updateHostComponent(fiber);
324
- }
325
- if (fiber.child) {
326
- return fiber.child;
327
- }
328
- let nextFiber = fiber;
329
- while (nextFiber) {
330
- if (nextFiber.sibling) {
331
- return nextFiber.sibling;
332
- }
333
- nextFiber = nextFiber.parent;
334
- }
335
- }
336
-
337
- let wipFiber = null;
338
- let hookIndex = null;
339
-
340
- /**
341
- * This function updates a function component by setting up a work-in-progress fiber, resetting the
342
- * hook index, creating an empty hooks array, rendering the component, and reconciling its children.
343
- * @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
344
- * contains information about the component, its props, state, and children. In this function, it is
345
- * used to update the state of the component and its children.
346
- */
347
- function updateFunctionComponent(fiber) {
348
- wipFiber = fiber;
349
- hookIndex = 0;
350
- wipFiber.hooks = [];
351
- const children = [fiber.type(fiber.props)];
352
- reconcileChildren(fiber, children);
353
- }
354
-
355
- /**
356
- * This function updates a host component's DOM element and reconciles its children.
357
- * @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
358
- * contains information about the component's type, props, and children, as well as pointers to other
359
- * fibers in the tree.
360
- */
361
- function updateHostComponent(fiber) {
362
- if (!fiber.dom) {
363
- fiber.dom = createDom(fiber);
364
- }
365
- reconcileChildren(fiber, fiber.props.children.flat());
366
- }
367
-
368
- /**
369
- * This function reconciles the children of a fiber node with a new set of elements, creating new
370
- * fibers for new elements, updating existing fibers for elements with the same type, and marking old
371
- * fibers for deletion if they are not present in the new set of elements.
372
- * @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
373
- * DOM tree.
374
- * @param elements - an array of elements representing the new children to be rendered in the current
375
- * fiber's subtree
376
- */
377
- function reconcileChildren(wipFiber, elements) {
378
- let index = 0;
379
- let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
380
- let prevSibling = null;
381
-
382
- while (index < elements.length || oldFiber != null) {
383
- const element = elements[index];
384
- let newFiber = null;
385
-
386
- const sameType = oldFiber && element && element.type == oldFiber.type;
387
-
388
- if (sameType) {
389
- newFiber = {
390
- type: oldFiber.type,
391
- props: element.props,
392
- dom: oldFiber.dom,
393
- parent: wipFiber,
394
- alternate: oldFiber,
395
- effectTag: "UPDATE",
396
- };
397
- }
398
- if (element && !sameType) {
399
- newFiber = {
400
- type: element.type,
401
- props: element.props,
402
- dom: null,
403
- parent: wipFiber,
404
- alternate: null,
405
- effectTag: "PLACEMENT",
406
- };
407
- }
408
- if (oldFiber && !sameType) {
409
- oldFiber.effectTag = "DELETION";
410
- deletions.push(oldFiber);
411
- }
412
-
413
- if (oldFiber) {
414
- oldFiber = oldFiber.sibling;
415
- }
416
-
417
- if (index === 0) {
418
- wipFiber.child = newFiber;
419
- } else if (element) {
420
- prevSibling.sibling = newFiber;
421
- }
422
-
423
- prevSibling = newFiber;
424
- index++;
425
- }
426
- }
427
-
428
- // Hooks
429
-
430
- /**
431
- * @description The function creates a state.
432
- * @param initial - The initial value of the state for the hook.
433
- * @returns The `useStore` function returns an array with two elements: the current state value and a
434
- * `setState` function that can be used to update the state.
435
- */
436
- function useStore(initial) {
437
- const oldHook =
438
- wipFiber.alternate &&
439
- wipFiber.alternate.hooks &&
440
- wipFiber.alternate.hooks[hookIndex];
441
- const hook = {
442
- state: oldHook ? oldHook.state : initial,
443
- queue: [],
444
- };
445
-
446
- const actions = oldHook ? oldHook.queue : [];
447
- actions.forEach((action) => {
448
- hook.state = typeof action === "function" ? action(hook.state) : action;
449
- });
450
-
451
- /**
452
- * The function `setState` updates the state of a component in Ryunix by adding an action to a queue
453
- * and setting up a new work-in-progress root.
454
- * @param action - The `action` parameter is an object that represents a state update to be performed
455
- * on a component. It contains information about the type of update to be performed and any new data
456
- * that needs to be applied to the component's state.
457
- */
458
- const setState = (action) => {
459
- hook.queue.push(action);
460
- wipRoot = {
461
- dom: currentRoot.dom,
462
- props: currentRoot.props,
463
- alternate: currentRoot,
464
- };
465
- nextUnitOfWork = wipRoot;
466
- deletions = [];
467
- };
468
-
469
- wipFiber.hooks.push(hook);
470
- hookIndex++;
471
- return [hook.state, setState];
472
- }
473
-
474
- /**
475
- * The function checks if the previous dependencies are different from the next dependencies.
476
- * @param prevDeps - The previous dependencies, which could be an array of values or objects that a
477
- * function or component depends on.
478
- * @param nextDeps - `nextDeps` is an array of dependencies that are being checked for changes. These
479
- * dependencies are typically used in React's `useEffect` and `useCallback` hooks to determine when a
480
- * component should re-render or when a function should be re-created.
481
- */
482
- const hasDepsChanged = (prevDeps, nextDeps) =>
483
- !prevDeps ||
484
- !nextDeps ||
485
- prevDeps.length !== nextDeps.length ||
486
- prevDeps.some((dep, index) => dep !== nextDeps[index]);
487
-
488
- /**
489
- * This is a function that creates a hook for managing side effects in Ryunix components.
490
- * @param effect - The effect function that will be executed after the component has rendered or when
491
- * the dependencies have changed. It can perform side effects such as fetching data, updating the DOM,
492
- * or subscribing to events.
493
- * @param deps - An array of dependencies that the effect depends on. If any of the dependencies change
494
- * between renders, the effect will be re-run. If the array is empty, the effect will only run once on
495
- * mount and never again.
496
- */
497
- function useEffect(effect, deps) {
498
- const oldHook =
499
- wipFiber.alternate &&
500
- wipFiber.alternate.hooks &&
501
- wipFiber.alternate.hooks[hookIndex];
502
-
503
- const hasChanged = hasDepsChanged(oldHook ? oldHook.deps : undefined, deps);
504
-
505
- const hook = {
506
- tag: "effect",
507
- effect: hasChanged ? effect : null,
508
- cancel: hasChanged && oldHook && oldHook.cancel,
509
- deps,
510
- };
511
-
512
- wipFiber.hooks.push(hook);
513
- hookIndex++;
514
- }
515
-
516
- // export
517
-
518
- export { useStore, useEffect };
519
-
520
- export default {
521
- createElement,
522
- render,
523
- createRoot,
524
- init,
525
- };
package/lib/main.js DELETED
@@ -1,7 +0,0 @@
1
- import Ryunix from "./dom";
2
-
3
- export { useStore, useEffect } from "./dom";
4
-
5
- window.Ryunix = Ryunix;
6
-
7
- export default Ryunix;