mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-04 18:29:39 +02:00
add p2p support for HLS https://github.com/Novage/p2p-media-loader
This commit is contained in:
parent
64c36d9f4e
commit
0d0338876d
1197 changed files with 121461 additions and 179724 deletions
298
node_modules/@codemirror/language/dist/index.cjs
generated
vendored
298
node_modules/@codemirror/language/dist/index.cjs
generated
vendored
|
@ -49,8 +49,13 @@ class Language {
|
|||
The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
|
||||
used for this language.
|
||||
*/
|
||||
data, parser, extraExtensions = []) {
|
||||
data, parser, extraExtensions = [],
|
||||
/**
|
||||
A language name.
|
||||
*/
|
||||
name = "") {
|
||||
this.data = data;
|
||||
this.name = name;
|
||||
// Kludge to define EditorState.tree as a debugging helper,
|
||||
// without the EditorState package actually knowing about
|
||||
// languages and lezer trees.
|
||||
|
@ -138,8 +143,8 @@ A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language)
|
|||
parsers.
|
||||
*/
|
||||
class LRLanguage extends Language {
|
||||
constructor(data, parser) {
|
||||
super(data, parser);
|
||||
constructor(data, parser, name) {
|
||||
super(data, parser, [], name);
|
||||
this.parser = parser;
|
||||
}
|
||||
/**
|
||||
|
@ -149,14 +154,14 @@ class LRLanguage extends Language {
|
|||
let data = defineLanguageFacet(spec.languageData);
|
||||
return new LRLanguage(data, spec.parser.configure({
|
||||
props: [languageDataProp.add(type => type.isTop ? data : undefined)]
|
||||
}));
|
||||
}), spec.name);
|
||||
}
|
||||
/**
|
||||
Create a new instance of this language with a reconfigured
|
||||
version of its parser.
|
||||
version of its parser and optionally a new name.
|
||||
*/
|
||||
configure(options) {
|
||||
return new LRLanguage(this.data, this.parser.configure(options));
|
||||
configure(options, name) {
|
||||
return new LRLanguage(this.data, this.parser.configure(options), name || this.name);
|
||||
}
|
||||
get allowsNesting() { return this.parser.hasWrappers(); }
|
||||
}
|
||||
|
@ -178,7 +183,13 @@ up to that point if the tree isn't already available.
|
|||
function ensureSyntaxTree(state, upto, timeout = 50) {
|
||||
var _a;
|
||||
let parse = (_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context;
|
||||
return !parse ? null : parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
|
||||
if (!parse)
|
||||
return null;
|
||||
let oldVieport = parse.viewport;
|
||||
parse.updateViewport({ from: 0, to: upto });
|
||||
let result = parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
|
||||
parse.updateViewport(oldVieport);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
Queries whether there is a full syntax tree available up to the
|
||||
|
@ -218,13 +229,13 @@ function syntaxParserRunning(view) {
|
|||
}
|
||||
// Lezer-style Input object for a Text document.
|
||||
class DocInput {
|
||||
constructor(doc, length = doc.length) {
|
||||
constructor(doc) {
|
||||
this.doc = doc;
|
||||
this.length = length;
|
||||
this.cursorPos = 0;
|
||||
this.string = "";
|
||||
this.cursor = doc.iter();
|
||||
}
|
||||
get length() { return this.doc.length; }
|
||||
syncTo(pos) {
|
||||
this.string = this.cursor.next(pos - this.cursorPos).value;
|
||||
this.cursorPos = pos + this.string.length;
|
||||
|
@ -503,14 +514,14 @@ class LanguageState {
|
|||
// state updates with parse work beyond the viewport.
|
||||
let upto = this.context.treeLen == tr.startState.doc.length ? undefined
|
||||
: Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
|
||||
if (!newCx.work(20 /* Apply */, upto))
|
||||
if (!newCx.work(20 /* Work.Apply */, upto))
|
||||
newCx.takeTree();
|
||||
return new LanguageState(newCx);
|
||||
}
|
||||
static init(state) {
|
||||
let vpTo = Math.min(3000 /* InitViewport */, state.doc.length);
|
||||
let vpTo = Math.min(3000 /* Work.InitViewport */, state.doc.length);
|
||||
let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
|
||||
if (!parseState.work(20 /* Apply */, vpTo))
|
||||
if (!parseState.work(20 /* Work.Apply */, vpTo))
|
||||
parseState.takeTree();
|
||||
return new LanguageState(parseState);
|
||||
}
|
||||
|
@ -527,14 +538,14 @@ Language.state = state.StateField.define({
|
|||
}
|
||||
});
|
||||
let requestIdle = (callback) => {
|
||||
let timeout = setTimeout(() => callback(), 500 /* MaxPause */);
|
||||
let timeout = setTimeout(() => callback(), 500 /* Work.MaxPause */);
|
||||
return () => clearTimeout(timeout);
|
||||
};
|
||||
if (typeof requestIdleCallback != "undefined")
|
||||
requestIdle = (callback) => {
|
||||
let idle = -1, timeout = setTimeout(() => {
|
||||
idle = requestIdleCallback(callback, { timeout: 500 /* MaxPause */ - 100 /* MinPause */ });
|
||||
}, 100 /* MinPause */);
|
||||
idle = requestIdleCallback(callback, { timeout: 500 /* Work.MaxPause */ - 100 /* Work.MinPause */ });
|
||||
}, 100 /* Work.MinPause */);
|
||||
return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
|
||||
};
|
||||
const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending)
|
||||
|
@ -557,7 +568,7 @@ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
|
|||
this.scheduleWork();
|
||||
if (update.docChanged) {
|
||||
if (this.view.hasFocus)
|
||||
this.chunkBudget += 50 /* ChangeBonus */;
|
||||
this.chunkBudget += 50 /* Work.ChangeBonus */;
|
||||
this.scheduleWork();
|
||||
}
|
||||
this.checkAsyncSchedule(cx);
|
||||
|
@ -573,19 +584,19 @@ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
|
|||
this.working = null;
|
||||
let now = Date.now();
|
||||
if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) { // Start a new chunk
|
||||
this.chunkEnd = now + 30000 /* ChunkTime */;
|
||||
this.chunkBudget = 3000 /* ChunkBudget */;
|
||||
this.chunkEnd = now + 30000 /* Work.ChunkTime */;
|
||||
this.chunkBudget = 3000 /* Work.ChunkBudget */;
|
||||
}
|
||||
if (this.chunkBudget <= 0)
|
||||
return; // No more budget
|
||||
let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
|
||||
if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* MaxParseAhead */))
|
||||
if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* Work.MaxParseAhead */))
|
||||
return;
|
||||
let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Slice */, deadline && !isInputPending ? Math.max(25 /* MinSlice */, deadline.timeRemaining() - 5) : 1e9);
|
||||
let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Work.Slice */, deadline && !isInputPending ? Math.max(25 /* Work.MinSlice */, deadline.timeRemaining() - 5) : 1e9);
|
||||
let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1000;
|
||||
let done = field.context.work(() => {
|
||||
return isInputPending && isInputPending() || Date.now() > endTime;
|
||||
}, vpTo + (viewportFirst ? 0 : 100000 /* MaxParseAhead */));
|
||||
}, vpTo + (viewportFirst ? 0 : 100000 /* Work.MaxParseAhead */));
|
||||
this.chunkBudget -= Date.now() - now;
|
||||
if (done || this.chunkBudget <= 0) {
|
||||
field.context.takeTree();
|
||||
|
@ -616,11 +627,21 @@ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
|
|||
eventHandlers: { focus() { this.scheduleWork(); } }
|
||||
});
|
||||
/**
|
||||
The facet used to associate a language with an editor state.
|
||||
The facet used to associate a language with an editor state. Used
|
||||
by `Language` object's `extension` property (so you don't need to
|
||||
manually wrap your languages in this). Can be used to access the
|
||||
current language on a state.
|
||||
*/
|
||||
const language = state.Facet.define({
|
||||
combine(languages) { return languages.length ? languages[0] : null; },
|
||||
enables: [Language.state, parseWorker]
|
||||
enables: language => [
|
||||
Language.state,
|
||||
parseWorker,
|
||||
view.EditorView.contentAttributes.compute([language], state => {
|
||||
let lang = state.facet(language);
|
||||
return lang && lang.name ? { "data-language": lang.name } : {};
|
||||
})
|
||||
]
|
||||
});
|
||||
/**
|
||||
This class bundles a [language](https://codemirror.net/6/docs/ref/#language.Language) with an
|
||||
|
@ -750,22 +771,27 @@ class LanguageDescription {
|
|||
|
||||
/**
|
||||
Facet that defines a way to provide a function that computes the
|
||||
appropriate indentation depth at the start of a given line, or
|
||||
`null` to indicate no appropriate indentation could be determined.
|
||||
appropriate indentation depth, as a column number (see
|
||||
[`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
|
||||
line. A return value of `null` indicates no indentation can be
|
||||
determined, and the line should inherit the indentation of the one
|
||||
above it. A return value of `undefined` defers to the next indent
|
||||
service.
|
||||
*/
|
||||
const indentService = state.Facet.define();
|
||||
/**
|
||||
Facet for overriding the unit by which indentation happens.
|
||||
Should be a string consisting either entirely of spaces or
|
||||
entirely of tabs. When not set, this defaults to 2 spaces.
|
||||
Facet for overriding the unit by which indentation happens. Should
|
||||
be a string consisting either entirely of the same whitespace
|
||||
character. When not set, this defaults to 2 spaces.
|
||||
*/
|
||||
const indentUnit = state.Facet.define({
|
||||
combine: values => {
|
||||
if (!values.length)
|
||||
return " ";
|
||||
if (!/^(?: +|\t+)$/.test(values[0]))
|
||||
let unit = values[0];
|
||||
if (!unit || /\S/.test(unit) || Array.from(unit).some(e => e != unit[0]))
|
||||
throw new Error("Invalid indent unit: " + JSON.stringify(values[0]));
|
||||
return values[0];
|
||||
return unit;
|
||||
}
|
||||
});
|
||||
/**
|
||||
|
@ -785,36 +811,64 @@ Will use tabs for as much of the columns as possible when the
|
|||
tabs.
|
||||
*/
|
||||
function indentString(state, cols) {
|
||||
let result = "", ts = state.tabSize;
|
||||
if (state.facet(indentUnit).charCodeAt(0) == 9)
|
||||
let result = "", ts = state.tabSize, ch = state.facet(indentUnit)[0];
|
||||
if (ch == "\t") {
|
||||
while (cols >= ts) {
|
||||
result += "\t";
|
||||
cols -= ts;
|
||||
}
|
||||
ch = " ";
|
||||
}
|
||||
for (let i = 0; i < cols; i++)
|
||||
result += " ";
|
||||
result += ch;
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
Get the indentation at the given position. Will first consult any
|
||||
[indent services](https://codemirror.net/6/docs/ref/#language.indentService) that are registered,
|
||||
and if none of those return an indentation, this will check the
|
||||
syntax tree for the [indent node prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp)
|
||||
and use that if found. Returns a number when an indentation could
|
||||
be determined, and null otherwise.
|
||||
Get the indentation, as a column number, at the given position.
|
||||
Will first consult any [indent services](https://codemirror.net/6/docs/ref/#language.indentService)
|
||||
that are registered, and if none of those return an indentation,
|
||||
this will check the syntax tree for the [indent node
|
||||
prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp) and use that if found. Returns a
|
||||
number when an indentation could be determined, and null
|
||||
otherwise.
|
||||
*/
|
||||
function getIndentation(context, pos) {
|
||||
if (context instanceof state.EditorState)
|
||||
context = new IndentContext(context);
|
||||
for (let service of context.state.facet(indentService)) {
|
||||
let result = service(context, pos);
|
||||
if (result != null)
|
||||
if (result !== undefined)
|
||||
return result;
|
||||
}
|
||||
let tree = syntaxTree(context.state);
|
||||
return tree ? syntaxIndentation(context, tree, pos) : null;
|
||||
}
|
||||
/**
|
||||
Create a change set that auto-indents all lines touched by the
|
||||
given document range.
|
||||
*/
|
||||
function indentRange(state, from, to) {
|
||||
let updated = Object.create(null);
|
||||
let context = new IndentContext(state, { overrideIndentation: start => { var _a; return (_a = updated[start]) !== null && _a !== void 0 ? _a : -1; } });
|
||||
let changes = [];
|
||||
for (let pos = from; pos <= to;) {
|
||||
let line = state.doc.lineAt(pos);
|
||||
pos = line.to + 1;
|
||||
let indent = getIndentation(context, line.from);
|
||||
if (indent == null)
|
||||
continue;
|
||||
if (!/\S/.test(line.text))
|
||||
indent = 0;
|
||||
let cur = /^\s*/.exec(line.text)[0];
|
||||
let norm = indentString(state, indent);
|
||||
if (cur != norm) {
|
||||
updated[line.from] = indent;
|
||||
changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
|
||||
}
|
||||
}
|
||||
return state.changes(changes);
|
||||
}
|
||||
/**
|
||||
Indentation contexts are used when calling [indentation
|
||||
services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
|
||||
useful in indentation logic, and can selectively override the
|
||||
|
@ -911,8 +965,9 @@ class IndentContext {
|
|||
/**
|
||||
A syntax tree node prop used to associate indentation strategies
|
||||
with node types. Such a strategy is a function from an indentation
|
||||
context to a column number or null, where null indicates that no
|
||||
definitive indentation can be determined.
|
||||
context to a column number (see also
|
||||
[`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)) or null, where null
|
||||
indicates that no definitive indentation can be determined.
|
||||
*/
|
||||
const indentNodeProp = new common.NodeProp();
|
||||
// Compute the indentation for a given position from the syntax tree.
|
||||
|
@ -1143,7 +1198,7 @@ function syntaxFolding(state, start, end) {
|
|||
let tree = syntaxTree(state);
|
||||
if (tree.length < end)
|
||||
return null;
|
||||
let inner = tree.resolveInner(end);
|
||||
let inner = tree.resolveInner(end, 1);
|
||||
let found = null;
|
||||
for (let cur = inner; cur; cur = cur.parent) {
|
||||
if (cur.to <= end || cur.from > end)
|
||||
|
@ -1204,6 +1259,13 @@ function selectedLines(view) {
|
|||
}
|
||||
return lines;
|
||||
}
|
||||
/**
|
||||
The state field that stores the folded ranges (as a [decoration
|
||||
set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
|
||||
[`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
|
||||
[`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
|
||||
state.
|
||||
*/
|
||||
const foldState = state.StateField.define({
|
||||
create() {
|
||||
return view.Decoration.none;
|
||||
|
@ -1231,7 +1293,24 @@ const foldState = state.StateField.define({
|
|||
}
|
||||
return folded;
|
||||
},
|
||||
provide: f => view.EditorView.decorations.from(f)
|
||||
provide: f => view.EditorView.decorations.from(f),
|
||||
toJSON(folded, state) {
|
||||
let ranges = [];
|
||||
folded.between(0, state.doc.length, (from, to) => { ranges.push(from, to); });
|
||||
return ranges;
|
||||
},
|
||||
fromJSON(value) {
|
||||
if (!Array.isArray(value) || value.length % 2)
|
||||
throw new RangeError("Invalid JSON for fold state");
|
||||
let ranges = [];
|
||||
for (let i = 0; i < value.length;) {
|
||||
let from = value[i++], to = value[i++];
|
||||
if (typeof from != "number" || typeof to != "number")
|
||||
throw new RangeError("Invalid JSON for fold state");
|
||||
ranges.push(foldWidget.range(from, to));
|
||||
}
|
||||
return view.Decoration.set(ranges, true);
|
||||
}
|
||||
});
|
||||
/**
|
||||
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
||||
|
@ -1324,6 +1403,41 @@ const unfoldAll = view => {
|
|||
view.dispatch({ effects });
|
||||
return true;
|
||||
};
|
||||
// Find the foldable region containing the given line, if one exists
|
||||
function foldableContainer(view, lineBlock) {
|
||||
// Look backwards through line blocks until we find a foldable region that
|
||||
// intersects with the line
|
||||
for (let line = lineBlock;;) {
|
||||
let foldableRegion = foldable(view.state, line.from, line.to);
|
||||
if (foldableRegion && foldableRegion.to > lineBlock.from)
|
||||
return foldableRegion;
|
||||
if (!line.from)
|
||||
return null;
|
||||
line = view.lineBlockAt(line.from - 1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
Toggle folding at cursors. Unfolds if there is an existing fold
|
||||
starting in that line, tries to find a foldable range around it
|
||||
otherwise.
|
||||
*/
|
||||
const toggleFold = (view) => {
|
||||
let effects = [];
|
||||
for (let line of selectedLines(view)) {
|
||||
let folded = findFold(view.state, line.from, line.to);
|
||||
if (folded) {
|
||||
effects.push(unfoldEffect.of(folded), announceFold(view, folded, false));
|
||||
}
|
||||
else {
|
||||
let foldRange = foldableContainer(view, line);
|
||||
if (foldRange)
|
||||
effects.push(foldEffect.of(foldRange), announceFold(view, foldRange));
|
||||
}
|
||||
}
|
||||
if (effects.length > 0)
|
||||
view.dispatch({ effects: maybeEnable(view.state, effects) });
|
||||
return !!effects.length;
|
||||
};
|
||||
/**
|
||||
Default fold-related key bindings.
|
||||
|
||||
|
@ -1479,7 +1593,12 @@ A highlight style associates CSS styles with higlighting
|
|||
[tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
|
||||
*/
|
||||
class HighlightStyle {
|
||||
constructor(spec, options) {
|
||||
constructor(
|
||||
/**
|
||||
The tag styles used to create this highlight style.
|
||||
*/
|
||||
specs, options) {
|
||||
this.specs = specs;
|
||||
let modSpec;
|
||||
function def(spec) {
|
||||
let cls = styleMod.StyleModule.newName();
|
||||
|
@ -1490,7 +1609,7 @@ class HighlightStyle {
|
|||
const scopeOpt = options.scope;
|
||||
this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data
|
||||
: scopeOpt ? (type) => type == scopeOpt : undefined;
|
||||
this.style = highlight.tagHighlighter(spec.map(style => ({
|
||||
this.style = highlight.tagHighlighter(specs.map(style => ({
|
||||
tag: style.tag,
|
||||
class: style.class || def(Object.assign({}, style, { tag: null }))
|
||||
})), {
|
||||
|
@ -1607,7 +1726,7 @@ A default highlight style (works well with light themes).
|
|||
*/
|
||||
const defaultHighlightStyle = HighlightStyle.define([
|
||||
{ tag: highlight.tags.meta,
|
||||
color: "#7a757a" },
|
||||
color: "#404740" },
|
||||
{ tag: highlight.tags.link,
|
||||
textDecoration: "underline" },
|
||||
{ tag: highlight.tags.heading,
|
||||
|
@ -1706,6 +1825,15 @@ highlighting style is used to indicate this.
|
|||
function bracketMatching(config = {}) {
|
||||
return [bracketMatchingConfig.of(config), bracketMatchingUnique];
|
||||
}
|
||||
/**
|
||||
When larger syntax nodes, such as HTML tags, are marked as
|
||||
opening/closing, it can be a bit messy to treat the whole node as
|
||||
a matchable bracket. This node prop allows you to define, for such
|
||||
a node, a ‘handle’—the part of the node that is highlighted, and
|
||||
that the cursor must be on to activate highlighting in the first
|
||||
place.
|
||||
*/
|
||||
const bracketMatchingHandle = new common.NodeProp();
|
||||
function matchingNodes(node, dir, brackets) {
|
||||
let byProp = node.prop(dir < 0 ? common.NodeProp.openedBy : common.NodeProp.closedBy);
|
||||
if (byProp)
|
||||
|
@ -1717,6 +1845,10 @@ function matchingNodes(node, dir, brackets) {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
function findHandle(node) {
|
||||
let hasHandle = node.type.prop(bracketMatchingHandle);
|
||||
return hasHandle ? hasHandle(node.node) : node;
|
||||
}
|
||||
/**
|
||||
Find the matching bracket for the token at `pos`, scanning
|
||||
direction `dir`. Only the `brackets` and `maxScanDistance`
|
||||
|
@ -1728,31 +1860,37 @@ function matchBrackets(state, pos, dir, config = {}) {
|
|||
let tree = syntaxTree(state), node = tree.resolveInner(pos, dir);
|
||||
for (let cur = node; cur; cur = cur.parent) {
|
||||
let matches = matchingNodes(cur.type, dir, brackets);
|
||||
if (matches && cur.from < cur.to)
|
||||
return matchMarkedBrackets(state, pos, dir, cur, matches, brackets);
|
||||
if (matches && cur.from < cur.to) {
|
||||
let handle = findHandle(cur);
|
||||
if (handle && (dir > 0 ? pos >= handle.from && pos < handle.to : pos > handle.from && pos <= handle.to))
|
||||
return matchMarkedBrackets(state, pos, dir, cur, handle, matches, brackets);
|
||||
}
|
||||
}
|
||||
return matchPlainBrackets(state, pos, dir, tree, node.type, maxScanDistance, brackets);
|
||||
}
|
||||
function matchMarkedBrackets(_state, _pos, dir, token, matching, brackets) {
|
||||
let parent = token.parent, firstToken = { from: token.from, to: token.to };
|
||||
function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, brackets) {
|
||||
let parent = token.parent, firstToken = { from: handle.from, to: handle.to };
|
||||
let depth = 0, cursor = parent === null || parent === void 0 ? void 0 : parent.cursor();
|
||||
if (cursor && (dir < 0 ? cursor.childBefore(token.from) : cursor.childAfter(token.to)))
|
||||
do {
|
||||
if (dir < 0 ? cursor.to <= token.from : cursor.from >= token.to) {
|
||||
if (depth == 0 && matching.indexOf(cursor.type.name) > -1 && cursor.from < cursor.to) {
|
||||
return { start: firstToken, end: { from: cursor.from, to: cursor.to }, matched: true };
|
||||
let endHandle = findHandle(cursor);
|
||||
return { start: firstToken, end: endHandle ? { from: endHandle.from, to: endHandle.to } : undefined, matched: true };
|
||||
}
|
||||
else if (matchingNodes(cursor.type, dir, brackets)) {
|
||||
depth++;
|
||||
}
|
||||
else if (matchingNodes(cursor.type, -dir, brackets)) {
|
||||
depth--;
|
||||
if (depth == 0)
|
||||
if (depth == 0) {
|
||||
let endHandle = findHandle(cursor);
|
||||
return {
|
||||
start: firstToken,
|
||||
end: cursor.from == cursor.to ? undefined : { from: cursor.from, to: cursor.to },
|
||||
end: endHandle && endHandle.from < endHandle.to ? { from: endHandle.from, to: endHandle.to } : undefined,
|
||||
matched: false
|
||||
};
|
||||
}
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
} while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
|
||||
|
@ -1772,7 +1910,7 @@ function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, b
|
|||
let basePos = pos + distance * dir;
|
||||
for (let pos = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos != end; pos += dir) {
|
||||
let found = brackets.indexOf(text[pos]);
|
||||
if (found < 0 || tree.resolve(basePos + pos, 1).type != tokenType)
|
||||
if (found < 0 || tree.resolveInner(basePos + pos, 1).type != tokenType)
|
||||
continue;
|
||||
if ((found % 2 == 0) == (dir > 0)) {
|
||||
depth++;
|
||||
|
@ -1823,10 +1961,11 @@ class StringStream {
|
|||
/**
|
||||
The current indent unit size.
|
||||
*/
|
||||
indentUnit) {
|
||||
indentUnit, overrideIndent) {
|
||||
this.string = string;
|
||||
this.tabSize = tabSize;
|
||||
this.indentUnit = indentUnit;
|
||||
this.overrideIndent = overrideIndent;
|
||||
/**
|
||||
The current position on the line.
|
||||
*/
|
||||
|
@ -1927,7 +2066,8 @@ class StringStream {
|
|||
Get the indentation column of the current line.
|
||||
*/
|
||||
indentation() {
|
||||
return countCol(this.string, null, this.tabSize);
|
||||
var _a;
|
||||
return (_a = this.overrideIndent) !== null && _a !== void 0 ? _a : countCol(this.string, null, this.tabSize);
|
||||
}
|
||||
/**
|
||||
Match the input against the given string or regular expression
|
||||
|
@ -1969,6 +2109,7 @@ class StringStream {
|
|||
|
||||
function fullParser(spec) {
|
||||
return {
|
||||
name: spec.name || "",
|
||||
token: spec.token,
|
||||
blankLine: spec.blankLine || (() => { }),
|
||||
startState: spec.startState || (() => true),
|
||||
|
@ -1988,6 +2129,7 @@ function defaultCopyState(state) {
|
|||
}
|
||||
return newState;
|
||||
}
|
||||
const IndentedFrom = new WeakMap();
|
||||
/**
|
||||
A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
|
||||
5-style [streaming parser](https://codemirror.net/6/docs/ref/#language.StreamParser).
|
||||
|
@ -2001,7 +2143,7 @@ class StreamLanguage extends Language {
|
|||
return new Parse(self, input, fragments, ranges);
|
||||
}
|
||||
};
|
||||
super(data, impl, [indentService.of((cx, pos) => this.getIndent(cx, pos))]);
|
||||
super(data, impl, [indentService.of((cx, pos) => this.getIndent(cx, pos))], parser.name);
|
||||
this.topNode = docID(data);
|
||||
self = this;
|
||||
this.streamParser = p;
|
||||
|
@ -2018,7 +2160,14 @@ class StreamLanguage extends Language {
|
|||
at = at.parent;
|
||||
if (!at)
|
||||
return null;
|
||||
let start = findState(this, tree, 0, at.from, pos), statePos, state;
|
||||
let from = undefined;
|
||||
let { overrideIndentation } = cx.options;
|
||||
if (overrideIndentation) {
|
||||
from = IndentedFrom.get(cx.state);
|
||||
if (from != null && from < pos - 1e4)
|
||||
from = undefined;
|
||||
}
|
||||
let start = findState(this, tree, 0, at.from, from !== null && from !== void 0 ? from : pos), statePos, state;
|
||||
if (start) {
|
||||
state = start.state;
|
||||
statePos = start.pos + 1;
|
||||
|
@ -2027,12 +2176,13 @@ class StreamLanguage extends Language {
|
|||
state = this.streamParser.startState(cx.unit);
|
||||
statePos = 0;
|
||||
}
|
||||
if (pos - statePos > 10000 /* MaxIndentScanDist */)
|
||||
if (pos - statePos > 10000 /* C.MaxIndentScanDist */)
|
||||
return null;
|
||||
while (statePos < pos) {
|
||||
let line = cx.state.doc.lineAt(statePos), end = Math.min(pos, line.to);
|
||||
if (line.length) {
|
||||
let stream = new StringStream(line.text, cx.state.tabSize, cx.unit);
|
||||
let indentation = overrideIndentation ? overrideIndentation(line.from) : -1;
|
||||
let stream = new StringStream(line.text, cx.state.tabSize, cx.unit, indentation < 0 ? undefined : indentation);
|
||||
while (stream.pos < end - line.from)
|
||||
readToken(this.streamParser.token, stream, state);
|
||||
}
|
||||
|
@ -2043,8 +2193,10 @@ class StreamLanguage extends Language {
|
|||
break;
|
||||
statePos = line.to + 1;
|
||||
}
|
||||
let { text } = cx.lineAt(pos);
|
||||
return this.streamParser.indent(state, /^\s*(.*)/.exec(text)[1], cx);
|
||||
let line = cx.lineAt(pos);
|
||||
if (overrideIndentation && from == null)
|
||||
IndentedFrom.set(cx.state, line.from);
|
||||
return this.streamParser.indent(state, /^\s*(.*)/.exec(line.text)[1], cx);
|
||||
}
|
||||
get allowsNesting() { return false; }
|
||||
}
|
||||
|
@ -2106,7 +2258,7 @@ class Parse {
|
|||
this.chunks.push(tree.children[i]);
|
||||
this.chunkPos.push(tree.positions[i]);
|
||||
}
|
||||
if (context && this.parsedPos < context.viewport.from - 100000 /* MaxDistanceBeforeViewport */) {
|
||||
if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */) {
|
||||
this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
|
||||
context.skipUntilInView(this.parsedPos, context.viewport.from);
|
||||
this.parsedPos = context.viewport.from;
|
||||
|
@ -2116,7 +2268,7 @@ class Parse {
|
|||
advance() {
|
||||
let context = ParseContext.get();
|
||||
let parseEnd = this.stoppedAt == null ? this.to : Math.min(this.to, this.stoppedAt);
|
||||
let end = Math.min(parseEnd, this.chunkStart + 2048 /* ChunkSize */);
|
||||
let end = Math.min(parseEnd, this.chunkStart + 2048 /* C.ChunkSize */);
|
||||
if (context)
|
||||
end = Math.min(end, context.viewport.to);
|
||||
while (this.parsedPos < end)
|
||||
|
@ -2200,7 +2352,7 @@ class Parse {
|
|||
let token = readToken(streamParser.token, stream, this.state);
|
||||
if (token)
|
||||
offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start, this.parsedPos + stream.pos, 4, offset);
|
||||
if (stream.start > 10000 /* MaxLineLength */)
|
||||
if (stream.start > 10000 /* C.MaxLineLength */)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2216,7 +2368,7 @@ class Parse {
|
|||
length: this.parsedPos - this.chunkStart,
|
||||
nodeSet,
|
||||
topID: 0,
|
||||
maxBufferLength: 2048 /* ChunkSize */,
|
||||
maxBufferLength: 2048 /* C.ChunkSize */,
|
||||
reused: this.chunkReused
|
||||
});
|
||||
tree = new common.Tree(tree.type, tree.children, tree.positions, tree.length, [[this.lang.stateAfter, this.lang.streamParser.copyState(this.state)]]);
|
||||
|
@ -2249,8 +2401,8 @@ for (let [legacyName, name] of [
|
|||
["variable-2", "variableName.special"],
|
||||
["string-2", "string.special"],
|
||||
["def", "variableName.definition"],
|
||||
["tag", "typeName"],
|
||||
["attribute", "propertyName"],
|
||||
["tag", "tagName"],
|
||||
["attribute", "attributeName"],
|
||||
["type", "typeName"],
|
||||
["builtin", "variableName.standard"],
|
||||
["qualifier", "modifier"],
|
||||
|
@ -2322,6 +2474,7 @@ exports.StreamLanguage = StreamLanguage;
|
|||
exports.StringStream = StringStream;
|
||||
exports.TreeIndentContext = TreeIndentContext;
|
||||
exports.bracketMatching = bracketMatching;
|
||||
exports.bracketMatchingHandle = bracketMatchingHandle;
|
||||
exports.codeFolding = codeFolding;
|
||||
exports.continuedIndent = continuedIndent;
|
||||
exports.defaultHighlightStyle = defaultHighlightStyle;
|
||||
|
@ -2337,6 +2490,7 @@ exports.foldInside = foldInside;
|
|||
exports.foldKeymap = foldKeymap;
|
||||
exports.foldNodeProp = foldNodeProp;
|
||||
exports.foldService = foldService;
|
||||
exports.foldState = foldState;
|
||||
exports.foldable = foldable;
|
||||
exports.foldedRanges = foldedRanges;
|
||||
exports.forceParsing = forceParsing;
|
||||
|
@ -2345,6 +2499,7 @@ exports.getIndentation = getIndentation;
|
|||
exports.highlightingFor = highlightingFor;
|
||||
exports.indentNodeProp = indentNodeProp;
|
||||
exports.indentOnInput = indentOnInput;
|
||||
exports.indentRange = indentRange;
|
||||
exports.indentService = indentService;
|
||||
exports.indentString = indentString;
|
||||
exports.indentUnit = indentUnit;
|
||||
|
@ -2355,6 +2510,7 @@ exports.syntaxHighlighting = syntaxHighlighting;
|
|||
exports.syntaxParserRunning = syntaxParserRunning;
|
||||
exports.syntaxTree = syntaxTree;
|
||||
exports.syntaxTreeAvailable = syntaxTreeAvailable;
|
||||
exports.toggleFold = toggleFold;
|
||||
exports.unfoldAll = unfoldAll;
|
||||
exports.unfoldCode = unfoldCode;
|
||||
exports.unfoldEffect = unfoldEffect;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue