vaw-js 0.0.1
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 +33 -0
- package/dist/index.d.ts +56 -0
- package/dist/vaw-js.js +123 -0
- package/dist/vaw-js.umd.cjs +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img alt="VAW Icon" src="https://i.imgur.com/mHV90x7.png" align="center">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# vaw-js [](https://www.npmjs.com/package/vaw-js)
|
|
6
|
+
|
|
7
|
+
## Getting Started
|
|
8
|
+
|
|
9
|
+
vaw-js is an educational project; it clearly isn’t looking to compete with the established frameworks on the market. Instead, it aims to replicate and adapt some of their best features, with the ultimate goal of learning and sharing knowledge among its contributors.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Questions
|
|
13
|
+
|
|
14
|
+
For any questions, doubts, or support, please send a message to the contact methods listed below in this README.
|
|
15
|
+
|
|
16
|
+
## Stay In Touch
|
|
17
|
+
|
|
18
|
+
- Email: srui@alumnos.exa.unicen.edu.ar
|
|
19
|
+
- Discord: santiagorbsd
|
|
20
|
+
|
|
21
|
+
## Contribution
|
|
22
|
+
|
|
23
|
+
Contributing is simple: just submit a pull request, and we will review your suggestion to ensure it aligns with our current project goals.
|
|
24
|
+
|
|
25
|
+
Meet the contributors board
|
|
26
|
+
|
|
27
|
+
<a href="https://github.com/vaw-js/graphs/contributors"><img src="https://opencollective.com/vaw-js/contributors.svg?width=890&limit=500" /></a>
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
[MIT](https://opensource.org/licenses/MIT)
|
|
32
|
+
|
|
33
|
+
Copyright (c) 2026-present, Santiago Rui
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize the virtual DOM and renderize the virtual nodes
|
|
3
|
+
* @param rootComponent
|
|
4
|
+
* @param container - Root container, usually a div with #app tag.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createApp(rootComponent: () => VNode, container: HTMLElement): void;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a virtual node object
|
|
10
|
+
* @param type - String or function
|
|
11
|
+
* @param props - Classes or events
|
|
12
|
+
* @param children
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function h(type: VNodeType, props?: any, ...children: VNodeChild[]): VNode;
|
|
16
|
+
|
|
17
|
+
export declare function mount(vnode: VNode | string, container: HTMLElement): Text;
|
|
18
|
+
|
|
19
|
+
export declare function nextTick<T = void>(fn?: (this: T) => any): Promise<void>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Compare nodes, update their props and childrens.
|
|
23
|
+
* @param n1
|
|
24
|
+
* @param n2
|
|
25
|
+
*/
|
|
26
|
+
export declare function patch(n1: VNode, n2: VNode): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Create an reactive to changes object based in an original Object.
|
|
30
|
+
* @param target - Base object
|
|
31
|
+
* @returns Reactive Proxy
|
|
32
|
+
*/
|
|
33
|
+
export declare function reactive<T extends object>(target: T): T;
|
|
34
|
+
|
|
35
|
+
declare interface VNode {
|
|
36
|
+
type: VNodeType;
|
|
37
|
+
props: any;
|
|
38
|
+
children: (VNode | string)[];
|
|
39
|
+
el?: HTMLElement;
|
|
40
|
+
componentInstance?: any;
|
|
41
|
+
onMounted?: () => void;
|
|
42
|
+
onUnmounted?: () => void;
|
|
43
|
+
onUpdated?: () => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare type VNodeChild = VNode | string | number | boolean | null | undefined;
|
|
47
|
+
|
|
48
|
+
declare type VNodeType = string | Function;
|
|
49
|
+
|
|
50
|
+
export declare function watch<T = any>(source: WatchSource<T>, cb: WatchCallback<T>): void;
|
|
51
|
+
|
|
52
|
+
declare type WatchCallback<T = any> = (val: T, oldVal: T) => void;
|
|
53
|
+
|
|
54
|
+
declare type WatchSource<T = any> = () => T;
|
|
55
|
+
|
|
56
|
+
export { }
|
package/dist/vaw-js.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const u = /* @__PURE__ */ new Set();
|
|
2
|
+
let p = !1, a = !1;
|
|
3
|
+
const w = Promise.resolve();
|
|
4
|
+
let g = null;
|
|
5
|
+
function x(e) {
|
|
6
|
+
const o = g || w;
|
|
7
|
+
return e ? o.then(() => e.call(void 0)) : o;
|
|
8
|
+
}
|
|
9
|
+
function y(e) {
|
|
10
|
+
u.has(e) || (u.add(e), C());
|
|
11
|
+
}
|
|
12
|
+
function C() {
|
|
13
|
+
!p && !a && (a = !0, g = w.then(M));
|
|
14
|
+
}
|
|
15
|
+
function M() {
|
|
16
|
+
a = !1, p = !0;
|
|
17
|
+
try {
|
|
18
|
+
u.forEach((e) => {
|
|
19
|
+
e();
|
|
20
|
+
});
|
|
21
|
+
} finally {
|
|
22
|
+
p = !1, u.clear(), g = null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
let d = null;
|
|
26
|
+
function c(e) {
|
|
27
|
+
d = e;
|
|
28
|
+
}
|
|
29
|
+
const h = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
function P(e, o) {
|
|
31
|
+
if (!d) return;
|
|
32
|
+
let n = h.get(e);
|
|
33
|
+
if (n || (n = /* @__PURE__ */ new Map(), h.set(e, n)), n) {
|
|
34
|
+
let t = n.get(o);
|
|
35
|
+
t || n.set(o, t = /* @__PURE__ */ new Set()), t.add(d);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function U(e, o) {
|
|
39
|
+
const n = h.get(e);
|
|
40
|
+
if (!n) return;
|
|
41
|
+
const t = n.get(o);
|
|
42
|
+
t && t.forEach((s) => y(s));
|
|
43
|
+
}
|
|
44
|
+
function L(e) {
|
|
45
|
+
return new Proxy(e, {
|
|
46
|
+
get(o, n, t) {
|
|
47
|
+
const s = Reflect.get(o, n, t);
|
|
48
|
+
return P(o, n), s;
|
|
49
|
+
},
|
|
50
|
+
set(o, n, t, s) {
|
|
51
|
+
const i = o[n], r = Reflect.set(o, n, t, s);
|
|
52
|
+
return r && i !== t && U(o, n), r;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function V(e, o) {
|
|
57
|
+
let n;
|
|
58
|
+
typeof e == "function" ? n = e : n = () => e;
|
|
59
|
+
let t, s;
|
|
60
|
+
c(() => {
|
|
61
|
+
c(null), s = n(), s !== t && (o(s, t), t = s);
|
|
62
|
+
}), t = n(), c(null);
|
|
63
|
+
}
|
|
64
|
+
function A(e, o = {}, ...n) {
|
|
65
|
+
const { onMounted: t, onUnmounted: s, onUpdated: i, ...r } = o;
|
|
66
|
+
return {
|
|
67
|
+
type: e,
|
|
68
|
+
props: r || {},
|
|
69
|
+
children: n.flat(),
|
|
70
|
+
onMounted: t,
|
|
71
|
+
onUnmounted: s,
|
|
72
|
+
onUpdated: i
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function m(e, o) {
|
|
76
|
+
if (typeof e == "string") {
|
|
77
|
+
const t = document.createTextNode(e);
|
|
78
|
+
return o.appendChild(t), t;
|
|
79
|
+
}
|
|
80
|
+
const n = document.createElement(e.type);
|
|
81
|
+
e.el = n;
|
|
82
|
+
for (const t in e.props)
|
|
83
|
+
t.startsWith("on") ? n.addEventListener(t.slice(2).toLowerCase(), e.props[t]) : n.setAttribute(t, e.props[t]);
|
|
84
|
+
e.children.forEach((t) => m(t, n)), o.appendChild(n), e.onMounted && e.onMounted();
|
|
85
|
+
}
|
|
86
|
+
function E(e, o) {
|
|
87
|
+
const n = o.el = e.el;
|
|
88
|
+
if (e.type !== o.type) {
|
|
89
|
+
const t = n.parentElement;
|
|
90
|
+
e.onUnmounted && e.onUnmounted(), t == null || t.removeChild(n), m(o, t);
|
|
91
|
+
} else {
|
|
92
|
+
const t = e.props || {}, s = o.props || {};
|
|
93
|
+
for (const l in s)
|
|
94
|
+
if (s[l] !== t[l])
|
|
95
|
+
if (l.startsWith("on")) {
|
|
96
|
+
const f = l.slice(2).toLowerCase();
|
|
97
|
+
n.removeEventListener(f, t[l]), n.addEventListener(f, s[l]);
|
|
98
|
+
} else
|
|
99
|
+
n.setAttribute(l, s[l]);
|
|
100
|
+
const i = e.children, r = o.children;
|
|
101
|
+
typeof r[0] == "string" ? r[0] !== i[0] && (n.textContent = r[0]) : r.forEach((l, f) => {
|
|
102
|
+
typeof l != "string" && typeof i[f] != "string" && E(i[f], l);
|
|
103
|
+
}), o.onUpdated && o.onUpdated();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function N(e, o) {
|
|
107
|
+
let n = null;
|
|
108
|
+
const t = () => {
|
|
109
|
+
c(t);
|
|
110
|
+
const s = e();
|
|
111
|
+
n ? E(n, s) : m(s, o), n = s, c(null);
|
|
112
|
+
};
|
|
113
|
+
c(t), t();
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
N as createApp,
|
|
117
|
+
A as h,
|
|
118
|
+
m as mount,
|
|
119
|
+
x as nextTick,
|
|
120
|
+
E as patch,
|
|
121
|
+
L as reactive,
|
|
122
|
+
V as watch
|
|
123
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(s,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(s=typeof globalThis<"u"?globalThis:s||self,f(s.Vaw={}))})(this,(function(s){"use strict";const f=new Set;let p=!1,h=!1;const E=Promise.resolve();let m=null;function M(e){const o=m||E;return e?o.then(()=>e.call(void 0)):o}function P(e){f.has(e)||(f.add(e),C())}function C(){!p&&!h&&(h=!0,m=E.then(T))}function T(){h=!1,p=!0;try{f.forEach(e=>{e()})}finally{p=!1,f.clear(),m=null}}let g=null;function u(e){g=e}const w=new WeakMap;function U(e,o){if(!g)return;let n=w.get(e);if(n||(n=new Map,w.set(e,n)),n){let t=n.get(o);t||n.set(o,t=new Set),t.add(g)}}function V(e,o){const n=w.get(e);if(!n)return;const t=n.get(o);t&&t.forEach(i=>P(i))}function b(e){return new Proxy(e,{get(o,n,t){const i=Reflect.get(o,n,t);return U(o,n),i},set(o,n,t,i){const r=o[n],c=Reflect.set(o,n,t,i);return c&&r!==t&&V(o,n),c}})}function A(e,o){let n;typeof e=="function"?n=e:n=()=>e;let t,i;u(()=>{u(null),i=n(),i!==t&&(o(i,t),t=i)}),t=n(),u(null)}function L(e,o={},...n){const{onMounted:t,onUnmounted:i,onUpdated:r,...c}=o;return{type:e,props:c||{},children:n.flat(),onMounted:t,onUnmounted:i,onUpdated:r}}function a(e,o){if(typeof e=="string"){const t=document.createTextNode(e);return o.appendChild(t),t}const n=document.createElement(e.type);e.el=n;for(const t in e.props)t.startsWith("on")?n.addEventListener(t.slice(2).toLowerCase(),e.props[t]):n.setAttribute(t,e.props[t]);e.children.forEach(t=>a(t,n)),o.appendChild(n),e.onMounted&&e.onMounted()}function y(e,o){const n=o.el=e.el;if(e.type!==o.type){const t=n.parentElement;e.onUnmounted&&e.onUnmounted(),t==null||t.removeChild(n),a(o,t)}else{const t=e.props||{},i=o.props||{};for(const l in i)if(i[l]!==t[l])if(l.startsWith("on")){const d=l.slice(2).toLowerCase();n.removeEventListener(d,t[l]),n.addEventListener(d,i[l])}else n.setAttribute(l,i[l]);const r=e.children,c=o.children;typeof c[0]=="string"?c[0]!==r[0]&&(n.textContent=c[0]):c.forEach((l,d)=>{typeof l!="string"&&typeof r[d]!="string"&&y(r[d],l)}),o.onUpdated&&o.onUpdated()}}function v(e,o){let n=null;const t=()=>{u(t);const i=e();n?y(n,i):a(i,o),n=i,u(null)};u(t),t()}s.createApp=v,s.h=L,s.mount=a,s.nextTick=M,s.patch=y,s.reactive=b,s.watch=A,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vaw-js",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "Santiago Rui",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"description": "Virtual Atomic Web - A lightweight reactive framework",
|
|
8
|
+
"main": "./dist/vaw-js.umd.cjs",
|
|
9
|
+
"module": "./dist/vaw-js.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/vaw-js.js",
|
|
18
|
+
"require": "./dist/vaw-js.umd.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "vite",
|
|
23
|
+
"build": "tsc && vite build",
|
|
24
|
+
"preview": "vite preview"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.0.0",
|
|
28
|
+
"typescript": "~5.7.0",
|
|
29
|
+
"vite": "^6.0.0",
|
|
30
|
+
"vite-plugin-dts": "^4.5.4"
|
|
31
|
+
}
|
|
32
|
+
}
|