<commit_before>import * as ko from 'knockout';
import {Container, inject} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
import {ViewSlot, CompositionEngine} from 'aurelia-templating';


function endsWith(s: string, suffix: string): boolean {
  return s.indexOf(suffix, s.length - suffix.length) !== -1;
}

function getMatchingProperty(result: any, propName: string): string|null {
  const properties: string[] = Object.keys(result);
  for (let index: number = 0; index < properties.length; index++) {
    const prop: string = properties[index].toLowerCase();
    if (prop.indexOf(propName) !== -1) {
      return properties[index];
    }
  }

  return null;
}

function callEvent(element: Element, eventName: string, args: any): void {
  const viewModel: any = ko.dataFor(element.children[0]);

  const func: Function = viewModel[eventName];

  if (func && typeof func === 'function') {
    func.apply(viewModel, args);
  }
}

function doComposition(element: Element, unwrappedValue: any, viewModel: any): void {
  this.buildCompositionSettings(unwrappedValue, viewModel).then((settings: any): void => {
    composeElementInstruction.call(this, element, settings).then((): void => {
      callEvent(element, 'compositionComplete', [element, element.parentElement]);
    });
  });
}
<commit_msg>fix: use first bound element instead of first array element<commit_after>import * as ko from 'knockout';
import {Container, inject} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
import {ViewSlot, CompositionEngine} from 'aurelia-templating';


function endsWith(s: string, suffix: string): boolean {
  return s.indexOf(suffix, s.length - suffix.length) !== -1;
}

function getMatchingProperty(result: any, propName: string): string|null {
  const properties: string[] = Object.keys(result);
  for (let index: number = 0; index < properties.length; index++) {
    const prop: string = properties[index].toLowerCase();
    if (prop.indexOf(propName) !== -1) {
      return properties[index];
    }
  }

  return null;
}

function getAuTarget(elements: HTMLCollection): Element | null {
  for (let i = 0; i < elements.length; i++) {
    if (elements.item(i)?.classList.contains("au-target")) {
      return elements.item(i);
    }
  }

  return null;
}

function callEvent(element: Element, eventName: string, args: any): void {
  const target: Element | null = getAuTarget(element.children);

  if (target) {
    const viewModel: any = ko.dataFor(target);
    const func: Function = viewModel[eventName];

    if (func && typeof func === 'function') {
      func.apply(viewModel, args);
    }
  }
}

function doComposition(element: Element, unwrappedValue: any, viewModel: any): void {
  this.buildCompositionSettings(unwrappedValue, viewModel).then((settings: any): void => {
    composeElementInstruction.call(this, element, settings).then((): void => {
      callEvent(element, 'compositionComplete', [element, element.parentElement]);
    });
  });
}

{'fraction_non_alphanumeric': 0.14399733954107083, 'fraction_numerical': 0.002660458929165281, 'mean_word_length': 4.611940298507463, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '2616535', 'n_tokens_mistral': 918, 'n_tokens_neox': 898, 'n_words': 238}