PRIVATE FUNCTIONS
334190
function initializeParser(document, debug) {
    const chars = new antlr.InputStream(document);
    const lexer = new grammar.DocumentLexer(chars);
    const listener = new CustomErrorListener(debug);
    lexer.removeErrorListeners();
    lexer.addErrorListener(listener);
    const tokens = new antlr.CommonTokenStream(lexer);
    const parser = new grammar.DocumentParser(tokens);
    parser.buildParseTrees = true;
    parser.removeErrorListeners();
    parser.addErrorListener(listener);
    parser._errHandler = new CustomErrorStrategy();
    return parser;
}
144768
function _defPrivateProperty(name, value) {
        if (instanceOf(value, Function)) value = value.bind(model)
        _privateProperties[name] = value
        $util.def(model, name, {
            enumerable: false,
            value: value
        })
    }
1291537
function(a) {
            if ( $.isFunction(a) ) {
                a.apply(this, Array.prototype.slice.call(arguments, 1));
            }
        }
21623
function () {
            var emptyFunction = new RegExp(/(\{\s\})|(\{\})/),
                publicMethods = {};
            for (property in this.settings) {
                if (typeof this.settings[property] == 'function' &&
                    typeof this[property] == 'function') {
                    var method = this.settings[property];
                    if (emptyFunction.test(method)) {
                        publicMethods[property] = this[property];
                    } else {
                        var defaultMethodName = this.createDefaultMethodName(property);
                        publicMethods[property] = this.settings[property];
                        publicMethods[defaultMethodName] = this[property];
                    }
                }
            }

            publicMethods.stylings = this.stylings;

            return publicMethods;
        }
214482
function(_first, _fun) {
      if(!_first) return _fun;
      return function(_value) {
        return _fun.call(this, _first.call(this, _value));
      };
    }
965645
function(object, methods) {
        _.each(methods, function(method, name) {
            if (!_.isFunction(method)) {
                throw new Error('Method "' + name + '" must be a function!');
            }
            object[name] = method
        });
    }
970700
function(d) {
        var a = d.attributes, i;
        if (a) {
          for (i = 0; i < a.length; i += 1) {
            if (typeof d[a[i].name] === 'function') d[a[i].name] = null;
          }
        }
        a = d.childNodes;
        if (a) {
          for (i = 0; i < a.length; i += 1) purge(d.childNodes[i]);
        }
      }
621888
function(db) {
		function call_func(data, fun, params) {
			try {

				// Parse data
				if(!(data && (data instanceof Array))) {
					throw new TypeError("First argument is not an array");
				}

				// Parse fun
				if(fun.substr(0, 8) === 'function') {
					// FIXME: This is the same code as in nor-function -- should be reused from there.
					fun = new Function('return (' + fun + ')')();
				} else {
					throw new TypeError("Second argument is not valid serialized function");
				}

				// Parse params
				if(!(params && (params instanceof Array))) {
					throw new TypeError("Third argument is not an array");
				}

				return fun.apply(undefined, [].concat(data).concat(params) );

			} catch (e) {
				plv8.elog(ERROR, e);
				return;
			}
		}
		return db.query('CREATE SCHEMA IF NOT EXISTS nopg')
			.query('CREATE OR REPLACE FUNCTION nopg.call_func(data json, fun json, params json) RETURNS json LANGUAGE plv8 STABLE AS ' + NoPg._escapeFunction(call_func, ["data", "fun", "params"]) );
	}
927020
function eachProp(obj, func) {
        var prop;
        for (prop in obj) {
            if (hasProp(obj, prop)) {
                if (func(obj[prop], prop)) {
                    break;
                }
            }
        }
    }
306900
function(fun) {
      var funLength = fun.length;

      if (funLength < 1) {
        return fun;
      }
      else if (funLength === 1)  {
        return function () {
          return fun.call(this, __slice.call(arguments, 0));
        };
      }
      else {
        return function () {
          var numberOfArgs = arguments.length,
              namedArgs = __slice.call(arguments, 0, funLength - 1),
              numberOfMissingNamedArgs = Math.max(funLength - numberOfArgs - 1, 0),
              argPadding = new Array(numberOfMissingNamedArgs),
              variadicArgs = __slice.call(arguments, fun.length - 1);

          return fun.apply(this, namedArgs.concat(argPadding).concat([variadicArgs]));
        };
      }
    }
595737
function(fn) {
      var keys = Object.keys(self);
      for(var i = keys.length - 1; i >= 0; i--) {
        var key = keys[i];
        if(!UT.Collection.isReservedKey(key)) {
          fn(key, self[key]);
        }
      }
    }
