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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./context.cjs"),y=Symbol.for("ajo.key"),h=Symbol.for("ajo.memo"),b=Symbol.for("ajo.ref"),p=Symbol.for("ajo.cache"),c=Symbol.for("ajo.generator"),l=Symbol.for("ajo.iterator"),m=Symbol.for("ajo.render"),a=Symbol.for("ajo.args"),v=t=>t.children,C=(t,e,...r)=>((e??={}).nodeName=t,!("children"in e)&&r.length&&(e.children=r.length==1?r[0]:r),e),f=(t,e)=>{let r=e.firstChild;for(t of g(t)){const n=E(t,e,r);r==null?e.appendChild(n):n==r?r=n.nextSibling:n==r.nextSibling?(e.appendChild(r),r=n.nextSibling):W(e,n,r)}for(;r;){const n=r.nextSibling;r.nodeType==1&&w(r),e.removeChild(r),r=n}},g=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*g(t);else"nodeName"in t?typeof t.nodeName=="function"?yield*N(t):yield t:yield String(t)},N=function*({nodeName:t,...e}){t.constructor.name=="GeneratorFunction"?yield k(t,e):yield*g(t(e))},k=function(t,e){const r={...t.attrs},n={...t.args};for(const s in e)s.startsWith("attr:")?r[s.slice(5)]=e[s]:s=="key"||s=="skip"||s=="memo"||s=="ref"||s.startsWith("set:")?r[s]=e[s]:n[s]=e[s];return{...r,nodeName:t.is??"div",[c]:t,[a]:n}},E=(t,e,r)=>typeof t=="string"?O(t,r):T(t,e,r),O=(t,e)=>{for(;e&&e.nodeType!=3;)e=e.nextSibling;return e?e.data!=t&&(e.data=t):e=document.createTextNode(t),e},T=({nodeName:t,children:e,key:r,skip:n,memo:s,ref:S,[c]:u,[a]:j,...x},A,i)=>{for(;i&&(i.localName!=t||i[y]!=null&&i[y]!=r||i[c]&&i[c]!=u);)i=i.nextSibling;return i??=document.createElementNS(x.xmlns??A.namespaceURI,t),r!=null&&(i[y]=r),(s==null||G(i[h],i[h]=s))&&(F(i[p]??R(i),i[p]=x,i),n||(u?B(u,j,i):f(e,i)),typeof S=="function"&&(i[b]=S)(i)),i},F=(t,e,r)=>{for(const n in{...t,...e})t[n]!==e[n]&&(n.startsWith("set:")?r[n.slice(4)]=e[n]:e[n]==null||e[n]===!1?r.removeAttribute(n):r.setAttribute(n,e[n]===!0?"":e[n]))},G=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.some((r,n)=>r!==e[n]):t!==e,R=t=>Array.from(t.attributes).reduce((e,r)=>(e[r.name]=r.value,e),{}),W=(t,e,r)=>{if(e.contains(document.activeElement)){const n=e.nextSibling;for(;r&&r!=e;){const s=r.nextSibling;t.insertBefore(r,n),r=s}}else t.insertBefore(e,r)},w=t=>{for(const e of t.children)w(e);typeof t.return=="function"&&t.return(),t[b]?.(null)},B=(t,e,r)=>{r[c]??=(I(r),t),Object.assign(r[a]??={},e),r[m]()},I=t=>{Object.assign(t,M),t[o.Context]=Object.create(o.current()?.[o.Context]??null)},M={[m](){const t=o.current();o.current(this);try{const{value:e,done:r}=(this[l]??=this[c].call(this,this[a])).next();f(e,this),this[b]?.(this),r&&this.return()}catch(e){this.throw(e)}finally{o.current(t)}},next(t){if(typeof t=="function")try{t.call(this,this[a])}catch(e){this.throw(e)}o.current()?.contains(this)||this[m]()},throw(t){for(let e=this;e;e=e.parentNode)if(typeof e[l]?.throw=="function")try{return f(e[l].throw(t).value,e)}catch(r){t=new Error(r instanceof Error?r.message:r,{cause:t})}throw t},return(){try{this[l]?.return()}catch(t){this.throw(t)}finally{this[l]=null}}};exports.Fragment=v;exports.h=C;exports.render=f;
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 h, current as l } from "./context.js";
2
- const u = Symbol.for("ajo.key"), p = Symbol.for("ajo.memo"), b = Symbol.for("ajo.ref"), w = Symbol.for("ajo.cache"), o = Symbol.for("ajo.generator"), c = Symbol.for("ajo.iterator"), y = Symbol.for("ajo.render"), a = Symbol.for("ajo.args"), M = (t) => t.children, U = (t, e, ...r) => ((e ??= {}).nodeName = t, !("children" in e) && r.length && (e.children = r.length == 1 ? r[0] : r), e), m = (t, e) => {
3
- let r = e.firstChild;
4
- for (t of g(t)) {
5
- const i = k(t, e, r);
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 (; r; ) {
9
- const i = r.nextSibling;
10
- r.nodeType == 1 && j(r), e.removeChild(r), r = i;
7
+ for (; e != i; ) {
8
+ const n = e.nextSibling;
9
+ e.nodeType == 1 && v(e), r.removeChild(e), e = n;
11
10
  }
12
- }, g = function* (t) {
11
+ }, S = function* (t) {
13
12
  if (t == null) return;
14
- const e = typeof t;
15
- if (e != "boolean")
16
- if (e == "string") yield t;
17
- else if (e == "number" || e == "bigint") yield String(t);
18
- else if (Symbol.iterator in t) for (t of t) yield* g(t);
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, ...e }) {
21
- t.constructor.name == "GeneratorFunction" ? yield N(t, e) : yield* g(t(e));
22
- }, N = function(t, e) {
23
- const r = { ...t.attrs }, i = { ...t.args };
24
- for (const s in e)
25
- s.startsWith("attr:") ? r[s.slice(5)] = e[s] : s == "key" || s == "skip" || s == "memo" || s == "ref" || s.startsWith("set:") ? r[s] = e[s] : i[s] = e[s];
26
- return { ...r, nodeName: t.is ?? "div", [o]: t, [a]: i };
27
- }, k = (t, e, r) => typeof t == "string" ? E(t, r) : G(t, e, r), E = (t, e) => {
28
- for (; e && e.nodeType != 3; ) e = e.nextSibling;
29
- return e ? e.data != t && (e.data = t) : e = document.createTextNode(t), e;
30
- }, G = ({ nodeName: t, children: e, key: r, skip: i, memo: s, ref: S, [o]: f, [a]: A, ...x }, v, n) => {
31
- for (; n && (n.localName != t || n[u] != null && n[u] != r || n[o] && n[o] != f); ) n = n.nextSibling;
32
- return n ??= document.createElementNS(x.xmlns ?? v.namespaceURI, t), r != null && (n[u] = r), (s == null || R(n[p], n[p] = s)) && (O(n[w] ?? T(n), n[w] = x, n), i || (f ? B(f, A, n) : m(e, n)), typeof S == "function" && (n[b] = S)(n)), n;
33
- }, O = (t, e, r) => {
34
- for (const i in { ...t, ...e })
35
- 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]));
36
- }, R = (t, e) => Array.isArray(t) && Array.isArray(e) ? t.some((r, i) => r !== e[i]) : t !== e, T = (t) => Array.from(t.attributes).reduce((e, r) => (e[r.name] = r.value, e), {}), W = (t, e, r) => {
37
- if (e.contains(document.activeElement)) {
38
- const i = e.nextSibling;
39
- for (; r && r != e; ) {
40
- const s = r.nextSibling;
41
- t.insertBefore(r, i), r = s;
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(e, r);
44
- }, j = (t) => {
45
- for (const e of t.children) j(e);
46
- typeof t.return == "function" && t.return(), t[b]?.(null);
47
- }, B = (t, e, r) => {
48
- r[o] ??= (F(r), t), Object.assign(r[a] ??= {}, e), r[y]();
49
- }, F = (t) => {
50
- Object.assign(t, I), t[h] = Object.create(l()?.[h] ?? null);
51
- }, I = {
52
- [y]() {
53
- const t = l();
54
- l(this);
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: e, done: r } = (this[c] ??= this[o].call(this, this[a])).next();
57
- m(e, this), this[b]?.(this), r && this.return();
58
- } catch (e) {
59
- this.throw(e);
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
- l(t);
60
+ f(t);
62
61
  }
63
62
  },
64
63
  next(t) {
65
64
  if (typeof t == "function") try {
66
- t.call(this, this[a]);
67
- } catch (e) {
68
- this.throw(e);
65
+ t.call(this, this[c]);
66
+ } catch (r) {
67
+ this.throw(r);
69
68
  }
70
- l()?.contains(this) || this[y]();
69
+ f()?.contains(this) || this[m]();
71
70
  },
72
71
  throw(t) {
73
- for (let e = this; e; e = e.parentNode) if (typeof e[c]?.throw == "function") try {
74
- return m(e[c].throw(t).value, e);
75
- } catch (r) {
76
- t = new Error(r instanceof Error ? r.message : r, { cause: t });
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[c]?.return();
81
+ this[a]?.return();
83
82
  } catch (t) {
84
83
  this.throw(t);
85
84
  } finally {
86
- this[c] = null;
85
+ this[a] = null;
87
86
  }
88
87
  }
89
88
  };
90
89
  export {
91
- M as Fragment,
92
- U as h,
93
- m as render
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.27",
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.3.0",
37
- "happy-dom": "18.0.1",
38
- "vite": "7.1.4",
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": "3.2.4"
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={true}
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<TProps extends Props = {}> = Stateless<TProps> | Stateful<TProps>
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: Element, child?: Node, ref?: Node): void
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' {