ajo 0.1.27 → 0.1.28
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/index.cjs +1 -1
- package/dist/index.js +66 -67
- package/package.json +5 -5
- package/readme.md +7 -3
- package/types.ts +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./context.cjs"),y=Symbol.for("ajo.key"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./context.cjs"),y=Symbol.for("ajo.key"),j=Symbol.for("ajo.memo"),g=Symbol.for("ajo.ref"),p=Symbol.for("ajo.cache"),c=Symbol.for("ajo.generator"),a=Symbol.for("ajo.iterator"),b=Symbol.for("ajo.render"),f=Symbol.for("ajo.args"),N=t=>t.children,k=(t,e,...r)=>((e??={}).nodeName=t,!("children"in e)&&r.length&&(e.children=r.length==1?r[0]:r),e),l=(t,e,r=e.firstChild,i=null)=>{for(t of S(t)){const n=T(t,e,r);r==null?m(e,n,i):n==r?r=n.nextSibling:n==r.nextSibling?(m(e,r,i),r=n.nextSibling):m(e,n,r)}for(;r!=i;){const n=r.nextSibling;r.nodeType==1&&A(r),e.removeChild(r),r=n}},S=function*(t){if(t==null)return;const e=typeof t;if(e!="boolean")if(e=="string")yield t;else if(e=="number"||e=="bigint")yield String(t);else if(Symbol.iterator in t)for(t of t)yield*S(t);else"nodeName"in t?typeof t.nodeName=="function"?yield*E(t):yield t:yield String(t)},E=function*({nodeName:t,...e}){t.constructor.name=="GeneratorFunction"?yield O(t,e):yield*S(t(e))},O=function(t,e){const r={...t.attrs},i={...t.args};for(const n in e)n.startsWith("attr:")?r[n.slice(5)]=e[n]:n=="key"||n=="skip"||n=="memo"||n=="ref"||n.startsWith("set:")?r[n]=e[n]:i[n]=e[n];return{...r,nodeName:t.is??"div",[c]:t,[f]:i}},T=(t,e,r)=>typeof t=="string"?F(t,r):G(t,e,r),F=(t,e)=>{for(;e&&e.nodeType!=3;)e=e.nextSibling;return e?e.data!=t&&(e.data=t):e=document.createTextNode(t),e},G=({nodeName:t,children:e,key:r,skip:i,memo:n,ref:x,[c]:u,[f]:v,...w},C,s)=>{for(;s&&(s.localName!=t||s[y]!=null&&s[y]!=r||s[c]&&s[c]!=u);)s=s.nextSibling;return s??=document.createElementNS(w.xmlns??C.namespaceURI,t),r!=null&&(s[y]=r),(n==null||W(s[j],s[j]=n))&&(R(s[p]??B(s),s[p]=w,s),i||(u?I(u,v,s):l(e,s)),typeof x=="function"&&(s[g]=x)(s)),s},R=(t,e,r)=>{for(const i in{...t,...e})t[i]!==e[i]&&(i.startsWith("set:")?r[i.slice(4)]=e[i]:e[i]==null||e[i]===!1?r.removeAttribute(i):r.setAttribute(i,e[i]===!0?"":e[i]))},W=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.some((r,i)=>r!==e[i]):t!==e,B=t=>Array.from(t.attributes).reduce((e,r)=>(e[r.name]=r.value,e),{}),m=(t,e,r)=>{if(e.contains(document.activeElement)){const i=e.nextSibling;for(;r&&r!=e;){const n=r.nextSibling;t.insertBefore(r,i),r=n}}else t.insertBefore(e,r)},A=t=>{for(const e of t.children)A(e);typeof t.return=="function"&&t.return(),t[g]?.(null)},I=(t,e,r)=>{r[c]??=(M(r),t),Object.assign(r[f]??={},e),r[b]()},M=t=>{Object.assign(t,h),t[o.Context]=Object.create(o.current()?.[o.Context]??null)},h={[b](){const t=o.current();o.current(this);try{const{value:e,done:r}=(this[a]??=this[c].call(this,this[f])).next();l(e,this),this[g]?.(this),r&&this.return()}catch(e){this.throw(e)}finally{o.current(t)}},next(t){if(typeof t=="function")try{t.call(this,this[f])}catch(e){this.throw(e)}o.current()?.contains(this)||this[b]()},throw(t){for(let e=this;e;e=e.parentNode)if(typeof e[a]?.throw=="function")try{return l(e[a].throw(t).value,e)}catch(r){t=new Error(r instanceof Error?r.message:r,{cause:t})}throw t},return(){try{this[a]?.return()}catch(t){this.throw(t)}finally{this[a]=null}}};exports.Fragment=N;exports.h=k;exports.render=l;
|
package/dist/index.js
CHANGED
|
@@ -1,94 +1,93 @@
|
|
|
1
|
-
import { Context as
|
|
2
|
-
const u = Symbol.for("ajo.key"), p = Symbol.for("ajo.memo"),
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
r == null ? e.appendChild(i) : i == r ? r = i.nextSibling : i == r.nextSibling ? (e.appendChild(r), r = i.nextSibling) : W(e, i, r);
|
|
1
|
+
import { Context as j, current as f } from "./context.js";
|
|
2
|
+
const u = Symbol.for("ajo.key"), p = Symbol.for("ajo.memo"), g = Symbol.for("ajo.ref"), A = Symbol.for("ajo.cache"), o = Symbol.for("ajo.generator"), a = Symbol.for("ajo.iterator"), m = Symbol.for("ajo.render"), c = Symbol.for("ajo.args"), U = (t) => t.children, h = (t, r, ...e) => ((r ??= {}).nodeName = t, !("children" in r) && e.length && (r.children = e.length == 1 ? e[0] : e), r), b = (t, r, e = r.firstChild, i = null) => {
|
|
3
|
+
for (t of S(t)) {
|
|
4
|
+
const n = G(t, r, e);
|
|
5
|
+
e == null ? y(r, n, i) : n == e ? e = n.nextSibling : n == e.nextSibling ? (y(r, e, i), e = n.nextSibling) : y(r, n, e);
|
|
7
6
|
}
|
|
8
|
-
for (;
|
|
9
|
-
const
|
|
10
|
-
|
|
7
|
+
for (; e != i; ) {
|
|
8
|
+
const n = e.nextSibling;
|
|
9
|
+
e.nodeType == 1 && v(e), r.removeChild(e), e = n;
|
|
11
10
|
}
|
|
12
|
-
},
|
|
11
|
+
}, S = function* (t) {
|
|
13
12
|
if (t == null) return;
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
if (
|
|
17
|
-
else if (
|
|
18
|
-
else if (Symbol.iterator in t) for (t of t) yield*
|
|
13
|
+
const r = typeof t;
|
|
14
|
+
if (r != "boolean")
|
|
15
|
+
if (r == "string") yield t;
|
|
16
|
+
else if (r == "number" || r == "bigint") yield String(t);
|
|
17
|
+
else if (Symbol.iterator in t) for (t of t) yield* S(t);
|
|
19
18
|
else "nodeName" in t ? typeof t.nodeName == "function" ? yield* C(t) : yield t : yield String(t);
|
|
20
|
-
}, C = function* ({ nodeName: t, ...
|
|
21
|
-
t.constructor.name == "GeneratorFunction" ? yield
|
|
22
|
-
},
|
|
23
|
-
const
|
|
24
|
-
for (const
|
|
25
|
-
|
|
26
|
-
return { ...
|
|
27
|
-
},
|
|
28
|
-
for (;
|
|
29
|
-
return
|
|
30
|
-
},
|
|
31
|
-
for (;
|
|
32
|
-
return
|
|
33
|
-
},
|
|
34
|
-
for (const i in { ...t, ...
|
|
35
|
-
t[i] !==
|
|
36
|
-
},
|
|
37
|
-
if (
|
|
38
|
-
const i =
|
|
39
|
-
for (;
|
|
40
|
-
const
|
|
41
|
-
t.insertBefore(
|
|
19
|
+
}, C = function* ({ nodeName: t, ...r }) {
|
|
20
|
+
t.constructor.name == "GeneratorFunction" ? yield E(t, r) : yield* S(t(r));
|
|
21
|
+
}, E = function(t, r) {
|
|
22
|
+
const e = { ...t.attrs }, i = { ...t.args };
|
|
23
|
+
for (const n in r)
|
|
24
|
+
n.startsWith("attr:") ? e[n.slice(5)] = r[n] : n == "key" || n == "skip" || n == "memo" || n == "ref" || n.startsWith("set:") ? e[n] = r[n] : i[n] = r[n];
|
|
25
|
+
return { ...e, nodeName: t.is ?? "div", [o]: t, [c]: i };
|
|
26
|
+
}, G = (t, r, e) => typeof t == "string" ? O(t, e) : R(t, r, e), O = (t, r) => {
|
|
27
|
+
for (; r && r.nodeType != 3; ) r = r.nextSibling;
|
|
28
|
+
return r ? r.data != t && (r.data = t) : r = document.createTextNode(t), r;
|
|
29
|
+
}, R = ({ nodeName: t, children: r, key: e, skip: i, memo: n, ref: x, [o]: l, [c]: N, ...w }, k, s) => {
|
|
30
|
+
for (; s && (s.localName != t || s[u] != null && s[u] != e || s[o] && s[o] != l); ) s = s.nextSibling;
|
|
31
|
+
return s ??= document.createElementNS(w.xmlns ?? k.namespaceURI, t), e != null && (s[u] = e), (n == null || W(s[p], s[p] = n)) && (T(s[A] ?? B(s), s[A] = w, s), i || (l ? F(l, N, s) : b(r, s)), typeof x == "function" && (s[g] = x)(s)), s;
|
|
32
|
+
}, T = (t, r, e) => {
|
|
33
|
+
for (const i in { ...t, ...r })
|
|
34
|
+
t[i] !== r[i] && (i.startsWith("set:") ? e[i.slice(4)] = r[i] : r[i] == null || r[i] === !1 ? e.removeAttribute(i) : e.setAttribute(i, r[i] === !0 ? "" : r[i]));
|
|
35
|
+
}, W = (t, r) => Array.isArray(t) && Array.isArray(r) ? t.some((e, i) => e !== r[i]) : t !== r, B = (t) => Array.from(t.attributes).reduce((r, e) => (r[e.name] = e.value, r), {}), y = (t, r, e) => {
|
|
36
|
+
if (r.contains(document.activeElement)) {
|
|
37
|
+
const i = r.nextSibling;
|
|
38
|
+
for (; e && e != r; ) {
|
|
39
|
+
const n = e.nextSibling;
|
|
40
|
+
t.insertBefore(e, i), e = n;
|
|
42
41
|
}
|
|
43
|
-
} else t.insertBefore(
|
|
44
|
-
},
|
|
45
|
-
for (const
|
|
46
|
-
typeof t.return == "function" && t.return(), t[
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
Object.assign(t,
|
|
51
|
-
},
|
|
52
|
-
[
|
|
53
|
-
const t =
|
|
54
|
-
|
|
42
|
+
} else t.insertBefore(r, e);
|
|
43
|
+
}, v = (t) => {
|
|
44
|
+
for (const r of t.children) v(r);
|
|
45
|
+
typeof t.return == "function" && t.return(), t[g]?.(null);
|
|
46
|
+
}, F = (t, r, e) => {
|
|
47
|
+
e[o] ??= (I(e), t), Object.assign(e[c] ??= {}, r), e[m]();
|
|
48
|
+
}, I = (t) => {
|
|
49
|
+
Object.assign(t, K), t[j] = Object.create(f()?.[j] ?? null);
|
|
50
|
+
}, K = {
|
|
51
|
+
[m]() {
|
|
52
|
+
const t = f();
|
|
53
|
+
f(this);
|
|
55
54
|
try {
|
|
56
|
-
const { value:
|
|
57
|
-
|
|
58
|
-
} catch (
|
|
59
|
-
this.throw(
|
|
55
|
+
const { value: r, done: e } = (this[a] ??= this[o].call(this, this[c])).next();
|
|
56
|
+
b(r, this), this[g]?.(this), e && this.return();
|
|
57
|
+
} catch (r) {
|
|
58
|
+
this.throw(r);
|
|
60
59
|
} finally {
|
|
61
|
-
|
|
60
|
+
f(t);
|
|
62
61
|
}
|
|
63
62
|
},
|
|
64
63
|
next(t) {
|
|
65
64
|
if (typeof t == "function") try {
|
|
66
|
-
t.call(this, this[
|
|
67
|
-
} catch (
|
|
68
|
-
this.throw(
|
|
65
|
+
t.call(this, this[c]);
|
|
66
|
+
} catch (r) {
|
|
67
|
+
this.throw(r);
|
|
69
68
|
}
|
|
70
|
-
|
|
69
|
+
f()?.contains(this) || this[m]();
|
|
71
70
|
},
|
|
72
71
|
throw(t) {
|
|
73
|
-
for (let
|
|
74
|
-
return
|
|
75
|
-
} catch (
|
|
76
|
-
t = new Error(
|
|
72
|
+
for (let r = this; r; r = r.parentNode) if (typeof r[a]?.throw == "function") try {
|
|
73
|
+
return b(r[a].throw(t).value, r);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
t = new Error(e instanceof Error ? e.message : e, { cause: t });
|
|
77
76
|
}
|
|
78
77
|
throw t;
|
|
79
78
|
},
|
|
80
79
|
return() {
|
|
81
80
|
try {
|
|
82
|
-
this[
|
|
81
|
+
this[a]?.return();
|
|
83
82
|
} catch (t) {
|
|
84
83
|
this.throw(t);
|
|
85
84
|
} finally {
|
|
86
|
-
this[
|
|
85
|
+
this[a] = null;
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
};
|
|
90
89
|
export {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
U as Fragment,
|
|
91
|
+
h,
|
|
92
|
+
b as render
|
|
94
93
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ajo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"description": "ajo is a JavaScript view library for building user interfaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./types.ts",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"types.ts"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "24.
|
|
37
|
-
"happy-dom": "
|
|
38
|
-
"vite": "7.
|
|
36
|
+
"@types/node": "24.10.1",
|
|
37
|
+
"happy-dom": "20.0.11",
|
|
38
|
+
"vite": "7.2.4",
|
|
39
39
|
"vite-tsconfig-paths": "5.1.4",
|
|
40
|
-
"vitest": "
|
|
40
|
+
"vitest": "4.0.14"
|
|
41
41
|
},
|
|
42
42
|
"keywords": [
|
|
43
43
|
"ui",
|
package/readme.md
CHANGED
|
@@ -148,7 +148,7 @@ function* MapComponent(args) {
|
|
|
148
148
|
new GoogleMap(el, args.config)
|
|
149
149
|
}
|
|
150
150
|
}}
|
|
151
|
-
skip
|
|
151
|
+
skip
|
|
152
152
|
>
|
|
153
153
|
{/* Google Maps API manages children elements */}
|
|
154
154
|
</div>
|
|
@@ -183,13 +183,17 @@ for await (const chunk of stream(<App />)) response.write(chunk)
|
|
|
183
183
|
|
|
184
184
|
### Core Module (`ajo`)
|
|
185
185
|
|
|
186
|
-
#### `render(children: Children, container: Element): void`
|
|
187
|
-
Renders JSX into a DOM container element.
|
|
186
|
+
#### `render(children: Children, container: Element, child?: ChildNode, ref?: ChildNode): void`
|
|
187
|
+
Renders JSX into a DOM container element. When `child` and `ref` are provided, only nodes between them (inclusive of `child`, exclusive of `ref`) are reconciled, leaving the rest of the container untouched.
|
|
188
188
|
|
|
189
189
|
```javascript
|
|
190
190
|
import { render } from 'ajo'
|
|
191
191
|
|
|
192
192
|
render(<App />, document.getElementById('root'))
|
|
193
|
+
|
|
194
|
+
// Update only the <main> region without touching header/footer
|
|
195
|
+
const container = document.body
|
|
196
|
+
render(<main>Updated</main>, container, container.querySelector('main'), container.querySelector('footer'))
|
|
193
197
|
```
|
|
194
198
|
|
|
195
199
|
#### `h(type: Type, props?: Props, ...children: Children[]): VNode`
|
package/types.ts
CHANGED
|
@@ -2,9 +2,9 @@ declare module 'ajo' {
|
|
|
2
2
|
|
|
3
3
|
type Tag = keyof (HTMLElementTagNameMap & SVGElementTagNameMap)
|
|
4
4
|
|
|
5
|
-
type Type = Tag | Stateless | Stateful
|
|
5
|
+
type Type<TArguments extends Props = {}, TTag extends Tag = 'div'> = Tag | Stateless<TArguments> | Stateful<TArguments, TTag>
|
|
6
6
|
|
|
7
|
-
type Component<
|
|
7
|
+
type Component<TArguments extends Props = {}> = Stateless<TArguments> | Stateful<TArguments>
|
|
8
8
|
|
|
9
9
|
type Props = Record<string, unknown>
|
|
10
10
|
|
|
@@ -61,11 +61,12 @@ declare module 'ajo' {
|
|
|
61
61
|
|
|
62
62
|
function Fragment({ children }: ElementChildrenAttribute): typeof children
|
|
63
63
|
function h(tag: Type, props?: Props | null, ...children: Children[]): VNode<Type, Props>
|
|
64
|
-
function render(h: Children, el:
|
|
64
|
+
function render(h: Children, el: ParentNode, child?: ChildNode, ref?: ChildNode): void
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
declare module 'ajo/context' {
|
|
68
68
|
function context<T>(fallback?: T): (value?: T) => T
|
|
69
|
+
function current(): import('ajo').Stateful | null
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
declare module 'ajo/html' {
|