<commit_before>import 'dart:html';
import 'dart:async';
import 'dart:math' as math;
import 'package:bot/bot.dart';
import 'package:bot_web/bot_html.dart';
import 'package:qr/qr.dart';

void main() {
  final CanvasElement canvas = querySelector("#content");
  final DivElement typeDiv = querySelector('#type-div');
  final DivElement errorDiv = querySelector('#error-div');
  final demo = new QrDemo(canvas, typeDiv, errorDiv);

  final InputElement input = querySelector('#input');

  demo.value = input.value;

  input.onKeyUp.listen((KeyboardEvent args) {
    demo.value = input.value;
  });

  demo.output.listen((data) {
    input.style.background = '';
  }, onError: (error) {
    input.style.background = 'red';
    print(error);
  });
}

class QrDemo{
  static final String _typeRadioIdKey = 'type-value';
  static final String _errorLevelIdKey = 'error-value';
  final BungeeNum _scale;
  final CanvasElement _canvas;
  final ThrottledStream<dynamic, List<bool>> _qrMapper;
  final CanvasRenderingContext2D _ctx;

  String _value = '';
  int _typeNumber = 10;
  int _errorCorrectLevel = QrErrorCorrectLevel.M;

  List<bool> _squares;

  bool _frameRequested = false;

  QrDemo(CanvasElement canvas, DivElement typeDiv, DivElement errorDiv) :
    _canvas = canvas,
    _ctx = canvas.context2D,
    _qrMapper = new ThrottledStream(_calc),
    _scale = new BungeeNum(1) {
    _ctx.fillStyle = 'black';

    _qrMapper.outputStream.listen((args) {
      _squares = _qrMapper.outputValue;
      requestFrame();
    });

    //
    // Type Div
    //
    for(int i = 1; i <= 10; i++) {
      final InputElement radio = new InputElement(type: 'radio');
      radio.id = 'type_$i';
      radio.name = 'type';
      radio.onChange.listen(_levelClick);
      radio.dataset[_typeRadioIdKey] = i.toString();
      if(i == _typeNumber) {
        radio.attributes['checked'] = 'checked';
      }
      typeDiv.children.add(radio);

      final label = new LabelElement();
      label.innerHtml = "$i";
      label.htmlFor = radio.id;
      label.classes.add('btn');
      typeDiv.children.add(label);
    }

    //
    // Error Correct Levels
    //
    for(final v in QrErrorCorrectLevel.levels) {
      final InputElement radio = new InputElement(type: 'radio');
      radio.id = 'error_$v';
      radio.name = 'error-level';
      radio.onChange.listen(_errorClick);
      radio.dataset[_errorLevelIdKey] = v.toString();
      if(v == _errorCorrectLevel) {
        radio.attributes['checked'] = 'checked';
      }
      errorDiv.children.add(radio);

      final label = new LabelElement();
      label.innerHtml = QrErrorCorrectLevel.getName(v);
      label.htmlFor = radio.id;
      label.classes.add('btn');
      errorDiv.children.add(label);
    }
  }

  Stream get output => _qrMapper.outputStream;

  String get value => _value;

  void set value(String input) {
    _value = input;
    _update();
  }

  void requestFrame(){
    if(!_frameRequested) {
      _frameRequested = true;
      window.requestAnimationFrame(_onFrame);
    }
  }

  void _levelClick(Event args) {
    final InputElement source = args.target;
    _typeNumber = int.parse(source.dataset[_typeRadioIdKey]);
    _update();
  }

  void _errorClick(Event args) {
    final InputElement source = args.target;
    _errorCorrectLevel = int.parse(source.dataset[_errorLevelIdKey]);
    _update();<commit_msg>cleanup<commit_after>import 'dart:html';
import 'dart:async';
import 'dart:math' as math;
import 'package:bot/bot.dart';
import 'package:bot_web/bot_html.dart';
import 'package:qr/qr.dart';

void main() {
  final CanvasElement canvas = querySelector("#content");
  final DivElement typeDiv = querySelector('#type-div');
  final DivElement errorDiv = querySelector('#error-div');
  final demo = new QrDemo(canvas, typeDiv, errorDiv);

  final InputElement input = querySelector('#input');

  demo.value = input.value;

  input.onKeyUp.listen((KeyboardEvent args) {
    demo.value = input.value;
  });

  demo.output.listen((data) {
    input.style.background = '';
  }, onError: (error) {
    input.style.background = 'red';
    print(error);
  });
}

class QrDemo{
  static final String _typeRadioIdKey = 'type-value';
  static final String _errorLevelIdKey = 'error-value';
  final BungeeNum _scale;
  final CanvasElement _canvas;
  final ThrottledStream<dynamic, List<bool>> _qrMapper;
  final CanvasRenderingContext2D _ctx;

  String _value = '';
  int _typeNumber = 10;
  int _errorCorrectLevel = QrErrorCorrectLevel.M;

  List<bool> _squares;

  bool _frameRequested = false;

  QrDemo(CanvasElement canvas, DivElement typeDiv, DivElement errorDiv) :
    _canvas = canvas,
    _ctx = canvas.context2D,
    _qrMapper = new ThrottledStream(_calc),
    _scale = new BungeeNum(1) {
    _ctx.fillStyle = 'black';

    _qrMapper.outputStream.listen((args) {
      _squares = _qrMapper.outputValue;
      requestFrame();
    });

    //
    // Type Div
    //
    for(int i = 1; i <= 10; i++) {
      var radio = new InputElement(type: 'radio')
        ..id = 'type_$i'
        ..name = 'type'
        ..onChange.listen(_levelClick)
        ..dataset[_typeRadioIdKey] = i.toString();
      if(i == _typeNumber) {
        radio.attributes['checked'] = 'checked';
      }
      typeDiv.children.add(radio);

      var label = new LabelElement()
        ..innerHtml = "$i"
        ..htmlFor = radio.id
        ..classes.add('btn');
      typeDiv.children.add(label);
    }

    //
    // Error Correct Levels
    //
    for(final v in QrErrorCorrectLevel.levels) {
      var radio = new InputElement(type: 'radio')
        ..id = 'error_$v'
        ..name = 'error-level'
        ..onChange.listen(_errorClick)
        ..dataset[_errorLevelIdKey] = v.toString();
      if(v == _errorCorrectLevel) {
        radio.attributes['checked'] = 'checked';
      }
      errorDiv.children.add(radio);

      var label = new LabelElement()
        ..innerHtml = QrErrorCorrectLevel.getName(v)
        ..htmlFor = radio.id
        ..classes.add('btn');
      errorDiv.children.add(label);
    }
  }

  Stream get output => _qrMapper.outputStream;

  String get value => _value;

  void set value(String input) {
    _value = input;
    _update();
  }

  void requestFrame(){
    if(!_frameRequested) {
      _frameRequested = true;
      window.requestAnimationFrame(_onFrame);
    }
  }

  void _levelClick(Event args) {
    final InputElement source = args.target;
    _typeNumber = int.parse(source.dataset[_typeRadioIdKey]);
    _update();
  }

  void _errorClick(Event args) {
    final InputElement source = args.target;
    _errorCorrectLevel = int.parse(source.dataset[_errorLevelIdKey]);
    _update();
{'fraction_non_alphanumeric': 0.13249400479616308, 'fraction_numerical': 0.002398081534772182, 'mean_word_length': 3.076359193646915, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '6464231', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2110, 'n_words': 443}