import { ChangeSet } from 'wordgard/doc'; /** The interface shared between {@link RangeSet} and {@link PointSet}. */ declare abstract class Set { /** The number of values in this set. */ abstract length: number; /** Returns `true` when this set is empty. */ abstract empty: boolean; /** Create a cursor over this point set, starting at the given position and side. */ abstract cursor(from?: number): Set.Cursor; /** Adjust this set's positions for a set of document changes. Returns a new set with the adjusted positions. Will delete values when the content around them was deleted. Optionally accepts an ordered sequence of replacements, whose positions should refer to the post-change document. */ abstract map(map: ChangeSet, replace?: readonly Set.Replacement[]): this; /** Create an updated copy of this set. */ abstract modify(spec: { /** If given, replace all values in these ranges. */ replace?: readonly Set.Replacement[]; /** Add values from this source. */ add?: Set.Source; /** Optionally filter out any value where this predicate returns false. */ filter?: (value: T, from: number, to: number) => boolean; }): this; } declare namespace Set { /** A cursor over a point or range set. */ interface Cursor { /** The value of the current range or point, or `null` when there are no more values. */ value: T | null; /** The start position of the current range or point. */ from: number; /** The end position of the current range. Will be equal to `from` for points. */ to: number; /** Move the cursor to a given position. */ goto(pos: number, side?: number): void; /** Continue to the next value, if any. */ next(): void; /** The set object that the current value points at, if any. */ set: any; } /** A source, used to create or extend a set, is either an array of `[value, pos, pos?]` tuples, or a function that calls its argument to add a value. For ranges, `to` must be given, and ranges must be provided ordered by start position. For points, `to` must be omitted or be the same as `from`, and the points must be ordered by position and {@link PointSet.Value.side side}. */ type Source = Iterable<[T, number, number?]> | ((add: (value: T, pos: number, to?: number) => void) => void); /** Represents a replaced section in a set. */ type Replacement = { /** The start of the replacement. */ from: number; /** The end of the replaced range. */ to: number; /** An optional source of points to to this section. */ add?: Source; }; } /** Data structure that stores sets of ranges, for use with {@link Decoration.Range range decorations} or other data types implementing {@link RangeSet.Value}. */ declare class RangeSet extends Set { private constructor(); /** Create a range set from an iterable of `[from, to, value]` tuples, or a function that calls its argument for every range to add. */ static create(source: Set.Source): RangeSet; get length(): number; get empty(): boolean; cursor(from?: number): Set.Cursor; /** Create a cursor over a collection of range sets. */ static cursor(sets: readonly RangeSet[], from?: number): Set.Cursor; map(map: ChangeSet, replace?: readonly Set.Replacement[]): this; private mapInner; modify(spec: { replace?: readonly Set.Replacement[]; add?: Set.Source; filter?: (value: T, from: number, to: number) => boolean; }): this; private modifyInner; /** Compare a section of this set with a section of the same length in another set. Calls `change` for any range where the two do not contain identical ranges. */ compareRange(fromA: number, b: RangeSet, fromB: number, len: number, change: (from: number, to: number) => void): void; /** The empty range set. */ static empty: RangeSet; } declare namespace RangeSet { /** Values stored in a range set must conform to this interface. */ interface Value { /** Whether content inserted at the start of this value's range is included in the range. */ inclusiveStart: boolean; /** Whether content inserted at the end is included. */ inclusiveEnd: boolean; /** Compare this value to another. */ eq(other: Value): boolean; } } /** Data structure used to store sets of points and then track them across document changes. Mostly used for {@link Decoration.Point point decorations}, but can also track your own types, if you make sure they implement the {@link PointSet.Value} interface. */ declare class PointSet implements Set { private constructor(); /** Create a point set from an iterable of `[position, value]` tuples, or a function that calls its argument for every point to add. */ static create(source: Set.Source): PointSet; get length(): number; get empty(): boolean; /** Create a cursor over this point set, starting at the given position and side. */ cursor(from?: number, side?: number): Set.Cursor; /** Create a cursor over a collection of point sets. */ static cursor(sets: readonly PointSet[], from?: number, side?: number): Set.Cursor; /** Get the value at the given position, if any. If there's multiple values at that position, the one with the lowest side is returned. If a predicate is given, only points that satisfy it are returned. */ at(pos: number, pred?: (value: T) => boolean): T | undefined; /** Adjust the points for a set of document changes. Returns a new set with the adjusted points. May delete points when the content around them was deleted. Optionally accepts an ordered sequence of replacements. */ map(map: ChangeSet, replace?: readonly Set.Replacement[]): this; private mapInner; modify(spec: { replace?: readonly Set.Replacement[]; add?: Set.Source; filter?: (value: T, from: number, to: number) => boolean; }): this; private modifyInner; /** Compare a range in this set with a range in another set. Call `change` for every point that exists in one but not the other. */ compareRange(fromA: number, b: PointSet, fromB: number, len: number, change: (pos: number, value: T) => void): void; /** The empty point set. */ static empty: PointSet; } declare namespace PointSet { /** Objects stored in a point set must conform to this interface. */ interface Value { /** The side of the point. Used to provide a sorting of points at the same position, and to determine cursor position relative to the points. Points with side < 0 are always displayed before a cursor at their position, those with side > 0 always after, and those with side == 0 before or after depending on the cursor's side. */ side: number; /** Configures whether the point should be deleted when content next to it is deleted. See {@link ChangeSet.mapPos}. */ trackMode: ChangeSet.TrackMode | undefined; /** Method to compare this value to another. */ eq(other: Value): boolean; } } /** Perform a binary search on the given array (starting at start) and return the index of the first element > n (or the length if no such element exists) @hidden */ declare function findAbove(array: readonly number[], start: number, n: number): number; export { PointSet, RangeSet, Set, findAbove };