<commit_before>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:html';

import 'package:angular/angular.dart';
import 'package:angular_components/laminate/overlay/constants.dart';
import 'package:angular_components/src/laminate/overlay/overlay_service.dart';
import 'package:angular_components/src/laminate/overlay/render/overlay_dom_render_service.dart';
import 'package:angular_components/src/laminate/overlay/render/overlay_style_config.dart';
import 'package:angular_components/laminate/overlay/zindexer.dart';
import 'package:angular_components/laminate/ruler/dom_ruler.dart';
import 'package:angular_components/utils/angular/imperative_view/imperative_view.dart';
import 'package:angular_components/utils/angular/managed_zone/angular_2.dart';
import 'package:angular_components/utils/browser/dom_service/angular_2.dart';
import 'package:angular_components/utils/browser/window/module.dart';

export 'package:angular_components/src/laminate/overlay/render/overlay_dom_render_service.dart'
    show
        overlayContainerName,
        overlayContainerParent,
        overlayContainerToken,
        overlayRepositionLoop,
        overlaySyncDom;

/// Either finds, or creates an "acx-overlay-container" div at the end of body.
@Injectable()
HtmlElement getDefaultContainer(
    @Inject(overlayContainerName) String name,
    @Inject(overlayContainerParent) HtmlElement parent,
    @Optional() @SkipSelf() @Inject(overlayContainerToken) container) {
  if (container != null) return container;

  var element = parent.querySelector('#$overlayDefaultContainerId');
  if (element == null) {
    // Add a hidden focusable element before overlay container to prevent screen
    // reader from picking up content from a random element when users shift tab
    // out of the first visible overlay.
    parent.append(DivElement()
      ..tabIndex = 0
      ..classes.add(overlayFocusablePlaceholderClassName));

    element = DivElement()
      ..id = overlayDefaultContainerId
      ..classes.add(overlayContainerClassName);
    parent.append(element);

    // Add a hidden focusable element after overlay container to ensure there's
    // a focusable element when users tab out of the last visible overlay.
    parent.append(DivElement()
      ..tabIndex = 0
      ..classes.add(overlayFocusablePlaceholderClassName));
  }
  element.attributes[overlayContainerNameAttribute] = name;
  return element;
}

@Injectable()
String getDefaultContainerName(
    @Optional() @SkipSelf() @Inject(overlayContainerName) containerName) {
  return containerName ?? 'default';
}

/// Returns an overlay container with debugging aid enabled.
@Injectable()
HtmlElement getDebugContainer(@Inject(overlayContainerName) String name,<commit_msg>Add method to create an accessible overlay container for clients that currently provide custom overlay container.<commit_after>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:html';

import 'package:angular/angular.dart';
import 'package:meta/meta.dart';
import 'package:angular_components/laminate/overlay/constants.dart';
import 'package:angular_components/src/laminate/overlay/overlay_service.dart';
import 'package:angular_components/src/laminate/overlay/render/overlay_dom_render_service.dart';
import 'package:angular_components/src/laminate/overlay/render/overlay_style_config.dart';
import 'package:angular_components/laminate/overlay/zindexer.dart';
import 'package:angular_components/laminate/ruler/dom_ruler.dart';
import 'package:angular_components/utils/angular/imperative_view/imperative_view.dart';
import 'package:angular_components/utils/angular/managed_zone/angular_2.dart';
import 'package:angular_components/utils/browser/dom_service/angular_2.dart';
import 'package:angular_components/utils/browser/window/module.dart';

export 'package:angular_components/src/laminate/overlay/render/overlay_dom_render_service.dart'
    show
        overlayContainerName,
        overlayContainerParent,
        overlayContainerToken,
        overlayRepositionLoop,
        overlaySyncDom;

/// Creates an overlay container inside the [parent] if one does not exist
/// already.
/// A hidden focusable element is inserted before and after the overlay
/// container to support a11y features.
HtmlElement createAcxOverlayContainer(HtmlElement parent,
    {@required String id, @required String name, String className}) {
  var container = parent.querySelector('#$id');
  if (container == null) {
    // Add a hidden focusable element before overlay container to prevent screen
    // reader from picking up content from a random element when users shift tab
    // out of the first visible overlay.
    parent.append(DivElement()
      ..tabIndex = 0
      ..classes.add(overlayFocusablePlaceholderClassName));

    container = DivElement()
      ..id = id
      ..classes.add(overlayContainerClassName);
    if (className != null) container.classes.add(className);
    parent.append(container);

    // Add a hidden focusable element after overlay container to ensure there's
    // a focusable element when users tab out of the last visible overlay.
    parent.append(DivElement()
      ..tabIndex = 0
      ..classes.add(overlayFocusablePlaceholderClassName));
  }
  container.attributes[overlayContainerNameAttribute] = name;
  return container;
}

/// Either finds, or creates an "acx-overlay-container" div at the end of body.
@Injectable()
HtmlElement getDefaultContainer(
    @Inject(overlayContainerName) String name,
    @Inject(overlayContainerParent) HtmlElement parent,
    @Optional() @SkipSelf() @Inject(overlayContainerToken) container) {
  if (container != null) return container;
  return createAcxOverlayContainer(parent,
      id: overlayDefaultContainerId, name: name);
}

@Injectable()
String getDefaultContainerName(
    @Optional() @SkipSelf() @Inject(overlayContainerName) containerName) {
  return containerName ?? 'default';
}

/// Returns an overlay container with debugging aid enabled.
@Injectable()
HtmlElement getDebugContainer(@Inject(overlayContainerName) String name,
{'fraction_non_alphanumeric': 0.09513378188076983, 'fraction_numerical': 0.002816460647785949, 'mean_word_length': 4.885819521178637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5445396', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1700, 'n_words': 464}