@vuu-ui/vuu-codemirror 0.8.34 → 0.8.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +0 -0
  2. package/cjs/codemirror-basic-setup.js +22 -0
  3. package/cjs/codemirror-basic-setup.js.map +1 -0
  4. package/cjs/index.js +118 -0
  5. package/cjs/{packages/vuu-codemirror/src/index.js.map → index.js.map} +1 -1
  6. package/cjs/parser-utils.js.map +1 -0
  7. package/cjs/{packages/vuu-codemirror/src/suggestion-utils.js → suggestion-utils.js} +2 -2
  8. package/cjs/suggestion-utils.js.map +1 -0
  9. package/esm/codemirror-basic-setup.js +20 -0
  10. package/esm/codemirror-basic-setup.js.map +1 -0
  11. package/esm/{packages/vuu-codemirror/src/index.js → index.js} +6 -6
  12. package/esm/parser-utils.js.map +1 -0
  13. package/esm/{packages/vuu-codemirror/src/suggestion-utils.js → suggestion-utils.js} +1 -1
  14. package/esm/suggestion-utils.js.map +1 -0
  15. package/package.json +5 -4
  16. package/types/index.d.ts +3 -3
  17. package/cjs/node_modules/@codemirror/autocomplete/dist/index.js +0 -1519
  18. package/cjs/node_modules/@codemirror/autocomplete/dist/index.js.map +0 -1
  19. package/cjs/node_modules/@codemirror/commands/dist/index.js +0 -1476
  20. package/cjs/node_modules/@codemirror/commands/dist/index.js.map +0 -1
  21. package/cjs/node_modules/@codemirror/language/dist/index.js +0 -1308
  22. package/cjs/node_modules/@codemirror/language/dist/index.js.map +0 -1
  23. package/cjs/node_modules/@codemirror/state/dist/index.js +0 -3915
  24. package/cjs/node_modules/@codemirror/state/dist/index.js.map +0 -1
  25. package/cjs/node_modules/@codemirror/view/dist/index.js +0 -8716
  26. package/cjs/node_modules/@codemirror/view/dist/index.js.map +0 -1
  27. package/cjs/node_modules/@lezer/common/dist/index.js +0 -1336
  28. package/cjs/node_modules/@lezer/common/dist/index.js.map +0 -1
  29. package/cjs/node_modules/style-mod/src/style-mod.js +0 -165
  30. package/cjs/node_modules/style-mod/src/style-mod.js.map +0 -1
  31. package/cjs/node_modules/w3c-keyname/index.js +0 -126
  32. package/cjs/node_modules/w3c-keyname/index.js.map +0 -1
  33. package/cjs/packages/vuu-codemirror/src/codemirror-basic-setup.js +0 -22
  34. package/cjs/packages/vuu-codemirror/src/codemirror-basic-setup.js.map +0 -1
  35. package/cjs/packages/vuu-codemirror/src/index.js +0 -58
  36. package/cjs/packages/vuu-codemirror/src/parser-utils.js.map +0 -1
  37. package/cjs/packages/vuu-codemirror/src/suggestion-utils.js.map +0 -1
  38. package/esm/node_modules/@codemirror/autocomplete/dist/index.js +0 -1506
  39. package/esm/node_modules/@codemirror/autocomplete/dist/index.js.map +0 -1
  40. package/esm/node_modules/@codemirror/commands/dist/index.js +0 -1401
  41. package/esm/node_modules/@codemirror/commands/dist/index.js.map +0 -1
  42. package/esm/node_modules/@codemirror/language/dist/index.js +0 -1283
  43. package/esm/node_modules/@codemirror/language/dist/index.js.map +0 -1
  44. package/esm/node_modules/@codemirror/state/dist/index.js +0 -3887
  45. package/esm/node_modules/@codemirror/state/dist/index.js.map +0 -1
  46. package/esm/node_modules/@codemirror/view/dist/index.js +0 -8698
  47. package/esm/node_modules/@codemirror/view/dist/index.js.map +0 -1
  48. package/esm/node_modules/@lezer/common/dist/index.js +0 -1327
  49. package/esm/node_modules/@lezer/common/dist/index.js.map +0 -1
  50. package/esm/node_modules/style-mod/src/style-mod.js +0 -163
  51. package/esm/node_modules/style-mod/src/style-mod.js.map +0 -1
  52. package/esm/node_modules/w3c-keyname/index.js +0 -122
  53. package/esm/node_modules/w3c-keyname/index.js.map +0 -1
  54. package/esm/packages/vuu-codemirror/src/codemirror-basic-setup.js +0 -20
  55. package/esm/packages/vuu-codemirror/src/codemirror-basic-setup.js.map +0 -1
  56. package/esm/packages/vuu-codemirror/src/parser-utils.js.map +0 -1
  57. package/esm/packages/vuu-codemirror/src/suggestion-utils.js.map +0 -1
  58. /package/cjs/{packages/vuu-codemirror/src/parser-utils.js → parser-utils.js} +0 -0
  59. /package/esm/{packages/vuu-codemirror/src/index.js.map → index.js.map} +0 -0
  60. /package/esm/{packages/vuu-codemirror/src/parser-utils.js → parser-utils.js} +0 -0
