malinajs 0.7.1-alpha → 0.7.2-a1
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/CHANGELOG.md +17 -0
- package/malina-esbuild.js +2 -8
- package/malina.js +6230 -5783
- package/package.json +7 -5
- package/readme.md +13 -7
- package/runtime.js +993 -868
package/runtime.js
CHANGED
|
@@ -1,1123 +1,1248 @@
|
|
|
1
1
|
let __app_onerror = console.error;
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
const configure = (option) => {
|
|
5
|
-
|
|
4
|
+
__app_onerror = option.onerror;
|
|
6
5
|
};
|
|
7
6
|
|
|
8
|
-
|
|
9
7
|
const isFunction = fn => typeof fn == 'function';
|
|
10
8
|
|
|
9
|
+
const isObject = d => typeof d == 'object';
|
|
11
10
|
|
|
12
11
|
const safeCall = fn => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
try {
|
|
13
|
+
return fn?.();
|
|
14
|
+
} catch (e) {
|
|
15
|
+
__app_onerror(e);
|
|
16
|
+
}
|
|
18
17
|
};
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
19
|
+
const safeGroupCall = list => {
|
|
20
|
+
try {
|
|
21
|
+
list?.forEach(fn => fn?.());
|
|
22
|
+
} catch (e) {
|
|
23
|
+
__app_onerror(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
28
26
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const safeCallMount = (mountList, destroyList) => {
|
|
28
|
+
mountList.forEach(fn => {
|
|
29
|
+
let r = safeCall(fn);
|
|
30
|
+
r && destroyList.push(r);
|
|
31
|
+
});
|
|
33
32
|
};
|
|
34
33
|
|
|
34
|
+
let current_destroyList, current_mountList, current_cd, destroyResults;
|
|
35
|
+
const $onDestroy = fn => fn && current_destroyList.push(fn);
|
|
36
|
+
const $onMount = fn => current_mountList.push(fn);
|
|
35
37
|
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function $watchReadOnly(cd, fn, callback) {
|
|
42
|
-
return $watch(cd, fn, callback, {ro: true});
|
|
38
|
+
function WatchObject(fn, cb) {
|
|
39
|
+
this.fn = fn;
|
|
40
|
+
this.cb = cb;
|
|
41
|
+
this.value = NaN;
|
|
42
|
+
this.cmp = null;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
|
|
45
|
+
function $watch(fn, callback, option) {
|
|
46
|
+
let w = new WatchObject(fn, callback);
|
|
47
|
+
option && Object.assign(w, option);
|
|
48
|
+
current_cd.watchers.push(w);
|
|
49
|
+
return w;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
|
|
52
|
+
function addEvent(el, event, callback) {
|
|
53
|
+
if(!callback) return;
|
|
54
|
+
el.addEventListener(event, callback);
|
|
55
|
+
|
|
56
|
+
$onDestroy(() => {
|
|
57
|
+
el.removeEventListener(event, callback);
|
|
58
|
+
});
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
|
|
61
|
+
function removeItem(array, item) {
|
|
62
|
+
let i = array.indexOf(item);
|
|
63
|
+
if(i >= 0) array.splice(i, 1);
|
|
57
64
|
}
|
|
65
|
+
|
|
58
66
|
function $ChangeDetector(parent) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.prefix = [];
|
|
67
|
+
this.parent = parent;
|
|
68
|
+
this.children = [];
|
|
69
|
+
this.watchers = [];
|
|
70
|
+
this.prefix = [];
|
|
64
71
|
}
|
|
65
|
-
$ChangeDetector.prototype.new = function() {
|
|
66
|
-
var cd = new $ChangeDetector(this);
|
|
67
|
-
this.children.push(cd);
|
|
68
|
-
return cd;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
$ChangeDetector.prototype.destroy = function(option) {
|
|
72
|
-
cd_destroy$1(this, option);
|
|
73
|
-
};
|
|
74
72
|
|
|
75
73
|
const cd_component = cd => {
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
while(cd.parent) cd = cd.parent;
|
|
75
|
+
return cd.component;
|
|
78
76
|
};
|
|
79
77
|
|
|
80
78
|
const cd_new = () => new $ChangeDetector();
|
|
81
79
|
|
|
82
80
|
const cd_attach = (parent, cd) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
if(cd) {
|
|
82
|
+
cd.parent = parent;
|
|
83
|
+
parent.children.push(cd);
|
|
84
|
+
}
|
|
87
85
|
};
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const cd_destroy$1 = (cd, option) => {
|
|
92
|
-
if(option !== false && cd.parent) $$removeItem(cd.parent.children, cd);
|
|
93
|
-
cd.watchers.length = 0;
|
|
94
|
-
cd.prefix.length = 0;
|
|
95
|
-
cd._d.forEach(fn => {
|
|
96
|
-
let p = safeCall(fn);
|
|
97
|
-
p && destroyResults && destroyResults.push(p);
|
|
98
|
-
});
|
|
99
|
-
cd._d.length = 0;
|
|
100
|
-
cd.children.map(cd => cd.destroy(false));
|
|
101
|
-
cd.children.length = 0;
|
|
102
|
-
};
|
|
87
|
+
const cd_detach = cd => removeItem(cd.parent.children, cd);
|
|
103
88
|
|
|
104
89
|
const isArray = (a) => Array.isArray(a);
|
|
105
90
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
const _compareArray = (a, b) => {
|
|
92
|
+
let a0 = isArray(a);
|
|
93
|
+
let a1 = isArray(b);
|
|
94
|
+
if(a0 !== a1) return true;
|
|
95
|
+
if(!a0) return a !== b;
|
|
96
|
+
if(a.length !== b.length) return true;
|
|
97
|
+
for(let i = 0; i < a.length; i++) {
|
|
98
|
+
if(a[i] !== b[i]) return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
116
101
|
};
|
|
117
102
|
|
|
118
103
|
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return w.ro ? 0 : 1;
|
|
104
|
+
function compareArray(w, value) {
|
|
105
|
+
if(!_compareArray(w.value, value)) return 0;
|
|
106
|
+
if(isArray(value)) w.value = value.slice();
|
|
107
|
+
else w.value = value;
|
|
108
|
+
w.cb(w.value);
|
|
125
109
|
}
|
|
126
110
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
for(let k in b) {
|
|
150
|
-
if(set[k]) continue;
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
111
|
+
|
|
112
|
+
const _compareDeep = (a, b, lvl) => {
|
|
113
|
+
if(lvl < 0 || !a || !b) return a !== b;
|
|
114
|
+
if(a === b) return false;
|
|
115
|
+
let o0 = isObject(a);
|
|
116
|
+
let o1 = isObject(b);
|
|
117
|
+
if(!(o0 && o1)) return a !== b;
|
|
118
|
+
|
|
119
|
+
let a0 = isArray(a);
|
|
120
|
+
let a1 = isArray(b);
|
|
121
|
+
if(a0 !== a1) return true;
|
|
122
|
+
|
|
123
|
+
if(a0) {
|
|
124
|
+
if(a.length !== b.length) return true;
|
|
125
|
+
for(let i = 0; i < a.length; i++) {
|
|
126
|
+
if(_compareDeep(a[i], b[i], lvl - 1)) return true;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
let set = {};
|
|
130
|
+
for(let k in a) {
|
|
131
|
+
if(_compareDeep(a[k], b[k], lvl - 1)) return true;
|
|
132
|
+
set[k] = true;
|
|
153
133
|
}
|
|
134
|
+
for(let k in b) {
|
|
135
|
+
if(set[k]) continue;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
154
139
|
|
|
155
|
-
|
|
140
|
+
return false;
|
|
156
141
|
};
|
|
157
142
|
|
|
158
143
|
function cloneDeep(d, lvl) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
144
|
+
if(lvl < 0 || !d) return d;
|
|
145
|
+
|
|
146
|
+
if(isObject(d)) {
|
|
147
|
+
if(d instanceof Date) return d;
|
|
148
|
+
if(d instanceof Element) return d;
|
|
149
|
+
if(isArray(d)) return d.map(i => cloneDeep(i, lvl - 1));
|
|
150
|
+
let r = {};
|
|
151
|
+
for(let k in d) r[k] = cloneDeep(d[k], lvl - 1);
|
|
152
|
+
return r;
|
|
153
|
+
}
|
|
154
|
+
return d;
|
|
170
155
|
}
|
|
171
|
-
const $$cloneDeep = function(d) {
|
|
172
|
-
return cloneDeep(d, 10);
|
|
173
|
-
};
|
|
174
156
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
157
|
+
|
|
158
|
+
function deepComparator(depth) {
|
|
159
|
+
return function(w, value) {
|
|
160
|
+
let diff = _compareDeep(w.value, value, depth);
|
|
161
|
+
diff && (w.value = cloneDeep(value, depth), !w.idle && w.cb(value));
|
|
162
|
+
w.idle = false;
|
|
163
|
+
};
|
|
182
164
|
}
|
|
183
|
-
|
|
165
|
+
|
|
166
|
+
const compareDeep = deepComparator(10);
|
|
184
167
|
|
|
185
168
|
|
|
186
169
|
const keyComparator = (w, value) => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return !w.ro && diff ? 1 : 0;
|
|
170
|
+
let diff = false;
|
|
171
|
+
for(let k in value) {
|
|
172
|
+
if(w.value[k] != value[k]) diff = true;
|
|
173
|
+
w.value[k] = value[k];
|
|
174
|
+
}
|
|
175
|
+
diff && !w.idle && w.cb(value);
|
|
176
|
+
w.idle = false;
|
|
195
177
|
};
|
|
196
178
|
|
|
197
179
|
|
|
198
180
|
const fire = w => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
181
|
+
if(w.cmp) w.cmp(w, w.fn());
|
|
182
|
+
else {
|
|
183
|
+
w.value = w.fn();
|
|
184
|
+
w.cb(w.value);
|
|
185
|
+
}
|
|
204
186
|
};
|
|
205
187
|
|
|
206
|
-
function $digest($cd) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
} if(cd.children.length) queue.push.apply(queue, cd.children);
|
|
229
|
-
cd = queue[index++];
|
|
188
|
+
function $digest($cd, flag) {
|
|
189
|
+
let loop = 10;
|
|
190
|
+
let w;
|
|
191
|
+
while(loop >= 0) {
|
|
192
|
+
let index = 0;
|
|
193
|
+
let queue = [];
|
|
194
|
+
let i, value, cd = $cd, changes = 0;
|
|
195
|
+
while(cd) {
|
|
196
|
+
for(i = 0; i < cd.prefix.length; i++) cd.prefix[i]();
|
|
197
|
+
for(i = 0; i < cd.watchers.length; i++) {
|
|
198
|
+
w = cd.watchers[i];
|
|
199
|
+
value = w.fn();
|
|
200
|
+
if(w.value !== value) {
|
|
201
|
+
flag[0] = 0;
|
|
202
|
+
if(w.cmp) {
|
|
203
|
+
w.cmp(w, value);
|
|
204
|
+
} else {
|
|
205
|
+
w.cb(w.value = value);
|
|
206
|
+
}
|
|
207
|
+
changes += flag[0];
|
|
230
208
|
}
|
|
231
|
-
|
|
232
|
-
|
|
209
|
+
}
|
|
210
|
+
if(cd.children.length) queue.push.apply(queue, cd.children);
|
|
211
|
+
cd = queue[index++];
|
|
233
212
|
}
|
|
234
|
-
|
|
213
|
+
loop--;
|
|
214
|
+
if(!changes) break;
|
|
215
|
+
}
|
|
216
|
+
if(loop < 0) __app_onerror('Infinity changes: ', w);
|
|
235
217
|
}
|
|
236
218
|
|
|
237
219
|
let templatecache = {};
|
|
238
220
|
let templatecacheSvg = {};
|
|
239
221
|
|
|
240
|
-
const childNodes = 'childNodes';
|
|
241
|
-
const firstChild = 'firstChild';
|
|
242
|
-
|
|
243
222
|
let noop = a => a;
|
|
244
223
|
|
|
245
224
|
const insertAfter = (label, node) => {
|
|
246
|
-
|
|
225
|
+
label.parentNode.insertBefore(node, label.nextSibling);
|
|
247
226
|
};
|
|
248
227
|
|
|
249
228
|
const createTextNode = (text) => document.createTextNode(text);
|
|
250
229
|
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
230
|
+
const htmlToFragment = (html, option) => {
|
|
231
|
+
let result = templatecache[html];
|
|
232
|
+
if(!result) {
|
|
233
|
+
let t = document.createElement('template');
|
|
234
|
+
t.innerHTML = html.replace(/<>/g, '<!---->');
|
|
235
|
+
result = t.content;
|
|
236
|
+
if(!(option & 2) && result.firstChild == result.lastChild) result = result.firstChild;
|
|
237
|
+
templatecache[html] = result;
|
|
238
|
+
}
|
|
260
239
|
|
|
261
|
-
|
|
240
|
+
return option & 1 ? result.cloneNode(true) : result;
|
|
262
241
|
};
|
|
263
242
|
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
if(!(option & 2) && result.firstChild == result.lastChild) result = result.firstChild;
|
|
277
|
-
templatecache[html] = result;
|
|
243
|
+
const htmlToFragmentClean = (html, option) => {
|
|
244
|
+
let result = templatecache[html];
|
|
245
|
+
if(!result) {
|
|
246
|
+
let t = document.createElement('template');
|
|
247
|
+
t.innerHTML = html.replace(/<>/g, '<!---->');
|
|
248
|
+
result = t.content;
|
|
249
|
+
|
|
250
|
+
let it = document.createNodeIterator(result, 128);
|
|
251
|
+
let n;
|
|
252
|
+
while(n = it.nextNode()) {
|
|
253
|
+
if(!n.nodeValue) n.parentNode.replaceChild(document.createTextNode(''), n);
|
|
278
254
|
}
|
|
279
255
|
|
|
280
|
-
|
|
256
|
+
if(!(option & 2) && result.firstChild == result.lastChild) result = result.firstChild;
|
|
257
|
+
templatecache[html] = result;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return option & 1 ? result.cloneNode(true) : result;
|
|
281
261
|
};
|
|
282
262
|
|
|
283
263
|
|
|
284
264
|
function svgToFragment(content) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
265
|
+
if(templatecacheSvg[content]) return templatecacheSvg[content].cloneNode(true);
|
|
266
|
+
let t = document.createElement('template');
|
|
267
|
+
t.innerHTML = '<svg>' + content + '</svg>';
|
|
268
|
+
|
|
269
|
+
let result = document.createDocumentFragment();
|
|
270
|
+
let svg = t.content.firstChild;
|
|
271
|
+
while(svg.firstChild) result.appendChild(svg.firstChild);
|
|
272
|
+
templatecacheSvg[content] = result.cloneNode(true);
|
|
273
|
+
return result;
|
|
294
274
|
}
|
|
295
275
|
|
|
276
|
+
|
|
296
277
|
const iterNodes = (el, last, fn) => {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
278
|
+
let next;
|
|
279
|
+
while(el) {
|
|
280
|
+
next = el.nextSibling;
|
|
281
|
+
fn(el);
|
|
282
|
+
if(el == last) break;
|
|
283
|
+
el = next;
|
|
284
|
+
}
|
|
304
285
|
};
|
|
305
286
|
|
|
306
287
|
|
|
307
|
-
const
|
|
288
|
+
const removeElements = (el, last) => iterNodes(el, last, n => n.remove());
|
|
308
289
|
|
|
309
290
|
|
|
310
291
|
function removeElementsBetween(el, stop) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
292
|
+
let next;
|
|
293
|
+
el = el.nextSibling;
|
|
294
|
+
while(el) {
|
|
295
|
+
next = el.nextSibling;
|
|
296
|
+
if(el == stop) break;
|
|
297
|
+
el.remove();
|
|
298
|
+
el = next;
|
|
299
|
+
}
|
|
319
300
|
}
|
|
301
|
+
|
|
320
302
|
const getFinalLabel = n => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
303
|
+
if(n.nextSibling) return n.nextSibling;
|
|
304
|
+
let e = document.createTextNode('');
|
|
305
|
+
n.parentNode.appendChild(e);
|
|
306
|
+
return e;
|
|
325
307
|
};
|
|
326
308
|
|
|
327
309
|
|
|
328
310
|
const resolvedPromise = Promise.resolve();
|
|
329
311
|
|
|
330
312
|
function $tick(fn) {
|
|
331
|
-
|
|
332
|
-
|
|
313
|
+
fn && resolvedPromise.then(fn);
|
|
314
|
+
return resolvedPromise;
|
|
333
315
|
}
|
|
334
316
|
|
|
335
|
-
function $makeEmitter(option) {
|
|
336
|
-
return (name, detail) => {
|
|
337
|
-
let fn = option.events[name];
|
|
338
|
-
if(!fn) return;
|
|
339
|
-
let e = document.createEvent('CustomEvent');
|
|
340
|
-
e.initCustomEvent(name, false, false, detail);
|
|
341
|
-
fn(e);
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
317
|
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
handler._list = [prev, fn];
|
|
356
|
-
list[event] = handler;
|
|
357
|
-
}
|
|
358
|
-
} else list[event] = fn;
|
|
318
|
+
function makeEmitter(option) {
|
|
319
|
+
return (name, detail) => {
|
|
320
|
+
let fn = option.events?.[name];
|
|
321
|
+
if(!fn) return;
|
|
322
|
+
let e = document.createEvent('CustomEvent');
|
|
323
|
+
e.initCustomEvent(name, false, false, detail);
|
|
324
|
+
fn(e);
|
|
325
|
+
};
|
|
359
326
|
}
|
|
360
327
|
|
|
361
|
-
let current_component, $context;
|
|
362
|
-
|
|
363
|
-
const $onDestroy = fn => current_component._d.push(fn);
|
|
364
|
-
const $onMount = fn => current_component._m.push(fn);
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const $base = {
|
|
368
|
-
a: ($component) => {
|
|
369
|
-
let $cd = cd_new();
|
|
370
|
-
$cd.component = $component;
|
|
371
|
-
$onDestroy(() => $cd.destroy());
|
|
372
|
-
|
|
373
|
-
let planned;
|
|
374
|
-
let apply = r => {
|
|
375
|
-
if(planned) return r;
|
|
376
|
-
planned = true;
|
|
377
|
-
$tick(() => {
|
|
378
|
-
try {
|
|
379
|
-
$digest($cd);
|
|
380
|
-
} finally {
|
|
381
|
-
planned = false;
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
return r;
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
$component.$cd = $cd;
|
|
388
|
-
$component.apply = apply;
|
|
389
|
-
$component.push = apply;
|
|
390
|
-
},
|
|
391
|
-
b: ($component) => {
|
|
392
|
-
safeCall(() => $digest($component.$cd));
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
328
|
|
|
329
|
+
let current_component;
|
|
396
330
|
|
|
397
|
-
const makeComponent = (init, $base) => {
|
|
398
|
-
return ($option={}) => {
|
|
399
|
-
let prev = current_component;
|
|
400
|
-
$context = $option.context || {};
|
|
401
|
-
let $component = current_component = {
|
|
402
|
-
$option,
|
|
403
|
-
destroy: () => $component._d.map(safeCall),
|
|
404
|
-
context: $context,
|
|
405
|
-
exported: {},
|
|
406
|
-
_d: [],
|
|
407
|
-
_m: []
|
|
408
|
-
};
|
|
409
|
-
$base?.a($component);
|
|
410
331
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
} finally {
|
|
415
|
-
current_component = prev;
|
|
416
|
-
$context = null;
|
|
417
|
-
}
|
|
332
|
+
const makeApply = () => {
|
|
333
|
+
let $cd = current_component.$cd = current_cd = cd_new();
|
|
334
|
+
$cd.component = current_component;
|
|
418
335
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
336
|
+
let planned, flag = [0];
|
|
337
|
+
let apply = r => {
|
|
338
|
+
flag[0]++;
|
|
339
|
+
if(planned) return r;
|
|
340
|
+
planned = true;
|
|
341
|
+
$tick(() => {
|
|
342
|
+
try {
|
|
343
|
+
$digest($cd, flag);
|
|
344
|
+
} finally {
|
|
345
|
+
planned = false;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
return r;
|
|
349
|
+
};
|
|
423
350
|
|
|
351
|
+
current_component.$apply = apply;
|
|
352
|
+
current_component.$push = apply;
|
|
353
|
+
apply();
|
|
354
|
+
return apply;
|
|
355
|
+
};
|
|
424
356
|
|
|
425
|
-
const callComponent = (context, component, option={}, propFn, cmp, setter, classFn) => {
|
|
426
|
-
option.context = {...context};
|
|
427
|
-
let $component, parentWatch, childWatch, cd;
|
|
428
|
-
|
|
429
|
-
if(propFn) {
|
|
430
|
-
if(cmp) {
|
|
431
|
-
cd = cd_new();
|
|
432
|
-
parentWatch = $watch(cd, propFn, value => {
|
|
433
|
-
option.props = value;
|
|
434
|
-
if($component) {
|
|
435
|
-
$component.push?.();
|
|
436
|
-
childWatch && (childWatch.idle = true);
|
|
437
|
-
$component.apply?.();
|
|
438
|
-
}
|
|
439
|
-
}, {ro: true, value: {}, cmp});
|
|
440
|
-
fire(parentWatch);
|
|
441
|
-
} else option.props = propFn();
|
|
442
|
-
}
|
|
443
357
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
358
|
+
const makeComponent = (init) => {
|
|
359
|
+
return ($option = {}) => {
|
|
360
|
+
let prev_component = current_component,
|
|
361
|
+
prev_cd = current_cd,
|
|
362
|
+
$component = current_component = { $option };
|
|
363
|
+
current_cd = null;
|
|
451
364
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
if(fn) {
|
|
458
|
-
cd = cd || cd_new();
|
|
459
|
-
anchors[name] = el => {
|
|
460
|
-
let $cd = cd_new();
|
|
461
|
-
cd_attach(cd, $cd);
|
|
462
|
-
fn($cd, el);
|
|
463
|
-
return () => cd_destroy$1($cd);
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
}
|
|
365
|
+
try {
|
|
366
|
+
$component.$dom = init($option);
|
|
367
|
+
} finally {
|
|
368
|
+
current_component = prev_component;
|
|
369
|
+
current_cd = prev_cd;
|
|
467
370
|
}
|
|
468
371
|
|
|
469
|
-
$component
|
|
470
|
-
|
|
471
|
-
childWatch = $watch($component.$cd, $component.exportedProps, value => {
|
|
472
|
-
setter(value);
|
|
473
|
-
cd_component(cd).apply();
|
|
474
|
-
}, {ro: true, idle: true, value: parentWatch.value, cmp});
|
|
475
|
-
}
|
|
476
|
-
return {
|
|
477
|
-
$cd: cd,
|
|
478
|
-
$dom: $component.$dom,
|
|
479
|
-
destroy: $component.destroy,
|
|
480
|
-
$component
|
|
481
|
-
};
|
|
372
|
+
return $component;
|
|
373
|
+
};
|
|
482
374
|
};
|
|
483
375
|
|
|
484
376
|
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
if(active) removeElementsBetween(label, finalLabel);
|
|
377
|
+
const callComponent = (component, context, option = {}) => {
|
|
378
|
+
option.context = { ...context };
|
|
379
|
+
let $component = safeCall(() => component(option));
|
|
380
|
+
if($component instanceof Node) $component = { $dom: $component };
|
|
381
|
+
return $component;
|
|
382
|
+
};
|
|
492
383
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
384
|
+
|
|
385
|
+
const callComponentDyn = (component, context, option = {}, propFn, cmp, setter, classFn) => {
|
|
386
|
+
let $component, parentWatch;
|
|
387
|
+
|
|
388
|
+
if(propFn) {
|
|
389
|
+
parentWatch = $watch(propFn, value => {
|
|
390
|
+
$component.$push?.(value);
|
|
391
|
+
$component.$apply?.();
|
|
392
|
+
}, { value: {}, idle: true, cmp });
|
|
393
|
+
fire(parentWatch);
|
|
394
|
+
option.props = parentWatch.value;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if(classFn) {
|
|
398
|
+
fire($watch(classFn, value => {
|
|
399
|
+
option.$class = value;
|
|
400
|
+
$component?.$apply?.();
|
|
401
|
+
}, { value: {}, cmp: keyComparator }));
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
$component = callComponent(component, context, option);
|
|
405
|
+
if(setter && $component?.$exportedProps) {
|
|
406
|
+
let parentCD = current_cd, w = new WatchObject($component.$exportedProps, value => {
|
|
407
|
+
setter(value);
|
|
408
|
+
cd_component(parentCD).$apply();
|
|
409
|
+
$component.$push(parentWatch.fn());
|
|
410
|
+
$component.$apply();
|
|
503
411
|
});
|
|
412
|
+
Object.assign(w, { idle: true, cmp, value: parentWatch.value });
|
|
413
|
+
$component.$cd.watchers.push(w);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return $component;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
const attachDynComponent = (label, exp, bind) => {
|
|
421
|
+
let parentCD = current_cd;
|
|
422
|
+
let active, destroyList, $cd, $dom, finalLabel = getFinalLabel(label);
|
|
423
|
+
const destroy = () => safeGroupCall(destroyList);
|
|
424
|
+
$onDestroy(destroy);
|
|
425
|
+
|
|
426
|
+
$watch(exp, (component) => {
|
|
427
|
+
destroy();
|
|
428
|
+
if($cd) cd_detach($cd);
|
|
429
|
+
if(active) removeElementsBetween(label, finalLabel);
|
|
430
|
+
|
|
431
|
+
if(component) {
|
|
432
|
+
destroyList = current_destroyList = [];
|
|
433
|
+
current_mountList = [];
|
|
434
|
+
$cd = current_cd = cd_new();
|
|
435
|
+
try {
|
|
436
|
+
$dom = bind(component).$dom;
|
|
437
|
+
cd_attach(parentCD, $cd);
|
|
438
|
+
insertAfter(label, $dom);
|
|
439
|
+
safeCallMount(current_mountList, destroyList);
|
|
440
|
+
} finally {
|
|
441
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
442
|
+
}
|
|
443
|
+
active = true;
|
|
444
|
+
} else {
|
|
445
|
+
$cd = null;
|
|
446
|
+
active = false;
|
|
447
|
+
destroyList = null;
|
|
448
|
+
}
|
|
449
|
+
});
|
|
504
450
|
};
|
|
505
451
|
|
|
506
452
|
|
|
507
453
|
const autoSubscribe = (...list) => {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
454
|
+
list.forEach(i => {
|
|
455
|
+
if(isFunction(i.subscribe)) {
|
|
456
|
+
let unsub = i.subscribe(current_component.$apply);
|
|
457
|
+
if(isFunction(unsub)) $onDestroy(unsub);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
514
460
|
};
|
|
515
461
|
|
|
516
462
|
|
|
517
463
|
const addStyles = (id, content) => {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
464
|
+
if(document.head.querySelector('style#' + id)) return;
|
|
465
|
+
let style = document.createElement('style');
|
|
466
|
+
style.id = id;
|
|
467
|
+
style.innerHTML = content;
|
|
468
|
+
document.head.appendChild(style);
|
|
523
469
|
};
|
|
524
470
|
|
|
525
471
|
|
|
526
472
|
const addClass = (el, className) => el.classList.add(className);
|
|
527
473
|
|
|
528
474
|
|
|
529
|
-
const bindClass = (
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
475
|
+
const bindClass = (element, fn, className) => {
|
|
476
|
+
$watch(fn, value => {
|
|
477
|
+
if(value) addClass(element, className);
|
|
478
|
+
else element.classList.remove(className);
|
|
479
|
+
}, { value: false });
|
|
534
480
|
};
|
|
535
481
|
|
|
536
482
|
|
|
537
483
|
const setClassToElement = (element, value) => bindAttributeBase(element, 'class', value);
|
|
538
484
|
|
|
539
485
|
|
|
540
|
-
const bindClassExp = (
|
|
541
|
-
|
|
486
|
+
const bindClassExp = (element, fn) => {
|
|
487
|
+
$watch(fn, value => setClassToElement(element, value), { value: '' });
|
|
542
488
|
};
|
|
543
489
|
|
|
544
490
|
|
|
545
|
-
const bindText = (
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
491
|
+
const bindText = (element, fn) => {
|
|
492
|
+
$watch(() => '' + fn(), value => {
|
|
493
|
+
element.textContent = value;
|
|
494
|
+
});
|
|
549
495
|
};
|
|
550
496
|
|
|
551
497
|
|
|
552
|
-
const bindStyle = (
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
498
|
+
const bindStyle = (element, name, fn) => {
|
|
499
|
+
$watch(fn, (value) => {
|
|
500
|
+
element.style.setProperty(name, value);
|
|
501
|
+
});
|
|
556
502
|
};
|
|
557
503
|
|
|
558
504
|
|
|
559
505
|
const bindAttributeBase = (element, name, value) => {
|
|
560
|
-
|
|
561
|
-
|
|
506
|
+
if(value != null) element.setAttribute(name, value);
|
|
507
|
+
else element.removeAttribute(name);
|
|
562
508
|
};
|
|
563
509
|
|
|
564
510
|
|
|
565
|
-
const bindAttribute = (
|
|
566
|
-
|
|
511
|
+
const bindAttribute = (element, name, fn) => {
|
|
512
|
+
$watch(() => {
|
|
513
|
+
let v = fn();
|
|
514
|
+
return v == null ? v : '' + v;
|
|
515
|
+
}, value => bindAttributeBase(element, name, value));
|
|
567
516
|
};
|
|
568
517
|
|
|
569
518
|
|
|
570
|
-
const bindAction = (
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
519
|
+
const bindAction = (element, action, fn, subscribe) => {
|
|
520
|
+
let handler, value;
|
|
521
|
+
if(fn) {
|
|
522
|
+
value = fn();
|
|
523
|
+
handler = action.apply(null, [element].concat(value));
|
|
524
|
+
} else handler = action(element);
|
|
525
|
+
if(isFunction(handler)) $onDestroy(handler);
|
|
526
|
+
else {
|
|
527
|
+
$onDestroy(handler?.destroy);
|
|
528
|
+
subscribe?.(fn, handler, value);
|
|
529
|
+
handler?.init && $onMount(handler.init);
|
|
530
|
+
}
|
|
580
531
|
};
|
|
581
532
|
|
|
582
533
|
|
|
583
|
-
const __bindActionSubscribe = (
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
534
|
+
const __bindActionSubscribe = (fn, handler, value) => {
|
|
535
|
+
if(handler?.update && fn) {
|
|
536
|
+
$watch(fn, args => {
|
|
537
|
+
handler.update.apply(handler, args);
|
|
538
|
+
}, { cmp: deepComparator(1), value: cloneDeep(value, 1) });
|
|
539
|
+
}
|
|
589
540
|
};
|
|
590
541
|
|
|
591
542
|
|
|
592
|
-
const bindInput = (
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
543
|
+
const bindInput = (element, name, get, set) => {
|
|
544
|
+
let w = $watch(name == 'checked' ? () => !!get() : get, value => {
|
|
545
|
+
element[name] = value == null ? '' : value;
|
|
546
|
+
});
|
|
547
|
+
addEvent(element, 'input', () => {
|
|
548
|
+
set(w.value = element[name]);
|
|
549
|
+
});
|
|
599
550
|
};
|
|
600
551
|
|
|
601
552
|
|
|
602
553
|
const makeClassResolver = ($option, classMap, metaClass, mainName) => {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
554
|
+
if(!$option.$class) $option.$class = {};
|
|
555
|
+
if(!mainName && metaClass.main) mainName = 'main';
|
|
556
|
+
return (line, defaults) => {
|
|
557
|
+
let result = {};
|
|
558
|
+
if(defaults) result[defaults] = 1;
|
|
559
|
+
line.trim().split(/\s+/).forEach(name => {
|
|
560
|
+
let meta;
|
|
561
|
+
if(name[0] == '$') {
|
|
562
|
+
name = name.substring(1);
|
|
563
|
+
meta = true;
|
|
564
|
+
}
|
|
565
|
+
let h = metaClass[name] || meta;
|
|
566
|
+
if(h) {
|
|
567
|
+
let className = ($option.$class[name === mainName ? '$$main' : name] || '').trim();
|
|
568
|
+
if(className) {
|
|
569
|
+
result[className] = 1;
|
|
570
|
+
} else if(h !== true) {
|
|
571
|
+
result[name] = 1;
|
|
572
|
+
result[h] = 1;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
let h2 = classMap[name];
|
|
576
|
+
if(h2) {
|
|
577
|
+
result[name] = 1;
|
|
578
|
+
result[h2] = 1;
|
|
579
|
+
} else if(!h) {
|
|
580
|
+
result[name] = 1;
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
return Object.keys(result).join(' ');
|
|
584
|
+
};
|
|
634
585
|
};
|
|
635
586
|
|
|
636
587
|
|
|
637
|
-
const makeExternalProperty = (
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
588
|
+
const makeExternalProperty = (name, getter, setter) => {
|
|
589
|
+
let $component = current_component;
|
|
590
|
+
Object.defineProperty($component, name, {
|
|
591
|
+
get: getter,
|
|
592
|
+
set: v => { setter(v); $component.$apply(); }
|
|
593
|
+
});
|
|
642
594
|
};
|
|
643
595
|
|
|
644
596
|
|
|
645
|
-
const
|
|
597
|
+
const attachAnchor = ($option, el, name) => {
|
|
598
|
+
$option.anchor?.[name || 'default']?.(el);
|
|
599
|
+
};
|
|
646
600
|
|
|
647
601
|
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
602
|
+
const makeAnchor = (fn) => {
|
|
603
|
+
let parentCD = current_cd;
|
|
604
|
+
return ($dom) => {
|
|
605
|
+
let prev = current_cd, $cd = current_cd = cd_new();
|
|
606
|
+
cd_attach(parentCD, $cd);
|
|
607
|
+
$onDestroy(() => cd_detach($cd));
|
|
608
|
+
try {
|
|
609
|
+
fn($dom);
|
|
610
|
+
} finally {
|
|
611
|
+
current_cd = prev;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
651
614
|
};
|
|
652
615
|
|
|
653
616
|
|
|
654
|
-
const spreadAttributes = (
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
617
|
+
const spreadAttributes = (el, fn) => {
|
|
618
|
+
const props = Object.getOwnPropertyDescriptors(el.__proto__);
|
|
619
|
+
let prev = {};
|
|
620
|
+
const set = (k, v) => {
|
|
621
|
+
if(k == 'style') el.style.cssText = v;
|
|
622
|
+
else if(props[k]?.set) el[k] = v;
|
|
623
|
+
else bindAttributeBase(el, k, v);
|
|
624
|
+
};
|
|
625
|
+
const apply = (state) => {
|
|
626
|
+
for(let k in state) {
|
|
627
|
+
let value = state[k];
|
|
628
|
+
if(prev[k] != value) {
|
|
629
|
+
set(k, value);
|
|
630
|
+
prev[k] = value;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
for(let k in prev) {
|
|
634
|
+
if(!(k in state)) {
|
|
635
|
+
set(k, null);
|
|
636
|
+
delete prev[k];
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
$watch(fn, apply, {
|
|
641
|
+
cmp: (_, state) => {
|
|
642
|
+
apply(state);
|
|
643
|
+
return 0;
|
|
644
|
+
}
|
|
645
|
+
});
|
|
681
646
|
};
|
|
682
647
|
|
|
683
648
|
|
|
684
649
|
const callExportedFragment = (childComponent, name, slot, events, props, cmp) => {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
r.$cd = $cd;
|
|
699
|
-
return r;
|
|
650
|
+
let push, $dom;
|
|
651
|
+
if(cmp) {
|
|
652
|
+
let result;
|
|
653
|
+
let w = $watch(props, (value) => {
|
|
654
|
+
result = value;
|
|
655
|
+
push?.();
|
|
656
|
+
}, { value: {}, cmp });
|
|
657
|
+
fire(w);
|
|
658
|
+
props = () => result;
|
|
659
|
+
}
|
|
660
|
+
let fn = childComponent.$exported?.[name];
|
|
661
|
+
([$dom, push] = fn(props, events, slot));
|
|
662
|
+
return $dom;
|
|
700
663
|
};
|
|
701
664
|
|
|
702
665
|
|
|
703
|
-
const exportFragment = (
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
666
|
+
const exportFragment = (component, name, fn) => {
|
|
667
|
+
let childCD = current_cd;
|
|
668
|
+
if(!component.$exported) component.$exported = {};
|
|
669
|
+
component.$exported[name] = (props, events, slot) => {
|
|
670
|
+
let prev = current_cd, apply;
|
|
671
|
+
if(childCD) {
|
|
672
|
+
let $cd = current_cd = cd_new();
|
|
673
|
+
cd_attach(childCD, $cd);
|
|
674
|
+
$onDestroy(() => cd_detach($cd));
|
|
675
|
+
apply = component.$apply;
|
|
676
|
+
apply();
|
|
677
|
+
} else {
|
|
678
|
+
current_cd = null;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
try {
|
|
682
|
+
return [fn(props, events || {}, slot), apply];
|
|
683
|
+
} finally {
|
|
684
|
+
current_cd = prev;
|
|
685
|
+
}
|
|
686
|
+
};
|
|
714
687
|
};
|
|
715
688
|
|
|
716
689
|
|
|
717
|
-
const prefixPush =
|
|
718
|
-
|
|
719
|
-
|
|
690
|
+
const prefixPush = fn => {
|
|
691
|
+
current_cd.prefix.push(fn);
|
|
692
|
+
fn();
|
|
720
693
|
};
|
|
721
694
|
|
|
722
695
|
|
|
723
|
-
const unwrapProps = (
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
696
|
+
const unwrapProps = (props, fn) => {
|
|
697
|
+
if(props) {
|
|
698
|
+
if(isFunction(props)) prefixPush(() => fn(props()));
|
|
699
|
+
else fn(props);
|
|
700
|
+
}
|
|
728
701
|
};
|
|
729
702
|
|
|
730
703
|
|
|
731
704
|
const makeBlock = (fr, fn) => {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
705
|
+
return (v) => {
|
|
706
|
+
let $dom = fr.cloneNode(true);
|
|
707
|
+
fn?.($dom, v);
|
|
708
|
+
return $dom;
|
|
709
|
+
};
|
|
737
710
|
};
|
|
738
711
|
|
|
739
712
|
|
|
740
|
-
const makeBlockBound = (
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
713
|
+
const makeBlockBound = (fr, fn) => {
|
|
714
|
+
let parentCD = current_cd;
|
|
715
|
+
return () => {
|
|
716
|
+
let $dom = fr.cloneNode(true), prev = current_cd, $cd = current_cd = cd_new();
|
|
717
|
+
cd_attach(parentCD, $cd);
|
|
718
|
+
$onDestroy(() => cd_detach($cd));
|
|
719
|
+
try {
|
|
720
|
+
fn($dom);
|
|
721
|
+
return $dom;
|
|
722
|
+
} finally {
|
|
723
|
+
current_cd = prev;
|
|
749
724
|
}
|
|
725
|
+
};
|
|
750
726
|
};
|
|
751
727
|
|
|
752
728
|
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
fn?.($dom);
|
|
757
|
-
return {$dom};
|
|
758
|
-
}
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
const attachBlock = (cdo, label, block) => {
|
|
762
|
-
if(!block) return;
|
|
763
|
-
cd_onDestroy(cdo, block.destroy);
|
|
764
|
-
cd_attach(cdo, block.$cd);
|
|
765
|
-
insertAfter(label, block.$dom);
|
|
729
|
+
const attachBlock = (label, $dom) => {
|
|
730
|
+
if(!$dom) return;
|
|
731
|
+
insertAfter(label, $dom.$dom || $dom);
|
|
766
732
|
};
|
|
767
733
|
|
|
768
|
-
|
|
769
734
|
const mergeEvents = (...callbacks) => {
|
|
770
|
-
|
|
771
|
-
|
|
735
|
+
callbacks = callbacks.filter(i => i);
|
|
736
|
+
return (e) => callbacks.forEach(cb => cb(e));
|
|
772
737
|
};
|
|
773
738
|
|
|
739
|
+
const mergeAllEvents = ($events, local) => {
|
|
740
|
+
let result = Object.assign({}, $events);
|
|
741
|
+
for(let e in local) {
|
|
742
|
+
if(result[e]) result[e] = mergeEvents($events[e], local[e]);
|
|
743
|
+
else result[e] = local[e];
|
|
744
|
+
}
|
|
745
|
+
return result;
|
|
746
|
+
};
|
|
774
747
|
|
|
775
748
|
const makeRootEvent = (root) => {
|
|
776
|
-
|
|
749
|
+
let events = {}, nodes = [];
|
|
750
|
+
|
|
751
|
+
if(root.nodeType == 11) {
|
|
752
|
+
let n = root.firstElementChild;
|
|
753
|
+
while(n) {
|
|
754
|
+
nodes.push(n);
|
|
755
|
+
n = n.nextElementSibling;
|
|
756
|
+
}
|
|
757
|
+
} else nodes = [root];
|
|
777
758
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
759
|
+
$onDestroy(() => {
|
|
760
|
+
for(let eventName in events) {
|
|
761
|
+
nodes.forEach(n => n.removeEventListener(eventName, events[eventName]));
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
return (target, eventName, callback) => {
|
|
765
|
+
const key = `_$$${eventName}`;
|
|
766
|
+
if(!events[eventName]) {
|
|
767
|
+
let handler = events[eventName] = ($event) => {
|
|
768
|
+
let top = $event.currentTarget;
|
|
769
|
+
let el = $event.target;
|
|
770
|
+
while(el) {
|
|
771
|
+
el[key]?.($event);
|
|
772
|
+
if(el == top || $event.cancelBubble) break;
|
|
773
|
+
el = el.parentNode;
|
|
783
774
|
}
|
|
784
|
-
|
|
775
|
+
};
|
|
776
|
+
nodes.forEach(n => n.addEventListener(eventName, handler));
|
|
777
|
+
}
|
|
778
|
+
target[key] = callback;
|
|
779
|
+
};
|
|
780
|
+
};
|
|
785
781
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
782
|
+
const mount = (label, component, option) => {
|
|
783
|
+
let app, first, last, destroyList = current_destroyList = [];
|
|
784
|
+
current_mountList = [];
|
|
785
|
+
try {
|
|
786
|
+
app = component(option);
|
|
787
|
+
let $dom = app.$dom;
|
|
788
|
+
delete app.$dom;
|
|
789
|
+
if($dom.nodeType == 11) {
|
|
790
|
+
first = $dom.firstChild;
|
|
791
|
+
last = $dom.lastChild;
|
|
792
|
+
} else first = last = $dom;
|
|
793
|
+
label.appendChild($dom);
|
|
794
|
+
safeCallMount(current_mountList, destroyList);
|
|
795
|
+
} finally {
|
|
796
|
+
current_destroyList = current_mountList = null;
|
|
797
|
+
}
|
|
798
|
+
app.destroy = () => {
|
|
799
|
+
safeGroupCall(destroyList);
|
|
800
|
+
removeElements(first, last);
|
|
801
|
+
};
|
|
802
|
+
return app;
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
const mountStatic = (label, component, option) => {
|
|
806
|
+
current_destroyList = [];
|
|
807
|
+
current_mountList = [];
|
|
808
|
+
try {
|
|
809
|
+
let app = component(option);
|
|
810
|
+
label.appendChild(app.$dom);
|
|
811
|
+
safeGroupCall(current_mountList);
|
|
812
|
+
return app;
|
|
813
|
+
} finally {
|
|
814
|
+
current_destroyList = current_mountList = null;
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
const refer = (active, line) => {
|
|
819
|
+
let result = [], i, v;
|
|
820
|
+
const code = (x, d) => x.charCodeAt() - d;
|
|
821
|
+
|
|
822
|
+
for(i = 0; i < line.length; i++) {
|
|
823
|
+
let a = line[i];
|
|
824
|
+
switch (a) {
|
|
825
|
+
case '>':
|
|
826
|
+
active = active.firstChild;
|
|
827
|
+
break;
|
|
828
|
+
case '+':
|
|
829
|
+
active = active.firstChild;
|
|
830
|
+
case '.':
|
|
831
|
+
result.push(active);
|
|
832
|
+
break;
|
|
833
|
+
case '!':
|
|
834
|
+
v = code(line[++i], 48) * 42 + code(line[++i], 48);
|
|
835
|
+
while(v--) active = active.nextSibling;
|
|
836
|
+
break;
|
|
837
|
+
case '#':
|
|
838
|
+
active = result[code(line[++i], 48) * 26 + code(line[++i], 48)];
|
|
839
|
+
break;
|
|
840
|
+
default:
|
|
841
|
+
v = code(a, 0);
|
|
842
|
+
if(v >= 97) active = result[v - 97];
|
|
843
|
+
else {
|
|
844
|
+
v -= 48;
|
|
845
|
+
while(v--) active = active.nextSibling;
|
|
789
846
|
}
|
|
790
|
-
});
|
|
791
|
-
return (target, eventName, callback) => {
|
|
792
|
-
const key = `_$$${eventName}`;
|
|
793
|
-
if(!events[eventName]) {
|
|
794
|
-
let handler = events[eventName] = ($event) => {
|
|
795
|
-
let top = $event.currentTarget;
|
|
796
|
-
let el = $event.target;
|
|
797
|
-
while(el) {
|
|
798
|
-
el[key]?.($event);
|
|
799
|
-
if(el == top || $event.cancelBubble) break;
|
|
800
|
-
el = el.parentNode;
|
|
801
|
-
}
|
|
802
|
-
};
|
|
803
|
-
nodes.forEach(n => n.addEventListener(eventName, handler));
|
|
804
|
-
} target[key] = callback;
|
|
805
847
|
}
|
|
848
|
+
}
|
|
849
|
+
return result;
|
|
806
850
|
};
|
|
807
851
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
852
|
+
let create = (tag, html) => {
|
|
853
|
+
let fr;
|
|
854
|
+
if(tag.parentElement instanceof SVGElement) {
|
|
855
|
+
let t = document.createElement('template');
|
|
856
|
+
t.innerHTML = '<svg>' + html + '</svg>';
|
|
857
|
+
fr = t.content.firstChild;
|
|
858
|
+
} else {
|
|
859
|
+
let t = document.createElement('template');
|
|
860
|
+
t.innerHTML = html;
|
|
861
|
+
fr = t.content;
|
|
862
|
+
}
|
|
863
|
+
let lastElement = fr.lastChild;
|
|
864
|
+
insertAfter(tag, fr);
|
|
865
|
+
return lastElement;
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
function htmlBlock(tag, fn) {
|
|
869
|
+
let lastElement;
|
|
870
|
+
let destroy = () => {
|
|
871
|
+
if(!lastElement) return;
|
|
872
|
+
removeElements(tag.nextSibling, lastElement);
|
|
873
|
+
lastElement = null;
|
|
874
|
+
};
|
|
875
|
+
$watch(fn, (html) => {
|
|
876
|
+
destroy();
|
|
877
|
+
if(html) lastElement = create(tag, html);
|
|
878
|
+
});
|
|
828
879
|
}
|
|
829
880
|
|
|
830
|
-
function
|
|
831
|
-
|
|
832
|
-
|
|
881
|
+
function htmlBlockStatic(tag, value) {
|
|
882
|
+
create(tag, value);
|
|
883
|
+
}
|
|
833
884
|
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
885
|
+
function ifBlock(label, fn, parts, parentLabel) {
|
|
886
|
+
let first, last, $cd, destroyList, parentCD = current_cd;
|
|
887
|
+
$onDestroy(() => safeGroupCall(destroyList));
|
|
888
|
+
|
|
889
|
+
function createBlock(builder) {
|
|
890
|
+
let $dom;
|
|
891
|
+
destroyList = current_destroyList = [];
|
|
892
|
+
let mountList = current_mountList = [];
|
|
893
|
+
$cd = current_cd = cd_new();
|
|
894
|
+
try {
|
|
895
|
+
$dom = builder();
|
|
896
|
+
} finally {
|
|
897
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
843
898
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
899
|
+
cd_attach(parentCD, $cd);
|
|
900
|
+
if($dom.nodeType == 11) {
|
|
901
|
+
first = $dom.firstChild;
|
|
902
|
+
last = $dom.lastChild;
|
|
903
|
+
} else first = last = $dom;
|
|
904
|
+
if(parentLabel) label.appendChild($dom);
|
|
905
|
+
else insertAfter(label, $dom);
|
|
906
|
+
safeCallMount(mountList, destroyList);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
function destroyBlock() {
|
|
910
|
+
if(!first) return;
|
|
911
|
+
destroyResults = [];
|
|
912
|
+
safeGroupCall(destroyList);
|
|
913
|
+
destroyList.length = 0;
|
|
914
|
+
if($cd) {
|
|
915
|
+
cd_detach($cd);
|
|
916
|
+
$cd = null;
|
|
861
917
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
918
|
+
if(destroyResults.length) {
|
|
919
|
+
let f = first, l = last;
|
|
920
|
+
Promise.allSettled(destroyResults).then(() => {
|
|
921
|
+
removeElements(f, l);
|
|
922
|
+
});
|
|
923
|
+
} else removeElements(first, last);
|
|
924
|
+
first = last = null;
|
|
925
|
+
destroyResults = null;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
$watch(fn, (value) => {
|
|
929
|
+
destroyBlock();
|
|
930
|
+
if(value != null) createBlock(parts[value]);
|
|
931
|
+
});
|
|
871
932
|
}
|
|
872
933
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
insertAfter(label, $dom);
|
|
878
|
-
}
|
|
879
|
-
if(fn()) createBlock(build);
|
|
880
|
-
else if(buildElse) createBlock(buildElse);
|
|
934
|
+
|
|
935
|
+
function ifBlockReadOnly(label, fn, parts) {
|
|
936
|
+
let value = fn();
|
|
937
|
+
if(value != null) insertAfter(label, parts[value]());
|
|
881
938
|
}
|
|
882
939
|
|
|
883
|
-
function
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
$$removeElements(first, last);
|
|
896
|
-
first = last = null;
|
|
940
|
+
function awaitBlock(label, relation, fn, build_main, build_then, build_catch) {
|
|
941
|
+
let parentCD = current_cd, first, last, $cd, promise, destroyList, status = 0;
|
|
942
|
+
$onDestroy(() => safeGroupCall(destroyList));
|
|
943
|
+
|
|
944
|
+
function destroyBlock() {
|
|
945
|
+
if(!first) return;
|
|
946
|
+
|
|
947
|
+
safeGroupCall(destroyList);
|
|
948
|
+
destroyList.length = 0;
|
|
949
|
+
if($cd) {
|
|
950
|
+
cd_detach($cd);
|
|
951
|
+
$cd = null;
|
|
897
952
|
}
|
|
898
|
-
|
|
899
|
-
|
|
953
|
+
removeElements(first, last);
|
|
954
|
+
first = last = null;
|
|
955
|
+
}
|
|
900
956
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
957
|
+
function render(builder, value) {
|
|
958
|
+
destroyBlock();
|
|
959
|
+
|
|
960
|
+
if(!builder) return;
|
|
961
|
+
destroyList = current_destroyList = [];
|
|
962
|
+
$cd = current_cd = cd_new();
|
|
963
|
+
let $dom, mountList = current_mountList = [];
|
|
964
|
+
try {
|
|
965
|
+
$dom = builder(value);
|
|
966
|
+
} finally {
|
|
967
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
910
968
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
969
|
+
cd_attach(parentCD, $cd);
|
|
970
|
+
if($dom.nodeType == 11) {
|
|
971
|
+
first = $dom.firstChild;
|
|
972
|
+
last = $dom.lastChild;
|
|
973
|
+
} else first = last = $dom;
|
|
974
|
+
insertAfter(label, $dom);
|
|
975
|
+
safeCallMount(mountList, destroyList);
|
|
976
|
+
cd_component(parentCD).$apply();
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
$watch(relation, () => {
|
|
980
|
+
let p = fn();
|
|
981
|
+
if(status !== 1) render(build_main);
|
|
982
|
+
status = 1;
|
|
983
|
+
if(p && p instanceof Promise) {
|
|
984
|
+
promise = p;
|
|
985
|
+
promise.then(value => {
|
|
986
|
+
status = 2;
|
|
987
|
+
if(promise !== p) return;
|
|
988
|
+
render(build_then, value);
|
|
989
|
+
}).catch(value => {
|
|
990
|
+
status = 3;
|
|
991
|
+
if(promise !== p) return;
|
|
992
|
+
render(build_catch, value);
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
}, { value: [], cmp: keyComparator });
|
|
928
996
|
}
|
|
929
997
|
|
|
998
|
+
const eachDefaultKey = (item, index, array) => isObject(array[0]) ? item : index;
|
|
999
|
+
|
|
1000
|
+
|
|
930
1001
|
const makeEachBlock = (fr, fn) => {
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
1002
|
+
return (item, index) => {
|
|
1003
|
+
let $dom = fr.cloneNode(true);
|
|
1004
|
+
return [$dom, fn($dom, item, index)];
|
|
1005
|
+
};
|
|
936
1006
|
};
|
|
937
1007
|
|
|
938
1008
|
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
1009
|
+
const makeEachSingleBlock = (fn) => {
|
|
1010
|
+
return (item, index) => {
|
|
1011
|
+
let [rebind, component] = fn(item, index);
|
|
1012
|
+
return [component.$dom, rebind];
|
|
1013
|
+
};
|
|
945
1014
|
};
|
|
946
1015
|
|
|
947
1016
|
|
|
948
|
-
const
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1017
|
+
const makeEachElseBlock = (fn) => {
|
|
1018
|
+
return (label, onlyChild, parentCD) => {
|
|
1019
|
+
let first, last;
|
|
1020
|
+
let destroyList = current_destroyList = [];
|
|
1021
|
+
let $cd = current_cd = cd_new();
|
|
1022
|
+
current_mountList = [];
|
|
1023
|
+
try {
|
|
1024
|
+
let $dom = fn();
|
|
1025
|
+
if($dom.nodeType == 11) {
|
|
1026
|
+
first = $dom.firstChild;
|
|
1027
|
+
last = $dom.lastChild;
|
|
1028
|
+
} else first = last = $dom;
|
|
1029
|
+
cd_attach(parentCD, $cd);
|
|
1030
|
+
if(onlyChild) label.appendChild($dom);
|
|
1031
|
+
else attachBlock(label, $dom);
|
|
1032
|
+
safeCallMount(current_mountList, destroyList);
|
|
1033
|
+
} finally {
|
|
1034
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
953
1035
|
}
|
|
1036
|
+
|
|
1037
|
+
return () => {
|
|
1038
|
+
removeElements(first, last);
|
|
1039
|
+
cd_detach($cd);
|
|
1040
|
+
safeGroupCall(destroyList);
|
|
1041
|
+
};
|
|
1042
|
+
};
|
|
954
1043
|
};
|
|
955
1044
|
|
|
956
1045
|
|
|
957
|
-
function $$eachBlock(
|
|
958
|
-
|
|
959
|
-
|
|
1046
|
+
function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
1047
|
+
let parentCD = current_cd;
|
|
1048
|
+
let eachCD = cd_new();
|
|
1049
|
+
cd_attach(parentCD, eachCD);
|
|
1050
|
+
|
|
1051
|
+
let mapping = new Map();
|
|
1052
|
+
let lastNode, vi = 0, p_promise = 0, p_destroy = 0, elseBlock;
|
|
1053
|
+
|
|
1054
|
+
const destroyAll = () => {
|
|
1055
|
+
p_destroy && safeCall(() => mapping.forEach(ctx => ctx.d?.forEach(fn => fn())));
|
|
1056
|
+
mapping.clear();
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
$onDestroy(destroyAll);
|
|
1060
|
+
buildElseBlock && $onDestroy(() => elseBlock?.());
|
|
1061
|
+
|
|
1062
|
+
$watch(fn, (array) => {
|
|
1063
|
+
if(!array) array = [];
|
|
1064
|
+
if(typeof (array) == 'number') array = [...Array(array)].map((_, i) => i + 1);
|
|
1065
|
+
else if(!isArray(array)) array = [];
|
|
1066
|
+
|
|
1067
|
+
let newMapping = new Map();
|
|
1068
|
+
let prevNode, parentNode;
|
|
1069
|
+
if(onlyChild) {
|
|
1070
|
+
prevNode = null;
|
|
1071
|
+
parentNode = label;
|
|
1072
|
+
} else {
|
|
1073
|
+
prevNode = label;
|
|
1074
|
+
parentNode = label.parentNode;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
if(mapping.size) {
|
|
1078
|
+
let ctx, count = 0;
|
|
1079
|
+
vi++;
|
|
1080
|
+
for(let i = 0; i < array.length; i++) {
|
|
1081
|
+
ctx = mapping.get(getKey(array[i], i, array));
|
|
1082
|
+
if(ctx) {
|
|
1083
|
+
ctx.a = vi;
|
|
1084
|
+
count++;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
if(!count && lastNode) {
|
|
1089
|
+
destroyResults = [];
|
|
1090
|
+
eachCD.children.length = 0;
|
|
1091
|
+
destroyAll();
|
|
960
1092
|
|
|
961
|
-
|
|
962
|
-
|
|
1093
|
+
if(destroyResults.length) {
|
|
1094
|
+
p_promise = 1;
|
|
1095
|
+
let removedNodes = [];
|
|
1096
|
+
iterNodes(onlyChild ? label.firstChild : label.nextSibling, lastNode, n => {
|
|
1097
|
+
n.$$removing = true;
|
|
1098
|
+
removedNodes.push(n);
|
|
1099
|
+
});
|
|
1100
|
+
Promise.allSettled(destroyResults).then(() => removedNodes.forEach(n => n.remove()));
|
|
1101
|
+
} else {
|
|
1102
|
+
if(onlyChild) label.textContent = '';
|
|
1103
|
+
else removeElements(label.nextSibling, lastNode);
|
|
1104
|
+
}
|
|
963
1105
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1106
|
+
destroyResults = null;
|
|
1107
|
+
} else if(count < mapping.size) {
|
|
1108
|
+
eachCD.children = [];
|
|
1109
|
+
destroyResults = [];
|
|
1110
|
+
let removedNodes = [];
|
|
1111
|
+
mapping.forEach(ctx => {
|
|
1112
|
+
if(ctx.a == vi) {
|
|
1113
|
+
ctx.$cd && eachCD.children.push(ctx.$cd);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
safeGroupCall(ctx.d);
|
|
1117
|
+
iterNodes(ctx.first, ctx.last, n => removedNodes.push(n));
|
|
1118
|
+
});
|
|
968
1119
|
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
parentNode = label;
|
|
1120
|
+
if(destroyResults.length) {
|
|
1121
|
+
p_promise = 1;
|
|
1122
|
+
removedNodes.forEach(n => n.$$removing = true);
|
|
1123
|
+
Promise.allSettled(destroyResults).then(() => removedNodes.forEach(n => n.remove()));
|
|
974
1124
|
} else {
|
|
975
|
-
|
|
976
|
-
parentNode = label.parentNode;
|
|
1125
|
+
removedNodes.forEach(n => n.remove());
|
|
977
1126
|
}
|
|
1127
|
+
destroyResults = null;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
978
1130
|
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
ctx = mapping.get(getKey(array[i], i, array));
|
|
984
|
-
if(ctx) {
|
|
985
|
-
ctx.a = vi;
|
|
986
|
-
count++;
|
|
987
|
-
}
|
|
988
|
-
}
|
|
1131
|
+
if(elseBlock && array.length) {
|
|
1132
|
+
elseBlock();
|
|
1133
|
+
elseBlock = null;
|
|
1134
|
+
}
|
|
989
1135
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
ctx.destroy?.();
|
|
1021
|
-
iterNodes(ctx.first, ctx.last, n => {
|
|
1022
|
-
n.$$removing = true;
|
|
1023
|
-
removedNodes.push(n);
|
|
1024
|
-
});
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
if(destroyResults.length) {
|
|
1028
|
-
Promise.allSettled(destroyResults).then(() => removedNodes.forEach(n => n.remove()));
|
|
1029
|
-
} else {
|
|
1030
|
-
removedNodes.forEach(n => n.remove());
|
|
1031
|
-
}
|
|
1032
|
-
destroyResults = null;
|
|
1136
|
+
let i, item, next_ctx, ctx, nextEl, key;
|
|
1137
|
+
for(i = 0; i < array.length; i++) {
|
|
1138
|
+
item = array[i];
|
|
1139
|
+
key = getKey(item, i, array);
|
|
1140
|
+
if(next_ctx) {
|
|
1141
|
+
ctx = next_ctx;
|
|
1142
|
+
next_ctx = null;
|
|
1143
|
+
} else ctx = mapping.get(key);
|
|
1144
|
+
if(ctx) {
|
|
1145
|
+
nextEl = i == 0 && onlyChild ? parentNode.firstChild : prevNode.nextSibling;
|
|
1146
|
+
if(p_promise) while(nextEl && nextEl.$$removing) nextEl = nextEl.nextSibling;
|
|
1147
|
+
if(nextEl != ctx.first) {
|
|
1148
|
+
let insert = true;
|
|
1149
|
+
|
|
1150
|
+
if(ctx.first == ctx.last && (i + 1 < array.length) && prevNode?.nextSibling) {
|
|
1151
|
+
next_ctx = mapping.get(getKey(array[i + 1], i + 1, array));
|
|
1152
|
+
if(next_ctx && prevNode.nextSibling.nextSibling === next_ctx.first) {
|
|
1153
|
+
parentNode.replaceChild(ctx.first, prevNode.nextSibling);
|
|
1154
|
+
insert = false;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
if(insert) {
|
|
1159
|
+
let insertBefore = prevNode?.nextSibling;
|
|
1160
|
+
let next, el = ctx.first;
|
|
1161
|
+
while(el) {
|
|
1162
|
+
next = el.nextSibling;
|
|
1163
|
+
parentNode.insertBefore(el, insertBefore);
|
|
1164
|
+
if(el == ctx.last) break;
|
|
1165
|
+
el = next;
|
|
1033
1166
|
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
ctx.rebind?.(item, i);
|
|
1170
|
+
} else {
|
|
1171
|
+
let $dom, rebind,
|
|
1172
|
+
d = current_destroyList = [],
|
|
1173
|
+
m = current_mountList = [],
|
|
1174
|
+
$cd = current_cd = cd_new();
|
|
1175
|
+
try {
|
|
1176
|
+
([$dom, rebind] = bind(item, i));
|
|
1177
|
+
} finally {
|
|
1178
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
1179
|
+
}
|
|
1180
|
+
ctx = { $cd, rebind };
|
|
1181
|
+
cd_attach(eachCD, $cd);
|
|
1182
|
+
if($dom.nodeType == 11) {
|
|
1183
|
+
ctx.first = $dom.firstChild;
|
|
1184
|
+
ctx.last = $dom.lastChild;
|
|
1185
|
+
} else ctx.first = ctx.last = $dom;
|
|
1186
|
+
parentNode.insertBefore($dom, prevNode?.nextSibling);
|
|
1187
|
+
safeCallMount(m, d);
|
|
1188
|
+
if(d.length) {
|
|
1189
|
+
ctx.d = d;
|
|
1190
|
+
p_destroy = 1;
|
|
1034
1191
|
}
|
|
1192
|
+
}
|
|
1193
|
+
prevNode = ctx.last;
|
|
1194
|
+
newMapping.set(key, ctx);
|
|
1195
|
+
}
|
|
1196
|
+
lastNode = prevNode;
|
|
1197
|
+
mapping.clear();
|
|
1198
|
+
mapping = newMapping;
|
|
1035
1199
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
if(next_ctx) {
|
|
1041
|
-
ctx = next_ctx;
|
|
1042
|
-
next_ctx = null;
|
|
1043
|
-
} else ctx = mapping.get(key);
|
|
1044
|
-
if(ctx) {
|
|
1045
|
-
nextEl = i == 0 && onlyChild ? parentNode[firstChild] : prevNode.nextSibling;
|
|
1046
|
-
while(nextEl && nextEl.$$removing) nextEl = nextEl.nextSibling;
|
|
1047
|
-
if(nextEl != ctx.first) {
|
|
1048
|
-
let insert = true;
|
|
1049
|
-
|
|
1050
|
-
if(ctx.first == ctx.last && (i + 1 < array.length) && prevNode?.nextSibling) {
|
|
1051
|
-
next_ctx = mapping.get(getKey(array[i + 1], i + 1, array));
|
|
1052
|
-
if(next_ctx && prevNode.nextSibling.nextSibling === next_ctx.first) {
|
|
1053
|
-
parentNode.replaceChild(ctx.first, prevNode.nextSibling);
|
|
1054
|
-
insert = false;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
if(insert) {
|
|
1059
|
-
let insertBefore = prevNode?.nextSibling;
|
|
1060
|
-
let next, el = ctx.first;
|
|
1061
|
-
while(el) {
|
|
1062
|
-
next = el.nextSibling;
|
|
1063
|
-
parentNode.insertBefore(el, insertBefore);
|
|
1064
|
-
if(el == ctx.last) break;
|
|
1065
|
-
el = next;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
ctx.rebind?.(i, item);
|
|
1070
|
-
} else {
|
|
1071
|
-
let $dom;
|
|
1072
|
-
({$dom, ...ctx} = bind(item, i));
|
|
1073
|
-
cd_attach(eachCD, ctx.$cd);
|
|
1074
|
-
if($dom.nodeType == 11) {
|
|
1075
|
-
ctx.first = $dom[firstChild];
|
|
1076
|
-
ctx.last = $dom.lastChild;
|
|
1077
|
-
} else ctx.first = ctx.last = $dom;
|
|
1078
|
-
parentNode.insertBefore($dom, prevNode?.nextSibling);
|
|
1079
|
-
}
|
|
1080
|
-
prevNode = ctx.last;
|
|
1081
|
-
newMapping.set(key, ctx);
|
|
1082
|
-
} lastNode = prevNode;
|
|
1083
|
-
mapping.clear();
|
|
1084
|
-
mapping = newMapping;
|
|
1085
|
-
}, {ro: true, cmp: $$compareArray});
|
|
1200
|
+
if(!array.length && !elseBlock && buildElseBlock) {
|
|
1201
|
+
elseBlock = buildElseBlock(label, onlyChild, parentCD);
|
|
1202
|
+
}
|
|
1203
|
+
}, { cmp: compareArray });
|
|
1086
1204
|
}
|
|
1087
1205
|
|
|
1088
1206
|
const invokeSlotBase = ($component, slotName, $context, props, placeholder) => {
|
|
1089
|
-
|
|
1090
|
-
|
|
1207
|
+
let $slot = $component.$option.slots?.[slotName || 'default'];
|
|
1208
|
+
return $slot ? $slot($component, $context, props) : placeholder?.();
|
|
1091
1209
|
};
|
|
1092
1210
|
|
|
1093
|
-
|
|
1094
1211
|
const invokeSlot = ($component, slotName, $context, propsFn, placeholder, cmp) => {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1212
|
+
let $slot = $component.$option.slots?.[slotName || 'default'];
|
|
1213
|
+
|
|
1214
|
+
if($slot) {
|
|
1215
|
+
let push, w = new WatchObject(propsFn, value => push(value));
|
|
1216
|
+
Object.assign(w, { value: {}, cmp, idle: true });
|
|
1217
|
+
fire(w);
|
|
1218
|
+
let $dom = $slot($component, $context, w.value);
|
|
1219
|
+
if($dom.$dom) {
|
|
1220
|
+
if($dom.push) {
|
|
1221
|
+
push = $dom.push;
|
|
1222
|
+
current_cd.watchers.push(w);
|
|
1223
|
+
}
|
|
1224
|
+
$dom = $dom.$dom;
|
|
1225
|
+
}
|
|
1226
|
+
return $dom;
|
|
1227
|
+
} else return placeholder?.();
|
|
1108
1228
|
};
|
|
1109
1229
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1230
|
+
const makeSlot = (fr, fn) => {
|
|
1231
|
+
let parentCD = current_cd;
|
|
1232
|
+
return (callerComponent, $context, props) => {
|
|
1233
|
+
let $dom = fr.cloneNode(true), prev = current_cd;
|
|
1234
|
+
if(parentCD) {
|
|
1235
|
+
let $cd = current_cd = cd_new();
|
|
1236
|
+
cd_attach(parentCD, $cd);
|
|
1237
|
+
$onDestroy(() => cd_detach($cd));
|
|
1238
|
+
cd_component(parentCD).$apply();
|
|
1239
|
+
} else current_cd = null;
|
|
1240
|
+
try {
|
|
1241
|
+
return { $dom, push: fn($dom, $context, callerComponent, props) };
|
|
1242
|
+
} finally {
|
|
1243
|
+
current_cd = prev;
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1121
1246
|
};
|
|
1122
1247
|
|
|
1123
|
-
export { $$
|
|
1248
|
+
export { $$eachBlock, $digest, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachBlock, attachDynComponent, autoSubscribe, awaitBlock, bindAction, bindAttribute, bindAttributeBase, bindClass, bindClassExp, bindInput, bindStyle, bindText, callComponent, callComponentDyn, callExportedFragment, cd_attach, cd_component, cd_detach, cd_new, cloneDeep, compareArray, compareDeep, configure, createTextNode, current_cd, current_component, current_destroyList, current_mountList, deepComparator, destroyResults, eachDefaultKey, exportFragment, fire, getFinalLabel, htmlBlock, htmlBlockStatic, htmlToFragment, htmlToFragmentClean, ifBlock, ifBlockReadOnly, insertAfter, invokeSlot, invokeSlotBase, isArray, isFunction, iterNodes, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeEmitter, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, refer, removeElements, removeElementsBetween, removeItem, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
|