ajo 0.1.31 → 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/LLMs.md +349 -329
- package/context.js +18 -18
- package/dist/html.cjs +1 -1
- package/dist/html.js +47 -46
- package/dist/index.cjs +1 -1
- package/dist/index.js +86 -70
- package/dist/jsx.cjs +1 -0
- package/dist/jsx.js +12 -0
- package/html.js +137 -142
- package/index.js +309 -286
- package/jsx.js +21 -0
- package/license +15 -15
- package/package.json +19 -3
- package/readme.md +447 -434
- package/types.ts +135 -91
package/html.js
CHANGED
|
@@ -1,142 +1,137 @@
|
|
|
1
|
-
import { Context, current } from '
|
|
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
|
|
12
|
-
|
|
13
|
-
export const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
else
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
else
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
else delete h.children
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return h
|
|
142
|
-
}
|
|
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
|
+
}
|