@unsetsoft/ryunixjs 1.1.6-canary.99 → 1.1.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/README.md +2 -35
- package/dist/Ryunix.js +205 -251
- package/dist/Ryunix.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
display: block;
|
|
3
3
|
margin: 0 auto;" />
|
|
4
4
|
|
|
5
|
-
## RyunixJS [](https://www.npmjs.com/package/@unsetsoft/ryunixjs)[](https://www.npmjs.com/package/@unsetsoft/ryunixjs)[](https://www.npmjs.com/package/@unsetsoft/ryunixjs/v/canary)
|
|
6
6
|
|
|
7
7
|
### What is RyunixJS?
|
|
8
8
|
|
|
@@ -10,41 +10,8 @@ Like React, NextJS, Preact, Vite. Ryunix allows you to build static websites fro
|
|
|
10
10
|
|
|
11
11
|
### Usage
|
|
12
12
|
|
|
13
|
-
`npx @unsetsoft/cra@latest
|
|
13
|
+
`npx @unsetsoft/cra@latest <my-app>`
|
|
14
14
|
|
|
15
15
|
### Do you want to contribute?
|
|
16
16
|
|
|
17
17
|
Fork a send a pull request!
|
|
18
|
-
|
|
19
|
-
[](https://cafecito.app/neyunse) [](https://ko-fi.com/A1314KEV)
|
|
20
|
-
|
|
21
|
-
# Ryunix Framework
|
|
22
|
-
|
|
23
|
-
## Funcionalidades principales
|
|
24
|
-
|
|
25
|
-
### Suspense y Lazy Loading
|
|
26
|
-
|
|
27
|
-
- **Suspense**: Permite manejar componentes cargados de forma diferida y mostrar un fallback mientras se cargan.
|
|
28
|
-
- **Lazy**: Carga componentes de forma diferida.
|
|
29
|
-
|
|
30
|
-
### Context API
|
|
31
|
-
|
|
32
|
-
- **createContext**: Crea un contexto para compartir datos entre componentes.
|
|
33
|
-
- **useContext**: Consume el contexto en un componente.
|
|
34
|
-
|
|
35
|
-
### Error Boundaries
|
|
36
|
-
|
|
37
|
-
- Captura errores en componentes hijos y muestra interfaces de error personalizadas.
|
|
38
|
-
|
|
39
|
-
### Portals
|
|
40
|
-
|
|
41
|
-
- Renderiza componentes fuera del árbol DOM principal.
|
|
42
|
-
|
|
43
|
-
## Optimización
|
|
44
|
-
|
|
45
|
-
- Mejoras en el reconciliador y hooks para reducir el uso de memoria y evitar renderizados innecesarios.
|
|
46
|
-
|
|
47
|
-
## Próximos pasos
|
|
48
|
-
|
|
49
|
-
- Ampliar compatibilidad y herramientas.
|
|
50
|
-
- Mejorar el ecosistema con CLI y DevTools.
|
package/dist/Ryunix.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
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
|
-
containerRoot:
|
|
9
|
-
nextUnitOfWork:
|
|
10
|
-
currentRoot:
|
|
11
|
-
wipRoot:
|
|
12
|
-
deletions:
|
|
13
|
-
wipFiber:
|
|
14
|
-
hookIndex:
|
|
8
|
+
containerRoot: null,
|
|
9
|
+
nextUnitOfWork: null,
|
|
10
|
+
currentRoot: null,
|
|
11
|
+
wipRoot: null,
|
|
12
|
+
deletions: null,
|
|
13
|
+
wipFiber: null,
|
|
14
|
+
hookIndex: null,
|
|
15
|
+
effects: null,
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
const reg = /[A-Z]/g;
|
|
@@ -86,14 +87,6 @@
|
|
|
86
87
|
*/
|
|
87
88
|
|
|
88
89
|
const createElement = (type, props, ...children) => {
|
|
89
|
-
// Validación: Asegurar que type y props sean válidos
|
|
90
|
-
if (typeof type !== 'string' && typeof type !== 'function') {
|
|
91
|
-
throw new Error("El parámetro 'type' debe ser una cadena o una función.")
|
|
92
|
-
}
|
|
93
|
-
if (props && typeof props !== 'object') {
|
|
94
|
-
throw new Error("El parámetro 'props' debe ser un objeto.")
|
|
95
|
-
}
|
|
96
|
-
|
|
97
90
|
children = childArray(children, []);
|
|
98
91
|
const key =
|
|
99
92
|
props && props.key
|
|
@@ -197,15 +190,9 @@
|
|
|
197
190
|
* @param nextProps - An object containing the new props that need to be updated in the DOM.
|
|
198
191
|
*/
|
|
199
192
|
const updateDom = (dom, prevProps, nextProps) => {
|
|
200
|
-
if (!nextProps) nextProps = {}; // Validar que nextProps no sea null o undefined
|
|
201
|
-
|
|
202
|
-
// Optimización: Combinar filtros para mejorar el rendimiento
|
|
203
193
|
Object.keys(prevProps)
|
|
204
|
-
.filter(
|
|
205
|
-
|
|
206
|
-
isEvent(key) &&
|
|
207
|
-
(isGone(nextProps)(key) || isNew(prevProps, nextProps)(key)),
|
|
208
|
-
)
|
|
194
|
+
.filter(isEvent)
|
|
195
|
+
.filter((key) => isGone(nextProps)(key) || isNew(prevProps, nextProps)(key))
|
|
209
196
|
.forEach((name) => {
|
|
210
197
|
const eventType = name.toLowerCase().substring(2);
|
|
211
198
|
dom.removeEventListener(eventType, prevProps[name]);
|
|
@@ -266,24 +253,6 @@
|
|
|
266
253
|
}, '');
|
|
267
254
|
};
|
|
268
255
|
|
|
269
|
-
// Implementación inicial de Portals
|
|
270
|
-
const createPortal = (children, container) => {
|
|
271
|
-
container.innerHTML = '';
|
|
272
|
-
children.forEach((child) => {
|
|
273
|
-
const domNode = createDom(child);
|
|
274
|
-
container.appendChild(domNode);
|
|
275
|
-
});
|
|
276
|
-
return container
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
var Dom = /*#__PURE__*/Object.freeze({
|
|
280
|
-
__proto__: null,
|
|
281
|
-
DomStyle: DomStyle,
|
|
282
|
-
createDom: createDom,
|
|
283
|
-
createPortal: createPortal,
|
|
284
|
-
updateDom: updateDom
|
|
285
|
-
});
|
|
286
|
-
|
|
287
256
|
/**
|
|
288
257
|
* The function commits changes made to the virtual DOM to the actual DOM.
|
|
289
258
|
*/
|
|
@@ -293,7 +262,15 @@
|
|
|
293
262
|
commitWork(vars.wipRoot.child);
|
|
294
263
|
vars.currentRoot = vars.wipRoot;
|
|
295
264
|
}
|
|
296
|
-
vars.
|
|
265
|
+
vars.effects.forEach((effect) => {
|
|
266
|
+
try {
|
|
267
|
+
effect();
|
|
268
|
+
} catch (err) {
|
|
269
|
+
console.error('Error in effect:', err);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
vars.effects = [];
|
|
273
|
+
vars.wipRoot = null;
|
|
297
274
|
};
|
|
298
275
|
|
|
299
276
|
/**
|
|
@@ -312,11 +289,10 @@
|
|
|
312
289
|
}
|
|
313
290
|
const domParent = domParentFiber.dom;
|
|
314
291
|
|
|
315
|
-
|
|
316
|
-
if (fiber.dom && fiber.effectTag === EFFECT_TAGS.PLACEMENT) {
|
|
292
|
+
if (fiber.effectTag === EFFECT_TAGS.PLACEMENT && fiber.dom != null) {
|
|
317
293
|
domParent.appendChild(fiber.dom);
|
|
318
294
|
runEffects(fiber);
|
|
319
|
-
} else if (fiber.
|
|
295
|
+
} else if (fiber.effectTag === EFFECT_TAGS.UPDATE && fiber.dom != null) {
|
|
320
296
|
cancelEffects(fiber);
|
|
321
297
|
updateDom(fiber.dom, fiber.alternate.props, fiber.props);
|
|
322
298
|
runEffects(fiber);
|
|
@@ -346,13 +322,6 @@
|
|
|
346
322
|
}
|
|
347
323
|
};
|
|
348
324
|
|
|
349
|
-
var Commits = /*#__PURE__*/Object.freeze({
|
|
350
|
-
__proto__: null,
|
|
351
|
-
commitDeletion: commitDeletion,
|
|
352
|
-
commitRoot: commitRoot,
|
|
353
|
-
commitWork: commitWork
|
|
354
|
-
});
|
|
355
|
-
|
|
356
325
|
/**
|
|
357
326
|
* This function reconciles the children of a fiber node with a new set of elements, creating new
|
|
358
327
|
* fibers for new elements, updating existing fibers for elements with the same type, and marking old
|
|
@@ -362,12 +331,26 @@
|
|
|
362
331
|
* @param elements - an array of elements representing the new children to be rendered in the current
|
|
363
332
|
* fiber's subtree
|
|
364
333
|
*/
|
|
365
|
-
const
|
|
366
|
-
//
|
|
367
|
-
|
|
368
|
-
|
|
334
|
+
const shouldComponentUpdate = (oldProps, newProps) => {
|
|
335
|
+
// Comparar las propiedades antiguas y nuevas
|
|
336
|
+
return (
|
|
337
|
+
!oldProps ||
|
|
338
|
+
!newProps ||
|
|
339
|
+
Object.keys(oldProps).length !== Object.keys(newProps).length ||
|
|
340
|
+
Object.keys(newProps).some((key) => oldProps[key] !== newProps[key])
|
|
341
|
+
)
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const recycleFiber = (oldFiber, newProps) => {
|
|
345
|
+
return {
|
|
346
|
+
...oldFiber,
|
|
347
|
+
props: newProps,
|
|
348
|
+
alternate: oldFiber,
|
|
349
|
+
effectTag: EFFECT_TAGS.UPDATE,
|
|
369
350
|
}
|
|
351
|
+
};
|
|
370
352
|
|
|
353
|
+
const reconcileChildren = (wipFiber, elements) => {
|
|
371
354
|
let index = 0;
|
|
372
355
|
let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
|
|
373
356
|
let prevSibling = null;
|
|
@@ -379,43 +362,36 @@
|
|
|
379
362
|
oldFiber = oldFiber.sibling;
|
|
380
363
|
}
|
|
381
364
|
|
|
382
|
-
// Refactorización: Reducir redundancia en la creación de newFiber
|
|
383
|
-
const createFiber = (type, props, dom, parent, alternate, effectTag) => ({
|
|
384
|
-
type,
|
|
385
|
-
props,
|
|
386
|
-
dom,
|
|
387
|
-
parent,
|
|
388
|
-
alternate,
|
|
389
|
-
effectTag,
|
|
390
|
-
});
|
|
391
|
-
|
|
392
365
|
while (index < elements.length) {
|
|
393
366
|
const element = elements[index];
|
|
394
|
-
const key = element.props
|
|
367
|
+
const key = element.props.key || element.type;
|
|
395
368
|
const oldFiber = oldFibersMap.get(key);
|
|
396
369
|
|
|
397
370
|
let newFiber;
|
|
398
371
|
const sameType = oldFiber && element && element.type === oldFiber.type;
|
|
399
372
|
|
|
400
|
-
if (sameType) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
element.props,
|
|
404
|
-
oldFiber.dom,
|
|
405
|
-
wipFiber,
|
|
406
|
-
oldFiber,
|
|
407
|
-
EFFECT_TAGS.UPDATE,
|
|
408
|
-
);
|
|
373
|
+
if (sameType && !shouldComponentUpdate(oldFiber.props, element.props)) {
|
|
374
|
+
// Reutilizar fibra existente si no hay cambios
|
|
375
|
+
newFiber = recycleFiber(oldFiber, element.props);
|
|
409
376
|
oldFibersMap.delete(key);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (element && !sameType) {
|
|
380
|
+
// Crear nueva fibra
|
|
381
|
+
newFiber = {
|
|
382
|
+
type: element.type,
|
|
383
|
+
props: element.props,
|
|
384
|
+
dom: null,
|
|
385
|
+
parent: wipFiber,
|
|
386
|
+
alternate: null,
|
|
387
|
+
effectTag: EFFECT_TAGS.PLACEMENT,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (oldFiber && !sameType) {
|
|
392
|
+
oldFiber.effectTag = EFFECT_TAGS.DELETION;
|
|
393
|
+
wipFiber.effects = wipFiber.effects || [];
|
|
394
|
+
wipFiber.effects.push(oldFiber);
|
|
419
395
|
}
|
|
420
396
|
|
|
421
397
|
if (index === 0) {
|
|
@@ -425,62 +401,16 @@
|
|
|
425
401
|
}
|
|
426
402
|
|
|
427
403
|
prevSibling = newFiber;
|
|
428
|
-
index++;
|
|
429
|
-
}
|
|
430
404
|
|
|
431
|
-
|
|
432
|
-
if (!elements.every((el) => el && el.type && el.props)) {
|
|
433
|
-
throw new Error(
|
|
434
|
-
`Cada elemento en 'elements' debe tener 'type' y 'props': ${JSON.stringify(elements)}`,
|
|
435
|
-
)
|
|
405
|
+
index++;
|
|
436
406
|
}
|
|
437
407
|
|
|
438
|
-
// Optimización: Eliminar claves no utilizadas después de la reconciliación
|
|
439
408
|
oldFibersMap.forEach((oldFiber) => {
|
|
440
409
|
oldFiber.effectTag = EFFECT_TAGS.DELETION;
|
|
441
410
|
vars.deletions.push(oldFiber);
|
|
442
411
|
});
|
|
443
|
-
|
|
444
|
-
// Optimización: Reducir uso de memoria en oldFibersMap
|
|
445
|
-
oldFibersMap.clear(); // Limpiar el mapa después de la reconciliación
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
// Ajustar Suspense para manejar correctamente los componentes Lazy
|
|
449
|
-
const Suspense = ({ fallback, children }) => {
|
|
450
|
-
try {
|
|
451
|
-
const resolvedChildren = children.map((child) => {
|
|
452
|
-
if (typeof child === 'function') {
|
|
453
|
-
return child()
|
|
454
|
-
}
|
|
455
|
-
return child
|
|
456
|
-
});
|
|
457
|
-
return resolvedChildren // Renderizar los hijos resueltos
|
|
458
|
-
} catch (promise) {
|
|
459
|
-
return fallback // Mostrar el fallback mientras se carga
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
const Lazy = (importFunc) => {
|
|
464
|
-
let Component = null;
|
|
465
|
-
let promise = importFunc().then((module) => {
|
|
466
|
-
Component = module.default || module;
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
return (props) => {
|
|
470
|
-
if (!Component) {
|
|
471
|
-
throw promise
|
|
472
|
-
}
|
|
473
|
-
return createElement(Component, props) // Asegurar que renderiza correctamente el componente cargado
|
|
474
|
-
}
|
|
475
412
|
};
|
|
476
413
|
|
|
477
|
-
var Reconciler = /*#__PURE__*/Object.freeze({
|
|
478
|
-
__proto__: null,
|
|
479
|
-
Lazy: Lazy,
|
|
480
|
-
Suspense: Suspense,
|
|
481
|
-
reconcileChildren: reconcileChildren
|
|
482
|
-
});
|
|
483
|
-
|
|
484
414
|
/**
|
|
485
415
|
* This function updates a function component by setting up a work-in-progress fiber, resetting the
|
|
486
416
|
* hook index, creating an empty hooks array, rendering the component, and reconciling its children.
|
|
@@ -493,11 +423,6 @@
|
|
|
493
423
|
vars.hookIndex = 0;
|
|
494
424
|
vars.wipFiber.hooks = [];
|
|
495
425
|
|
|
496
|
-
// Validación: Asegurar que fiber.type sea una función válida
|
|
497
|
-
if (typeof fiber.type !== 'function') {
|
|
498
|
-
throw new Error('El tipo de componente debe ser una función válida.')
|
|
499
|
-
}
|
|
500
|
-
|
|
501
426
|
const children = fiber.type(fiber.props);
|
|
502
427
|
let childArr = Array.isArray(children) ? children : [children];
|
|
503
428
|
|
|
@@ -514,24 +439,72 @@
|
|
|
514
439
|
if (!fiber.dom) {
|
|
515
440
|
fiber.dom = createDom(fiber);
|
|
516
441
|
}
|
|
442
|
+
reconcileChildren(fiber, fiber.props.children);
|
|
443
|
+
};
|
|
517
444
|
|
|
518
|
-
|
|
519
|
-
'[updateHostComponent] fiber props children',
|
|
520
|
-
fiber.props?.children || 'undefined',
|
|
521
|
-
);
|
|
445
|
+
/* Internal components*/
|
|
522
446
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
447
|
+
/**
|
|
448
|
+
* The function `optimizationImageApi` optimizes image URLs by adding query parameters for width,
|
|
449
|
+
* height, quality, and extension, and handles local and remote image sources.
|
|
450
|
+
* @returns The function `optimizationImageApi` returns either the original `src` if it is a local
|
|
451
|
+
* image and the page is being run on localhost, or it returns a modified image URL with optimization
|
|
452
|
+
* parameters added if the `src` is not local.
|
|
453
|
+
*/
|
|
454
|
+
const optimizationImageApi = ({ src, props }) => {
|
|
455
|
+
const query = new URLSearchParams();
|
|
456
|
+
const apiEndpoint = 'https://image.unsetsoft.com';
|
|
457
|
+
|
|
458
|
+
const isLocal = !src.startsWith('http') || !src.startsWith('https');
|
|
459
|
+
|
|
460
|
+
if (props.width) query.set('width', props.width);
|
|
461
|
+
if (props.height) query.set('width', props.height);
|
|
462
|
+
if (props.quality) query.set('quality', props.quality);
|
|
463
|
+
|
|
464
|
+
const extension = props.extension ? `@${props.extension}` : '';
|
|
465
|
+
|
|
466
|
+
const localhost =
|
|
467
|
+
window.location.origin === 'http://localhost:3000' ||
|
|
468
|
+
window.location.origin === 'http://localhost:5173' ||
|
|
469
|
+
window.location.origin === 'http://localhost:4173';
|
|
470
|
+
|
|
471
|
+
if (isLocal) {
|
|
472
|
+
if (localhost) {
|
|
473
|
+
console.warn(
|
|
474
|
+
'Image optimizations only work with full links and must not contain localhost.',
|
|
475
|
+
);
|
|
476
|
+
return src
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return `${window.location.origin}/${src}`
|
|
527
480
|
}
|
|
481
|
+
|
|
482
|
+
return `${apiEndpoint}/image/${src}${extension}?${query.toString()}`
|
|
528
483
|
};
|
|
529
484
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
485
|
+
/**
|
|
486
|
+
* The `Image` function in JavaScript optimizes image loading based on a specified optimization flag.
|
|
487
|
+
* @returns An `<img>` element is being returned with the specified `src` and other props passed to the
|
|
488
|
+
* `Image` component. The `src` is either the original `src` value or the result of calling
|
|
489
|
+
* `optimizationImageApi` function with `src` and `props` if `optimization` is set to 'true'.
|
|
490
|
+
*/
|
|
491
|
+
const Image = ({ src, ...props }) => {
|
|
492
|
+
const optimization = props.optimization === 'true' ? true : false;
|
|
493
|
+
|
|
494
|
+
const url = optimization
|
|
495
|
+
? optimizationImageApi({
|
|
496
|
+
src,
|
|
497
|
+
props,
|
|
498
|
+
})
|
|
499
|
+
: src;
|
|
500
|
+
|
|
501
|
+
const ImageProps = {
|
|
502
|
+
src: url,
|
|
503
|
+
props,
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
return createElement('img', ImageProps, null)
|
|
507
|
+
};
|
|
535
508
|
|
|
536
509
|
/**
|
|
537
510
|
* This function uses requestIdleCallback to perform work on a fiber tree until it is complete or the
|
|
@@ -552,19 +525,10 @@
|
|
|
552
525
|
commitRoot();
|
|
553
526
|
}
|
|
554
527
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Si requestIdleCallback no está disponible, se utiliza un fallback con tiempo infinito para continuar el bucle de trabajo.
|
|
559
|
-
*/
|
|
560
|
-
if (typeof requestIdleCallback === 'function') {
|
|
561
|
-
requestIdleCallback(workLoop);
|
|
562
|
-
} else {
|
|
563
|
-
workLoop(fallbackDeadline);
|
|
564
|
-
}
|
|
528
|
+
requestIdleCallback(workLoop);
|
|
565
529
|
};
|
|
566
530
|
|
|
567
|
-
requestIdleCallback(workLoop)
|
|
531
|
+
//requestIdleCallback(workLoop)
|
|
568
532
|
|
|
569
533
|
/**
|
|
570
534
|
* The function performs a unit of work by updating either a function component or a host component and
|
|
@@ -598,11 +562,15 @@
|
|
|
598
562
|
return undefined
|
|
599
563
|
};
|
|
600
564
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
565
|
+
const scheduleWork = (root) => {
|
|
566
|
+
vars.nextUnitOfWork = root;
|
|
567
|
+
vars.wipRoot = root;
|
|
568
|
+
vars.deletions = [];
|
|
569
|
+
|
|
570
|
+
vars.hookIndex = 0;
|
|
571
|
+
vars.effects = [];
|
|
572
|
+
requestIdleCallback(workLoop);
|
|
573
|
+
};
|
|
606
574
|
|
|
607
575
|
/**
|
|
608
576
|
* Renders an element into a container using a work-in-progress (WIP) root.
|
|
@@ -621,18 +589,9 @@
|
|
|
621
589
|
alternate: vars.currentRoot,
|
|
622
590
|
};
|
|
623
591
|
|
|
624
|
-
vars.deletions = [];
|
|
625
592
|
vars.nextUnitOfWork = vars.wipRoot;
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (typeof requestIdleCallback === 'function') {
|
|
630
|
-
requestIdleCallback(workLoop);
|
|
631
|
-
} else {
|
|
632
|
-
// Si requestIdleCallback no está disponible, se utiliza un fallback con tiempo infinito.
|
|
633
|
-
workLoop(fallbackDeadline);
|
|
634
|
-
}
|
|
635
|
-
|
|
593
|
+
vars.deletions = [];
|
|
594
|
+
scheduleWork(vars.wipRoot);
|
|
636
595
|
return vars.wipRoot
|
|
637
596
|
};
|
|
638
597
|
|
|
@@ -648,7 +607,9 @@
|
|
|
648
607
|
const init = (MainElement, root = '__ryunix') => {
|
|
649
608
|
vars.containerRoot = document.getElementById(root);
|
|
650
609
|
|
|
651
|
-
render(MainElement, vars.containerRoot);
|
|
610
|
+
const renderProcess = render(MainElement, vars.containerRoot);
|
|
611
|
+
|
|
612
|
+
return renderProcess
|
|
652
613
|
};
|
|
653
614
|
|
|
654
615
|
/**
|
|
@@ -657,50 +618,51 @@
|
|
|
657
618
|
* @returns The `useStore` function returns an array with two elements: the current state value and a
|
|
658
619
|
* `setState` function that can be used to update the state.
|
|
659
620
|
*/
|
|
660
|
-
const useStore = (
|
|
621
|
+
const useStore = (initialState, init) => {
|
|
622
|
+
const reducer = (state, action) =>
|
|
623
|
+
typeof action === 'function' ? action(state) : action;
|
|
624
|
+
|
|
625
|
+
return useReducer(reducer, initialState, init)
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
const useReducer = (reducer, initialState, init) => {
|
|
661
629
|
const oldHook =
|
|
662
630
|
vars.wipFiber.alternate &&
|
|
663
631
|
vars.wipFiber.alternate.hooks &&
|
|
664
632
|
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
665
633
|
|
|
666
634
|
const hook = {
|
|
667
|
-
state: oldHook ? oldHook.state :
|
|
668
|
-
|
|
669
|
-
queue: oldHook ? [...oldHook.queue] : [],
|
|
635
|
+
state: oldHook ? oldHook.state : init ? init(initialState) : initialState,
|
|
636
|
+
queue: oldHook && Array.isArray(oldHook.queue) ? oldHook.queue.slice() : [],
|
|
670
637
|
};
|
|
671
638
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
hook.queue = [];
|
|
639
|
+
if (oldHook && Array.isArray(oldHook.queue)) {
|
|
640
|
+
oldHook.queue.forEach((action) => {
|
|
641
|
+
hook.state = reducer(hook.state, action);
|
|
642
|
+
});
|
|
643
|
+
}
|
|
678
644
|
|
|
679
|
-
const
|
|
645
|
+
const dispatch = (action) => {
|
|
680
646
|
hook.queue.push(action);
|
|
681
647
|
|
|
682
648
|
vars.wipRoot = {
|
|
683
649
|
dom: vars.currentRoot.dom,
|
|
684
|
-
|
|
685
|
-
props: {
|
|
686
|
-
...vars.currentRoot.props,
|
|
687
|
-
},
|
|
688
|
-
|
|
650
|
+
props: vars.currentRoot.props,
|
|
689
651
|
alternate: vars.currentRoot,
|
|
690
652
|
};
|
|
691
|
-
|
|
692
|
-
vars.nextUnitOfWork = vars.wipRoot;
|
|
693
|
-
|
|
694
653
|
vars.deletions = [];
|
|
654
|
+
vars.hookIndex = 0;
|
|
655
|
+
scheduleWork(vars.wipRoot);
|
|
695
656
|
};
|
|
696
657
|
|
|
697
|
-
|
|
698
|
-
|
|
658
|
+
hook.queue.forEach((action) => {
|
|
659
|
+
hook.state = reducer(hook.state, action);
|
|
660
|
+
});
|
|
699
661
|
|
|
700
|
-
|
|
701
|
-
|
|
662
|
+
vars.wipFiber.hooks[vars.hookIndex] = hook;
|
|
663
|
+
vars.hookIndex++;
|
|
702
664
|
|
|
703
|
-
return [hook.state,
|
|
665
|
+
return [hook.state, dispatch]
|
|
704
666
|
};
|
|
705
667
|
|
|
706
668
|
/**
|
|
@@ -722,21 +684,28 @@
|
|
|
722
684
|
const hook = {
|
|
723
685
|
type: RYUNIX_TYPES.RYUNIX_EFFECT,
|
|
724
686
|
deps,
|
|
687
|
+
cleanup: oldHook?.cleanup,
|
|
725
688
|
};
|
|
726
689
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
690
|
+
const hasChanged = !oldHook || !lodash.isEqual(oldHook.deps, deps);
|
|
691
|
+
|
|
692
|
+
if (hasChanged) {
|
|
693
|
+
vars.effects.push(() => {
|
|
694
|
+
// Llama al cleanup anterior si existe
|
|
695
|
+
if (typeof hook.cleanup === 'function') {
|
|
696
|
+
hook.cleanup();
|
|
697
|
+
}
|
|
735
698
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
699
|
+
// Ejecuta el nuevo efecto y guarda el nuevo cleanup
|
|
700
|
+
const result = callback();
|
|
701
|
+
if (typeof result === 'function') {
|
|
702
|
+
hook.cleanup = result;
|
|
703
|
+
}
|
|
704
|
+
});
|
|
739
705
|
}
|
|
706
|
+
|
|
707
|
+
vars.wipFiber.hooks[vars.hookIndex] = hook;
|
|
708
|
+
vars.hookIndex++;
|
|
740
709
|
};
|
|
741
710
|
|
|
742
711
|
const useRef = (initial) => {
|
|
@@ -750,10 +719,8 @@
|
|
|
750
719
|
value: oldHook ? oldHook.value : { current: initial },
|
|
751
720
|
};
|
|
752
721
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
vars.hookIndex++;
|
|
756
|
-
}
|
|
722
|
+
vars.wipFiber.hooks[vars.hookIndex] = hook;
|
|
723
|
+
vars.hookIndex++;
|
|
757
724
|
|
|
758
725
|
return hook.value
|
|
759
726
|
};
|
|
@@ -771,7 +738,7 @@
|
|
|
771
738
|
};
|
|
772
739
|
|
|
773
740
|
if (oldHook) {
|
|
774
|
-
if (isEqual(oldHook.deps, hook.deps)) {
|
|
741
|
+
if (lodash.isEqual(oldHook.deps, hook.deps)) {
|
|
775
742
|
hook.value = oldHook.value;
|
|
776
743
|
} else {
|
|
777
744
|
hook.value = comp();
|
|
@@ -780,10 +747,8 @@
|
|
|
780
747
|
hook.value = comp();
|
|
781
748
|
}
|
|
782
749
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
vars.hookIndex++;
|
|
786
|
-
}
|
|
750
|
+
vars.wipFiber.hooks[vars.hookIndex] = hook;
|
|
751
|
+
vars.hookIndex++;
|
|
787
752
|
|
|
788
753
|
return hook.value
|
|
789
754
|
};
|
|
@@ -968,39 +933,28 @@
|
|
|
968
933
|
return { Children, NavLink, navigate }
|
|
969
934
|
};
|
|
970
935
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
const [currentValue, setCurrentValue] = useStore(context.value);
|
|
982
|
-
context.subscribers.push(setCurrentValue);
|
|
983
|
-
return children(currentValue)
|
|
984
|
-
},
|
|
985
|
-
};
|
|
986
|
-
return context
|
|
987
|
-
};
|
|
936
|
+
var Hooks = /*#__PURE__*/Object.freeze({
|
|
937
|
+
__proto__: null,
|
|
938
|
+
useCallback: useCallback,
|
|
939
|
+
useEffect: useEffect,
|
|
940
|
+
useMemo: useMemo,
|
|
941
|
+
useQuery: useQuery,
|
|
942
|
+
useRef: useRef,
|
|
943
|
+
useRouter: useRouter,
|
|
944
|
+
useStore: useStore
|
|
945
|
+
});
|
|
988
946
|
|
|
989
947
|
var Ryunix = {
|
|
990
|
-
Dom,
|
|
991
|
-
Workers,
|
|
992
|
-
Reconciler,
|
|
993
|
-
Components,
|
|
994
|
-
Commits,
|
|
995
948
|
createElement,
|
|
996
|
-
Fragment,
|
|
997
|
-
init,
|
|
998
949
|
render,
|
|
950
|
+
init,
|
|
951
|
+
Fragment,
|
|
952
|
+
Hooks,
|
|
999
953
|
};
|
|
1000
954
|
|
|
1001
955
|
window.Ryunix = Ryunix;
|
|
1002
956
|
|
|
1003
|
-
exports.
|
|
957
|
+
exports.Image = Image;
|
|
1004
958
|
exports.default = Ryunix;
|
|
1005
959
|
exports.useCallback = useCallback;
|
|
1006
960
|
exports.useEffect = useEffect;
|
package/dist/Ryunix.min.js
CHANGED
|
@@ -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
|
|
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=>`${e}-${Math.random().toString(36).substring(2,9)}`,c=(e,t)=>(t=t||[],null==e||typeof e==s.boolean||(Array.isArray(e)?e.some((e=>{c(e,t)})):t.push(e)),t),u=(e,t,...o)=>{o=c(o,[]);const n=t&&t.key?a(t.key):a(r.Ryunix_ELEMENT.toString());return{type:e,props:{...t,key:n,children:o.map((e=>typeof e===s.object?e:p(e)))}}},p=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),f=e=>e.startsWith("on"),d=e=>e!==s.children&&!f(e),h=(e,t)=>o=>e[o]!==t[o],y=e=>t=>!(t in e),m=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},E=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},w=(e,t,o)=>{Object.keys(t).filter(f).filter((e=>y(o)(e)||h(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(d).filter(y(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(d).filter(h(t,o)).forEach((n=>{if(n===s.style)b(e,o["ryunix-style"]);else if(n===i.style)b(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(f).filter(h(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])}))},b=(e,t)=>{e.style=Object.keys(t).reduce(((e,o)=>e+=`${o.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${t[o]};`),"")},k=e=>{if(!e)return;let t=e.parent;for(;!t.dom;)t=t.parent;const o=t.dom;if(e.effectTag===l.PLACEMENT&&null!=e.dom)o.appendChild(e.dom),E(e);else if(e.effectTag===l.UPDATE&&null!=e.dom)m(e),w(e.dom,e.alternate.props,e.props),E(e);else if(e.effectTag===l.DELETION)return R(e,o),void m(e);k(e.child),k(e.sibling)},R=(e,t)=>{e.dom?t.removeChild(e.dom):R(e.child,t)},x=(e,t)=>!e||!t||Object.keys(e).length!==Object.keys(t).length||Object.keys(t).some((o=>e[o]!==t[o])),g=(e,t)=>({...e,props:t,alternate:e,effectTag:l.UPDATE}),N=(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 o=t[n],r=o.props.key||o.type,a=i.get(r);let c;const u=a&&o&&o.type===a.type;u&&!x(a.props,o.props)&&(c=g(a,o.props),i.delete(r)),o&&!u&&(c={type:o.type,props:o.props,dom:null,parent:e,alternate:null,effectTag:l.PLACEMENT}),a&&!u&&(a.effectTag=l.DELETION,e.effects=e.effects||[],e.effects.push(a)),0===n?e.child=c:s&&(s.sibling=c),s=c,n++}i.forEach((e=>{e.effectTag=l.DELETION,o.deletions.push(e)}))},F=e=>{e.dom||(e.dom=(e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return w(t,{},e.props),t})(e)),N(e,e.props.children)},I=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=T(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&(o.deletions.forEach(k),o.wipRoot&&o.wipRoot.child&&(k(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(I)},T=e=>{if(e.type instanceof Function?(e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];const t=e.type(e.props);let n=Array.isArray(t)?t:[t];N(e,n)})(e):F(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}},O=e=>{o.nextUnitOfWork=e,o.wipRoot=e,o.deletions=[],o.hookIndex=0,o.effects=[],requestIdleCallback(I)},L=(e,t)=>(o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[],O(o.wipRoot),o.wipRoot),U=(e,t)=>v(((e,t)=>"function"==typeof t?t(e):t),e,t),v=(e,t,n)=>{const r=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],s={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=>{s.state=e(s.state,t)}));return s.queue.forEach((t=>{s.state=e(s.state,t)})),o.wipFiber.hooks[o.hookIndex]=s,o.hookIndex++,[s.state,e=>{s.queue.push(e),o.wipRoot={dom:o.currentRoot.dom,props:o.currentRoot.props,alternate:o.currentRoot},o.deletions=[],o.hookIndex=0,O(o.wipRoot)}]},_=(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++},S=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},C=(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},j=(e,t)=>C((()=>e),t),M=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},q=e=>{const[t,o]=U(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)};_((()=>{const e=()=>i(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=M(),{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})=>u("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}};var A={createElement:u,render:L,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t);return L(e,o.containerRoot)},Fragment:e=>e.children,Hooks:Object.freeze({__proto__:null,useCallback:j,useEffect:_,useMemo:C,useQuery:M,useRef:S,useRouter:q,useStore:U})};window.Ryunix=A,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 u("img",{src:o,props:t},null)},e.default=A,e.useCallback=j,e.useEffect=_,e.useMemo=C,e.useQuery=M,e.useRef=S,e.useRouter=q,e.useStore=U,Object.defineProperty(e,"__esModule",{value:!0})}));
|