ajo 0.1.15 → 0.1.18

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{assign:p,entries:$,hasOwn:g}=Object,f=e=>typeof e!="string"&&typeof(e==null?void 0:e[Symbol.iterator])=="function",c=e=>[...y(e)].join(""),y=function*(e){for(e of d(e))if(typeof e=="string")yield m(e);else{const{nodeName:t,skip:o,children:i=""}=e;let n="";for(const[l,r]of $(e))v.has(l)||l.startsWith("set:")||r==null||r===!1||(n+=r===!0?`${n} ${l}`:`${n} ${l}="${m(String(r))}"`);k.has(t)?yield`<${t}${n}>`:o?yield`<${t}${n}></${t}>`:typeof i=="string"?yield`<${t}${n}>${i}</${t}>`:(yield`<${t}${n}>`,yield*y(i),yield`</${t}>`)}},d=function*(e,t={value:""},o=!0){for(e of f(e)?e:[e])if(!(e==null||typeof e=="boolean"))if(g(e,"nodeName")){const{value:i}=t,{nodeName:n}=e,l=typeof n;if(i&&(yield i,t.value=""),l==="function")if(delete e.nodeName,n.constructor.name==="GeneratorFunction"){const r={},s=p({},n.attrs);for(const a in e){const u=e[a];a.startsWith("attr:")?s[a.slice(5)]=u:r[a]=u}s.nodeName=n.is??"div",s.children=w(n,r),yield s}else delete e.nodeName,yield*d(n(e),t,!1);else l==="string"&&(yield e)}else f(e)?yield*d(e,t,!1):t.value+=e;o&&t.value&&(yield t.value)},k=new Set("area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",")),v=new Set("nodeName,key,skip,memo,ref,children".split(",")),m=e=>e.replace(/[&<>"']/g,t=>`&#${t.charCodeAt(0)};`),w=(e,t)=>{let o,i;try{const n=e.call(o={$args:t,*[Symbol.iterator](){for(;;)yield t},refresh(){},next(){i=c(n.next().value)},throw(l){i=c(n.throw(l).value)},return(){n.return()}},t);o.next()}catch(n){o.throw(n)}finally{o.return()}return i};exports.html=y;exports.render=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const{create:p,assign:v,entries:g,hasOwn:x}=Object,{isArray:f,from:k}=Array,m="",c=e=>k(d(e)).join(""),d=function*(e){for(e of u(e))if(typeof e=="string")yield $(e);else{const{nodeName:t,skip:o,children:r=""}=e;let n="";for(const[l,i]of g(e))S.has(l)||l.startsWith("set:")||i==null||i===!1||(n+=i===!0?` ${l}`:` ${l}="${$(String(i))}"`);w.has(t)?yield`<${t}${n}>`:o?yield`<${t}${n}></${t}>`:(yield`<${t}${n}>`,typeof r=="string"&&r.startsWith(m)?yield r.slice(1):yield*d(r),yield`</${t}>`)}},u=function*(e,t={value:""},o=!0){for(e of f(e)?e:[e])if(!(e==null||typeof e=="boolean"))if(x(e,"nodeName")){const{value:r}=t,{nodeName:n}=e;if(r&&(yield r,t.value=""),typeof n=="function")if(n.constructor.name==="GeneratorFunction"){const l={},i=v({},n.attrs);for(const a in e){const y=e[a];a.startsWith("attr:")?i[a.slice(5)]=y:l[a]=y}i.nodeName=n.is??"div",i.children=N(n,l),yield i}else yield*u(n(e),t,!1);else yield e}else f(e)?yield*u(e,t,!1):t.value+=e;o&&t.value&&(yield t.value)},w=new Set("area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",")),S=new Set("nodeName,key,skip,memo,ref,children".split(",")),$=e=>e.replace(/[&<>"']/g,t=>`&#${t.charCodeAt(0)};`);let s=null;const N=(e,t)=>{let o,r;try{const n=e.call(o={$args:t,$context:p(s?s.$context:null),render(){s!==o&&o.$next()},$next(){const l=s;s=o,r=c(n.next().value),s=l},$throw(l){r=c(n.throw(l).value)},$return(){n.return()}},t);o.$next()}catch(n){o.$throw(n)}finally{o.$return()}return m+r},b=(e,t=Symbol())=>function(o,r){return arguments.length===1?t in o.$context?o.$context[t]:e:o.$context[t]=r};exports.context=b;exports.html=d;exports.render=c;
package/dist/html.js CHANGED
@@ -1,64 +1,64 @@
1
- const { assign: p, entries: $, hasOwn: g } = Object, y = (e) => typeof e != "string" && typeof (e == null ? void 0 : e[Symbol.iterator]) == "function", f = (e) => [...m(e)].join(""), m = function* (e) {
1
+ const { create: p, assign: v, entries: x, hasOwn: g } = Object, { isArray: d, from: k } = Array, f = "", y = (e) => k(m(e)).join(""), m = function* (e) {
2
2
  for (e of c(e))
3
- if (typeof e == "string")
4
- yield u(e);
3
+ if (typeof e == "string") yield $(e);
5
4
  else {
6
- const { nodeName: t, skip: o, children: i = "" } = e;
5
+ const { nodeName: t, skip: o, children: r = "" } = e;
7
6
  let n = "";
8
- for (const [l, s] of $(e))
9
- w.has(l) || l.startsWith("set:") || s == null || s === !1 || (n += s === !0 ? `${n} ${l}` : `${n} ${l}="${u(String(s))}"`);
10
- k.has(t) ? yield `<${t}${n}>` : o ? yield `<${t}${n}></${t}>` : typeof i == "string" ? yield `<${t}${n}>${i}</${t}>` : (yield `<${t}${n}>`, yield* m(i), yield `</${t}>`);
7
+ for (const [i, l] of x(e))
8
+ N.has(i) || i.startsWith("set:") || l == null || l === !1 || (n += l === !0 ? ` ${i}` : ` ${i}="${$(String(l))}"`);
9
+ w.has(t) ? yield `<${t}${n}>` : o ? yield `<${t}${n}></${t}>` : (yield `<${t}${n}>`, typeof r == "string" && r.startsWith(f) ? yield r.slice(1) : yield* m(r), yield `</${t}>`);
11
10
  }
12
11
  }, c = function* (e, t = { value: "" }, o = !0) {
13
- for (e of y(e) ? e : [e])
12
+ for (e of d(e) ? e : [e])
14
13
  if (!(e == null || typeof e == "boolean"))
15
14
  if (g(e, "nodeName")) {
16
- const { value: i } = t, { nodeName: n } = e, l = typeof n;
17
- if (i && (yield i, t.value = ""), l === "function")
18
- if (delete e.nodeName, n.constructor.name === "GeneratorFunction") {
19
- const s = {}, r = p({}, n.attrs);
15
+ const { value: r } = t, { nodeName: n } = e;
16
+ if (r && (yield r, t.value = ""), typeof n == "function")
17
+ if (n.constructor.name === "GeneratorFunction") {
18
+ const i = {}, l = v({}, n.attrs);
20
19
  for (const a in e) {
21
- const d = e[a];
22
- a.startsWith("attr:") ? r[a.slice(5)] = d : s[a] = d;
20
+ const u = e[a];
21
+ a.startsWith("attr:") ? l[a.slice(5)] = u : i[a] = u;
23
22
  }
24
- r.nodeName = n.is ?? "div", r.children = v(n, s), yield r;
25
- } else
26
- delete e.nodeName, yield* c(n(e), t, !1);
27
- else
28
- l === "string" && (yield e);
29
- } else
30
- y(e) ? yield* c(e, t, !1) : t.value += e;
23
+ l.nodeName = n.is ?? "div", l.children = S(n, i), yield l;
24
+ } else yield* c(n(e), t, !1);
25
+ else yield e;
26
+ } else d(e) ? yield* c(e, t, !1) : t.value += e;
31
27
  o && t.value && (yield t.value);
32
- }, k = new Set("area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",")), w = new Set("nodeName,key,skip,memo,ref,children".split(",")), u = (e) => e.replace(/[&<>"']/g, (t) => `&#${t.charCodeAt(0)};`), v = (e, t) => {
33
- let o, i;
28
+ }, w = new Set("area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",")), N = new Set("nodeName,key,skip,memo,ref,children".split(",")), $ = (e) => e.replace(/[&<>"']/g, (t) => `&#${t.charCodeAt(0)};`);
29
+ let s = null;
30
+ const S = (e, t) => {
31
+ let o, r;
34
32
  try {
35
33
  const n = e.call(o = {
36
34
  $args: t,
37
- *[Symbol.iterator]() {
38
- for (; ; )
39
- yield t;
35
+ $context: p(s ? s.$context : null),
36
+ render() {
37
+ s !== o && o.$next();
40
38
  },
41
- refresh() {
39
+ $next() {
40
+ const i = s;
41
+ s = o, r = y(n.next().value), s = i;
42
42
  },
43
- next() {
44
- i = f(n.next().value);
43
+ $throw(i) {
44
+ r = y(n.throw(i).value);
45
45
  },
46
- throw(l) {
47
- i = f(n.throw(l).value);
48
- },
49
- return() {
46
+ $return() {
50
47
  n.return();
51
48
  }
52
49
  }, t);
53
- o.next();
50
+ o.$next();
54
51
  } catch (n) {
55
- o.throw(n);
52
+ o.$throw(n);
56
53
  } finally {
57
- o.return();
54
+ o.$return();
58
55
  }
59
- return i;
56
+ return f + r;
57
+ }, A = (e, t = Symbol()) => function(o, r) {
58
+ return arguments.length === 1 ? t in o.$context ? o.$context[t] : e : o.$context[t] = r;
60
59
  };
61
60
  export {
61
+ A as context,
62
62
  m as html,
63
- f as render
63
+ y as render
64
64
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=({children:e})=>e,A=function(e,t){const{length:i}=arguments;return(t??(t=C(null))).nodeName=e,"children"in t||i<3||(t.children=i===3?arguments[2]:O.call(arguments,2)),t},d=(e,t)=>{let i=t.firstChild;for(e of h(e)){let n=i;if(typeof e=="string"){for(;n&&n.nodeType!=3;)n=n.nextSibling;n?n.data!=e&&(n.data=e):n=document.createTextNode(e)}else if(e instanceof Node)n=e;else{const{nodeName:o,key:a,skip:m,memo:r,ref:s,children:u}=e;for(;n&&!(n.localName===o&&(n.$key??(n.$key=a))==a);)n=n.nextSibling;if(n??(n=g(document.createElementNS(e.xmlns??o==="svg"?T:t.namespaceURI,o),{$key:a})),r==null||P(n.$memo,n.$memo=r)){const{$props:y}=n,w={};for(const l of p(g({},y,e))){if(q.has(l))continue;const f=w[l]=e[l];f!==(y==null?void 0:y[l])&&(l.startsWith("set:")?n[l.slice(4)]=f:f==null||f===!1?n.removeAttribute(l):n.setAttribute(l,f===!0?"":f))}n.$props=w,m||d(u,n),typeof s=="function"&&(n.$ref=s)(n)}}n===i?i=i.nextSibling:E(t,n,i)}for(;i;){const n=i.nextSibling;i.nodeType===1&&N(i),t.removeChild(i),i=n}},{isArray:$,prototype:{slice:O}}=Array,{create:C,keys:p,assign:g,hasOwn:F,setPrototypeOf:x,getPrototypeOf:v}=Object,T="http://www.w3.org/2000/svg",q=new Set("nodeName,key,skip,memo,ref,children".split(",")),S=e=>typeof e!="string"&&typeof(e==null?void 0:e[Symbol.iterator])=="function",P=(e,t)=>$(e)&&$(t)?e.some((i,n)=>i!==t[n]):e!==t,h=function*(e,t={value:""},i=!0){for(e of S(e)?e:[e])if(!(e==null||typeof e=="boolean"))if(F(e,"nodeName")){const{value:n}=t,{nodeName:o}=e,a=typeof o;if(n&&(yield n,t.value=""),a==="function")if(delete e.nodeName,o.constructor.name==="GeneratorFunction"){const m={},r=g({},o.attrs);for(const s of p(e)){const u=e[s];s.startsWith("attr:")&&(r[s.slice(5)]=u),s==="key"||s==="memo"?r[s]=u:m[s]=u}r.nodeName=o.is??"div",r.skip=!0,r.ref=j.bind(null,o,m),yield r}else yield*h(o(e),t,!1);else a==="string"&&(yield e)}else S(e)?yield*h(e,t,!1):t.value+=e;i&&t.value&&(yield t.value)},j=(e,t,i)=>{i&&(i.$gen??(i.$gen=(new W(i),e)),i.$ref=B.bind(null,i),i.$args=t,i.next())},B=(e,t)=>t??e.return(),E=(e,t,i)=>{if(t.contains(document.activeElement)){const n=t.nextSibling;for(;i&&i!=t;){const o=i.nextSibling;e.insertBefore(i,n),i=o}}else e.insertBefore(t,i)},N=e=>{for(const i of e.children)N(i);const{$ref:t}=e;typeof t=="function"&&t(null);for(const i of p(e))e[i]=null};let c,k;const I=()=>{for(const e of c)e.isConnected&&e.next();c.clear(),k=null};class W{constructor(t){x(t,x(v(this),v(t)))}*[Symbol.iterator](){for(;;)yield this.$args??{}}refresh(){(c??(c=new Set)).has(this)&&c.delete(this);for(const t of c){if(t.contains(this))return;this.contains(t)&&c.delete(t)}c.add(this),k??(k=requestAnimationFrame(I))}next(){try{d((this.$it??(this.$it=this.$gen.call(this,this.$args??{}))).next().value,this),typeof this.$ref=="function"&&this.$ref(this)}catch(t){this.throw(t)}}throw(t){var i;for(let n=this;n;n=n.parentNode)if(typeof((i=n.$it)==null?void 0:i.throw)=="function")try{return d(n.$it.throw(t).value,n)}catch{}throw t}return(){var t;try{(t=this.$it)==null||t.return()}catch(i){this.throw(i)}finally{this.$it=null}}}exports.Fragment=b;exports.h=A;exports.render=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=({children:i})=>i,b=function(i,e){const{length:t}=arguments;return(e??(e=v(null))).nodeName=i,"children"in e||t<3||(e.children=t===3?arguments[2]:O.call(arguments,2)),e},y=(i,e)=>{let t=e.firstChild;for(i of g(i)){let n=t;if(typeof i=="string"){for(;n&&n.nodeType!=3;)n=n.nextSibling;n?n.data!=i&&(n.data=i):n=document.createTextNode(i)}else{const{nodeName:o,key:a,skip:c,memo:s,ref:f,children:N}=i;for(;n&&!(n.localName===o&&(n.$key??(n.$key=a))==a);)n=n.nextSibling;if(n??(n=d(document.createElementNS(i.xmlns??o==="svg"?T:e.namespaceURI,o),{$key:a})),s==null||F(n.$memo,n.$memo=s)){const{$props:m}=n,x={};for(const l of w(d({},m,i))){if(C.has(l))continue;const u=x[l]=i[l];u!==(m==null?void 0:m[l])&&(l.startsWith("set:")?n[l.slice(4)]=u:u==null||u===!1?n.removeAttribute(l):n.setAttribute(l,u===!0?"":u))}n.$props=x,c||y(N,n),typeof f=="function"&&(n.$ref=f)(n)}}n===t?t=t.nextSibling:B(e,n,t)}for(;t;){const n=t.nextSibling;t.nodeType===1&&S(t),e.removeChild(t),t=n}},{isArray:$,prototype:{slice:O}}=Array,{create:v,keys:w,assign:d,hasOwn:A,setPrototypeOf:p,getPrototypeOf:h}=Object,T="http://www.w3.org/2000/svg",C=new Set("nodeName,key,skip,memo,ref,children".split(",")),F=(i,e)=>$(i)&&$(e)?i.some((t,n)=>t!==e[n]):i!==e,g=function*(i,e={value:""},t=!0){for(i of $(i)?i:[i])if(!(i==null||typeof i=="boolean"))if(A(i,"nodeName")){const{value:n}=e,{nodeName:o}=i;if(n&&(yield n,e.value=""),typeof o=="function")if(o.constructor.name==="GeneratorFunction"){const a={},c=d({},o.attrs);for(const s of w(i)){const f=i[s];s.startsWith("attr:")?c[s.slice(5)]=f:s==="key"||s==="memo"?c[s]=f:a[s]=f}c.nodeName=o.is??"div",c.skip=!0,c.ref=P.bind(null,o,a),yield c}else yield*g(o(i),e,!1);else yield i}else $(i)?yield*g(i,e,!1):e.value+=i;t&&e.value&&(yield e.value)},P=(i,e,t)=>{if(!t)return;t.$gen??(t.$gen=(new E(t),i)),t.$ref=j.bind(null,t);const{skip:n,...o}=e;d(t.$args??(t.$args={}),o),n||t.$next()},j=(i,e)=>e??i.$return(),B=(i,e,t)=>{if(e.contains(document.activeElement)){const n=e.nextSibling;for(;t&&t!=e;){const o=t.nextSibling;i.insertBefore(t,n),t=o}}else i.insertBefore(e,t)},S=i=>{for(const t of i.children)S(t);const{$ref:e}=i;typeof e=="function"&&e(null)};let r=null;class E{constructor(e){p(e,p(h(this),h(e))),e.$context=v((r==null?void 0:r.$context)??null)}render(){r!=null&&r.contains(this)||this.$next()}$next(){const e=r;r=this;try{y((this.$it??(this.$it=this.$gen.call(this,this.$args))).next().value,this),typeof this.$ref=="function"&&this.$ref(this)}catch(t){this.$throw(t)}finally{r=e}}$throw(e){var t;for(let n=this;n;n=n.parentNode)if(typeof((t=n.$it)==null?void 0:t.throw)=="function")try{return y(n.$it.throw(e).value,n)}catch{}throw e}$return(){var e;try{(e=this.$it)==null||e.return()}catch(t){this.$throw(t)}finally{this.$it=null}}}const W=(i,e=Symbol())=>function(t,n){return arguments.length===1?e in t.$context?t.$context[e]:i:t.$context[e]=n};exports.Fragment=k;exports.context=W;exports.h=b;exports.render=y;
package/dist/index.js CHANGED
@@ -1,129 +1,111 @@
1
- const W = ({ children: e }) => e, j = function(e, t) {
2
- const { length: i } = arguments;
3
- return (t ?? (t = A(null))).nodeName = e, "children" in t || i < 3 || (t.children = i === 3 ? arguments[2] : b.call(arguments, 2)), t;
4
- }, d = (e, t) => {
5
- let i = t.firstChild;
6
- for (e of p(e)) {
7
- let n = i;
8
- if (typeof e == "string") {
9
- for (; n && n.nodeType != 3; )
10
- n = n.nextSibling;
11
- n ? n.data != e && (n.data = e) : n = document.createTextNode(e);
12
- } else if (e instanceof Node)
13
- n = e;
14
- else {
15
- const { nodeName: o, key: a, skip: m, memo: r, ref: s, children: u } = e;
16
- for (; n && !(n.localName === o && (n.$key ?? (n.$key = a)) == a); )
17
- n = n.nextSibling;
18
- if (n ?? (n = g(document.createElementNS(e.xmlns ?? o === "svg" ? O : t.namespaceURI, o), { $key: a })), r == null || F(n.$memo, n.$memo = r)) {
19
- const { $props: y } = n, w = {};
20
- for (const l of h(g({}, y, e))) {
21
- if (q.has(l))
22
- continue;
23
- const f = w[l] = e[l];
24
- f !== (y == null ? void 0 : y[l]) && (l.startsWith("set:") ? n[l.slice(4)] = f : f == null || f === !1 ? n.removeAttribute(l) : n.setAttribute(l, f === !0 ? "" : f));
1
+ const P = ({ children: i }) => i, W = function(i, e) {
2
+ const { length: t } = arguments;
3
+ return (e ?? (e = v(null))).nodeName = i, "children" in e || t < 3 || (e.children = t === 3 ? arguments[2] : S.call(arguments, 2)), e;
4
+ }, d = (i, e) => {
5
+ let t = e.firstChild;
6
+ for (i of g(i)) {
7
+ let n = t;
8
+ if (typeof i == "string") {
9
+ for (; n && n.nodeType != 3; ) n = n.nextSibling;
10
+ n ? n.data != i && (n.data = i) : n = document.createTextNode(i);
11
+ } else {
12
+ const { nodeName: o, key: a, skip: c, memo: s, ref: f, children: k } = i;
13
+ for (; n && !(n.localName === o && (n.$key ?? (n.$key = a)) == a); ) n = n.nextSibling;
14
+ if (n ?? (n = $(document.createElementNS(i.xmlns ?? o === "svg" ? A : e.namespaceURI, o), { $key: a })), s == null || C(n.$memo, n.$memo = s)) {
15
+ const { $props: m } = n, x = {};
16
+ for (const l of w($({}, m, i))) {
17
+ if (O.has(l)) continue;
18
+ const u = x[l] = i[l];
19
+ u !== (m == null ? void 0 : m[l]) && (l.startsWith("set:") ? n[l.slice(4)] = u : u == null || u === !1 ? n.removeAttribute(l) : n.setAttribute(l, u === !0 ? "" : u));
25
20
  }
26
- n.$props = w, m || d(u, n), typeof s == "function" && (n.$ref = s)(n);
21
+ n.$props = x, c || d(k, n), typeof f == "function" && (n.$ref = f)(n);
27
22
  }
28
23
  }
29
- n === i ? i = i.nextSibling : E(t, n, i);
24
+ n === t ? t = t.nextSibling : E(e, n, t);
30
25
  }
31
- for (; i; ) {
32
- const n = i.nextSibling;
33
- i.nodeType === 1 && k(i), t.removeChild(i), i = n;
26
+ for (; t; ) {
27
+ const n = t.nextSibling;
28
+ t.nodeType === 1 && N(t), e.removeChild(t), t = n;
34
29
  }
35
- }, { isArray: $, prototype: { slice: b } } = Array, { create: A, keys: h, assign: g, hasOwn: C, setPrototypeOf: x, getPrototypeOf: v } = Object, O = "http://www.w3.org/2000/svg", q = new Set("nodeName,key,skip,memo,ref,children".split(",")), N = (e) => typeof e != "string" && typeof (e == null ? void 0 : e[Symbol.iterator]) == "function", F = (e, t) => $(e) && $(t) ? e.some((i, n) => i !== t[n]) : e !== t, p = function* (e, t = { value: "" }, i = !0) {
36
- for (e of N(e) ? e : [e])
37
- if (!(e == null || typeof e == "boolean"))
38
- if (C(e, "nodeName")) {
39
- const { value: n } = t, { nodeName: o } = e, a = typeof o;
40
- if (n && (yield n, t.value = ""), a === "function")
41
- if (delete e.nodeName, o.constructor.name === "GeneratorFunction") {
42
- const m = {}, r = g({}, o.attrs);
43
- for (const s of h(e)) {
44
- const u = e[s];
45
- s.startsWith("attr:") && (r[s.slice(5)] = u), s === "key" || s === "memo" ? r[s] = u : m[s] = u;
30
+ }, { isArray: y, prototype: { slice: S } } = Array, { create: v, keys: w, assign: $, hasOwn: b, setPrototypeOf: p, getPrototypeOf: h } = Object, A = "http://www.w3.org/2000/svg", O = new Set("nodeName,key,skip,memo,ref,children".split(",")), C = (i, e) => y(i) && y(e) ? i.some((t, n) => t !== e[n]) : i !== e, g = function* (i, e = { value: "" }, t = !0) {
31
+ for (i of y(i) ? i : [i])
32
+ if (!(i == null || typeof i == "boolean"))
33
+ if (b(i, "nodeName")) {
34
+ const { value: n } = e, { nodeName: o } = i;
35
+ if (n && (yield n, e.value = ""), typeof o == "function")
36
+ if (o.constructor.name === "GeneratorFunction") {
37
+ const a = {}, c = $({}, o.attrs);
38
+ for (const s of w(i)) {
39
+ const f = i[s];
40
+ s.startsWith("attr:") ? c[s.slice(5)] = f : s === "key" || s === "memo" ? c[s] = f : a[s] = f;
46
41
  }
47
- r.nodeName = o.is ?? "div", r.skip = !0, r.ref = T.bind(null, o, m), yield r;
48
- } else
49
- yield* p(o(e), t, !1);
50
- else
51
- a === "string" && (yield e);
52
- } else
53
- N(e) ? yield* p(e, t, !1) : t.value += e;
54
- i && t.value && (yield t.value);
55
- }, T = (e, t, i) => {
56
- i && (i.$gen ?? (i.$gen = (new P(i), e)), i.$ref = B.bind(null, i), i.$args = t, i.next());
57
- }, B = (e, t) => t ?? e.return(), E = (e, t, i) => {
58
- if (t.contains(document.activeElement)) {
59
- const n = t.nextSibling;
60
- for (; i && i != t; ) {
61
- const o = i.nextSibling;
62
- e.insertBefore(i, n), i = o;
42
+ c.nodeName = o.is ?? "div", c.skip = !0, c.ref = T.bind(null, o, a), yield c;
43
+ } else yield* g(o(i), e, !1);
44
+ else yield i;
45
+ } else y(i) ? yield* g(i, e, !1) : e.value += i;
46
+ t && e.value && (yield e.value);
47
+ }, T = (i, e, t) => {
48
+ if (!t) return;
49
+ t.$gen ?? (t.$gen = (new F(t), i)), t.$ref = B.bind(null, t);
50
+ const { skip: n, ...o } = e;
51
+ $(t.$args ?? (t.$args = {}), o), n || t.$next();
52
+ }, B = (i, e) => e ?? i.$return(), E = (i, e, t) => {
53
+ if (e.contains(document.activeElement)) {
54
+ const n = e.nextSibling;
55
+ for (; t && t != e; ) {
56
+ const o = t.nextSibling;
57
+ i.insertBefore(t, n), t = o;
63
58
  }
64
- } else
65
- e.insertBefore(t, i);
66
- }, k = (e) => {
67
- for (const i of e.children)
68
- k(i);
69
- const { $ref: t } = e;
70
- typeof t == "function" && t(null);
71
- for (const i of h(e))
72
- e[i] = null;
73
- };
74
- let c, S;
75
- const I = () => {
76
- for (const e of c)
77
- e.isConnected && e.next();
78
- c.clear(), S = null;
59
+ } else i.insertBefore(e, t);
60
+ }, N = (i) => {
61
+ for (const t of i.children) N(t);
62
+ const { $ref: e } = i;
63
+ typeof e == "function" && e(null);
79
64
  };
80
- class P {
81
- constructor(t) {
82
- x(t, x(v(this), v(t)));
65
+ let r = null;
66
+ class F {
67
+ constructor(e) {
68
+ p(e, p(h(this), h(e))), e.$context = v((r == null ? void 0 : r.$context) ?? null);
83
69
  }
84
- *[Symbol.iterator]() {
85
- for (; ; )
86
- yield this.$args ?? {};
70
+ render() {
71
+ r != null && r.contains(this) || this.$next();
87
72
  }
88
- refresh() {
89
- (c ?? (c = /* @__PURE__ */ new Set())).has(this) && c.delete(this);
90
- for (const t of c) {
91
- if (t.contains(this))
92
- return;
93
- this.contains(t) && c.delete(t);
94
- }
95
- c.add(this), S ?? (S = requestAnimationFrame(I));
96
- }
97
- next() {
73
+ $next() {
74
+ const e = r;
75
+ r = this;
98
76
  try {
99
- d((this.$it ?? (this.$it = this.$gen.call(this, this.$args ?? {}))).next().value, this), typeof this.$ref == "function" && this.$ref(this);
77
+ d((this.$it ?? (this.$it = this.$gen.call(this, this.$args))).next().value, this), typeof this.$ref == "function" && this.$ref(this);
100
78
  } catch (t) {
101
- this.throw(t);
79
+ this.$throw(t);
80
+ } finally {
81
+ r = e;
102
82
  }
103
83
  }
104
- throw(t) {
105
- var i;
106
- for (let n = this; n; n = n.parentNode)
107
- if (typeof ((i = n.$it) == null ? void 0 : i.throw) == "function")
108
- try {
109
- return d(n.$it.throw(t).value, n);
110
- } catch {
111
- }
112
- throw t;
113
- }
114
- return() {
84
+ $throw(e) {
115
85
  var t;
86
+ for (let n = this; n; n = n.parentNode) if (typeof ((t = n.$it) == null ? void 0 : t.throw) == "function") try {
87
+ return d(n.$it.throw(e).value, n);
88
+ } catch {
89
+ }
90
+ throw e;
91
+ }
92
+ $return() {
93
+ var e;
116
94
  try {
117
- (t = this.$it) == null || t.return();
118
- } catch (i) {
119
- this.throw(i);
95
+ (e = this.$it) == null || e.return();
96
+ } catch (t) {
97
+ this.$throw(t);
120
98
  } finally {
121
99
  this.$it = null;
122
100
  }
123
101
  }
124
102
  }
103
+ const j = (i, e = Symbol()) => function(t, n) {
104
+ return arguments.length === 1 ? e in t.$context ? t.$context[e] : i : t.$context[e] = n;
105
+ };
125
106
  export {
126
- W as Fragment,
127
- j as h,
107
+ P as Fragment,
108
+ j as context,
109
+ W as h,
128
110
  d as render
129
111
  };
package/license CHANGED
@@ -1,6 +1,6 @@
1
1
  ISC License
2
2
 
3
- Copyright (c) 2023, Cristian Falcone
3
+ Copyright (c) 2024, Cristian Falcone
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "ajo",
3
- "version": "0.1.15",
3
+ "version": "0.1.18",
4
4
  "description": "ajo is a JavaScript view library for building user interfaces",
5
5
  "type": "module",
6
+ "module": "./dist/index.js",
7
+ "main": "./dist/index.cjs",
8
+ "types": "./types.ts",
6
9
  "exports": {
7
10
  ".": {
8
11
  "import": "./dist/index.js",
@@ -20,10 +23,10 @@
20
23
  "types.ts"
21
24
  ],
22
25
  "devDependencies": {
23
- "@types/node": "^20.12.7",
24
- "jsdom": "24.0.0",
25
- "vite": "5.2.8",
26
- "vitest": "1.5.0"
26
+ "@types/node": "^20.14.10",
27
+ "jsdom": "24.1.0",
28
+ "vite": "5.3.3",
29
+ "vitest": "2.0.1"
27
30
  },
28
31
  "keywords": [
29
32
  "ui",
package/readme.md CHANGED
@@ -68,7 +68,7 @@ function* Counter() {
68
68
 
69
69
  const handleClick = () => {
70
70
  count++
71
- this.refresh()
71
+ this.render()
72
72
  }
73
73
 
74
74
  while (true) yield (
@@ -254,7 +254,7 @@ Stateful components in Ajo are defined using generator functions. These componen
254
254
  The following example demonstrates key features of stateful components in Ajo:
255
255
 
256
256
  ```jsx
257
- function* ChatComponent({ user = 'Anonymous', room }) { // Receive arguments initial values.
257
+ function* ChatComponent(props) {
258
258
 
259
259
  // Define mutable state variables.
260
260
  let message = '', connected = false
@@ -264,36 +264,33 @@ function* ChatComponent({ user = 'Anonymous', room }) { // Receive arguments ini
264
264
 
265
265
  message = event.target.value
266
266
 
267
- // Render synchronously.
268
- this.next()
267
+ this.render()
269
268
  }
270
269
 
271
270
  const send = () => {
272
271
 
273
272
  if (message) {
274
273
 
275
- // Access current arguments values with 'this.$args'.
276
- connection.send(JSON.stringify({ user: this.$args.user, message }))
274
+ connection.send(JSON.stringify({ user: props.user ?? 'Anonymous', message }))
277
275
 
278
276
  message = ''
279
277
 
280
- // Render asynchronously.
281
- this.refresh()
278
+ this.render()
282
279
  }
283
280
  }
284
281
 
285
282
  const handleConnectionOpen = () => {
286
283
  connected = true
287
- this.refresh()
284
+ this.render()
288
285
  }
289
286
 
290
287
  const handleConnectionError = error => {
291
288
  // Throw error to be caught by the component itself or a parent component.
292
- this.throw(new Error('Connection error: ' + error.message))
289
+ this.$throw(new Error('Connection error: ' + error.message))
293
290
  }
294
291
 
295
292
  // Setup resources.
296
- const server = `ws://chat.com/${room}`
293
+ const server = `ws://chat.com/${props.room}`
297
294
  const connection = new WebSocket(server)
298
295
 
299
296
  connection.onopen = handleConnectionOpen
@@ -304,12 +301,12 @@ function* ChatComponent({ user = 'Anonymous', room }) { // Receive arguments ini
304
301
 
305
302
  try { // Optional try/finally block for cleanup logic.
306
303
 
307
- for ({ user } of this) { // Iterates over generator, optionally receiving updated arguments.
304
+ while (true) {
308
305
 
309
306
  try { // Optional try/catch block for error handling.
310
307
 
311
308
  // Compute derived values.
312
- const status = connected ? `You are connected as ${user}.` : "Connecting to chat..."
309
+ const status = connected ? `You are connected as ${props.user ?? 'Anonymous'}.` : "Connecting to chat..."
313
310
 
314
311
  // Render the component UI.
315
312
  yield (
@@ -401,7 +398,7 @@ function* ParentComponent() {
401
398
  />
402
399
  }
403
400
 
404
- function* ChildComponent({ data, onEvent }) {
401
+ function* ChildComponent(props) { // props is an object containing data and onEvent
405
402
  // ...
406
403
  }
407
404
  ```
@@ -417,95 +414,76 @@ In the context of Server-Side Rendering (SSR), this features allows Ajo to grace
417
414
 
418
415
  Stateful components in Ajo are equipped with several methods that allow for advanced control over component behavior, error handling, and rendering processes. These methods are called lifecycle methods and are invoked at different stages of the component's lifecycle.
419
416
 
420
- ### `this.refresh()`
417
+ ### `this.$next()`
421
418
 
422
- The `refresh` method is used to asynchronously trigger a re-render of a stateful component in Ajo. It schedules a render using `requestAnimationFrame`, ensuring that the rendering aligns with the browser's paint cycle.
419
+ The `$next` method is used within stateful components in Ajo to advance the component's generator function to its next yield point. This method is crucial for rendering the next state of the component.
423
420
 
424
421
  #### Purpose:
425
422
 
426
- - **Asynchronous Rendering:** `this.refresh()` queues a render of the component in the next animation frame, making it asynchronous.
427
- - **Single Render:** If called multiple times before the browser paints, `this.refresh()` schedules only one render, ensuring that the component is rendered only once.
423
+ - **Synchronous Rendering:** `this.$next()` is used to render the next state of the component. It advances the generator function to the next yield, reflecting any changes in state or props right away.
428
424
 
429
425
  #### Usage:
430
426
 
431
- - **For Performance Optimization:** Ideal in scenarios where multiple state updates occur in quick succession.
432
- - **In Event Handlers and Async Operations:** Useful in event handlers or after asynchronous operations where you need to update the UI in response to changes.
427
+ - **In Response to State Changes:** Typically, `this.$next()` is called in scenarios where the component's state has changed and an update to the DOM is required.
433
428
 
434
429
  #### Example:
435
430
 
436
431
  ```jsx
437
- function* DataFetcher() {
432
+ function* Counter() {
438
433
 
439
- let data = null
434
+ let count = 0
440
435
 
441
- const fetchData = async () => {
436
+ const increment = () => {
442
437
 
443
- data = await fetchSomeData()
438
+ count++
444
439
 
445
- // Queue a re-render to update the component with the fetched data:
446
- this.refresh()
440
+ this.$next()
447
441
  }
448
442
 
449
443
  while (true) {
450
- yield (
451
- <div>
452
- <button set:onclick={fetchData}>Fetch Data</button>
453
- {data && <DisplayData data={data} />}
454
- </div>
455
- )
444
+ yield <button set:onclick={increment}>{count}</button>
456
445
  }
457
446
  }
458
447
  ```
459
- > In this example, `DataFetcher` uses `this.refresh()` to update its display after data is fetched. The use of `this.refresh()` ensures that the rendering is efficient and aligned with the browser's rendering cycle.
460
-
461
- ### `this.next()`
462
- > **Note:** `this.next()` is called asynchronously when calling `this.refresh()`.
463
-
464
- The `next` method is used within stateful components in Ajo to manually advance the component's generator function to its next yield point. This method is crucial for synchronously rendering the next state of the component.
465
-
466
- #### Purpose:
467
-
468
- - **Synchronous Rendering:** `this.next()` is used to immediately render the next state of the component. It advances the generator function to the next yield, reflecting any changes in state or props right away.
469
-
470
- #### Usage:
471
-
472
- - **In Response to State Changes:** Typically, `this.next()` is called in scenarios where the component's state has changed and an immediate update to the DOM is required.
473
- - **For Controlled Updates:** It allows for more controlled and predictable updates, as it bypasses the asynchronous rendering cycle from `this.refresh()`.
474
-
475
- #### Example:
448
+ > In this example, `Counter` uses `this.$next()` in its `increment` function to render the updated count whenever the button is clicked.
476
449
 
477
450
  ```jsx
478
- function* Counter() {
451
+ function* DataFetcher() {
479
452
 
480
- let count = 0
453
+ let data = null
481
454
 
482
- const increment = () => {
455
+ const fetchData = async () => {
483
456
 
484
- count++
457
+ data = await fetchSomeData()
485
458
 
486
- // Immediately render the updated count
487
- this.next()
459
+ // Queue a re-render to update the component with the fetched data:
460
+ this.$next()
488
461
  }
489
462
 
490
463
  while (true) {
491
- yield <button set:onclick={increment}>{count}</button>
464
+ yield (
465
+ <div>
466
+ <button set:onclick={fetchData}>Fetch Data</button>
467
+ {data && <DisplayData data={data} />}
468
+ </div>
469
+ )
492
470
  }
493
471
  }
494
472
  ```
495
- > In this example, `Counter` uses `this.next()` in its `increment` function to immediately render the updated count whenever the button is clicked.
473
+ > In this example, `DataFetcher` uses `this.$next()` to update its display after data is fetched.
496
474
 
497
- ### `this.throw()`
498
- > **Note:** `this.throw()` is automatically called when an error is thrown from a component's generator function.
475
+ ### `this.$throw()`
476
+ > **Note:** `this.$throw()` is automatically called when an error is thrown from a component's generator function.
499
477
 
500
- The `throw` method in Ajo stateful components is designed for error propagation within the component hierarchy. It allows developers to throw errors from a child component to be caught and handled by itself or a parent component, facilitating a structured approach to error management.
478
+ The `$throw` method in Ajo stateful components is designed for error propagation within the component hierarchy. It allows developers to throw errors from a child component to be caught and handled by itself or a parent component, facilitating a structured approach to error management.
501
479
 
502
480
  #### Purpose:
503
481
 
504
- - **Error Propagation:** `this.throw()` is used to send errors from the current component up to its parents component, akin to creating an error boundary.
482
+ - **Error Propagation:** `this.$throw()` is used to send errors from the current component up to its parents component, akin to creating an error boundary.
505
483
 
506
484
  #### Usage:
507
485
 
508
- - **Handling Uncaught Exceptions:** Typically used within event handlers or asynchronous operations where errors might occur. Instead of handling these errors locally within the component, `this.throw()` sends them to the parent component for a more centralized handling approach.
486
+ - **Handling Uncaught Exceptions:** Typically used within event handlers or asynchronous operations where errors might occur. Instead of handling these errors locally within the component, `this.$throw()` sends them to the parent component for a more centralized handling approach.
509
487
  - **Creating Error Boundaries:** Useful in scenarios where a parent component is designed to handle errors from its child components, maintaining separation of concerns and cleaner code.
510
488
 
511
489
  #### Example:
@@ -522,7 +500,7 @@ function* ChildComponent() {
522
500
  } catch (err) {
523
501
 
524
502
  // Propagate error to parent component
525
- this.throw(err)
503
+ this.$throw(err)
526
504
  }
527
505
  }
528
506
 
@@ -541,16 +519,16 @@ function* ParentComponent() {
541
519
  }
542
520
  }
543
521
  ```
544
- > In this example, `ChildComponent` uses `this.throw()` within an event handler to propagate errors upwards to its parent component, `ParentComponent`. The parent component then catches the error and renders it to the DOM.
522
+ > In this example, `ChildComponent` uses `this.$throw()` within an event handler to propagate errors upwards to its parent component, `ParentComponent`. The parent component then catches the error and renders it to the DOM.
545
523
 
546
- ### `this.return()`
547
- > **Note:** `this.return()` is automatically called when a stateful component is unmounted.
524
+ ### `this.$return()`
525
+ > **Note:** `this.$return()` is automatically called when a stateful component is unmounted.
548
526
 
549
- The `return` method in Ajo is used to reset and restart the generator function of a stateful component. It effectively ends the current execution of the component's generator function, and optionally re-execute it from scratch allowing for a complete reset of the component's state and behavior.
527
+ The `$return` method in Ajo is used to reset and restart the generator function of a stateful component. It effectively ends the current execution of the component's generator function, and optionally re-execute it from scratch allowing for a complete reset of the component's state and behavior.
550
528
 
551
529
  #### Purpose:
552
530
 
553
- - **Component Reset:** `this.return()` is used to restart a component's generator function from the beginning, resetting its internal state and re-initializing it as needed.
531
+ - **Component Reset:** `this.$return()` is used to restart a component's generator function from the beginning, resetting its internal state and re-initializing it as needed.
554
532
 
555
533
  #### Usage:
556
534
 
@@ -571,16 +549,16 @@ function* MultiStepForm({ initialData }) {
571
549
  currentStep++
572
550
 
573
551
  // Re-render with the next step
574
- this.refresh()
552
+ this.render()
575
553
  }
576
554
 
577
555
  const handleRestart = () => {
578
556
 
579
557
  // Reset the generator function
580
- this.return()
558
+ this.$return()
581
559
 
582
560
  // Re-render the component in its initial state
583
- this.refresh()
561
+ this.render()
584
562
  }
585
563
 
586
564
  while (true) {
@@ -608,7 +586,7 @@ function* MultiStepForm({ initialData }) {
608
586
  }
609
587
  }
610
588
  ```
611
- > In `handleRestart`, `this.return()` is first called to reset the generator function. This effectively ends the current execution of the component's generator function and prepares it to start from the beginning. Immediately after, `this.refresh()` is called to trigger a re-render of the component. This ensures that after the state is reset, the component's UI is also updated to reflect its initial state.
589
+ > In `handleRestart`, `this.$return()` is first called to reset the generator function. This effectively ends the current execution of the component's generator function and prepares it to start from the beginning. Immediately after, `this.$next()` is called to trigger a re-render of the component. This ensures that after the state is reset, the component's UI is also updated to reflect its initial state.
612
590
 
613
591
  ## Server-Side Rendering (SSR)
614
592
 
package/types.ts CHANGED
@@ -2,21 +2,13 @@ declare module 'ajo' {
2
2
 
3
3
  type Tag = keyof (HTMLElementTagNameMap & SVGElementTagNameMap)
4
4
 
5
+ type Type = Tag | Function | Component
6
+
5
7
  type Props = Record<string, unknown>
6
8
 
7
- type AjoNode<TTag = Tag> = { nodeName: TTag } & AjoProps<ElementType<TTag>> & Props
9
+ type AjoNode<TTag extends Type> = { nodeName: TTag } & TagProps<TTag>
8
10
 
9
- type Children =
10
- | null
11
- | undefined
12
- | boolean
13
- | bigint
14
- | number
15
- | string
16
- | symbol
17
- | Node
18
- | AjoNode
19
- | Iterable<Children>
11
+ type Children = any
20
12
 
21
13
  type ElementType<TTag = Tag> = TTag extends keyof HTMLElementTagNameMap
22
14
  ? HTMLElementTagNameMap[TTag]
@@ -40,21 +32,23 @@ declare module 'ajo' {
40
32
  }
41
33
 
42
34
  type Context<TArguments = Props> = {
43
- $args: TArguments
44
- next: () => void
45
- throw: (value?: unknown) => void
46
- return: () => void
47
- refresh: () => void
48
- [Symbol.iterator]: () => Generator<TArguments, unknown, unknown>
35
+ $args: TArguments,
36
+ $context: { [key: symbol]: unknown },
37
+ render: () => void,
38
+ $next: () => void
39
+ $throw: (value?: unknown) => void
40
+ $return: () => void
49
41
  }
50
42
 
51
43
  type Function<TArguments = Props> = (args: TArguments) => Children
52
44
 
53
45
  type Component<TArguments = Props, TTag extends Tag = 'div'> = {
54
- (this: ComponentElement<TArguments, TTag>, args: TArguments): Generator<Children, unknown, unknown>
46
+ (this: ElementType<TTag> & Context<TArguments>, args: TArguments): Iterator<Children, unknown, unknown>
55
47
  } & (TTag extends 'div' ? { is?: TTag } : { is: TTag })
56
48
 
57
- type ComponentElement<TArguments = Props, TTag = Tag> = Context<TArguments> & ElementType<TTag>
49
+ type Ref<TComponent> = TComponent extends Component<infer TArguments, infer TTag>
50
+ ? Component<TArguments & { ref: (el: ThisParameterType<Ref<TComponent>> | null) => void }, TTag>
51
+ : never
58
52
 
59
53
  type IntrinsicElements = {
60
54
  [TTag in Tag]: Partial<SetProps<TTag> & AjoProps<ElementType<TTag>>> & Props
@@ -64,9 +58,18 @@ declare module 'ajo' {
64
58
 
65
59
  type ElementChildrenAttribute = { children: Children }
66
60
 
61
+ type TagProps<TTag extends Type> = TTag extends Tag
62
+ ? IntrinsicElements[TTag] & IntrinsicAttributes
63
+ : TTag extends Function<infer TArguments>
64
+ ? TArguments
65
+ : TTag extends Component<infer TArguments>
66
+ ? TArguments
67
+ : never
68
+
67
69
  function Fragment({ children }: ElementChildrenAttribute): typeof children
68
- function h<TProps = Props>(type: Tag | Function<TProps> | Component<TProps>, props?: TProps | null, ...children: Children[]): AjoNode<typeof type>
70
+ function h<TTag extends Tag>(tag: TTag, props?: TagProps<TTag> | null, ...children: Array<unknown>): AjoNode<TTag>
69
71
  function render(h: Children, el: Element): void
72
+ function context<T>(fallback?: T): { (el: ThisParameterType<Component<unknown, Tag>>, value?: T): T }
70
73
  }
71
74
 
72
75
  declare namespace JSX {