shadow-dom.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  5. </head>
  6. <body>
  7. <h2>Monaco Editor Shadow DOM</h2>
  8. <div style="clear: both"></div>
  9. <div
  10. id="container"
  11. style="float: left; width: 800px; height: 450px; border: 1px solid grey"
  12. ></div>
  13. <div style="clear: both"></div>
  14. <script src="dev-setup.js"></script>
  15. <script>
  16. const container = document.getElementById('container');
  17. const shadowRoot = container.attachShadow({
  18. mode: 'closed'
  19. });
  20. loadEditor(function () {
  21. const innerContainer = document.createElement('div');
  22. shadowRoot.appendChild(innerContainer);
  23. innerContainer.style.width = '800px';
  24. innerContainer.style.height = '450px';
  25. // We must move all CSS inside the shadow root, pick only link tags relevant to the editor
  26. const documentLinks = Array.prototype.slice
  27. .call(document.getElementsByTagName('link'), 0)
  28. .filter((documentLink) => {
  29. if (/vs\/(base|editor|platform)/.test(documentLink.getAttribute('href'))) {
  30. return true;
  31. }
  32. console.log(`Not moving: `, documentLink);
  33. return true;
  34. });
  35. documentLinks.forEach((documentLink) => shadowRoot.appendChild(documentLink));
  36. // We must define the font face outside the shadowroot
  37. const codiconCSS = `@font-face { font-family: "codicon"; src: url("${getCodiconPath()}") format("truetype"); }`;
  38. const style = document.createElement('style');
  39. style.type = 'text/css';
  40. style.media = 'screen';
  41. document.getElementsByTagName('head')[0].appendChild(style);
  42. style.innerHTML = codiconCSS;
  43. monaco.editor.create(innerContainer, {
  44. value: ['function hello() {', '\tconsole.log("hello world");', '}', ''].join('\n'),
  45. language: 'javascript',
  46. ariaContainerElement: innerContainer
  47. });
  48. });
  49. </script>
  50. </body>
  51. </html>