1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 18:29:39 +02:00
This commit is contained in:
DanieL 2023-02-13 14:41:08 -03:00
parent 64c36d9f4e
commit 0d0338876d
1197 changed files with 121461 additions and 179724 deletions

View file

@ -27,10 +27,10 @@ class Text {
*/
replace(from, to, text) {
let parts = [];
this.decompose(0, from, parts, 2 /* To */);
this.decompose(0, from, parts, 2 /* Open.To */);
if (text.length)
text.decompose(0, text.length, parts, 1 /* From */ | 2 /* To */);
this.decompose(to, this.length, parts, 1 /* From */);
text.decompose(0, text.length, parts, 1 /* Open.From */ | 2 /* Open.To */);
this.decompose(to, this.length, parts, 1 /* Open.From */);
return TextNode.from(parts, this.length - (to - from) + text.length);
}
/**
@ -120,7 +120,7 @@ class Text {
throw new RangeError("A document must have at least one line");
if (text.length == 1 && !text[0])
return Text.empty;
return text.length <= 32 /* Branch */ ? new TextLeaf(text) : TextNode.from(TextLeaf.split(text, []));
return text.length <= 32 /* Tree.Branch */ ? new TextLeaf(text) : TextNode.from(TextLeaf.split(text, []));
}
}
// Leaves store an array of line strings. There are always line breaks
@ -146,10 +146,10 @@ class TextLeaf extends Text {
decompose(from, to, target, open) {
let text = from <= 0 && to >= this.length ? this
: new TextLeaf(sliceText(this.text, from, to), Math.min(to, this.length) - Math.max(0, from));
if (open & 1 /* From */) {
if (open & 1 /* Open.From */) {
let prev = target.pop();
let joined = appendText(text.text, prev.text.slice(), 0, text.length);
if (joined.length <= 32 /* Branch */) {
if (joined.length <= 32 /* Tree.Branch */) {
target.push(new TextLeaf(joined, prev.length + text.length));
}
else {
@ -166,7 +166,7 @@ class TextLeaf extends Text {
return super.replace(from, to, text);
let lines = appendText(this.text, appendText(text.text, sliceText(this.text, 0, from)), to);
let newLen = this.length + text.length - (to - from);
if (lines.length <= 32 /* Branch */)
if (lines.length <= 32 /* Tree.Branch */)
return new TextLeaf(lines, newLen);
return TextNode.from(TextLeaf.split(lines, []), newLen);
}
@ -192,7 +192,7 @@ class TextLeaf extends Text {
for (let line of text) {
part.push(line);
len += line.length + 1;
if (part.length == 32 /* Branch */) {
if (part.length == 32 /* Tree.Branch */) {
target.push(new TextLeaf(part, len));
part = [];
len = -1;
@ -229,7 +229,7 @@ class TextNode extends Text {
for (let i = 0, pos = 0; pos <= to && i < this.children.length; i++) {
let child = this.children[i], end = pos + child.length;
if (from <= end && to >= pos) {
let childOpen = open & ((pos <= from ? 1 /* From */ : 0) | (end >= to ? 2 /* To */ : 0));
let childOpen = open & ((pos <= from ? 1 /* Open.From */ : 0) | (end >= to ? 2 /* Open.To */ : 0));
if (pos >= from && end <= to && !childOpen)
target.push(child);
else
@ -248,8 +248,8 @@ class TextNode extends Text {
if (from >= pos && to <= end) {
let updated = child.replace(from - pos, to - pos, text);
let totalLines = this.lines - child.lines + updated.lines;
if (updated.lines < (totalLines >> (5 /* BranchShift */ - 1)) &&
updated.lines > (totalLines >> (5 /* BranchShift */ + 1))) {
if (updated.lines < (totalLines >> (5 /* Tree.BranchShift */ - 1)) &&
updated.lines > (totalLines >> (5 /* Tree.BranchShift */ + 1))) {
let copy = this.children.slice();
copy[i] = updated;
return new TextNode(copy, this.length - (to - from) + text.length);
@ -295,13 +295,13 @@ class TextNode extends Text {
let lines = 0;
for (let ch of children)
lines += ch.lines;
if (lines < 32 /* Branch */) {
if (lines < 32 /* Tree.Branch */) {
let flat = [];
for (let ch of children)
ch.flatten(flat);
return new TextLeaf(flat, length);
}
let chunk = Math.max(32 /* Branch */, lines >> 5 /* BranchShift */), maxChunk = chunk << 1, minChunk = chunk >> 1;
let chunk = Math.max(32 /* Tree.Branch */, lines >> 5 /* Tree.BranchShift */), maxChunk = chunk << 1, minChunk = chunk >> 1;
let chunked = [], currentLines = 0, currentLen = -1, currentChunk = [];
function add(child) {
let last;
@ -315,7 +315,7 @@ class TextNode extends Text {
}
else if (child instanceof TextLeaf && currentLines &&
(last = currentChunk[currentChunk.length - 1]) instanceof TextLeaf &&
child.lines + last.lines <= 32 /* Branch */) {
child.lines + last.lines <= 32 /* Tree.Branch */) {
currentLines += child.lines;
currentLen += child.length + 1;
currentChunk[currentChunk.length - 1] = new TextLeaf(last.text.concat(child.text), last.length + 1 + child.length);
@ -1125,51 +1125,65 @@ function iterChanges(desc, f, individual) {
}
}
function mapSet(setA, setB, before, mkSet = false) {
// Produce a copy of setA that applies to the document after setB
// has been applied (assuming both start at the same document).
let sections = [], insert = mkSet ? [] : null;
let a = new SectionIter(setA), b = new SectionIter(setB);
for (let posA = 0, posB = 0;;) {
if (a.ins == -1) {
posA += a.len;
a.next();
// Iterate over both sets in parallel. inserted tracks, for changes
// in A that have to be processed piece-by-piece, whether their
// content has been inserted already, and refers to the section
// index.
for (let inserted = -1;;) {
if (a.ins == -1 && b.ins == -1) {
// Move across ranges skipped by both sets.
let len = Math.min(a.len, b.len);
addSection(sections, len, -1);
a.forward(len);
b.forward(len);
}
else if (b.ins == -1 && posB < posA) {
let skip = Math.min(b.len, posA - posB);
b.forward(skip);
addSection(sections, skip, -1);
posB += skip;
}
else if (b.ins >= 0 && (a.done || posB < posA || posB == posA && (b.len < a.len || b.len == a.len && !before))) {
else if (b.ins >= 0 && (a.ins < 0 || inserted == a.i || a.off == 0 && (b.len < a.len || b.len == a.len && !before))) {
// If there's a change in B that comes before the next change in
// A (ordered by start pos, then len, then before flag), skip
// that (and process any changes in A it covers).
let len = b.len;
addSection(sections, b.ins, -1);
while (posA > posB && !a.done && posA + a.len < posB + b.len) {
posA += a.len;
a.next();
while (len) {
let piece = Math.min(a.len, len);
if (a.ins >= 0 && inserted < a.i && a.len <= piece) {
addSection(sections, 0, a.ins);
if (insert)
addInsert(insert, sections, a.text);
inserted = a.i;
}
a.forward(piece);
len -= piece;
}
posB += b.len;
b.next();
}
else if (a.ins >= 0) {
let len = 0, end = posA + a.len;
for (;;) {
if (b.ins >= 0 && posB > posA && posB + b.len < end) {
len += b.ins;
posB += b.len;
b.next();
// Process the part of a change in A up to the start of the next
// non-deletion change in B (if overlapping).
let len = 0, left = a.len;
while (left) {
if (b.ins == -1) {
let piece = Math.min(left, b.len);
len += piece;
left -= piece;
b.forward(piece);
}
else if (b.ins == -1 && posB < end) {
let skip = Math.min(b.len, end - posB);
len += skip;
b.forward(skip);
posB += skip;
else if (b.ins == 0 && b.len < left) {
left -= b.len;
b.next();
}
else {
break;
}
}
addSection(sections, len, a.ins);
if (insert)
addSection(sections, len, inserted < a.i ? a.ins : 0);
if (insert && inserted < a.i)
addInsert(insert, sections, a.text);
posA = end;
a.next();
inserted = a.i;
a.forward(a.len - left);
}
else if (a.done && b.done) {
return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);
@ -1297,12 +1311,12 @@ class SelectionRange {
The anchor of the rangethe side that doesn't move when you
extend it.
*/
get anchor() { return this.flags & 16 /* Inverted */ ? this.to : this.from; }
get anchor() { return this.flags & 16 /* RangeFlag.Inverted */ ? this.to : this.from; }
/**
The head of the range, which is moved when the range is
[extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
*/
get head() { return this.flags & 16 /* Inverted */ ? this.from : this.to; }
get head() { return this.flags & 16 /* RangeFlag.Inverted */ ? this.from : this.to; }
/**
True when `anchor` and `head` are at the same position.
*/
@ -1313,13 +1327,13 @@ class SelectionRange {
the character before its position, 1 the character after, and 0
means no association.
*/
get assoc() { return this.flags & 4 /* AssocBefore */ ? -1 : this.flags & 8 /* AssocAfter */ ? 1 : 0; }
get assoc() { return this.flags & 4 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 8 /* RangeFlag.AssocAfter */ ? 1 : 0; }
/**
The bidirectional text level associated with this cursor, if
any.
*/
get bidiLevel() {
let level = this.flags & 3 /* BidiLevelMask */;
let level = this.flags & 3 /* RangeFlag.BidiLevelMask */;
return level == 3 ? null : level;
}
/**
@ -1329,8 +1343,8 @@ class SelectionRange {
lines of different length.
*/
get goalColumn() {
let value = this.flags >> 5 /* GoalColumnOffset */;
return value == 33554431 /* NoGoalColumn */ ? undefined : value;
let value = this.flags >> 5 /* RangeFlag.GoalColumnOffset */;
return value == 33554431 /* RangeFlag.NoGoalColumn */ ? undefined : value;
}
/**
Map this range through a change, producing a valid range in the
@ -1490,17 +1504,18 @@ class EditorSelection {
safely ignore the optional arguments in most situations.
*/
static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 4 /* AssocBefore */ : 8 /* AssocAfter */) |
return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 4 /* RangeFlag.AssocBefore */ : 8 /* RangeFlag.AssocAfter */) |
(bidiLevel == null ? 3 : Math.min(2, bidiLevel)) |
((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */));
((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */));
}
/**
Create a selection range.
*/
static range(anchor, head, goalColumn) {
let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */;
return head < anchor ? SelectionRange.create(head, anchor, 16 /* Inverted */ | goal | 8 /* AssocAfter */)
: SelectionRange.create(anchor, head, goal | (head > anchor ? 4 /* AssocBefore */ : 0));
static range(anchor, head, goalColumn, bidiLevel) {
let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */) |
(bidiLevel == null ? 3 : Math.min(2, bidiLevel));
return head < anchor ? SelectionRange.create(head, anchor, 16 /* RangeFlag.Inverted */ | 8 /* RangeFlag.AssocAfter */ | flags)
: SelectionRange.create(anchor, head, (head > anchor ? 4 /* RangeFlag.AssocBefore */ : 0) | flags);
}
/**
@internal
@ -1551,21 +1566,17 @@ class Facet {
/**
@internal
*/
compare, isStatic,
/**
@internal
*/
extensions) {
compare, isStatic, enables) {
this.combine = combine;
this.compareInput = compareInput;
this.compare = compare;
this.isStatic = isStatic;
this.extensions = extensions;
/**
@internal
*/
this.id = nextID++;
this.default = combine([]);
this.extensions = typeof enables == "function" ? enables(this) : enables;
}
/**
Define a new facet.
@ -1577,7 +1588,7 @@ class Facet {
Returns an extension that adds the given value to this facet.
*/
of(value) {
return new FacetProvider([], this, 0 /* Static */, value);
return new FacetProvider([], this, 0 /* Provider.Static */, value);
}
/**
Create an extension that computes a value for the facet from a
@ -1591,7 +1602,7 @@ class Facet {
compute(deps, get) {
if (this.isStatic)
throw new Error("Can't compute a static facet");
return new FacetProvider(deps, this, 1 /* Single */, get);
return new FacetProvider(deps, this, 1 /* Provider.Single */, get);
}
/**
Create an extension that computes zero or more values for this
@ -1600,7 +1611,7 @@ class Facet {
computeN(deps, get) {
if (this.isStatic)
throw new Error("Can't compute a static facet");
return new FacetProvider(deps, this, 2 /* Multi */, get);
return new FacetProvider(deps, this, 2 /* Provider.Multi */, get);
}
from(field, get) {
if (!get)
@ -1623,7 +1634,7 @@ class FacetProvider {
var _a;
let getter = this.value;
let compare = this.facet.compareInput;
let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2 /* Multi */;
let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2 /* Provider.Multi */;
let depDoc = false, depSel = false, depAddrs = [];
for (let dep of this.dependencies) {
if (dep == "doc")
@ -1636,33 +1647,35 @@ class FacetProvider {
return {
create(state) {
state.values[idx] = getter(state);
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
},
update(state, tr) {
if ((depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) || ensureAll(state, depAddrs)) {
let newVal = getter(state);
if (multi ? !compareArray(newVal, state.values[idx], compare) : !compare(newVal, state.values[idx])) {
state.values[idx] = newVal;
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
}
}
return 0;
},
reconfigure: (state, oldState) => {
let newVal = getter(state);
let oldAddr = oldState.config.address[id];
let newVal, oldAddr = oldState.config.address[id];
if (oldAddr != null) {
let oldVal = getAddr(oldState, oldAddr);
if (this.dependencies.every(dep => {
return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) :
dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;
}) || (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal))) {
}) || (multi ? compareArray(newVal = getter(state), oldVal, compare) : compare(newVal = getter(state), oldVal))) {
state.values[idx] = oldVal;
return 0;
}
}
else {
newVal = getter(state);
}
state.values[idx] = newVal;
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
}
};
}
@ -1678,7 +1691,7 @@ function compareArray(a, b, compare) {
function ensureAll(state, addrs) {
let changed = false;
for (let addr of addrs)
if (ensureAddr(state, addr) & 1 /* Changed */)
if (ensureAddr(state, addr) & 1 /* SlotStatus.Changed */)
changed = true;
return changed;
}
@ -1691,7 +1704,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
let values = [];
for (let i = 0; i < providerAddrs.length; i++) {
let value = getAddr(state, providerAddrs[i]);
if (providerTypes[i] == 2 /* Multi */)
if (providerTypes[i] == 2 /* Provider.Multi */)
for (let val of value)
values.push(val);
else
@ -1704,7 +1717,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
for (let addr of providerAddrs)
ensureAddr(state, addr);
state.values[idx] = get(state);
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
},
update(state, tr) {
if (!ensureAll(state, dynamic))
@ -1713,7 +1726,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
if (facet.compare(value, state.values[idx]))
return 0;
state.values[idx] = value;
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
},
reconfigure(state, oldState) {
let depChanged = ensureAll(state, providerAddrs);
@ -1728,7 +1741,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
return 0;
}
state.values[idx] = value;
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
}
};
}
@ -1778,7 +1791,7 @@ class StateField {
return {
create: (state) => {
state.values[idx] = this.create(state);
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
},
update: (state, tr) => {
let oldVal = state.values[idx];
@ -1786,7 +1799,7 @@ class StateField {
if (this.compareF(oldVal, value))
return 0;
state.values[idx] = value;
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
},
reconfigure: (state, oldState) => {
if (oldState.config.address[this.id] != null) {
@ -1794,7 +1807,7 @@ class StateField {
return 0;
}
state.values[idx] = this.create(state);
return 1 /* Changed */;
return 1 /* SlotStatus.Changed */;
}
};
}
@ -1903,7 +1916,7 @@ class Configuration {
this.facets = facets;
this.statusTemplate = [];
while (this.statusTemplate.length < dynamicSlots.length)
this.statusTemplate.push(0 /* Unresolved */);
this.statusTemplate.push(0 /* SlotStatus.Unresolved */);
}
staticFacet(facet) {
let addr = this.address[facet.id];
@ -1930,7 +1943,7 @@ class Configuration {
for (let id in facets) {
let providers = facets[id], facet = providers[0].facet;
let oldProviders = oldFacets && oldFacets[id] || [];
if (providers.every(p => p.type == 0 /* Static */)) {
if (providers.every(p => p.type == 0 /* Provider.Static */)) {
address[facet.id] = (staticValues.length << 1) | 1;
if (sameArray(oldProviders, providers)) {
staticValues.push(oldState.facet(facet));
@ -1942,7 +1955,7 @@ class Configuration {
}
else {
for (let p of providers) {
if (p.type == 0 /* Static */) {
if (p.type == 0 /* Provider.Static */) {
address[p.id] = (staticValues.length << 1) | 1;
staticValues.push(p.value);
}
@ -1996,7 +2009,7 @@ function flatten(extension, compartments, newCompartments) {
else if (ext instanceof FacetProvider) {
result[prec].push(ext);
if (ext.facet.extensions)
inner(ext.facet.extensions, prec);
inner(ext.facet.extensions, Prec_.default);
}
else {
let content = ext.extension;
@ -2010,16 +2023,16 @@ function flatten(extension, compartments, newCompartments) {
}
function ensureAddr(state, addr) {
if (addr & 1)
return 2 /* Computed */;
return 2 /* SlotStatus.Computed */;
let idx = addr >> 1;
let status = state.status[idx];
if (status == 4 /* Computing */)
if (status == 4 /* SlotStatus.Computing */)
throw new Error("Cyclic dependency between fields and/or facets");
if (status & 2 /* Computed */)
if (status & 2 /* SlotStatus.Computed */)
return status;
state.status[idx] = 4 /* Computing */;
state.status[idx] = 4 /* SlotStatus.Computing */;
let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
return state.status[idx] = 2 /* Computed */ | changed;
return state.status[idx] = 2 /* SlotStatus.Computed */ | changed;
}
function getAddr(state, addr) {
return addr & 1 ? state.config.staticValues[addr >> 1] : state.values[addr >> 1];
@ -2434,7 +2447,7 @@ function filterTransaction(tr) {
else {
let filtered = tr.changes.filter(result);
changes = filtered.changes;
back = filtered.filtered.invertedDesc;
back = filtered.filtered.mapDesc(filtered.changes).invertedDesc;
}
tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
}
@ -2456,7 +2469,7 @@ function extendTransaction(tr) {
for (let i = extenders.length - 1; i >= 0; i--) {
let extension = extenders[i](tr);
if (extension && Object.keys(extension).length)
spec = mergeTransaction(tr, resolveTransactionInner(state, extension, tr.changes.newLength), true);
spec = mergeTransaction(spec, resolveTransactionInner(state, extension, tr.changes.newLength), true);
}
return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
}
@ -2706,7 +2719,7 @@ class EditorState {
if (fields)
for (let prop in fields) {
let value = fields[prop];
if (value instanceof StateField)
if (value instanceof StateField && this.config.address[value.id] != null)
result[prop] = value.spec.toJSON(this.field(fields[prop]), this);
}
return result;
@ -2723,8 +2736,10 @@ class EditorState {
let fieldInit = [];
if (fields)
for (let prop in fields) {
let field = fields[prop], value = json[prop];
fieldInit.push(field.init(state => field.spec.fromJSON(value, state)));
if (Object.prototype.hasOwnProperty.call(json, prop)) {
let field = fields[prop], value = json[prop];
fieldInit.push(field.init(state => field.spec.fromJSON(value, state)));
}
}
return EditorState.create({
doc: json.doc,
@ -2785,13 +2800,25 @@ class EditorState {
if (i == "$")
return "$";
let n = +(i || 1);
return n > insert.length ? m : insert[n - 1];
return !n || n > insert.length ? m : insert[n - 1];
});
return phrase;
}
/**
Find the values for a given language data field, provided by the
the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
Examples of language data fields are...
- [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
comment syntax.
- [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
for providing language-specific completion sources.
- [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
characters that should be considered part of words in this
language.
- [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
bracket closing behavior.
*/
languageDataAt(name, pos, side = -1) {
let values = [];
@ -3063,7 +3090,7 @@ class Chunk {
}
}
between(offset, from, to, f) {
for (let i = this.findIndex(from, -1000000000 /* Far */, true), e = this.findIndex(to, 1000000000 /* Far */, false, i); i < e; i++)
for (let i = this.findIndex(from, -1000000000 /* C.Far */, true), e = this.findIndex(to, 1000000000 /* C.Far */, false, i); i < e; i++)
if (f(this.from[i] + offset, this.to[i] + offset, this.value[i]) === false)
return false;
}
@ -3296,7 +3323,7 @@ class RangeSet {
*/
static eq(oldSets, newSets, from = 0, to) {
if (to == null)
to = 1000000000 /* Far */;
to = 1000000000 /* C.Far */ - 1;
let a = oldSets.filter(set => !set.isEmpty && newSets.indexOf(set) < 0);
let b = newSets.filter(set => !set.isEmpty && oldSets.indexOf(set) < 0);
if (a.length != b.length)
@ -3330,23 +3357,24 @@ class RangeSet {
*/
minPointSize = -1) {
let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;
let open = cursor.openStart;
let openRanges = cursor.openStart;
for (;;) {
let curTo = Math.min(cursor.to, to);
if (cursor.point) {
iterator.point(pos, curTo, cursor.point, cursor.activeForPoint(cursor.to), open, cursor.pointRank);
open = cursor.openEnd(curTo) + (cursor.to > curTo ? 1 : 0);
let active = cursor.activeForPoint(cursor.to);
let openCount = cursor.pointFrom < from ? active.length + 1 : Math.min(active.length, openRanges);
iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
openRanges = Math.min(cursor.openEnd(curTo), active.length);
}
else if (curTo > pos) {
iterator.span(pos, curTo, cursor.active, open);
open = cursor.openEnd(curTo);
iterator.span(pos, curTo, cursor.active, openRanges);
openRanges = cursor.openEnd(curTo);
}
if (cursor.to > to)
break;
return openRanges + (cursor.point && cursor.to > to ? 1 : 0);
pos = cursor.to;
cursor.next();
}
return open;
}
/**
Create a range set for the given range or array of ranges. By
@ -3391,8 +3419,8 @@ class RangeSetBuilder {
this.chunkPos = [];
this.chunkStart = -1;
this.last = null;
this.lastFrom = -1000000000 /* Far */;
this.lastTo = -1000000000 /* Far */;
this.lastFrom = -1000000000 /* C.Far */;
this.lastTo = -1000000000 /* C.Far */;
this.from = [];
this.to = [];
this.value = [];
@ -3429,7 +3457,7 @@ class RangeSetBuilder {
throw new Error("Ranges must be added sorted by `from` position and `startSide`");
if (diff < 0)
return false;
if (this.from.length == 250 /* ChunkSize */)
if (this.from.length == 250 /* C.ChunkSize */)
this.finishChunk(true);
if (this.chunkStart < 0)
this.chunkStart = from;
@ -3503,7 +3531,7 @@ class LayerCursor {
}
get startSide() { return this.value ? this.value.startSide : 0; }
get endSide() { return this.value ? this.value.endSide : 0; }
goto(pos, side = -1000000000 /* Far */) {
goto(pos, side = -1000000000 /* C.Far */) {
this.chunkIndex = this.rangeIndex = 0;
this.gotoInner(pos, side, false);
return this;
@ -3532,7 +3560,7 @@ class LayerCursor {
next() {
for (;;) {
if (this.chunkIndex == this.layer.chunk.length) {
this.from = this.to = 1000000000 /* Far */;
this.from = this.to = 1000000000 /* C.Far */;
this.value = null;
break;
}
@ -3586,7 +3614,7 @@ class HeapCursor {
return heap.length == 1 ? heap[0] : new HeapCursor(heap);
}
get startSide() { return this.value ? this.value.startSide : 0; }
goto(pos, side = -1000000000 /* Far */) {
goto(pos, side = -1000000000 /* C.Far */) {
for (let cur of this.heap)
cur.goto(pos, side);
for (let i = this.heap.length >> 1; i >= 0; i--)
@ -3604,7 +3632,7 @@ class HeapCursor {
}
next() {
if (this.heap.length == 0) {
this.from = this.to = 1000000000 /* Far */;
this.from = this.to = 1000000000 /* C.Far */;
this.value = null;
this.rank = -1;
}
@ -3648,12 +3676,14 @@ class SpanCursor {
this.point = null;
this.pointFrom = 0;
this.pointRank = 0;
this.to = -1000000000 /* Far */;
this.to = -1000000000 /* C.Far */;
this.endSide = 0;
// The amount of open active ranges at the start of the iterator.
// Not including points.
this.openStart = -1;
this.cursor = HeapCursor.from(sets, skip, minPoint);
}
goto(pos, side = -1000000000 /* Far */) {
goto(pos, side = -1000000000 /* C.Far */) {
this.cursor.goto(pos, side);
this.active.length = this.activeTo.length = this.activeRank.length = 0;
this.minActive = -1;
@ -3690,7 +3720,7 @@ class SpanCursor {
next() {
let from = this.to, wasPoint = this.point;
this.point = null;
let trackOpen = this.openStart < 0 ? [] : null, trackExtra = 0;
let trackOpen = this.openStart < 0 ? [] : null;
for (;;) {
let a = this.minActive;
if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {
@ -3704,7 +3734,7 @@ class SpanCursor {
remove(trackOpen, a);
}
else if (!this.cursor.value) {
this.to = this.endSide = 1000000000 /* Far */;
this.to = this.endSide = 1000000000 /* C.Far */;
break;
}
else if (this.cursor.from > from) {
@ -3728,8 +3758,6 @@ class SpanCursor {
this.pointRank = this.cursor.rank;
this.to = this.cursor.to;
this.endSide = nextVal.endSide;
if (this.cursor.from < from)
trackExtra = 1;
this.cursor.next();
this.forward(this.to, this.endSide);
break;
@ -3737,10 +3765,9 @@ class SpanCursor {
}
}
if (trackOpen) {
let openStart = 0;
while (openStart < trackOpen.length && trackOpen[openStart] < from)
openStart++;
this.openStart = openStart + trackExtra;
this.openStart = 0;
for (let i = trackOpen.length - 1; i >= 0 && trackOpen[i] < from; i--)
this.openStart++;
}
}
activeForPoint(to) {
@ -3807,7 +3834,7 @@ function insert(array, index, value) {
array[index] = value;
}
function findMinIndex(value, array) {
let found = -1, foundPos = 1000000000 /* Far */;
let found = -1, foundPos = 1000000000 /* C.Far */;
for (let i = 0; i < array.length; i++)
if ((array[i] - foundPos || value[i].endSide - value[found].endSide) < 0) {
found = i;