1299145
function(object) {
		var methods = Array.prototype.slice.call(arguments).slice(1);
		if (!methods.length) {
			methods = gui.Object.ownmethods(object).filter(function(name) {
				return name[0] !== "_"; // exclude private methods
			});
		}
		methods.forEach(function(name) {
			object[name] = object[name].bind(object);
		});
		return object;
	}
592384
function (obj) {

            var length = !!obj && "length" in obj && obj.length,
                type   = $this.type(obj);

            if (type === "function" || $this.isWindow(obj)) {
                return false;
            }

            return type === "array" ||
                length === 0 ||
                typeof length === "number" &&
                length > 0 &&
                (length - 1) in obj;
        }
188566
function(fn) {
    var n = this.elements.length, k = n, i;
    do { i = k - n;
      fn(this.elements[i], i+1);
    } while (--n);
  }
205303
function (fn) {
        return function () {
            var tokens = arguments;
            var i;

            for (i = 0; i < tokens.length; i += 1) {
                fn.call(this, tokens[i]);
            }
        };
    }
894636
function() {
  var args = arguments;
  return function(err) {
    var params = Array.prototype.slice.call(args);
    params.push(err);
    Entity.debug.apply(Entity.debug, params);
    throw err;
  };
}
1285903
function Timer () {
  /*
  * PRIVATE variables and Functions
  */
  let counters = new TimeCounter();
  let totalCounters = new TimeCounter();

  let intervalId;
  let eventEmitter = hasDOM() ? document.createElement('span')
    : hasEventEmitter() ? new events.EventEmitter() : undefined;
  let running = false;
  let paused = false;
  let precision;
  let timerTypeFactor;
  let customCallback;
  let timerConfig = {};
  let currentParams;
  let targetValues;
  let startValues;
  let countdown;
  let startingDate;
  let targetDate;
  let eventData = {
    detail: {
      timer: this
    }
  };

  function updateCounters (precision, roundedValue) {
    totalCounters[precision] = roundedValue;

    if (precision === DAYS) {
      counters[precision] = roundedValue;
    } else if (roundedValue >= 0) {
      counters[precision] = mod(roundedValue, groupedUnits[precision]);
    } else {
      counters[precision] = groupedUnits[precision] - mod(roundedValue, groupedUnits[precision]);
    }
  }

  function updateDays (value) {
    return updateUnitByPrecision(value, DAYS);
  }

  function updateHours (value) {
    return updateUnitByPrecision(value, HOURS);
  }

  function updateMinutes (value) {
    return updateUnitByPrecision(value, MINUTES);
  }

  function updateSeconds (value) {
    return updateUnitByPrecision(value, SECONDS);
  }

  function updateSecondTenths (value) {
    return updateUnitByPrecision(value, SECOND_TENTHS);
  }

  function updateUnitByPrecision (value, precision) {
    let previousValue = totalCounters[precision];
    updateCounters(precision, calculateIntegerUnitQuotient(value, unitsInMilliseconds[precision]));

    return totalCounters[precision] !== previousValue;
  }

  function stopTimerAndResetCounters () {
    stopTimer();
    resetCounters();
  }

  function stopTimer () {
    clearInterval(intervalId);
    intervalId = undefined;
    running = false;
    paused = false;
  }

  function setParamsAndStartTimer (params) {
    if (!isPaused()) {
      setParams(params);
    } else {
      startingDate = calculateStartingDate();
      targetValues = setTarget(currentParams.target);
    }

    startTimer();
  }

  function startTimer () {
    let interval = unitsInMilliseconds[precision];

    if (isTargetAchieved(roundTimestamp(Date.now()))) {
      return;
    }

    intervalId = setInterval(
      updateTimerAndDispatchEvents,
      interval
    );

    running = true;
    paused = false;
  }

  function calculateStartingDate () {
    return roundTimestamp(Date.now()) -
      totalCounters.secondTenths * unitsInMilliseconds[SECOND_TENTHS] *
      timerTypeFactor;
  }

  function updateTimerAndDispatchEvents () {
    let currentTime = roundTimestamp(Date.now());
    let valuesUpdated = updateTimer();

    dispatchEvents(valuesUpdated);

    customCallback(eventData.detail.timer);
    if (isTargetAchieved(currentTime)) {
      stop();
      dispatchEvent('targetAchieved', eventData);
    }
  }

  function updateTimer (currentTime = roundTimestamp(Date.now())) {
    let elapsedTime = timerTypeFactor > 0 ? (currentTime - startingDate) : (startingDate - currentTime);
    let valuesUpdated = {};

    valuesUpdated[SECOND_TENTHS] = updateSecondTenths(elapsedTime);
    valuesUpdated[SECONDS] = updateSeconds(elapsedTime);
    valuesUpdated[MINUTES] = updateMinutes(elapsedTime);
    valuesUpdated[HOURS] = updateHours(elapsedTime);
    valuesUpdated[DAYS] = updateDays(elapsedTime);

    return valuesUpdated;
  }

  function roundTimestamp (timestamp) {
    return Math.floor(timestamp / unitsInMilliseconds[precision]) * unitsInMilliseconds[precision];
  }

  function dispatchEvents (valuesUpdated) {
    if (valuesUpdated[SECOND_TENTHS]) {
      dispatchEvent('secondTenthsUpdated', eventData);
    }
    if (valuesUpdated[SECONDS]) {
      dispatchEvent('secondsUpdated', eventData);
    }
    if (valuesUpdated[MINUTES]) {
      dispatchEvent('minutesUpdated', eventData);
    }
    if (valuesUpdated[HOURS]) {
      dispatchEvent('hoursUpdated', eventData);
    }
    if (valuesUpdated[DAYS]) {
      dispatchEvent('daysUpdated', eventData);
    }
  }

  function isTargetAchieved (currentDate) {
    return targetValues instanceof Array &&
      currentDate >= targetDate;
  }

  function resetCounters () {
    for (let counter in counters) {
      if (counters.hasOwnProperty(counter) && typeof counters[counter] === 'number') {
        counters[counter] = 0;
      }
    }

    for (let counter in totalCounters) {
      if (totalCounters.hasOwnProperty(counter) && typeof totalCounters[counter] === 'number') {
        totalCounters[counter] = 0;
      }
    }
  }

  function setParams (params) {
    params = params || {};

    precision = checkPrecision(params.precision);

    customCallback = typeof params.callback === 'function' ? params.callback : function () {};

    countdown = params.countdown === true;

    timerTypeFactor = countdown === true ? -1 : 1;

    if (typeof params.startValues === 'object') {
      setStartValues(params.startValues);
    } else {
      startValues = null;
    }

    startingDate = calculateStartingDate();

    updateTimer();

    if (typeof params.target === 'object') {
      targetValues = setTarget(params.target);
    } else if (countdown) {
      params.target = { seconds: 0 };
      targetValues = setTarget(params.target);
    } else {
      targetValues = null;
    }

    timerConfig = {
      precision: precision,
      callback: customCallback,
      countdown: typeof params === 'object' && params.countdown === true,
      target: targetValues,
      startValues: startValues
    };

    currentParams = params;
  }

  function checkPrecision (precision) {
    precision = typeof precision === 'string' ? precision : SECONDS;
    if (!isValidInputValue(precision)) {
      throw new Error(`Error in precision parameter: ${precision} is not a valid value`);
    }

    return precision;
  }

  function isValidInputValue (value) {
    return VALID_INPUT_VALUES.indexOf(value) >= 0;
  }

  function configInputValues (inputValues) {
    let secondTenths, seconds, minutes, hours, days, values;
    if (typeof inputValues === 'object') {
      if (inputValues instanceof Array) {
        if (inputValues.length !== 5) {
          throw new Error('Array size not valid');
        }
        values = inputValues;
      } else {
        for (let value in inputValues) {
          if (VALID_INPUT_VALUES.indexOf(value) < 0) {
            throw new Error(`Error in startValues or target parameter: ${value} is not a valid input value`);
          }
        }
        values = [
          inputValues.secondTenths || 0, inputValues.seconds || 0,
          inputValues.minutes || 0, inputValues.hours || 0,
          inputValues.days || 0
        ];
      }
    }

    secondTenths = values[SECOND_TENTHS_POSITION];
    seconds = values[SECONDS_POSITION] + calculateIntegerUnitQuotient(secondTenths, SECOND_TENTHS_PER_SECOND);
    minutes = values[MINUTES_POSITION] + calculateIntegerUnitQuotient(seconds, SECONDS_PER_MINUTE);
    hours = values[HOURS_POSITION] + calculateIntegerUnitQuotient(minutes, MINUTES_PER_HOUR);
    days = values[DAYS_POSITION] + calculateIntegerUnitQuotient(hours, HOURS_PER_DAY);

    values[SECOND_TENTHS_POSITION] = secondTenths % SECOND_TENTHS_PER_SECOND;
    values[SECONDS_POSITION] = seconds % SECONDS_PER_MINUTE;
    values[MINUTES_POSITION] = minutes % MINUTES_PER_HOUR;
    values[HOURS_POSITION] = hours % HOURS_PER_DAY;
    values[DAYS_POSITION] = days;

    return values;
  }

  function calculateIntegerUnitQuotient (unit, divisor) {
    let quotient = unit / divisor;

    return quotient < 0 ? Math.ceil(quotient) : Math.floor(quotient);
  }

  function setTarget (inputTarget) {
    if (!inputTarget) {
      return;
    }

    targetValues = configInputValues(inputTarget);
    let targetCounter = calculateTotalCounterFromValues(targetValues);
    targetDate = startingDate +
      targetCounter.secondTenths *
      unitsInMilliseconds[SECOND_TENTHS] *
      timerTypeFactor;

    return targetValues;
  }

  function setStartValues (inputStartValues) {
    startValues = configInputValues(inputStartValues);
    counters.secondTenths = startValues[SECOND_TENTHS_POSITION];
    counters.seconds = startValues[SECONDS_POSITION];
    counters.minutes = startValues[MINUTES_POSITION];
    counters.hours = startValues[HOURS_POSITION];
    counters.days = startValues[DAYS_POSITION];

    totalCounters = calculateTotalCounterFromValues(startValues, totalCounters);
  }

  function calculateTotalCounterFromValues (values, outputCounter) {
    let total = outputCounter || {};

    total.days = values[DAYS_POSITION];
    total.hours = total.days * HOURS_PER_DAY + values[HOURS_POSITION];
    total.minutes = total.hours * MINUTES_PER_HOUR + values[MINUTES_POSITION];
    total.seconds = total.minutes * SECONDS_PER_MINUTE + values[SECONDS_POSITION];
    total.secondTenths = total.seconds * SECOND_TENTHS_PER_SECOND + values[[SECOND_TENTHS_POSITION]];

    return total;
  }

  /*
   * PUBLIC functions
   */

  /**
   * [stop stops the timer and resets the counters. Dispatch stopped event]
   */
  function stop () {
    stopTimerAndResetCounters();
    dispatchEvent('stopped', eventData);
  }

  /**
   * [stop stops and starts the timer. Dispatch stopped event]
   */
  function reset () {
    stopTimerAndResetCounters();
    setParamsAndStartTimer(currentParams);
    dispatchEvent('reset', eventData);
  }

  /**
   * [start starts the timer configured by the params object. Dispatch started event]
   * @param  {object} params [Configuration parameters]
   */
  function start (params = {}) {
    if (isRunning()) {
      return;
    }

    setParamsAndStartTimer(params);
    dispatchEvent('started', eventData);
  }

  /**
   * [pause stops the timer without resetting the counters. The timer it can be restarted with start function.
   * Dispatch paused event]
   * @return {type} [description]
   */
  function pause () {
    stopTimer();
    paused = true;
    dispatchEvent('paused', eventData);
  }

  /**
   * [addEventListener Adds event listener to the timer]
   * @param {string} event      [event to listen]
   * @param {function} listener   [the event listener function]
   */
  function addEventListener (event, listener) {
    if (hasDOM()) {
      eventEmitter.addEventListener(event, listener);
    } else if (hasEventEmitter()) {
      eventEmitter.on(event, listener);
    }
  }

  /**
   * [removeEventListener Removes event listener to the timer]
   * @param  {string} event    [event to remove listener]
   * @param  {function} listener [listener to remove]
   */
  function removeEventListener (event, listener) {
    if (hasDOM()) {
      eventEmitter.removeEventListener(event, listener);
    } else if (hasEventEmitter()) {
      eventEmitter.removeListener(event, listener);
    }
  }

  /**
   * [dispatchEvent dispatches an event]
   * @param  {string} event [event to dispatch]
   */
  function dispatchEvent (event, data) {
    if (hasDOM()) {
      eventEmitter.dispatchEvent(new CustomEvent(event, data));
    } else if (hasEventEmitter()) {
      eventEmitter.emit(event, data);
    }
  }

  /**
   * [isRunning return true if the timer is running]
   * @return {Boolean}
   */
  function isRunning () {
    return running;
  }

  /**
   * [isPaused returns true if the timer is paused]
   * @return {Boolean}
   */
  function isPaused () {
    return paused;
  }

  /**
   * [getTimeValues returns the counter with the current timer values]
   * @return {TimeCounter}
   */
  function getTimeValues () {
    return counters;
  }

  /**
   * [getTotalTimeValues returns the counter with the current timer total values]
   * @return {TimeCounter}
   */
  function getTotalTimeValues () {
    return totalCounters;
  }

  /**
   * [getConfig returns the configuration parameters]
   * @return {type}
   */
  function getConfig () {
    return timerConfig;
  }

  /**
   * Public API
   * Definition of Timer instance public functions
   */
  if (typeof this !== 'undefined') {
    this.start = start;

    this.pause = pause;

    this.stop = stop;

    this.reset = reset;

    this.isRunning = isRunning;

    this.isPaused = isPaused;

    this.getTimeValues = getTimeValues;

    this.getTotalTimeValues = getTotalTimeValues;

    this.getConfig = getConfig;

    this.addEventListener = addEventListener;

    this.on = addEventListener;

    this.removeEventListener = removeEventListener;

    this.off = removeEventListener;
  }
}