/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { isNoopMark, tryExtendMark } from "./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
 */
export 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 (isNoopMark(item)) {
                this.pushOffset(item.count);
            }
            else {
                this.pushContent(item);
            }
        }
    }
    pushOffset(offset) {
        this.offset += offset;
    }
    pushContent(mark) {
        if (this.offset > 0) {
            this.list.push({ count: this.offset });
            this.offset = 0;
        }
        const prev = this.list[this.list.length - 1];
        if (prev !== undefined && prev.type === mark.type) {
            if (tryExtendMark(prev, mark, this.revision, this.moveEffects, this.recordMerges)) {
                return;
            }
        }
        this.list.push(mark);
    }
}
//# sourceMappingURL=markListFactory.js.map