<commit_before>import 'dart:html' show DocumentFragment, NodeTreeSanitizer;

import 'package:angular/di.dart' show Injectable, Inject;
import 'package:angular/src/core/application_tokens.dart' show APP_ID;
import 'package:angular/src/core/change_detection/change_detection.dart'
    show devModeEqual;
import 'package:angular/src/core/metadata/view.dart' show ViewEncapsulation;
import 'package:angular/src/core/render/api.dart' show RenderComponentType;
import 'package:angular/src/core/security.dart';
import 'package:angular/src/platform/dom/events/event_manager.dart'
    show EventManager;
import 'package:angular/src/runtime.dart';
import 'package:meta/dart2js.dart' as dart2js;

import 'exceptions.dart' show ExpressionChangedAfterItHasBeenCheckedException;

/// Application wide view utilities.
AppViewUtils appViewUtils;

/// Utilities to create unique RenderComponentType instances for AppViews and
/// provide access to root dom renderer.
@Injectable()
class AppViewUtils {
  final String _appId;
  EventManager eventManager;
  static int _nextCompTypeId = 0;

  /// Whether change detection should throw an exception when a change is
  /// detected.
  ///
  /// Latency sensitive! Used by checkBinding during change detection.
  static bool get throwOnChanges => isDevMode && _throwOnChanges;
  static set throwOnChanges(bool value) => _throwOnChanges = value;
  static bool _throwOnChanges = false;
  static int _throwOnChangesCounter = 0;

  SanitizationService sanitizer;

  AppViewUtils(@Inject(APP_ID) this._appId, this.sanitizer, this.eventManager);

  /// Used by the generated code to initialize and share common rendering data
  /// such as css across instances.
  @dart2js.noInline
  RenderComponentType createRenderType(
      String templateUrl,
      ViewEncapsulation encapsulation,
      List<dynamic /* String | List < dynamic > */ > styles) {
    return RenderComponentType(
        '$_appId-${_nextCompTypeId++}', templateUrl, encapsulation, styles);
  }

  /// Enters execution mode that will throw exceptions if any binding
  /// has been updated since last change detection cycle.
  ///
  /// Used by Developer mode and Test beds to validate that bindings are
  /// stable.
  static void enterThrowOnChanges() {
    _throwOnChangesCounter++;
    throwOnChanges = true;
  }

  /// Exits change detection check mode.
  ///
  /// Used by Developer mode and Test beds to validate that bindings are
  /// stable.
  static void exitThrowOnChanges() {
    _throwOnChangesCounter--;
    throwOnChanges = _throwOnChangesCounter != 0;
  }

  /// Used in tests that cause exceptions on purpose.
  static void resetChangeDetection() {
    _throwOnChangesCounter = 0;
    throwOnChanges = false;
  }
}

/// Creates a document fragment from [trustedHtml].
DocumentFragment createTrustedHtml(String trustedHtml) {
  return DocumentFragment.html(
    trustedHtml,
    treeSanitizer: NodeTreeSanitizer.trusted,
  );
}

/// Flattens a `List<List<?>>` into a `List<?>`.<commit_msg>refactor(Core): Make EventManager, SanitizationService, final.<commit_after>import 'dart:html' show DocumentFragment, NodeTreeSanitizer;

import 'package:angular/di.dart' show Injectable, Inject;
import 'package:angular/src/core/application_tokens.dart' show APP_ID;
import 'package:angular/src/core/change_detection/change_detection.dart'
    show devModeEqual;
import 'package:angular/src/core/metadata/view.dart' show ViewEncapsulation;
import 'package:angular/src/core/render/api.dart' show RenderComponentType;
import 'package:angular/src/core/security.dart';
import 'package:angular/src/platform/dom/events/event_manager.dart'
    show EventManager;
import 'package:angular/src/runtime.dart';
import 'package:meta/dart2js.dart' as dart2js;

import 'exceptions.dart' show ExpressionChangedAfterItHasBeenCheckedException;

/// Application wide view utilities.
AppViewUtils appViewUtils;

/// Utilities to create unique RenderComponentType instances for AppViews and
/// provide access to root dom renderer.
@Injectable()
class AppViewUtils {
  final String _appId;
  final EventManager eventManager;
  final SanitizationService sanitizer;
  static int _nextCompTypeId = 0;

  /// Whether change detection should throw an exception when a change is
  /// detected.
  ///
  /// Latency sensitive! Used by checkBinding during change detection.
  static bool get throwOnChanges => isDevMode && _throwOnChanges;
  static bool _throwOnChanges = false;
  static int _throwOnChangesCounter = 0;

  AppViewUtils(@Inject(APP_ID) this._appId, this.sanitizer, this.eventManager);

  /// Used by the generated code to initialize and share common rendering data
  /// such as css across instances.
  @dart2js.noInline
  RenderComponentType createRenderType(
      String templateUrl,
      ViewEncapsulation encapsulation,
      List<dynamic /* String | List < dynamic > */ > styles) {
    return RenderComponentType(
        '$_appId-${_nextCompTypeId++}', templateUrl, encapsulation, styles);
  }

  /// Enters execution mode that will throw exceptions if any binding
  /// has been updated since last change detection cycle.
  ///
  /// Used by Developer mode and Test beds to validate that bindings are
  /// stable.
  static void enterThrowOnChanges() {
    _throwOnChangesCounter++;
    _throwOnChanges = true;
  }

  /// Exits change detection check mode.
  ///
  /// Used by Developer mode and Test beds to validate that bindings are
  /// stable.
  static void exitThrowOnChanges() {
    _throwOnChangesCounter--;
    _throwOnChanges = _throwOnChangesCounter != 0;
  }

  /// Used in tests that cause exceptions on purpose.
  static void resetChangeDetection() {
    _throwOnChangesCounter = 0;
    _throwOnChanges = false;
  }
}

/// Creates a document fragment from [trustedHtml].
DocumentFragment createTrustedHtml(String trustedHtml) {
  return DocumentFragment.html(
    trustedHtml,
    treeSanitizer: NodeTreeSanitizer.trusted,
  );
}

/// Flattens a `List<List<?>>` into a `List<?>`.
{'fraction_non_alphanumeric': 0.09490392648287385, 'fraction_numerical': 0.0023391812865497076, 'mean_word_length': 4.155900086132644, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3217987', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1690, 'n_words': 505}