preload-platform.ts 645 B

1234567891011121314
  1. /** Marks the document root with the host platform so shared Web UI CSS can scope desktop-only rules. */
  2. /**
  3. * Sets `data-platform` (e.g. `darwin`) on `<html>`, deferring to DOMContentLoaded
  4. * when the preload runs before the document root exists.
  5. */
  6. export function markDocumentPlatform(): void {
  7. const mark = (): void => { document.documentElement.dataset.platform = process.platform }
  8. // lib.dom types documentElement non-null, but a preload runs before the
  9. // document root exists.
  10. const root = document.documentElement as HTMLElement | null
  11. if (root === null) window.addEventListener('DOMContentLoaded', mark)
  12. else mark()
  13. }