ajo 0.1.23 → 0.1.24
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 +1 -1
- package/dist/html.js +64 -63
- package/dist/index.cjs +1 -1
- package/dist/index.js +61 -53
- package/dist/stream.cjs +1 -1
- package/dist/stream.js +21 -19
- package/package.json +17 -14
- package/types.ts +70 -59
package/dist/html.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./context.cjs"),$=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"]),S=new Set(["nodeName","children",...g]),b=Symbol.for("ajo.args"),d=e=>e.replace(/[&<>"']/g,i=>`&#${i.charCodeAt(0)};`),o=()=>{},A=e=>[...w(e)].join(""),w=function*(e,{alloc:i=()=>"",placeholder:r=o,push:t=o}={}){yield*y(a(e,{alloc:i,placeholder:r,push:t}))},a=(e,i)=>{const r=typeof e;if(!(e==null||r==="boolean")){if(r==="string"||r==="number")return String(e);if(Array.isArray(e)){const t=[];for(e of e.flat(1/0)){const n=a(e,i);n!=null&&t.push(n)}return t.length===1?t[0]:t}if("nodeName"in e){if(typeof e.nodeName=="function")return v(e,i);const t={nodeName:e.nodeName};for(const n in e)!S.has(n)&&!n.startsWith("set:")&&(t[n]=e[n]);return"children"in e&&(t.children=a(e.children,i)),t}return String(e)}},v=({nodeName:e,fallback:i=e.fallback,...r},t)=>{if(e.src){const c=t.alloc();return t.push({id:c,src:e.src,h:r,done:!0}),t.placeholder(c,i)}const n=e.constructor.name;if(n==="GeneratorFunction")return x(e,r,t);if(n==="AsyncGeneratorFunction")return j(e,i,r,t);if(r=e(r),r instanceof Promise){if(t.push===o)return i;const c=t.alloc();return r.then(s=>t.push({id:c,h:a(s,{...t,alloc:(u=c)=>t.alloc(u)}),done:!0})),t.placeholder(c,i)}return a(r,t)},x=(e,i,r)=>{var p,m;const t={...e.attrs},n={...e.args};for(const l in i)l.startsWith("attr:")?t[l.slice(5)]=i[l]:g.has(l)||l.startsWith("set:")?t[l]=i[l]:n[l]=i[l];const c={[f.Context]:Object.assign(Object.create(null),(p=f.current())==null?void 0:p[f.Context]),[b]:n,render:o,next:o,return:o,throw:l=>{throw l}},s=e.call(c,n),u=f.current();f.current(c);try{return{...t,nodeName:e.is??"div",children:a(s.next().value,r)}}finally{(m=s.return)==null||m.call(s),f.current(u)}},j=(e,i,r,t)=>{if(t.push===o)return i;const n=t.alloc();return Promise.resolve().then(async()=>{var s;const c=e(r);t={...t,alloc:(u=n)=>t.alloc(u)};try{for(r=await c.next();!r.done;)t.push({id:n,h:a(r.value,t),done:!1}),r=await c.next();t.push({id:n,h:a(r.value,t),done:!0})}catch(u){t.push({id:n,h:a(u,t),done:!0})}finally{(s=c.return)==null||s.call(c)}}),t.placeholder(n,i)},y=function*(e){if(typeof e=="string")yield d(e);else if(Array.isArray(e))for(e of e)yield*y(e);else if("nodeName"in e){const{nodeName:i,children:r}=e;let t="";for(const n in e)S.has(n)||n.startsWith("set:")||e[n]==null||e[n]===!1||(e[n]===!0?t+=` ${n}`:t+=` ${n}="${d(String(e[n]))}"`);$.has(i)?yield`<${i}${t}>`:(yield`<${i}${t}>`,r!=null&&(yield*y(r)),yield`</${i}>`)}else yield d(String(e))};exports.html=w;exports.render=A;
|
package/dist/html.js
CHANGED
|
@@ -1,90 +1,91 @@
|
|
|
1
|
-
import { Context as
|
|
2
|
-
const
|
|
3
|
-
},
|
|
4
|
-
yield*
|
|
5
|
-
},
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Context as g, current as f } from "./context.js";
|
|
2
|
+
const $ = /* @__PURE__ */ new Set(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]), w = /* @__PURE__ */ new Set(["key", "skip", "memo", "ref"]), S = /* @__PURE__ */ new Set(["nodeName", "children", ...w]), A = Symbol.for("ajo.args"), d = (e) => e.replace(/[&<>"']/g, (i) => `&#${i.charCodeAt(0)};`), o = () => {
|
|
3
|
+
}, W = (e) => [...b(e)].join(""), b = function* (e, { alloc: i = () => "", placeholder: r = o, push: n = o } = {}) {
|
|
4
|
+
yield* y(a(e, { alloc: i, placeholder: r, push: n }));
|
|
5
|
+
}, a = (e, i) => {
|
|
6
|
+
const r = typeof e;
|
|
7
|
+
if (!(e == null || r === "boolean")) {
|
|
8
|
+
if (r === "string" || r === "number") return String(e);
|
|
8
9
|
if (Array.isArray(e)) {
|
|
9
10
|
const n = [];
|
|
10
11
|
for (e of e.flat(1 / 0)) {
|
|
11
|
-
const t =
|
|
12
|
+
const t = a(e, i);
|
|
12
13
|
t != null && n.push(t);
|
|
13
14
|
}
|
|
14
15
|
return n.length === 1 ? n[0] : n;
|
|
15
16
|
}
|
|
16
|
-
if (
|
|
17
|
-
if (typeof e.nodeName == "function") return
|
|
17
|
+
if ("nodeName" in e) {
|
|
18
|
+
if (typeof e.nodeName == "function") return v(e, i);
|
|
18
19
|
const n = { nodeName: e.nodeName };
|
|
19
|
-
for (const t in e) !
|
|
20
|
-
return "children" in e && (n.children =
|
|
20
|
+
for (const t in e) !S.has(t) && !t.startsWith("set:") && (n[t] = e[t]);
|
|
21
|
+
return "children" in e && (n.children = a(e.children, i)), n;
|
|
21
22
|
}
|
|
22
23
|
return String(e);
|
|
23
24
|
}
|
|
24
|
-
},
|
|
25
|
+
}, v = ({ nodeName: e, fallback: i = e.fallback, ...r }, n) => {
|
|
25
26
|
if (e.src) {
|
|
26
|
-
const
|
|
27
|
-
return
|
|
27
|
+
const c = n.alloc();
|
|
28
|
+
return n.push({ id: c, src: e.src, h: r, done: !0 }), n.placeholder(c, i);
|
|
28
29
|
}
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
if (
|
|
32
|
-
if (
|
|
33
|
-
if (
|
|
34
|
-
const
|
|
35
|
-
return
|
|
30
|
+
const t = e.constructor.name;
|
|
31
|
+
if (t === "GeneratorFunction") return x(e, r, n);
|
|
32
|
+
if (t === "AsyncGeneratorFunction") return j(e, i, r, n);
|
|
33
|
+
if (r = e(r), r instanceof Promise) {
|
|
34
|
+
if (n.push === o) return i;
|
|
35
|
+
const c = n.alloc();
|
|
36
|
+
return r.then((s) => n.push({ id: c, h: a(s, { ...n, alloc: (u = c) => n.alloc(u) }), done: !0 })), n.placeholder(c, i);
|
|
36
37
|
}
|
|
37
|
-
return
|
|
38
|
-
}, x = (e,
|
|
39
|
-
var
|
|
40
|
-
const
|
|
41
|
-
for (const
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
render:
|
|
47
|
-
next:
|
|
48
|
-
return:
|
|
49
|
-
throw: (
|
|
50
|
-
throw
|
|
38
|
+
return a(r, n);
|
|
39
|
+
}, x = (e, i, r) => {
|
|
40
|
+
var p, m;
|
|
41
|
+
const n = { ...e.attrs }, t = { ...e.args };
|
|
42
|
+
for (const l in i)
|
|
43
|
+
l.startsWith("attr:") ? n[l.slice(5)] = i[l] : w.has(l) || l.startsWith("set:") ? n[l] = i[l] : t[l] = i[l];
|
|
44
|
+
const c = {
|
|
45
|
+
[g]: Object.assign(/* @__PURE__ */ Object.create(null), (p = f()) == null ? void 0 : p[g]),
|
|
46
|
+
[A]: t,
|
|
47
|
+
render: o,
|
|
48
|
+
next: o,
|
|
49
|
+
return: o,
|
|
50
|
+
throw: (l) => {
|
|
51
|
+
throw l;
|
|
51
52
|
}
|
|
52
|
-
},
|
|
53
|
-
|
|
53
|
+
}, s = e.call(c, t), u = f();
|
|
54
|
+
f(c);
|
|
54
55
|
try {
|
|
55
|
-
return { ...
|
|
56
|
+
return { ...n, nodeName: e.is ?? "div", children: a(s.next().value, r) };
|
|
56
57
|
} finally {
|
|
57
|
-
(
|
|
58
|
+
(m = s.return) == null || m.call(s), f(u);
|
|
58
59
|
}
|
|
59
|
-
},
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
60
|
+
}, j = (e, i, r, n) => {
|
|
61
|
+
if (n.push === o) return i;
|
|
62
|
+
const t = n.alloc();
|
|
62
63
|
return Promise.resolve().then(async () => {
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
var s;
|
|
65
|
+
const c = e(r);
|
|
66
|
+
n = { ...n, alloc: (u = t) => n.alloc(u) };
|
|
66
67
|
try {
|
|
67
|
-
for (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} catch (
|
|
71
|
-
|
|
68
|
+
for (r = await c.next(); !r.done; )
|
|
69
|
+
n.push({ id: t, h: a(r.value, n), done: !1 }), r = await c.next();
|
|
70
|
+
n.push({ id: t, h: a(r.value, n), done: !0 });
|
|
71
|
+
} catch (u) {
|
|
72
|
+
n.push({ id: t, h: a(u, n), done: !0 });
|
|
72
73
|
} finally {
|
|
73
|
-
(
|
|
74
|
+
(s = c.return) == null || s.call(c);
|
|
74
75
|
}
|
|
75
|
-
}),
|
|
76
|
-
},
|
|
77
|
-
if (typeof e == "string") yield
|
|
78
|
-
else if (Array.isArray(e)) for (e of e) yield*
|
|
79
|
-
else if (
|
|
80
|
-
const { nodeName:
|
|
76
|
+
}), n.placeholder(t, i);
|
|
77
|
+
}, y = function* (e) {
|
|
78
|
+
if (typeof e == "string") yield d(e);
|
|
79
|
+
else if (Array.isArray(e)) for (e of e) yield* y(e);
|
|
80
|
+
else if ("nodeName" in e) {
|
|
81
|
+
const { nodeName: i, children: r } = e;
|
|
81
82
|
let n = "";
|
|
82
83
|
for (const t in e)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} else yield
|
|
84
|
+
S.has(t) || t.startsWith("set:") || e[t] == null || e[t] === !1 || (e[t] === !0 ? n += ` ${t}` : n += ` ${t}="${d(String(e[t]))}"`);
|
|
85
|
+
$.has(i) ? yield `<${i}${n}>` : (yield `<${i}${n}>`, r != null && (yield* y(r)), yield `</${i}>`);
|
|
86
|
+
} else yield d(String(e));
|
|
86
87
|
};
|
|
87
88
|
export {
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
b as html,
|
|
90
|
+
W as render
|
|
90
91
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./context.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./context.cjs"),f=Symbol.for("ajo.keyed"),b=Symbol.for("ajo.key"),j=Symbol.for("ajo.memo"),m=Symbol.for("ajo.ref"),v=Symbol.for("ajo.cache"),u=Symbol.for("ajo.generator"),o=Symbol.for("ajo.iterator"),l=Symbol.for("ajo.args"),p=t=>t.children,A=(t,r,...e)=>((r??(r={})).nodeName=t,!("children"in r)&&e.length&&(r.children=e.length==1?e[0]:e),r),y=(t,r)=>{let e=r.firstChild;for(t of x(t)){const n=O(t,r,e);e==null?g(r,n):n==e?e=e.nextSibling:g(r,n,n==e.nextSibling?e=C(r,e):e)}for(;e;){const n=e.nextSibling;r.removeChild(e),e=n}},C=(t,r)=>{const e=r.nextSibling;return g(t,r),e.nextSibling},x=function*(t){const r=typeof t;if(!(t==null||r=="boolean"))if(r==="string"||r==="number")yield String(t);else if(Array.isArray(t))for(t of t)yield*x(t);else"nodeName"in t?typeof t.nodeName=="function"?yield*E(t):yield t:yield String(t)},E=function*({nodeName:t,...r}){t.constructor.name=="GeneratorFunction"?yield N(t,r):yield*x(t(r))},N=function(t,r){const e={...t.attrs},n={...t.args};for(const i in r)i.startsWith("attr:")?e[i.slice(5)]=r[i]:i=="key"||i=="memo"||i.startsWith("set:")?e[i]=r[i]:n[i]=r[i];return{...e,nodeName:t.is??"div",skip:!0,ref:B.bind(null,t,n)}},O=(t,r,e)=>typeof t=="string"?M(t,e):T(t,r,e),M=(t,r)=>{for(;r&&r.nodeType!=3;)r=r.nextSibling;return r?r.data!=t&&(r.data=t):r=document.createTextNode(t),r},T=({nodeName:t,children:r,key:e,skip:n,memo:i,ref:w,...h},a,s)=>{if(e!=null)s=(a[f]??(a[f]=new Map)).get(e)??s;else for(;s&&s.localName!=t;)s=s.nextSibling;return s??(s=document.createElementNS(h.xmlns??a.namespaceURI,t)),e!=null&&s[b]!=e&&(s[b]!=null&&S(s),a[f].set(s[b]=e,s)),(i==null||F(s[j],s[j]=i))&&(k(s[v]??W(s),s[v]=h,s),n||y(r,s),typeof w=="function"&&(s[m]=w)(s)),s},k=(t,r,e)=>{for(const n in{...t,...r})t[n]!==r[n]&&(n.startsWith("set:")?e[n.slice(4)]=r[n]:r[n]==null||r[n]===!1?e.removeAttribute(n):e.setAttribute(n,r[n]===!0?"":r[n]))},F=(t,r)=>Array.isArray(t)&&Array.isArray(r)?t.some((e,n)=>e!==r[n]):t!==r,W=t=>Array.from(t.attributes).reduce((r,e)=>(r[e.name]=e.value,r),{}),g=(t,r,e)=>{if(!r.contains(document.activeElement))return t.insertBefore(r,e);const n=r.nextSibling;for(;e&&e!=r;){const i=e.nextSibling;t.insertBefore(e,n),e=i}},S=t=>{var r,e;for(const n of t.children)S(n);(r=t[f])==null||r.clear(),(e=t[m])==null||e.call(t,null)},B=(t,{skip:r,ref:e,...n},i)=>{i&&(i[u]??(i[u]=(R(i),t)),i[m]=q.bind(null,e,i),Object.assign(i[l]??(i[l]={}),n),r||i.next())},R=t=>{var r;Object.assign(t,G),t[c.Context]=Object.create(((r=c.current())==null?void 0:r[c.Context])??null)},q=(t,r,e)=>{typeof t=="function"&&t(e),e||r.return()},G={render(){var t;(t=c.current())!=null&&t.contains(this)||this.next()},next(){var r;const t=c.current();c.current(this);try{const{value:e,done:n}=(this[o]??(this[o]=this[u].call(this,this[l]))).next();y(e,this),(r=this[m])==null||r.call(this,this),n&&this.return()}catch(e){this.throw(e)}finally{c.current(t)}},throw(t){var r;for(let e=this;e;e=e.parentNode)if(typeof((r=e[o])==null?void 0:r.throw)=="function")try{return y(e[o].throw(t).value,e)}catch(n){t=new Error(n instanceof Error?n.message:n,{cause:t})}throw t},return(){var t;try{(t=this[o])==null||t.return()}catch(r){this.throw(r)}finally{this[o]=null}}};new MutationObserver(t=>t.forEach(r=>r.removedNodes.forEach(e=>e.isConnected||e.nodeType==1&&S(e)))).observe(document,{childList:!0,subtree:!0});exports.Fragment=p;exports.h=A;exports.render=y;
|
package/dist/index.js
CHANGED
|
@@ -1,77 +1,82 @@
|
|
|
1
|
-
import { Context as
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
e
|
|
1
|
+
import { Context as j, current as f } from "./context.js";
|
|
2
|
+
const a = Symbol.for("ajo.keyed"), y = Symbol.for("ajo.key"), p = Symbol.for("ajo.memo"), m = Symbol.for("ajo.ref"), v = Symbol.for("ajo.cache"), u = Symbol.for("ajo.generator"), o = Symbol.for("ajo.iterator"), l = Symbol.for("ajo.args"), U = (t) => t.children, q = (t, r, ...n) => ((r ?? (r = {})).nodeName = t, !("children" in r) && n.length && (r.children = n.length == 1 ? n[0] : n), r), b = (t, r) => {
|
|
3
|
+
let n = r.firstChild;
|
|
4
|
+
for (t of x(t)) {
|
|
5
|
+
const e = C(t, r, n);
|
|
6
|
+
n == null ? g(r, e) : e == n ? n = n.nextSibling : g(r, e, e == n.nextSibling ? n = A(r, n) : n);
|
|
6
7
|
}
|
|
7
|
-
for (; n
|
|
8
|
+
for (; n; ) {
|
|
8
9
|
const e = n.nextSibling;
|
|
9
|
-
|
|
10
|
+
r.removeChild(n), n = e;
|
|
10
11
|
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
}, A = (t, r) => {
|
|
13
|
+
const n = r.nextSibling;
|
|
14
|
+
return g(t, r), n.nextSibling;
|
|
15
|
+
}, x = function* (t) {
|
|
16
|
+
const r = typeof t;
|
|
17
|
+
if (!(t == null || r == "boolean"))
|
|
18
|
+
if (r === "string" || r === "number") yield String(t);
|
|
19
|
+
else if (Array.isArray(t)) for (t of t) yield* x(t);
|
|
20
|
+
else "nodeName" in t ? typeof t.nodeName == "function" ? yield* E(t) : yield t : yield String(t);
|
|
21
|
+
}, E = function* ({ nodeName: t, ...r }) {
|
|
22
|
+
t.constructor.name == "GeneratorFunction" ? yield N(t, r) : yield* x(t(r));
|
|
23
|
+
}, N = function(t, r) {
|
|
24
|
+
const n = { ...t.attrs }, e = { ...t.args };
|
|
25
|
+
for (const i in r)
|
|
26
|
+
i.startsWith("attr:") ? n[i.slice(5)] = r[i] : i == "key" || i == "memo" || i.startsWith("set:") ? n[i] = r[i] : e[i] = r[i];
|
|
27
|
+
return { ...n, nodeName: t.is ?? "div", skip: !0, ref: B.bind(null, t, e) };
|
|
28
|
+
}, C = (t, r, n) => typeof t == "string" ? O(t, n) : k(t, r, n), O = (t, r) => {
|
|
25
29
|
for (; r && r.nodeType != 3; ) r = r.nextSibling;
|
|
26
30
|
return r ? r.data != t && (r.data = t) : r = document.createTextNode(t), r;
|
|
27
|
-
}, k = ({ nodeName: t, children: r, key: n, skip:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
}, k = ({ nodeName: t, children: r, key: n, skip: e, memo: i, ref: w, ...h }, c, s) => {
|
|
32
|
+
if (n != null) s = (c[a] ?? (c[a] = /* @__PURE__ */ new Map())).get(n) ?? s;
|
|
33
|
+
else for (; s && s.localName != t; ) s = s.nextSibling;
|
|
34
|
+
return s ?? (s = document.createElementNS(h.xmlns ?? c.namespaceURI, t)), n != null && s[y] != n && (s[y] != null && S(s), c[a].set(s[y] = n, s)), (i == null || T(s[p], s[p] = i)) && (M(s[v] ?? W(s), s[v] = h, s), e || b(r, s), typeof w == "function" && (s[m] = w)(s)), s;
|
|
35
|
+
}, M = (t, r, n) => {
|
|
36
|
+
for (const e in { ...t, ...r })
|
|
37
|
+
t[e] !== r[e] && (e.startsWith("set:") ? n[e.slice(4)] = r[e] : r[e] == null || r[e] === !1 ? n.removeAttribute(e) : n.setAttribute(e, r[e] === !0 ? "" : r[e]));
|
|
38
|
+
}, T = (t, r) => Array.isArray(t) && Array.isArray(r) ? t.some((n, e) => n !== r[e]) : t !== r, W = (t) => Array.from(t.attributes).reduce((r, n) => (r[n.name] = n.value, r), {}), g = (t, r, n) => {
|
|
34
39
|
if (!r.contains(document.activeElement)) return t.insertBefore(r, n);
|
|
35
|
-
const
|
|
40
|
+
const e = r.nextSibling;
|
|
36
41
|
for (; n && n != r; ) {
|
|
37
|
-
const
|
|
38
|
-
t.insertBefore(n,
|
|
42
|
+
const i = n.nextSibling;
|
|
43
|
+
t.insertBefore(n, e), n = i;
|
|
39
44
|
}
|
|
40
|
-
},
|
|
41
|
-
var r;
|
|
42
|
-
for (const
|
|
43
|
-
(r = t[
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
},
|
|
45
|
+
}, S = (t) => {
|
|
46
|
+
var r, n;
|
|
47
|
+
for (const e of t.children) S(e);
|
|
48
|
+
(r = t[a]) == null || r.clear(), (n = t[m]) == null || n.call(t, null);
|
|
49
|
+
}, B = (t, { skip: r, ref: n, ...e }, i) => {
|
|
50
|
+
i && (i[u] ?? (i[u] = (F(i), t)), i[m] = R.bind(null, n, i), Object.assign(i[l] ?? (i[l] = {}), e), r || i.next());
|
|
51
|
+
}, F = (t) => {
|
|
47
52
|
var r;
|
|
48
|
-
Object.assign(t,
|
|
49
|
-
},
|
|
53
|
+
Object.assign(t, G), t[j] = Object.create(((r = f()) == null ? void 0 : r[j]) ?? null);
|
|
54
|
+
}, R = (t, r, n) => {
|
|
50
55
|
typeof t == "function" && t(n), n || r.return();
|
|
51
|
-
},
|
|
56
|
+
}, G = {
|
|
52
57
|
render() {
|
|
53
58
|
var t;
|
|
54
|
-
(t =
|
|
59
|
+
(t = f()) != null && t.contains(this) || this.next();
|
|
55
60
|
},
|
|
56
61
|
next() {
|
|
57
62
|
var r;
|
|
58
|
-
const t =
|
|
59
|
-
|
|
63
|
+
const t = f();
|
|
64
|
+
f(this);
|
|
60
65
|
try {
|
|
61
|
-
const { value: n, done:
|
|
62
|
-
|
|
66
|
+
const { value: n, done: e } = (this[o] ?? (this[o] = this[u].call(this, this[l]))).next();
|
|
67
|
+
b(n, this), (r = this[m]) == null || r.call(this, this), e && this.return();
|
|
63
68
|
} catch (n) {
|
|
64
69
|
this.throw(n);
|
|
65
70
|
} finally {
|
|
66
|
-
|
|
71
|
+
f(t);
|
|
67
72
|
}
|
|
68
73
|
},
|
|
69
74
|
throw(t) {
|
|
70
75
|
var r;
|
|
71
76
|
for (let n = this; n; n = n.parentNode) if (typeof ((r = n[o]) == null ? void 0 : r.throw) == "function") try {
|
|
72
|
-
return
|
|
73
|
-
} catch (
|
|
74
|
-
t = new Error(
|
|
77
|
+
return b(n[o].throw(t).value, n);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
t = new Error(e instanceof Error ? e.message : e, { cause: t });
|
|
75
80
|
}
|
|
76
81
|
throw t;
|
|
77
82
|
},
|
|
@@ -86,8 +91,11 @@ const c = Symbol.for("ajo.key"), S = Symbol.for("ajo.memo"), l = Symbol.for("ajo
|
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
};
|
|
94
|
+
new MutationObserver(
|
|
95
|
+
(t) => t.forEach((r) => r.removedNodes.forEach((n) => n.isConnected || n.nodeType == 1 && S(n)))
|
|
96
|
+
).observe(document, { childList: !0, subtree: !0 });
|
|
89
97
|
export {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
U as Fragment,
|
|
99
|
+
q as h,
|
|
100
|
+
b as render
|
|
93
101
|
};
|
package/dist/stream.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index.cjs"),m=require("./html.cjs"),y=async function*(o,n=""){const s=new Map([[n,0]]),t=new Set,i=[],r=(e=n)=>(s.set(e,(s.get(e)??0)+1),e?`${e}:${s.get(e)-1}`:String(s.get(e)-1)),h=(e,c)=>({nodeName:"div","data-ssr":e,children:c}),f=e=>{const c=Promise.resolve(`<script>window.$stream?.push(${JSON.stringify(e)})<\/script>`);t.add(c),c.then(u=>i.push(u)).finally(()=>t.delete(c))};for(const e of m.html(o,{alloc:r,placeholder:h,push:f}))yield e;for(;t.size||i.length;){for(;i.length;)yield i.shift();t.size&&await Promise.race(t)}},d=new Set;async function l({id:o,src:n,h:s}){const t=document.querySelector(`[data-ssr="${o}"]`);if(!t)return d.add({id:o,src:n,h:s});n?a.render(a.h((await import(n)).default,s),t):a.render(s,t);const i=o+":";for(const r of d)r.id.startsWith(i)&&(d.delete(r),l(r))}exports.hydrate=l;exports.stream=y;
|
package/dist/stream.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { render as
|
|
2
|
-
import { html as
|
|
3
|
-
const
|
|
4
|
-
const e = /* @__PURE__ */ new Set(),
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
}, c = (i) => {
|
|
8
|
-
const o = Promise.resolve(`<script>window.$stream?.push(${JSON.stringify(i)})<\/script>`);
|
|
9
|
-
e.add(o), o.then((a) => t.push(a)).finally(() => e.delete(o));
|
|
1
|
+
import { render as l, h as m } from "./index.js";
|
|
2
|
+
import { html as u } from "./html.js";
|
|
3
|
+
const y = async function* (i, n = "") {
|
|
4
|
+
const s = /* @__PURE__ */ new Map([[n, 0]]), e = /* @__PURE__ */ new Set(), o = [], c = (t = n) => (s.set(t, (s.get(t) ?? 0) + 1), t ? `${t}:${s.get(t) - 1}` : String(s.get(t) - 1)), d = (t, r) => ({ nodeName: "div", "data-ssr": t, children: r }), f = (t) => {
|
|
5
|
+
const r = Promise.resolve(`<script>window.$stream?.push(${JSON.stringify(t)})<\/script>`);
|
|
6
|
+
e.add(r), r.then((h) => o.push(h)).finally(() => e.delete(r));
|
|
10
7
|
};
|
|
11
|
-
for (
|
|
12
|
-
for (; e.size; )
|
|
13
|
-
for (
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
8
|
+
for (const t of u(i, { alloc: c, placeholder: d, push: f })) yield t;
|
|
9
|
+
for (; e.size || o.length; ) {
|
|
10
|
+
for (; o.length; ) yield o.shift();
|
|
11
|
+
e.size && await Promise.race(e);
|
|
12
|
+
}
|
|
13
|
+
}, a = /* @__PURE__ */ new Set();
|
|
14
|
+
async function p({ id: i, src: n, h: s }) {
|
|
15
|
+
const e = document.querySelector(`[data-ssr="${i}"]`);
|
|
16
|
+
if (!e) return a.add({ id: i, src: n, h: s });
|
|
17
|
+
n ? l(m((await import(n)).default, s), e) : l(s, e);
|
|
18
|
+
const o = i + ":";
|
|
19
|
+
for (const c of a) c.id.startsWith(o) && (a.delete(c), p(c));
|
|
20
|
+
}
|
|
19
21
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
p as hydrate,
|
|
23
|
+
y as stream
|
|
22
24
|
};
|
package/package.json
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ajo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "ajo is a JavaScript view library for building user interfaces",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"types": "./types.ts",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
6
9
|
"exports": {
|
|
7
10
|
".": {
|
|
8
11
|
"types": "./types.ts",
|
|
9
12
|
"import": "./dist/index.js",
|
|
10
13
|
"require": "./dist/index.cjs"
|
|
11
14
|
},
|
|
12
|
-
"./html": {
|
|
13
|
-
"types": "./types.ts",
|
|
14
|
-
"import": "./dist/html.js",
|
|
15
|
-
"require": "./dist/html.cjs"
|
|
16
|
-
},
|
|
17
15
|
"./context": {
|
|
18
16
|
"types": "./types.ts",
|
|
19
17
|
"import": "./dist/context.js",
|
|
20
18
|
"require": "./dist/context.cjs"
|
|
21
19
|
},
|
|
20
|
+
"./html": {
|
|
21
|
+
"types": "./types.ts",
|
|
22
|
+
"import": "./dist/html.js",
|
|
23
|
+
"require": "./dist/html.cjs"
|
|
24
|
+
},
|
|
22
25
|
"./stream": {
|
|
23
26
|
"types": "./types.ts",
|
|
24
27
|
"import": "./dist/stream.js",
|
|
@@ -29,12 +32,6 @@
|
|
|
29
32
|
"dist",
|
|
30
33
|
"types.ts"
|
|
31
34
|
],
|
|
32
|
-
"scripts": {
|
|
33
|
-
"test": "vitest --run",
|
|
34
|
-
"build": "vite build",
|
|
35
|
-
"bump": "pnpm version patch && git push && git push --tags",
|
|
36
|
-
"release": "pnpm test && pnpm build && pnpm bump && pnpm publish"
|
|
37
|
-
},
|
|
38
35
|
"devDependencies": {
|
|
39
36
|
"@types/node": "24.0.0",
|
|
40
37
|
"happy-dom": "18.0.1",
|
|
@@ -53,5 +50,11 @@
|
|
|
53
50
|
"author": "Cristian Falcone",
|
|
54
51
|
"license": "ISC",
|
|
55
52
|
"bugs": "https://github.com/cristianfalcone/ajo/issues",
|
|
56
|
-
"homepage": "https://github.com/cristianfalcone/ajo#readme"
|
|
57
|
-
|
|
53
|
+
"homepage": "https://github.com/cristianfalcone/ajo#readme",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"test": "vitest --run",
|
|
56
|
+
"build": "vite build",
|
|
57
|
+
"bump": "pnpm version patch && git push && git push --tags",
|
|
58
|
+
"release": "pnpm test && pnpm build && pnpm bump && pnpm publish"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/types.ts
CHANGED
|
@@ -1,88 +1,99 @@
|
|
|
1
1
|
declare module 'ajo' {
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type Tag = keyof (HTMLElementTagNameMap & SVGElementTagNameMap)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type Type = Tag | Stateless | Stateful
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
type Component<TProps extends Props = {}> = Stateless<TProps> | Stateful<TProps>
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
type Props = Record<string, unknown>
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
type VNode<TTag extends Type, TProps extends Props> = TProps & {
|
|
12
|
+
nodeName: TTag,
|
|
13
|
+
children?: Children,
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
type Children = unknown
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
type ElementType<TTag> = TTag extends keyof HTMLElementTagNameMap
|
|
19
|
+
? HTMLElementTagNameMap[TTag]
|
|
20
|
+
: TTag extends keyof SVGElementTagNameMap
|
|
21
|
+
? SVGElementTagNameMap[TTag]
|
|
22
|
+
: never
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
type SpecialProps<TElement> = {
|
|
25
|
+
key: unknown,
|
|
26
|
+
skip: boolean,
|
|
27
|
+
memo: unknown,
|
|
28
|
+
ref: (el: TElement | null) => void,
|
|
29
|
+
} & ElementChildrenAttribute
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
type PropSetter<TTag> = {
|
|
32
|
+
[K in keyof ElementType<TTag> as `set:${Exclude<K, symbol>}`]: ElementType<TTag>[K]
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
type AttrSetter = {
|
|
36
|
+
[key: `attr:${string}`]: unknown
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
type Stateless<TArguments extends Props = {}> = (args: TArguments) => Children
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
type Stateful<TArguments extends Props = {}, TTag extends Tag = 'div'> = {
|
|
42
|
+
(this: StatefulElement<TTag>, args: StatefulProps<TArguments, TTag>): Iterator<Children>
|
|
43
|
+
} & (TTag extends 'div' ? { is?: TTag } : { is: TTag }) & { attrs?: Partial<PropSetter<TTag>> & Props, args?: Partial<TArguments> }
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
type StatefulProps<TArguments, TTag> =
|
|
46
|
+
Partial<SpecialProps<StatefulElement<TTag>> & PropSetter<TTag>> &
|
|
47
|
+
AttrSetter &
|
|
48
|
+
TArguments
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
type StatefulElement<TTag> = ElementType<TTag> & {
|
|
51
|
+
render: () => void,
|
|
52
|
+
next: () => void,
|
|
53
|
+
throw: (value?: unknown) => void,
|
|
54
|
+
return: () => void,
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
type IntrinsicElements = {
|
|
58
|
+
[TTag in Tag]: Partial<PropSetter<TTag> & SpecialProps<ElementType<TTag>>> & Props
|
|
59
|
+
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
type ElementChildrenAttribute = { children: Children }
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
function Fragment({ children }: ElementChildrenAttribute): typeof children
|
|
64
|
+
function h(tag: Type, props?: Props | null, ...children: Children[]): VNode<Type, Props>
|
|
65
|
+
function render(h: Children, el: Element, child?: Node, ref?: Node): void
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
declare module 'ajo/
|
|
68
|
+
declare module 'ajo/context' {
|
|
69
|
+
function context<T>(fallback?: T): (value?: T) => T
|
|
70
|
+
}
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
declare module 'ajo/html' {
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
type Patch = {
|
|
75
|
+
id: string,
|
|
76
|
+
h?: import('ajo').Children,
|
|
77
|
+
src?: string,
|
|
78
|
+
done?: boolean,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type Hooks = {
|
|
82
|
+
alloc?: (parentId: string) => string,
|
|
83
|
+
placeholder?: (id: string, children: import('ajo').Children) => unknown,
|
|
84
|
+
push?: (patch: Patch) => void,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function render(h: import('ajo').Children): string
|
|
88
|
+
function html(h: import('ajo').Children, hooks?: Hooks): IterableIterator<string>
|
|
74
89
|
}
|
|
75
90
|
|
|
76
91
|
declare module 'ajo/stream' {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
declare module 'ajo/context' {
|
|
82
|
-
function context<T>(fallback?: T): (value?: T) => T
|
|
92
|
+
function stream(h: import('ajo').Children): AsyncIterableIterator<string>
|
|
93
|
+
function hydrate(patch: import('ajo/html').Patch): Promise<void>
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
declare namespace JSX {
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
type ElementChildrenAttribute = import('ajo').ElementChildrenAttribute
|
|
98
|
+
type IntrinsicElements = import('ajo').IntrinsicElements
|
|
88
99
|
}
|