ajo 0.0.17 → 0.0.18
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 +78 -54
- package/index.js +80 -52
- package/index.min.js +1 -1
- package/package.json +3 -6
package/index.cjs
CHANGED
|
@@ -33,49 +33,50 @@ __export(ajo_exports, {
|
|
|
33
33
|
stx: () => stx
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(ajo_exports);
|
|
36
|
-
|
|
37
|
-
const Fragment = ({ children }) => children, For = ({ is, each, by, children, ref: ref2, ...props }) => h(is ?? "div", {
|
|
36
|
+
const Fragment = ({ children }) => children, For = ({ is, each, by, children, ref, ...props }) => h(is ?? "div", {
|
|
38
37
|
...props,
|
|
39
38
|
skip: true,
|
|
40
|
-
ref: (host
|
|
41
|
-
}), h = (nodeName, props, ...children) =>
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
ref: (host) => iterate(host, each, by, children, ref)
|
|
40
|
+
}), h = (nodeName, props, ...children) => {
|
|
41
|
+
const { length } = children;
|
|
42
|
+
children = length == 0 ? null : length == 1 ? children[0] : children;
|
|
43
|
+
return { children, ...props, nodeName };
|
|
44
|
+
}, render = (h2, host, ns) => {
|
|
45
|
+
let child = host.firstChild;
|
|
44
46
|
for (h2 of normalize(h2)) {
|
|
47
|
+
let node = child;
|
|
45
48
|
if (h2 instanceof Node)
|
|
46
49
|
node = h2;
|
|
47
50
|
else if (typeof h2 == "string") {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
node == to ? node = document.createTextNode(h2) : node.data != h2 && (node.data = h2);
|
|
51
|
+
while (node && node.nodeType != 3)
|
|
52
|
+
node = node.nextSibling;
|
|
53
|
+
node ? node.data != h2 && (node.data = h2) : node = document.createTextNode(h2);
|
|
52
54
|
} else {
|
|
53
|
-
const { nodeName, block, skip, children, ref
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
node == to && (node = document.createElement(nodeName));
|
|
55
|
+
const { xmlns = ns, nodeName, key, block, skip, children, ref, ...props } = h2;
|
|
56
|
+
while (node && !(node.localName == nodeName && (node.$key ??= key) == key))
|
|
57
|
+
node = node.nextSibling;
|
|
58
|
+
node ??= create(xmlns, nodeName, key);
|
|
58
59
|
if (block == null || some(node.$deps, node.$deps = block)) {
|
|
59
60
|
update(props, node);
|
|
60
|
-
skip || render(children, node,
|
|
61
|
-
isFunction(
|
|
61
|
+
skip || render(children, node, xmlns);
|
|
62
|
+
isFunction(ref) && ref(node);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
node == child ? child = child.nextSibling : before(host, node, child);
|
|
65
66
|
}
|
|
66
|
-
while (child
|
|
67
|
+
while (child) {
|
|
67
68
|
const next = child.nextSibling;
|
|
68
69
|
host.removeChild(child);
|
|
69
70
|
child = next;
|
|
70
71
|
}
|
|
71
|
-
}, component = (setup) => ({ is, props, ref
|
|
72
|
+
}, component = (setup) => ({ is, props, ref, ...params }) => h(is ?? setup.is ?? "div", {
|
|
72
73
|
...setup.props,
|
|
73
74
|
...props,
|
|
74
75
|
skip: true,
|
|
75
|
-
ref: (host
|
|
76
|
+
ref: (host) => run(host, setup, params, ref)
|
|
76
77
|
}), refresh = (host) => {
|
|
77
78
|
try {
|
|
78
|
-
render((host.$render ??= host.$setup(host))(host.$params), host
|
|
79
|
+
render((host.$render ??= host.$setup(host))(host.$params), host);
|
|
79
80
|
} catch (error) {
|
|
80
81
|
propagate(host, error);
|
|
81
82
|
}
|
|
@@ -87,28 +88,46 @@ const Fragment = ({ children }) => children, For = ({ is, each, by, children, re
|
|
|
87
88
|
}, intercept = (host, fn) => isFunction(fn) && (host.$interceptor = fn), propagate = (host, error) => {
|
|
88
89
|
for (let fn; host; host = host.parentNode)
|
|
89
90
|
if (isFunction(fn = host.$interceptor))
|
|
90
|
-
return render(fn(error));
|
|
91
|
+
return render(fn(error), host);
|
|
91
92
|
throw error;
|
|
92
93
|
}, cleanup = (host, fn) => isFunction(fn) && (host.$cleanups ??= /* @__PURE__ */ new Set()).add(fn), 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), {});
|
|
93
94
|
const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) => typeof v == "function", noop = () => {
|
|
94
|
-
},
|
|
95
|
-
let
|
|
95
|
+
}, on = (host, type, v) => {
|
|
96
|
+
let fn, map2;
|
|
97
|
+
if (fn = (map2 = host.$on ??= {})[type]) {
|
|
98
|
+
host.removeEventListener(type, fn, fn.options), map2[type] = null;
|
|
99
|
+
}
|
|
100
|
+
if (typeof (fn = (v = isArray(v) ? v : [v])[0]) == "function") {
|
|
101
|
+
host.addEventListener(type, fn = map2[type] = fn.bind(null, v[1]), fn.options = v[2]);
|
|
102
|
+
}
|
|
103
|
+
}, map = (list) => list.reduce(set, /* @__PURE__ */ new Map()), set = (m, v, i) => (m.set(v, i), m), some = (a, b) => isArray(a) && isArray(b) ? a.some((v, i) => v !== b[i]) : a !== b, reduce = (v) => from(v).reduce(assign, {}), assign = (v, { name, value }) => (v[name] = value, v), create = (ns, name, key) => {
|
|
104
|
+
const node = ns ? document.createElementNS(ns, name) : document.createElement(name);
|
|
105
|
+
return node.$key = key, node;
|
|
106
|
+
}, proxy = { firstChild: null, insertBefore: (node) => proxy.firstChild ??= node }, handler = {
|
|
107
|
+
get(target, key) {
|
|
108
|
+
const value = key == "nextSibling" ? null : target[key];
|
|
109
|
+
return isFunction(value) ? value.bind(target) : value;
|
|
110
|
+
}
|
|
111
|
+
}, search = /([a-z0-9])([A-Z])/g, replace = "$1-$2", normalize = function* (h2, buffer = { t: "" }, root = true) {
|
|
112
|
+
let t;
|
|
96
113
|
for (h2 of isArray(h2) ? h2 : [h2]) {
|
|
97
114
|
if (h2 == null || typeof h2 == "boolean")
|
|
98
115
|
continue;
|
|
99
|
-
if (typeof h2.nodeName == "string")
|
|
100
|
-
|
|
116
|
+
else if (typeof h2.nodeName == "string")
|
|
117
|
+
t = buffer.t && (buffer.t = "", yield t), yield h2;
|
|
101
118
|
else if (isFunction(h2.nodeName))
|
|
102
119
|
yield* normalize(h2.nodeName(h2), buffer, false);
|
|
103
120
|
else
|
|
104
|
-
isArray(h2) ? yield* normalize(h2, buffer, false) : buffer
|
|
121
|
+
isArray(h2) ? yield* normalize(h2, buffer, false) : buffer.t += h2;
|
|
105
122
|
}
|
|
106
|
-
root && (
|
|
123
|
+
root && (t = buffer.t) && (yield t);
|
|
107
124
|
}, update = (props, host) => {
|
|
108
|
-
const prev = host.$props
|
|
109
|
-
for (const name in { ...prev, ...props }) {
|
|
125
|
+
const prev = host.$props ??= host.hasAttributes() ? reduce(host.attributes) : {};
|
|
126
|
+
for (const name in { ...prev, ...host.$props = props }) {
|
|
110
127
|
let value = props[name];
|
|
111
|
-
if (
|
|
128
|
+
if (name.startsWith("on:")) {
|
|
129
|
+
some(value, prev[name]) && on(host, name.slice(3), value);
|
|
130
|
+
} else if (value !== prev[name])
|
|
112
131
|
if (name.startsWith("set:"))
|
|
113
132
|
host[name.slice(4)] = value;
|
|
114
133
|
else if (value == null || value === false)
|
|
@@ -116,33 +135,33 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
|
|
|
116
135
|
else
|
|
117
136
|
host.setAttribute(name, value === true ? "" : value);
|
|
118
137
|
}
|
|
119
|
-
host.$props = props;
|
|
120
138
|
}, before = (host, node, child) => {
|
|
121
139
|
if (node.contains?.(document.activeElement)) {
|
|
122
|
-
const
|
|
123
|
-
while (child && child
|
|
140
|
+
const ref = node.nextSibling;
|
|
141
|
+
while (child && child != node) {
|
|
124
142
|
const next = child.nextSibling;
|
|
125
|
-
host.insertBefore(child,
|
|
143
|
+
host.insertBefore(child, ref);
|
|
126
144
|
child = next;
|
|
127
145
|
}
|
|
128
146
|
} else
|
|
129
147
|
host.insertBefore(node, child);
|
|
130
|
-
}, iterate = (host,
|
|
148
|
+
}, iterate = (host, each, by, fn, ref) => {
|
|
131
149
|
each = isArray(each) ? each : [];
|
|
132
150
|
by = isFunction(by) ? by : (v) => v;
|
|
133
151
|
fn = isFunction(fn) ? fn : noop;
|
|
134
|
-
const map2 = host.$for ??= /* @__PURE__ */ new Map(), del = (node) => map2.delete(node.$
|
|
152
|
+
const map2 = host.$for ??= /* @__PURE__ */ new Map(), del = (node) => map2.delete(node.$by), clr = each !== host.$each, len = (host.$each = each).length, a = from(host.childNodes), b = new Array(len);
|
|
135
153
|
clr && map2.clear();
|
|
136
|
-
for (let
|
|
154
|
+
for (let child, index = 0; index < len; index++) {
|
|
137
155
|
const item = each[index], key = by(item, index);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
156
|
+
child = clr ? a[index] : map2.get(key);
|
|
157
|
+
proxy.firstChild = child ? new Proxy(child, handler) : null;
|
|
158
|
+
render(fn(item), proxy);
|
|
159
|
+
child ??= proxy.firstChild;
|
|
141
160
|
proxy.firstChild = null;
|
|
142
|
-
map2.set(
|
|
161
|
+
map2.set(child.$by = key, b[index] = child);
|
|
143
162
|
}
|
|
144
163
|
arrange(host, a, b, del);
|
|
145
|
-
isFunction(
|
|
164
|
+
isFunction(ref) && ref(host);
|
|
146
165
|
}, arrange = (host, a, b, dispose2 = noop) => {
|
|
147
166
|
const aLen = a.length, bLen = b.length;
|
|
148
167
|
let aIndex = 0, bIndex = 0, aValue, bValue, aMap, bMap, i;
|
|
@@ -172,17 +191,22 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
|
|
|
172
191
|
}
|
|
173
192
|
}
|
|
174
193
|
}
|
|
175
|
-
}, run = (host,
|
|
176
|
-
host.$
|
|
177
|
-
host.$setup ??= isFunction(setup) ? setup : noop;
|
|
194
|
+
}, run = (host, setup, params, ref) => {
|
|
195
|
+
host.$setup ??= (host.addEventListener("DOMNodeRemovedFromDocument", dispose), isFunction(setup) ? setup : noop);
|
|
178
196
|
host.$params = { ...setup.params, ...params };
|
|
179
197
|
refresh(host);
|
|
180
|
-
isFunction(
|
|
181
|
-
}, dispose = (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
isFunction(ref) && ref(host);
|
|
199
|
+
}, dispose = ({ target }) => {
|
|
200
|
+
(globalThis.queueMicrotask ?? ((v) => v()))(() => {
|
|
201
|
+
if (document.contains(target))
|
|
202
|
+
return;
|
|
203
|
+
if ("$cleanups" in target) {
|
|
204
|
+
try {
|
|
205
|
+
for (const fn of target.$cleanups)
|
|
206
|
+
fn(target);
|
|
207
|
+
} finally {
|
|
208
|
+
target.$cleanups.clear();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
188
212
|
};
|
package/index.js
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
import { notify } from 'element-notifier'
|
|
2
|
-
|
|
3
1
|
export const
|
|
4
2
|
Fragment = ({ children }) => children,
|
|
5
3
|
|
|
6
4
|
For = ({ is, each, by, children, ref, ...props }) => h(is ?? 'div', {
|
|
7
|
-
...props, skip: true, ref:
|
|
5
|
+
...props, skip: true, ref: host => iterate(host, each, by, children, ref)
|
|
8
6
|
}),
|
|
9
7
|
|
|
10
|
-
h = (nodeName, props, ...children) =>
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
h = (nodeName, props, ...children) => {
|
|
9
|
+
const { length } = children
|
|
10
|
+
children = length == 0 ? null : length == 1 ? children[0] : children
|
|
11
|
+
return { children, ...props, nodeName }
|
|
12
|
+
},
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
render = (h, host, ns) => {
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
let child = host.firstChild
|
|
17
17
|
|
|
18
18
|
for (h of normalize(h)) {
|
|
19
19
|
|
|
20
|
+
let node = child
|
|
21
|
+
|
|
20
22
|
if (h instanceof Node) node = h
|
|
21
23
|
|
|
22
24
|
else if (typeof h == 'string') {
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
node
|
|
26
|
+
while (node && node.nodeType != 3) node = node.nextSibling
|
|
27
|
+
node ? node.data != h && (node.data = h) : node = document.createTextNode(h)
|
|
26
28
|
|
|
27
29
|
} else {
|
|
28
30
|
|
|
29
|
-
const { nodeName, block, skip, children, ref, ...props } = h
|
|
31
|
+
const { xmlns = ns, nodeName, key, block, skip, children, ref, ...props } = h
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
node
|
|
33
|
+
while (node && !(node.localName == nodeName && (node.$key ??= key) == key)) node = node.nextSibling
|
|
34
|
+
node ??= create(xmlns, nodeName, key)
|
|
33
35
|
|
|
34
36
|
if (block == null || some(node.$deps, node.$deps = block)) {
|
|
35
37
|
update(props, node)
|
|
36
|
-
skip || render(children, node,
|
|
37
|
-
isFunction(ref) && ref(node
|
|
38
|
+
skip || render(children, node, xmlns)
|
|
39
|
+
isFunction(ref) && ref(node)
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
node == child ? child = child.nextSibling : before(host, node, child)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
while (child
|
|
46
|
+
while (child) {
|
|
45
47
|
const next = child.nextSibling
|
|
46
48
|
host.removeChild(child)
|
|
47
49
|
child = next
|
|
@@ -49,12 +51,12 @@ export const
|
|
|
49
51
|
},
|
|
50
52
|
|
|
51
53
|
component = setup => ({ is, props, ref, ...params }) => h(is ?? setup.is ?? 'div', {
|
|
52
|
-
...setup.props, ...props, skip: true, ref:
|
|
54
|
+
...setup.props, ...props, skip: true, ref: host => run(host, setup, params, ref)
|
|
53
55
|
}),
|
|
54
56
|
|
|
55
57
|
refresh = host => {
|
|
56
58
|
try {
|
|
57
|
-
render((host.$render ??= host.$setup(host))(host.$params), host
|
|
59
|
+
render((host.$render ??= host.$setup(host))(host.$params), host)
|
|
58
60
|
} catch (error) {
|
|
59
61
|
propagate(host, error)
|
|
60
62
|
}
|
|
@@ -70,7 +72,7 @@ export const
|
|
|
70
72
|
intercept = (host, fn) => isFunction(fn) && (host.$interceptor = fn),
|
|
71
73
|
|
|
72
74
|
propagate = (host, error) => {
|
|
73
|
-
for (let fn; host; host = host.parentNode) if (isFunction(fn = host.$interceptor)) return render(fn(error))
|
|
75
|
+
for (let fn; host; host = host.parentNode) if (isFunction(fn = host.$interceptor)) return render(fn(error), host)
|
|
74
76
|
throw error
|
|
75
77
|
},
|
|
76
78
|
|
|
@@ -83,9 +85,20 @@ export const
|
|
|
83
85
|
keb = o => keys(o).reduce((r, k) => ((r[k.replace(search, replace).toLowerCase()] = o[k]), r), {})
|
|
84
86
|
|
|
85
87
|
const
|
|
86
|
-
{ isArray, from } = Array, { keys, entries } = Object,
|
|
88
|
+
{ isArray, from } = Array, { keys, entries } = Object,
|
|
89
|
+
|
|
90
|
+
isFunction = v => typeof v == 'function', noop = () => { }, on = (host, type, v) => {
|
|
87
91
|
|
|
88
|
-
|
|
92
|
+
let fn, map
|
|
93
|
+
|
|
94
|
+
if (fn = (map = host.$on ??= {})[type]) {
|
|
95
|
+
host.removeEventListener(type, fn, fn.options), map[type] = null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (typeof (fn = (v = isArray(v) ? v : [v])[0]) == 'function') {
|
|
99
|
+
host.addEventListener(type, fn = map[type] = fn.bind(null, v[1]), fn.options = v[2])
|
|
100
|
+
}
|
|
101
|
+
},
|
|
89
102
|
|
|
90
103
|
map = list => list.reduce(set, new Map), set = (m, v, i) => (m.set(v, i), m),
|
|
91
104
|
|
|
@@ -93,39 +106,49 @@ const
|
|
|
93
106
|
|
|
94
107
|
reduce = v => from(v).reduce(assign, {}), assign = (v, { name, value }) => ((v[name] = value), v),
|
|
95
108
|
|
|
96
|
-
|
|
109
|
+
create = (ns, name, key) => {
|
|
110
|
+
const node = ns ? document.createElementNS(ns, name) : document.createElement(name)
|
|
111
|
+
return node.$key = key, node
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
proxy = { firstChild: null, insertBefore: node => proxy.firstChild ??= node }, handler = {
|
|
115
|
+
get(target, key) {
|
|
116
|
+
const value = key == 'nextSibling' ? null : target[key]
|
|
117
|
+
return isFunction(value) ? value.bind(target) : value
|
|
118
|
+
},
|
|
119
|
+
},
|
|
97
120
|
|
|
98
121
|
search = /([a-z0-9])([A-Z])/g, replace = '$1-$2',
|
|
99
122
|
|
|
100
|
-
normalize = function* (h, buffer =
|
|
123
|
+
normalize = function* (h, buffer = { t: '' }, root = true) {
|
|
101
124
|
|
|
102
|
-
let
|
|
125
|
+
let t
|
|
103
126
|
|
|
104
127
|
for (h of isArray(h) ? h : [h]) {
|
|
105
128
|
if (h == null || typeof h == 'boolean') continue
|
|
106
|
-
if (typeof h.nodeName == 'string') (
|
|
129
|
+
else if (typeof h.nodeName == 'string') (t = buffer.t && (buffer.t = '', yield t)), yield h
|
|
107
130
|
else if (isFunction(h.nodeName)) yield* normalize(h.nodeName(h), buffer, false)
|
|
108
|
-
else isArray(h) ? yield* normalize(h, buffer, false) : buffer
|
|
131
|
+
else isArray(h) ? yield* normalize(h, buffer, false) : buffer.t += h
|
|
109
132
|
}
|
|
110
133
|
|
|
111
|
-
root && (
|
|
134
|
+
root && (t = buffer.t) && (yield t)
|
|
112
135
|
},
|
|
113
136
|
|
|
114
137
|
update = (props, host) => {
|
|
115
138
|
|
|
116
|
-
const prev = host.$props
|
|
139
|
+
const prev = host.$props ??= host.hasAttributes() ? reduce(host.attributes) : {}
|
|
117
140
|
|
|
118
|
-
for (const name in { ...prev, ...props }) {
|
|
141
|
+
for (const name in { ...prev, ...(host.$props = props) }) {
|
|
119
142
|
|
|
120
143
|
let value = props[name]
|
|
121
144
|
|
|
122
|
-
if (
|
|
145
|
+
if (name.startsWith('on:')) {
|
|
146
|
+
some(value, prev[name]) && on(host, name.slice(3), value)
|
|
147
|
+
} else if (value !== prev[name])
|
|
123
148
|
if (name.startsWith('set:')) host[name.slice(4)] = value
|
|
124
149
|
else if (value == null || value === false) host.removeAttribute(name)
|
|
125
150
|
else host.setAttribute(name, value === true ? '' : value)
|
|
126
151
|
}
|
|
127
|
-
|
|
128
|
-
host.$props = props
|
|
129
152
|
},
|
|
130
153
|
|
|
131
154
|
before = (host, node, child) => {
|
|
@@ -133,7 +156,7 @@ const
|
|
|
133
156
|
|
|
134
157
|
const ref = node.nextSibling
|
|
135
158
|
|
|
136
|
-
while (child && child
|
|
159
|
+
while (child && child != node) {
|
|
137
160
|
const next = child.nextSibling
|
|
138
161
|
host.insertBefore(child, ref)
|
|
139
162
|
child = next
|
|
@@ -142,7 +165,7 @@ const
|
|
|
142
165
|
} else host.insertBefore(node, child)
|
|
143
166
|
},
|
|
144
167
|
|
|
145
|
-
iterate = (host,
|
|
168
|
+
iterate = (host, each, by, fn, ref) => {
|
|
146
169
|
|
|
147
170
|
each = isArray(each) ? each : []
|
|
148
171
|
by = isFunction(by) ? by : v => v
|
|
@@ -150,7 +173,7 @@ const
|
|
|
150
173
|
|
|
151
174
|
const
|
|
152
175
|
map = host.$for ??= new Map,
|
|
153
|
-
del = node => map.delete(node.$
|
|
176
|
+
del = node => map.delete(node.$by),
|
|
154
177
|
clr = each !== host.$each,
|
|
155
178
|
len = (host.$each = each).length,
|
|
156
179
|
a = from(host.childNodes),
|
|
@@ -158,21 +181,23 @@ const
|
|
|
158
181
|
|
|
159
182
|
clr && map.clear()
|
|
160
183
|
|
|
161
|
-
for (let
|
|
184
|
+
for (let child, index = 0; index < len; index++) {
|
|
162
185
|
|
|
163
186
|
const item = each[index], key = by(item, index)
|
|
164
187
|
|
|
165
|
-
|
|
166
|
-
|
|
188
|
+
child = (clr ? a[index] : map.get(key))
|
|
189
|
+
|
|
190
|
+
proxy.firstChild = child ? new Proxy(child, handler) : null
|
|
191
|
+
render(fn(item), proxy)
|
|
167
192
|
|
|
168
|
-
|
|
193
|
+
child ??= proxy.firstChild
|
|
169
194
|
proxy.firstChild = null
|
|
170
195
|
|
|
171
|
-
map.set(
|
|
196
|
+
map.set(child.$by = key, b[index] = child)
|
|
172
197
|
}
|
|
173
198
|
|
|
174
199
|
arrange(host, a, b, del)
|
|
175
|
-
isFunction(ref) && ref(host
|
|
200
|
+
isFunction(ref) && ref(host)
|
|
176
201
|
},
|
|
177
202
|
|
|
178
203
|
arrange = (host, a, b, dispose = noop) => {
|
|
@@ -209,22 +234,25 @@ const
|
|
|
209
234
|
}
|
|
210
235
|
},
|
|
211
236
|
|
|
212
|
-
run = (host,
|
|
237
|
+
run = (host, setup, params, ref) => {
|
|
213
238
|
|
|
214
|
-
host.$
|
|
215
|
-
host.$setup ??= isFunction(setup) ? setup : noop
|
|
239
|
+
host.$setup ??= (host.addEventListener('DOMNodeRemovedFromDocument', dispose), isFunction(setup) ? setup : noop)
|
|
216
240
|
host.$params = { ...setup.params, ...params }
|
|
217
241
|
|
|
218
242
|
refresh(host)
|
|
219
|
-
isFunction(ref) && ref(host
|
|
243
|
+
isFunction(ref) && ref(host)
|
|
220
244
|
},
|
|
221
245
|
|
|
222
|
-
dispose =
|
|
246
|
+
dispose = ({ target }) => {
|
|
247
|
+
(globalThis.queueMicrotask ?? (v => v()))(() => {
|
|
248
|
+
if (document.contains(target)) return
|
|
223
249
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
250
|
+
if ('$cleanups' in target) {
|
|
251
|
+
try {
|
|
252
|
+
for (const fn of target.$cleanups) fn(target)
|
|
253
|
+
} finally {
|
|
254
|
+
target.$cleanups.clear()
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
})
|
|
230
258
|
}
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ajo=(()=>{var
|
|
1
|
+
var ajo=(()=>{var x=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var F=(e,n)=>{for(var i in n)x(e,i,{get:n[i],enumerable:!0})},T=(e,n,i,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of j(n))!B.call(e,r)&&r!==i&&x(e,r,{get:()=>n[r],enumerable:!(l=L(n,r))||l.enumerable});return e};var z=e=>T(x({},"__esModule",{value:!0}),e);var ae={};F(ae,{For:()=>I,Fragment:()=>D,cleanup:()=>P,clx:()=>R,component:()=>O,consume:()=>W,h:()=>b,intercept:()=>q,keb:()=>G,propagate:()=>k,provide:()=>V,refresh:()=>S,render:()=>g,stx:()=>Z});const D=({children:e})=>e,I=({is:e,each:n,by:i,children:l,ref:r,...o})=>b(e??"div",{...o,skip:!0,ref:t=>ie(t,n,i,l,r)}),b=(e,n,...i)=>{const{length:l}=i;return i=l==0?null:l==1?i[0]:i,{children:i,...n,nodeName:e}},g=(e,n,i)=>{let l=n.firstChild;for(e of y(e)){let r=l;if(e instanceof Node)r=e;else if(typeof e=="string"){for(;r&&r.nodeType!=3;)r=r.nextSibling;r?r.data!=e&&(r.data=e):r=document.createTextNode(e)}else{const{xmlns:o=i,nodeName:t,key:s,block:c,skip:f,children:p,ref:a,...d}=e;for(;r&&!(r.localName==t&&(r.$key??=s)==s);)r=r.nextSibling;r??=X(o,t,s),(c==null||E(r.$deps,r.$deps=c))&&(ee(d,r),f||g(p,r,o),u(a)&&a(r))}r==l?l=l.nextSibling:ne(n,r,l)}for(;l;){const r=l.nextSibling;n.removeChild(l),l=r}},O=e=>({is:n,props:i,ref:l,...r})=>b(n??e.is??"div",{...e.props,...i,skip:!0,ref:o=>re(o,e,r,l)}),S=e=>{try{g((e.$render??=e.$setup(e))(e.$params),e)}catch(n){k(e,n)}},V=(e,n,i)=>(e.$provisions??=new Map).set(n,i),W=(e,n,i)=>{for(let l;e;e=e.parentNode)if((l=e.$provisions)&&l.has(n))return l.get(n);return i},q=(e,n)=>u(n)&&(e.$interceptor=n),k=(e,n)=>{for(let i;e;e=e.parentNode)if(u(i=e.$interceptor))return g(i(n),e);throw n},P=(e,n)=>u(n)&&(e.$cleanups??=new Set).add(n),R=e=>M(e).filter(n=>e[n]).join(" ")||null,Z=e=>H(e).map(n=>n.join(":")).join(";")||null,G=e=>M(e).reduce((n,i)=>(n[i.replace(_,h).toLowerCase()]=e[i],n),{}),{isArray:m,from:A}=Array,{keys:M,entries:H}=Object,u=e=>typeof e=="function",w=()=>{},J=(e,n,i)=>{let l,r;(l=(r=e.$on??={})[n])&&(e.removeEventListener(n,l,l.options),r[n]=null),typeof(l=(i=m(i)?i:[i])[0])=="function"&&e.addEventListener(n,l=r[n]=l.bind(null,i[1]),l.options=i[2])},C=e=>e.reduce(K,new Map),K=(e,n,i)=>(e.set(n,i),e),E=(e,n)=>m(e)&&m(n)?e.some((i,l)=>i!==n[l]):e!==n,Q=e=>A(e).reduce(U,{}),U=(e,{name:n,value:i})=>(e[n]=i,e),X=(e,n,i)=>{const l=e?document.createElementNS(e,n):document.createElement(n);return l.$key=i,l},$={firstChild:null,insertBefore:e=>$.firstChild??=e},Y={get(e,n){const i=n=="nextSibling"?null:e[n];return u(i)?i.bind(e):i}},_=/([a-z0-9])([A-Z])/g,h="$1-$2",y=function*(e,n={t:""},i=!0){let l;for(e of m(e)?e:[e])e==null||typeof e=="boolean"||(typeof e.nodeName=="string"?(l=n.t&&(n.t="",yield l),yield e):u(e.nodeName)?yield*y(e.nodeName(e),n,!1):m(e)?yield*y(e,n,!1):n.t+=e);i&&(l=n.t)&&(yield l)},ee=(e,n)=>{const i=n.$props??=n.hasAttributes()?Q(n.attributes):{};for(const l in{...i,...n.$props=e}){let r=e[l];l.startsWith("on:")?E(r,i[l])&&J(n,l.slice(3),r):r!==i[l]&&(l.startsWith("set:")?n[l.slice(4)]=r:r==null||r===!1?n.removeAttribute(l):n.setAttribute(l,r===!0?"":r))}},ne=(e,n,i)=>{if(n.contains?.(document.activeElement)){const l=n.nextSibling;for(;i&&i!=n;){const r=i.nextSibling;e.insertBefore(i,l),i=r}}else e.insertBefore(n,i)},ie=(e,n,i,l,r)=>{n=m(n)?n:[],i=u(i)?i:a=>a,l=u(l)?l:w;const o=e.$for??=new Map,t=a=>o.delete(a.$by),s=n!==e.$each,c=(e.$each=n).length,f=A(e.childNodes),p=new Array(c);s&&o.clear();for(let a,d=0;d<c;d++){const v=n[d],N=i(v,d);a=s?f[d]:o.get(N),$.firstChild=a?new Proxy(a,Y):null,g(l(v),$),a??=$.firstChild,$.firstChild=null,o.set(a.$by=N,p[d]=a)}le(e,f,p,t),u(r)&&r(e)},le=(e,n,i,l=w)=>{const r=n.length,o=i.length;let t=0,s=0,c,f,p,a,d;for(;t!==r||s!==o;)c=n[t],f=i[s],c===null?t++:o<=s?(t++,l(e.removeChild(c))):r<=t?(s++,e.appendChild(f)):c===f?(t++,s++):(p??=C(n),a??=C(i),a.get(c)==null?(t++,l(e.removeChild(c))):(e.insertBefore(f,c),s++,(d=p.get(f))!=null&&(d>t+1&&t++,n[d]=null)))},re=(e,n,i,l)=>{e.$setup??=(e.addEventListener("DOMNodeRemovedFromDocument",te),u(n)?n:w),e.$params={...n.params,...i},S(e),u(l)&&l(e)},te=({target:e})=>{(globalThis.queueMicrotask??(n=>n()))(()=>{if(!document.contains(e)&&"$cleanups"in e)try{for(const n of e.$cleanups)n(e)}finally{e.$cleanups.clear()}})};return z(ae);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ajo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "ajo is a JavaScript view library for building user interfaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -37,11 +37,8 @@
|
|
|
37
37
|
"bugs": "https://github.com/cristianfalcone/ajo/issues",
|
|
38
38
|
"homepage": "https://github.com/cristianfalcone/ajo#readme",
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"backdom": "^0.0.
|
|
41
|
-
"esbuild": "^0.15.
|
|
40
|
+
"backdom": "^0.0.8",
|
|
41
|
+
"esbuild": "^0.15.7",
|
|
42
42
|
"uvu": "^0.5.6"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"element-notifier": "^1.1.2"
|
|
46
43
|
}
|
|
47
44
|
}
|