"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkListFactory = void 0;
const utils_1 = require("./utils");
/**
 * Helper class for constructing an offset list of marks that...
 * - Does not insert offsets if there is no content after them
 * - Does not insert 0-sized offsets
 * - Merges runs of offsets together
 * - Merges marks together
 */
class MarkListFactory {
    constructor(
    // TODO: Is there a usage of MarkListFactory where we need a non-undefined revision?
    revision, moveEffects, recordMerges = false) {
        this.revision = revision;
        this.moveEffects = moveEffects;
        this.recordMerges = recordMerges;
        this.offset = 0;
        this.list = [];
    }
    push(...marks) {
        for (const item of marks) {
            if ((0, utils_1.isSkipMark)(item)) {
                this.pushOffset(item);
            }
            else {
                this.pushContent(item);
            }
        }
    }
    pushOffset(offset) {
        this.offset += offset;
    }
    pushContent(mark) {
        if (this.offset > 0) {
            this.list.push(this.offset);
            this.offset = 0;
        }
        const prev = this.list[this.list.length - 1];
        if ((0, utils_1.isObjMark)(prev) && prev.type === mark.type) {
            if ((0, utils_1.tryExtendMark)(prev, mark, this.revision, this.moveEffects, this.recordMerges)) {
                return;
            }
        }
        this.list.push(mark);
    }
}
exports.MarkListFactory = MarkListFactory;
//# sourceMappingURL=markListFactory.js.map