1 | <script src="./index.js"></script>
|
2 | <script>
|
3 | function __ssr () {
|
4 | const script = document.currentScript;
|
5 | const host = script.previousElementSibling;
|
6 | const fakeShadowRoot = host.firstElementChild;
|
7 |
|
8 |
|
9 |
|
10 | script.parentNode.removeChild(script);
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | host.attachShadow({ mode: 'open' }).innerHTML = fakeShadowRoot.innerHTML;
|
20 | }
|
21 | </script>
|
22 | <script>
|
23 | test(a => {
|
24 | const frag = document.createDocumentFragment();
|
25 | const div = document.createElement('div');
|
26 | const script = document.createElement('script');
|
27 |
|
28 | div.innerHTML = `<shadow-root><strong><slot></slot></strong></shadow-root>${a}`;
|
29 | script.innerHTML = `__ssr();`;
|
30 |
|
31 | frag.appendChild(div);
|
32 | frag.appendChild(script);
|
33 |
|
34 | return frag;
|
35 | });
|
36 | </script>
|