<commit_before>import * as akala from '@akala/core';
import * as client from '@akala/client';
import { IconName, IconPrefix } from '@fortawesome/fontawesome-common-types'
import * as fa from '@fortawesome/fontawesome-svg-core'
import '../../assets/css/scss/main.scss';
import tiles from '../../views/tiles.html'

import { Tile, BlockColors, TileDef, FaIconLibraryInterface, bootstrap } from './public_api'

bootstrap.addDependency(akala.module('@domojs/theme-default', client.$$injector.name).activate(['$injector'], function (module: akala.Module)
{
  var list: akala.ObservableArray<TileDef> = new akala.ObservableArray<TileDef>([]);

  module.register('tiles', {
    add(tile: TileDef)
    {
      list.push(tile);
    },
    array: list
  })

  module.register('bootstrap', []);

  @akala.module('@domojs/theme-default').service('faIcon')
  class FaIconLibrary implements FaIconLibraryInterface
  {
    private definitions: { [prefix: string]: { [name: string]: fa.IconDefinition } } = {};

    addIcons(...icons: fa.IconDefinition[])
    {
      for (const icon of icons)
      {
        if (!(icon.prefix in this.definitions))
        {
          this.definitions[icon.prefix] = {};
        }
        this.definitions[icon.prefix][icon.iconName] = icon;
      }
    }

    addIconPacks(...packs: fa.IconPack[])
    {
      for (const pack of packs)
      {
        const icons = Object.keys(pack).map((key) => pack[key]);
        this.addIcons(...icons);
      }
    }

    getIconDefinition(prefix: IconPrefix, name: IconName): fa.IconDefinition | null
    {
      if (prefix in this.definitions && name in this.definitions[prefix])
      {
        return this.definitions[prefix][name];
      }
      return null;
    }
  }

  @client.control('@domojs/theme-default.faIcon')
  class FA extends client.BaseControl<fa.IconLookup>
  {
    constructor(private library: FaIconLibraryInterface)
    {
      super('fa');
    }

    public apply(scope: any, element: Element, parameter: fa.IconLookup | akala.Proxy<fa.IconLookup, akala.Binding>): any
    {
      if (typeof parameter !== 'undefined')
      {
        if (parameter.prefix instanceof akala.Binding || parameter.iconName instanceof akala.Binding)
          return this.apply(scope, element, akala.Binding.unbindify(parameter) as fa.IconLookup);
      }

      element.innerHTML = fa.icon(this.library.getIconDefinition(parameter.prefix as fa.IconPrefix, parameter.iconName as fa.IconName)).html.join('\n')
    }
  }

  @client.control()
  class BlockColor extends client.BaseControl<string>
  {
    constructor()
    {
      super('color');
    }

    public apply(_scope: client.IScope<any>, element: Element, parameter?: string): any
    {
      if (typeof parameter == 'undefined')
        parameter = BlockColors[Math.floor(Math.random() * Object.keys(BlockColors).length / 2)];
      element.classList.add('block-' + parameter);
    }
  }

  module.ready(['akala-services.$part'], function (part: client.Part)
  {
    part.use('/', 'body', {
      template: tiles, controller: function (scope)
      {
        scope['list'] = list;

        scope['tileClick'] = function (tile: Tile, $location: client.LocationService, $http: akala.Http)
        {
          if (tile.url)
            if (akala.isPromiseLike(tile.url))
              tile.url.then(function (url) { $location.show(url) });
            else
              $location.show(tile.url);
          if (tile.cmd)
            $http.get(tile.cmd)
        }
        scope['tileClick'].$inject = ['tile', '$modules.akala-services.$location', '$http'];

      }
    });
  });
}));


var domReady = function (callback)
{
  document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback);
};
domReady(function ()
{
  bootstrap.start();
});<commit_msg>now supporting icons as plain icons<commit_after>import * as akala from '@akala/core';
import * as client from '@akala/client';
import { IconName, IconPrefix } from '@fortawesome/fontawesome-common-types'
import * as fa from '@fortawesome/fontawesome-svg-core'
import '../../assets/css/scss/main.scss';
import tiles from '../../views/tiles.html'

