@maketribe/ms-app 3.0.36 → 3.0.38

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