/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { type ChangeAtomId, type ChangesetLocalId, type RevisionMetadataSource, type RevisionTag } from "../../core/index.js";
import { type NodeId, type CrossFieldKeyRange, type NestedChangesIndices } from "../modular-schema/index.js";
import type { DetachOfRemovedNodes, EmptyInputCellMark } from "./helperTypes.js";
import { type Attach, type CellId, type CellMark, type Changeset, type Detach, type Mark, type MarkEffect, type NoopMark, type CellCount, type Rename, type Pin } from "./types.js";
export declare function isEmpty(change: Changeset): boolean;
export declare function createEmpty(): Changeset;
export declare function getNestedChanges(change: Changeset): NestedChangesIndices;
export declare function isNewAttach(mark: Mark, revision?: RevisionTag): boolean;
export declare function isNewAttachEffect(effect: MarkEffect, cellId: CellId | undefined, revision?: RevisionTag): boolean;
export declare function isRename(mark: MarkEffect): mark is Rename;
export declare function isInsert(mark: MarkEffect): mark is Attach;
export declare function isAttach(effect: MarkEffect): effect is Attach;
export declare function isReattach(mark: Mark): boolean;
export declare function isReattachEffect(effect: MarkEffect, cellId: CellId | undefined): boolean;
export declare function isActiveReattach(mark: Mark): mark is CellMark<Attach> & {
    conflictsWith?: undefined;
};
export declare function areEqualCellIds(a: CellId | undefined, b: CellId | undefined): boolean;
export declare function getInputCellId(mark: Mark): CellId | undefined;
export declare function getOutputCellId(mark: Mark): CellId | undefined;
export declare function cellSourcesFromMarks(marks: readonly Mark[], contextGetter: typeof getInputCellId | typeof getOutputCellId): Set<RevisionTag | undefined>;
export declare enum CellOrder {
    SameCell = 0,
    OldThenNew = 1,
    NewThenOld = 2
}
/**
 * Determines the order of two cells from two changesets.
 *
 * This function makes the following assumptions:
 * 1. The cells represent the same context.
 * 2. `oldMarkCell` is from a mark in a changeset that is older than the changeset that contains the mark that
 * `newMarkCell` is from.
 * 3. In terms of sequence index, all cells located before A are also located before B,
 * and all cells located before B are also located before A.
 * 4. If a changeset has a mark/tombstone that describes a cell named in some revision R,
 * then that changeset must contain marks/tombstones for all cells named in R as well as all cells named in later
 * revisions up to its own.
 * 5. If a changeset foo is rebased over a changeset bar, then the rebased version of foo must contain tombstones or
 * marks for all cells referenced or named in bar. It has yet to be determined whether this assumption is necessary
 * for the logic below.
 *
 * @param oldMarkCell - The cell referenced or named by a mark or tombstone from the older changeset.
 * @param newMarkCell - The cell referenced or named by a mark or tombstone from the newer changeset.
 * @param oldChangeKnowledge - The set of revisions that the older changeset has cell representations for.
 * @param newChangeKnowledge - The set of revisions that the newer changeset has cell representations for.
 * @param metadata - Revision metadata for the operation being carried out.
 * @returns a {@link CellOrder} which describes how the cells are ordered relative to one-another.
 */
export declare function compareCellPositionsUsingTombstones(oldMarkCell: ChangeAtomId, newMarkCell: ChangeAtomId, oldChangeKnowledge: ReadonlySet<RevisionTag | undefined>, newChangeKnowledge: ReadonlySet<RevisionTag | undefined>, metadata: RevisionMetadataSource): CellOrder;
/**
 * Gets the ID of the cell in the output context of the given detach `mark`.
 */
export declare function getDetachOutputCellId(mark: Detach): ChangeAtomId;
/**
 * Gets the ID of the node to be attached in the input context of the given detach `mark`.
 */
export declare function getAttachedRootId(mark: Attach): ChangeAtomId;
/**
 * Gets the ID of the detached node in the output context of the given detach `mark`.
 */
export declare function getDetachedRootId(mark: Detach): ChangeAtomId;
export declare function getMovedNodeId(mark: Attach | Detach): ChangeAtomId;
/**
 * Preserves the semantics of the given `mark` but repackages it into a `DetachOfRemovedNodes` when possible.
 */
