mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 10:49:36 +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
300
node_modules/@codemirror/language/dist/index.js
generated
vendored
300
node_modules/@codemirror/language/dist/index.js
generated
vendored
|
@ -1,6 +1,6 @@
|
|||
import { NodeProp, Tree, IterMode, TreeFragment, Parser, NodeType, NodeSet } from '@lezer/common';
|
||||
import { NodeProp, IterMode, Tree, TreeFragment, Parser, NodeType, NodeSet } from '@lezer/common';
|
||||
import { StateEffect, StateField, Facet, EditorState, countColumn, combineConfig, RangeSet, RangeSetBuilder, Prec } from '@codemirror/state';
|
||||
import { ViewPlugin, logException, Decoration, EditorView, WidgetType, gutter, GutterMarker } from '@codemirror/view';
|
||||
import { ViewPlugin, logException, EditorView, Decoration, WidgetType, gutter, GutterMarker } from '@codemirror/view';
|
||||
import { tags, tagHighlighter, highlightTree, styleTags } from '@lezer/highlight';
|
||||
import { StyleModule } from 'style-mod';
|
||||
|
||||
|
@ -45,8 +45,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.
|
||||
|
@ -134,8 +139,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;
|
||||
}
|
||||
/**
|
||||
|
@ -145,14 +150,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(); }
|
||||
}
|
||||
|
@ -174,7 +179,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
|
||||
|
@ -214,13 +225,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;
|
||||
|
@ -499,14 +510,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);
|
||||
}
|
||||
|
@ -523,14 +534,14 @@ Language.state = /*@__PURE__*/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)
|
||||
|
@ -553,7 +564,7 @@ const parseWorker = /*@__PURE__*/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);
|
||||
|
@ -569,19 +580,19 @@ const parseWorker = /*@__PURE__*/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();
|
||||
|
@ -612,11 +623,21 @@ const parseWorker = /*@__PURE__*/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 = /*@__PURE__*/Facet.define({
|
||||
combine(languages) { return languages.length ? languages[0] : null; },
|
||||
enables: [Language.state, parseWorker]
|
||||
enables: language => [
|
||||
Language.state,
|
||||
parseWorker,
|
||||
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
|
||||
|
@ -746,22 +767,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 = /*@__PURE__*/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 = /*@__PURE__*/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;
|
||||
}
|
||||
});
|
||||
/**
|
||||
|
@ -781,36 +807,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 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
|
||||
|
@ -907,8 +961,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 = /*@__PURE__*/new NodeProp();
|
||||
// Compute the indentation for a given position from the syntax tree.
|
||||
|
@ -1139,7 +1194,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)
|
||||
|
@ -1200,6 +1255,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 = /*@__PURE__*/StateField.define({
|
||||
create() {
|
||||
return Decoration.none;
|
||||
|
@ -1227,7 +1289,24 @@ const foldState = /*@__PURE__*/StateField.define({
|
|||
}
|
||||
return folded;
|
||||
},
|
||||
provide: f => EditorView.decorations.from(f)
|
||||
provide: f => 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 Decoration.set(ranges, true);
|
||||
}
|
||||
});
|
||||
/**
|
||||
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
||||
|
@ -1320,6 +1399,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.
|
||||
|
||||
|
@ -1475,7 +1589,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 = StyleModule.newName();
|
||||
|
@ -1486,7 +1605,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 = tagHighlighter(spec.map(style => ({
|
||||
this.style = tagHighlighter(specs.map(style => ({
|
||||
tag: style.tag,
|
||||
class: style.class || def(Object.assign({}, style, { tag: null }))
|
||||
})), {
|
||||
|
@ -1603,7 +1722,7 @@ A default highlight style (works well with light themes).
|
|||
*/
|
||||
const defaultHighlightStyle = /*@__PURE__*/HighlightStyle.define([
|
||||
{ tag: tags.meta,
|
||||
color: "#7a757a" },
|
||||
color: "#404740" },
|
||||
{ tag: tags.link,
|
||||
textDecoration: "underline" },
|
||||
{ tag: tags.heading,
|
||||
|
@ -1702,6 +1821,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 = /*@__PURE__*/new NodeProp();
|
||||
function matchingNodes(node, dir, brackets) {
|
||||
let byProp = node.prop(dir < 0 ? NodeProp.openedBy : NodeProp.closedBy);
|
||||
if (byProp)
|
||||
|
@ -1713,6 +1841,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`
|
||||
|
@ -1724,31 +1856,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());
|
||||
|
@ -1768,7 +1906,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++;
|
||||
|
@ -1819,10 +1957,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.
|
||||
*/
|
||||
|
@ -1923,7 +2062,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
|
||||
|
@ -1965,6 +2105,7 @@ class StringStream {
|
|||
|
||||
function fullParser(spec) {
|
||||
return {
|
||||
name: spec.name || "",
|
||||
token: spec.token,
|
||||
blankLine: spec.blankLine || (() => { }),
|
||||
startState: spec.startState || (() => true),
|
||||
|
@ -1984,6 +2125,7 @@ function defaultCopyState(state) {
|
|||
}
|
||||
return newState;
|
||||
}
|
||||
const IndentedFrom = /*@__PURE__*/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).
|
||||
|
@ -1997,7 +2139,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;
|
||||
|
@ -2014,7 +2156,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;
|
||||
|
@ -2023,12 +2172,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);
|
||||
}
|
||||
|
@ -2039,8 +2189,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; }
|
||||
}
|
||||
|
@ -2102,7 +2254,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;
|
||||
|
@ -2112,7 +2264,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)
|
||||
|
@ -2196,7 +2348,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;
|
||||
}
|
||||
}
|
||||
|
@ -2212,7 +2364,7 @@ class Parse {
|
|||
length: this.parsedPos - this.chunkStart,
|
||||
nodeSet,
|
||||
topID: 0,
|
||||
maxBufferLength: 2048 /* ChunkSize */,
|
||||
maxBufferLength: 2048 /* C.ChunkSize */,
|
||||
reused: this.chunkReused
|
||||
});
|
||||
tree = new Tree(tree.type, tree.children, tree.positions, tree.length, [[this.lang.stateAfter, this.lang.streamParser.copyState(this.state)]]);
|
||||
|
@ -2245,8 +2397,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"],
|
||||
|
@ -2307,4 +2459,4 @@ function docID(data) {
|
|||
return type;
|
||||
}
|
||||
|
||||
export { HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
|
||||
export { HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, TreeIndentContext, bracketMatching, bracketMatchingHandle, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentRange, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, toggleFold, unfoldAll, unfoldCode, unfoldEffect };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue