insertRule method

int insertRule(
  1. String text,
  2. int index, {
  3. required double windowWidth,
  4. required double windowHeight,
  5. required bool isDarkMode,
})

Implementation

int insertRule(
  String text,
  int index, {
  required double windowWidth,
  required double windowHeight,
  required bool isDarkMode,
}) {
  // Parse with this stylesheet's href so relative URLs in inserted rules
  // resolve against the stylesheet URL, not the document URL.
  List<CSSRule> rules = CSSParser(text, href: href)
      .parseRules(windowWidth: windowWidth, windowHeight: windowHeight, isDarkMode: isDarkMode);
  if (index < 0 || index > cssRules.length) {
    throw RangeError.index(index, cssRules, 'index');
  }
  cssRules.insertAll(index, rules);
  for (final rule in rules) {
    _assignParentStyleSheetRecursive(rule, this);
  }
  return index;
}