@veltra/desktop 1.2.16 → 1.2.18

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 (72) hide show
  1. package/dist/components/action/action-group.vue.d.ts +2 -2
  2. package/dist/components/action/action.vue.d.ts +1 -1
  3. package/dist/components/auto-complete/auto-complete.vue.d.ts +2 -2
  4. package/dist/components/cascade/cascade.vue.d.ts +3 -3
  5. package/dist/components/checkbox/checkbox-button.vue.d.ts +1 -1
  6. package/dist/components/checkbox-group/checkbox-group.vue.d.ts +2 -2
  7. package/dist/components/code-editor/basic-setup.js +7 -7
  8. package/dist/components/code-editor/code-editor.js +15 -10
  9. package/dist/components/code-editor/code-editor.js.map +1 -1
  10. package/dist/components/date-picker/date-picker.vue.d.ts +2 -2
  11. package/dist/components/date-range-picker/date-range-picker.vue.d.ts +2 -2
  12. package/dist/components/empty/empty.vue.d.ts +1 -1
  13. package/dist/components/file-picker/file-picker.vue.d.ts +1 -1
  14. package/dist/components/input/input.vue.d.ts +2 -2
  15. package/dist/components/multi-select/multi-select.vue.d.ts +3 -3
  16. package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +3 -3
  17. package/dist/components/number-input/number-input.vue.d.ts +2 -2
  18. package/dist/components/number-range-input/number-range-input.vue.d.ts +1 -1
  19. package/dist/components/password-input/password-input.vue.d.ts +1 -1
  20. package/dist/components/pop-confirm/pop-confirm.vue.d.ts +1 -1
  21. package/dist/components/radio-group/radio-group.vue.d.ts +2 -2
  22. package/dist/components/rich-text-editor/rich-text-editor.vue.d.ts +1 -1
  23. package/dist/components/select/select.vue.d.ts +2 -2
  24. package/dist/components/textarea/textarea.vue.d.ts +2 -2
  25. package/dist/components/tip/tip.vue.d.ts +1 -1
  26. package/dist/components/tree-select/tree-select.vue.d.ts +3 -3
  27. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js +1750 -0
  28. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  29. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js +1719 -0
  30. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  31. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js +51 -0
  32. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js.map +1 -0
  33. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js +378 -0
  34. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js.map +1 -0
  35. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js +31 -0
  36. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js.map +1 -0
  37. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js +601 -0
  38. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js.map +1 -0
  39. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js +1767 -0
  40. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js.map +1 -0
  41. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js +569 -0
  42. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  43. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js +1142 -0
  44. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js.map +1 -0
  45. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js +3372 -0
  46. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js.map +1 -0
  47. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js +165 -0
  48. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js.map +1 -0
  49. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js +9770 -0
  50. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js.map +1 -0
  51. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js +1567 -0
  52. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js.map +1 -0
  53. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js +864 -0
  54. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js.map +1 -0
  55. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js +235 -0
  56. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js.map +1 -0
  57. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js +470 -0
  58. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js.map +1 -0
  59. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js +55 -0
  60. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js.map +1 -0
  61. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js +1485 -0
  62. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js.map +1 -0
  63. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js +73 -0
  64. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js.map +1 -0
  65. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js +26 -0
  66. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js.map +1 -0
  67. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js +95 -0
  68. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js.map +1 -0
  69. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js +104 -0
  70. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js.map +1 -0
  71. package/package.json +20 -18
  72. package/src/components/code-editor/code-editor.vue +12 -7