export declare function normalizeCellRename(cellId: CellId, count: CellCount, attach: Attach, detach: Detach): CellMark<DetachOfRemovedNodes | Rename | NoopMark>;
export declare function cloneMark<TMark extends Mark>(mark: TMark): TMark;
export declare function cloneMarkEffect<TEffect extends MarkEffect>(effect: TEffect): TEffect;
export declare function cloneCellId(id: CellId): CellId;
/**
 * Gets the number of nodes within the output context of the mark.
 * @param mark - The mark to get the length of.
 * @param ignorePairing - When true, the length of a paired mark (e.g. MoveIn/MoveOut) whose matching mark is not active
 * will be treated the same as if the matching mark were active.
 */
export declare function getOutputLength(mark: Mark, ignorePairing?: boolean): number;
/**
 * Gets the number of nodes within the input context of the mark.
 * @param mark - The mark to get the length of.
 */
export declare function getInputLength(mark: Mark): number;
export declare function markEmptiesCells(mark: Mark): boolean;
export declare function markFillsCells(mark: Mark): boolean;
export declare function markHasCellEffect(mark: Mark): boolean;
export declare function areInputCellsEmpty(mark: Mark): mark is EmptyInputCellMark;
export declare function areOutputCellsEmpty(mark: Mark): boolean;
/**
 * Returns true if and only iff the given `mark` would have impact on the field when applied.
 *
 * @remarks
 * Ignores the impact of nested changes.
 * CellRename effects are considered impactful if they actually change the ID of the cells.
 */
export declare function isImpactful(mark: Mark): boolean;
export declare function isTombstone(mark: Mark): mark is CellMark<NoopMark> & {
    cellId: CellId;
};
export declare function isNoopMark(mark: Mark): mark is CellMark<NoopMark>;
export declare function areOverlappingIdRanges(id1: ChangesetLocalId, count1: number, id2: ChangesetLocalId, count2: number): boolean;
export declare function compareCellsFromSameRevision(cell1: CellId, count1: number, cell2: CellId, count2: number): number | undefined;
export declare function isDetach(mark: MarkEffect | undefined): mark is Detach;
export declare function isPin(mark: Mark): mark is Pin;
export declare function isRemoveMark(mark: Mark | undefined): mark is CellMark<Detach>;
export declare function areMergeableChangeAtoms(lhs: ChangeAtomId | undefined, lhsCount: number, rhs: ChangeAtomId | undefined): boolean;
/**
 * Attempts to extend `lhs` to include the effects of `rhs`.
 * @param lhs - The mark to extend.
 * @param rhs - The effect so extend `rhs` with.
 * @returns `lhs` iff the function was able to mutate `lhs` to include the effects of `rhs`.
 * When `undefined` is returned, `lhs` is left untouched.
 */
export declare function tryMergeMarks(lhs: Mark, rhs: Readonly<Mark>): Mark | undefined;
/**
 * Splits the `mark` into two marks such that the first returned mark has length `length`.
 * @param mark - The mark to split.
 * @param revision - The revision of the changeset the mark is part of.
 * @param length - The desired length for the first of the two returned marks.
 * @param genId - An ID allocator
 * @param moveEffects - The table in which to record splitting of move marks
 * @param recordMoveEffect - Whether when splitting a move an entry should be added to `moveEffects` indicating that the mark should be split (in case we process this mark again).
 * An entry is always added to `moveEffects` indicating that the opposite end of the move should be split.
 * @returns A pair of marks equivalent to the original `mark`
 * such that the first returned mark has input length `length`.
 */
export declare function splitMark<TMark extends Mark>(mark: TMark, length: number): [TMark, TMark];
export declare function splitMarkEffect<TEffect extends MarkEffect>(effect: TEffect, length: number): [TEffect, TEffect];
export declare function extractMarkEffect<TEffect extends MarkEffect>(mark: CellMark<TEffect>): TEffect;
export declare function omitMarkEffect(mark: CellMark<unknown>): CellMark<NoopMark>;
export declare function withNodeChange<TMark extends CellMark<TKind>, TKind extends MarkEffect>(mark: TMark, changes: NodeId | undefined): TMark;
export declare function withRevision<TMark extends Mark>(mark: TMark, revision: RevisionTag | undefined): TMark;
export declare function getCrossFieldKeys(change: Changeset): CrossFieldKeyRange[];
//# sourceMappingURL=utils.d.ts.map