dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.24k stars 1.57k forks source link

html.window.getComputedStyleMap, is not defined #35048

Open ghost opened 6 years ago

ghost commented 6 years ago
html.window.getComputedStyleMap(html.querySelector('#test'),'');

Gives error:

Uncaught TypeError: window.getComputedStyleMap is not a function
    at Object.main (index.dart:4)

As per MDN docs, html.window.getComputedStyleMap() should be replaced with window.getComputedStyle().

https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

At the moment window.getComputedStyle() is not available in dart:html package.

dart sdk version: 2.0.0

Chromium version: Version 70.0.3538.67 (Official Build) Arch Linux (64-bit)

natebosch commented 5 years ago

Here is a potential workaround but I have not tested it extensively...

Iterable<CssStyleRule> findStyles(Element element) sync* {
  for (final sheet in document.styleSheets.whereType<CssStyleSheet>()) {
    if (sheet.disabled) continue;
    if (!window.matchMedia(sheet.media.mediaText).matches) continue;
    for(final rule in sheet.cssRules.whereType<CssStyleRule>()) {
      if (element.matches(rule.selectorText)) yield rule;
    }
  }
}