|
1 | 1 | /* eslint-disable no-var, key-spacing, object-curly-spacing, prefer-arrow-callback, semi, keyword-spacing */
|
2 | 2 |
|
3 |
| -function initPreactIslandElement() { |
4 |
| - class PreactIslandElement extends HTMLElement { |
5 |
| - connectedCallback() { |
6 |
| - var d = this; |
7 |
| - if (!d.isConnected) return; |
8 |
| - |
9 |
| - let i = this.getAttribute('data-target'); |
10 |
| - if (!i) return; |
11 |
| - |
12 |
| - var s, |
13 |
| - e, |
14 |
| - c = document.createNodeIterator(document, 128); |
15 |
| - while (c.nextNode()) { |
16 |
| - let n = c.referenceNode; |
17 |
| - |
18 |
| - if (n.data == 'preact-island:' + i) s = n; |
19 |
| - else if (n.data == '/preact-island:' + i) e = n; |
20 |
| - if (s && e) break; |
21 |
| - } |
22 |
| - if (s && e) { |
23 |
| - var p = e.previousSibling; |
24 |
| - while (p != s) { |
25 |
| - if (!p || p == s) break; |
26 |
| - e.parentNode.removeChild(p); |
27 |
| - p = e.previousSibling; |
28 |
| - } |
29 |
| - |
30 |
| - requestAnimationFrame(() => { |
31 |
| - for (let i = 0; i <= d.children.length; i++) { |
32 |
| - const child = d.children[i]; |
33 |
| - e.parentNode.insertBefore(child, e); |
34 |
| - } |
35 |
| - |
36 |
| - d.parentNode.removeChild(d); |
37 |
| - }); |
38 |
| - } |
39 |
| - } |
40 |
| - } |
41 |
| - |
42 |
| - customElements.define('preact-island', PreactIslandElement); |
43 |
| -} |
44 |
| - |
45 |
| -const fn = initPreactIslandElement.toString(); |
46 |
| -const INIT_SCRIPT = fn |
47 |
| - .slice(fn.indexOf('{') + 1, fn.lastIndexOf('}')) |
48 |
| - .replace(/\n\s+/gm, ''); |
| 3 | +// function initPreactIslandElement() { |
| 4 | +// class PreactIslandElement extends HTMLElement { |
| 5 | +// connectedCallback() { |
| 6 | +// var d = this; |
| 7 | +// if (!d.isConnected) return; |
| 8 | + |
| 9 | +// let i = this.getAttribute('data-target'); |
| 10 | +// if (!i) return; |
| 11 | + |
| 12 | +// var s, |
| 13 | +// e, |
| 14 | +// c = document.createNodeIterator(document, 128); |
| 15 | +// while (c.nextNode()) { |
| 16 | +// let n = c.referenceNode; |
| 17 | + |
| 18 | +// if (n.data == 'preact-island:' + i) s = n; |
| 19 | +// else if (n.data == '/preact-island:' + i) e = n; |
| 20 | +// if (s && e) break; |
| 21 | +// } |
| 22 | +// if (s && e) { |
| 23 | +// requestAnimationFrame(() => { |
| 24 | +// var p = e.previousSibling; |
| 25 | +// while (p != s) { |
| 26 | +// if (!p || p == s) break; |
| 27 | +// e.parentNode.removeChild(p); |
| 28 | +// p = e.previousSibling; |
| 29 | +// } |
| 30 | + |
| 31 | +// c = s; |
| 32 | +// while (d.firstChild) { |
| 33 | +// s = d.firstChild; |
| 34 | +// d.removeChild(s); |
| 35 | +// c.after(s); |
| 36 | +// c = s; |
| 37 | +// } |
| 38 | + |
| 39 | +// d.parentNode.removeChild(d); |
| 40 | +// }); |
| 41 | +// } |
| 42 | +// } |
| 43 | +// } |
| 44 | + |
| 45 | +// customElements.define('preact-island', PreactIslandElement); |
| 46 | +// } |
| 47 | + |
| 48 | +// To modify the INIT_SCRIPT, uncomment the above code, modify it, and paste it into https://try.terser.org/. |
| 49 | +const INIT_SCRIPT = `class e extends HTMLElement{connectedCallback(){var e=this;if(!e.isConnected)return;let t=this.getAttribute("data-target");if(t){for(var r,a,i=document.createNodeIterator(document,128);i.nextNode();){let e=i.referenceNode;if(e.data=="preact-island:"+t?r=e:e.data=="/preact-island:"+t&&(a=e),r&&a)break}r&&a&&requestAnimationFrame((()=>{for(var t=a.previousSibling;t!=r&&t&&t!=r;)a.parentNode.removeChild(t),t=a.previousSibling;for(i=r;e.firstChild;)r=e.firstChild,e.removeChild(r),i.after(r),i=r;e.parentNode.removeChild(e)}))}}}customElements.define("preact-island",e);`; |
49 | 50 |
|
50 | 51 | export function createInitScript() {
|
51 | 52 | return `<script>(function(){${INIT_SCRIPT}}())</script>`;
|
|
0 commit comments