import { Tile, BlockColors, TileDef, FaIconLibraryInterface, bootstrap } from './public_api'

bootstrap.addDependency(akala.module('@domojs/theme-default', client.$$injector.name).activate(['$injector'], function (module: akala.Module)
{
  var list: akala.ObservableArray<TileDef> = new akala.ObservableArray<TileDef>([]);

  module.register('tiles', {
    add(tile: TileDef)
    {
      list.push(tile);
    },
    array: list
  })

  module.register('bootstrap', []);

  @akala.module('@domojs/theme-default').service('faIcon')
  class FaIconLibrary implements FaIconLibraryInterface
  {
    private definitions: { [prefix: string]: { [name: string]: fa.IconDefinition } } = {};

    addIcons(...icons: fa.IconDefinition[])
    {
      for (const icon of icons)
      {
        if (!(icon.prefix in this.definitions))
        {
          this.definitions[icon.prefix] = {};
        }
        this.definitions[icon.prefix][icon.iconName] = icon;
      }
    }

    addIconPacks(...packs: fa.IconPack[])
    {
      for (const pack of packs)
      {
        const icons = Object.keys(pack).map((key) => pack[key]);
        this.addIcons(...icons);
      }
    }

    getIconDefinition(prefix: IconPrefix, name: IconName): fa.IconDefinition | null
    {
      if (prefix in this.definitions && name in this.definitions[prefix])
      {
        return this.definitions[prefix][name];
      }
      return null;
    }
  }

  @client.control('@domojs/theme-default.faIcon')
  class FA extends client.BaseControl<fa.IconLookup | fa.IconDefinition>
  {
    constructor(private library: FaIconLibraryInterface)
    {
      super('fa');
    }

    public apply(scope: any, element: Element, parameter: fa.IconLookup | fa.IconDefinition | akala.Proxy<fa.IconLookup, akala.Binding>): any
    {
      if (typeof parameter !== 'undefined')
      {
        if (parameter.prefix instanceof akala.Binding || parameter.iconName instanceof akala.Binding)
          return this.apply(scope, element, akala.Binding.unbindify(parameter) as fa.IconLookup);
      }

      if (typeof parameter['icon'] != 'undefined')
        element.innerHTML = fa.icon(parameter['icon']).html.join('\n');
      else
        element.innerHTML = fa.icon(this.library.getIconDefinition(parameter.prefix as fa.IconPrefix, parameter.iconName as fa.IconName)).html.join('\n')
    }
  }

  @client.control()
  class BlockColor extends client.BaseControl<string>
  {
    constructor()
    {
      super('color');
    }

    public apply(_scope: client.IScope<any>, element: Element, parameter?: string): any
    {
      if (typeof parameter == 'undefined')
        parameter = BlockColors[Math.floor(Math.random() * Object.keys(BlockColors).length / 2)];
      element.classList.add('block-' + parameter);
    }
  }

  module.ready(['akala-services.$part'], function (part: client.Part)
  {
    part.use('/', 'body', {
      template: tiles, controller: function (scope)
      {
        scope['list'] = list;

        scope['tileClick'] = function (tile: Tile, $location: client.LocationService, $http: akala.Http)
        {
          if (tile.url)
            if (akala.isPromiseLike(tile.url))
              tile.url.then(function (url) { $location.show(url) });
            else
              $location.show(tile.url);
          if (tile.cmd)
            $http.get(tile.cmd)
        }
        scope['tileClick'].$inject = ['tile', '$modules.akala-services.$location', '$http'];

      }
    });
  });
}));


var domReady = function (callback)
{
  document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback);
};
domReady(function ()
{
  bootstrap.start();
});
{'fraction_non_alphanumeric': 0.14965069248682436, 'fraction_numerical': 0.00024512807942149775, 'mean_word_length': 2.6282792352156514, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '5989777', 'n_tokens_mistral': 2480, 'n_tokens_neox': 2405, 'n_words': 462}