import { MapMode, ChangeDesc } from '@codemirror/state'; /** Each range is associated with a value, which must inherit from this class. */ declare abstract class RangeValue { /** Compare this value with another value. The default implementation compares by identity. */ eq(other: RangeValue): boolean; /** The bias value at the start of the range. Determines how the range is positioned relative to other ranges starting at this position. Defaults to 0. */ startSide: number; /** The bias value at the end of the range. Defaults to 0. */ endSide: number; /** The mode with which the location of the range should be mapped when its `from` and `to` are the same, to decide whether a change deletes the range. Defaults to `MapMode.TrackDel`. */ mapMode: MapMode; /** Whether this value marks a point range, which is treated as atomic and shadows the ranges contained in it. */ point: boolean; /** Create a [range](https://codemirror.net/6/docs/ref/#rangeset.Range) with this value. */ range(from: number, to?: number): Range; } /** A range associates a value with a range of positions. */ declare class Range { /** The range's start position. */ readonly from: number; /** Its end position. */ readonly to: number; /** The value associated with this range. */ readonly value: T; } /** Collection of methods used when comparing range sets. */ interface RangeComparator { /** Notifies the comparator that the given range has the given set of values associated with it. */ compareRange(from: number, to: number, activeA: T[], activeB: T[]): void; /** Notification for a point range. */ comparePoint(from: number, to: number, byA: T | null, byB: T | null): void; } /** Methods used when iterating over the spans created by a set of ranges. The entire iterated range will be covered with either `span` or `point` calls. */ interface SpanIterator { /** Called for any ranges not covered by point decorations. `active` holds the values that the range is marked with (and may be empty). `openStart` indicates how many of those ranges are open (continued) at the start of the span. */ span(from: number, to: number, active: readonly T[], openStart: number): void; /** Called when going over a point decoration. The active range decorations that cover the point and have a higher precedence are provided in `active`. The open count in `openStart` counts the number of those ranges that started before the point and. If the point started before the iterated range, `openStart` will be `active.length + 1` to signal this. */ point(from: number, to: number, value: T, active: readonly T[], openStart: number): void; /** When provided, this will be called for each point processed, causing the ones for which it returns false to be ignored. */ filterPoint?(from: number, to: number, value: T, index: number): boolean; } /** A range cursor is an object that moves to the next range every time you call `next` on it. Note that, unlike ES6 iterators, these start out pointing at the first element, so you should call `next` only after reading the first range (if any). */ interface RangeCursor { /** Move the iterator forward. */ next: () => void; /** The next range's value. Holds `null` when the cursor has reached its end. */ value: T | null; /** The next range's start position. */ from: number; /** The next end position. */ to: number; } declare type RangeSetUpdate = { /** An array of ranges to add. If given, this should be sorted by `from` position and `startSide` unless [`sort`](https://codemirror.net/6/docs/ref/#rangeset.RangeSet.update^updateSpec.sort) is given as `true`. */ add?: readonly Range[]; /** Indicates whether the library should sort the ranges in `add`. Defaults to `false`. */ sort?: boolean; /** Filter the ranges already in the set. Only those for which this function returns `true` are kept. */ filter?: (from: number, to: number, value: T) => boolean; /** Can be used to limit the range on which the filter is applied. Filtering only a small range, as opposed to the entire set, can make updates cheaper. */ filterFrom?: number; /** The end position to apply the filter to. */ filterTo?: number; }; /** A range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#rangeset.Range) in a way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#rangeset.RangeSet.map) and [update](https://codemirror.net/6/docs/ref/#rangeset.RangeSet.update). This is an immutable data structure. */ declare class RangeSet { /** The number of ranges in the set. */ get size(): number; /** Update the range set, optionally adding new ranges or filtering out existing ones. (The extra type parameter is just there as a kludge to work around TypeScript variance issues that prevented `RangeSet` from being a subtype of `RangeSet` when `X` is a subtype of `Y`.) */ update(updateSpec: RangeSetUpdate): RangeSet; /** Map this range set through a set of changes, return the new set. */ map(changes: ChangeDesc): RangeSet; /** Iterate over the ranges that touch the region `from` to `to`, calling `f` for each. There is no guarantee that the ranges will be reported in any specific order. When the callback returns `false`, iteration stops. */ between(from: number, to: number, f: (from: number, to: number, value: T) => void | false): void; /** Iterate over the ranges in this set, in order, including all ranges that end at or after `from`. */ iter(from?: number): RangeCursor; /** Iterate over the ranges in a collection of sets, in order, starting from `from`. */ static iter(sets: readonly RangeSet[], from?: number): RangeCursor; /** Iterate over two groups of sets, calling methods on `comparator` to notify it of possible differences. */ static compare(oldSets: readonly RangeSet[], newSets: readonly RangeSet[], /** This indicates how the underlying data changed between these ranges, and is needed to synchronize the iteration. `from` and `to` are coordinates in the _new_ space, after these changes. */ textDiff: ChangeDesc, comparator: RangeComparator, /** Can be used to ignore all non-point ranges, and points below the given size. When -1, all ranges are compared. */ minPointSize?: number): void; /** Compare the contents of two groups of range sets, returning true if they are equivalent in the given range. */ static eq(oldSets: readonly RangeSet[], newSets: readonly RangeSet[], from?: number, to?: number): boolean; /** Iterate over a group of range sets at the same time, notifying the iterator about the ranges covering every given piece of content. Returns the open count (see [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#rangeset.SpanIterator.span)) at the end of the iteration. */ static spans(sets: readonly RangeSet[], from: number, to: number, iterator: SpanIterator, /** When given and greater than -1, only points of at least this size are taken into account. */ minPointSize?: number): number; /** Create a range set for the given range or array of ranges. By default, this expects the ranges to be _sorted_ (by start position and, if two start at the same position, `value.startSide`). You can pass `true` as second argument to cause the method to sort them. */ static of(ranges: readonly Range[] | Range, sort?: boolean): RangeSet; /** The empty set of ranges. */ static empty: RangeSet; } /** A range set builder is a data structure that helps build up a [range set](https://codemirror.net/6/docs/ref/#rangeset.RangeSet) directly, without first allocating an array of [`Range`](https://codemirror.net/6/docs/ref/#rangeset.Range) objects. */ declare class RangeSetBuilder { private chunks; private chunkPos; private chunkStart; private last; private lastFrom; private lastTo; private from; private to; private value; private maxPoint; private setMaxPoint; private nextLayer; private finishChunk; /** Create an empty builder. */ constructor(); /** Add a range. Ranges should be added in sorted (by `from` and `value.startSide`) order. */ add(from: number, to: number, value: T): void; /** Finish the range set. Returns the new set. The builder can't be used anymore after this has been called. */ finish(): RangeSet; } export { Range, RangeComparator, RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SpanIterator };