@@ -1,1308 +0,0 @@
1
- 'use strict';
2
-
3
- var index = require('../../../@lezer/common/dist/index.js');
4
- var index$1 = require('../../state/dist/index.js');
5
- var index$2 = require('../../view/dist/index.js');
6
- var highlight = require('@lezer/highlight');
7
- var styleMod = require('../../../style-mod/src/style-mod.js');
8
-
9
- var _a;
10
- /**
11
- Node prop stored in a parser's top syntax node to provide the
12
- facet that stores language-specific data for that language.
13
- */
14
- const languageDataProp = /*@__PURE__*/new index.NodeProp();
15
- /**
16
- Helper function to define a facet (to be added to the top syntax
17
- node(s) for a language via
18
- [`languageDataProp`](https://codemirror.net/6/docs/ref/#language.languageDataProp)), that will be
19
- used to associate language data with the language. You
20
- probably only need this when subclassing
21
- [`Language`](https://codemirror.net/6/docs/ref/#language.Language).
22
- */
23
- function defineLanguageFacet(baseData) {
24
- return index$1.Facet.define({
25
- combine: baseData ? values => values.concat(baseData) : undefined
26
- });
27
- }
28
- /**
29
- Syntax node prop used to register sublanguages. Should be added to
30
- the top level node type for the language.
31
- */
32
- const sublanguageProp = /*@__PURE__*/new index.NodeProp();
33
- /**
34
- A language object manages parsing and per-language
35
- [metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
36
- managed as a [Lezer](https://lezer.codemirror.net) tree. The class
37
- can be used directly, via the [`LRLanguage`](https://codemirror.net/6/docs/ref/#language.LRLanguage)
38
- subclass for [Lezer](https://lezer.codemirror.net/) LR parsers, or
39
- via the [`StreamLanguage`](https://codemirror.net/6/docs/ref/#language.StreamLanguage) subclass
40
- for stream parsers.
41
- */
42
- class Language {
43
- /**
44
- Construct a language object. If you need to invoke this
45
- directly, first define a data facet with
46
- [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
47
- configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
48
- to the language's outer syntax node.
49
- */
50
- constructor(
51
- /**
52
- The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
53
- used for this language.
54
- */
55
- data, parser, extraExtensions = [],
56
- /**
57
- A language name.
58
- */
59
- name = "") {
60
- this.data = data;
61
- this.name = name;
62
- // Kludge to define EditorState.tree as a debugging helper,
63
- // without the EditorState package actually knowing about
64
- // languages and lezer trees.
65
- if (!index$1.EditorState.prototype.hasOwnProperty("tree"))
66
- Object.defineProperty(index$1.EditorState.prototype, "tree", { get() { return syntaxTree(this); } });
67
- this.parser = parser;
68
- this.extension = [
69
- language.of(this),
70
- index$1.EditorState.languageData.of((state, pos, side) => {
71
- let top = topNodeAt(state, pos, side), data = top.type.prop(languageDataProp);
72
- if (!data)
73
- return [];
74
- let base = state.facet(data), sub = top.type.prop(sublanguageProp);
75
- if (sub) {
76
- let innerNode = top.resolve(pos - top.from, side);
77
- for (let sublang of sub)
78
- if (sublang.test(innerNode, state)) {
79
- let data = state.facet(sublang.facet);
80
- return sublang.type == "replace" ? data : data.concat(base);
81
- }
82
- }
83
- return base;
84
- })
85
- ].concat(extraExtensions);
86
- }
87
- /**
88
- Query whether this language is active at the given position.
89
- */
90
- isActiveAt(state, pos, side = -1) {
91
- return topNodeAt(state, pos, side).type.prop(languageDataProp) == this.data;
92
- }
93
- /**
94
- Find the document regions that were parsed using this language.
95
- The returned regions will _include_ any nested languages rooted
96
- in this language, when those exist.
97
- */
98
- findRegions(state) {
99
- let lang = state.facet(language);
100
- if ((lang === null || lang === void 0 ? void 0 : lang.data) == this.data)
101
- return [{ from: 0, to: state.doc.length }];
102
- if (!lang || !lang.allowsNesting)
103
- return [];
104
- let result = [];
105
- let explore = (tree, from) => {
106
- if (tree.prop(languageDataProp) == this.data) {
107
- result.push({ from, to: from + tree.length });
108
- return;
109
- }
110
- let mount = tree.prop(index.NodeProp.mounted);
111
- if (mount) {
112
- if (mount.tree.prop(languageDataProp) == this.data) {
113
- if (mount.overlay)
114
- for (let r of mount.overlay)
115
- result.push({ from: r.from + from, to: r.to + from });
116
- else
117
- result.push({ from: from, to: from + tree.length });
118
- return;
119
- }
120
- else if (mount.overlay) {
121
- let size = result.length;
122
- explore(mount.tree, mount.overlay[0].from + from);
123
- if (result.length > size)
124
- return;
125
- }
126
- }
127
- for (let i = 0; i < tree.children.length; i++) {
128
- let ch = tree.children[i];
129
- if (ch instanceof index.Tree)
130
- explore(ch, tree.positions[i] + from);
131
- }
132
- };
133
- explore(syntaxTree(state), 0);
134
- return result;
135
- }
136
- /**
137
- Indicates whether this language allows nested languages. The
138
- default implementation returns true.
139
- */
140
- get allowsNesting() { return true; }
141
- }
142
- /**
143
- @internal
144
- */
145
- Language.setState = /*@__PURE__*/index$1.StateEffect.define();
146
- function topNodeAt(state, pos, side) {
147
- let topLang = state.facet(language), tree = syntaxTree(state).topNode;
148
- if (!topLang || topLang.allowsNesting) {
149
- for (let node = tree; node; node = node.enter(pos, side, index.IterMode.ExcludeBuffers))
150
- if (node.type.isTop)
151
- tree = node;
152
- }
153
- return tree;
154
- }
155
- /**
156
- A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language) for use with Lezer
157
- [LR parsers](https://lezer.codemirror.net/docs/ref#lr.LRParser)
158
- parsers.
159
- */
160
- class LRLanguage extends Language {
161
- constructor(data, parser, name) {
162
- super(data, parser, [], name);
163
- this.parser = parser;
164
- }
165
- /**
166
- Define a language from a parser.
167
- */
168
- static define(spec) {
169
- let data = defineLanguageFacet(spec.languageData);
170
- return new LRLanguage(data, spec.parser.configure({
171
- props: [languageDataProp.add(type => type.isTop ? data : undefined)]
172
- }), spec.name);
173
- }
174
- /**
175
- Create a new instance of this language with a reconfigured
176
- version of its parser and optionally a new name.
177
- */
178
- configure(options, name) {
179
- return new LRLanguage(this.data, this.parser.configure(options), name || this.name);
180
- }
181
- get allowsNesting() { return this.parser.hasWrappers(); }
182
- }
183
- /**
184
- Get the syntax tree for a state, which is the current (possibly
185
- incomplete) parse tree of the active
186
- [language](https://codemirror.net/6/docs/ref/#language.Language), or the empty tree if there is no
187
- language available.
188
- */
189
- function syntaxTree(state) {
190
- let field = state.field(Language.state, false);
191
- return field ? field.tree : index.Tree.empty;
192
- }
193
- /**
194
- Try to get a parse tree that spans at least up to `upto`. The
195
- method will do at most `timeout` milliseconds of work to parse
196
- up to that point if the tree isn't already available.
197
- */
198
- function ensureSyntaxTree(state, upto, timeout = 50) {
199
- var _a;
200
- let parse = (_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context;
201
- if (!parse)
202
- return null;
203
- let oldVieport = parse.viewport;
204
- parse.updateViewport({ from: 0, to: upto });
205
- let result = parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
206
- parse.updateViewport(oldVieport);
207
- return result;
208
- }
209
- /**
210
- Lezer-style
211
- [`Input`](https://lezer.codemirror.net/docs/ref#common.Input)
212
- object for a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) object.
213
- */
214
- class DocInput {
215
- /**
216
- Create an input object for the given document.
217
- */
218
- constructor(doc) {
219
- this.doc = doc;
220
- this.cursorPos = 0;
221
- this.string = "";
222
- this.cursor = doc.iter();
223
- }
224
- get length() { return this.doc.length; }
225
- syncTo(pos) {
226
- this.string = this.cursor.next(pos - this.cursorPos).value;
227
- this.cursorPos = pos + this.string.length;
228
- return this.cursorPos - this.string.length;
229
- }
230
- chunk(pos) {
231
- this.syncTo(pos);
232
- return this.string;
233
- }
234
- get lineChunks() { return true; }
235
- read(from, to) {
236
- let stringStart = this.cursorPos - this.string.length;
237
- if (from < stringStart || to >= this.cursorPos)
238
- return this.doc.sliceString(from, to);
239
- else
240
- return this.string.slice(from - stringStart, to - stringStart);
241
- }
242
- }
243
- let currentContext = null;
244
- /**
245
- A parse context provided to parsers working on the editor content.
246
- */
247
- class ParseContext {
248
- constructor(parser,
249
- /**
250
- The current editor state.
251
- */
252
- state,
253
- /**
254
- Tree fragments that can be reused by incremental re-parses.
255
- */
256
- fragments = [],
257
- /**
258
- @internal
259
- */
260
- tree,
261
- /**
262
- @internal
263
- */
264
- treeLen,
265
- /**
266
- The current editor viewport (or some overapproximation
267
- thereof). Intended to be used for opportunistically avoiding
268
- work (in which case
269
- [`skipUntilInView`](https://codemirror.net/6/docs/ref/#language.ParseContext.skipUntilInView)
270
- should be called to make sure the parser is restarted when the
271
- skipped region becomes visible).
272
- */
273
- viewport,
274
- /**
275
- @internal
276
- */
277
- skipped,
278
- /**
279
- This is where skipping parsers can register a promise that,
280
- when resolved, will schedule a new parse. It is cleared when
281
- the parse worker picks up the promise. @internal
282
- */
283
- scheduleOn) {
284
- this.parser = parser;
285
- this.state = state;
286
- this.fragments = fragments;
287
- this.tree = tree;
288
- this.treeLen = treeLen;
289
- this.viewport = viewport;
290
- this.skipped = skipped;
291
- this.scheduleOn = scheduleOn;
292
- this.parse = null;
293
- /**
294
- @internal
295
- */
296
- this.tempSkipped = [];
297
- }
298
- /**
299
- @internal
300
- */
301
- static create(parser, state, viewport) {
302
- return new ParseContext(parser, state, [], index.Tree.empty, 0, viewport, [], null);
303
- }
304
- startParse() {
305
- return this.parser.startParse(new DocInput(this.state.doc), this.fragments);
306
- }
307
- /**
308
- @internal
309
- */
310
- work(until, upto) {
311
- if (upto != null && upto >= this.state.doc.length)
312
- upto = undefined;
313
- if (this.tree != index.Tree.empty && this.isDone(upto !== null && upto !== void 0 ? upto : this.state.doc.length)) {
314
- this.takeTree();
315
- return true;
316
- }
317
- return this.withContext(() => {
318
- var _a;
319
- if (typeof until == "number") {
320
- let endTime = Date.now() + until;
321
- until = () => Date.now() > endTime;
322
- }
323
- if (!this.parse)
324
- this.parse = this.startParse();
325
- if (upto != null && (this.parse.stoppedAt == null || this.parse.stoppedAt > upto) &&
326
- upto < this.state.doc.length)
327
- this.parse.stopAt(upto);
328
- for (;;) {
329
- let done = this.parse.advance();
330
- if (done) {
331
- this.fragments = this.withoutTempSkipped(index.TreeFragment.addTree(done, this.fragments, this.parse.stoppedAt != null));
332
- this.treeLen = (_a = this.parse.stoppedAt) !== null && _a !== void 0 ? _a : this.state.doc.length;
333
- this.tree = done;
334
- this.parse = null;
335
- if (this.treeLen < (upto !== null && upto !== void 0 ? upto : this.state.doc.length))
336
- this.parse = this.startParse();
337
- else
338
- return true;
339
- }
340
- if (until())
341
- return false;
342
- }
343
- });
344
- }
345
- /**
346
- @internal
347
- */
348
- takeTree() {
349
- let pos, tree;
350
- if (this.parse && (pos = this.parse.parsedPos) >= this.treeLen) {
351
- if (this.parse.stoppedAt == null || this.parse.stoppedAt > pos)
352
- this.parse.stopAt(pos);
353
- this.withContext(() => { while (!(tree = this.parse.advance())) { } });
354
- this.treeLen = pos;
355
- this.tree = tree;
356
- this.fragments = this.withoutTempSkipped(index.TreeFragment.addTree(this.tree, this.fragments, true));
357
- this.parse = null;
358
- }
359
- }
360
- withContext(f) {
361
- let prev = currentContext;
362
- currentContext = this;
363
- try {
364
- return f();
365
- }
366
- finally {
367
- currentContext = prev;
368
- }
369
- }
370
- withoutTempSkipped(fragments) {
371
- for (let r; r = this.tempSkipped.pop();)
372
- fragments = cutFragments(fragments, r.from, r.to);
373
- return fragments;
374
- }
375
- /**
376
- @internal
377
- */
378
- changes(changes, newState) {
379
- let { fragments, tree, treeLen, viewport, skipped } = this;
380
- this.takeTree();
381
- if (!changes.empty) {
382
- let ranges = [];
383
- changes.iterChangedRanges((fromA, toA, fromB, toB) => ranges.push({ fromA, toA, fromB, toB }));
384
- fragments = index.TreeFragment.applyChanges(fragments, ranges);
385
- tree = index.Tree.empty;
386
- treeLen = 0;
387
- viewport = { from: changes.mapPos(viewport.from, -1), to: changes.mapPos(viewport.to, 1) };
388
- if (this.skipped.length) {
389
- skipped = [];
390
- for (let r of this.skipped) {
391
- let from = changes.mapPos(r.from, 1), to = changes.mapPos(r.to, -1);
392
- if (from < to)
393
- skipped.push({ from, to });
394
- }
395
- }
396
- }
397
- return new ParseContext(this.parser, newState, fragments, tree, treeLen, viewport, skipped, this.scheduleOn);
398
- }
399
- /**
400
- @internal
401
- */
402
- updateViewport(viewport) {
403
- if (this.viewport.from == viewport.from && this.viewport.to == viewport.to)
404
- return false;
405
- this.viewport = viewport;
406
- let startLen = this.skipped.length;
407
- for (let i = 0; i < this.skipped.length; i++) {
408
- let { from, to } = this.skipped[i];
409
- if (from < viewport.to && to > viewport.from) {
410
- this.fragments = cutFragments(this.fragments, from, to);
411
- this.skipped.splice(i--, 1);
412
- }
413
- }
414
- if (this.skipped.length >= startLen)
415
- return false;
416
- this.reset();
417
- return true;
418
- }
419
- /**
420
- @internal
421
- */
422
- reset() {
423
- if (this.parse) {
424
- this.takeTree();
425
- this.parse = null;
426
- }
427
- }
428
- /**
429
- Notify the parse scheduler that the given region was skipped
430
- because it wasn't in view, and the parse should be restarted
431
- when it comes into view.
432
- */
433
- skipUntilInView(from, to) {
434
- this.skipped.push({ from, to });
435
- }
436
- /**
437
- Returns a parser intended to be used as placeholder when
438
- asynchronously loading a nested parser. It'll skip its input and
439
- mark it as not-really-parsed, so that the next update will parse
440
- it again.
441
-
442
- When `until` is given, a reparse will be scheduled when that
443
- promise resolves.
444
- */
445
- static getSkippingParser(until) {
446
- return new class extends index.Parser {
447
- createParse(input, fragments, ranges) {
448
- let from = ranges[0].from, to = ranges[ranges.length - 1].to;
449
- let parser = {
450
- parsedPos: from,
451
- advance() {
452
- let cx = currentContext;
453
- if (cx) {
454
- for (let r of ranges)
455
- cx.tempSkipped.push(r);
456
- if (until)
457
- cx.scheduleOn = cx.scheduleOn ? Promise.all([cx.scheduleOn, until]) : until;
458
- }
459
- this.parsedPos = to;
460
- return new index.Tree(index.NodeType.none, [], [], to - from);
461
- },
462
- stoppedAt: null,
463
- stopAt() { }
464
- };
465
- return parser;
466
- }
467
- };
468
- }
469
- /**
470
- @internal
471
- */
472
- isDone(upto) {
473
- upto = Math.min(upto, this.state.doc.length);
474
- let frags = this.fragments;
475
- return this.treeLen >= upto && frags.length && frags[0].from == 0 && frags[0].to >= upto;
476
- }
477
- /**
478
- Get the context for the current parse, or `null` if no editor
479
- parse is in progress.
480
- */
481
- static get() { return currentContext; }
482
- }
483
- function cutFragments(fragments, from, to) {
484
- return index.TreeFragment.applyChanges(fragments, [{ fromA: from, toA: to, fromB: from, toB: to }]);
485
- }
486
- class LanguageState {
487
- constructor(
488
- // A mutable parse state that is used to preserve work done during
489
- // the lifetime of a state when moving to the next state.
490
- context) {
491
- this.context = context;
492
- this.tree = context.tree;
493
- }
494
- apply(tr) {
495
- if (!tr.docChanged && this.tree == this.context.tree)
496
- return this;
497
- let newCx = this.context.changes(tr.changes, tr.state);
498
- // If the previous parse wasn't done, go forward only up to its
499
- // end position or the end of the viewport, to avoid slowing down
500
- // state updates with parse work beyond the viewport.
501
- let upto = this.context.treeLen == tr.startState.doc.length ? undefined
502
- : Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
503
- if (!newCx.work(20 /* Apply */, upto))
504
- newCx.takeTree();
505
- return new LanguageState(newCx);
506
- }
507
- static init(state) {
508
- let vpTo = Math.min(3000 /* InitViewport */, state.doc.length);
509
- let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
510
- if (!parseState.work(20 /* Apply */, vpTo))
511
- parseState.takeTree();
512
- return new LanguageState(parseState);
513
- }
514
- }
515
- Language.state = /*@__PURE__*/index$1.StateField.define({
516
- create: LanguageState.init,
517
- update(value, tr) {
518
- for (let e of tr.effects)
519
- if (e.is(Language.setState))
520
- return e.value;
521
- if (tr.startState.facet(language) != tr.state.facet(language))
522
- return LanguageState.init(tr.state);
523
- return value.apply(tr);
524
- }
525
- });
526
- let requestIdle = (callback) => {
527
- let timeout = setTimeout(() => callback(), 500 /* MaxPause */);
528
- return () => clearTimeout(timeout);
529
- };
530
- if (typeof requestIdleCallback != "undefined")
531
- requestIdle = (callback) => {
532
- let idle = -1, timeout = setTimeout(() => {
533
- idle = requestIdleCallback(callback, { timeout: 500 /* MaxPause */ - 100 /* MinPause */ });
534
- }, 100 /* MinPause */);
535
- return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
536
- };
537
- const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending)
538
- ? () => navigator.scheduling.isInputPending() : null;
539
- const parseWorker = /*@__PURE__*/index$2.ViewPlugin.fromClass(class ParseWorker {
540
- constructor(view) {
541
- this.view = view;
542
- this.working = null;
543
- this.workScheduled = 0;
544
- // End of the current time chunk
545
- this.chunkEnd = -1;
546
- // Milliseconds of budget left for this chunk
547
- this.chunkBudget = -1;
548
- this.work = this.work.bind(this);
549
- this.scheduleWork();
550
- }
551
- update(update) {
552
- let cx = this.view.state.field(Language.state).context;
553
- if (cx.updateViewport(update.view.viewport) || this.view.viewport.to > cx.treeLen)
554
- this.scheduleWork();
555
- if (update.docChanged) {
556
- if (this.view.hasFocus)
557
- this.chunkBudget += 50 /* ChangeBonus */;
558
- this.scheduleWork();
559
- }
560
- this.checkAsyncSchedule(cx);
561
- }
562
- scheduleWork() {
563
- if (this.working)
564
- return;
565
- let { state } = this.view, field = state.field(Language.state);
566
- if (field.tree != field.context.tree || !field.context.isDone(state.doc.length))
567
- this.working = requestIdle(this.work);
568
- }
569
- work(deadline) {
570
- this.working = null;
571
- let now = Date.now();
572
- if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) { // Start a new chunk
573
- this.chunkEnd = now + 30000 /* ChunkTime */;
574
- this.chunkBudget = 3000 /* ChunkBudget */;
575
- }
576
- if (this.chunkBudget <= 0)
577
- return; // No more budget
578
- let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
579
- if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* MaxParseAhead */))
580
- return;
581
- let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Slice */, deadline && !isInputPending ? Math.max(25 /* MinSlice */, deadline.timeRemaining() - 5) : 1e9);
582
- let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1000;
583
- let done = field.context.work(() => {
584
- return isInputPending && isInputPending() || Date.now() > endTime;
585
- }, vpTo + (viewportFirst ? 0 : 100000 /* MaxParseAhead */));
586
- this.chunkBudget -= Date.now() - now;
587
- if (done || this.chunkBudget <= 0) {
588
- field.context.takeTree();
589
- this.view.dispatch({ effects: Language.setState.of(new LanguageState(field.context)) });
590
- }
591
- if (this.chunkBudget > 0 && !(done && !viewportFirst))
592
- this.scheduleWork();
593
- this.checkAsyncSchedule(field.context);
594
- }
595
- checkAsyncSchedule(cx) {
596
- if (cx.scheduleOn) {
597
- this.workScheduled++;
598
- cx.scheduleOn
599
- .then(() => this.scheduleWork())
600
- .catch(err => index$2.logException(this.view.state, err))
601
- .then(() => this.workScheduled--);
602
- cx.scheduleOn = null;
603
- }
604
- }
605
- destroy() {
606
- if (this.working)
607
- this.working();
608
- }
609
- isWorking() {
610
- return !!(this.working || this.workScheduled > 0);
611
- }
612
- }, {
613
- eventHandlers: { focus() { this.scheduleWork(); } }
614
- });
615
- /**
616
- The facet used to associate a language with an editor state. Used
617
- by `Language` object's `extension` property (so you don't need to
618
- manually wrap your languages in this). Can be used to access the
619
- current language on a state.
620
- */
621
- const language = /*@__PURE__*/index$1.Facet.define({
622
- combine(languages) { return languages.length ? languages[0] : null; },
623
- enables: language => [
624
- Language.state,
625
- parseWorker,
626
- index$2.EditorView.contentAttributes.compute([language], state => {
627
- let lang = state.facet(language);
628
- return lang && lang.name ? { "data-language": lang.name } : {};
629
- })
630
- ]
631
- });
632
- /**
633
- This class bundles a [language](https://codemirror.net/6/docs/ref/#language.Language) with an
634
- optional set of supporting extensions. Language packages are
635
- encouraged to export a function that optionally takes a
636
- configuration object and returns a `LanguageSupport` instance, as
637
- the main way for client code to use the package.
638
- */
639
- class LanguageSupport {
640
- /**
641
- Create a language support object.
642
- */
643
- constructor(
644
- /**
645
- The language object.
646
- */
647
- language,
648
- /**
649
- An optional set of supporting extensions. When nesting a
650
- language in another language, the outer language is encouraged
651
- to include the supporting extensions for its inner languages
652
- in its own set of support extensions.
653
- */
654
- support = []) {
655
- this.language = language;
656
- this.support = support;
657
- this.extension = [language, support];
658
- }
659
- }
660
-
661
- /**
662
- Facet that defines a way to provide a function that computes the
663
- appropriate indentation depth, as a column number (see
664
- [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
665
- line. A return value of `null` indicates no indentation can be
666
- determined, and the line should inherit the indentation of the one
667
- above it. A return value of `undefined` defers to the next indent
668
- service.
669
- */
670
- const indentService = /*@__PURE__*/index$1.Facet.define();
671
- /**
672
- Facet for overriding the unit by which indentation happens. Should
673
- be a string consisting either entirely of the same whitespace
674
- character. When not set, this defaults to 2 spaces.
675
- */
676
- const indentUnit = /*@__PURE__*/index$1.Facet.define({
677
- combine: values => {
678
- if (!values.length)
679
- return " ";
680
- let unit = values[0];
681
- if (!unit || /\S/.test(unit) || Array.from(unit).some(e => e != unit[0]))
682
- throw new Error("Invalid indent unit: " + JSON.stringify(values[0]));
683
- return unit;
684
- }
685
- });
686
- /**
687
- Return the _column width_ of an indent unit in the state.
688
- Determined by the [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit)
689
- facet, and [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) when that
690
- contains tabs.
691
- */
692
- function getIndentUnit(state) {
693
- let unit = state.facet(indentUnit);
694
- return unit.charCodeAt(0) == 9 ? state.tabSize * unit.length : unit.length;
695
- }
696
- /**
697
- Create an indentation string that covers columns 0 to `cols`.
698
- Will use tabs for as much of the columns as possible when the
699
- [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit) facet contains
700
- tabs.
701
- */
702
- function indentString(state, cols) {
703
- let result = "", ts = state.tabSize, ch = state.facet(indentUnit)[0];
704
- if (ch == "\t") {
705
- while (cols >= ts) {
706
- result += "\t";
707
- cols -= ts;
708
- }
709
- ch = " ";
710
- }
711
- for (let i = 0; i < cols; i++)
712
- result += ch;
713
- return result;
714
- }
715
- /**
716
- Get the indentation, as a column number, at the given position.
717
- Will first consult any [indent services](https://codemirror.net/6/docs/ref/#language.indentService)
718
- that are registered, and if none of those return an indentation,
719
- this will check the syntax tree for the [indent node
720
- prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp) and use that if found. Returns a
721
- number when an indentation could be determined, and null
722
- otherwise.
723
- */
724
- function getIndentation(context, pos) {
725
- if (context instanceof index$1.EditorState)
726
- context = new IndentContext(context);
727
- for (let service of context.state.facet(indentService)) {
728
- let result = service(context, pos);
729
- if (result !== undefined)
730
- return result;
731
- }
732
- let tree = syntaxTree(context.state);
733
- return tree ? syntaxIndentation(context, tree, pos) : null;
734
- }
735
- /**
736
- Indentation contexts are used when calling [indentation
737
- services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
738
- useful in indentation logic, and can selectively override the
739
- indentation reported for some lines.
740
- */
741
- class IndentContext {
742
- /**
743
- Create an indent context.
744
- */
745
- constructor(
746
- /**
747
- The editor state.
748
- */
749
- state,
750
- /**
751
- @internal
752
- */
753
- options = {}) {
754
- this.state = state;
755
- this.options = options;
756
- this.unit = getIndentUnit(state);
757
- }
758
- /**
759
- Get a description of the line at the given position, taking
760
- [simulated line
761
- breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
762
- into account. If there is such a break at `pos`, the `bias`
763
- argument determines whether the part of the line line before or
764
- after the break is used.
765
- */
766
- lineAt(pos, bias = 1) {
767
- let line = this.state.doc.lineAt(pos);
768
- let { simulateBreak, simulateDoubleBreak } = this.options;
769
- if (simulateBreak != null && simulateBreak >= line.from && simulateBreak <= line.to) {
770
- if (simulateDoubleBreak && simulateBreak == pos)
771
- return { text: "", from: pos };
772
- else if (bias < 0 ? simulateBreak < pos : simulateBreak <= pos)
773
- return { text: line.text.slice(simulateBreak - line.from), from: simulateBreak };
774
- else
775
- return { text: line.text.slice(0, simulateBreak - line.from), from: line.from };
776
- }
777
- return line;
778
- }
779
- /**
780
- Get the text directly after `pos`, either the entire line
781
- or the next 100 characters, whichever is shorter.
782
- */
783
- textAfterPos(pos, bias = 1) {
784
- if (this.options.simulateDoubleBreak && pos == this.options.simulateBreak)
785
- return "";
786
- let { text, from } = this.lineAt(pos, bias);
787
- return text.slice(pos - from, Math.min(text.length, pos + 100 - from));
788
- }
789
- /**
790
- Find the column for the given position.
791
- */
792
- column(pos, bias = 1) {
793
- let { text, from } = this.lineAt(pos, bias);
794
- let result = this.countColumn(text, pos - from);
795
- let override = this.options.overrideIndentation ? this.options.overrideIndentation(from) : -1;
796
- if (override > -1)
797
- result += override - this.countColumn(text, text.search(/\S|$/));
798
- return result;
799
- }
800
- /**
801
- Find the column position (taking tabs into account) of the given
802
- position in the given string.
803
- */
804
- countColumn(line, pos = line.length) {
805
- return index$1.countColumn(line, this.state.tabSize, pos);
806
- }
807
- /**
808
- Find the indentation column of the line at the given point.
809
- */
810
- lineIndent(pos, bias = 1) {
811
- let { text, from } = this.lineAt(pos, bias);
812
- let override = this.options.overrideIndentation;
813
- if (override) {
814
- let overriden = override(from);
815
- if (overriden > -1)
816
- return overriden;
817
- }
818
- return this.countColumn(text, text.search(/\S|$/));
819
- }
820
- /**
821
- Returns the [simulated line
822
- break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
823
- for this context, if any.
824
- */
825
- get simulatedBreak() {
826
- return this.options.simulateBreak || null;
827
- }
828
- }
829
- /**
830
- A syntax tree node prop used to associate indentation strategies
831
- with node types. Such a strategy is a function from an indentation
832
- context to a column number (see also
833
- [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)) or null, where null
834
- indicates that no definitive indentation can be determined.
835
- */
836
- const indentNodeProp = /*@__PURE__*/new index.NodeProp();
837
- // Compute the indentation for a given position from the syntax tree.
838
- function syntaxIndentation(cx, ast, pos) {
839
- return indentFrom(ast.resolveInner(pos).enterUnfinishedNodesBefore(pos), pos, cx);
840
- }
841
- function ignoreClosed(cx) {
842
- return cx.pos == cx.options.simulateBreak && cx.options.simulateDoubleBreak;
843
- }
844
- function indentStrategy(tree) {
845
- let strategy = tree.type.prop(indentNodeProp);
846
- if (strategy)
847
- return strategy;
848
- let first = tree.firstChild, close;
849
- if (first && (close = first.type.prop(index.NodeProp.closedBy))) {
850
- let last = tree.lastChild, closed = last && close.indexOf(last.name) > -1;
851
- return cx => delimitedStrategy(cx, true, 1, undefined, closed && !ignoreClosed(cx) ? last.from : undefined);
852
- }
853
- return tree.parent == null ? topIndent : null;
854
- }
855
- function indentFrom(node, pos, base) {
856
- for (; node; node = node.parent) {
857
- let strategy = indentStrategy(node);
858
- if (strategy)
859
- return strategy(TreeIndentContext.create(base, pos, node));
860
- }
861
- return null;
862
- }
863
- function topIndent() { return 0; }
864
- /**
865
- Objects of this type provide context information and helper
866
- methods to indentation functions registered on syntax nodes.
867
- */
868
- class TreeIndentContext extends IndentContext {
869
- constructor(base,
870
- /**
871
- The position at which indentation is being computed.
872
- */
873
- pos,
874
- /**
875
- The syntax tree node to which the indentation strategy
876
- applies.
877
- */
878
- node) {
879
- super(base.state, base.options);
880
- this.base = base;
881
- this.pos = pos;
882
- this.node = node;
883
- }
884
- /**
885
- @internal
886
- */
887
- static create(base, pos, node) {
888
- return new TreeIndentContext(base, pos, node);
889
- }
890
- /**
891
- Get the text directly after `this.pos`, either the entire line
892
- or the next 100 characters, whichever is shorter.
893
- */
894
- get textAfter() {
895
- return this.textAfterPos(this.pos);
896
- }
897
- /**
898
- Get the indentation at the reference line for `this.node`, which
899
- is the line on which it starts, unless there is a node that is
900
- _not_ a parent of this node covering the start of that line. If
901
- so, the line at the start of that node is tried, again skipping
902
- on if it is covered by another such node.
903
- */
904
- get baseIndent() {
905
- return this.baseIndentFor(this.node);
906
- }
907
- /**
908
- Get the indentation for the reference line of the given node
909
- (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
910
- */
911
- baseIndentFor(node) {
912
- let line = this.state.doc.lineAt(node.from);
913
- // Skip line starts that are covered by a sibling (or cousin, etc)
914
- for (;;) {
915
- let atBreak = node.resolve(line.from);
916
- while (atBreak.parent && atBreak.parent.from == atBreak.from)
917
- atBreak = atBreak.parent;
918
- if (isParent(atBreak, node))
919
- break;
920
- line = this.state.doc.lineAt(atBreak.from);
921
- }
922
- return this.lineIndent(line.from);
923
- }
924
- /**
925
- Continue looking for indentations in the node's parent nodes,
926
- and return the result of that.
927
- */
928
- continue() {
929
- let parent = this.node.parent;
930
- return parent ? indentFrom(parent, this.pos, this.base) : 0;
931
- }
932
- }
933
- function isParent(parent, of) {
934
- for (let cur = of; cur; cur = cur.parent)
935
- if (parent == cur)
936
- return true;
937
- return false;
938
- }
939
- // Check whether a delimited node is aligned (meaning there are
940
- // non-skipped nodes on the same line as the opening delimiter). And
941
- // if so, return the opening token.
942
- function bracketedAligned(context) {
943
- let tree = context.node;
944
- let openToken = tree.childAfter(tree.from), last = tree.lastChild;
945
- if (!openToken)
946
- return null;
947
- let sim = context.options.simulateBreak;
948
- let openLine = context.state.doc.lineAt(openToken.from);
949
- let lineEnd = sim == null || sim <= openLine.from ? openLine.to : Math.min(openLine.to, sim);
950
- for (let pos = openToken.to;;) {
951
- let next = tree.childAfter(pos);
952
- if (!next || next == last)
953
- return null;
954
- if (!next.type.isSkipped)
955
- return next.from < lineEnd ? openToken : null;
956
- pos = next.to;
957
- }
958
- }
959
- function delimitedStrategy(context, align, units, closing, closedAt) {
960
- let after = context.textAfter, space = after.match(/^\s*/)[0].length;
961
- let closed = closing && after.slice(space, space + closing.length) == closing || closedAt == context.pos + space;
962
- let aligned = align ? bracketedAligned(context) : null;
963
- if (aligned)
964
- return closed ? context.column(aligned.from) : context.column(aligned.to);
965
- return context.baseIndent + (closed ? 0 : context.unit * units);
966
- }
967
-
968
- /**
969
- A highlight style associates CSS styles with higlighting
970
- [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
971
- */
972
- class HighlightStyle {
973
- constructor(
974
- /**
975
- The tag styles used to create this highlight style.
976
- */
977
- specs, options) {
978
- this.specs = specs;
979
- let modSpec;
980
- function def(spec) {
981
- let cls = styleMod.StyleModule.newName();
982
- (modSpec || (modSpec = Object.create(null)))["." + cls] = spec;
983
- return cls;
984
- }
985
- const all = typeof options.all == "string" ? options.all : options.all ? def(options.all) : undefined;
986
- const scopeOpt = options.scope;
987
- this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data
988
- : scopeOpt ? (type) => type == scopeOpt : undefined;
989
- this.style = highlight.tagHighlighter(specs.map(style => ({
990
- tag: style.tag,
991
- class: style.class || def(Object.assign({}, style, { tag: null }))
992
- })), {
993
- all,
994
- }).style;
995
- this.module = modSpec ? new styleMod.StyleModule(modSpec) : null;
996
- this.themeType = options.themeType;
997
- }
998
- /**
999
- Create a highlighter style that associates the given styles to
1000
- the given tags. The specs must be objects that hold a style tag
1001
- or array of tags in their `tag` property, and either a single
1002
- `class` property providing a static CSS class (for highlighter
1003
- that rely on external styling), or a
1004
- [`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
1005
- set of CSS properties (which define the styling for those tags).
1006
-
1007
- The CSS rules created for a highlighter will be emitted in the
1008
- order of the spec's properties. That means that for elements that
1009
- have multiple tags associated with them, styles defined further
1010
- down in the list will have a higher CSS precedence than styles
1011
- defined earlier.
1012
- */
1013
- static define(specs, options) {
1014
- return new HighlightStyle(specs, options || {});
1015
- }
1016
- }
1017
- const highlighterFacet = /*@__PURE__*/index$1.Facet.define();
1018
- const fallbackHighlighter = /*@__PURE__*/index$1.Facet.define({
1019
- combine(values) { return values.length ? [values[0]] : null; }
1020
- });
1021
- function getHighlighters(state) {
1022
- let main = state.facet(highlighterFacet);
1023
- return main.length ? main : state.facet(fallbackHighlighter);
1024
- }
1025
- /**
1026
- Wrap a highlighter in an editor extension that uses it to apply
1027
- syntax highlighting to the editor content.
1028
-
1029
- When multiple (non-fallback) styles are provided, the styling
1030
- applied is the union of the classes they emit.
1031
- */
1032
- function syntaxHighlighting(highlighter, options) {
1033
- let ext = [treeHighlighter], themeType;
1034
- if (highlighter instanceof HighlightStyle) {
1035
- if (highlighter.module)
1036
- ext.push(index$2.EditorView.styleModule.of(highlighter.module));
1037
- themeType = highlighter.themeType;
1038
- }
1039
- if (options === null || options === void 0 ? void 0 : options.fallback)
1040
- ext.push(fallbackHighlighter.of(highlighter));
1041
- else if (themeType)
1042
- ext.push(highlighterFacet.computeN([index$2.EditorView.darkTheme], state => {
1043
- return state.facet(index$2.EditorView.darkTheme) == (themeType == "dark") ? [highlighter] : [];
1044
- }));
1045
- else
1046
- ext.push(highlighterFacet.of(highlighter));
1047
- return ext;
1048
- }
1049
- class TreeHighlighter {
1050
- constructor(view) {
1051
- this.markCache = Object.create(null);
1052
- this.tree = syntaxTree(view.state);
1053
- this.decorations = this.buildDeco(view, getHighlighters(view.state));
1054
- }
1055
- update(update) {
1056
- let tree = syntaxTree(update.state), highlighters = getHighlighters(update.state);
1057
- let styleChange = highlighters != getHighlighters(update.startState);
1058
- if (tree.length < update.view.viewport.to && !styleChange && tree.type == this.tree.type) {
1059
- this.decorations = this.decorations.map(update.changes);
1060
- }
1061
- else if (tree != this.tree || update.viewportChanged || styleChange) {
1062
- this.tree = tree;
1063
- this.decorations = this.buildDeco(update.view, highlighters);
1064
- }
1065
- }
1066
- buildDeco(view, highlighters) {
1067
- if (!highlighters || !this.tree.length)
1068
- return index$2.Decoration.none;
1069
- let builder = new index$1.RangeSetBuilder();
1070
- for (let { from, to } of view.visibleRanges) {
1071
- highlight.highlightTree(this.tree, highlighters, (from, to, style) => {
1072
- builder.add(from, to, this.markCache[style] || (this.markCache[style] = index$2.Decoration.mark({ class: style })));
1073
- }, from, to);
1074
- }
1075
- return builder.finish();
1076
- }
1077
- }
1078
- const treeHighlighter = /*@__PURE__*/index$1.Prec.high(/*@__PURE__*/index$2.ViewPlugin.fromClass(TreeHighlighter, {
1079
- decorations: v => v.decorations
1080
- }));
1081
- /**
1082
- A default highlight style (works well with light themes).
1083
- */
1084
- const defaultHighlightStyle = /*@__PURE__*/HighlightStyle.define([
1085
- { tag: highlight.tags.meta,
1086
- color: "#404740" },
1087
- { tag: highlight.tags.link,
1088
- textDecoration: "underline" },
1089
- { tag: highlight.tags.heading,
1090
- textDecoration: "underline",
1091
- fontWeight: "bold" },
1092
- { tag: highlight.tags.emphasis,
1093
- fontStyle: "italic" },
1094
- { tag: highlight.tags.strong,
1095
- fontWeight: "bold" },
1096
- { tag: highlight.tags.strikethrough,
1097
- textDecoration: "line-through" },
1098
- { tag: highlight.tags.keyword,
1099
- color: "#708" },
1100
- { tag: [highlight.tags.atom, highlight.tags.bool, highlight.tags.url, highlight.tags.contentSeparator, highlight.tags.labelName],
1101
- color: "#219" },
1102
- { tag: [highlight.tags.literal, highlight.tags.inserted],
1103
- color: "#164" },
1104
- { tag: [highlight.tags.string, highlight.tags.deleted],
1105
- color: "#a11" },
1106
- { tag: [highlight.tags.regexp, highlight.tags.escape, /*@__PURE__*/highlight.tags.special(highlight.tags.string)],
1107
- color: "#e40" },
1108
- { tag: /*@__PURE__*/highlight.tags.definition(highlight.tags.variableName),
1109
- color: "#00f" },
1110
- { tag: /*@__PURE__*/highlight.tags.local(highlight.tags.variableName),
1111
- color: "#30a" },
1112
- { tag: [highlight.tags.typeName, highlight.tags.namespace],
1113
- color: "#085" },
1114
- { tag: highlight.tags.className,
1115
- color: "#167" },
1116
- { tag: [/*@__PURE__*/highlight.tags.special(highlight.tags.variableName), highlight.tags.macroName],
1117
- color: "#256" },
1118
- { tag: /*@__PURE__*/highlight.tags.definition(highlight.tags.propertyName),
1119
- color: "#00c" },
1120
- { tag: highlight.tags.comment,
1121
- color: "#940" },
1122
- { tag: highlight.tags.invalid,
1123
- color: "#f00" }
1124
- ]);
1125
- const DefaultScanDist = 10000, DefaultBrackets = "()[]{}";
1126
- /**
1127
- When larger syntax nodes, such as HTML tags, are marked as
1128
- opening/closing, it can be a bit messy to treat the whole node as
1129
- a matchable bracket. This node prop allows you to define, for such
1130
- a node, a ‘handle’—the part of the node that is highlighted, and
1131
- that the cursor must be on to activate highlighting in the first
1132
- place.
1133
- */
1134
- const bracketMatchingHandle = /*@__PURE__*/new index.NodeProp();
1135
- function matchingNodes(node, dir, brackets) {
1136
- let byProp = node.prop(dir < 0 ? index.NodeProp.openedBy : index.NodeProp.closedBy);
1137
- if (byProp)
1138
- return byProp;
1139
- if (node.name.length == 1) {
1140
- let index = brackets.indexOf(node.name);
1141
- if (index > -1 && index % 2 == (dir < 0 ? 1 : 0))
1142
- return [brackets[index + dir]];
1143
- }
1144
- return null;
1145
- }
1146
- function findHandle(node) {
1147
- let hasHandle = node.type.prop(bracketMatchingHandle);
1148
- return hasHandle ? hasHandle(node.node) : node;
1149
- }
1150
- /**
1151
- Find the matching bracket for the token at `pos`, scanning
1152
- direction `dir`. Only the `brackets` and `maxScanDistance`
1153
- properties are used from `config`, if given. Returns null if no
1154
- bracket was found at `pos`, or a match result otherwise.
1155
- */
1156
- function matchBrackets(state, pos, dir, config = {}) {
1157
- let maxScanDistance = config.maxScanDistance || DefaultScanDist, brackets = config.brackets || DefaultBrackets;
1158
- let tree = syntaxTree(state), node = tree.resolveInner(pos, dir);
1159
- for (let cur = node; cur; cur = cur.parent) {
1160
- let matches = matchingNodes(cur.type, dir, brackets);
1161
- if (matches && cur.from < cur.to) {
1162
- let handle = findHandle(cur);
1163
- if (handle && (dir > 0 ? pos >= handle.from && pos < handle.to : pos > handle.from && pos <= handle.to))
1164
- return matchMarkedBrackets(state, pos, dir, cur, handle, matches, brackets);
1165
- }
1166
- }
1167
- return matchPlainBrackets(state, pos, dir, tree, node.type, maxScanDistance, brackets);
1168
- }
1169
- function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, brackets) {
1170
- let parent = token.parent, firstToken = { from: handle.from, to: handle.to };
1171
- let depth = 0, cursor = parent === null || parent === void 0 ? void 0 : parent.cursor();
1172
- if (cursor && (dir < 0 ? cursor.childBefore(token.from) : cursor.childAfter(token.to)))
1173
- do {
1174
- if (dir < 0 ? cursor.to <= token.from : cursor.from >= token.to) {
1175
- if (depth == 0 && matching.indexOf(cursor.type.name) > -1 && cursor.from < cursor.to) {
1176
- let endHandle = findHandle(cursor);
1177
- return { start: firstToken, end: endHandle ? { from: endHandle.from, to: endHandle.to } : undefined, matched: true };
1178
- }
1179
- else if (matchingNodes(cursor.type, dir, brackets)) {
1180
- depth++;
1181
- }
1182
- else if (matchingNodes(cursor.type, -dir, brackets)) {
1183
- if (depth == 0) {
1184
- let endHandle = findHandle(cursor);
1185
- return {
1186
- start: firstToken,
1187
- end: endHandle && endHandle.from < endHandle.to ? { from: endHandle.from, to: endHandle.to } : undefined,
1188
- matched: false
1189
- };
1190
- }
1191
- depth--;
1192
- }
1193
- }
1194
- } while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
1195
- return { start: firstToken, matched: false };
1196
- }
1197
- function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, brackets) {
1198
- let startCh = dir < 0 ? state.sliceDoc(pos - 1, pos) : state.sliceDoc(pos, pos + 1);
1199
- let bracket = brackets.indexOf(startCh);
1200
- if (bracket < 0 || (bracket % 2 == 0) != (dir > 0))
1201
- return null;
1202
- let startToken = { from: dir < 0 ? pos - 1 : pos, to: dir > 0 ? pos + 1 : pos };
1203
- let iter = state.doc.iterRange(pos, dir > 0 ? state.doc.length : 0), depth = 0;
1204
- for (let distance = 0; !(iter.next()).done && distance <= maxScanDistance;) {
1205
- let text = iter.value;
1206
- if (dir < 0)
1207
- distance += text.length;
1208
- let basePos = pos + distance * dir;
1209
- for (let pos = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos != end; pos += dir) {
1210
- let found = brackets.indexOf(text[pos]);
1211
- if (found < 0 || tree.resolveInner(basePos + pos, 1).type != tokenType)
1212
- continue;
1213
- if ((found % 2 == 0) == (dir > 0)) {
1214
- depth++;
1215
- }
1216
- else if (depth == 1) { // Closing
1217
- return { start: startToken, end: { from: basePos + pos, to: basePos + pos + 1 }, matched: (found >> 1) == (bracket >> 1) };
1218
- }
1219
- else {
1220
- depth--;
1221
- }
1222
- }
1223
- if (dir > 0)
1224
- distance += text.length;
1225
- }
1226
- return iter.done ? { start: startToken, matched: false } : null;
1227
- }
1228
- const noTokens = /*@__PURE__*/Object.create(null);
1229
- const typeArray = [index.NodeType.none];
1230
- const warned = [];
1231
- const defaultTable = /*@__PURE__*/Object.create(null);
1232
- for (let [legacyName, name] of [
1233
- ["variable", "variableName"],
1234
- ["variable-2", "variableName.special"],
1235
- ["string-2", "string.special"],
1236
- ["def", "variableName.definition"],
1237
- ["tag", "tagName"],
1238
- ["attribute", "attributeName"],
1239
- ["type", "typeName"],
1240
- ["builtin", "variableName.standard"],
1241
- ["qualifier", "modifier"],
1242
- ["error", "invalid"],
1243
- ["header", "heading"],
1244
- ["property", "propertyName"]
1245
- ])
1246
- defaultTable[legacyName] = /*@__PURE__*/createTokenType(noTokens, name);
1247
- function warnForPart(part, msg) {
1248
- if (warned.indexOf(part) > -1)
1249
- return;
1250
- warned.push(part);
1251
- console.warn(msg);
1252
- }
1253
- function createTokenType(extra, tagStr) {
1254
- let tag = null;
1255
- for (let part of tagStr.split(".")) {
1256
- let value = (extra[part] || highlight.tags[part]);
1257
- if (!value) {
1258
- warnForPart(part, `Unknown highlighting tag ${part}`);
1259
- }
1260
- else if (typeof value == "function") {
1261
- if (!tag)
1262
- warnForPart(part, `Modifier ${part} used at start of tag`);
1263
- else
1264
- tag = value(tag);
1265
- }
1266
- else {
1267
- if (tag)
1268
- warnForPart(part, `Tag ${part} used as modifier`);
1269
- else
1270
- tag = value;
1271
- }
1272
- }
1273
- if (!tag)
1274
- return 0;
1275
- let name = tagStr.replace(/ /g, "_"), type = index.NodeType.define({
1276
- id: typeArray.length,
1277
- name,
1278
- props: [highlight.styleTags({ [name]: tag })]
1279
- });
1280
- typeArray.push(type);
1281
- return type.id;
1282
- }
1283
-
1284
- exports.DocInput = DocInput;
1285
- exports.HighlightStyle = HighlightStyle;
1286
- exports.IndentContext = IndentContext;
1287
- exports.LRLanguage = LRLanguage;
1288
- exports.Language = Language;
1289
- exports.LanguageSupport = LanguageSupport;
1290
- exports.ParseContext = ParseContext;
1291
- exports.TreeIndentContext = TreeIndentContext;
1292
- exports.bracketMatchingHandle = bracketMatchingHandle;
1293
- exports.defaultHighlightStyle = defaultHighlightStyle;
1294
- exports.defineLanguageFacet = defineLanguageFacet;
1295
- exports.ensureSyntaxTree = ensureSyntaxTree;
1296
- exports.getIndentUnit = getIndentUnit;
1297
- exports.getIndentation = getIndentation;
1298
- exports.indentNodeProp = indentNodeProp;
1299
- exports.indentService = indentService;
1300
- exports.indentString = indentString;
1301
- exports.indentUnit = indentUnit;
1302
- exports.language = language;
1303
- exports.languageDataProp = languageDataProp;
1304
- exports.matchBrackets = matchBrackets;
1305
- exports.sublanguageProp = sublanguageProp;
1306
- exports.syntaxHighlighting = syntaxHighlighting;
1307
- exports.syntaxTree = syntaxTree;
1308
- //# sourceMappingURL=index.js.map