closures 0.7.8 → 0.7.10
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/dist/closures.cjs +67 -42
- package/dist/closures.js +67 -42
- package/dist/closures.min.js +1 -1
- package/package.json +1 -1
package/dist/closures.cjs
CHANGED
@@ -37,13 +37,16 @@ let NIL = void 0,
|
|
37
37
|
REF_ARRAY = 4, // ref with array of nodes
|
38
38
|
REF_PARENT = 8, // ref with a child ref
|
39
39
|
RETAIN_KEY = '=',
|
40
|
+
exists = x => x !== null && x !== undefined,
|
41
|
+
hasKey = vnode => vnode && exists(vnode.key),
|
42
|
+
haveMatchingKeys = (x, y) => (!exists(x) ? NIL : x.key) === (!exists(y) ? NIL : y.key),
|
40
43
|
generateClosureId = _ => NUM++,
|
41
44
|
isFn = x => typeof x === 'function',
|
42
45
|
isStr = x => typeof x === 'string',
|
43
46
|
isObj = x => x !== null && typeof x === 'object',
|
44
47
|
isArr = x => Array.isArray(x),
|
45
48
|
toJson = v => JSON.stringify(v),
|
46
|
-
isEmpty = c => c
|
49
|
+
isEmpty = c => !exists(c) || c === false || (isArr(c) && c.length === 0) || (c && c._t === RETAIN_KEY),
|
47
50
|
isNonEmptyArray = c => isArr(c) && c.length > 0,
|
48
51
|
isLeaf = c => isStr(c) || typeof c === 'number',
|
49
52
|
isElement = c => c && c.vtype === VTYPE_ELEMENT,
|
@@ -91,8 +94,7 @@ let replaceDom = (parent, newRef, oldRef) => {
|
|
91
94
|
};
|
92
95
|
|
93
96
|
let setDomAttribute = (el, attr, value, isSVG) => {
|
94
|
-
if (
|
95
|
-
if (value === NIL) value = '';
|
97
|
+
if (!exists(value)) value = '';
|
96
98
|
if (value === true) el.setAttribute(attr, '');
|
97
99
|
else if (value === false) el.removeAttribute(attr);
|
98
100
|
else (isSVG && NS_ATTRS[attr])
|
@@ -160,7 +162,7 @@ let mount = (vnode, env, closureId, closure, onRemove = noop) => {
|
|
160
162
|
let baseRef = { closureId, closure, onRemove };
|
161
163
|
|
162
164
|
if (isEmpty(vnode))
|
163
|
-
return { ...baseRef, type: REF_SINGLE, node: document.
|
165
|
+
return { ...baseRef, type: REF_SINGLE, node: document.createTextNode('') };
|
164
166
|
|
165
167
|
if (isLeaf(vnode))
|
166
168
|
return { ...baseRef, type: REF_SINGLE, node: document.createTextNode(vnode) };
|
@@ -276,8 +278,12 @@ let patchInPlace = (parentDomNode, newVnode, oldVnode, ref, env) => {
|
|
276
278
|
};
|
277
279
|
|
278
280
|
let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
279
|
-
// we need to retrieve the next sibling before the old children get removed from the DOM
|
280
|
-
let
|
281
|
+
// we need to retrieve the next sibling before the old children get eventually removed from the current DOM document
|
282
|
+
let oldVnode,
|
283
|
+
newVnode,
|
284
|
+
oldRef,
|
285
|
+
newRef,
|
286
|
+
refMap,
|
281
287
|
nextNode = getNextSibling(ref),
|
282
288
|
children = Array(newChildren.length),
|
283
289
|
refChildren = ref.children,
|
@@ -285,22 +291,22 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
285
291
|
oldStart = 0,
|
286
292
|
newEnd = newChildren.length - 1,
|
287
293
|
oldEnd = oldChildren.length - 1;
|
288
|
-
|
294
|
+
|
289
295
|
while (newStart <= newEnd && oldStart <= oldEnd) {
|
290
296
|
if (refChildren[oldStart] === NIL) {
|
291
297
|
oldStart++;
|
292
298
|
continue;
|
293
299
|
}
|
294
|
-
|
300
|
+
|
295
301
|
if (refChildren[oldEnd] === NIL) {
|
296
302
|
oldEnd--;
|
297
303
|
continue;
|
298
304
|
}
|
299
|
-
|
305
|
+
|
300
306
|
oldVnode = oldChildren[oldStart];
|
301
307
|
newVnode = newChildren[newStart];
|
302
|
-
|
303
|
-
if (
|
308
|
+
|
309
|
+
if (haveMatchingKeys(newVnode, oldVnode)) {
|
304
310
|
oldRef = refChildren[oldStart];
|
305
311
|
newRef = children[newStart] = patchInPlace(
|
306
312
|
parentDomNode,
|
@@ -309,16 +315,15 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
309
315
|
oldRef,
|
310
316
|
env
|
311
317
|
);
|
312
|
-
|
313
318
|
newStart++;
|
314
319
|
oldStart++;
|
315
320
|
continue;
|
316
321
|
}
|
317
|
-
|
322
|
+
|
318
323
|
oldVnode = oldChildren[oldEnd];
|
319
324
|
newVnode = newChildren[newEnd];
|
320
|
-
|
321
|
-
if (
|
325
|
+
|
326
|
+
if (haveMatchingKeys(newVnode, oldVnode)) {
|
322
327
|
oldRef = refChildren[oldEnd];
|
323
328
|
newRef = children[newEnd] = patchInPlace(
|
324
329
|
parentDomNode,
|
@@ -327,22 +332,24 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
327
332
|
oldRef,
|
328
333
|
env
|
329
334
|
);
|
330
|
-
|
331
335
|
newEnd--;
|
332
336
|
oldEnd--;
|
333
337
|
continue;
|
334
338
|
}
|
335
|
-
|
336
|
-
if (refMap
|
337
|
-
|
339
|
+
|
340
|
+
if (!refMap) {
|
341
|
+
refMap = {};
|
342
|
+
for (let i = oldStart; i <= oldEnd; i++) {
|
338
343
|
oldVnode = oldChildren[i];
|
339
|
-
if (oldVnode
|
344
|
+
if (hasKey(oldVnode)) {
|
340
345
|
refMap[oldVnode.key] = i;
|
346
|
+
}
|
341
347
|
}
|
342
|
-
|
348
|
+
}
|
349
|
+
|
343
350
|
newVnode = newChildren[newStart];
|
344
|
-
idx = newVnode && newVnode.key !== NIL ? refMap[newVnode.key] : NIL;
|
345
351
|
|
352
|
+
let idx = hasKey(newVnode) ? refMap[newVnode.key] : NIL;
|
346
353
|
if (idx !== NIL) {
|
347
354
|
oldVnode = oldChildren[idx];
|
348
355
|
oldRef = refChildren[idx];
|
@@ -353,45 +360,46 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
353
360
|
oldRef,
|
354
361
|
env
|
355
362
|
);
|
356
|
-
|
363
|
+
|
357
364
|
insertDom(parentDomNode, newRef, getDomNode(refChildren[oldStart]));
|
358
|
-
|
365
|
+
|
359
366
|
if (newRef !== oldRef) {
|
360
367
|
removeDom(parentDomNode, oldRef);
|
361
368
|
unmount(oldVnode, oldRef, env);
|
362
369
|
}
|
363
|
-
|
370
|
+
|
364
371
|
refChildren[idx] = NIL;
|
365
372
|
} else {
|
366
373
|
newRef = children[newStart] = mount(newVnode, env);
|
367
374
|
insertDom(parentDomNode, newRef, getDomNode(refChildren[oldStart]));
|
368
375
|
}
|
369
|
-
|
376
|
+
|
370
377
|
newStart++;
|
371
378
|
}
|
372
|
-
|
373
|
-
beforeNode =
|
374
|
-
|
375
|
-
|
376
|
-
|
379
|
+
|
380
|
+
let beforeNode =
|
381
|
+
newEnd < newChildren.length - 1
|
382
|
+
? getDomNode(children[newEnd + 1])
|
383
|
+
: nextNode;
|
384
|
+
|
377
385
|
while (newStart <= newEnd) {
|
378
|
-
newRef = mount(newChildren[newStart], env);
|
386
|
+
let newRef = mount(newChildren[newStart], env);
|
379
387
|
children[newStart] = newRef;
|
380
388
|
insertDom(parentDomNode, newRef, beforeNode);
|
381
389
|
newStart++;
|
382
390
|
}
|
383
|
-
|
391
|
+
|
384
392
|
while (oldStart <= oldEnd) {
|
385
393
|
oldRef = refChildren[oldStart];
|
386
|
-
|
394
|
+
|
387
395
|
if (oldRef !== NIL) {
|
388
396
|
removeDom(parentDomNode, oldRef);
|
389
397
|
unmount(oldChildren[oldStart], oldRef, env);
|
390
398
|
}
|
391
|
-
|
399
|
+
|
392
400
|
oldStart++;
|
393
401
|
}
|
394
|
-
|
402
|
+
|
395
403
|
ref.children = children;
|
396
404
|
};
|
397
405
|
|
@@ -507,13 +515,30 @@ function h(_t, ...children) {
|
|
507
515
|
? { ...props, children: children[0] }
|
508
516
|
: props;
|
509
517
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
518
|
+
if (isStr(_t)) {
|
519
|
+
if (props.className && !props.class) {
|
520
|
+
props.class = props.className;
|
521
|
+
delete props.className;
|
522
|
+
}
|
523
|
+
|
524
|
+
// class parsing
|
525
|
+
if (isObj(props.class)) {
|
526
|
+
let k, tmp = '';
|
527
|
+
|
528
|
+
for (k in props.class)
|
529
|
+
if (props.class[k]) {
|
530
|
+
tmp && (tmp += ' ');
|
531
|
+
tmp += k
|
532
|
+
}
|
514
533
|
|
515
|
-
|
516
|
-
|
534
|
+
props.class = tmp;
|
535
|
+
}
|
536
|
+
|
537
|
+
if (~(idx = _t.indexOf('.'))) {
|
538
|
+
let className = _t.slice(idx + 1).replace(/\./g, ' ') + (props.class ? ' ' + props.class : '');
|
539
|
+
if (className) props.class = className;
|
540
|
+
_t = _t.slice(0, idx);
|
541
|
+
}
|
517
542
|
}
|
518
543
|
|
519
544
|
if (props.key !== props.key) throw new Error("Invalid NaN key");
|
package/dist/closures.js
CHANGED
@@ -37,13 +37,16 @@ let NIL = void 0,
|
|
37
37
|
REF_ARRAY = 4, // ref with array of nodes
|
38
38
|
REF_PARENT = 8, // ref with a child ref
|
39
39
|
RETAIN_KEY = '=',
|
40
|
+
exists = x => x !== null && x !== undefined,
|
41
|
+
hasKey = vnode => vnode && exists(vnode.key),
|
42
|
+
haveMatchingKeys = (x, y) => (!exists(x) ? NIL : x.key) === (!exists(y) ? NIL : y.key),
|
40
43
|
generateClosureId = _ => NUM++,
|
41
44
|
isFn = x => typeof x === 'function',
|
42
45
|
isStr = x => typeof x === 'string',
|
43
46
|
isObj = x => x !== null && typeof x === 'object',
|
44
47
|
isArr = x => Array.isArray(x),
|
45
48
|
toJson = v => JSON.stringify(v),
|
46
|
-
isEmpty = c => c
|
49
|
+
isEmpty = c => !exists(c) || c === false || (isArr(c) && c.length === 0) || (c && c._t === RETAIN_KEY),
|
47
50
|
isNonEmptyArray = c => isArr(c) && c.length > 0,
|
48
51
|
isLeaf = c => isStr(c) || typeof c === 'number',
|
49
52
|
isElement = c => c && c.vtype === VTYPE_ELEMENT,
|
@@ -91,8 +94,7 @@ let replaceDom = (parent, newRef, oldRef) => {
|
|
91
94
|
};
|
92
95
|
|
93
96
|
let setDomAttribute = (el, attr, value, isSVG) => {
|
94
|
-
if (
|
95
|
-
if (value === NIL) value = '';
|
97
|
+
if (!exists(value)) value = '';
|
96
98
|
if (value === true) el.setAttribute(attr, '');
|
97
99
|
else if (value === false) el.removeAttribute(attr);
|
98
100
|
else (isSVG && NS_ATTRS[attr])
|
@@ -160,7 +162,7 @@ let mount = (vnode, env, closureId, closure, onRemove = noop) => {
|
|
160
162
|
let baseRef = { closureId, closure, onRemove };
|
161
163
|
|
162
164
|
if (isEmpty(vnode))
|
163
|
-
return { ...baseRef, type: REF_SINGLE, node: document.
|
165
|
+
return { ...baseRef, type: REF_SINGLE, node: document.createTextNode('') };
|
164
166
|
|
165
167
|
if (isLeaf(vnode))
|
166
168
|
return { ...baseRef, type: REF_SINGLE, node: document.createTextNode(vnode) };
|
@@ -276,8 +278,12 @@ let patchInPlace = (parentDomNode, newVnode, oldVnode, ref, env) => {
|
|
276
278
|
};
|
277
279
|
|
278
280
|
let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
279
|
-
// we need to retrieve the next sibling before the old children get removed from the DOM
|
280
|
-
let
|
281
|
+
// we need to retrieve the next sibling before the old children get eventually removed from the current DOM document
|
282
|
+
let oldVnode,
|
283
|
+
newVnode,
|
284
|
+
oldRef,
|
285
|
+
newRef,
|
286
|
+
refMap,
|
281
287
|
nextNode = getNextSibling(ref),
|
282
288
|
children = Array(newChildren.length),
|
283
289
|
refChildren = ref.children,
|
@@ -285,22 +291,22 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
285
291
|
oldStart = 0,
|
286
292
|
newEnd = newChildren.length - 1,
|
287
293
|
oldEnd = oldChildren.length - 1;
|
288
|
-
|
294
|
+
|
289
295
|
while (newStart <= newEnd && oldStart <= oldEnd) {
|
290
296
|
if (refChildren[oldStart] === NIL) {
|
291
297
|
oldStart++;
|
292
298
|
continue;
|
293
299
|
}
|
294
|
-
|
300
|
+
|
295
301
|
if (refChildren[oldEnd] === NIL) {
|
296
302
|
oldEnd--;
|
297
303
|
continue;
|
298
304
|
}
|
299
|
-
|
305
|
+
|
300
306
|
oldVnode = oldChildren[oldStart];
|
301
307
|
newVnode = newChildren[newStart];
|
302
|
-
|
303
|
-
if (
|
308
|
+
|
309
|
+
if (haveMatchingKeys(newVnode, oldVnode)) {
|
304
310
|
oldRef = refChildren[oldStart];
|
305
311
|
newRef = children[newStart] = patchInPlace(
|
306
312
|
parentDomNode,
|
@@ -309,16 +315,15 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
309
315
|
oldRef,
|
310
316
|
env
|
311
317
|
);
|
312
|
-
|
313
318
|
newStart++;
|
314
319
|
oldStart++;
|
315
320
|
continue;
|
316
321
|
}
|
317
|
-
|
322
|
+
|
318
323
|
oldVnode = oldChildren[oldEnd];
|
319
324
|
newVnode = newChildren[newEnd];
|
320
|
-
|
321
|
-
if (
|
325
|
+
|
326
|
+
if (haveMatchingKeys(newVnode, oldVnode)) {
|
322
327
|
oldRef = refChildren[oldEnd];
|
323
328
|
newRef = children[newEnd] = patchInPlace(
|
324
329
|
parentDomNode,
|
@@ -327,22 +332,24 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
327
332
|
oldRef,
|
328
333
|
env
|
329
334
|
);
|
330
|
-
|
331
335
|
newEnd--;
|
332
336
|
oldEnd--;
|
333
337
|
continue;
|
334
338
|
}
|
335
|
-
|
336
|
-
if (refMap
|
337
|
-
|
339
|
+
|
340
|
+
if (!refMap) {
|
341
|
+
refMap = {};
|
342
|
+
for (let i = oldStart; i <= oldEnd; i++) {
|
338
343
|
oldVnode = oldChildren[i];
|
339
|
-
if (oldVnode
|
344
|
+
if (hasKey(oldVnode)) {
|
340
345
|
refMap[oldVnode.key] = i;
|
346
|
+
}
|
341
347
|
}
|
342
|
-
|
348
|
+
}
|
349
|
+
|
343
350
|
newVnode = newChildren[newStart];
|
344
|
-
idx = newVnode && newVnode.key !== NIL ? refMap[newVnode.key] : NIL;
|
345
351
|
|
352
|
+
let idx = hasKey(newVnode) ? refMap[newVnode.key] : NIL;
|
346
353
|
if (idx !== NIL) {
|
347
354
|
oldVnode = oldChildren[idx];
|
348
355
|
oldRef = refChildren[idx];
|
@@ -353,45 +360,46 @@ let patchChildren = (parentDomNode, newChildren, oldChildren, ref, env) => {
|
|
353
360
|
oldRef,
|
354
361
|
env
|
355
362
|
);
|
356
|
-
|
363
|
+
|
357
364
|
insertDom(parentDomNode, newRef, getDomNode(refChildren[oldStart]));
|
358
|
-
|
365
|
+
|
359
366
|
if (newRef !== oldRef) {
|
360
367
|
removeDom(parentDomNode, oldRef);
|
361
368
|
unmount(oldVnode, oldRef, env);
|
362
369
|
}
|
363
|
-
|
370
|
+
|
364
371
|
refChildren[idx] = NIL;
|
365
372
|
} else {
|
366
373
|
newRef = children[newStart] = mount(newVnode, env);
|
367
374
|
insertDom(parentDomNode, newRef, getDomNode(refChildren[oldStart]));
|
368
375
|
}
|
369
|
-
|
376
|
+
|
370
377
|
newStart++;
|
371
378
|
}
|
372
|
-
|
373
|
-
beforeNode =
|
374
|
-
|
375
|
-
|
376
|
-
|
379
|
+
|
380
|
+
let beforeNode =
|
381
|
+
newEnd < newChildren.length - 1
|
382
|
+
? getDomNode(children[newEnd + 1])
|
383
|
+
: nextNode;
|
384
|
+
|
377
385
|
while (newStart <= newEnd) {
|
378
|
-
newRef = mount(newChildren[newStart], env);
|
386
|
+
let newRef = mount(newChildren[newStart], env);
|
379
387
|
children[newStart] = newRef;
|
380
388
|
insertDom(parentDomNode, newRef, beforeNode);
|
381
389
|
newStart++;
|
382
390
|
}
|
383
|
-
|
391
|
+
|
384
392
|
while (oldStart <= oldEnd) {
|
385
393
|
oldRef = refChildren[oldStart];
|
386
|
-
|
394
|
+
|
387
395
|
if (oldRef !== NIL) {
|
388
396
|
removeDom(parentDomNode, oldRef);
|
389
397
|
unmount(oldChildren[oldStart], oldRef, env);
|
390
398
|
}
|
391
|
-
|
399
|
+
|
392
400
|
oldStart++;
|
393
401
|
}
|
394
|
-
|
402
|
+
|
395
403
|
ref.children = children;
|
396
404
|
};
|
397
405
|
|
@@ -507,13 +515,30 @@ export function h(_t, ...children) {
|
|
507
515
|
? { ...props, children: children[0] }
|
508
516
|
: props;
|
509
517
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
518
|
+
if (isStr(_t)) {
|
519
|
+
if (props.className && !props.class) {
|
520
|
+
props.class = props.className;
|
521
|
+
delete props.className;
|
522
|
+
}
|
523
|
+
|
524
|
+
// class parsing
|
525
|
+
if (isObj(props.class)) {
|
526
|
+
let k, tmp = '';
|
527
|
+
|
528
|
+
for (k in props.class)
|
529
|
+
if (props.class[k]) {
|
530
|
+
tmp && (tmp += ' ');
|
531
|
+
tmp += k
|
532
|
+
}
|
514
533
|
|
515
|
-
|
516
|
-
|
534
|
+
props.class = tmp;
|
535
|
+
}
|
536
|
+
|
537
|
+
if (~(idx = _t.indexOf('.'))) {
|
538
|
+
let className = _t.slice(idx + 1).replace(/\./g, ' ') + (props.class ? ' ' + props.class : '');
|
539
|
+
if (className) props.class = className;
|
540
|
+
_t = _t.slice(0, idx);
|
541
|
+
}
|
517
542
|
}
|
518
543
|
|
519
544
|
if (props.key !== props.key) throw new Error("Invalid NaN key");
|
package/dist/closures.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.closures={})}(this,(function(e){let t=void 0,r=e=>{},n=e=>({mount(t,r=""){t[e]=r},patch(t,r="",n){r!==n&&(t[e]=r)},unmount(r){r[e]=t}}),i={isSVG:!1,redraw:r,directives:{selected:n("selected"),checked:n("checked"),value:n("value"),innerHTML:n("innerHTML")}},o=[],l=[],d=new WeakMap,c=1,s={},f="http://www.w3.org/1999/xlink",h={show:f,actuate:f,href:f},p=e=>"function"==typeof e,
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.closures={})}(this,(function(e){let t=void 0,r=e=>{},n=e=>({mount(t,r=""){t[e]=r},patch(t,r="",n){r!==n&&(t[e]=r)},unmount(r){r[e]=t}}),i={isSVG:!1,redraw:r,directives:{selected:n("selected"),checked:n("checked"),value:n("value"),innerHTML:n("innerHTML")}},o=[],l=[],d=new WeakMap,c=1,s={},f="http://www.w3.org/1999/xlink",h={show:f,actuate:f,href:f},u=e=>null!=e,a=e=>e&&u(e.key),p=(e,r)=>(u(e)?e.key:t)===(u(r)?r.key:t),y=e=>"function"==typeof e,v=e=>"string"==typeof e,w=e=>null!==e&&"object"==typeof e,m=e=>Array.isArray(e),g=e=>JSON.stringify(e),k=e=>!u(e)||!1===e||m(e)&&0===e.length||e&&"="===e._t,R=e=>m(e)&&e.length>0,_=e=>v(e)||"number"==typeof e,S=e=>e&&1===e.vtype,N=e=>e&&2===e.vtype,E=e=>{let t=e.type;if(1===t)return e.node;if(8===t)return E(e.childRef);if(4===t)return E(e.children[0]);throw Error("Unknown ref type "+g(e))},x=e=>{let t=e.type;if(1===t)return e.node.nextSibling;if(8===t)return x(e.childRef);if(4===t)return x(e.children[e.children.length-1]);throw Error("Unknown ref type "+g(e))},V=(e,t,r)=>{let n=t.type;if(1===n)e.insertBefore(t.node,r);else if(8===n)V(e,t.childRef,r);else{if(4!==n)throw Error("Unknown ref type "+g(t));for(let n=0;n<t.children.length;n++)V(e,t.children[n],r)}},b=(e,t)=>{let r=t.type;if(1===r)e.removeChild(t.node);else if(8===r)b(e,t.childRef);else{if(4!==r)throw Error("Unknown ref type "+g(t));for(let r=0;r<t.children.length;r++)b(e,t.children[r])}},A=(e,t,r,n)=>{u(r)||(r=""),!0===r?e.setAttribute(t,""):!1===r?e.removeAttribute(t):n&&h[t]?e.setAttributeNS(h[t],t,r):e.setAttribute(t,r)},G=(e,n,i,o,s=r)=>{let f={closureId:i,closure:o,onRemove:s};if(k(e))return{...f,type:1,node:document.createTextNode("")};if(_(e))return{...f,type:1,node:document.createTextNode(e)};if(S(e)){let r,{_t:i,props:o}=e;"svg"!==i||n.isSVG||(n={...n,isSVG:!0}),r=n.isSVG?document.createElementNS("http://www.w3.org/2000/svg",i):document.createElement(i),y(o.oncreate)&&o.oncreate(r),((e,t,r)=>{for(let n in t)"key"===n||"children"===n||"oncreate"===n||n in r.directives||(n.startsWith("on")?e[n.toLowerCase()]=e=>{t[n](e),!r.manualRedraw&&r.rerender()}:A(e,n,t[n],r.isSVG))})(r,o,n);let l=o.children===t?o.children:G(o.children,n);return l!==t&&V(r,l),((e,t,r)=>{for(let n in t)n in r.directives&&r.directives[n].mount(e,t[n])})(r,o,n),{...f,type:1,node:r,children:l}}if(R(e)){let t=0,r=[];for(;t<e.length;t++)r.push(G(e[t],n));return{...f,type:4,children:r}}if(N(e)){let t=e._t(e.props);if(y(t)){let i=c++,o=d.get(e._t)||new Map,s=l.pop()||r;o.set(i,t),d.set(e._t,o);let f=e._t;return e._t=t,G(e,n,i,f,s)}return{...f,type:8,childRef:G(t,n),childState:t}}if(e instanceof Node)return{...f,type:1,node:e};if(e===t)throw Error("mount: vnode is undefined");throw Error("mount: Invalid vnode")},C=(e,r,n)=>{if(S(e))((e,t,r)=>{for(let n in t)n in r.directives&&r.directives[n].unmount(e,t[n])})(r.node,e.props,n),e.props.children!==t&&C(e.props.children,r.children,n);else if(R(e))for(let t=0;t<e.length;t++)C(e[t],r.children[t],n);else if(N(e)){let e=r.closure,t=r.closureId,i=r.onRemove,o=d.get(e);o&&t&&o.get(t)&&(o.delete(t),!o.size&&d.delete(e),i()),C(r.childState,r.childRef,n)}},I=(e,t,r,n,i)=>{let o=L(e,t,r,n,i);return o!==n&&(((e,t,r)=>{V(e,t,E(r)),b(e,r)})(e,o,n),C(r,n,i)),o},L=(e,r,n,o,l={...i})=>{if(r&&"="===r._t)return o;let c,s;if(w(o)&&(c=o.closure,s=o.closureId),N(r)&&N(n)&&(r._t===n._t||c&&s)){let t,n=r._t,i=d.get(c);i&&s&&(t=i.get(s))&&(n=t);let f=n(r.props),h=L(e,f,o.childState,o.childRef,l);return h!==o.childRef?{type:8,childRef:h,childState:f}:(o.childState=f,o)}if(n===r||k(r)&&k(n))return o;if(_(r)&&_(n))return o.node.nodeValue=r,o;if(S(r)&&S(n)&&r._t===n._t){"svg"!==r._t||l.isSVG||(l={...l,isSVG:!0}),((e,r,n,i)=>{let o;for(o in r){if("key"===o||"children"===o||"oncreate"===o||o in i.directives)continue;let t=n[o],l=r[o];t!==l&&(o.startsWith("on")?e[o.toLowerCase()]=e=>{l(e),!i.manualRedraw&&i.rerender()}:A(e,o,l,i.isSVG))}for(o in n)"key"===o||"children"===o||o in r||o in i.directives||(o.startsWith("on")?e[o.toLowerCase()]=t:e.removeAttribute(o))})(o.node,r.props,n.props,l);let e=n.props.children,i=r.props.children;return e===t?i!==t&&(o.children=G(i,l),V(o.node,o.children)):i===t?(o.node.textContent="",C(e,o.children,l),o.children=t):o.children=I(o.node,i,e,o.children,l),((e,t,r,n)=>{let i;for(i in t)i in n.directives&&n.directives[i].patch(e,t[i],r[i]);for(i in r)i in n.directives&&!(i in t)&&n.directives[i].unmount(e,r[i])})(o.node,r.props,n.props,l),o}return R(r)&&R(n)?(((e,r,n,i,o)=>{let l,d,c,s,f,h=x(i),u=Array(r.length),y=i.children,v=0,w=0,m=r.length-1,g=n.length-1;for(;v<=m&&w<=g;){if(y[w]===t){w++;continue}if(y[g]===t){g--;continue}if(l=n[w],d=r[v],p(d,l)){c=y[w],s=u[v]=I(e,d,l,c,o),v++,w++;continue}if(l=n[g],d=r[m],p(d,l)){c=y[g],s=u[m]=I(e,d,l,c,o),m--,g--;continue}if(!f){f={};for(let e=w;e<=g;e++)l=n[e],a(l)&&(f[l.key]=e)}d=r[v];let i=a(d)?f[d.key]:t;i!==t?(l=n[i],c=y[i],s=u[v]=L(e,d,l,c,o),V(e,s,E(y[w])),s!==c&&(b(e,c),C(l,c,o)),y[i]=t):(s=u[v]=G(d,o),V(e,s,E(y[w]))),v++}let k=m<r.length-1?E(u[m+1]):h;for(;v<=m;){let t=G(r[v],o);u[v]=t,V(e,t,k),v++}for(;w<=g;)c=y[w],c!==t&&(b(e,c),C(n[w],c,o)),w++;i.children=u})(e,r,n,o,l),o):r instanceof Node&&n instanceof Node?(o.node=r,o):G(r,l)};function M(e,...r){let n,i=r[0];if(!i||!w(i)||m(i)||i._t||i.props?i=s:r.shift(),i=r.length>1?{...i,children:r}:1===r.length?{...i,children:r[0]}:i,v(e)){if(i.className&&!i.class&&(i.class=i.className,delete i.className),w(i.class)){let e,t="";for(e in i.class)i.class[e]&&(t&&(t+=" "),t+=e);i.class=t}if(~(n=e.indexOf("."))){let t=e.slice(n+1).replace(/\./g," ")+(i.class?" "+i.class:"");t&&(i.class=t),e=e.slice(0,n)}}if(i.key!=i.key)throw new Error("Invalid NaN key");let o=v(e)?1:y(e)?2:t;if(o===t)throw new Error("Invalid VNode type");return{vtype:o,_t:e,key:i.key,props:i}}M.retain=e=>M("=");const T=M;e.Fragment=e=>e.children,e.app=function(e,r,n={}){let l,d={...i,manualRedraw:n.manualRedraw},c=r.$_REF;if(d.directives={...d.directives,...n.directives||{}},c!==t)throw Error("App already mounted on this node");return l=G(e,d),c=r.$_REF={ref:l,vnode:e},r.textContent="",V(r,l,t),o.push(d.rerender=(t=e)=>{c.ref=I(r,t,c.vnode,c.ref,d),c.vnode=t})&&d.rerender},e.h=M,e.m=T,e.onRemove=e=>l.push(e),e.redraw=e=>{for(let e=0;e<o.length;e++)o[e]()}}));
|