tangled
alpha
login
or
join now
yippee.fun
/
morphlex
0
fork
atom
Precise DOM morphing
morphing
typescript
dom
0
fork
atom
overview
issues
pulls
pipelines
Remove unused file
joel.drapper.me
4 months ago
4d918c14
0cde519c
-51
1 changed file
expand all
collapse all
unified
split
test-mutations.html
-51
test-mutations.html
···
1
1
-
<!DOCTYPE html>
2
2
-
<html>
3
3
-
<body>
4
4
-
<div id="test"></div>
5
5
-
<script type="module">
6
6
-
import { morph } from './dist/morphlex.min.js';
7
7
-
8
8
-
const observer = new MutationObserver((mutations) => {
9
9
-
console.log(`Total mutations: ${mutations.length}`);
10
10
-
mutations.forEach((m, i) => {
11
11
-
console.log(`Mutation ${i}: type=${m.type}, added=${m.addedNodes.length}, removed=${m.removedNodes.length}`);
12
12
-
});
13
13
-
});
14
14
-
15
15
-
const from = document.createElement('ul');
16
16
-
for (let i = 1; i <= 5; i++) {
17
17
-
const li = document.createElement('li');
18
18
-
li.textContent = `Item ${i}`;
19
19
-
from.appendChild(li);
20
20
-
}
21
21
-
22
22
-
const to = document.createElement('ul');
23
23
-
for (let i = 5; i >= 1; i--) {
24
24
-
const li = document.createElement('li');
25
25
-
li.textContent = `Item ${i}`;
26
26
-
to.appendChild(li);
27
27
-
}
28
28
-
29
29
-
document.getElementById('test').appendChild(from);
30
30
-
31
31
-
observer.observe(from, {
32
32
-
childList: true,
33
33
-
attributes: true,
34
34
-
characterData: true,
35
35
-
subtree: true
36
36
-
});
37
37
-
38
38
-
console.log('Before morph:');
39
39
-
console.log(Array.from(from.children).map(li => li.textContent));
40
40
-
41
41
-
morph(from, to);
42
42
-
43
43
-
console.log('After morph:');
44
44
-
console.log(Array.from(from.children).map(li => li.textContent));
45
45
-
46
46
-
setTimeout(() => {
47
47
-
observer.disconnect();
48
48
-
}, 100);
49
49
-
</script>
50
50
-
</body>
51
51
-
</html>