message: fix: allow for embedding styles in shadowRoot
diff: @@ -229,6 +229,15 @@ async function loadOpts(opt: EmbedOptions, loader: Loader): Promise<EmbedOptions
  };
  }
  +function getRoot(el: Element) {
  + const possibleRoot = el.getRootNode ? el.getRootNode() : document;
  + if (possibleRoot instanceof ShadowRoot) {
  + return { root: possibleRoot, rootContainer: possibleRoot };
  + } else {
  + return { root: document, rootContainer: document.head ?? document.body };
  + }
  +}
  +
  async function _embed(
  el: HTMLElement | string,
  spec: VisualizationSpec,
  @@ -244,18 +253,23 @@ async function _embed(
  const logLevel = opts.logLevel ?? vega.Warn;
  const downloadFileName = opts.downloadFileName ?? 'visualization';
  + const div = typeof el === 'string' ? document.querySelector(el) : el;
  + if (!div) {
  + throw new Error(`${el} does not exist`);
  + }
  +
  if (opts.defaultStyle !== false) {
  // Add a default stylesheet to the head of the document.
  const ID = 'vega-embed-style';
  - if (!document.getElementById(ID)) {
  + const { root, rootContainer } = getRoot(div);
  + if (!root.getElementById(ID)) {
  const style = document.createElement('style');
  style.id = ID;
  style.innerText =
  opts.defaultStyle === undefined || opts.defaultStyle === true
  ? (embedStyle ?? '').toString()
  : opts.defaultStyle;
  -
  - document.head.appendChild(style);
  + rootContainer.appendChild(style);
  }
  }
  @@ -273,11 +287,6 @@ async function _embed(
  }
  }
  - const div = typeof el === 'string' ? document.querySelector(el) : el;
  - if (!div) {
  - throw Error(`${el} does not exist`);
  - }
  -
  div.classList.add('vega-embed');
  if (actions) {
  div.classList.add('has-actions');
  