ajo 0.1.34 → 0.1.35
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/LLMs.md +111 -19
- package/dist/html.js +1 -1
- package/dist/index.js +1 -1
- package/html.js +5 -3
- package/index.js +363 -401
- package/jsx.js +5 -5
- package/package.json +1 -1
- package/readme.md +93 -34
- package/types.ts +12 -12
package/index.js
CHANGED
|
@@ -1,401 +1,363 @@
|
|
|
1
|
-
import { Context, current } from './context.js'
|
|
2
|
-
import { isVNode } from './jsx.js'
|
|
3
|
-
|
|
4
|
-
const { isArray } = Array, { assign, hasOwn, keys } = Object
|
|
5
|
-
|
|
6
|
-
const Key = Symbol.for('ajo.key')
|
|
7
|
-
const Keyed = Symbol.for('ajo.keyed')
|
|
8
|
-
const Memo = Symbol.for('ajo.memo')
|
|
9
|
-
const Cache = Symbol.for('ajo.cache')
|
|
10
|
-
const Generator = Symbol.for('ajo.generator')
|
|
11
|
-
const Iterator = Symbol.for('ajo.iterator')
|
|
12
|
-
const Render = Symbol.for('ajo.render')
|
|
13
|
-
const Args = Symbol.for('ajo.args')
|
|
14
|
-
const Controller = Symbol.for('ajo.controller')
|
|
15
|
-
|
|
16
|
-
export const defaults = { tag: 'div' }
|
|
17
|
-
|
|
18
|
-
export const stateful = (fn, is) => (is && (fn.is = is), fn)
|
|
19
|
-
|
|
20
|
-
export const render = (h, el, child = el.firstChild, ref = null) => {
|
|
21
|
-
|
|
22
|
-
walk(h, h => {
|
|
23
|
-
|
|
24
|
-
const node = typeof h == 'string' ? text(h, child, ref) : element(h, el, child, ref)
|
|
25
|
-
|
|
26
|
-
if (child == null) {
|
|
27
|
-
|
|
28
|
-
before(el, node, ref)
|
|
29
|
-
|
|
30
|
-
} else if (node == child) {
|
|
31
|
-
|
|
32
|
-
child = node.nextSibling
|
|
33
|
-
|
|
34
|
-
} else if (node == child.nextSibling) {
|
|
35
|
-
|
|
36
|
-
if (child.contains(document.activeElement)) el.insertBefore(node, child)
|
|
37
|
-
|
|
38
|
-
else el.insertBefore(child, ref)
|
|
39
|
-
|
|
40
|
-
child = node.nextSibling
|
|
41
|
-
|
|
42
|
-
} else {
|
|
43
|
-
|
|
44
|
-
before(el, node, child)
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
if (child && !ref && child == el.firstChild) {
|
|
49
|
-
|
|
50
|
-
const gone = [...el.children]
|
|
51
|
-
|
|
52
|
-
el[Keyed]?.clear()
|
|
53
|
-
|
|
54
|
-
el.textContent = ''
|
|
55
|
-
|
|
56
|
-
for (const node of gone) unref(node)
|
|
57
|
-
|
|
58
|
-
} else while (child && child != ref) {
|
|
59
|
-
|
|
60
|
-
const node = child.nextSibling
|
|
61
|
-
|
|
62
|
-
el.removeChild(child)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
child = node
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const walk = (h, fn) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (h
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
else
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
try {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
} catch (e) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
for (let el = this; el; el = el.parentNode) if (el[Iterator]?.throw) try {
|
|
365
|
-
|
|
366
|
-
return render(el[Iterator].throw(value).value, el)
|
|
367
|
-
|
|
368
|
-
} catch (e) {
|
|
369
|
-
|
|
370
|
-
value = new Error(e?.message ?? e, { cause: value })
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
throw value
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
return(deep = true) {
|
|
377
|
-
|
|
378
|
-
const iterator = this[Iterator]
|
|
379
|
-
|
|
380
|
-
if (iterator === false) return
|
|
381
|
-
|
|
382
|
-
this[Iterator] = false
|
|
383
|
-
|
|
384
|
-
if (deep) each(el => typeof el.return == 'function' ? el.return() : true, this)
|
|
385
|
-
|
|
386
|
-
try {
|
|
387
|
-
|
|
388
|
-
iterator?.return()
|
|
389
|
-
|
|
390
|
-
} catch (e) {
|
|
391
|
-
|
|
392
|
-
this.throw(e)
|
|
393
|
-
|
|
394
|
-
} finally {
|
|
395
|
-
|
|
396
|
-
this[Iterator] = null
|
|
397
|
-
|
|
398
|
-
this[Controller]?.abort()
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
1
|
+
import { Context, current } from './context.js'
|
|
2
|
+
import { isVNode } from './jsx.js'
|
|
3
|
+
|
|
4
|
+
const { isArray } = Array, { assign, hasOwn, keys } = Object
|
|
5
|
+
|
|
6
|
+
const Key = Symbol.for('ajo.key')
|
|
7
|
+
const Keyed = Symbol.for('ajo.keyed')
|
|
8
|
+
const Memo = Symbol.for('ajo.memo')
|
|
9
|
+
const Cache = Symbol.for('ajo.cache')
|
|
10
|
+
const Generator = Symbol.for('ajo.generator')
|
|
11
|
+
const Iterator = Symbol.for('ajo.iterator')
|
|
12
|
+
const Render = Symbol.for('ajo.render')
|
|
13
|
+
const Args = Symbol.for('ajo.args')
|
|
14
|
+
const Controller = Symbol.for('ajo.controller')
|
|
15
|
+
|
|
16
|
+
export const defaults = { tag: 'div' }
|
|
17
|
+
|
|
18
|
+
export const stateful = (fn, is) => (is && (fn.is = is), fn)
|
|
19
|
+
|
|
20
|
+
export const render = (h, el, child = el.firstChild, ref = null) => {
|
|
21
|
+
|
|
22
|
+
walk(h, h => {
|
|
23
|
+
|
|
24
|
+
const node = typeof h == 'string' ? text(h, child, ref) : element(h, el, child, ref)
|
|
25
|
+
|
|
26
|
+
if (child == null) {
|
|
27
|
+
|
|
28
|
+
before(el, node, ref)
|
|
29
|
+
|
|
30
|
+
} else if (node == child) {
|
|
31
|
+
|
|
32
|
+
child = node.nextSibling
|
|
33
|
+
|
|
34
|
+
} else if (node == child.nextSibling) {
|
|
35
|
+
|
|
36
|
+
if (child.contains(document.activeElement)) el.insertBefore(node, child)
|
|
37
|
+
|
|
38
|
+
else el.insertBefore(child, ref)
|
|
39
|
+
|
|
40
|
+
child = node.nextSibling
|
|
41
|
+
|
|
42
|
+
} else {
|
|
43
|
+
|
|
44
|
+
before(el, node, child)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
if (child && !ref && child == el.firstChild) {
|
|
49
|
+
|
|
50
|
+
const gone = [...el.children]
|
|
51
|
+
|
|
52
|
+
el[Keyed]?.clear()
|
|
53
|
+
|
|
54
|
+
el.textContent = ''
|
|
55
|
+
|
|
56
|
+
for (const node of gone) unref(node)
|
|
57
|
+
|
|
58
|
+
} else while (child && child != ref) {
|
|
59
|
+
|
|
60
|
+
const node = child.nextSibling
|
|
61
|
+
|
|
62
|
+
el.removeChild(child)
|
|
63
|
+
|
|
64
|
+
unref(child, el)
|
|
65
|
+
|
|
66
|
+
child = node
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const walk = (h, fn) => {
|
|
71
|
+
|
|
72
|
+
if (h == null || typeof h == 'boolean') return
|
|
73
|
+
|
|
74
|
+
if (isVNode(h)) {
|
|
75
|
+
|
|
76
|
+
if (typeof h.nodeName != 'function') return fn(h)
|
|
77
|
+
|
|
78
|
+
const { nodeName, ...rest } = h
|
|
79
|
+
|
|
80
|
+
if (nodeName.prototype?.next) fn(runGenerator(nodeName, rest))
|
|
81
|
+
|
|
82
|
+
else walk(nodeName(rest), fn)
|
|
83
|
+
|
|
84
|
+
} else if (typeof h == 'object' && Symbol.iterator in h) for (h of h) walk(h, fn)
|
|
85
|
+
|
|
86
|
+
else fn(String(h))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const runGenerator = (fn, h) => {
|
|
90
|
+
|
|
91
|
+
const attrs = { ...fn.attrs }, args = { ...fn.args }
|
|
92
|
+
|
|
93
|
+
for (const key of keys(h)) {
|
|
94
|
+
|
|
95
|
+
if (key.startsWith('attr:')) attrs[key.slice(5)] = h[key]
|
|
96
|
+
|
|
97
|
+
else if (key == 'key' || key == 'skip' || key == 'memo' || key == 'ref' || key.startsWith('set:')) attrs[key] = h[key]
|
|
98
|
+
|
|
99
|
+
else args[key] = h[key]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
attrs.nodeName = fn.is ?? defaults.tag
|
|
103
|
+
|
|
104
|
+
attrs[Generator] = fn
|
|
105
|
+
|
|
106
|
+
attrs[Args] = args
|
|
107
|
+
|
|
108
|
+
return attrs
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const text = (h, node, ref) => {
|
|
112
|
+
|
|
113
|
+
while (node && node != ref && node.nodeType != 3) node = node.nextSibling
|
|
114
|
+
|
|
115
|
+
if (node == null || node == ref) node = document.createTextNode(h)
|
|
116
|
+
|
|
117
|
+
else if (node.data != h) node.data = h
|
|
118
|
+
|
|
119
|
+
return node
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const element = (h, el, node, ref) => {
|
|
123
|
+
|
|
124
|
+
const nodeName = h.nodeName, key = h.key, gen = h[Generator]
|
|
125
|
+
|
|
126
|
+
if (node && key != null && ref == null) node = el[Keyed]?.get(key) ?? node
|
|
127
|
+
|
|
128
|
+
while (node && node != ref) {
|
|
129
|
+
|
|
130
|
+
const k = node[Key], g = node[Generator]
|
|
131
|
+
|
|
132
|
+
if (node.localName == nodeName && (k == null || k == key) && (!g || g == gen)) break
|
|
133
|
+
|
|
134
|
+
node = k != null ? null : node.nextElementSibling
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (node == null || node == ref) node = document.createElementNS(h.xmlns ?? el.namespaceURI, nodeName)
|
|
138
|
+
|
|
139
|
+
if (key != null) (el[Keyed] ??= new Map()).set(node[Key] = key, node)
|
|
140
|
+
|
|
141
|
+
if (!node[Cache] || h.memo == null || some(node[Memo], h.memo)) {
|
|
142
|
+
|
|
143
|
+
attrs(node[Cache], h, node)
|
|
144
|
+
|
|
145
|
+
if (!h.skip) {
|
|
146
|
+
|
|
147
|
+
if (gen) next(gen, h[Args], node)
|
|
148
|
+
|
|
149
|
+
else if (!node[Cache] && (typeof h.children == 'string' || typeof h.children == 'number')) node.textContent = h.children + ''
|
|
150
|
+
|
|
151
|
+
else render(h.children, node)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
node[Memo] = h.memo
|
|
155
|
+
|
|
156
|
+
node[Cache] = h
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return node
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const special = key => key == 'nodeName' || key == 'children' || key == 'key' || key == 'skip' || key == 'memo'
|
|
163
|
+
|
|
164
|
+
const attrs = (cache, h, node) => {
|
|
165
|
+
|
|
166
|
+
for (const key of cache ? keys(cache) : node.getAttributeNames()) {
|
|
167
|
+
|
|
168
|
+
if (hasOwn(h, key) || special(key)) continue
|
|
169
|
+
|
|
170
|
+
if (key.startsWith('set:')) node[key.slice(4)] = undefined
|
|
171
|
+
|
|
172
|
+
else node.removeAttribute(key)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (const key of keys(h)) {
|
|
176
|
+
|
|
177
|
+
const value = h[key]
|
|
178
|
+
|
|
179
|
+
if (cache && cache[key] === value || special(key)) continue
|
|
180
|
+
|
|
181
|
+
if (key == 'ref' && typeof value == 'function') value(node)
|
|
182
|
+
|
|
183
|
+
else if (key.startsWith('set:')) node[key.slice(4)] = value
|
|
184
|
+
|
|
185
|
+
else if (value == null || value === false) node.removeAttribute(key)
|
|
186
|
+
|
|
187
|
+
else if (key == 'class' && typeof node.className == 'string') node.className = value === true ? '' : value
|
|
188
|
+
|
|
189
|
+
else node.setAttribute(key, value === true ? '' : value)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const some = (a, b) =>
|
|
194
|
+
|
|
195
|
+
isArray(a) && isArray(b) ? a.length != b.length || a.some((v, i) => v !== b[i]) : a !== b
|
|
196
|
+
|
|
197
|
+
const each = (fn, node) => {
|
|
198
|
+
|
|
199
|
+
for (let child = node.firstElementChild; child; child = child.nextElementSibling) if (fn(child)) each(fn, child)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const before = (el, node, child) => {
|
|
203
|
+
|
|
204
|
+
if (node.isConnected && node.contains(document.activeElement)) {
|
|
205
|
+
|
|
206
|
+
const ref = node.nextSibling
|
|
207
|
+
|
|
208
|
+
while (child && child != node) {
|
|
209
|
+
|
|
210
|
+
const next = child.nextSibling
|
|
211
|
+
|
|
212
|
+
el.insertBefore(child, ref)
|
|
213
|
+
|
|
214
|
+
child = next
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
} else el.insertBefore(node, child)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const unref = (root, parent) => {
|
|
221
|
+
|
|
222
|
+
if (root[Memo] == unref) return
|
|
223
|
+
|
|
224
|
+
root[Memo] = unref
|
|
225
|
+
|
|
226
|
+
const clean = node => {
|
|
227
|
+
|
|
228
|
+
for (let child = node.firstElementChild, next; child; child = next) {
|
|
229
|
+
|
|
230
|
+
next = child.nextElementSibling
|
|
231
|
+
|
|
232
|
+
clean(child)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (node[Key] != null) (node.parentNode ?? parent)?.[Keyed]?.delete(node[Key])
|
|
236
|
+
|
|
237
|
+
if (typeof node.return == 'function') node.return(false)
|
|
238
|
+
|
|
239
|
+
if (typeof node[Cache]?.ref == 'function') node[Cache].ref(null)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
clean(root)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let observer
|
|
246
|
+
|
|
247
|
+
const next = (fn, args, el) => {
|
|
248
|
+
|
|
249
|
+
if (!el[Generator]) {
|
|
250
|
+
|
|
251
|
+
if (!observer) (observer = new MutationObserver(records => {
|
|
252
|
+
|
|
253
|
+
for (const record of records) for (const node of record.removedNodes) if (node.nodeType == 1 && !node.isConnected) unref(node, record.target)
|
|
254
|
+
|
|
255
|
+
})).observe(document, { childList: true, subtree: true })
|
|
256
|
+
|
|
257
|
+
assign(el, methods)[Context] = Object.create(current()?.[Context] ?? null)
|
|
258
|
+
|
|
259
|
+
el[Generator] = fn
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const prev = el[Args] ??= args
|
|
263
|
+
|
|
264
|
+
for (const key of keys(prev)) if (!hasOwn(args, key)) delete prev[key]
|
|
265
|
+
|
|
266
|
+
assign(prev, args)
|
|
267
|
+
|
|
268
|
+
el[Render]()
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const methods = {
|
|
272
|
+
|
|
273
|
+
*[Symbol.iterator]() { while (true) yield this[Args] },
|
|
274
|
+
|
|
275
|
+
[Render]() {
|
|
276
|
+
|
|
277
|
+
const parent = current()
|
|
278
|
+
|
|
279
|
+
current(this)
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
|
|
283
|
+
if (!this[Iterator]) {
|
|
284
|
+
|
|
285
|
+
this.signal = (this[Controller] = new AbortController()).signal
|
|
286
|
+
|
|
287
|
+
this[Iterator] = this[Generator].call(this, this[Args])
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const { value, done } = this[Iterator].next()
|
|
291
|
+
|
|
292
|
+
render(value, this)
|
|
293
|
+
|
|
294
|
+
if (done) this.return()
|
|
295
|
+
|
|
296
|
+
} catch (e) {
|
|
297
|
+
|
|
298
|
+
this.throw(e)
|
|
299
|
+
|
|
300
|
+
} finally {
|
|
301
|
+
|
|
302
|
+
current(parent)
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
next(fn, result) {
|
|
307
|
+
|
|
308
|
+
if (this[Iterator] === false || !this.isConnected) return result
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
|
|
312
|
+
if (typeof fn == 'function') result = fn.call(this, this[Args])
|
|
313
|
+
|
|
314
|
+
} catch (e) {
|
|
315
|
+
|
|
316
|
+
return this.throw(e)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!current()?.contains(this)) this[Render]()
|
|
320
|
+
|
|
321
|
+
return result
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
throw(value) {
|
|
325
|
+
|
|
326
|
+
for (let el = this; el; el = el.parentNode) if (el[Iterator]?.throw) try {
|
|
327
|
+
|
|
328
|
+
return render(el[Iterator].throw(value).value, el)
|
|
329
|
+
|
|
330
|
+
} catch (e) {
|
|
331
|
+
|
|
332
|
+
value = new Error(e?.message ?? e, { cause: value })
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
throw value
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
return(deep = true) {
|
|
339
|
+
|
|
340
|
+
const iterator = this[Iterator]
|
|
341
|
+
|
|
342
|
+
if (iterator === false) return
|
|
343
|
+
|
|
344
|
+
this[Iterator] = false
|
|
345
|
+
|
|
346
|
+
if (deep) each(el => typeof el.return == 'function' ? el.return() : true, this)
|
|
347
|
+
|
|
348
|
+
try {
|
|
349
|
+
|
|
350
|
+
iterator?.return()
|
|
351
|
+
|
|
352
|
+
} catch (e) {
|
|
353
|
+
|
|
354
|
+
this.throw(e)
|
|
355
|
+
|
|
356
|
+
} finally {
|
|
357
|
+
|
|
358
|
+
this[Iterator] = null
|
|
359
|
+
|
|
360
|
+
this[Controller]?.abort()
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|