"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ClassList = /** @class */ (function () {
    function ClassList(classes) {
        this._classes = [];
        if (classes) {
            this._classes = this._parseValue(classes);
        }
    }
    Object.defineProperty(ClassList.prototype, "length", {
        get: function () { return this._classes.length; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ClassList.prototype, "value", {
        get: function () { return this._classes.join(" "); },
        set: function (value) { this._classes = this._parseValue(value); },
        enumerable: true,
        configurable: true
    });
    ClassList.prototype._parseValue = function (value) {
        return value.split(/[ ]+/g)
            .filter(function (value, index, self) { return self.indexOf(value) === index; });
    };
    ClassList.prototype.add = function (token) {
        if (!this.contains(token)) {
            this._classes.push(token);
        }
    };
    ClassList.prototype.remove = function (token) {
        var index = this._classes.indexOf(token);
        if (index !== -1) {
            this._classes.splice(index, 1);
        }
    };
    ClassList.prototype.item = function (index) {
        if (index < 0 || index >= this._classes.length)
            throw new Error("Index out of bounds.");
        return this._classes[index];
    };
    ClassList.prototype.toggle = function (token) {
        var index = this._classes.indexOf(token);
        if (index === -1) {
            this._classes.push(token);
            return true;
        }
        else {
            this._classes.splice(index, 1);
            return false;
        }
    };
    ClassList.prototype.contains = function (token) {
        return this._classes.indexOf(token) !== -1;
    };
    ClassList.prototype.replace = function (oldToken, newToken) {
        var index = this._classes.indexOf(oldToken);
        if (index !== -1) {
            this._classes.splice(index, 1, newToken);
        }
    };
    ClassList.prototype.entries = function () {
        return this._classes.entries();
    };
    ClassList.prototype.forEach = function (callbackfn, thisArg) {
        var list = Array.from(this._classes);
        list.forEach(callbackfn, thisArg);
    };
    ClassList.prototype.keys = function () {
        return this._classes.keys();
    };
    ClassList.prototype.values = function () {
        return this._classes.values();
    };
    return ClassList;
}());
exports.ClassList = ClassList;
//# sourceMappingURL=ClassList.js.map