ajo 0.1.26 → 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/html.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./context.cjs"),m=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),g=new Set(["key","skip","memo","ref"]),b=new Set(["nodeName","children"]),S=Symbol.for("ajo.args"),y=e=>e.replace(/[&<>"']/g,r=>`&#${r.charCodeAt(0)};`),u=()=>{},w=e=>[...f(e)].join(""),f=function*(e,{alloc:r=u,push:t=u,placeholder:n=u}={}){for(e of d(e,{alloc:r,push:t,placeholder:n}))typeof e=="string"?yield y(e):yield*$(e,{alloc:r,push:t,placeholder:n})},$=function*(e,r){const{nodeName:t,children:n}=e;let l="";for(const i in e)b.has(i)||i.startsWith("set:")||e[i]==null||e[i]===!1||(e[i]===!0?l+=` ${i}`:l+=` ${i}="${y(String(e[i]))}"`);m.has(t)?yield`<${t}${l}>`:(yield`<${t}${l}>`,n!=null&&(yield*f(n,r)),yield`</${t}>`)},d=function*(e,r){if(e==null)return;const t=typeof e;if(t!="boolean")if(t=="string")yield e;else if(t=="number"||t=="bigint")yield String(e);else if(Symbol.iterator in e)for(e of e)yield*d(e,r);else"nodeName"in e?typeof e.nodeName=="function"?yield*v(e,r):yield o(e,r):yield String(e)},v=function*({nodeName:e,fallback:r=e.fallback,...t},n){const l=e.constructor.name;e.src?yield x(e.src,t,n):l=="GeneratorFunction"?yield A(e,t,n):l=="AsyncGeneratorFunction"?yield j(e,r,t,n):(t=e(t),typeof t?.then=="function"?yield G(r,t,n):yield*d(t,n))},x=(e,r,t)=>{const n=t.alloc();return t.push({id:n,src:e,h:o(r,t),done:!0}),t.placeholder(n)},A=(e,r,t)=>{const n={...e.attrs},l={...e.args};for(const c in r)c.startsWith("attr:")?n[c.slice(5)]=r[c]:g.has(c)||c.startsWith("set:")?n[c]=r[c]:l[c]=r[c];const i={[a.Context]:Object.create(a.current()?.[a.Context]??null),[S]:l,next:u,return:u,throw:c=>{throw c}},s=e.call(i,l),p=a.current();a.current(i);try{const c=[...d(s.next().value,t)];return{...n,nodeName:e.is??"div",children:c.length==1?c[0]:c}}finally{s.return?.(),a.current(p)}},j=(e,r,t,n)=>{const l=n.alloc();return Promise.resolve().then(async()=>{const i=e(t);n={...n,alloc:(s=l)=>n.alloc(s)};try{for(t=await i.next();!t.done;)n.push({id:l,h:o(t.value,n),done:!1}),t=await i.next();n.push({id:l,h:o(t.value,n),done:!0})}catch(s){n.push({id:l,h:o(s,n),done:!0})}finally{i.return?.()}}),n.placeholder(l,r)},G=(e,r,t)=>{const n=t.alloc();return r.then(l=>t.push({id:n,h:o(l,{...t,alloc:(i=n)=>t.alloc(i)}),done:!0})),t.placeholder(n,e)},o=({key:e,skip:r,memo:t,ref:n,...l},i)=>{if("children"in l){const s=[...d(l.children,i)];s.length?l.children=s.length==1?s[0]:s:delete l.children}return l};exports.html=f;exports.render=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./context.cjs"),g=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),m=Symbol.for("ajo.args"),y=e=>e.replace(/[&<>"']/g,r=>`&#${r.charCodeAt(0)};`),o=()=>{},b=e=>[...f(e)].join(""),f=function*(e,{alloc:r=o,push:t=o,placeholder:n=o}={}){for(e of d(e,{alloc:r,push:t,placeholder:n}))typeof e=="string"?yield y(e):yield*$(e,{alloc:r,push:t,placeholder:n})},$=function*({nodeName:e,children:r,...t},n){let l="";for(const i in t)i.startsWith("set:")||t[i]==null||t[i]===!1||(t[i]===!0?l+=` ${i}`:l+=` ${i}="${y(String(t[i]))}"`);g.has(e)?yield`<${e}${l}>`:(yield`<${e}${l}>`,r!=null&&(yield*f(r,n)),yield`</${e}>`)},d=function*(e,r){if(e==null)return;const t=typeof e;if(t!="boolean")if(t=="string")yield e;else if(t=="number"||t=="bigint")yield String(e);else if(Symbol.iterator in e)for(e of e)yield*d(e,r);else"nodeName"in e?typeof e.nodeName=="function"?yield*v(e,r):yield u(e,r):yield String(e)},v=function*({nodeName:e,fallback:r=e.fallback,...t},n){const l=e.constructor.name;e.src?yield w(e.src,t,n):l=="GeneratorFunction"?yield S(e,t,n):l=="AsyncGeneratorFunction"?yield x(e,r,t,n):(t=e(t),typeof t?.then=="function"?yield A(r,t,n):yield*d(t,n))},w=(e,r,t)=>{const n=t.alloc();return t.push({id:n,src:e,h:u(r,t),done:!0}),t.placeholder(n)},S=(e,r,t)=>{const n={...e.attrs},l={...e.args};for(const c in r)c.startsWith("attr:")?n[c.slice(5)]=r[c]:c=="key"||c=="skip"||c=="memo"||c=="ref"||c.startsWith("set:")?n[c]=r[c]:l[c]=r[c];const i={[a.Context]:Object.create(a.current()?.[a.Context]??null),[m]:l,next:o,return:o,throw:c=>{throw c}},s=e.call(i,l),p=a.current();a.current(i);try{const c=[...d(s.next().value,t)];return{...n,nodeName:e.is??"div",children:c.length==1?c[0]:c}}finally{s.return?.(),a.current(p)}},x=(e,r,t,n)=>{const l=n.alloc();return Promise.resolve().then(async()=>{const i=e(t);n={...n,alloc:(s=l)=>n.alloc(s)};try{for(t=await i.next();!t.done;)n.push({id:l,h:u(t.value,n),done:!1}),t=await i.next();n.push({id:l,h:u(t.value,n),done:!0})}catch(s){n.push({id:l,h:u(s,n),done:!0})}finally{i.return?.()}}),n.placeholder(l,r)},A=(e,r,t)=>{const n=t.alloc();return r.then(l=>t.push({id:n,h:u(l,{...t,alloc:(i=n)=>t.alloc(i)}),done:!0})),t.placeholder(n,e)},u=({key:e,skip:r,memo:t,ref:n,...l},i)=>{if("children"in l){const s=[...d(l.children,i)];s.length?l.children=s.length==1?s[0]:s:delete l.children}return l};exports.html=f;exports.render=b;
package/dist/html.js CHANGED
@@ -1,74 +1,73 @@
1
- import { Context as f, current as d } from "./context.js";
2
- const g = /* @__PURE__ */ new Set(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]), b = /* @__PURE__ */ new Set(["key", "skip", "memo", "ref"]), w = /* @__PURE__ */ new Set(["nodeName", "children"]), S = Symbol.for("ajo.args"), y = (e) => e.replace(/[&<>"']/g, (r) => `&#${r.charCodeAt(0)};`), o = () => {
3
- }, C = (e) => [...p(e)].join(""), p = function* (e, { alloc: r = o, push: t = o, placeholder: n = o } = {}) {
4
- for (e of u(e, { alloc: r, push: t, placeholder: n }))
5
- typeof e == "string" ? yield y(e) : yield* $(e, { alloc: r, push: t, placeholder: n });
6
- }, $ = function* (e, r) {
7
- const { nodeName: t, children: n } = e;
8
- let i = "";
9
- for (const l in e)
10
- w.has(l) || l.startsWith("set:") || e[l] == null || e[l] === !1 || (e[l] === !0 ? i += ` ${l}` : i += ` ${l}="${y(String(e[l]))}"`);
11
- g.has(t) ? yield `<${t}${i}>` : (yield `<${t}${i}>`, n != null && (yield* p(n, r)), yield `</${t}>`);
12
- }, u = function* (e, r) {
1
+ import { Context as y, current as f } from "./context.js";
2
+ const m = /* @__PURE__ */ new Set(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]), b = Symbol.for("ajo.args"), d = (e) => e.replace(/[&<>"']/g, (r) => `&#${r.charCodeAt(0)};`), u = () => {
3
+ }, j = (e) => [...p(e)].join(""), p = function* (e, { alloc: r = u, push: t = u, placeholder: n = u } = {}) {
4
+ for (e of o(e, { alloc: r, push: t, placeholder: n }))
5
+ typeof e == "string" ? yield d(e) : yield* $(e, { alloc: r, push: t, placeholder: n });
6
+ }, $ = function* ({ nodeName: e, children: r, ...t }, n) {
7
+ let l = "";
8
+ for (const i in t)
9
+ i.startsWith("set:") || t[i] == null || t[i] === !1 || (t[i] === !0 ? l += ` ${i}` : l += ` ${i}="${d(String(t[i]))}"`);
10
+ m.has(e) ? yield `<${e}${l}>` : (yield `<${e}${l}>`, r != null && (yield* p(r, n)), yield `</${e}>`);
11
+ }, o = function* (e, r) {
13
12
  if (e == null) return;
14
13
  const t = typeof e;
15
14
  if (t != "boolean")
16
15
  if (t == "string") yield e;
17
16
  else if (t == "number" || t == "bigint") yield String(e);
18
- else if (Symbol.iterator in e) for (e of e) yield* u(e, r);
19
- else "nodeName" in e ? typeof e.nodeName == "function" ? yield* v(e, r) : yield a(e, r) : yield String(e);
20
- }, v = function* ({ nodeName: e, fallback: r = e.fallback, ...t }, n) {
21
- const i = e.constructor.name;
22
- e.src ? yield x(e.src, t, n) : i == "GeneratorFunction" ? yield A(e, t, n) : i == "AsyncGeneratorFunction" ? yield G(e, r, t, n) : (t = e(t), typeof t?.then == "function" ? yield j(r, t, n) : yield* u(t, n));
23
- }, x = (e, r, t) => {
17
+ else if (Symbol.iterator in e) for (e of e) yield* o(e, r);
18
+ else "nodeName" in e ? typeof e.nodeName == "function" ? yield* w(e, r) : yield a(e, r) : yield String(e);
19
+ }, w = function* ({ nodeName: e, fallback: r = e.fallback, ...t }, n) {
20
+ const l = e.constructor.name;
21
+ e.src ? yield v(e.src, t, n) : l == "GeneratorFunction" ? yield x(e, t, n) : l == "AsyncGeneratorFunction" ? yield S(e, r, t, n) : (t = e(t), typeof t?.then == "function" ? yield A(r, t, n) : yield* o(t, n));
22
+ }, v = (e, r, t) => {
24
23
  const n = t.alloc();
25
24
  return t.push({ id: n, src: e, h: a(r, t), done: !0 }), t.placeholder(n);
26
- }, A = (e, r, t) => {
27
- const n = { ...e.attrs }, i = { ...e.args };
25
+ }, x = (e, r, t) => {
26
+ const n = { ...e.attrs }, l = { ...e.args };
28
27
  for (const c in r)
29
- c.startsWith("attr:") ? n[c.slice(5)] = r[c] : b.has(c) || c.startsWith("set:") ? n[c] = r[c] : i[c] = r[c];
30
- const l = {
31
- [f]: Object.create(d()?.[f] ?? null),
32
- [S]: i,
33
- next: o,
34
- return: o,
28
+ c.startsWith("attr:") ? n[c.slice(5)] = r[c] : c == "key" || c == "skip" || c == "memo" || c == "ref" || c.startsWith("set:") ? n[c] = r[c] : l[c] = r[c];
29
+ const i = {
30
+ [y]: Object.create(f()?.[y] ?? null),
31
+ [b]: l,
32
+ next: u,
33
+ return: u,
35
34
  throw: (c) => {
36
35
  throw c;
37
36
  }
38
- }, s = e.call(l, i), m = d();
39
- d(l);
37
+ }, s = e.call(i, l), g = f();
38
+ f(i);
40
39
  try {
41
- const c = [...u(s.next().value, t)];
40
+ const c = [...o(s.next().value, t)];
42
41
  return { ...n, nodeName: e.is ?? "div", children: c.length == 1 ? c[0] : c };
43
42
  } finally {
44
- s.return?.(), d(m);
43
+ s.return?.(), f(g);
45
44
  }
46
- }, G = (e, r, t, n) => {
47
- const i = n.alloc();
45
+ }, S = (e, r, t, n) => {
46
+ const l = n.alloc();
48
47
  return Promise.resolve().then(async () => {
49
- const l = e(t);
50
- n = { ...n, alloc: (s = i) => n.alloc(s) };
48
+ const i = e(t);
49
+ n = { ...n, alloc: (s = l) => n.alloc(s) };
51
50
  try {
52
- for (t = await l.next(); !t.done; )
53
- n.push({ id: i, h: a(t.value, n), done: !1 }), t = await l.next();
54
- n.push({ id: i, h: a(t.value, n), done: !0 });
51
+ for (t = await i.next(); !t.done; )
52
+ n.push({ id: l, h: a(t.value, n), done: !1 }), t = await i.next();
53
+ n.push({ id: l, h: a(t.value, n), done: !0 });
55
54
  } catch (s) {
56
- n.push({ id: i, h: a(s, n), done: !0 });
55
+ n.push({ id: l, h: a(s, n), done: !0 });
57
56
  } finally {
58
- l.return?.();
57
+ i.return?.();
59
58
  }
60
- }), n.placeholder(i, r);
61
- }, j = (e, r, t) => {
59
+ }), n.placeholder(l, r);
60
+ }, A = (e, r, t) => {
62
61
  const n = t.alloc();
63
- return r.then((i) => t.push({ id: n, h: a(i, { ...t, alloc: (l = n) => t.alloc(l) }), done: !0 })), t.placeholder(n, e);
64
- }, a = ({ key: e, skip: r, memo: t, ref: n, ...i }, l) => {
65
- if ("children" in i) {
66
- const s = [...u(i.children, l)];
67
- s.length ? i.children = s.length == 1 ? s[0] : s : delete i.children;
62
+ return r.then((l) => t.push({ id: n, h: a(l, { ...t, alloc: (i = n) => t.alloc(i) }), done: !0 })), t.placeholder(n, e);
63
+ }, a = ({ key: e, skip: r, memo: t, ref: n, ...l }, i) => {
64
+ if ("children" in l) {
65
+ const s = [...o(l.children, i)];
66
+ s.length ? l.children = s.length == 1 ? s[0] : s : delete l.children;
68
67
  }
69
- return i;
68
+ return l;
70
69
  };
71
70
  export {
72
71
  p as html,
73
- C as render
72
+ j as render
74
73
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./context.cjs"),a=Symbol.for("ajo.keyed"),l=Symbol.for("ajo.key"),p=Symbol.for("ajo.memo"),u=Symbol.for("ajo.ref"),w=Symbol.for("ajo.cache"),g=Symbol.for("ajo.generator"),c=Symbol.for("ajo.iterator"),m=Symbol.for("ajo.render"),b=Symbol.for("ajo.args"),A=e=>e.children,v=(e,t,...r)=>((t??={}).nodeName=e,!("children"in t)&&r.length&&(t.children=r.length==1?r[0]:r),t),f=(e,t)=>{let r=t.firstChild;for(e of S(e)){const n=k(e,t,r);r==null?t.appendChild(n):n==r?r=n.nextSibling:n==r.nextSibling?(t.appendChild(r),r=n.nextSibling):M(t,n,r)}for(;r;){const n=r.nextSibling;r.nodeType==1&&j(t,r),t.removeChild(r),r=n}},S=function*(e){if(e==null)return;const t=typeof e;if(t!="boolean")if(t=="string")yield e;else if(t=="number"||t=="bigint")yield String(e);else if(Symbol.iterator in e)for(e of e)yield*S(e);else"nodeName"in e?typeof e.nodeName=="function"?yield*C(e):yield e:yield String(e)},C=function*({nodeName:e,...t}){e.constructor.name=="GeneratorFunction"?yield N(e,t):yield*S(e(t))},N=function(e,t){const r={...e.attrs},n={...e.args};for(const i in t)i.startsWith("attr:")?r[i.slice(5)]=t[i]:i=="key"||i=="memo"||i.startsWith("set:")?r[i]=t[i]:n[i]=t[i];return{...r,nodeName:e.is??"div",skip:!0,ref:R.bind(null,e,n)}},k=(e,t,r)=>typeof e=="string"?E(e,r):O(e,t,r),E=(e,t)=>{for(;t&&t.nodeType!=3;)t=t.nextSibling;return t?t.data!=e&&(t.data=e):t=document.createTextNode(e),t},O=({nodeName:e,children:t,key:r,skip:n,memo:i,ref:x,...h},y,s)=>{for(r!=null&&(s=(y[a]??=new Map).get(r)??(s?.[l]==null?s:null));s&&s.localName!=e;)s=s.nextSibling;return s??=document.createElementNS(h.xmlns??y.namespaceURI,e),r!=s[l]&&y[a].set(s[l]=r,s),(i==null||F(s[p],s[p]=i))&&(T(s[w]??G(s),s[w]=h,s),n||f(t,s),typeof x=="function"&&(s[u]=x)(s)),s},T=(e,t,r)=>{for(const n in{...e,...t})e[n]!==t[n]&&(n.startsWith("set:")?r[n.slice(4)]=t[n]:t[n]==null||t[n]===!1?r.removeAttribute(n):r.setAttribute(n,t[n]===!0?"":t[n]))},F=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.some((r,n)=>r!==t[n]):e!==t,G=e=>Array.from(e.attributes).reduce((t,r)=>(t[r.name]=r.value,t),{}),M=(e,t,r)=>{if(t.contains(document.activeElement)){const n=t.nextSibling;for(;r&&r!=t;){const i=r.nextSibling;e.insertBefore(r,n),r=i}}else e.insertBefore(t,r)},j=(e,t)=>{for(const r of t.children)j(t,r);e[a]?.delete(t[l]),t[a]?.clear(),t[u]?.(null),t[g]&&=null},R=(e,{skip:t,ref:r,...n},i)=>{i&&(i[g]??=(W(i),e),i[u]=B.bind(null,r,i),Object.assign(i[b]??={},n),t||i[m]())},W=e=>{Object.assign(e,I),e[o.Context]=Object.create(o.current()?.[o.Context]??null)},B=(e,t,r)=>{typeof e=="function"&&e(r),r||t.return()},I={[m](){const e=o.current();o.current(this);try{const{value:t,done:r}=(this[c]??=this[g].call(this,this[b])).next();f(t,this),this[u]?.(this),r&&this.return()}catch(t){this.throw(t)}finally{o.current(e)}},next(e){if(typeof e=="function")try{e.call(this,this[b])}catch(t){this.throw(t)}o.current()?.contains(this)||this[m]()},throw(e){for(let t=this;t;t=t.parentNode)if(typeof t[c]?.throw=="function")try{return f(t[c].throw(e).value,t)}catch(r){e=new Error(r instanceof Error?r.message:r,{cause:e})}throw e},return(){try{this[c]?.return()}catch(e){this.throw(e)}finally{this[c]=null}}};exports.Fragment=A;exports.h=v;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,96 +1,93 @@
1
- import { Context as p, current as c } from "./context.js";
2
- const a = Symbol.for("ajo.keyed"), l = Symbol.for("ajo.key"), w = Symbol.for("ajo.memo"), f = Symbol.for("ajo.ref"), j = Symbol.for("ajo.cache"), g = Symbol.for("ajo.generator"), o = Symbol.for("ajo.iterator"), y = Symbol.for("ajo.render"), m = Symbol.for("ajo.args"), M = (e) => e.children, U = (e, t, ...r) => ((t ??= {}).nodeName = e, !("children" in t) && r.length && (t.children = r.length == 1 ? r[0] : r), t), b = (e, t) => {
3
- let r = t.firstChild;
4
- for (e of S(e)) {
5
- const i = N(e, t, r);
6
- r == null ? t.appendChild(i) : i == r ? r = i.nextSibling : i == r.nextSibling ? (t.appendChild(r), r = i.nextSibling) : T(t, 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 && A(t, r), t.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
- }, S = function* (e) {
13
- if (e == null) return;
14
- const t = typeof e;
15
- if (t != "boolean")
16
- if (t == "string") yield e;
17
- else if (t == "number" || t == "bigint") yield String(e);
18
- else if (Symbol.iterator in e) for (e of e) yield* S(e);
19
- else "nodeName" in e ? typeof e.nodeName == "function" ? yield* v(e) : yield e : yield String(e);
20
- }, v = function* ({ nodeName: e, ...t }) {
21
- e.constructor.name == "GeneratorFunction" ? yield C(e, t) : yield* S(e(t));
22
- }, C = function(e, t) {
23
- const r = { ...e.attrs }, i = { ...e.args };
24
- for (const n in t)
25
- n.startsWith("attr:") ? r[n.slice(5)] = t[n] : n == "key" || n == "memo" || n.startsWith("set:") ? r[n] = t[n] : i[n] = t[n];
26
- return { ...r, nodeName: e.is ?? "div", skip: !0, ref: W.bind(null, e, i) };
27
- }, N = (e, t, r) => typeof e == "string" ? k(e, r) : E(e, t, r), k = (e, t) => {
28
- for (; t && t.nodeType != 3; ) t = t.nextSibling;
29
- return t ? t.data != e && (t.data = e) : t = document.createTextNode(e), t;
30
- }, E = ({ nodeName: e, children: t, key: r, skip: i, memo: n, ref: x, ...h }, u, s) => {
31
- for (r != null && (s = (u[a] ??= /* @__PURE__ */ new Map()).get(r) ?? (s?.[l] == null ? s : null)); s && s.localName != e; ) s = s.nextSibling;
32
- return s ??= document.createElementNS(h.xmlns ?? u.namespaceURI, e), r != s[l] && u[a].set(s[l] = r, s), (n == null || O(s[w], s[w] = n)) && (G(s[j] ?? R(s), s[j] = h, s), i || b(t, s), typeof x == "function" && (s[f] = x)(s)), s;
33
- }, G = (e, t, r) => {
34
- for (const i in { ...e, ...t })
35
- e[i] !== t[i] && (i.startsWith("set:") ? r[i.slice(4)] = t[i] : t[i] == null || t[i] === !1 ? r.removeAttribute(i) : r.setAttribute(i, t[i] === !0 ? "" : t[i]));
36
- }, O = (e, t) => Array.isArray(e) && Array.isArray(t) ? e.some((r, i) => r !== t[i]) : e !== t, R = (e) => Array.from(e.attributes).reduce((t, r) => (t[r.name] = r.value, t), {}), T = (e, t, r) => {
37
- if (t.contains(document.activeElement)) {
38
- const i = t.nextSibling;
39
- for (; r && r != t; ) {
40
- const n = r.nextSibling;
41
- e.insertBefore(r, i), r = n;
11
+ }, S = function* (t) {
12
+ if (t == null) return;
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);
18
+ else "nodeName" in t ? typeof t.nodeName == "function" ? yield* C(t) : yield t : yield String(t);
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 e.insertBefore(t, r);
44
- }, A = (e, t) => {
45
- for (const r of t.children) A(t, r);
46
- e[a]?.delete(t[l]), t[a]?.clear(), t[f]?.(null), t[g] &&= null;
47
- }, W = (e, { skip: t, ref: r, ...i }, n) => {
48
- n && (n[g] ??= (B(n), e), n[f] = F.bind(null, r, n), Object.assign(n[m] ??= {}, i), t || n[y]());
49
- }, B = (e) => {
50
- Object.assign(e, I), e[p] = Object.create(c()?.[p] ?? null);
51
- }, F = (e, t, r) => {
52
- typeof e == "function" && e(r), r || t.return();
53
- }, I = {
54
- [y]() {
55
- const e = c();
56
- c(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);
57
54
  try {
58
- const { value: t, done: r } = (this[o] ??= this[g].call(this, this[m])).next();
59
- b(t, this), this[f]?.(this), r && this.return();
60
- } catch (t) {
61
- this.throw(t);
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);
62
59
  } finally {
63
- c(e);
60
+ f(t);
64
61
  }
65
62
  },
66
- next(e) {
67
- if (typeof e == "function") try {
68
- e.call(this, this[m]);
69
- } catch (t) {
70
- this.throw(t);
63
+ next(t) {
64
+ if (typeof t == "function") try {
65
+ t.call(this, this[c]);
66
+ } catch (r) {
67
+ this.throw(r);
71
68
  }
72
- c()?.contains(this) || this[y]();
69
+ f()?.contains(this) || this[m]();
73
70
  },
74
- throw(e) {
75
- for (let t = this; t; t = t.parentNode) if (typeof t[o]?.throw == "function") try {
76
- return b(t[o].throw(e).value, t);
77
- } catch (r) {
78
- e = new Error(r instanceof Error ? r.message : r, { cause: e });
71
+ throw(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 });
79
76
  }
80
- throw e;
77
+ throw t;
81
78
  },
82
79
  return() {
83
80
  try {
84
- this[o]?.return();
85
- } catch (e) {
86
- this.throw(e);
81
+ this[a]?.return();
82
+ } catch (t) {
83
+ this.throw(t);
87
84
  } finally {
88
- this[o] = null;
85
+ this[a] = null;
89
86
  }
90
87
  }
91
88
  };
92
89
  export {
93
- M as Fragment,
94
- U as h,
90
+ U as Fragment,
91
+ h,
95
92
  b as render
96
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajo",
3
- "version": "0.1.26",
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
@@ -36,24 +36,23 @@ npm install ajo
36
36
  Create your first component:
37
37
 
38
38
  ```javascript
39
- import { render } from 'ajo';
39
+ import { render } from 'ajo'
40
40
 
41
41
  // Stateless component
42
42
  const Greeting = ({ name }) => <p>Hello, {name}!</p>
43
43
 
44
44
  // Stateful component
45
45
  function* Counter() {
46
+
46
47
  let count = 0
47
48
 
48
49
  const increment = () => this.next(() => count++)
49
50
 
50
- while (true) {
51
- yield (
52
- <button set:onclick={increment}>
53
- Count: {count}
54
- </button>
55
- );
56
- }
51
+ while (true) yield (
52
+ <button set:onclick={increment}>
53
+ Count: {count}
54
+ </button>
55
+ )
57
56
  }
58
57
 
59
58
  // Render to DOM
@@ -77,26 +76,19 @@ const UserCard = ({ user }) => (
77
76
  **Stateful Components** use generator functions with automatic wrapper elements:
78
77
  ```javascript
79
78
  function* TodoList() {
79
+
80
80
  let todos = []
81
81
 
82
- const addTodo = (text) => {
83
- this.next(() => todos.push({ id: Date.now(), text }))
84
- };
85
-
86
- while (true) {
87
- yield (
88
- <>
89
- <input set:onkeydown={(e) => {
90
- if (e.key === 'Enter') addTodo(e.target.value);
91
- }} />
92
- <ul>
93
- {todos.map(todo => (
94
- <li key={todo.id}>{todo.text}</li>
95
- ))}
96
- </ul>
97
- </>
98
- );
99
- }
82
+ const addTodo = text => this.next(() => todos.push({ id: Date.now(), text }))
83
+
84
+ while (true) yield (
85
+ <>
86
+ <input set:onkeydown={e => e.key === 'Enter' && addTodo(e.target.value)} />
87
+ <ul>
88
+ {todos.map(todo => <li key={todo.id}>{todo.text}</li>)}
89
+ </ul>
90
+ </>
91
+ )
100
92
  }
101
93
  ```
102
94
 
@@ -108,27 +100,27 @@ The generator structure provides a natural mental model:
108
100
 
109
101
  ```javascript
110
102
  function* ShoppingCart(args) {
103
+
111
104
  // Persistent state (like useState)
112
105
  let items = []
113
-
106
+
114
107
  // Persistent handlers (like useCallback)
115
- const addItem = (product) => {
116
- this.next(() => items.push(product))
117
- };
108
+ const addItem = product => this.next(() => items.push(product))
118
109
 
119
110
  // Main render loop
120
111
  while (true) {
112
+
121
113
  // Derived values computed fresh each render
122
114
  const total = items.reduce((sum, item) => sum + item.price, 0)
123
115
  const itemCount = items.length
124
-
116
+
125
117
  yield (
126
118
  <>
127
119
  <h2>Cart ({itemCount} items)</h2>
128
120
  <p>Total: ${total}</p>
129
121
  {/* ... */}
130
122
  </>
131
- );
123
+ )
132
124
  }
133
125
  }
134
126
  ```
@@ -144,26 +136,23 @@ function* ShoppingCart(args) {
144
136
 
145
137
  ```javascript
146
138
  function* MapComponent(args) {
139
+
147
140
  let mapRef = null
148
-
149
- while (true) {
150
- yield (
151
- <div
152
- ref={el => {
153
- if (el && !mapRef) {
154
- mapRef = el
155
- // Third-party map library controls this DOM
156
- new GoogleMap(el, args.config)
157
- }
158
- }}
159
- skip={true}
160
- >
161
- {/* Google Maps API manages these elements */}
162
- <div class="map-controls"></div>
163
- <div class="map-markers"></div>
164
- </div>
165
- );
166
- }
141
+
142
+ while (true) yield (
143
+ <div
144
+ ref={el => {
145
+ if (el && !mapRef) {
146
+ mapRef = el
147
+ // Third-party map library controls this DOM
148
+ new GoogleMap(el, args.config)
149
+ }
150
+ }}
151
+ skip
152
+ >
153
+ {/* Google Maps API manages children elements */}
154
+ </div>
155
+ )
167
156
  }
168
157
  ```
169
158
 
@@ -178,11 +167,9 @@ const html = render(<App />)
178
167
 
179
168
  ### Streaming SSR
180
169
  ```javascript
181
- import { stream } from 'ajo/stream';
170
+ import { stream } from 'ajo/stream'
182
171
 
183
- for await (const chunk of stream(<App />)) {
184
- response.write(chunk);
185
- }
172
+ for await (const chunk of stream(<App />)) response.write(chunk)
186
173
  ```
187
174
 
188
175
  ## Best Practices
@@ -196,13 +183,17 @@ for await (const chunk of stream(<App />)) {
196
183
 
197
184
  ### Core Module (`ajo`)
198
185
 
199
- #### `render(children: Children, container: Element): void`
200
- 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.
201
188
 
202
189
  ```javascript
203
- import { render } from 'ajo';
190
+ import { render } from 'ajo'
204
191
 
205
- render(<App />, document.getElementById('root'));
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'))
206
197
  ```
207
198
 
208
199
  #### `h(type: Type, props?: Props, ...children: Children[]): VNode`
@@ -217,7 +208,7 @@ const List = () => (
217
208
  <li>Item 1</li>
218
209
  <li>Item 2</li>
219
210
  </>
220
- );
211
+ )
221
212
  ```
222
213
 
223
214
  ### Stateful Component Instance Methods
@@ -229,17 +220,18 @@ Triggers a re-render of the component by advancing to the next yield point. Opti
229
220
 
230
221
  ```javascript
231
222
  function* Counter(args) {
232
- let count = 0;
223
+
224
+ let count = 0
233
225
 
234
226
  const increment = () => {
235
227
  // Simple re-render
236
- this.next(() => count++);
237
- };
228
+ this.next(() => count++)
229
+ }
238
230
 
239
231
  const incrementByStep = () => {
240
232
  // Access current props in callback
241
- this.next(({ step }) => count += step);
242
- };
233
+ this.next(({ step }) => count += step)
234
+ }
243
235
 
244
236
  // ... rest of component
245
237
  }
@@ -257,15 +249,15 @@ Terminates the generator and triggers cleanup (rarely used directly).
257
249
  Creates a context for sharing data across component trees.
258
250
 
259
251
  ```javascript
260
- import { context } from 'ajo/context';
252
+ import { context } from 'ajo/context'
261
253
 
262
- const ThemeContext = context('light');
254
+ const ThemeContext = context('light')
263
255
 
264
256
  // Set value
265
- ThemeContext('dark');
257
+ ThemeContext('dark')
266
258
 
267
259
  // Get value
268
- const theme = ThemeContext(); // 'dark'
260
+ const theme = ThemeContext() // 'dark'
269
261
  ```
270
262
 
271
263
  ### HTML Module (`ajo/html`)
@@ -274,9 +266,9 @@ const theme = ThemeContext(); // 'dark'
274
266
  Renders JSX to an HTML string for static site generation.
275
267
 
276
268
  ```javascript
277
- import { render } from 'ajo/html';
269
+ import { render } from 'ajo/html'
278
270
 
279
- const html = render(<HomePage title="Welcome" />);
271
+ const html = render(<HomePage title="Welcome" />)
280
272
  ```
281
273
 
282
274
  #### `html(children: Children, hooks?: Hooks): IterableIterator<string>`
@@ -288,54 +280,52 @@ Low-level HTML streaming function with custom hooks.
288
280
  Renders components to an async stream for progressive SSR.
289
281
 
290
282
  ```javascript
291
- import { stream } from 'ajo/stream';
283
+ import { stream } from 'ajo/stream'
292
284
 
293
- for await (const chunk of stream(<App />)) {
294
- response.write(chunk);
295
- }
285
+ for await (const chunk of stream(<App />)) response.write(chunk)
296
286
  ```
297
287
 
298
288
  #### `hydrate(patch: Patch): Promise<void>`
299
289
  Client-side function for applying streamed patches during hydration.
300
290
 
301
291
  ```javascript
302
- import { hydrate } from 'ajo/stream';
292
+ import { hydrate } from 'ajo/stream'
303
293
 
304
- window.$stream = { push: hydrate };
294
+ window.$stream = { push: hydrate }
305
295
  ```
306
296
 
307
297
  ### TypeScript Support
308
298
 
309
299
  ```typescript
310
300
  // Component types
311
- type Stateless<Props = {}> = (props: Props) => Children;
301
+ type Stateless<Props = {}> = (props: Props) => Children
312
302
  type Stateful<Props = {}, Tag = 'div'> = {
313
- (this: StatefulElement<Tag>, props: Props): Iterator<Children>;
314
- is?: Tag;
315
- attrs?: Record<string, unknown>;
316
- args?: Partial<Props>;
317
- };
303
+ (this: StatefulElement<Tag>, props: Props): Iterator<Children>
304
+ is?: Tag
305
+ attrs?: Record<string, unknown>
306
+ args?: Partial<Props>
307
+ }
318
308
 
319
309
  // Stateful component instance
320
310
  type StatefulElement<Tag> = HTMLElement & {
321
- next: (callback?: (args: ComponentArgs) => void) => void;
322
- throw: (error: unknown) => void;
323
- return: () => void;
311
+ next: (callback?: (args: ComponentArgs) => void) => void
312
+ throw: (error: unknown) => void
313
+ return: () => void
324
314
  };
325
315
 
326
316
  // Element types
327
- type Children = unknown;
317
+ type Children = unknown
328
318
  type VNode<Type, Props> = Props & {
329
- nodeName: Type;
330
- children?: Children;
319
+ nodeName: Type
320
+ children?: Children
331
321
  };
332
322
 
333
323
  // Special attributes
334
324
  type SpecialAttributes = {
335
- key?: unknown;
336
- ref?: (element: Element | null) => void;
337
- memo?: unknown[];
338
- skip?: boolean;
325
+ key?: unknown
326
+ ref?: (element: Element | null) => void
327
+ memo?: unknown[]
328
+ skip?: boolean
339
329
  };
340
330
  ```
341
331
 
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' {