@@ -0,0 +1,1767 @@
1
+ import { IterMode, NodeProp, NodeType, Parser, Tree, TreeFragment } from "../../../../../@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js";
2
+ import { highlightTree, styleTags, tagHighlighter, tags } from "../../../../../@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js";
3
+ import { EditorState, Facet, Prec, RangeSet, RangeSetBuilder, StateEffect, StateField, combineConfig, countColumn } from "../../../../../@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js";
4
+ import { StyleModule } from "../../../../../style-mod@4.1.3/node_modules/style-mod/src/style-mod.js";
5
+ import { Decoration, Direction, EditorView, GutterMarker, ViewPlugin, WidgetType, gutter, logException } from "../../../../../@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js";
6
+ //#region ../../node_modules/.bun/@codemirror+language@6.12.4/node_modules/@codemirror/language/dist/index.js
7
+ var _a;
8
+ /**
9
+ Node prop stored in a parser's top syntax node to provide the
10
+ facet that stores language-specific data for that language.
11
+ */
12
+ const languageDataProp = /*@__PURE__*/ new NodeProp();
13
+ /**
14
+ Helper function to define a facet (to be added to the top syntax
15
+ node(s) for a language via
16
+ [`languageDataProp`](https://codemirror.net/6/docs/ref/#language.languageDataProp)), that will be
17
+ used to associate language data with the language. You
18
+ probably only need this when subclassing
19
+ [`Language`](https://codemirror.net/6/docs/ref/#language.Language).
20
+ */
21
+ function defineLanguageFacet(baseData) {
22
+ return Facet.define({ combine: baseData ? (values) => values.concat(baseData) : void 0 });
23
+ }
24
+ /**
25
+ Syntax node prop used to register sublanguages. Should be added to
26
+ the top level node type for the language.
27
+ */
28
+ const sublanguageProp = /*@__PURE__*/ new NodeProp();
29
+ /**
30
+ A language object manages parsing and per-language
31
+ [metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
32
+ managed as a [Lezer](https://lezer.codemirror.net) tree. The class
33
+ can be used directly, via the [`LRLanguage`](https://codemirror.net/6/docs/ref/#language.LRLanguage)
34
+ subclass for [Lezer](https://lezer.codemirror.net/) LR parsers, or
35
+ via the [`StreamLanguage`](https://codemirror.net/6/docs/ref/#language.StreamLanguage) subclass
36
+ for stream parsers.
37
+ */
38
+ var Language = class {
39
+ /**
40
+ Construct a language object. If you need to invoke this
41
+ directly, first define a data facet with
42
+ [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
43
+ configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
44
+ to the language's outer syntax node.
45
+ */
46
+ constructor(data, parser, extraExtensions = [], name = "") {
47
+ this.data = data;
48
+ this.name = name;
49
+ if (!EditorState.prototype.hasOwnProperty("tree")) Object.defineProperty(EditorState.prototype, "tree", { get() {
50
+ return syntaxTree(this);
51
+ } });
52
+ this.parser = parser;
53
+ this.extension = [language.of(this), EditorState.languageData.of((state, pos, side) => {
54
+ let top = topNodeAt(state, pos, side), data = top.type.prop(languageDataProp);
55
+ if (!data) return [];
56
+ let base = state.facet(data), sub = top.type.prop(sublanguageProp);
57
+ if (sub) {
58
+ let innerNode = top.resolve(pos - top.from, side);
59
+ for (let sublang of sub) if (sublang.test(innerNode, state)) {
60
+ let data = state.facet(sublang.facet);
61
+ return sublang.type == "replace" ? data : data.concat(base);
62
+ }
63
+ }
64
+ return base;
65
+ })].concat(extraExtensions);
66
+ }
67
+ /**
68
+ Query whether this language is active at the given position.
69
+ */
70
+ isActiveAt(state, pos, side = -1) {
71
+ return topNodeAt(state, pos, side).type.prop(languageDataProp) == this.data;
72
+ }
73
+ /**
74
+ Find the document regions that were parsed using this language.
75
+ The returned regions will _include_ any nested languages rooted
76
+ in this language, when those exist.
77
+ */
78
+ findRegions(state) {
79
+ let lang = state.facet(language);
80
+ if ((lang === null || lang === void 0 ? void 0 : lang.data) == this.data) return [{
81
+ from: 0,
82
+ to: state.doc.length
83
+ }];
84
+ if (!lang || !lang.allowsNesting) return [];
85
+ let result = [];
86
+ let explore = (tree, from) => {
87
+ if (tree.prop(languageDataProp) == this.data) {
88
+ result.push({
89
+ from,
90
+ to: from + tree.length
91
+ });
92
+ return;
93
+ }
94
+ let mount = tree.prop(NodeProp.mounted);
95
+ if (mount) {
96
+ if (mount.tree.prop(languageDataProp) == this.data) {
97
+ if (mount.overlay) for (let r of mount.overlay) result.push({
98
+ from: r.from + from,
99
+ to: r.to + from
100
+ });
101
+ else result.push({
102
+ from,
103
+ to: from + tree.length
104
+ });
105
+ return;
106
+ } else if (mount.overlay) {
107
+ let size = result.length;
108
+ explore(mount.tree, mount.overlay[0].from + from);
109
+ if (result.length > size) return;
110
+ }
111
+ }
112
+ for (let i = 0; i < tree.children.length; i++) {
113
+ let ch = tree.children[i];
114
+ if (ch instanceof Tree) explore(ch, tree.positions[i] + from);
115
+ }
116
+ };
117
+ explore(syntaxTree(state), 0);
118
+ return result;
119
+ }
120
+ /**
121
+ Indicates whether this language allows nested languages. The
122
+ default implementation returns true.
123
+ */
124
+ get allowsNesting() {
125
+ return true;
126
+ }
127
+ };
128
+ /**
129
+ @internal
130
+ */
131
+ Language.setState = /*@__PURE__*/ StateEffect.define();
132
+ function topNodeAt(state, pos, side) {
133
+ let topLang = state.facet(language), tree = syntaxTree(state).topNode;
134
+ if (!topLang || topLang.allowsNesting) {
135
+ for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers | IterMode.EnterBracketed)) if (node.type.isTop) tree = node;
136
+ }
137
+ return tree;
138
+ }
139
+ /**
140
+ A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language) for use with Lezer
141
+ [LR parsers](https://lezer.codemirror.net/docs/ref#lr.LRParser).
142
+ */
143
+ var LRLanguage = class LRLanguage extends Language {
144
+ constructor(data, parser, name) {
145
+ super(data, parser, [], name);
146
+ this.parser = parser;
147
+ }
148
+ /**
149
+ Define a language from a parser.
150
+ */
151
+ static define(spec) {
152
+ let data = defineLanguageFacet(spec.languageData);
153
+ return new LRLanguage(data, spec.parser.configure({ props: [languageDataProp.add((type) => type.isTop ? data : void 0)] }), spec.name);
154
+ }
155
+ /**
156
+ Create a new instance of this language with a reconfigured
157
+ version of its parser and optionally a new name.
158
+ */
159
+ configure(options, name) {
160
+ return new LRLanguage(this.data, this.parser.configure(options), name || this.name);
161
+ }
162
+ get allowsNesting() {
163
+ return this.parser.hasWrappers();
164
+ }
165
+ };
166
+ /**
167
+ Get the syntax tree for a state, which is the current (possibly
168
+ incomplete) parse tree of the active
169
+ [language](https://codemirror.net/6/docs/ref/#language.Language), or the empty tree if there is no
170
+ language available.
171
+ */
172
+ function syntaxTree(state) {
173
+ let field = state.field(Language.state, false);
174
+ return field ? field.tree : Tree.empty;
175
+ }
176
+ /**
177
+ Lezer-style
178
+ [`Input`](https://lezer.codemirror.net/docs/ref#common.Input)
179
+ object for a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) object.
180
+ */
181
+ var DocInput = class {
182
+ /**
183
+ Create an input object for the given document.
184
+ */
185
+ constructor(doc) {
186
+ this.doc = doc;
187
+ this.cursorPos = 0;
188
+ this.string = "";
189
+ this.cursor = doc.iter();
190
+ }
191
+ get length() {
192
+ return this.doc.length;
193
+ }
194
+ syncTo(pos) {
195
+ this.string = this.cursor.next(pos - this.cursorPos).value;
196
+ this.cursorPos = pos + this.string.length;
197
+ return this.cursorPos - this.string.length;
198
+ }
199
+ chunk(pos) {
200
+ this.syncTo(pos);
201
+ return this.string;
202
+ }
203
+ get lineChunks() {
204
+ return true;
205
+ }
206
+ read(from, to) {
207
+ let stringStart = this.cursorPos - this.string.length;
208
+ if (from < stringStart || to >= this.cursorPos) return this.doc.sliceString(from, to);
209
+ else return this.string.slice(from - stringStart, to - stringStart);
210
+ }
211
+ };
212
+ let currentContext = null;
213
+ /**
214
+ A parse context provided to parsers working on the editor content.
215
+ */
216
+ var ParseContext = class ParseContext {
217
+ constructor(parser, state, fragments = [], tree, treeLen, viewport, skipped, scheduleOn) {
218
+ this.parser = parser;
219
+ this.state = state;
220
+ this.fragments = fragments;
221
+ this.tree = tree;
222
+ this.treeLen = treeLen;
223
+ this.viewport = viewport;
224
+ this.skipped = skipped;
225
+ this.scheduleOn = scheduleOn;
226
+ this.parse = null;
227
+ /**
228
+ @internal
229
+ */
230
+ this.tempSkipped = [];
231
+ }
232
+ /**
233
+ @internal
234
+ */
235
+ static create(parser, state, viewport) {
236
+ return new ParseContext(parser, state, [], Tree.empty, 0, viewport, [], null);
237
+ }
238
+ startParse() {
239
+ return this.parser.startParse(new DocInput(this.state.doc), this.fragments);
240
+ }
241
+ /**
242
+ @internal
243
+ */
244
+ work(until, upto) {
245
+ if (upto != null && upto >= this.state.doc.length) upto = void 0;
246
+ if (this.tree != Tree.empty && this.isDone(upto !== null && upto !== void 0 ? upto : this.state.doc.length)) {
247
+ this.takeTree();
248
+ return true;
249
+ }
250
+ return this.withContext(() => {
251
+ var _a;
252
+ if (typeof until == "number") {
253
+ let endTime = Date.now() + until;
254
+ until = () => Date.now() > endTime;
255
+ }
256
+ if (!this.parse) this.parse = this.startParse();
257
+ if (upto != null && (this.parse.stoppedAt == null || this.parse.stoppedAt > upto) && upto < this.state.doc.length) this.parse.stopAt(upto);
258
+ for (;;) {
259
+ let done = this.parse.advance();
260
+ if (done) {
261
+ this.fragments = this.withoutTempSkipped(TreeFragment.addTree(done, this.fragments, this.parse.stoppedAt != null));
262
+ this.treeLen = (_a = this.parse.stoppedAt) !== null && _a !== void 0 ? _a : this.state.doc.length;
263
+ this.tree = done;
264
+ this.parse = null;
265
+ if (this.treeLen < (upto !== null && upto !== void 0 ? upto : this.state.doc.length)) this.parse = this.startParse();
266
+ else return true;
267
+ }
268
+ if (until()) return false;
269
+ }
270
+ });
271
+ }
272
+ /**
273
+ @internal
274
+ */
275
+ takeTree() {
276
+ let pos, tree;
277
+ if (this.parse && (pos = this.parse.parsedPos) >= this.treeLen) {
278
+ if (this.parse.stoppedAt == null || this.parse.stoppedAt > pos) this.parse.stopAt(pos);
279
+ this.withContext(() => {
280
+ while (!(tree = this.parse.advance()));
281
+ });
282
+ this.treeLen = pos;
283
+ this.tree = tree;
284
+ this.fragments = this.withoutTempSkipped(TreeFragment.addTree(this.tree, this.fragments, true));
285
+ this.parse = null;
286
+ }
287
+ }
288
+ withContext(f) {
289
+ let prev = currentContext;
290
+ currentContext = this;
291
+ try {
292
+ return f();
293
+ } finally {
294
+ currentContext = prev;
295
+ }
296
+ }
297
+ withoutTempSkipped(fragments) {
298
+ for (let r; r = this.tempSkipped.pop();) fragments = cutFragments(fragments, r.from, r.to);
299
+ return fragments;
300
+ }
301
+ /**
302
+ @internal
303
+ */
304
+ changes(changes, newState) {
305
+ let { fragments, tree, treeLen, viewport, skipped } = this;
306
+ this.takeTree();
307
+ if (!changes.empty) {
308
+ let ranges = [];
309
+ changes.iterChangedRanges((fromA, toA, fromB, toB) => ranges.push({
310
+ fromA,
311
+ toA,
312
+ fromB,
313
+ toB
314
+ }));
315
+ fragments = TreeFragment.applyChanges(fragments, ranges);
316
+ tree = Tree.empty;
317
+ treeLen = 0;
318
+ viewport = {
319
+ from: changes.mapPos(viewport.from, -1),
320
+ to: changes.mapPos(viewport.to, 1)
321
+ };
322
+ if (this.skipped.length) {
323
+ skipped = [];
324
+ for (let r of this.skipped) {
325
+ let from = changes.mapPos(r.from, 1), to = changes.mapPos(r.to, -1);
326
+ if (from < to) skipped.push({
327
+ from,
328
+ to
329
+ });
330
+ }
331
+ }
332
+ }
333
+ return new ParseContext(this.parser, newState, fragments, tree, treeLen, viewport, skipped, this.scheduleOn);
334
+ }
335
+ /**
336
+ @internal
337
+ */
338
+ updateViewport(viewport) {
339
+ if (this.viewport.from == viewport.from && this.viewport.to == viewport.to) return false;
340
+ this.viewport = viewport;
341
+ let startLen = this.skipped.length;
342
+ for (let i = 0; i < this.skipped.length; i++) {
343
+ let { from, to } = this.skipped[i];
344
+ if (from < viewport.to && to > viewport.from) {
345
+ this.fragments = cutFragments(this.fragments, from, to);
346
+ this.skipped.splice(i--, 1);
347
+ }
348
+ }
349
+ if (this.skipped.length >= startLen) return false;
350
+ this.reset();
351
+ return true;
352
+ }
353
+ /**
354
+ @internal
355
+ */
356
+ reset() {
357
+ if (this.parse) {
358
+ this.takeTree();
359
+ this.parse = null;
360
+ }
361
+ }
362
+ /**
363
+ Notify the parse scheduler that the given region was skipped
364
+ because it wasn't in view, and the parse should be restarted
365
+ when it comes into view.
366
+ */
367
+ skipUntilInView(from, to) {
368
+ this.skipped.push({
369
+ from,
370
+ to
371
+ });
372
+ }
373
+ /**
374
+ Returns a parser intended to be used as placeholder when
375
+ asynchronously loading a nested parser. It'll skip its input and
376
+ mark it as not-really-parsed, so that the next update will parse
377
+ it again.
378
+
379
+ When `until` is given, a reparse will be scheduled when that
380
+ promise resolves.
381
+ */
382
+ static getSkippingParser(until) {
383
+ return new class extends Parser {
384
+ createParse(input, fragments, ranges) {
385
+ let from = ranges[0].from, to = ranges[ranges.length - 1].to;
386
+ return {
387
+ parsedPos: from,
388
+ advance() {
389
+ let cx = currentContext;
390
+ if (cx) {
391
+ for (let r of ranges) cx.tempSkipped.push(r);
392
+ if (until) cx.scheduleOn = cx.scheduleOn ? Promise.all([cx.scheduleOn, until]) : until;
393
+ }
394
+ this.parsedPos = to;
395
+ return new Tree(NodeType.none, [], [], to - from);
396
+ },
397
+ stoppedAt: null,
398
+ stopAt() {}
399
+ };
400
+ }
401
+ }();
402
+ }
403
+ /**
404
+ @internal
405
+ */
406
+ isDone(upto) {
407
+ upto = Math.min(upto, this.state.doc.length);
408
+ let frags = this.fragments;
409
+ return this.treeLen >= upto && frags.length && frags[0].from == 0 && frags[0].to >= upto;
410
+ }
411
+ /**
412
+ Get the context for the current parse, or `null` if no editor
413
+ parse is in progress.
414
+ */
415
+ static get() {
416
+ return currentContext;
417
+ }
418
+ };
419
+ function cutFragments(fragments, from, to) {
420
+ return TreeFragment.applyChanges(fragments, [{
421
+ fromA: from,
422
+ toA: to,
423
+ fromB: from,
424
+ toB: to
425
+ }]);
426
+ }
427
+ var LanguageState = class LanguageState {
428
+ constructor(context) {
429
+ this.context = context;
430
+ this.tree = context.tree;
431
+ }
432
+ apply(tr) {
433
+ if (!tr.docChanged && this.tree == this.context.tree) return this;
434
+ let newCx = this.context.changes(tr.changes, tr.state);
435
+ let upto = this.context.treeLen == tr.startState.doc.length ? void 0 : Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
436
+ if (!newCx.work(20, upto)) newCx.takeTree();
437
+ return new LanguageState(newCx);
438
+ }
439
+ static init(state) {
440
+ let vpTo = Math.min(3e3, state.doc.length);
441
+ let parseState = ParseContext.create(state.facet(language).parser, state, {
442
+ from: 0,
443
+ to: vpTo
444
+ });
445
+ if (!parseState.work(20, vpTo)) parseState.takeTree();
446
+ return new LanguageState(parseState);
447
+ }
448
+ };
449
+ Language.state = /*@__PURE__*/ StateField.define({
450
+ create: LanguageState.init,
451
+ update(value, tr) {
452
+ for (let e of tr.effects) if (e.is(Language.setState)) return e.value;
453
+ if (tr.startState.facet(language) != tr.state.facet(language)) return LanguageState.init(tr.state);
454
+ return value.apply(tr);
455
+ }
456
+ });
457
+ let requestIdle = (callback) => {
458
+ let timeout = setTimeout(() => callback(), 500);
459
+ return () => clearTimeout(timeout);
460
+ };
461
+ if (typeof requestIdleCallback != "undefined") requestIdle = (callback) => {
462
+ let idle = -1, timeout = setTimeout(() => {
463
+ idle = requestIdleCallback(callback, { timeout: 400 });
464
+ }, 100);
465
+ return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
466
+ };
467
+ const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending) ? () => navigator.scheduling.isInputPending() : null;
468
+ const parseWorker = /*@__PURE__*/ ViewPlugin.fromClass(class ParseWorker {
469
+ constructor(view) {
470
+ this.view = view;
471
+ this.working = null;
472
+ this.workScheduled = 0;
473
+ this.chunkEnd = -1;
474
+ this.chunkBudget = -1;
475
+ this.work = this.work.bind(this);
476
+ this.scheduleWork();
477
+ }
478
+ update(update) {
479
+ let cx = this.view.state.field(Language.state).context;
480
+ if (cx.updateViewport(update.view.viewport) || this.view.viewport.to > cx.treeLen) this.scheduleWork();
481
+ if (update.docChanged || update.selectionSet) {
482
+ if (this.view.hasFocus) this.chunkBudget += 50;
483
+ this.scheduleWork();
484
+ }
485
+ this.checkAsyncSchedule(cx);
486
+ }
487
+ scheduleWork() {
488
+ if (this.working) return;
489
+ let { state } = this.view, field = state.field(Language.state);
490
+ if (field.tree != field.context.tree || !field.context.isDone(state.doc.length)) this.working = requestIdle(this.work);
491
+ }
492
+ work(deadline) {
493
+ this.working = null;
494
+ let now = Date.now();
495
+ if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) {
496
+ this.chunkEnd = now + 3e4;
497
+ this.chunkBudget = 3e3;
498
+ }
499
+ if (this.chunkBudget <= 0) return;
500
+ let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
501
+ if (field.tree == field.context.tree && field.context.isDone(vpTo + 1e5)) return;
502
+ let endTime = Date.now() + Math.min(this.chunkBudget, 100, deadline && !isInputPending ? Math.max(25, deadline.timeRemaining() - 5) : 1e9);
503
+ let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1e3;
504
+ let done = field.context.work(() => {
505
+ return isInputPending && isInputPending() || Date.now() > endTime;
506
+ }, vpTo + (viewportFirst ? 0 : 1e5));
507
+ this.chunkBudget -= Date.now() - now;
508
+ if (done || this.chunkBudget <= 0) {
509
+ field.context.takeTree();
510
+ this.view.dispatch({ effects: Language.setState.of(new LanguageState(field.context)) });
511
+ }
512
+ if (this.chunkBudget > 0 && !(done && !viewportFirst)) this.scheduleWork();
513
+ this.checkAsyncSchedule(field.context);
514
+ }
515
+ checkAsyncSchedule(cx) {
516
+ if (cx.scheduleOn) {
517
+ this.workScheduled++;
518
+ cx.scheduleOn.then(() => this.scheduleWork()).catch((err) => logException(this.view.state, err)).then(() => this.workScheduled--);
519
+ cx.scheduleOn = null;
520
+ }
521
+ }
522
+ destroy() {
523
+ if (this.working) this.working();
524
+ }
525
+ isWorking() {
526
+ return !!(this.working || this.workScheduled > 0);
527
+ }
528
+ }, { eventHandlers: { focus() {
529
+ this.scheduleWork();
530
+ } } });
531
+ /**
532
+ The facet used to associate a language with an editor state. Used
533
+ by `Language` object's `extension` property (so you don't need to
534
+ manually wrap your languages in this). Can be used to access the
535
+ current language on a state.
536
+ */
537
+ const language = /*@__PURE__*/ Facet.define({
538
+ combine(languages) {
539
+ return languages.length ? languages[0] : null;
540
+ },
541
+ enables: (language) => [
542
+ Language.state,
543
+ parseWorker,
544
+ EditorView.contentAttributes.compute([language], (state) => {
545
+ let lang = state.facet(language);
546
+ return lang && lang.name ? { "data-language": lang.name } : {};
547
+ })
548
+ ]
549
+ });
550
+ /**
551
+ This class bundles a [language](https://codemirror.net/6/docs/ref/#language.Language) with an
552
+ optional set of supporting extensions. Language packages are
553
+ encouraged to export a function that optionally takes a
554
+ configuration object and returns a `LanguageSupport` instance, as
555
+ the main way for client code to use the package.
556
+ */
557
+ var LanguageSupport = class {
558
+ /**
559
+ Create a language support object.
560
+ */
561
+ constructor(language, support = []) {
562
+ this.language = language;
563
+ this.support = support;
564
+ this.extension = [language, support];
565
+ }
566
+ };
567
+ /**
568
+ Facet that defines a way to provide a function that computes the
569
+ appropriate indentation depth, as a column number (see
570
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
571
+ line. A return value of `null` indicates no indentation can be
572
+ determined, and the line should inherit the indentation of the one
573
+ above it. A return value of `undefined` defers to the next indent
574
+ service.
575
+ */
576
+ const indentService = /*@__PURE__*/ Facet.define();
577
+ /**
578
+ Facet for overriding the unit by which indentation happens. Should
579
+ be a string consisting entirely of the same whitespace character.
580
+ When not set, this defaults to 2 spaces.
581
+ */
582
+ const indentUnit = /*@__PURE__*/ Facet.define({ combine: (values) => {
583
+ if (!values.length) return " ";
584
+ let unit = values[0];
585
+ if (!unit || /\S/.test(unit) || Array.from(unit).some((e) => e != unit[0])) throw new Error("Invalid indent unit: " + JSON.stringify(values[0]));
586
+ return unit;
587
+ } });
588
+ /**
589
+ Return the _column width_ of an indent unit in the state.
590
+ Determined by the [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit)
591
+ facet, and [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) when that
592
+ contains tabs.
593
+ */
594
+ function getIndentUnit(state) {
595
+ let unit = state.facet(indentUnit);
596
+ return unit.charCodeAt(0) == 9 ? state.tabSize * unit.length : unit.length;
597
+ }
598
+ /**
599
+ Create an indentation string that covers columns 0 to `cols`.
600
+ Will use tabs for as much of the columns as possible when the
601
+ [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit) facet contains
602
+ tabs.
603
+ */
604
+ function indentString(state, cols) {
605
+ let result = "", ts = state.tabSize, ch = state.facet(indentUnit)[0];
606
+ if (ch == " ") {
607
+ while (cols >= ts) {
608
+ result += " ";
609
+ cols -= ts;
610
+ }
611
+ ch = " ";
612
+ }
613
+ for (let i = 0; i < cols; i++) result += ch;
614
+ return result;
615
+ }
616
+ /**
617
+ Get the indentation, as a column number, at the given position.
618
+ Will first consult any [indent services](https://codemirror.net/6/docs/ref/#language.indentService)
619
+ that are registered, and if none of those return an indentation,
620
+ this will check the syntax tree for the [indent node
621
+ prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp) and use that if found. Returns a
622
+ number when an indentation could be determined, and null
623
+ otherwise.
624
+ */
625
+ function getIndentation(context, pos) {
626
+ if (context instanceof EditorState) context = new IndentContext(context);
627
+ for (let service of context.state.facet(indentService)) {
628
+ let result = service(context, pos);
629
+ if (result !== void 0) return result;
630
+ }
631
+ let tree = syntaxTree(context.state);
632
+ return tree.length >= pos ? syntaxIndentation(context, tree, pos) : null;
633
+ }
634
+ /**
635
+ Indentation contexts are used when calling [indentation
636
+ services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
637
+ useful in indentation logic, and can selectively override the
638
+ indentation reported for some lines.
639
+ */
640
+ var IndentContext = class {
641
+ /**
642
+ Create an indent context.
643
+ */
644
+ constructor(state, options = {}) {
645
+ this.state = state;
646
+ this.options = options;
647
+ this.unit = getIndentUnit(state);
648
+ }
649
+ /**
650
+ Get a description of the line at the given position, taking
651
+ [simulated line
652
+ breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
653
+ into account. If there is such a break at `pos`, the `bias`
654
+ argument determines whether the part of the line line before or
655
+ after the break is used.
656
+ */
657
+ lineAt(pos, bias = 1) {
658
+ let line = this.state.doc.lineAt(pos);
659
+ let { simulateBreak, simulateDoubleBreak } = this.options;
660
+ if (simulateBreak != null && simulateBreak >= line.from && simulateBreak <= line.to) if (simulateDoubleBreak && simulateBreak == pos) return {
661
+ text: "",
662
+ from: pos
663
+ };
664
+ else if (bias < 0 ? simulateBreak < pos : simulateBreak <= pos) return {
665
+ text: line.text.slice(simulateBreak - line.from),
666
+ from: simulateBreak
667
+ };
668
+ else return {
669
+ text: line.text.slice(0, simulateBreak - line.from),
670
+ from: line.from
671
+ };
672
+ return line;
673
+ }
674
+ /**
675
+ Get the text directly after `pos`, either the entire line
676
+ or the next 100 characters, whichever is shorter.
677
+ */
678
+ textAfterPos(pos, bias = 1) {
679
+ if (this.options.simulateDoubleBreak && pos == this.options.simulateBreak) return "";
680
+ let { text, from } = this.lineAt(pos, bias);
681
+ return text.slice(pos - from, Math.min(text.length, pos + 100 - from));
682
+ }
683
+ /**
684
+ Find the column for the given position.
685
+ */
686
+ column(pos, bias = 1) {
687
+ let { text, from } = this.lineAt(pos, bias);
688
+ let result = this.countColumn(text, pos - from);
689
+ let override = this.options.overrideIndentation ? this.options.overrideIndentation(from) : -1;
690
+ if (override > -1) result += override - this.countColumn(text, text.search(/\S|$/));
691
+ return result;
692
+ }
693
+ /**
694
+ Find the column position (taking tabs into account) of the given
695
+ position in the given string.
696
+ */
697
+ countColumn(line, pos = line.length) {
698
+ return countColumn(line, this.state.tabSize, pos);
699
+ }
700
+ /**
701
+ Find the indentation column of the line at the given point.
702
+ */
703
+ lineIndent(pos, bias = 1) {
704
+ let { text, from } = this.lineAt(pos, bias);
705
+ let override = this.options.overrideIndentation;
706
+ if (override) {
707
+ let overriden = override(from);
708
+ if (overriden > -1) return overriden;
709
+ }
710
+ return this.countColumn(text, text.search(/\S|$/));
711
+ }
712
+ /**
713
+ Returns the [simulated line
714
+ break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
715
+ for this context, if any.
716
+ */
717
+ get simulatedBreak() {
718
+ return this.options.simulateBreak || null;
719
+ }
720
+ };
721
+ /**
722
+ A syntax tree node prop used to associate indentation strategies
723
+ with node types. Such a strategy is a function from an indentation
724
+ context to a column number (see also
725
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)) or null, where null
726
+ indicates that no definitive indentation can be determined.
727
+ */
728
+ const indentNodeProp = /*@__PURE__*/ new NodeProp();
729
+ function syntaxIndentation(cx, ast, pos) {
730
+ let stack = ast.resolveStack(pos);
731
+ let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
732
+ if (inner != stack.node) {
733
+ let add = [];
734
+ for (let cur = inner; cur && !(cur.from < stack.node.from || cur.to > stack.node.to || cur.from == stack.node.from && cur.type == stack.node.type); cur = cur.parent) add.push(cur);
735
+ for (let i = add.length - 1; i >= 0; i--) stack = {
736
+ node: add[i],
737
+ next: stack
738
+ };
739
+ }
740
+ return indentFor(stack, cx, pos);
741
+ }
742
+ function indentFor(stack, cx, pos) {
743
+ for (let cur = stack; cur; cur = cur.next) {
744
+ let strategy = indentStrategy(cur.node);
745
+ if (strategy) return strategy(TreeIndentContext.create(cx, pos, cur));
746
+ }
747
+ return 0;
748
+ }
749
+ function ignoreClosed(cx) {
750
+ return cx.pos == cx.options.simulateBreak && cx.options.simulateDoubleBreak;
751
+ }
752
+ function indentStrategy(tree) {
753
+ let strategy = tree.type.prop(indentNodeProp);
754
+ if (strategy) return strategy;
755
+ let first = tree.firstChild, close;
756
+ if (first && (close = first.type.prop(NodeProp.closedBy))) {
757
+ let last = tree.lastChild, closed = last && close.indexOf(last.name) > -1;
758
+ return (cx) => delimitedStrategy(cx, true, 1, void 0, closed && !ignoreClosed(cx) ? last.from : void 0);
759
+ }
760
+ return tree.parent == null ? topIndent : null;
761
+ }
762
+ function topIndent() {
763
+ return 0;
764
+ }
765
+ /**
766
+ Objects of this type provide context information and helper
767
+ methods to indentation functions registered on syntax nodes.
768
+ */
769
+ var TreeIndentContext = class TreeIndentContext extends IndentContext {
770
+ constructor(base, pos, context) {
771
+ super(base.state, base.options);
772
+ this.base = base;
773
+ this.pos = pos;
774
+ this.context = context;
775
+ }
776
+ /**
777
+ The syntax tree node to which the indentation strategy
778
+ applies.
779
+ */
780
+ get node() {
781
+ return this.context.node;
782
+ }
783
+ /**
784
+ @internal
785
+ */
786
+ static create(base, pos, context) {
787
+ return new TreeIndentContext(base, pos, context);
788
+ }
789
+ /**
790
+ Get the text directly after `this.pos`, either the entire line
791
+ or the next 100 characters, whichever is shorter.
792
+ */
793
+ get textAfter() {
794
+ return this.textAfterPos(this.pos);
795
+ }
796
+ /**
797
+ Get the indentation at the reference line for `this.node`, which
798
+ is the line on which it starts, unless there is a node that is
799
+ _not_ a parent of this node covering the start of that line. If
800
+ so, the line at the start of that node is tried, again skipping
801
+ on if it is covered by another such node.
802
+ */
803
+ get baseIndent() {
804
+ return this.baseIndentFor(this.node);
805
+ }
806
+ /**
807
+ Get the indentation for the reference line of the given node
808
+ (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
809
+ */
810
+ baseIndentFor(node) {
811
+ let line = this.state.doc.lineAt(node.from);
812
+ for (;;) {
813
+ let atBreak = node.resolve(line.from);
814
+ while (atBreak.parent && atBreak.parent.from == atBreak.from) atBreak = atBreak.parent;
815
+ if (isParent(atBreak, node)) break;
816
+ line = this.state.doc.lineAt(atBreak.from);
817
+ }
818
+ return this.lineIndent(line.from);
819
+ }
820
+ /**
821
+ Continue looking for indentations in the node's parent nodes,
822
+ and return the result of that.
823
+ */
824
+ continue() {
825
+ return indentFor(this.context.next, this.base, this.pos);
826
+ }
827
+ };
828
+ function isParent(parent, of) {
829
+ for (let cur = of; cur; cur = cur.parent) if (parent == cur) return true;
830
+ return false;
831
+ }
832
+ function bracketedAligned(context) {
833
+ let tree = context.node;
834
+ let openToken = tree.childAfter(tree.from), last = tree.lastChild;
835
+ if (!openToken) return null;
836
+ let sim = context.options.simulateBreak;
837
+ let openLine = context.state.doc.lineAt(openToken.from);
838
+ let lineEnd = sim == null || sim <= openLine.from ? openLine.to : Math.min(openLine.to, sim);
839
+ for (let pos = openToken.to;;) {
840
+ let next = tree.childAfter(pos);
841
+ if (!next || next == last) return null;
842
+ if (!next.type.isSkipped) {
843
+ if (next.from >= lineEnd) return null;
844
+ let space = /^ */.exec(openLine.text.slice(openToken.to - openLine.from))[0].length;
845
+ return {
846
+ from: openToken.from,
847
+ to: openToken.to + space
848
+ };
849
+ }
850
+ pos = next.to;
851
+ }
852
+ }
853
+ /**
854
+ An indentation strategy for delimited (usually bracketed) nodes.
855
+ Will, by default, indent one unit more than the parent's base
856
+ indent unless the line starts with a closing token. When `align`
857
+ is true and there are non-skipped nodes on the node's opening
858
+ line, the content of the node will be aligned with the end of the
859
+ opening node, like this:
860
+
861
+ foo(bar,
862
+ baz)
863
+ */
864
+ function delimitedIndent({ closing, align = true, units = 1 }) {
865
+ return (context) => delimitedStrategy(context, align, units, closing);
866
+ }
867
+ function delimitedStrategy(context, align, units, closing, closedAt) {
868
+ let after = context.textAfter, space = after.match(/^\s*/)[0].length;
869
+ let closed = closing && after.slice(space, space + closing.length) == closing || closedAt == context.pos + space;
870
+ let aligned = align ? bracketedAligned(context) : null;
871
+ if (aligned) return closed ? context.column(aligned.from) : context.column(aligned.to);
872
+ return context.baseIndent + (closed ? 0 : context.unit * units);
873
+ }
874
+ /**
875
+ An indentation strategy that aligns a node's content to its base
876
+ indentation.
877
+ */
878
+ const flatIndent = (context) => context.baseIndent;
879
+ /**
880
+ Creates an indentation strategy that, by default, indents
881
+ continued lines one unit more than the node's base indentation.
882
+ You can provide `except` to prevent indentation of lines that
883
+ match a pattern (for example `/^else\b/` in `if`/`else`
884
+ constructs), and you can change the amount of units used with the
885
+ `units` option.
886
+ */
887
+ function continuedIndent({ except, units = 1 } = {}) {
888
+ return (context) => {
889
+ let matchExcept = except && except.test(context.textAfter);
890
+ return context.baseIndent + (matchExcept ? 0 : units * context.unit);
891
+ };
892
+ }
893
+ const DontIndentBeyond = 200;
894
+ /**
895
+ Enables reindentation on input. When a language defines an
896
+ `indentOnInput` field in its [language
897
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt), which must hold a regular
898
+ expression, the line at the cursor will be reindented whenever new
899
+ text is typed and the input from the start of the line up to the
900
+ cursor matches that regexp.
901
+
902
+ To avoid unneccesary reindents, it is recommended to start the
903
+ regexp with `^` (usually followed by `\s*`), and end it with `$`.
904
+ For example, `/^\s*\}$/` will reindent when a closing brace is
905
+ added at the start of a line.
906
+ */
907
+ function indentOnInput() {
908
+ return EditorState.transactionFilter.of((tr) => {
909
+ if (!tr.docChanged || !tr.isUserEvent("input.type") && !tr.isUserEvent("input.complete")) return tr;
910
+ let rules = tr.startState.languageDataAt("indentOnInput", tr.startState.selection.main.head);
911
+ if (!rules.length) return tr;
912
+ let doc = tr.newDoc, { head } = tr.newSelection.main, line = doc.lineAt(head);
913
+ if (head > line.from + DontIndentBeyond) return tr;
914
+ let lineStart = doc.sliceString(line.from, head);
915
+ if (!rules.some((r) => r.test(lineStart))) return tr;
916
+ let { state } = tr, last = -1, changes = [];
917
+ for (let { head } of state.selection.ranges) {
918
+ let line = state.doc.lineAt(head);
919
+ if (line.from == last) continue;
920
+ last = line.from;
921
+ let indent = getIndentation(state, line.from);
922
+ if (indent == null) continue;
923
+ let cur = /^\s*/.exec(line.text)[0];
924
+ let norm = indentString(state, indent);
925
+ if (cur != norm) changes.push({
926
+ from: line.from,
927
+ to: line.from + cur.length,
928
+ insert: norm
929
+ });
930
+ }
931
+ return changes.length ? [tr, {
932
+ changes,
933
+ sequential: true
934
+ }] : tr;
935
+ });
936
+ }
937
+ /**
938
+ A facet that registers a code folding service. When called with
939
+ the extent of a line, such a function should return a foldable
940
+ range that starts on that line (but continues beyond it), if one
941
+ can be found.
942
+ */
943
+ const foldService = /*@__PURE__*/ Facet.define();
944
+ /**
945
+ This node prop is used to associate folding information with
946
+ syntax node types. Given a syntax node, it should check whether
947
+ that tree is foldable and return the range that can be collapsed
948
+ when it is.
949
+ */
950
+ const foldNodeProp = /*@__PURE__*/ new NodeProp();
951
+ /**
952
+ [Fold](https://codemirror.net/6/docs/ref/#language.foldNodeProp) function that folds everything but
953
+ the first and the last child of a syntax node. Useful for nodes
954
+ that start and end with delimiters.
955
+ */
956
+ function foldInside(node) {
957
+ let first = node.firstChild, last = node.lastChild;
958
+ return first && first.to < last.from ? {
959
+ from: first.to,
960
+ to: last.type.isError ? node.to : last.from
961
+ } : null;
962
+ }
963
+ function syntaxFolding(state, start, end) {
964
+ let tree = syntaxTree(state);
965
+ if (tree.length < end) return null;
966
+ let stack = tree.resolveStack(end, 1);
967
+ let found = null;
968
+ for (let iter = stack; iter; iter = iter.next) {
969
+ let cur = iter.node;
970
+ if (cur.to <= end || cur.from > end) continue;
971
+ if (found && cur.from < start) break;
972
+ let prop = cur.type.prop(foldNodeProp);
973
+ if (prop && (cur.to < tree.length - 50 || tree.length == state.doc.length || !isUnfinished(cur))) {
974
+ let value = prop(cur, state);
975
+ if (value && value.from <= end && value.from >= start && value.to > end) found = value;
976
+ }
977
+ }
978
+ return found;
979
+ }
980
+ function isUnfinished(node) {
981
+ let ch = node.lastChild;
982
+ return ch && ch.to == node.to && ch.type.isError;
983
+ }
984
+ /**
985
+ Check whether the given line is foldable. First asks any fold
986
+ services registered through
987
+ [`foldService`](https://codemirror.net/6/docs/ref/#language.foldService), and if none of them return
988
+ a result, tries to query the [fold node
989
+ prop](https://codemirror.net/6/docs/ref/#language.foldNodeProp) of syntax nodes that cover the end
990
+ of the line.
991
+ */
992
+ function foldable(state, lineStart, lineEnd) {
993
+ for (let service of state.facet(foldService)) {
994
+ let result = service(state, lineStart, lineEnd);
995
+ if (result) return result;
996
+ }
997
+ return syntaxFolding(state, lineStart, lineEnd);
998
+ }
999
+ function mapRange(range, mapping) {
1000
+ let from = mapping.mapPos(range.from, 1), to = mapping.mapPos(range.to, -1);
1001
+ return from >= to ? void 0 : {
1002
+ from,
1003
+ to
1004
+ };
1005
+ }
1006
+ /**
1007
+ State effect that can be attached to a transaction to fold the
1008
+ given range. (You probably only need this in exceptional
1009
+ circumstances—usually you'll just want to let
1010
+ [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode) and the [fold
1011
+ gutter](https://codemirror.net/6/docs/ref/#language.foldGutter) create the transactions.)
1012
+ */
1013
+ const foldEffect = /*@__PURE__*/ StateEffect.define({ map: mapRange });
1014
+ /**
1015
+ State effect that unfolds the given range (if it was folded).
1016
+ */
1017
+ const unfoldEffect = /*@__PURE__*/ StateEffect.define({ map: mapRange });
1018
+ function selectedLines(view) {
1019
+ let lines = [];
1020
+ for (let { head } of view.state.selection.ranges) {
1021
+ if (lines.some((l) => l.from <= head && l.to >= head)) continue;
1022
+ lines.push(view.lineBlockAt(head));
1023
+ }
1024
+ return lines;
1025
+ }
1026
+ /**
1027
+ The state field that stores the folded ranges (as a [decoration
1028
+ set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
1029
+ [`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
1030
+ [`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
1031
+ state.
1032
+ */
1033
+ const foldState = /*@__PURE__*/ StateField.define({
1034
+ create() {
1035
+ return Decoration.none;
1036
+ },
1037
+ update(folded, tr) {
1038
+ if (tr.isUserEvent("delete")) tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
1039
+ folded = folded.map(tr.changes);
1040
+ let rangesToFold = [];
1041
+ for (let e of tr.effects) if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) rangesToFold.push(e.value);
1042
+ else if (e.is(unfoldEffect)) folded = folded.update({
1043
+ filter: (from, to) => e.value.from != from || e.value.to != to,
1044
+ filterFrom: e.value.from,
1045
+ filterTo: e.value.to
1046
+ });
1047
+ if (rangesToFold.length) {
1048
+ let { preparePlaceholder } = tr.state.facet(foldConfig);
1049
+ let decorations = rangesToFold.map((value) => {
1050
+ return (!preparePlaceholder ? foldWidget : Decoration.replace({ widget: new PreparedFoldWidget(preparePlaceholder(tr.state, value)) })).range(value.from, value.to);
1051
+ });
1052
+ folded = folded.update({ add: decorations });
1053
+ }
1054
+ if (tr.selection) folded = clearTouchedFolds(folded, tr.selection.main.head);
1055
+ return folded;
1056
+ },
1057
+ provide: (f) => EditorView.decorations.from(f),
1058
+ toJSON(folded, state) {
1059
+ let ranges = [];
1060
+ folded.between(0, state.doc.length, (from, to) => {
1061
+ ranges.push(from, to);
1062
+ });
1063
+ return ranges;
1064
+ },
1065
+ fromJSON(value) {
1066
+ if (!Array.isArray(value) || value.length % 2) throw new RangeError("Invalid JSON for fold state");
1067
+ let ranges = [];
1068
+ for (let i = 0; i < value.length;) {
1069
+ let from = value[i++], to = value[i++];
1070
+ if (typeof from != "number" || typeof to != "number") throw new RangeError("Invalid JSON for fold state");
1071
+ ranges.push(foldWidget.range(from, to));
1072
+ }
1073
+ return Decoration.set(ranges, true);
1074
+ }
1075
+ });
1076
+ function clearTouchedFolds(folded, from, to = from) {
1077
+ let touched = false;
1078
+ folded.between(from, to, (a, b) => {
1079
+ if (a < to && b > from) touched = true;
1080
+ });
1081
+ return !touched ? folded : folded.update({
1082
+ filterFrom: from,
1083
+ filterTo: to,
1084
+ filter: (a, b) => a >= to || b <= from
1085
+ });
1086
+ }
1087
+ function findFold(state, from, to) {
1088
+ var _a;
1089
+ let found = null;
1090
+ (_a = state.field(foldState, false)) === null || _a === void 0 || _a.between(from, to, (from, to) => {
1091
+ if (!found || found.from > from) found = {
1092
+ from,
1093
+ to
1094
+ };
1095
+ });
1096
+ return found;
1097
+ }
1098
+ function foldExists(folded, from, to) {
1099
+ let found = false;
1100
+ folded.between(from, from, (a, b) => {
1101
+ if (a == from && b == to) found = true;
1102
+ });
1103
+ return found;
1104
+ }
1105
+ function maybeEnable(state, other) {
1106
+ return state.field(foldState, false) ? other : other.concat(StateEffect.appendConfig.of(codeFolding()));
1107
+ }
1108
+ /**
1109
+ Fold the lines that are selected, if possible.
1110
+ */
1111
+ const foldCode = (view) => {
1112
+ for (let line of selectedLines(view)) {
1113
+ let range = foldable(view.state, line.from, line.to);
1114
+ if (range) {
1115
+ view.dispatch({ effects: maybeEnable(view.state, [foldEffect.of(range), announceFold(view, range)]) });
1116
+ return true;
1117
+ }
1118
+ }
1119
+ return false;
1120
+ };
1121
+ /**
1122
+ Unfold folded ranges on selected lines.
1123
+ */
1124
+ const unfoldCode = (view) => {
1125
+ if (!view.state.field(foldState, false)) return false;
1126
+ let effects = [];
1127
+ for (let line of selectedLines(view)) {
1128
+ let folded = findFold(view.state, line.from, line.to);
1129
+ if (folded) effects.push(unfoldEffect.of(folded), announceFold(view, folded, false));
1130
+ }
1131
+ if (effects.length) view.dispatch({ effects });
1132
+ return effects.length > 0;
1133
+ };
1134
+ function announceFold(view, range, fold = true) {
1135
+ let lineFrom = view.state.doc.lineAt(range.from).number, lineTo = view.state.doc.lineAt(range.to).number;
1136
+ return EditorView.announce.of(`${view.state.phrase(fold ? "Folded lines" : "Unfolded lines")} ${lineFrom} ${view.state.phrase("to")} ${lineTo}.`);
1137
+ }
1138
+ /**
1139
+ Fold all top-level foldable ranges. Note that, in most cases,
1140
+ folding information will depend on the [syntax
1141
+ tree](https://codemirror.net/6/docs/ref/#language.syntaxTree), and folding everything may not work
1142
+ reliably when the document hasn't been fully parsed (either
1143
+ because the editor state was only just initialized, or because the
1144
+ document is so big that the parser decided not to parse it
1145
+ entirely).
1146
+ */
1147
+ const foldAll = (view) => {
1148
+ let { state } = view, effects = [];
1149
+ for (let pos = 0; pos < state.doc.length;) {
1150
+ let line = view.lineBlockAt(pos), range = foldable(state, line.from, line.to);
1151
+ if (range) effects.push(foldEffect.of(range));
1152
+ pos = (range ? view.lineBlockAt(range.to) : line).to + 1;
1153
+ }
1154
+ if (effects.length) view.dispatch({ effects: maybeEnable(view.state, effects) });
1155
+ return !!effects.length;
1156
+ };
1157
+ /**
1158
+ Unfold all folded code.
1159
+ */
1160
+ const unfoldAll = (view) => {
1161
+ let field = view.state.field(foldState, false);
1162
+ if (!field || !field.size) return false;
1163
+ let effects = [];
1164
+ field.between(0, view.state.doc.length, (from, to) => {
1165
+ effects.push(unfoldEffect.of({
1166
+ from,
1167
+ to
1168
+ }));
1169
+ });
1170
+ view.dispatch({ effects });
1171
+ return true;
1172
+ };
1173
+ /**
1174
+ Default fold-related key bindings.
1175
+
1176
+ - Ctrl-Shift-[ (Cmd-Alt-[ on macOS): [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode).
1177
+ - Ctrl-Shift-] (Cmd-Alt-] on macOS): [`unfoldCode`](https://codemirror.net/6/docs/ref/#language.unfoldCode).
1178
+ - Ctrl-Alt-[: [`foldAll`](https://codemirror.net/6/docs/ref/#language.foldAll).
1179
+ - Ctrl-Alt-]: [`unfoldAll`](https://codemirror.net/6/docs/ref/#language.unfoldAll).
1180
+ */
1181
+ const foldKeymap = [
1182
+ {
1183
+ key: "Ctrl-Shift-[",
1184
+ mac: "Cmd-Alt-[",
1185
+ run: foldCode
1186
+ },
1187
+ {
1188
+ key: "Ctrl-Shift-]",
1189
+ mac: "Cmd-Alt-]",
1190
+ run: unfoldCode
1191
+ },
1192
+ {
1193
+ key: "Ctrl-Alt-[",
1194
+ run: foldAll
1195
+ },
1196
+ {
1197
+ key: "Ctrl-Alt-]",
1198
+ run: unfoldAll
1199
+ }
1200
+ ];
1201
+ const defaultConfig = {
1202
+ placeholderDOM: null,
1203
+ preparePlaceholder: null,
1204
+ placeholderText: "…"
1205
+ };
1206
+ const foldConfig = /*@__PURE__*/ Facet.define({ combine(values) {
1207
+ return combineConfig(values, defaultConfig);
1208
+ } });
1209
+ /**
1210
+ Create an extension that configures code folding.
1211
+ */
1212
+ function codeFolding(config) {
1213
+ let result = [foldState, baseTheme$1];
1214
+ if (config) result.push(foldConfig.of(config));
1215
+ return result;
1216
+ }
1217
+ function widgetToDOM(view, prepared) {
1218
+ let { state } = view, conf = state.facet(foldConfig);
1219
+ let onclick = (event) => {
1220
+ let line = view.lineBlockAt(view.posAtDOM(event.target));
1221
+ let folded = findFold(view.state, line.from, line.to);
1222
+ if (folded) view.dispatch({ effects: unfoldEffect.of(folded) });
1223
+ event.preventDefault();
1224
+ };
1225
+ if (conf.placeholderDOM) return conf.placeholderDOM(view, onclick, prepared);
1226
+ let element = document.createElement("span");
1227
+ element.textContent = conf.placeholderText;
1228
+ element.setAttribute("aria-label", state.phrase("folded code"));
1229
+ element.title = state.phrase("unfold");
1230
+ element.className = "cm-foldPlaceholder";
1231
+ element.onclick = onclick;
1232
+ return element;
1233
+ }
1234
+ const foldWidget = /*@__PURE__*/ Decoration.replace({ widget: /*@__PURE__*/ new class extends WidgetType {
1235
+ toDOM(view) {
1236
+ return widgetToDOM(view, null);
1237
+ }
1238
+ }() });
1239
+ var PreparedFoldWidget = class extends WidgetType {
1240
+ constructor(value) {
1241
+ super();
1242
+ this.value = value;
1243
+ }
1244
+ eq(other) {
1245
+ return this.value == other.value;
1246
+ }
1247
+ toDOM(view) {
1248
+ return widgetToDOM(view, this.value);
1249
+ }
1250
+ };
1251
+ const foldGutterDefaults = {
1252
+ openText: "⌄",
1253
+ closedText: "›",
1254
+ markerDOM: null,
1255
+ domEventHandlers: {},
1256
+ foldingChanged: () => false
1257
+ };
1258
+ var FoldMarker = class extends GutterMarker {
1259
+ constructor(config, open) {
1260
+ super();
1261
+ this.config = config;
1262
+ this.open = open;
1263
+ }
1264
+ eq(other) {
1265
+ return this.config == other.config && this.open == other.open;
1266
+ }
1267
+ toDOM(view) {
1268
+ if (this.config.markerDOM) return this.config.markerDOM(this.open);
1269
+ let span = document.createElement("span");
1270
+ span.textContent = this.open ? this.config.openText : this.config.closedText;
1271
+ span.title = view.state.phrase(this.open ? "Fold line" : "Unfold line");
1272
+ return span;
1273
+ }
1274
+ };
1275
+ /**
1276
+ Create an extension that registers a fold gutter, which shows a
1277
+ fold status indicator before foldable lines (which can be clicked
1278
+ to fold or unfold the line).
1279
+ */
1280
+ function foldGutter(config = {}) {
1281
+ let fullConfig = {
1282
+ ...foldGutterDefaults,
1283
+ ...config
1284
+ };
1285
+ let canFold = new FoldMarker(fullConfig, true), canUnfold = new FoldMarker(fullConfig, false);
1286
+ let markers = ViewPlugin.fromClass(class {
1287
+ constructor(view) {
1288
+ this.from = view.viewport.from;
1289
+ this.markers = this.buildMarkers(view);
1290
+ }
1291
+ update(update) {
1292
+ if (update.docChanged || update.viewportChanged || update.startState.facet(language) != update.state.facet(language) || update.startState.field(foldState, false) != update.state.field(foldState, false) || syntaxTree(update.startState) != syntaxTree(update.state) || fullConfig.foldingChanged(update)) this.markers = this.buildMarkers(update.view);
1293
+ }
1294
+ buildMarkers(view) {
1295
+ let builder = new RangeSetBuilder();
1296
+ for (let line of view.viewportLineBlocks) {
1297
+ let mark = findFold(view.state, line.from, line.to) ? canUnfold : foldable(view.state, line.from, line.to) ? canFold : null;
1298
+ if (mark) builder.add(line.from, line.from, mark);
1299
+ }
1300
+ return builder.finish();
1301
+ }
1302
+ });
1303
+ let { domEventHandlers } = fullConfig;
1304
+ return [
1305
+ markers,
1306
+ gutter({
1307
+ class: "cm-foldGutter",
1308
+ markers(view) {
1309
+ var _a;
1310
+ return ((_a = view.plugin(markers)) === null || _a === void 0 ? void 0 : _a.markers) || RangeSet.empty;
1311
+ },
1312
+ initialSpacer() {
1313
+ return new FoldMarker(fullConfig, false);
1314
+ },
1315
+ domEventHandlers: {
1316
+ ...domEventHandlers,
1317
+ click: (view, line, event) => {
1318
+ if (domEventHandlers.click && domEventHandlers.click(view, line, event)) return true;
1319
+ let folded = findFold(view.state, line.from, line.to);
1320
+ if (folded) {
1321
+ view.dispatch({ effects: unfoldEffect.of(folded) });
1322
+ return true;
1323
+ }
1324
+ let range = foldable(view.state, line.from, line.to);
1325
+ if (range) {
1326
+ view.dispatch({ effects: foldEffect.of(range) });
1327
+ return true;
1328
+ }
1329
+ return false;
1330
+ }
1331
+ }
1332
+ }),
1333
+ codeFolding()
1334
+ ];
1335
+ }
1336
+ const baseTheme$1 = /*@__PURE__*/ EditorView.baseTheme({
1337
+ ".cm-foldPlaceholder": {
1338
+ backgroundColor: "#eee",
1339
+ border: "1px solid #ddd",
1340
+ color: "#888",
1341
+ borderRadius: ".2em",
1342
+ margin: "0 1px",
1343
+ padding: "0 1px",
1344
+ cursor: "pointer"
1345
+ },
1346
+ ".cm-foldGutter span": {
1347
+ padding: "0 1px",
1348
+ cursor: "pointer"
1349
+ }
1350
+ });
1351
+ /**
1352
+ A highlight style associates CSS styles with highlighting
1353
+ [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
1354
+ */
1355
+ var HighlightStyle = class HighlightStyle {
1356
+ constructor(specs, options) {
1357
+ this.specs = specs;
1358
+ let modSpec;
1359
+ function def(spec) {
1360
+ let cls = StyleModule.newName();
1361
+ (modSpec || (modSpec = Object.create(null)))["." + cls] = spec;
1362
+ return cls;
1363
+ }
1364
+ const all = typeof options.all == "string" ? options.all : options.all ? def(options.all) : void 0;
1365
+ const scopeOpt = options.scope;
1366
+ this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data : scopeOpt ? (type) => type == scopeOpt : void 0;
1367
+ this.style = tagHighlighter(specs.map((style) => ({
1368
+ tag: style.tag,
1369
+ class: style.class || def(Object.assign({}, style, { tag: null }))
1370
+ })), { all }).style;
1371
+ this.module = modSpec ? new StyleModule(modSpec) : null;
1372
+ this.themeType = options.themeType;
1373
+ }
1374
+ /**
1375
+ Create a highlighter style that associates the given styles to
1376
+ the given tags. The specs must be objects that hold a style tag
1377
+ or array of tags in their `tag` property, and either a single
1378
+ `class` property providing a static CSS class (for highlighter
1379
+ that rely on external styling), or a
1380
+ [`style-mod`](https://code.haverbeke.berlin/marijn/style-mod#documentation)-style
1381
+ set of CSS properties (which define the styling for those tags).
1382
+
1383
+ The CSS rules created for a highlighter will be emitted in the
1384
+ order of the spec's properties. That means that for elements that
1385
+ have multiple tags associated with them, styles defined further
1386
+ down in the list will have a higher CSS precedence than styles
1387
+ defined earlier.
1388
+ */
1389
+ static define(specs, options) {
1390
+ return new HighlightStyle(specs, options || {});
1391
+ }
1392
+ };
1393
+ const highlighterFacet = /*@__PURE__*/ Facet.define();
1394
+ const fallbackHighlighter = /*@__PURE__*/ Facet.define({ combine(values) {
1395
+ return values.length ? [values[0]] : null;
1396
+ } });
1397
+ function getHighlighters(state) {
1398
+ let main = state.facet(highlighterFacet);
1399
+ return main.length ? main : state.facet(fallbackHighlighter);
1400
+ }
1401
+ /**
1402
+ Wrap a highlighter in an editor extension that uses it to apply
1403
+ syntax highlighting to the editor content.
1404
+
1405
+ When multiple (non-fallback) styles are provided, the styling
1406
+ applied is the union of the classes they emit.
1407
+ */
1408
+ function syntaxHighlighting(highlighter, options) {
1409
+ let ext = [treeHighlighter], themeType;
1410
+ if (highlighter instanceof HighlightStyle) {
1411
+ if (highlighter.module) ext.push(EditorView.styleModule.of(highlighter.module));
1412
+ themeType = highlighter.themeType;
1413
+ }
1414
+ if (options === null || options === void 0 ? void 0 : options.fallback) ext.push(fallbackHighlighter.of(highlighter));
1415
+ else if (themeType) ext.push(highlighterFacet.computeN([EditorView.darkTheme], (state) => {
1416
+ return state.facet(EditorView.darkTheme) == (themeType == "dark") ? [highlighter] : [];
1417
+ }));
1418
+ else ext.push(highlighterFacet.of(highlighter));
1419
+ return ext;
1420
+ }
1421
+ var TreeHighlighter = class {
1422
+ constructor(view) {
1423
+ this.markCache = Object.create(null);
1424
+ this.tree = syntaxTree(view.state);
1425
+ this.decorations = this.buildDeco(view, getHighlighters(view.state));
1426
+ this.decoratedTo = view.viewport.to;
1427
+ }
1428
+ update(update) {
1429
+ let tree = syntaxTree(update.state), highlighters = getHighlighters(update.state);
1430
+ let styleChange = highlighters != getHighlighters(update.startState);
1431
+ let { viewport } = update.view, decoratedToMapped = update.changes.mapPos(this.decoratedTo, 1);
1432
+ if (tree.length < viewport.to && !styleChange && tree.type == this.tree.type && decoratedToMapped >= viewport.to) {
1433
+ this.decorations = this.decorations.map(update.changes);
1434
+ this.decoratedTo = decoratedToMapped;
1435
+ } else if (tree != this.tree || update.viewportChanged || styleChange) {
1436
+ this.tree = tree;
1437
+ this.decorations = this.buildDeco(update.view, highlighters);
1438
+ this.decoratedTo = viewport.to;
1439
+ }
1440
+ }
1441
+ buildDeco(view, highlighters) {
1442
+ if (!highlighters || !this.tree.length) return Decoration.none;
1443
+ let builder = new RangeSetBuilder();
1444
+ for (let { from, to } of view.visibleRanges) highlightTree(this.tree, highlighters, (from, to, style) => {
1445
+ builder.add(from, to, this.markCache[style] || (this.markCache[style] = Decoration.mark({ class: style })));
1446
+ }, from, to);
1447
+ return builder.finish();
1448
+ }
1449
+ };
1450
+ const treeHighlighter = /*@__PURE__*/ Prec.high(/*@__PURE__*/ ViewPlugin.fromClass(TreeHighlighter, { decorations: (v) => v.decorations }));
1451
+ /**
1452
+ A default highlight style (works well with light themes).
1453
+ */
1454
+ const defaultHighlightStyle = /*@__PURE__*/ HighlightStyle.define([
1455
+ {
1456
+ tag: tags.meta,
1457
+ color: "#404740"
1458
+ },
1459
+ {
1460
+ tag: tags.link,
1461
+ textDecoration: "underline"
1462
+ },
1463
+ {
1464
+ tag: tags.heading,
1465
+ textDecoration: "underline",
1466
+ fontWeight: "bold"
1467
+ },
1468
+ {
1469
+ tag: tags.emphasis,
1470
+ fontStyle: "italic"
1471
+ },
1472
+ {
1473
+ tag: tags.strong,
1474
+ fontWeight: "bold"
1475
+ },
1476
+ {
1477
+ tag: tags.strikethrough,
1478
+ textDecoration: "line-through"
1479
+ },
1480
+ {
1481
+ tag: tags.keyword,
1482
+ color: "#708"
1483
+ },
1484
+ {
1485
+ tag: [
1486
+ tags.atom,
1487
+ tags.bool,
1488
+ tags.url,
1489
+ tags.contentSeparator,
1490
+ tags.labelName
1491
+ ],
1492
+ color: "#219"
1493
+ },
1494
+ {
1495
+ tag: [tags.literal, tags.inserted],
1496
+ color: "#164"
1497
+ },
1498
+ {
1499
+ tag: [tags.string, tags.deleted],
1500
+ color: "#a11"
1501
+ },
1502
+ {
1503
+ tag: [
1504
+ tags.regexp,
1505
+ tags.escape,
1506
+ /*@__PURE__*/ tags.special(tags.string)
1507
+ ],
1508
+ color: "#e40"
1509
+ },
1510
+ {
1511
+ tag: /*@__PURE__*/ tags.definition(tags.variableName),
1512
+ color: "#00f"
1513
+ },
1514
+ {
1515
+ tag: /*@__PURE__*/ tags.local(tags.variableName),
1516
+ color: "#30a"
1517
+ },
1518
+ {
1519
+ tag: [tags.typeName, tags.namespace],
1520
+ color: "#085"
1521
+ },
1522
+ {
1523
+ tag: tags.className,
1524
+ color: "#167"
1525
+ },
1526
+ {
1527
+ tag: [/*@__PURE__*/ tags.special(tags.variableName), tags.macroName],
1528
+ color: "#256"
1529
+ },
1530
+ {
1531
+ tag: /*@__PURE__*/ tags.definition(tags.propertyName),
1532
+ color: "#00c"
1533
+ },
1534
+ {
1535
+ tag: tags.comment,
1536
+ color: "#940"
1537
+ },
1538
+ {
1539
+ tag: tags.invalid,
1540
+ color: "#f00"
1541
+ }
1542
+ ]);
1543
+ const baseTheme = /*@__PURE__*/ EditorView.baseTheme({
1544
+ "&.cm-focused .cm-matchingBracket": { backgroundColor: "#328c8252" },
1545
+ "&.cm-focused .cm-nonmatchingBracket": { backgroundColor: "#bb555544" }
1546
+ });
1547
+ const DefaultScanDist = 1e4, DefaultBrackets = "()[]{}";
1548
+ const bracketMatchingConfig = /*@__PURE__*/ Facet.define({ combine(configs) {
1549
+ return combineConfig(configs, {
1550
+ afterCursor: true,
1551
+ brackets: DefaultBrackets,
1552
+ maxScanDistance: DefaultScanDist,
1553
+ renderMatch: defaultRenderMatch
1554
+ });
1555
+ } });
1556
+ const matchingMark = /*@__PURE__*/ Decoration.mark({ class: "cm-matchingBracket" }), nonmatchingMark = /*@__PURE__*/ Decoration.mark({ class: "cm-nonmatchingBracket" });
1557
+ function defaultRenderMatch(match) {
1558
+ let decorations = [];
1559
+ let mark = match.matched ? matchingMark : nonmatchingMark;
1560
+ decorations.push(mark.range(match.start.from, match.start.to));
1561
+ if (match.end) decorations.push(mark.range(match.end.from, match.end.to));
1562
+ return decorations;
1563
+ }
1564
+ function bracketDeco(state) {
1565
+ let decorations = [];
1566
+ let config = state.facet(bracketMatchingConfig);
1567
+ for (let range of state.selection.ranges) {
1568
+ if (!range.empty) continue;
1569
+ let match = matchBrackets(state, range.head, -1, config) || range.head > 0 && matchBrackets(state, range.head - 1, 1, config) || config.afterCursor && (matchBrackets(state, range.head, 1, config) || range.head < state.doc.length && matchBrackets(state, range.head + 1, -1, config));
1570
+ if (match) decorations = decorations.concat(config.renderMatch(match, state));
1571
+ }
1572
+ return Decoration.set(decorations, true);
1573
+ }
1574
+ const bracketMatchingUnique = [/* @__PURE__ */ ViewPlugin.fromClass(class {
1575
+ constructor(view) {
1576
+ this.paused = false;
1577
+ this.decorations = bracketDeco(view.state);
1578
+ }
1579
+ update(update) {
1580
+ if (update.docChanged || update.selectionSet || this.paused) if (update.view.composing) {
1581
+ this.decorations = this.decorations.map(update.changes);
1582
+ this.paused = true;
1583
+ } else {
1584
+ this.decorations = bracketDeco(update.state);
1585
+ this.paused = false;
1586
+ }
1587
+ }
1588
+ }, { decorations: (v) => v.decorations }), baseTheme];
1589
+ /**
1590
+ Create an extension that enables bracket matching. Whenever the
1591
+ cursor is next to a bracket, that bracket and the one it matches
1592
+ are highlighted. Or, when no matching bracket is found, another
1593
+ highlighting style is used to indicate this.
1594
+ */
1595
+ function bracketMatching(config = {}) {
1596
+ return [bracketMatchingConfig.of(config), bracketMatchingUnique];
1597
+ }
1598
+ /**
1599
+ When larger syntax nodes, such as HTML tags, are marked as
1600
+ opening/closing, it can be a bit messy to treat the whole node as
1601
+ a matchable bracket. This node prop allows you to define, for such
1602
+ a node, a ‘handle’—the part of the node that is highlighted, and
1603
+ that the cursor must be on to activate highlighting in the first
1604
+ place.
1605
+ */
1606
+ const bracketMatchingHandle = /*@__PURE__*/ new NodeProp();
1607
+ function matchingNodes(node, dir, brackets) {
1608
+ let byProp = node.prop(dir < 0 ? NodeProp.openedBy : NodeProp.closedBy);
1609
+ if (byProp) return byProp;
1610
+ if (node.name.length == 1) {
1611
+ let index = brackets.indexOf(node.name);
1612
+ if (index > -1 && index % 2 == (dir < 0 ? 1 : 0)) return [brackets[index + dir]];
1613
+ }
1614
+ return null;
1615
+ }
1616
+ function findHandle(node) {
1617
+ let hasHandle = node.type.prop(bracketMatchingHandle);
1618
+ return hasHandle ? hasHandle(node.node) : node;
1619
+ }
1620
+ /**
1621
+ Find the matching bracket for the token at `pos`, scanning
1622
+ direction `dir`. Only the `brackets` and `maxScanDistance`
1623
+ properties are used from `config`, if given. Returns null if no
1624
+ bracket was found at `pos`, or a match result otherwise.
1625
+ */
1626
+ function matchBrackets(state, pos, dir, config = {}) {
1627
+ let maxScanDistance = config.maxScanDistance || DefaultScanDist, brackets = config.brackets || DefaultBrackets;
1628
+ let tree = syntaxTree(state), node = tree.resolveInner(pos, dir);
1629
+ for (let cur = node; cur; cur = cur.parent) {
1630
+ let matches = matchingNodes(cur.type, dir, brackets);
1631
+ if (matches && cur.from < cur.to) {
1632
+ let handle = findHandle(cur);
1633
+ 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);
1634
+ }
1635
+ }
1636
+ return matchPlainBrackets(state, pos, dir, tree, node.type, maxScanDistance, brackets);
1637
+ }
1638
+ function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, brackets) {
1639
+ let parent = token.parent, firstToken = {
1640
+ from: handle.from,
1641
+ to: handle.to
1642
+ };
1643
+ let depth = 0, cursor = parent === null || parent === void 0 ? void 0 : parent.cursor();
1644
+ if (cursor && (dir < 0 ? cursor.childBefore(token.from) : cursor.childAfter(token.to))) do
1645
+ if (dir < 0 ? cursor.to <= token.from : cursor.from >= token.to) {
1646
+ if (depth == 0 && matching.indexOf(cursor.type.name) > -1 && cursor.from < cursor.to) {
1647
+ let endHandle = findHandle(cursor);
1648
+ return {
1649
+ start: firstToken,
1650
+ end: endHandle ? {
1651
+ from: endHandle.from,
1652
+ to: endHandle.to
1653
+ } : void 0,
1654
+ matched: true
1655
+ };
1656
+ } else if (matchingNodes(cursor.type, dir, brackets)) depth++;
1657
+ else if (matchingNodes(cursor.type, -dir, brackets)) {
1658
+ if (depth == 0) {
1659
+ let endHandle = findHandle(cursor);
1660
+ return {
1661
+ start: firstToken,
1662
+ end: endHandle && endHandle.from < endHandle.to ? {
1663
+ from: endHandle.from,
1664
+ to: endHandle.to
1665
+ } : void 0,
1666
+ matched: false
1667
+ };
1668
+ }
1669
+ depth--;
1670
+ }
1671
+ }
1672
+ while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
1673
+ return {
1674
+ start: firstToken,
1675
+ matched: false
1676
+ };
1677
+ }
1678
+ function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, brackets) {
1679
+ if (dir < 0 ? !pos : pos == state.doc.length) return null;
1680
+ let startCh = dir < 0 ? state.sliceDoc(pos - 1, pos) : state.sliceDoc(pos, pos + 1);
1681
+ let bracket = brackets.indexOf(startCh);
1682
+ if (bracket < 0 || bracket % 2 == 0 != dir > 0) return null;
1683
+ let startToken = {
1684
+ from: dir < 0 ? pos - 1 : pos,
1685
+ to: dir > 0 ? pos + 1 : pos
1686
+ };
1687
+ let iter = state.doc.iterRange(pos, dir > 0 ? state.doc.length : 0), depth = 0;
1688
+ for (let distance = 0; !iter.next().done && distance <= maxScanDistance;) {
1689
+ let text = iter.value;
1690
+ if (dir < 0) distance += text.length;
1691
+ let basePos = pos + distance * dir;
1692
+ for (let pos = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos != end; pos += dir) {
1693
+ let found = brackets.indexOf(text[pos]);
1694
+ if (found < 0 || tree.resolveInner(basePos + pos, 1).type != tokenType) continue;
1695
+ if (found % 2 == 0 == dir > 0) depth++;
1696
+ else if (depth == 1) return {
1697
+ start: startToken,
1698
+ end: {
1699
+ from: basePos + pos,
1700
+ to: basePos + pos + 1
1701
+ },
1702
+ matched: found >> 1 == bracket >> 1
1703
+ };
1704
+ else depth--;
1705
+ }
1706
+ if (dir > 0) distance += text.length;
1707
+ }
1708
+ return iter.done ? {
1709
+ start: startToken,
1710
+ matched: false
1711
+ } : null;
1712
+ }
1713
+ const noTokens = /*@__PURE__*/ Object.create(null);
1714
+ const typeArray = [NodeType.none];
1715
+ const warned = [];
1716
+ const byTag = /*@__PURE__*/ Object.create(null);
1717
+ const defaultTable = /*@__PURE__*/ Object.create(null);
1718
+ for (let [legacyName, name] of [
1719
+ ["variable", "variableName"],
1720
+ ["variable-2", "variableName.special"],
1721
+ ["string-2", "string.special"],
1722
+ ["def", "variableName.definition"],
1723
+ ["tag", "tagName"],
1724
+ ["attribute", "attributeName"],
1725
+ ["type", "typeName"],
1726
+ ["builtin", "variableName.standard"],
1727
+ ["qualifier", "modifier"],
1728
+ ["error", "invalid"],
1729
+ ["header", "heading"],
1730
+ ["property", "propertyName"]
1731
+ ]) defaultTable[legacyName] = /*@__PURE__*/ createTokenType(noTokens, name);
1732
+ function warnForPart(part, msg) {
1733
+ if (warned.indexOf(part) > -1) return;
1734
+ warned.push(part);
1735
+ console.warn(msg);
1736
+ }
1737
+ function createTokenType(extra, tagStr) {
1738
+ let tags$1 = [];
1739
+ for (let name of tagStr.split(" ")) {
1740
+ let found = [];
1741
+ for (let part of name.split(".")) {
1742
+ let value = extra[part] || tags[part];
1743
+ if (!value) warnForPart(part, `Unknown highlighting tag ${part}`);
1744
+ else if (typeof value == "function") if (!found.length) warnForPart(part, `Modifier ${part} used at start of tag`);
1745
+ else found = found.map(value);
1746
+ else if (found.length) warnForPart(part, `Tag ${part} used as modifier`);
1747
+ else found = Array.isArray(value) ? value : [value];
1748
+ }
1749
+ for (let tag of found) tags$1.push(tag);
1750
+ }
1751
+ if (!tags$1.length) return 0;
1752
+ let name = tagStr.replace(/ /g, "_"), key = name + " " + tags$1.map((t) => t.id);
1753
+ let known = byTag[key];
1754
+ if (known) return known.id;
1755
+ let type = byTag[key] = NodeType.define({
1756
+ id: typeArray.length,
1757
+ name,
1758
+ props: [styleTags({ [name]: tags$1 })]
1759
+ });
1760
+ typeArray.push(type);
1761
+ return type.id;
1762
+ }
1763
+ Direction.RTL, Direction.LTR;
1764
+ //#endregion
1765
+ export { HighlightStyle, IndentContext, LRLanguage, LanguageSupport, bracketMatching, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, flatIndent, foldGutter, foldInside, foldKeymap, foldNodeProp, getIndentUnit, getIndentation, indentNodeProp, indentOnInput, indentString, indentUnit, matchBrackets, sublanguageProp, syntaxHighlighting, syntaxTree };
1766
+
1767
+ //# sourceMappingURL=index.js.map