<commit_before>'use strict';

import { Env } from '../../lib/env';
import { qps } from '../../lib/pseudo';
import { L10nError } from '../../lib/errors';
import { getResourceLinks } from '../../bindings/html/head';
import { translateFragment } from '../../bindings/html/dom';
import { getDirection } from '../../bindings/html/langs';
import { serializeEntries } from '../../bindings/gaiabuild/serialize';

export class View {
  constructor(htmloptimizer, fetch) {
    this.env = new Env(
      htmloptimizer.config.GAIA_DEFAULT_LOCALE, fetch);
    this.doc = htmloptimizer.win.document;
    this.ctx = this.env.createContext(getResourceLinks(this.doc.head));
  }

  observe() {}
  disconnect() {}

  translate(code) {
    let dir = getDirection(code);
    let langs = [{ code, dir, src: 'app' }];
    let setDocLang = () => {
      this.doc.documentElement.lang = code;
      this.doc.documentElement.dir = dir;
    };
    return this.ctx.fetch(langs).then(
      langs => translateFragment(this, langs, this.doc.documentElement)).then(
      setDocLang);
  }

  serializeEntries(code) {
    let lang = {
      code,
      dir: getDirection(code),
      src: code in qps ? 'qps' : 'app'
    };
    return this.ctx.fetch([lang]).then(
      () => serializeContext(this.ctx, lang));
  }
}

function serializeContext(ctx, lang) {
  let cache = ctx._env._resCache;
  return ctx._resIds.reduce((seq, cur) => {
    let resource = cache[cur + lang.code + lang.src];
    return resource instanceof L10nError ?
      seq : seq.concat(serializeEntries(resource));
  }, []);
}
<commit_msg>removed htmloptimizer.win<commit_after>'use strict';

import { Env } from '../../lib/env';
import { qps } from '../../lib/pseudo';
import { L10nError } from '../../lib/errors';
import { getResourceLinks } from '../../bindings/html/head';
import { translateFragment } from '../../bindings/html/dom';
import { getDirection } from '../../bindings/html/langs';
import { serializeEntries } from '../../bindings/gaiabuild/serialize';

export class View {
  constructor(htmloptimizer, fetch) {
    this.env = new Env(
      htmloptimizer.config.GAIA_DEFAULT_LOCALE, fetch);
    this.doc = htmloptimizer.document;
    this.ctx = this.env.createContext(getResourceLinks(this.doc.head));
  }

  observe() {}
  disconnect() {}

  translate(code) {
    let dir = getDirection(code);
    let langs = [{ code, dir, src: 'app' }];
    let setDocLang = () => {
      this.doc.documentElement.lang = code;
      this.doc.documentElement.dir = dir;
    };
    return this.ctx.fetch(langs).then(
      langs => translateFragment(this, langs, this.doc.documentElement)).then(
      setDocLang);
  }

  serializeEntries(code) {
    let lang = {
      code,
      dir: getDirection(code),
      src: code in qps ? 'qps' : 'app'
    };
    return this.ctx.fetch([lang]).then(
      () => serializeContext(this.ctx, lang));
  }
}

function serializeContext(ctx, lang) {
  let cache = ctx._env._resCache;
  return ctx._resIds.reduce((seq, cur) => {
    let resource = cache[cur + lang.code + lang.src];
    return resource instanceof L10nError ?
      seq : seq.concat(serializeEntries(resource));
  }, []);
}

{'fraction_non_alphanumeric': 0.16888045540796964, 'fraction_numerical': 0.002530044275774826, 'mean_word_length': 3.044757033248082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '100615', 'n_tokens_mistral': 1010, 'n_tokens_neox': 1014, 'n_words': 211}