<commit_before>/**
 * Package
 */
(function( scope, Packer ){
"use strict";

/**
 * Extend JSON setup, with circular references to items' containers.
 * Creates an array of items and virtual containers, 
 * that maps to nodes in setup tree.
 * Applies default container name.
 * @param {Object} setup packer setup
 * @param {Item} [container] parent node
 * @param {Object} [items={}] map of items to update
 * @returns {Array} array of updated/created items
 */
function parseSetup( setup, container, items ){
    items = items || {};
    var name, currentContainer;
    if( !container ){
      name = setup.name = "root"
      container = null;
    } else {
      name = setup.name || ( (container && container.name) + "_" + sNo );
      // FIXME i'm ugly
      setup.name = name;
    }
    // create item for current container
    items[ name ] = currentContainer = setup;
    Object.defineProperty(setup, "container", {value: container, writable: true});

    // create items list
    for(var sNo = 0, sLen = setup.items.length; sNo < sLen; sNo++) {
      var itemSetup = setup.items[sNo];

      // walk the tree recursively
      if(itemSetup.items){
        // FIXME I'm ugly
        // create default name
        if(!itemSetup.name){
          itemSetup.name = ( currentContainer.name + "_" + sNo );
        }
        parseSetup( itemSetup, currentContainer, items );
      } else {
        items[ itemSetup.index ] = itemSetup;
        Object.defineProperty(itemSetup, "container", {value: currentContainer, writable: true });
      }
    }
    return items;
}
 /**
 * Returns the minimum value of the priority property from the given array of objects
 * @param {Array<Object>} arr
 * @return {Number} number in range from 0 to 1
 * @TODO DRY
 */
function getMinimumPriority(arr) {
  var min = 1;
  for (var i = 0, ilen = arr.length; i < ilen; i++) {
    if (arr[i].priority < min) {
      min = arr[i].priority;
    }
  }
  if (min < 0) {
    min = 0;
  }
  return min;
}

/**
 * [Package description]
 * @param {Object} [setup] packer setup
 *
 * @todo remove #elements from here
 */
function Package( setup ){
  this.setup = setup || {
    name: "root",
    direction: "rightDown",
    gap: 0,
    items: []
  };
  // XXX: this is only used by layer above (pj-srotable-tiles to match with elements)
  this.items = 
  parseSetup( this.setup );

  // this.reset();
}
// Package.prototype.elements = [];
Package.prototype.items = null;
Package.prototype.setup = null;


Package.prototype.direction = "rightDown";


/**
 * [packItems description]
 * @param {Object} setup setup of items fo pack, if not give `#setup` will be used
 * @param {Array<Element>} elements array of DOM elements to update.
 */
Package.prototype.packItems = function packItems( setup, elements ) {
  setup || (setup = this.setup);
  elements || (elements = this.elements);
  var that = this,
      packer = new Packer(setup);

  //pack rectangles, and calculate container size
  packer.items = setup.items
    .sort(this.sorter) // sort- if neded
    .map(function(itemSetup){
      // TODO: do it more lightweight
      var rect = new Rectangle(itemSetup);
      // TODO, property?
      rect.container = setup;

      if (elements) {
        var element = elements[ itemSetup.index ];
        if (!element) {
          element = elements[ itemSetup.name ];
          if (!element) {
            element = document.createElement('DIV');
            element.style.zIndex = -1;
            element.style.position = "absolute";// FIXME: should be done in css
            that.$.container.appendChild(element);
            elements[ itemSetup.name ] = element;
          }
        }
      }

      //first calculate rect width because it cannot be auto TODO: fix for downRight mode
      if( typeof rect.width == "string" && rect.width != "auto" && rect.width.indexOf("%") > 0 ){
        rect.width = ( (setup.width + setup.gap) * parseFloat(rect.width) /100  - setup.gap);
      }
      // caluclate relative size
      // we cannot use calc(xx% - gap px) as it can be in virtual container which is a sibling
      if( typeof rect.height == "string" && rect.height != "auto" && rect.height.indexOf("%") > 0 ){
        rect.height = ( (setup.height + setup.gap) * parseFloat(rect.height) /100 - setup.gap );
      }

      
      if (itemSetup.items && itemSetup.propertyIsEnumerable("items")) { // container. propertyIsEnumerable is needed to rule out virtual "items" added by juicy-tiles-editor on nested tiles
        // pack its items first, to figureout minSize
        rect = that.packItems(
          rect, // use caculated width and height
          elements
        );
<commit_msg>We do not need this hack any longer.<commit_after>/**
 * Package
 */
(function( scope, Packer ){
"use strict";

/**
 * Extend JSON setup, with circular references to items' containers.
 * Creates an array of items and virtual containers, 
 * that maps to nodes in setup tree.
 * Applies default container name.
 * @param {Object} setup packer setup
 * @param {Item} [container] parent node
 * @param {Object} [items={}] map of items to update
 * @returns {Array} array of updated/created items
 */
function parseSetup( setup, container, items ){
    items = items || {};
    var name, currentContainer;
    if( !container ){
      name = setup.name = "root"
      container = null;
    } else {
      name = setup.name || ( (container && container.name) + "_" + sNo );
      // FIXME i'm ugly
      setup.name = name;
    }
    // create item for current container
    items[ name ] = currentContainer = setup;
    Object.defineProperty(setup, "container", {value: container, writable: true});

    // create items list
    for(var sNo = 0, sLen = setup.items.length; sNo < sLen; sNo++) {
      var itemSetup = setup.items[sNo];

      // walk the tree recursively
      if(itemSetup.items){
        // FIXME I'm ugly
        // create default name
        if(!itemSetup.name){
          itemSetup.name = ( currentContainer.name + "_" + sNo );
        }
        parseSetup( itemSetup, currentContainer, items );
      } else {
        items[ itemSetup.index ] = itemSetup;
        Object.defineProperty(itemSetup, "container", {value: currentContainer, writable: true });
      }
    }
    return items;
}
 /**
 * Returns the minimum value of the priority property from the given array of objects
 * @param {Array<Object>} arr
 * @return {Number} number in range from 0 to 1
 * @TODO DRY
 */
function getMinimumPriority(arr) {
  var min = 1;
  for (var i = 0, ilen = arr.length; i < ilen; i++) {
    if (arr[i].priority < min) {
      min = arr[i].priority;
    }
  }
  if (min < 0) {
    min = 0;
  }
  return min;
}

/**
 * [Package description]
 * @param {Object} [setup] packer setup
 *
 * @todo remove #elements from here
 */
function Package( setup ){
  this.setup = setup || {
    name: "root",
    direction: "rightDown",
    gap: 0,
    items: []
  };
  // XXX: this is only used by layer above (pj-srotable-tiles to match with elements)
  this.items = 
  parseSetup( this.setup );

  // this.reset();
}
// Package.prototype.elements = [];
Package.prototype.items = null;
Package.prototype.setup = null;


Package.prototype.direction = "rightDown";


/**
 * [packItems description]
 * @param {Object} setup setup of items fo pack, if not give `#setup` will be used
 * @param {Array<Element>} elements array of DOM elements to update.
 */
Package.prototype.packItems = function packItems( setup, elements ) {
  setup || (setup = this.setup);
  elements || (elements = this.elements);
  var that = this,
      packer = new Packer(setup);

  //pack rectangles, and calculate container size
  packer.items = setup.items
    .sort(this.sorter) // sort- if neded
    .map(function(itemSetup){
      // TODO: do it more lightweight
      var rect = new Rectangle(itemSetup);
      // TODO, property?
      rect.container = setup;

      if (elements) {
        var element = elements[ itemSetup.index ];
        if (!element) {
          element = elements[ itemSetup.name ];
          if (!element) {
            element = document.createElement('DIV');
            element.style.zIndex = -1;
            element.style.position = "absolute";// FIXME: should be done in css
            that.$.container.appendChild(element);
            elements[ itemSetup.name ] = element;
          }
        }
      }

      //first calculate rect width because it cannot be auto TODO: fix for downRight mode
      if( typeof rect.width == "string" && rect.width != "auto" && rect.width.indexOf("%") > 0 ){
        rect.width = ( (setup.width + setup.gap) * parseFloat(rect.width) /100  - setup.gap);
      }
      // caluclate relative size
      // we cannot use calc(xx% - gap px) as it can be in virtual container which is a sibling
      if( typeof rect.height == "string" && rect.height != "auto" && rect.height.indexOf("%") > 0 ){
        rect.height = ( (setup.height + setup.gap) * parseFloat(rect.height) /100 - setup.gap );
      }

      
      if (itemSetup.items ) { // container
        // pack its items first, to figureout minSize
        rect = that.packItems(
          rect, // use caculated width and height
          elements
        );

{'fraction_non_alphanumeric': 0.13049137650504394, 'fraction_numerical': 0.003688035578696171, 'mean_word_length': 2.5003796507213365, 'pattern_counts': {'":': 0, '<': 15, '<?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': '863376', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2667, 'n_words': 882}