ajo 0.0.7 → 0.0.8
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/index.cjs +24 -19
- package/index.js +29 -33
- package/index.test.js +5 -5
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -32,10 +32,10 @@ __export(ajo_exports, {
|
|
|
32
32
|
stx: () => stx
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(ajo_exports);
|
|
35
|
-
const Fragment = ({ children }) => children, h = (
|
|
35
|
+
const Fragment = ({ children }) => children, h = (nodeName, props, ...children) => {
|
|
36
36
|
children = children.length == 0 ? null : children.length == 1 ? children[0] : children;
|
|
37
|
-
return { children, ...props,
|
|
38
|
-
}, component = (setup) => ({ is, key,
|
|
37
|
+
return { children, ...props, nodeName };
|
|
38
|
+
}, component = (setup) => ({ is, key, host, ref, ...props }) => h(is ?? setup.is ?? "div", {
|
|
39
39
|
key,
|
|
40
40
|
...setup.host,
|
|
41
41
|
...host,
|
|
@@ -44,26 +44,27 @@ const Fragment = ({ children }) => children, h = (tagName, props, ...children) =
|
|
|
44
44
|
}), render = (h2, host) => {
|
|
45
45
|
let child = host.firstChild, node, byKey = keyed.get(host);
|
|
46
46
|
for (h2 of normalize(h2, host)) {
|
|
47
|
-
if (typeof h2 ==
|
|
47
|
+
if (typeof h2 == "string") {
|
|
48
48
|
for (node = child; node; node = node.nextSibling)
|
|
49
49
|
if (node.nodeType == 3)
|
|
50
50
|
break;
|
|
51
51
|
node ? node.data !== h2 && (node.data = h2) : node = document.createTextNode(h2);
|
|
52
|
-
} else if (
|
|
53
|
-
|
|
52
|
+
} else if (h2 instanceof Node) {
|
|
53
|
+
node = h2;
|
|
54
|
+
} else {
|
|
55
|
+
const { key, nodeName, skip, block, children, ref, ...props } = h2;
|
|
54
56
|
if (key != null && (node = byKey?.get(key)))
|
|
55
57
|
;
|
|
56
58
|
else
|
|
57
59
|
for (node = child; node; node = node.nextSibling)
|
|
58
|
-
if (node.localName ==
|
|
60
|
+
if (node.localName == nodeName)
|
|
59
61
|
break;
|
|
60
|
-
node ||= document.createElement(
|
|
61
|
-
key != null && (byKey ||= keyed.set(host,
|
|
62
|
+
node ||= document.createElement(nodeName);
|
|
63
|
+
key != null && (byKey ||= keyed.set(host, /* @__PURE__ */ new Map())).set(key, node);
|
|
62
64
|
update(props, node);
|
|
63
65
|
!(skip || block != null && every(deps.get(node), deps.set(node, block))) && render(children, node);
|
|
64
66
|
isFn(ref) && ref(node);
|
|
65
|
-
}
|
|
66
|
-
node = h2;
|
|
67
|
+
}
|
|
67
68
|
node === child ? child = child.nextSibling : before(host, child, node);
|
|
68
69
|
}
|
|
69
70
|
while (child) {
|
|
@@ -80,7 +81,7 @@ const Fragment = ({ children }) => children, h = (tagName, props, ...children) =
|
|
|
80
81
|
} catch (error) {
|
|
81
82
|
propagate(host, error);
|
|
82
83
|
}
|
|
83
|
-
}, provide = (host, key, value) => (provisions.get(host) ?? provisions.set(host,
|
|
84
|
+
}, provide = (host, key, value) => (provisions.get(host) ?? provisions.set(host, /* @__PURE__ */ new Map())).set(key, value), consume = (host, key, fallback) => {
|
|
84
85
|
let map;
|
|
85
86
|
while (host) {
|
|
86
87
|
if ((map = provisions.get(host)) && map.has(key))
|
|
@@ -102,21 +103,25 @@ const Fragment = ({ children }) => children, h = (tagName, props, ...children) =
|
|
|
102
103
|
throwTypeError("Cleaner", cleaner, fn);
|
|
103
104
|
(cleaners.get(host) ?? cleaners.set(host, /* @__PURE__ */ new Set())).add(cleaner);
|
|
104
105
|
}, clx = (o) => keys(o).filter((k) => o[k]).join(" ") || null, stx = (o) => entries(o).map((t) => t.join(":")).join(";") || null, keb = (o) => keys(o).reduce((r, k) => (r[k.replace(search, replace).toLowerCase()] = o[k], r), {});
|
|
105
|
-
const
|
|
106
|
-
const instance = new
|
|
106
|
+
const wm = () => {
|
|
107
|
+
const instance = /* @__PURE__ */ new WeakMap();
|
|
107
108
|
const { set } = instance;
|
|
108
109
|
instance.set = (key, value) => (set.call(instance, key, value), value);
|
|
109
110
|
return instance;
|
|
110
111
|
}, throwTypeError = (name, value, expected) => {
|
|
111
112
|
throw new TypeError(`Expected ${name} to be of type ${expected}, got ${typeof value} instead`);
|
|
112
|
-
}, every = (a, b) => a === b || isArray(a) && isArray(b) && a.length == b.length && a.every((v, i) => v === b[i]), apply = (o, { name, value }) => (o[name] = value, o), reduce = (list) => from(list).reduce(apply, {}), isFn = (v) => typeof v == fn, search = /([a-z0-9])([A-Z])/g, replace = "$1-$2",
|
|
113
|
+
}, every = (a, b) => a === b || isArray(a) && isArray(b) && a.length == b.length && a.every((v, i) => v === b[i]), apply = (o, { name, value }) => (o[name] = value, o), reduce = (list) => from(list).reduce(apply, {}), isFn = (v) => typeof v == fn, { keys, entries } = Object, { isArray, from } = Array, fn = "function", search = /([a-z0-9])([A-Z])/g, replace = "$1-$2", keyed = wm(), deps = wm(), memo = wm(), renders = wm(), provisions = wm(), interceptors = wm(), cleaners = wm(), cache = wm(), normalize = function* (h2, host) {
|
|
113
114
|
let type, buffer = "";
|
|
114
115
|
for (h2 of isFn(h2?.[Symbol.iterator]) ? h2 : [h2]) {
|
|
115
116
|
if (h2 == null || (type = typeof h2) == "boolean")
|
|
116
117
|
continue;
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
if (type == "string" || type == "number") {
|
|
119
|
+
buffer += h2;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if ("nodeName" in Object(h2)) {
|
|
123
|
+
if (isFn(h2.nodeName)) {
|
|
124
|
+
yield* normalize(h2.nodeName(h2, host), host);
|
|
120
125
|
continue;
|
|
121
126
|
}
|
|
122
127
|
if (buffer) {
|
|
@@ -126,7 +131,7 @@ const createMap = (constructor, ...args) => {
|
|
|
126
131
|
yield h2;
|
|
127
132
|
continue;
|
|
128
133
|
}
|
|
129
|
-
|
|
134
|
+
isFn(h2[Symbol.iterator]) ? yield* normalize(h2, host) : buffer += h2;
|
|
130
135
|
}
|
|
131
136
|
if (buffer)
|
|
132
137
|
yield buffer;
|
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export const
|
|
2
2
|
Fragment = ({ children }) => children,
|
|
3
3
|
|
|
4
|
-
h = (
|
|
4
|
+
h = (nodeName, props, ...children) => {
|
|
5
5
|
children = children.length == 0 ? null : children.length == 1 ? children[0] : children
|
|
6
|
-
return { children, ...props,
|
|
6
|
+
return { children, ...props, nodeName }
|
|
7
7
|
},
|
|
8
8
|
|
|
9
|
-
component = setup => ({ is, key,
|
|
9
|
+
component = setup => ({ is, key, host, ref, ...props }) => h(is ?? setup.is ?? 'div', {
|
|
10
10
|
key, ...setup.host, ...host, skip: true, ref: host => (refresh(host, props, setup), isFn(ref) && ref(host))
|
|
11
11
|
}),
|
|
12
12
|
|
|
@@ -16,29 +16,32 @@ export const
|
|
|
16
16
|
|
|
17
17
|
for (h of normalize(h, host)) {
|
|
18
18
|
|
|
19
|
-
if (typeof h ==
|
|
19
|
+
if (typeof h == 'string') {
|
|
20
20
|
|
|
21
21
|
for (node = child; node; node = node.nextSibling) if (node.nodeType == 3) break
|
|
22
22
|
node ? node.data !== h && (node.data = h) : node = document.createTextNode(h)
|
|
23
23
|
|
|
24
|
-
} else if (
|
|
24
|
+
} else if (h instanceof Node) {
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
node = h
|
|
27
|
+
|
|
28
|
+
} else {
|
|
29
|
+
|
|
30
|
+
const { key, nodeName, skip, block, children, ref, ...props } = h
|
|
27
31
|
|
|
28
32
|
if (key != null && (node = byKey?.get(key)));
|
|
29
|
-
else for (node = child; node; node = node.nextSibling) if (node.localName ==
|
|
33
|
+
else for (node = child; node; node = node.nextSibling) if (node.localName == nodeName) break
|
|
30
34
|
|
|
31
|
-
node ||= document.createElement(
|
|
35
|
+
node ||= document.createElement(nodeName)
|
|
32
36
|
|
|
33
|
-
key != null && (byKey ||= keyed.set(host,
|
|
37
|
+
key != null && (byKey ||= keyed.set(host, new Map)).set(key, node)
|
|
34
38
|
|
|
35
39
|
update(props, node)
|
|
36
40
|
|
|
37
41
|
!(skip || block != null && every(deps.get(node), deps.set(node, block))) && render(children, node)
|
|
38
42
|
|
|
39
43
|
isFn(ref) && ref(node)
|
|
40
|
-
|
|
41
|
-
} else node = h
|
|
44
|
+
}
|
|
42
45
|
|
|
43
46
|
node === child ? child = child.nextSibling : before(host, child, node)
|
|
44
47
|
}
|
|
@@ -60,7 +63,7 @@ export const
|
|
|
60
63
|
}
|
|
61
64
|
},
|
|
62
65
|
|
|
63
|
-
provide = (host, key, value) => (provisions.get(host) ?? provisions.set(host,
|
|
66
|
+
provide = (host, key, value) => (provisions.get(host) ?? provisions.set(host, new Map)).set(key, value),
|
|
64
67
|
|
|
65
68
|
consume = (host, key, fallback) => {
|
|
66
69
|
let map
|
|
@@ -92,8 +95,8 @@ export const
|
|
|
92
95
|
keb = o => keys(o).reduce((r, k) => ((r[k.replace(search, replace).toLowerCase()] = o[k]), r), {})
|
|
93
96
|
|
|
94
97
|
const
|
|
95
|
-
|
|
96
|
-
const instance = new
|
|
98
|
+
wm = () => {
|
|
99
|
+
const instance = new WeakMap
|
|
97
100
|
const { set } = instance
|
|
98
101
|
instance.set = (key, value) => (set.call(instance, key, value), value)
|
|
99
102
|
return instance
|
|
@@ -108,23 +111,11 @@ const
|
|
|
108
111
|
reduce = list => from(list).reduce(apply, {}),
|
|
109
112
|
isFn = v => typeof v == fn,
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
replace = '$1-$2',
|
|
113
|
-
str = 'string',
|
|
114
|
-
fn = 'function',
|
|
114
|
+
{ keys, entries } = Object, { isArray, from } = Array,
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
{ isArray, from } = Array,
|
|
118
|
-
wm = WeakMap,
|
|
116
|
+
fn = 'function', search = /([a-z0-9])([A-Z])/g, replace = '$1-$2',
|
|
119
117
|
|
|
120
|
-
deps =
|
|
121
|
-
memo = createMap(wm),
|
|
122
|
-
keyed = createMap(wm),
|
|
123
|
-
cache = createMap(wm),
|
|
124
|
-
renders = createMap(wm),
|
|
125
|
-
cleaners = createMap(wm),
|
|
126
|
-
provisions = createMap(wm),
|
|
127
|
-
interceptors = createMap(wm),
|
|
118
|
+
keyed = wm(), deps = wm(), memo = wm(), renders = wm(), provisions = wm(), interceptors = wm(), cleaners = wm(), cache = wm(),
|
|
128
119
|
|
|
129
120
|
normalize = function* (h, host) {
|
|
130
121
|
|
|
@@ -134,10 +125,15 @@ const
|
|
|
134
125
|
|
|
135
126
|
if (h == null || (type = typeof h) == 'boolean') continue
|
|
136
127
|
|
|
137
|
-
if (
|
|
128
|
+
if (type == 'string' || type == 'number') {
|
|
129
|
+
buffer += h
|
|
130
|
+
continue
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if ('nodeName' in Object(h)) {
|
|
138
134
|
|
|
139
|
-
if (isFn(h.
|
|
140
|
-
yield* normalize(h.
|
|
135
|
+
if (isFn(h.nodeName)) {
|
|
136
|
+
yield* normalize(h.nodeName(h, host), host)
|
|
141
137
|
continue
|
|
142
138
|
}
|
|
143
139
|
|
|
@@ -150,7 +146,7 @@ const
|
|
|
150
146
|
continue
|
|
151
147
|
}
|
|
152
148
|
|
|
153
|
-
|
|
149
|
+
isFn(h[Symbol.iterator]) ? yield* normalize(h, host) : buffer += h
|
|
154
150
|
}
|
|
155
151
|
|
|
156
152
|
if (buffer) yield buffer
|
package/index.test.js
CHANGED
|
@@ -11,27 +11,27 @@ it = suite('h')
|
|
|
11
11
|
|
|
12
12
|
it('should create empty vnode', () => {
|
|
13
13
|
const vnode = h('div')
|
|
14
|
-
assert.equal(vnode, {
|
|
14
|
+
assert.equal(vnode, { nodeName: 'div', children: null })
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
it('should create vnode with props', () => {
|
|
18
|
-
assert.equal(h('div', { id: 'app' }), {
|
|
18
|
+
assert.equal(h('div', { id: 'app' }), { nodeName: 'div', children: null, id: 'app' })
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
it('should create vnode with one string child', () => {
|
|
22
|
-
assert.equal(h('div', null, 'foo'), {
|
|
22
|
+
assert.equal(h('div', null, 'foo'), { nodeName: 'div', children: 'foo' })
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
it('should create vnode with one vnode child', () => {
|
|
26
26
|
const child = h('span')
|
|
27
27
|
const vnode = h('div', null, child)
|
|
28
|
-
assert.equal(vnode.children, {
|
|
28
|
+
assert.equal(vnode.children, { nodeName: 'span', children: null })
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
it('should allow children as prop', () => {
|
|
32
32
|
const child = h('span')
|
|
33
33
|
const vnode = h('div', { children: child })
|
|
34
|
-
assert.equal(vnode.children, {
|
|
34
|
+
assert.equal(vnode.children, { nodeName: 'span', children: null })
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
it.run()
|