ajo 0.1.31 → 0.1.33

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/context.js CHANGED
@@ -1,11 +1 @@
1
- const e = /* @__PURE__ */ Symbol.for("ajo.context"), r = (t, o = /* @__PURE__ */ Symbol()) => function(...l) {
2
- const n = this ?? c;
3
- return n ? l.length ? n[e][o] = l[0] : o in n[e] ? n[e][o] : t : t;
4
- };
5
- let c = null;
6
- const s = (...t) => t.length ? c = t[0] : c;
7
- export {
8
- e as Context,
9
- r as context,
10
- s as current
11
- };
1
+ var t=Symbol.for("ajo.context"),n=(n,o=Symbol())=>function(...l){let r=this??e;return r?l.length?r[t][o]=l[0]:o in r[t]?r[t][o]:n:n},e=null,o=(...t)=>t.length?e=t[0]:e;export{t as Context,n as context,o as current};
package/dist/html.js CHANGED
@@ -1,54 +1 @@
1
- import { Context as u, current as s } from "./context.js";
2
- const p = /* @__PURE__ */ new Set(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]), k = /* @__PURE__ */ Symbol.for("ajo.args"), d = (e) => e.replace(/[&<>"']/g, (n) => `&#${n.charCodeAt(0)};`), y = () => {
3
- }, x = (e) => [...g(e)].join(""), g = function* (e) {
4
- for (e of c(e))
5
- typeof e == "string" ? yield d(e) : yield* $(e);
6
- }, $ = function* ({ nodeName: e, children: n, ...i }) {
7
- let o = "";
8
- for (const r in i)
9
- r.startsWith("set:") || i[r] == null || i[r] === !1 || (i[r] === !0 ? o += ` ${r}` : o += ` ${r}="${d(String(i[r]))}"`);
10
- p.has(e) ? yield `<${e}${o}>` : (yield `<${e}${o}>`, n != null && (yield* g(n)), yield `</${e}>`);
11
- }, c = function* (e) {
12
- if (e == null) return;
13
- const n = typeof e;
14
- if (n != "boolean")
15
- if (n == "string") yield e;
16
- else if (n == "number" || n == "bigint") yield String(e);
17
- else if (Symbol.iterator in e) for (e of e) yield* c(e);
18
- else "nodeName" in e ? typeof e.nodeName == "function" ? yield* w(e) : yield m(e) : yield String(e);
19
- }, w = function* ({ nodeName: e, fallback: n = e.fallback, ...i }) {
20
- e.constructor.name == "GeneratorFunction" ? yield S(e, i) : yield* c(e(i));
21
- }, S = (e, n) => {
22
- const i = { ...e.attrs }, o = { ...e.args };
23
- for (const t in n)
24
- t.startsWith("attr:") ? i[t.slice(5)] = n[t] : t == "key" || t == "skip" || t == "memo" || t == "ref" || t.startsWith("set:") ? i[t] = n[t] : o[t] = n[t];
25
- const r = new AbortController(), l = {
26
- [u]: Object.create(s()?.[u] ?? null),
27
- [k]: o,
28
- signal: r.signal,
29
- next: y,
30
- return: y,
31
- throw: (t) => {
32
- throw t;
33
- }
34
- }, a = e.call(l, o), b = s();
35
- s(l);
36
- const f = (t) => ({ ...i, nodeName: e.is ?? "div", ...m({ children: t }) });
37
- try {
38
- return f(a.next().value);
39
- } catch (t) {
40
- return f(a.throw(t).value);
41
- } finally {
42
- a.return(), r.abort(), s(b);
43
- }
44
- }, m = ({ key: e, skip: n, memo: i, ref: o, ...r }) => {
45
- if ("children" in r) {
46
- const l = [...c(r.children)];
47
- l.length ? r.children = l.length == 1 ? l[0] : l : delete r.children;
48
- }
49
- return r;
50
- };
51
- export {
52
- g as html,
53
- x as render
54
- };
1
+ import{isVNode as t,mark as n}from"./jsx.js";import{Context as e,current as o}from"./context.js";var{keys:r}=Object,a=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),l=Symbol.for("ajo.args"),s=e=>e.replace(/[&<>"']/g,e=>`&#${e.charCodeAt(0)};`),i=/^[A-Za-z][\w:.-]*$/,m=/^[^\s"'/>=\0-\x1F\x7F]+$/,f=()=>{},c={tag:"div"},u=e=>{let t="";return d(e,e=>t+=e),t},d=(e,r)=>{if(null==e)return;let a=typeof e;if("boolean"!=a)if("string"==a)r(s(e));else if("number"==a||"bigint"==a)r(s(String(e)));else if(t(e))"function"==typeof e.nodeName?b(e,r):g(e,r);else if(Symbol.iterator in Object(e))for(e of e)d(e,r);else r(s(String(e)))},g=(e,t)=>{let{nodeName:o,children:n}=e;o="string"==typeof o&&i.test(o)?o:c.tag;let l="";for(let t of r(e))"nodeName"==t||"children"==t||"key"==t||"skip"==t||"memo"==t||"ref"==t||t.startsWith("set:")||!m.test(t)||null==e[t]||!1===e[t]||(!0===e[t]?l+=` ${t}`:l+=` ${t}="${s(String(e[t]))}"`);t(`<${o}${l}>`),a.has(o)||(null!=n&&d(n,t),t(`</${o}>`))},b=({nodeName:e,...t},r)=>{"GeneratorFunction"==e.constructor.name?h(e,t,r):d(e(t),r)},h=(t,a,s)=>{let i={...t.attrs},m={...t.args};for(let e of r(a))e.startsWith("attr:")?i[e.slice(5)]=a[e]:"key"==e||"skip"==e||"memo"==e||"ref"==e||e.startsWith("set:")?i[e]=a[e]:m[e]=a[e];let u=new AbortController,d={*[Symbol.iterator](){for(;;)yield this[l]},[e]:Object.create(o()?.[e]??null),[l]:m,signal:u.signal,next:f,return:f,throw:e=>{throw e}},b=t.call(d,m),h=o();o(d);let y=e=>n({...i,nodeName:t.is??c.tag,children:e}),p="";try{g(y(b.next().value),e=>p+=e)}catch(t){p="",g(y(b.throw(t).value),e=>p+=e)}finally{b.return(),u.abort(),o(h)}s(p)};export{c as defaults,d as html,u as render};
package/dist/index.js CHANGED
@@ -1,94 +1 @@
1
- import { Context as j, current as l } from "./context.js";
2
- const u = /* @__PURE__ */ Symbol.for("ajo.key"), p = /* @__PURE__ */ Symbol.for("ajo.memo"), g = /* @__PURE__ */ Symbol.for("ajo.ref"), A = /* @__PURE__ */ Symbol.for("ajo.cache"), a = /* @__PURE__ */ Symbol.for("ajo.generator"), o = /* @__PURE__ */ Symbol.for("ajo.iterator"), m = /* @__PURE__ */ Symbol.for("ajo.render"), c = /* @__PURE__ */ Symbol.for("ajo.args"), C = /* @__PURE__ */ Symbol.for("ajo.controller"), U = (e) => e.children, q = (e, t, ...r) => ((t ??= {}).nodeName = e, !("children" in t) && r.length && (t.children = r.length == 1 ? r[0] : r), t), b = (e, t, r = t.firstChild, s = null) => {
3
- for (e of S(e)) {
4
- const n = G(e, t, r);
5
- r == null ? y(t, n, s) : n == r ? r = n.nextSibling : n == r.nextSibling ? (y(t, r, s), r = n.nextSibling) : y(t, n, r);
6
- }
7
- for (; r != s; ) {
8
- const n = r.nextSibling;
9
- r.nodeType == 1 && h(r), t.removeChild(r), r = n;
10
- }
11
- }, S = function* (e) {
12
- if (e == null) return;
13
- const t = typeof e;
14
- if (t != "boolean")
15
- if (t == "string") yield e;
16
- else if (t == "number" || t == "bigint") yield String(e);
17
- else if (Symbol.iterator in e) for (e of e) yield* S(e);
18
- else "nodeName" in e ? typeof e.nodeName == "function" ? yield* v(e) : yield e : yield String(e);
19
- }, v = function* ({ nodeName: e, ...t }) {
20
- e.constructor.name == "GeneratorFunction" ? yield E(e, t) : yield* S(e(t));
21
- }, E = (e, t) => {
22
- const r = { ...e.attrs }, s = { ...e.args };
23
- for (const n in t)
24
- n.startsWith("attr:") ? r[n.slice(5)] = t[n] : n == "key" || n == "skip" || n == "memo" || n == "ref" || n.startsWith("set:") ? r[n] = t[n] : s[n] = t[n];
25
- return { ...r, nodeName: e.is ?? "div", [a]: e, [c]: s };
26
- }, G = (e, t, r) => typeof e == "string" ? O(e, r) : R(e, t, r), O = (e, t) => {
27
- for (; t && t.nodeType != 3; ) t = t.nextSibling;
28
- return t ? t.data != e && (t.data = e) : t = document.createTextNode(e), t;
29
- }, R = ({ nodeName: e, children: t, key: r, skip: s, memo: n, ref: x, [a]: f, [c]: N, ...w }, k, i) => {
30
- for (; i && (i.localName != e || i[u] != null && i[u] != r || i[a] && i[a] != f); ) i = i.nextSibling;
31
- return i ??= document.createElementNS(w.xmlns ?? k.namespaceURI, e), r != null && (i[u] = r), (n == null || W(i[p], i[p] = n)) && (T(i[A] ?? B(i), i[A] = w, i), s || (f ? F(f, N, i) : b(t, i)), typeof x == "function" && (i[g] = x)(i)), i;
32
- }, T = (e, t, r) => {
33
- for (const s in { ...e, ...t })
34
- e[s] !== t[s] && (s.startsWith("set:") ? r[s.slice(4)] = t[s] : t[s] == null || t[s] === !1 ? r.removeAttribute(s) : r.setAttribute(s, t[s] === !0 ? "" : t[s]));
35
- }, W = (e, t) => Array.isArray(e) && Array.isArray(t) ? e.some((r, s) => r !== t[s]) : e !== t, B = (e) => Array.from(e.attributes).reduce((t, r) => (t[r.name] = r.value, t), {}), y = (e, t, r) => {
36
- if (t.contains(document.activeElement)) {
37
- const s = t.nextSibling;
38
- for (; r && r != t; ) {
39
- const n = r.nextSibling;
40
- e.insertBefore(r, s), r = n;
41
- }
42
- } else e.insertBefore(t, r);
43
- }, h = (e) => {
44
- for (const t of e.children) h(t);
45
- typeof e.return == "function" && e.return(), e[g]?.(null);
46
- }, F = (e, t, r) => {
47
- r[a] ??= (I(r), e), Object.assign(r[c] ??= {}, t), r[m]();
48
- }, I = (e) => {
49
- Object.assign(e, K), e[j] = Object.create(l()?.[j] ?? null);
50
- }, K = {
51
- [m]() {
52
- const e = l();
53
- l(this);
54
- try {
55
- this[o] || (this.signal = (this[C] = new AbortController()).signal, this[o] = this[a].call(this, this[c]));
56
- const { value: t, done: r } = this[o].next();
57
- b(t, this), this[g]?.(this), r && this.return();
58
- } catch (t) {
59
- this.throw(t);
60
- } finally {
61
- l(e);
62
- }
63
- },
64
- next(e, t) {
65
- try {
66
- typeof e == "function" && (t = e.call(this, this[c]));
67
- } catch (r) {
68
- return this.throw(r);
69
- }
70
- return l()?.contains(this) || this[m](), t;
71
- },
72
- throw(e) {
73
- for (let t = this; t; t = t.parentNode) if (t[o]?.throw) try {
74
- return b(t[o].throw(e).value, t);
75
- } catch (r) {
76
- e = new Error(r?.message ?? r, { cause: e });
77
- }
78
- throw e;
79
- },
80
- return() {
81
- try {
82
- this[o]?.return();
83
- } catch (e) {
84
- this.throw(e);
85
- } finally {
86
- this[o] = null, this[C]?.abort();
87
- }
88
- }
89
- };
90
- export {
91
- U as Fragment,
92
- q as h,
93
- b as render
94
- };
1
+ import{isVNode as t,mark as n}from"./jsx.js";import{Context as e,current as o}from"./context.js";var y,{isArray:r}=Array,{assign:a,hasOwn:l,keys:s}=Object,i=Symbol.for("ajo.key"),m=Symbol.for("ajo.keyed"),f=Symbol.for("ajo.memo"),c=Symbol.for("ajo.cache"),u=Symbol.for("ajo.generator"),d=Symbol.for("ajo.iterator"),g=Symbol.for("ajo.render"),b=Symbol.for("ajo.args"),h=Symbol.for("ajo.controller"),p={tag:"div"},S=(e,t)=>(t&&(e.is=t),e),x=(e,t,r=t.firstChild,n=null)=>{if(C(e,e=>{let i="string"==typeof e?E(e,r,n):k(e,t,r,n);null==r?A(t,i,n):i==r?r=i.nextSibling:i==r.nextSibling?(A(t,r,n),r=i.nextSibling):A(t,i,r)}),r&&!n&&r==t.firstChild){let e=[];for(t[m]?.clear();r;)e.push(r),r=r.nextSibling;for(r of(t.textContent="",e))1==r.nodeType&&O(r)}else for(;r&&r!=n;){let e=r.nextSibling,n=t.removeChild(r);1==n.nodeType&&O(n,t),r=e}},C=(e,r)=>{if(null==e)return;let n=typeof e;if("boolean"!=n)if("string"==n)r(e);else if("number"==n||"bigint"==n)r(String(e));else if(t(e))"function"==typeof e.nodeName?N(e,r):r(e);else if(Symbol.iterator in Object(e))for(e of e)C(e,r);else r(String(e))},N=({nodeName:e,...t},r)=>{"GeneratorFunction"==e.constructor.name?r(j(e,t)):C(e(t),r)},j=(e,t)=>{let r={...e.attrs},i={...e.args};for(let e of s(t))e.startsWith("attr:")?r[e.slice(5)]=t[e]:"key"==e||"skip"==e||"memo"==e||"ref"==e||e.startsWith("set:")?r[e]=t[e]:i[e]=t[e];return n({...r,nodeName:e.is??p.tag,[u]:e,[b]:i})},E=(e,t,r)=>{for(;t&&t!=r&&3!=t.nodeType;)t=t.nextSibling;return t&&t!=r?t.data!=e&&(t.data=e):t=document.createTextNode(e),t},k=(e,t,r,n)=>{let o=e.nodeName,l=e.key,s=e[u];for(r&&null!=l&&null==n&&(r=(t[m]??=new Map).get(l)??r);r&&r!=n&&(r.localName!=o||null!=r[i]&&r[i]!=l||r[u]&&r[u]!=s);)r=null==r[i]?r.nextElementSibling:null;return r==n&&(r=null),r??=document.createElementNS(e.xmlns??t.namespaceURI,o),null!=l&&(t[m]??=new Map).set(r[i]=l,r),(!r[c]||null==e.memo||w(r[f],e.memo))&&(v(r[c],e,r),e.skip||(s?T(s,e[b],r):r[c]||"string"!=typeof e.children&&"number"!=typeof e.children?x(e.children,r):r.textContent=e.children+""),r[f]=e.memo,r[c]=e),r},v=(e,t,r)=>{if(!e)for(let e=r.attributes.length;e--;)l(t,r.attributes[e].name)||r.removeAttribute(r.attributes[e].name);for(let n in t)if(l(t,n)){let i=t[n];if(e&&e[n]===i||"nodeName"==n||"children"==n||"key"==n||"skip"==n||"memo"==n)continue;"ref"==n&&"function"==typeof i?i(r):n.startsWith("set:")?r[n.slice(4)]=i:null==i||!1===i?r.removeAttribute(n):"class"==n&&"string"==typeof r.className?r.className=!0===i?"":i:r.setAttribute(n,!0===i?"":i)}if(e)for(let n in e)if(l(e,n)){if(l(t,n)||"nodeName"==n||"children"==n||"key"==n||"skip"==n||"memo"==n)continue;n.startsWith("set:")?r[n.slice(4)]=void 0:r.removeAttribute(n)}},w=(e,t)=>{if(r(e)&&r(t)){if(e.length!=t.length)return!0;for(let r=e.length;r--;)if(e[r]!==t[r])return!0;return!1}return e!==t},A=(e,t,r)=>{if(t.isConnected&&t.contains(document.activeElement)){let n=t.nextSibling;for(;r&&r!=t;){let t=r.nextSibling;e.insertBefore(r,n),r=t}}else e.insertBefore(t,r)},O=(e,t)=>{if(e[f]==O)return;e[f]=O;let r=e;for(;r.firstElementChild;)r=r.firstElementChild;for(;;){let{nextElementSibling:n,parentNode:o}=r;if(null!=r[i]&&(o??t)?.[m]?.delete(r[i]),"function"==typeof r.return&&r.return(!1),"function"==typeof r[c]?.ref&&r[c].ref(null),r===e)break;if(r=n??o??e,n)for(;r.firstElementChild;)r=r.firstElementChild}},T=(t,r,n)=>{n[u]??=(W(),a(n,M)[e]=Object.create(o()?.[e]??null),t);for(let e of s(n[b]??=r))l(r,e)||delete n[b][e];a(n[b],r),n[g]()},W=()=>y||(y=new MutationObserver(e=>{for(let t of e)for(let e of t.removedNodes)1==e.nodeType&&!e.isConnected&&O(e,t.target)})).observe(document,{childList:!0,subtree:!0}),M={*[Symbol.iterator](){for(;;)yield this[b]},[g](){let e=o();o(this);try{this[d]||(this.signal=(this[h]=new AbortController).signal,this[d]=this[u].call(this,this[b]));let{value:e,done:t}=this[d].next();x(e,this),t&&this.return()}catch(e){this.throw(e)}finally{o(e)}},next(e,t){if(!1===this[d]||!this.isConnected)return t;try{"function"==typeof e&&(t=e.call(this,this[b]))}catch(e){return this.throw(e)}return o()?.contains(this)||this[g](),t},throw(e){for(let t=this;t;t=t.parentNode)if(t[d]?.throw)try{return x(t[d].throw(e).value,t)}catch(t){e=Error(t?.message??t,{cause:e})}throw e},return(e=!0){if(!1===this[d])return;let t=this[d];this[d]=!1,e&&((e,t)=>{let r=t.firstElementChild;for(;r;)if(e(r)&&r.firstElementChild)r=r.firstElementChild;else{for(;r!=t&&!r.nextElementSibling;)r=r.parentNode??t;r=r!=t&&r.nextElementSibling}})(e=>"function"!=typeof e.return||e.return(),this);try{t?.return()}catch(e){this.throw(e)}finally{this[d]=null,this[h]?.abort()}}};export{p as defaults,x as render,S as stateful};
package/dist/jsx.js ADDED
@@ -0,0 +1 @@
1
+ var t=Symbol.for("ajo.vnode"),n=a=>(a[t]=a,a),e=a=>a?.[t]===a,o=a=>a.children;function r(a,s,e){return(s??={}).nodeName=a,null!=e&&(s.key=e),n(s)}var a=r,l=r;export{o as Fragment,e as isVNode,r as jsx,l as jsxDEV,a as jsxs,n as mark};
package/html.js CHANGED
@@ -1,4 +1,7 @@
1
- import { Context, current } from 'ajo/context'
1
+ import { Context, current } from './context.js'
2
+ import { isVNode, mark } from './jsx.js'
3
+
4
+ const { keys } = Object
2
5
 
3
6
  const Void = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'])
4
7
 
@@ -6,137 +9,134 @@ const Args = Symbol.for('ajo.args')
6
9
 
7
10
  const escape = s => s.replace(/[&<>"']/g, c => `&#${c.charCodeAt(0)};`)
8
11
 
9
- const noop = () => { }
10
-
11
- export const render = h => [...html(h)].join('')
12
-
13
- export const html = function* (h) {
12
+ const Tag = /^[A-Za-z][\w:.-]*$/, Attr = /^[^\s"'/>=\0-\x1F\x7F]+$/
14
13
 
15
- for (h of walk(h)) {
16
-
17
- if (typeof h == 'string') yield escape(h)
18
-
19
- else yield* element(h)
20
- }
21
- }
22
-
23
- const element = function* ({ nodeName, children, ...h }) {
24
-
25
- let attrs = ''
26
-
27
- for (const key in h) {
28
-
29
- if (key.startsWith('set:') || h[key] == null || h[key] === false) continue
30
-
31
- if (h[key] === true) attrs += ` ${key}`
32
-
33
- else attrs += ` ${key}="${escape(String(h[key]))}"`
34
- }
35
-
36
- if (Void.has(nodeName)) yield `<${nodeName}${attrs}>`
37
-
38
- else {
39
-
40
- yield `<${nodeName}${attrs}>`
41
-
42
- if (children != null) yield* html(children)
43
-
44
- yield `</${nodeName}>`
45
- }
46
- }
47
-
48
- const walk = function* (h) {
14
+ const noop = () => { }
15
+
16
+ export const defaults = { tag: 'div' }
17
+
18
+ export const render = h => {
19
+
20
+ let out = ''
21
+
22
+ html(h, chunk => out += chunk)
23
+
24
+ return out
25
+ }
26
+
27
+ export const html = (h, emit) => {
49
28
 
50
29
  if (h == null) return
51
30
 
52
31
  const type = typeof h
53
32
 
54
33
  if (type == 'boolean') return
34
+
35
+ if (type == 'string') emit(escape(h))
36
+
37
+ else if (type == 'number' || type == 'bigint') emit(escape(String(h)))
38
+
39
+ else if (isVNode(h)) typeof h.nodeName == 'function' ? run(h, emit) : element(h, emit)
55
40
 
56
- if (type == 'string') yield h
57
-
58
- else if (type == 'number' || type == 'bigint') yield String(h)
59
-
60
- else if (Symbol.iterator in h) for (h of h) yield* walk(h)
61
-
62
- else if ('nodeName' in h) typeof h.nodeName == 'function' ? yield* run(h) : yield vdom(h)
63
-
64
- else yield String(h)
65
- }
66
-
67
- const run = function* ({ nodeName, fallback = nodeName.fallback, ...h }) {
68
-
69
- if (nodeName.constructor.name == 'GeneratorFunction') yield runGenerator(nodeName, h)
41
+ else if (Symbol.iterator in Object(h)) for (h of h) html(h, emit)
70
42
 
71
- else yield* walk(nodeName(h))
43
+ else emit(escape(String(h)))
72
44
  }
45
+
46
+ const element = (h, emit) => {
47
+
48
+ let { nodeName, children } = h
73
49
 
74
- const runGenerator = (fn, h) => {
50
+ nodeName = typeof nodeName == 'string' && Tag.test(nodeName) ? nodeName : defaults.tag
75
51
 
76
- const attrs = { ...fn.attrs }, args = { ...fn.args }
52
+ let a = ''
77
53
 
78
- for (const key in h) {
54
+ for (const key of keys(h)) {
79
55
 
80
- if (key.startsWith('attr:')) attrs[key.slice(5)] = h[key]
56
+ if (key == 'nodeName' || key == 'children' || key == 'key' || key == 'skip' || key == 'memo' || key == 'ref' || key.startsWith('set:') || !Attr.test(key) || h[key] == null || h[key] === false) continue
81
57
 
82
- else if (key == 'key' || key == 'skip' || key == 'memo' || key == 'ref' || key.startsWith('set:')) attrs[key] = h[key]
58
+ if (h[key] === true) a += ` ${key}`
83
59
 
84
- else args[key] = h[key]
60
+ else a += ` ${key}="${escape(String(h[key]))}"`
85
61
  }
86
-
87
- const controller = new AbortController()
88
-
89
- const instance = {
90
-
91
- [Context]: Object.create(current()?.[Context] ?? null),
92
-
93
- [Args]: args,
94
-
95
- signal: controller.signal,
96
-
97
- next: noop,
98
-
99
- return: noop,
100
-
101
- throw: value => { throw value }
102
- }
103
-
104
- const iterator = fn.call(instance, args)
105
-
106
- const parent = current()
107
-
108
- current(instance)
109
-
110
- const result = children => ({ ...attrs, nodeName: fn.is ?? 'div', ...vdom({ children }) })
62
+
63
+ emit(`<${nodeName}${a}>`)
64
+
65
+ if (!Void.has(nodeName)) {
66
+
67
+ if (children != null) html(children, emit)
68
+
69
+ emit(`</${nodeName}>`)
70
+ }
71
+ }
72
+
73
+ const run = ({ nodeName, ...h }, emit) => {
74
+
75
+ if (nodeName.constructor.name == 'GeneratorFunction') runGenerator(nodeName, h, emit)
76
+
77
+ else html(nodeName(h), emit)
78
+ }
79
+
80
+ const runGenerator = (fn, h, emit) => {
81
+
82
+ const attrs = { ...fn.attrs }, args = { ...fn.args }
83
+
84
+ for (const key of keys(h)) {
85
+
86
+ if (key.startsWith('attr:')) attrs[key.slice(5)] = h[key]
87
+
88
+ else if (key == 'key' || key == 'skip' || key == 'memo' || key == 'ref' || key.startsWith('set:')) attrs[key] = h[key]
89
+
90
+ else args[key] = h[key]
91
+ }
92
+
93
+ const controller = new AbortController()
94
+
95
+ const instance = {
96
+
97
+ *[Symbol.iterator]() { while (true) yield this[Args] },
98
+
99
+ [Context]: Object.create(current()?.[Context] ?? null),
100
+
101
+ [Args]: args,
102
+
103
+ signal: controller.signal,
104
+
105
+ next: noop,
106
+
107
+ return: noop,
108
+
109
+ throw: value => { throw value }
110
+ }
111
+
112
+ const iterator = fn.call(instance, args)
113
+
114
+ const parent = current()
115
+
116
+ current(instance)
117
+
118
+ const vnode = children => mark({ ...attrs, nodeName: fn.is ?? defaults.tag, children })
119
+
120
+ let out = ''
111
121
 
112
122
  try {
113
123
 
114
- return result(iterator.next().value)
124
+ element(vnode(iterator.next().value), chunk => out += chunk)
115
125
 
116
126
  } catch (error) {
117
127
 
118
- return result(iterator.throw(error).value)
119
-
120
- } finally {
121
-
122
- iterator.return()
123
-
124
- controller.abort()
125
-
126
- current(parent)
127
- }
128
- }
129
-
130
- const vdom = ({ key, skip, memo, ref, ...h }) => {
131
-
132
- if ('children' in h) {
133
-
134
- const children = [...walk(h.children)]
135
-
136
- if (children.length) h.children = children.length == 1 ? children[0] : children
137
-
138
- else delete h.children
139
- }
140
-
141
- return h
142
- }
128
+ out = ''
129
+
130
+ element(vnode(iterator.throw(error).value), chunk => out += chunk)
131
+
132
+ } finally {
133
+
134
+ iterator.return()
135
+
136
+ controller.abort()
137
+
138
+ current(parent)
139
+ }
140
+
141
+ emit(out)
142
+ }