ajo 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,93 +1,110 @@
1
- import { Context as j, current as c } 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"), o = /* @__PURE__ */ Symbol.for("ajo.generator"), a = /* @__PURE__ */ Symbol.for("ajo.iterator"), m = /* @__PURE__ */ Symbol.for("ajo.render"), l = /* @__PURE__ */ Symbol.for("ajo.args"), U = (e) => e.children, h = (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);
1
+ import { Context as x, current as c } from "./context.js";
2
+ const { isArray: h } = Array, { assign: N, create: A } = Object, l = /* @__PURE__ */ Symbol.for("ajo.key"), b = /* @__PURE__ */ Symbol.for("ajo.keyed"), C = /* @__PURE__ */ Symbol.for("ajo.memo"), u = /* @__PURE__ */ Symbol.for("ajo.cache"), a = /* @__PURE__ */ Symbol.for("ajo.generator"), o = /* @__PURE__ */ Symbol.for("ajo.iterator"), g = /* @__PURE__ */ Symbol.for("ajo.render"), f = /* @__PURE__ */ Symbol.for("ajo.args"), E = /* @__PURE__ */ Symbol.for("ajo.controller"), v = { tag: "div" }, q = (r, t) => (t && (r.is = t), r), S = (r, t, e = t.firstChild, i = null) => {
3
+ for (p(r, (n) => {
4
+ const s = typeof n == "string" ? W(n, e) : B(n, t, e);
5
+ e == null ? y(t, s, i) : s == e ? e = s.nextSibling : s == e.nextSibling ? (y(t, e, i), e = s.nextSibling) : y(t, s, e);
6
+ }); e != i; ) {
7
+ const n = e.nextSibling;
8
+ e.nodeType == 1 && R(e), t.removeChild(e), e = n;
6
9
  }
7
- for (; r != s; ) {
8
- const n = r.nextSibling;
9
- r.nodeType == 1 && N(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* C(e) : yield e : yield String(e);
19
- }, C = 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 };
10
+ }, p = (r, t) => {
11
+ if (r == null) return;
12
+ const e = typeof r;
13
+ if (e != "boolean")
14
+ if (e == "string") t(r);
15
+ else if (e == "number" || e == "bigint") t(String(r));
16
+ else if (Symbol.iterator in r) for (r of r) p(r, t);
17
+ else "nodeName" in r ? typeof r.nodeName == "function" ? G(r, t) : t(r) : t(String(r));
18
+ }, G = ({ nodeName: r, ...t }, e) => {
19
+ r.constructor.name == "GeneratorFunction" ? e(T(r, t)) : p(r(t), e);
20
+ }, T = (r, t) => {
21
+ const e = { ...r.attrs }, i = { ...r.args };
23
22
  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", [o]: e, [l]: s };
26
- }, G = (e, t, r) => typeof e == "string" ? O(e, r) : R(e, t, r), O = (e, t) => {
23
+ n.startsWith("attr:") ? e[n.slice(5)] = t[n] : n == "key" || n == "skip" || n == "memo" || n == "ref" || n.startsWith("set:") ? e[n] = t[n] : i[n] = t[n];
24
+ return { ...e, nodeName: r.is ?? v.tag, [a]: r, [f]: i };
25
+ }, W = (r, t) => {
27
26
  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, [o]: f, [l]: k, ...w }, v, i) => {
30
- for (; i && (i.localName != e || i[u] != null && i[u] != r || i[o] && i[o] != f); ) i = i.nextSibling;
31
- return i ??= document.createElementNS(w.xmlns ?? v.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, k, 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;
27
+ return t ? t.data != r && (t.data = r) : t = document.createTextNode(r), t;
28
+ }, B = (r, t, e) => {
29
+ const { nodeName: i, children: n, key: s, skip: k, memo: w, [a]: m, [f]: j } = r;
30
+ for (s != null && (e = (t[b] ??= /* @__PURE__ */ new Map()).get(s) ?? e); e && (e.localName != i || e[l] != null && e[l] != s || e[a] && e[a] != m); ) e = e[l] != null ? null : e.nextElementSibling;
31
+ return e ??= document.createElementNS(r.xmlns ?? t.namespaceURI, i), s != null && t[b].set(e[l] = s, e), (w == null || K(e[C], e[C] = w)) && (I(e[u], e[u] = r, e), k || (m ? F(m, j, e) : S(n, e))), e;
32
+ }, I = (r, t, e) => {
33
+ for (const i in { ...r, ...t })
34
+ i == "nodeName" || i == "children" || i == "key" || i == "skip" || i == "memo" || r?.[i] === t[i] || (i == "ref" && typeof t[i] == "function" ? t[i](e) : i.startsWith("set:") ? e[i.slice(4)] = t[i] : t[i] == null || t[i] === !1 ? e.removeAttribute(i) : e.setAttribute(i, t[i] === !0 ? "" : t[i]));
35
+ }, K = (r, t) => h(r) && h(t) ? r.some((e, i) => e !== t[i]) : r !== t, M = (r, t) => {
36
+ let e = t.firstElementChild;
37
+ for (; e; )
38
+ if (r(e) && e.firstElementChild) e = e.firstElementChild;
39
+ else {
40
+ for (; e != t && !e.nextElementSibling; ) e = e.parentNode ?? t;
41
+ e = e != t && e.nextElementSibling;
42
+ }
43
+ }, y = (r, t, e) => {
44
+ if (t.isConnected && t.contains(document.activeElement)) {
45
+ const i = t.nextSibling;
46
+ for (; e && e != t; ) {
47
+ const n = e.nextSibling;
48
+ r.insertBefore(e, i), e = n;
41
49
  }
42
- } else e.insertBefore(t, r);
43
- }, N = (e) => {
44
- for (const t of e.children) N(t);
45
- typeof e.return == "function" && e.return(), e[g]?.(null);
46
- }, F = (e, t, r) => {
47
- r[o] ??= (I(r), e), Object.assign(r[l] ??= {}, t), r[m]();
48
- }, I = (e) => {
49
- Object.assign(e, K), e[j] = Object.create(c()?.[j] ?? null);
50
- }, K = {
51
- [m]() {
52
- const e = c();
50
+ } else r.insertBefore(t, e);
51
+ }, R = (r) => {
52
+ let t = r;
53
+ for (; t.firstElementChild; ) t = t.firstElementChild;
54
+ for (; ; ) {
55
+ const { nextElementSibling: e, parentNode: i } = t;
56
+ if (t[l] != null && i?.[b]?.delete(t[l]), typeof t.return == "function" && t.return(!1), typeof t[u]?.ref == "function" && t[u].ref(null), t === r) break;
57
+ if (t = e ?? i ?? r, e) for (; t.firstElementChild; ) t = t.firstElementChild;
58
+ }
59
+ }, F = (r, t, e) => {
60
+ e[a] ??= (N(e, O)[x] = A(c()?.[x] ?? null), r), e[f] = t, e[g]();
61
+ }, O = {
62
+ *[Symbol.iterator]() {
63
+ for (; ; ) yield this[f];
64
+ },
65
+ [g]() {
66
+ const r = c();
53
67
  c(this);
54
68
  try {
55
- const { value: t, done: r } = (this[a] ??= this[o].call(this, this[l])).next();
56
- b(t, this), this[g]?.(this), r && this.return();
69
+ this[o] || (this.signal = (this[E] = new AbortController()).signal, this[o] = this[a].call(this, this[f]));
70
+ const { value: t, done: e } = this[o].next();
71
+ S(t, this), e && this.return();
57
72
  } catch (t) {
58
73
  this.throw(t);
59
74
  } finally {
60
- c(e);
75
+ c(r);
61
76
  }
62
77
  },
63
- next(e) {
78
+ next(r, t) {
79
+ if (!this.isConnected) return t;
64
80
  try {
65
- e?.call(this, this[l]);
66
- } catch (t) {
67
- return this.throw(t);
81
+ typeof r == "function" && (t = r.call(this, this[f]));
82
+ } catch (e) {
83
+ return this.throw(e);
68
84
  }
69
- c()?.contains(this) || this[m]();
85
+ return c()?.contains(this) || this[g](), t;
70
86
  },
71
- throw(e) {
72
- for (let t = this; t; t = t.parentNode) if (t[a]?.throw) try {
73
- return b(t[a].throw(e).value, t);
74
- } catch (r) {
75
- e = new Error(r?.message ?? r, { cause: e });
87
+ throw(r) {
88
+ for (let t = this; t; t = t.parentNode) if (t[o]?.throw) try {
89
+ return S(t[o].throw(r).value, t);
90
+ } catch (e) {
91
+ r = new Error(e?.message ?? e, { cause: r });
76
92
  }
77
- throw e;
93
+ throw r;
78
94
  },
79
- return() {
95
+ return(r = !0) {
96
+ r && M((t) => typeof t.return == "function" ? t.return() : !0, this);
80
97
  try {
81
- this[a]?.return();
82
- } catch (e) {
83
- this.throw(e);
98
+ this[o]?.return();
99
+ } catch (t) {
100
+ this.throw(t);
84
101
  } finally {
85
- this[a] = null;
102
+ this[o] = null, this[E]?.abort();
86
103
  }
87
104
  }
88
105
  };
89
106
  export {
90
- U as Fragment,
91
- h,
92
- b as render
107
+ v as defaults,
108
+ S as render,
109
+ q as stateful
93
110
  };
package/dist/jsx.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=e=>e.children,c=(e,n,...t)=>((n??={}).nodeName=e,!("children"in n)&&t.length&&(n.children=t.length==1?t[0]:t),n);function s(e,n,t){return t!=null&&((n??={}).key=t),c(e,n)}const j=s,l=s;exports.Fragment=i;exports.h=c;exports.jsx=s;exports.jsxDEV=l;exports.jsxs=j;
package/dist/jsx.js ADDED
@@ -0,0 +1,12 @@
1
+ const l = (e) => e.children, i = (e, n, ...t) => ((n ??= {}).nodeName = e, !("children" in n) && t.length && (n.children = t.length == 1 ? t[0] : t), n);
2
+ function c(e, n, t) {
3
+ return t != null && ((n ??= {}).key = t), i(e, n);
4
+ }
5
+ const s = c, u = c;
6
+ export {
7
+ l as Fragment,
8
+ i as h,
9
+ c as jsx,
10
+ u as jsxDEV,
11
+ s as jsxs
12
+ };
package/html.js ADDED
@@ -0,0 +1,137 @@
1
+ import { Context, current } from './context.js'
2
+
3
+ const Void = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'])
4
+
5
+ const Args = Symbol.for('ajo.args')
6
+
7
+ const escape = s => s.replace(/[&<>"']/g, c => `&#${c.charCodeAt(0)};`)
8
+
9
+ const noop = () => { }
10
+
11
+ export const defaults = { tag: 'div' }
12
+
13
+ export const render = h => {
14
+
15
+ let out = ''
16
+
17
+ html(h, chunk => out += chunk)
18
+
19
+ return out
20
+ }
21
+
22
+ export const html = (h, emit) => {
23
+
24
+ if (h == null) return
25
+
26
+ const type = typeof h
27
+
28
+ if (type == 'boolean') return
29
+
30
+ if (type == 'string') emit(escape(h))
31
+
32
+ else if (type == 'number' || type == 'bigint') emit(escape(String(h)))
33
+
34
+ else if (Symbol.iterator in h) for (h of h) html(h, emit)
35
+
36
+ else if ('nodeName' in h) typeof h.nodeName == 'function' ? run(h, emit) : element(h, emit)
37
+
38
+ else emit(escape(String(h)))
39
+ }
40
+
41
+ const element = (h, emit) => {
42
+
43
+ const { nodeName, children } = h
44
+
45
+ let a = ''
46
+
47
+ for (const key in h) {
48
+
49
+ if (key == 'nodeName' || key == 'children' || key == 'key' || key == 'skip' || key == 'memo' || key == 'ref' || key.startsWith('set:') || h[key] == null || h[key] === false) continue
50
+
51
+ if (h[key] === true) a += ` ${key}`
52
+
53
+ else a += ` ${key}="${escape(String(h[key]))}"`
54
+ }
55
+
56
+ if (Void.has(nodeName)) emit(`<${nodeName}${a}>`)
57
+
58
+ else {
59
+
60
+ emit(`<${nodeName}${a}>`)
61
+
62
+ if (children != null) html(children, emit)
63
+
64
+ emit(`</${nodeName}>`)
65
+ }
66
+ }
67
+
68
+ const run = ({ nodeName, fallback = nodeName.fallback, ...h }, emit) => {
69
+
70
+ if (nodeName.constructor.name == 'GeneratorFunction') runGenerator(nodeName, h, emit)
71
+
72
+ else html(nodeName(h), emit)
73
+ }
74
+
75
+ const runGenerator = (fn, h, emit) => {
76
+
77
+ const attrs = { ...fn.attrs }, args = { ...fn.args }
78
+
79
+ for (const key in h) {
80
+
81
+ if (key.startsWith('attr:')) attrs[key.slice(5)] = h[key]
82
+
83
+ else if (key == 'key' || key == 'skip' || key == 'memo' || key == 'ref' || key.startsWith('set:')) attrs[key] = h[key]
84
+
85
+ else args[key] = h[key]
86
+ }
87
+
88
+ const controller = new AbortController()
89
+
90
+ const instance = {
91
+
92
+ *[Symbol.iterator]() { while (true) yield this[Args] },
93
+
94
+ [Context]: Object.create(current()?.[Context] ?? null),
95
+
96
+ [Args]: args,
97
+
98
+ signal: controller.signal,
99
+
100
+ next: noop,
101
+
102
+ return: noop,
103
+
104
+ throw: value => { throw value }
105
+ }
106
+
107
+ const iterator = fn.call(instance, args)
108
+
109
+ const parent = current()
110
+
111
+ current(instance)
112
+
113
+ const vnode = children => ({ ...attrs, nodeName: fn.is ?? defaults.tag, children })
114
+
115
+ let out = ''
116
+
117
+ try {
118
+
119
+ element(vnode(iterator.next().value), chunk => out += chunk)
120
+
121
+ } catch (error) {
122
+
123
+ out = ''
124
+
125
+ element(vnode(iterator.throw(error).value), chunk => out += chunk)
126
+
127
+ } finally {
128
+
129
+ iterator.return()
130
+
131
+ controller.abort()
132
+
133
+ current(parent)
134
+ }
135
+
136
+ emit(out)
137
+ }
package/index.js ADDED
@@ -0,0 +1,309 @@
1
+ import { Context, current } from './context.js'
2
+
3
+ const { isArray } = Array, { assign, create } = Object
4
+
5
+ const Key = Symbol.for('ajo.key')
6
+ const Keyed = Symbol.for('ajo.keyed')
7
+ const Memo = Symbol.for('ajo.memo')
8
+ const Cache = Symbol.for('ajo.cache')
9
+ const Generator = Symbol.for('ajo.generator')
10
+ const Iterator = Symbol.for('ajo.iterator')
11
+ const Render = Symbol.for('ajo.render')
12
+ const Args = Symbol.for('ajo.args')
13
+ const Controller = Symbol.for('ajo.controller')
14
+
15
+ export const defaults = { tag: 'div' }
16
+
17
+ export const stateful = (fn, is) => (is && (fn.is = is), fn)
18
+
19
+ export const render = (h, el, child = el.firstChild, ref = null) => {
20
+
21
+ walk(h, h => {
22
+
23
+ const node = typeof h == 'string' ? text(h, child) : element(h, el, child)
24
+
25
+ if (child == null) {
26
+
27
+ before(el, node, ref)
28
+
29
+ } else if (node == child) {
30
+
31
+ child = node.nextSibling
32
+
33
+ } else if (node == child.nextSibling) {
34
+
35
+ before(el, child, ref)
36
+
37
+ child = node.nextSibling
38
+
39
+ } else {
40
+
41
+ before(el, node, child)
42
+ }
43
+ })
44
+
45
+ while (child != ref) {
46
+
47
+ const node = child.nextSibling
48
+
49
+ if (child.nodeType == 1) unref(child)
50
+
51
+ el.removeChild(child)
52
+
53
+ child = node
54
+ }
55
+ }
56
+
57
+ const walk = (h, fn) => {
58
+
59
+ if (h == null) return
60
+
61
+ const type = typeof h
62
+
63
+ if (type == 'boolean') return
64
+
65
+ if (type == 'string') fn(h)
66
+
67
+ else if (type == 'number' || type == 'bigint') fn(String(h))
68
+
69
+ else if (Symbol.iterator in h) for (h of h) walk(h, fn)
70
+
71
+ else if ('nodeName' in h) typeof h.nodeName == 'function' ? run(h, fn) : fn(h)
72
+
73
+ else fn(String(h))
74
+ }
75
+
76
+ const run = ({ nodeName, ...h }, fn) => {
77
+
78
+ if (nodeName.constructor.name == 'GeneratorFunction') fn(runGenerator(nodeName, h))
79
+
80
+ else walk(nodeName(h), fn)
81
+ }
82
+
83
+ const runGenerator = (fn, h) => {
84
+
85
+ const attrs = { ...fn.attrs }, args = { ...fn.args }
86
+
87
+ for (const key in h) {
88
+
89
+ if (key.startsWith('attr:')) attrs[key.slice(5)] = h[key]
90
+
91
+ else if (key == 'key' || key == 'skip' || key == 'memo' || key == 'ref' || key.startsWith('set:')) attrs[key] = h[key]
92
+
93
+ else args[key] = h[key]
94
+ }
95
+
96
+ return { ...attrs, nodeName: fn.is ?? defaults.tag, [Generator]: fn, [Args]: args }
97
+ }
98
+
99
+ const text = (h, node) => {
100
+
101
+ while (node && node.nodeType != 3) node = node.nextSibling
102
+
103
+ node ? node.data != h && (node.data = h) : node = document.createTextNode(h)
104
+
105
+ return node
106
+ }
107
+
108
+ const element = (h, el, node) => {
109
+
110
+ const { nodeName, children, key, skip, memo, [Generator]: gen, [Args]: args } = h
111
+
112
+ if (key != null) node = (el[Keyed] ??= new Map()).get(key) ?? node
113
+
114
+ while (node && (
115
+
116
+ (node.localName != nodeName) ||
117
+
118
+ (node[Key] != null && node[Key] != key) ||
119
+
120
+ (node[Generator] && node[Generator] != gen)
121
+
122
+ )) node = node[Key] != null ? null : node.nextElementSibling
123
+
124
+ node ??= document.createElementNS(h.xmlns ?? el.namespaceURI, nodeName)
125
+
126
+ if (key != null) el[Keyed].set(node[Key] = key, node)
127
+
128
+ if (memo == null || some(node[Memo], node[Memo] = memo)) {
129
+
130
+ attrs(node[Cache], node[Cache] = h, node)
131
+
132
+ if (!skip) gen ? next(gen, args, node) : render(children, node)
133
+ }
134
+
135
+ return node
136
+ }
137
+
138
+ const attrs = (cache, h, node) => {
139
+
140
+ for (const key in { ...cache, ...h }) {
141
+
142
+ if (key == 'nodeName' || key == 'children' || key == 'key' || key == 'skip' || key == 'memo' || cache?.[key] === h[key]) continue
143
+
144
+ if (key == 'ref' && typeof h[key] == 'function') h[key](node)
145
+
146
+ else if (key.startsWith('set:')) node[key.slice(4)] = h[key]
147
+
148
+ else if (h[key] == null || h[key] === false) node.removeAttribute(key)
149
+
150
+ else node.setAttribute(key, h[key] === true ? '' : h[key])
151
+ }
152
+ }
153
+
154
+ const some = (a, b) => isArray(a) && isArray(b) ? a.some((v, i) => v !== b[i]) : a !== b
155
+
156
+ const each = (fn, node) => {
157
+
158
+ let child = node.firstElementChild
159
+
160
+ while (child)
161
+
162
+ if (fn(child) && child.firstElementChild) child = child.firstElementChild
163
+
164
+ else {
165
+
166
+ while (child != node && !child.nextElementSibling) child = child.parentNode ?? node
167
+
168
+ child = child != node && child.nextElementSibling
169
+ }
170
+ }
171
+
172
+ const before = (el, node, child) => {
173
+
174
+ if (node.isConnected && node.contains(document.activeElement)) {
175
+
176
+ const ref = node.nextSibling
177
+
178
+ while (child && child != node) {
179
+
180
+ const next = child.nextSibling
181
+
182
+ el.insertBefore(child, ref)
183
+
184
+ child = next
185
+ }
186
+
187
+ } else el.insertBefore(node, child)
188
+ }
189
+
190
+ const unref = root => {
191
+
192
+ let node = root
193
+
194
+ while (node.firstElementChild) node = node.firstElementChild
195
+
196
+ while (true) {
197
+
198
+ const { nextElementSibling, parentNode } = node
199
+
200
+ if (node[Key] != null) parentNode?.[Keyed]?.delete(node[Key])
201
+
202
+ if (typeof node.return == 'function') node.return(false)
203
+
204
+ if (typeof node[Cache]?.ref == 'function') node[Cache].ref(null)
205
+
206
+ if (node === root) break
207
+
208
+ node = nextElementSibling ?? parentNode ?? root
209
+
210
+ if (nextElementSibling) while (node.firstElementChild) node = node.firstElementChild
211
+ }
212
+ }
213
+
214
+ const next = (fn, args, el) => {
215
+
216
+ el[Generator] ??= (assign(el, methods)[Context] = create(current()?.[Context] ?? null), fn)
217
+
218
+ el[Args] = args
219
+
220
+ el[Render]()
221
+ }
222
+
223
+ const methods = {
224
+
225
+ *[Symbol.iterator]() { while (true) yield this[Args] },
226
+
227
+ [Render]() {
228
+
229
+ const parent = current()
230
+
231
+ current(this)
232
+
233
+ try {
234
+
235
+ if (!this[Iterator]) {
236
+
237
+ this.signal = (this[Controller] = new AbortController()).signal
238
+
239
+ this[Iterator] = this[Generator].call(this, this[Args])
240
+ }
241
+
242
+ const { value, done } = this[Iterator].next()
243
+
244
+ render(value, this)
245
+
246
+ if (done) this.return()
247
+
248
+ } catch (e) {
249
+
250
+ this.throw(e)
251
+
252
+ } finally {
253
+
254
+ current(parent)
255
+ }
256
+ },
257
+
258
+ next(fn, result) {
259
+
260
+ if (!this.isConnected) return result
261
+
262
+ try {
263
+
264
+ if (typeof fn == 'function') result = fn.call(this, this[Args])
265
+
266
+ } catch (e) {
267
+
268
+ return this.throw(e)
269
+ }
270
+
271
+ if (!current()?.contains(this)) this[Render]()
272
+
273
+ return result
274
+ },
275
+
276
+ throw(value) {
277
+
278
+ for (let el = this; el; el = el.parentNode) if (el[Iterator]?.throw) try {
279
+
280
+ return render(el[Iterator].throw(value).value, el)
281
+
282
+ } catch (e) {
283
+
284
+ value = new Error(e?.message ?? e, { cause: value })
285
+ }
286
+
287
+ throw value
288
+ },
289
+
290
+ return(deep = true) {
291
+
292
+ if (deep) each(el => typeof el.return == 'function' ? el.return() : true, this)
293
+
294
+ try {
295
+
296
+ this[Iterator]?.return()
297
+
298
+ } catch (e) {
299
+
300
+ this.throw(e)
301
+
302
+ } finally {
303
+
304
+ this[Iterator] = null
305
+
306
+ this[Controller]?.abort()
307
+ }
308
+ }
309
+ }
package/jsx.js ADDED
@@ -0,0 +1,21 @@
1
+ export const Fragment = props => props.children
2
+
3
+ export const h = (type, props, ...children) => {
4
+
5
+ (props ??= {}).nodeName = type
6
+
7
+ if (!('children' in props) && children.length) props.children = children.length == 1 ? children[0] : children
8
+
9
+ return props
10
+ }
11
+
12
+ export function jsx(type, props, key) {
13
+
14
+ if (key != null) (props ??= {}).key = key
15
+
16
+ return h(type, props)
17
+ }
18
+
19
+ export const jsxs = jsx
20
+
21
+ export const jsxDEV = jsx