function _check_private_redeclaration(obj, privateCollection) {
    if (privateCollection.has(obj)) {
        throw new TypeError("Cannot initialize the same private elements twice on an object");
    }
}
function _class_apply_descriptor_get(receiver, descriptor) {
    if (descriptor.get) {
        return descriptor.get.call(receiver);
    }
    return descriptor.value;
}
function _class_apply_descriptor_set(receiver, descriptor, value) {
    if (descriptor.set) {
        descriptor.set.call(receiver, value);
    } else {
        if (!descriptor.writable) {
            throw new TypeError("attempted to set read only private field");
        }
        descriptor.value = value;
    }
}
function _class_extract_field_descriptor(receiver, privateMap, action) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to " + action + " private field on non-instance");
    }
    return privateMap.get(receiver);
}
function _class_private_field_get(receiver, privateMap) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
    return _class_apply_descriptor_get(receiver, descriptor);
}
function _class_private_field_init(obj, privateMap, value) {
    _check_private_redeclaration(obj, privateMap);
    privateMap.set(obj, value);
}
function _class_private_field_set(receiver, privateMap, value) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
    _class_apply_descriptor_set(receiver, descriptor, value);
    return value;
}
var _indexSet = /*#__PURE__*/ new WeakMap();
/**
 * The view order is a list of indexes that represent the order of the rendered elements.
 * Uses a Set alongside the array for O(1) membership checks.
 *
 * @class {ViewOrder}
 */ export class ViewOrder {
    /**
   * The length of the view order.
   *
   * @returns {number}
   */ get length() {
        return this.order.length;
    }
    /**
   * Checks if the view order contains the offset index.
   *
   * @param {number} offsetIndex The offset index.
   * @returns {boolean}
   */ has(offsetIndex) {
        return _class_private_field_get(this, _indexSet).has(offsetIndex);
    }
    /**
   * Gets the offset index at the given zero-based index. If the index
   * is out of bounds, -1 is returned.
   *
   * @param {number} zeroBasedIndex The zero-based index.
   * @returns {number}
   */ get(zeroBasedIndex) {
        return zeroBasedIndex < this.order.length ? this.order[zeroBasedIndex] : -1;
    }
    /**
   * Removes the offset index from the view order.
   *
   * @param {number} offsetIndex The offset index.
   */ remove(offsetIndex) {
        const idx = this.order.indexOf(offsetIndex);
        if (idx > -1) {
            this.order.splice(idx, 1);
            _class_private_field_get(this, _indexSet).delete(offsetIndex);
        }
    }
    /**
   * Prepends the offset index to the view order. To keep the order length constant,
   * the last offset index is removed.
   *
   * @param {number} offsetIndex The offset index.
   * @returns {number}
   */ prepend(offsetIndex) {
        this.order.unshift(offsetIndex);
        _class_private_field_get(this, _indexSet).add(offsetIndex);
        const removed = this.order.pop();
        _class_private_field_get(this, _indexSet).delete(removed);
        return removed;
    }
    constructor(viewOffset, viewSize){
        _class_private_field_init(this, _indexSet, {
            writable: true,
            value: void 0
        });
        this.order = [];
        _class_private_field_set(this, _indexSet, new Set());
        const order = new Array(viewSize);
        const indexSet = _class_private_field_get(this, _indexSet);
        for(let i = 0; i < viewSize; i++){
            const value = viewOffset + i;
            order[i] = value;
            indexSet.add(value);
        }
        this.order = order;
    }
}
