<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:async';
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:quiver/time.dart';
import 'package:angular_components/utils/angular/properties/properties.dart';
import 'package:angular_components/utils/angular/scroll_host/interface.dart';
import 'package:angular_components/src/utils/angular/scroll_host/gestures.dart';
import 'package:angular_components/src/utils/angular/scroll_host/scroll_host_base.dart';
import 'package:angular_components/src/utils/angular/scroll_host/scroll_host_interface.dart';
import 'package:angular_components/utils/browser/dom_service/angular_2.dart';

export 'package:angular_components/src/utils/angular/scroll_host/scroll_host_interface.dart'
    show ScrollHost;

const clockValue = Clock();

const scrollHostProviders = <Provider>[
  ClassProvider(ScrollHost, useClass: WindowScrollHost),
  ValueProvider(Clock, clockValue),
  ClassProvider(GestureListenerFactory),
];
@Deprecated('Use [scrollHostProviders] or [scrollHostNewModule]')
const scrollHostModule = scrollHostProviders;

const scrollHostNewModule = Module(
  provide: scrollHostProviders,
);

/// Provides a scroll host that is restricted within the content area of
/// a specific element.
@Directive(
  selector: '[acxScrollHost]',
  providers: [
    Provider(ScrollHost, useExisting: ElementScrollHost),
    Provider(Clock, useValue: clockValue),
    GestureListenerFactory,
  ],
  exportAs: 'acxScrollHost',
  visibility: Visibility.all, // injected
)
class ElementScrollHost implements OnInit, OnDestroy, ElementScrollHostBase {
  final DomService _domService;
  final NgZone _ngZone;
  final HtmlElement element;
  final GestureListenerFactory _gestureListenerFactory;

  ElementScrollHostBase _scrollHost;

  bool _disableAutoScroll;
  bool _usePositionSticky = false;
  bool _enableSmoothPushing = false;

  ElementScrollHost(this._domService, this._ngZone,
      this._gestureListenerFactory, this.element);

  @override
  void ngOnInit() {
    _init();
  }

  void _init() {
    _scrollHost?.dispose();
    _scrollHost = ElementScrollHostBase(
        _domService, _ngZone, _gestureListenerFactory, element,
        usePositionSticky: _usePositionSticky);
    stickyController.enableSmoothPushing = _enableSmoothPushing;
  }

  @Input()
  set disableAutoScroll(bool value) {
    if (value != _disableAutoScroll) {
      _disableAutoScroll = value;
      _domService.scheduleWrite(() {
        element.style.overflowY = value ? 'scroll' : 'auto';
      });
    }
  }

  /// If enabled, smoothly push colliding elements which share a stickyKey,<commit_msg>Clean up ScrollHost docs a little.<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:async';
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:quiver/time.dart';
import 'package:angular_components/utils/angular/properties/properties.dart';
import 'package:angular_components/utils/angular/scroll_host/interface.dart';
import 'package:angular_components/src/utils/angular/scroll_host/gestures.dart';
import 'package:angular_components/src/utils/angular/scroll_host/scroll_host_base.dart';
import 'package:angular_components/src/utils/angular/scroll_host/scroll_host_interface.dart';
import 'package:angular_components/utils/browser/dom_service/angular_2.dart';

export 'package:angular_components/src/utils/angular/scroll_host/scroll_host_interface.dart'
    show ScrollHost;

const clockValue = Clock();

const scrollHostProviders = <Provider>[
  ClassProvider(ScrollHost, useClass: WindowScrollHost),
  ValueProvider(Clock, clockValue),
  ClassProvider(GestureListenerFactory),
];
@Deprecated('Use [scrollHostProviders] or [scrollHostNewModule]')
const scrollHostModule = scrollHostProviders;

const scrollHostNewModule = Module(
  provide: scrollHostProviders,
);

/// Provides a scroll host that is restricted within the content area of
/// a specific element.
@Directive(
  selector: '[acxScrollHost]',
  providers: [
    Provider(ScrollHost, useExisting: ElementScrollHost),
    Provider(Clock, useValue: clockValue),
    GestureListenerFactory,
  ],
  exportAs: 'acxScrollHost',
  visibility: Visibility.all, // injected
)
class ElementScrollHost implements OnInit, OnDestroy, ElementScrollHostBase {
  final DomService _domService;
  final NgZone _ngZone;
  final HtmlElement element;
  final GestureListenerFactory _gestureListenerFactory;

  ElementScrollHostBase _scrollHost;

  bool _disableAutoScroll;
  bool _usePositionSticky = false;
  bool _enableSmoothPushing = false;

  ElementScrollHost(this._domService, this._ngZone,
      this._gestureListenerFactory, this.element);

  @override
  void ngOnInit() {
    _init();
  }

  void _init() {
    _scrollHost?.dispose();
    _scrollHost = ElementScrollHostBase(
        _domService, _ngZone, _gestureListenerFactory, element,
        usePositionSticky: _usePositionSticky);
    stickyController.enableSmoothPushing = _enableSmoothPushing;
  }

  /// If true, forces a vertical scrollbar to appear even if the contents are
  /// not long enough to normally trigger a scrollbar.
  ///
  /// Works by setting `overflow-y` to `scroll` on the attached element.
  /// If false, `overflow-y` is set to `auto`.
  ///
  /// This avoids a re-layout in cases where the content of the scroll area is
  /// loaded dynamically, thus improving performance slightly.
  @Input()
  set disableAutoScroll(bool value) {
    if (value != _disableAutoScroll) {
      _disableAutoScroll = value;
      _domService.scheduleWrite(() {
        element.style.overflowY = value ? 'scroll' : 'auto';
      });
    }
  }

  /// If enabled, smoothly push colliding elements which share a stickyKey,
{'fraction_non_alphanumeric': 0.0969706947645703, 'fraction_numerical': 0.0016463615409944023, 'mean_word_length': 4.886627906976744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6805708', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1738, 'n_words': 440}