groove-dev 0.22.7 → 0.22.9

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 (125) hide show
  1. package/node_modules/@groove-dev/daemon/src/api.js +12 -2
  2. package/node_modules/@groove-dev/daemon/src/gateways/manager.js +3 -0
  3. package/node_modules/@groove-dev/gui/dist/assets/{index-B6DQvtWt.js → index-BKZQfaOu.js} +19 -19
  4. package/node_modules/@groove-dev/gui/dist/assets/index-CDWObHaG.css +1 -0
  5. package/node_modules/@groove-dev/gui/dist/index.html +2 -2
  6. package/node_modules/@groove-dev/gui/src/components/agents/agent-feed.jsx +1 -1
  7. package/node_modules/@groove-dev/gui/src/views/agents.jsx +5 -2
  8. package/package.json +1 -1
  9. package/packages/daemon/src/api.js +12 -2
  10. package/packages/daemon/src/gateways/manager.js +3 -0
  11. package/packages/gui/dist/assets/{index-B6DQvtWt.js → index-BKZQfaOu.js} +19 -19
  12. package/packages/gui/dist/assets/index-CDWObHaG.css +1 -0
  13. package/packages/gui/dist/index.html +2 -2
  14. package/packages/gui/src/components/agents/agent-feed.jsx +1 -1
  15. package/packages/gui/src/views/agents.jsx +5 -2
  16. package/node_modules/@groove-dev/gui/dist/assets/index-DHaSTu1c.css +0 -1
  17. package/packages/gui/dist/assets/index-DHaSTu1c.css +0 -1
  18. package/packages/gui/node_modules/.vite/deps/@codemirror_autocomplete.js +0 -68
  19. package/packages/gui/node_modules/.vite/deps/@codemirror_autocomplete.js.map +0 -7
  20. package/packages/gui/node_modules/.vite/deps/@codemirror_commands.js +0 -1420
  21. package/packages/gui/node_modules/.vite/deps/@codemirror_commands.js.map +0 -7
  22. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-css.js +0 -17
  23. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-css.js.map +0 -7
  24. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-html.js +0 -22
  25. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-html.js.map +0 -7
  26. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-javascript.js +0 -34
  27. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-javascript.js.map +0 -7
  28. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-json.js +0 -101
  29. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-json.js.map +0 -7
  30. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-markdown.js +0 -2534
  31. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-markdown.js.map +0 -7
  32. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-python.js +0 -789
  33. package/packages/gui/node_modules/.vite/deps/@codemirror_lang-python.js.map +0 -7
  34. package/packages/gui/node_modules/.vite/deps/@codemirror_language.js +0 -115
  35. package/packages/gui/node_modules/.vite/deps/@codemirror_language.js.map +0 -7
  36. package/packages/gui/node_modules/.vite/deps/@codemirror_search.js +0 -1136
  37. package/packages/gui/node_modules/.vite/deps/@codemirror_search.js.map +0 -7
  38. package/packages/gui/node_modules/.vite/deps/@codemirror_state.js +0 -63
  39. package/packages/gui/node_modules/.vite/deps/@codemirror_state.js.map +0 -7
  40. package/packages/gui/node_modules/.vite/deps/@codemirror_theme-one-dark.js +0 -179
  41. package/packages/gui/node_modules/.vite/deps/@codemirror_theme-one-dark.js.map +0 -7
  42. package/packages/gui/node_modules/.vite/deps/@codemirror_view.js +0 -104
  43. package/packages/gui/node_modules/.vite/deps/@codemirror_view.js.map +0 -7
  44. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-dialog.js +0 -367
  45. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-dialog.js.map +0 -7
  46. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-scroll-area.js +0 -755
  47. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-scroll-area.js.map +0 -7
  48. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-select.js +0 -1254
  49. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-select.js.map +0 -7
  50. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-tabs.js +0 -436
  51. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-tabs.js.map +0 -7
  52. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-tooltip.js +0 -531
  53. package/packages/gui/node_modules/.vite/deps/@radix-ui_react-tooltip.js.map +0 -7
  54. package/packages/gui/node_modules/.vite/deps/@xterm_addon-fit.js +0 -46
  55. package/packages/gui/node_modules/.vite/deps/@xterm_addon-fit.js.map +0 -7
  56. package/packages/gui/node_modules/.vite/deps/@xterm_addon-web-links.js +0 -121
  57. package/packages/gui/node_modules/.vite/deps/@xterm_addon-web-links.js.map +0 -7
  58. package/packages/gui/node_modules/.vite/deps/@xterm_xterm.js +0 -9237
  59. package/packages/gui/node_modules/.vite/deps/@xterm_xterm.js.map +0 -7
  60. package/packages/gui/node_modules/.vite/deps/@xyflow_react.js +0 -9934
  61. package/packages/gui/node_modules/.vite/deps/@xyflow_react.js.map +0 -7
  62. package/packages/gui/node_modules/.vite/deps/_metadata.json +0 -265
  63. package/packages/gui/node_modules/.vite/deps/chunk-3EE34IFC.js +0 -5169
  64. package/packages/gui/node_modules/.vite/deps/chunk-3EE34IFC.js.map +0 -7
  65. package/packages/gui/node_modules/.vite/deps/chunk-3IB5EUP7.js +0 -2000
  66. package/packages/gui/node_modules/.vite/deps/chunk-3IB5EUP7.js.map +0 -7
  67. package/packages/gui/node_modules/.vite/deps/chunk-3LBP22MX.js +0 -1115
  68. package/packages/gui/node_modules/.vite/deps/chunk-3LBP22MX.js.map +0 -7
  69. package/packages/gui/node_modules/.vite/deps/chunk-3Q7HT7ZF.js +0 -701
  70. package/packages/gui/node_modules/.vite/deps/chunk-3Q7HT7ZF.js.map +0 -7
  71. package/packages/gui/node_modules/.vite/deps/chunk-44CLUOQE.js +0 -1776
  72. package/packages/gui/node_modules/.vite/deps/chunk-44CLUOQE.js.map +0 -7
  73. package/packages/gui/node_modules/.vite/deps/chunk-6DLNZUA5.js +0 -142
  74. package/packages/gui/node_modules/.vite/deps/chunk-6DLNZUA5.js.map +0 -7
  75. package/packages/gui/node_modules/.vite/deps/chunk-ACEP5X2F.js +0 -292
  76. package/packages/gui/node_modules/.vite/deps/chunk-ACEP5X2F.js.map +0 -7
  77. package/packages/gui/node_modules/.vite/deps/chunk-AZUN7XMC.js +0 -87
  78. package/packages/gui/node_modules/.vite/deps/chunk-AZUN7XMC.js.map +0 -7
  79. package/packages/gui/node_modules/.vite/deps/chunk-CDLO3JFW.js +0 -1004
  80. package/packages/gui/node_modules/.vite/deps/chunk-CDLO3JFW.js.map +0 -7
  81. package/packages/gui/node_modules/.vite/deps/chunk-HPXOV7QR.js +0 -23
  82. package/packages/gui/node_modules/.vite/deps/chunk-HPXOV7QR.js.map +0 -7
  83. package/packages/gui/node_modules/.vite/deps/chunk-HVFOBSCQ.js +0 -1062
  84. package/packages/gui/node_modules/.vite/deps/chunk-HVFOBSCQ.js.map +0 -7
  85. package/packages/gui/node_modules/.vite/deps/chunk-I2PYXDFH.js +0 -1106
  86. package/packages/gui/node_modules/.vite/deps/chunk-I2PYXDFH.js.map +0 -7
  87. package/packages/gui/node_modules/.vite/deps/chunk-JPXYHBLX.js +0 -306
  88. package/packages/gui/node_modules/.vite/deps/chunk-JPXYHBLX.js.map +0 -7
  89. package/packages/gui/node_modules/.vite/deps/chunk-JYDZ3XIW.js +0 -264
  90. package/packages/gui/node_modules/.vite/deps/chunk-JYDZ3XIW.js.map +0 -7
  91. package/packages/gui/node_modules/.vite/deps/chunk-PR4QN5HX.js +0 -42
  92. package/packages/gui/node_modules/.vite/deps/chunk-PR4QN5HX.js.map +0 -7
  93. package/packages/gui/node_modules/.vite/deps/chunk-QZQGPDRM.js +0 -2328
  94. package/packages/gui/node_modules/.vite/deps/chunk-QZQGPDRM.js.map +0 -7
  95. package/packages/gui/node_modules/.vite/deps/chunk-RE2FU7ZU.js +0 -10985
  96. package/packages/gui/node_modules/.vite/deps/chunk-RE2FU7ZU.js.map +0 -7
  97. package/packages/gui/node_modules/.vite/deps/chunk-UO4Y2XXS.js +0 -105
  98. package/packages/gui/node_modules/.vite/deps/chunk-UO4Y2XXS.js.map +0 -7
  99. package/packages/gui/node_modules/.vite/deps/chunk-VW6LO3QI.js +0 -9
  100. package/packages/gui/node_modules/.vite/deps/chunk-VW6LO3QI.js.map +0 -7
  101. package/packages/gui/node_modules/.vite/deps/chunk-YAD7VOVN.js +0 -280
  102. package/packages/gui/node_modules/.vite/deps/chunk-YAD7VOVN.js.map +0 -7
  103. package/packages/gui/node_modules/.vite/deps/chunk-YYJMNVCJ.js +0 -3459
  104. package/packages/gui/node_modules/.vite/deps/chunk-YYJMNVCJ.js.map +0 -7
  105. package/packages/gui/node_modules/.vite/deps/clsx.js +0 -22
  106. package/packages/gui/node_modules/.vite/deps/clsx.js.map +0 -7
  107. package/packages/gui/node_modules/.vite/deps/framer-motion.js +0 -12732
  108. package/packages/gui/node_modules/.vite/deps/framer-motion.js.map +0 -7
  109. package/packages/gui/node_modules/.vite/deps/lucide-react.js +0 -29653
  110. package/packages/gui/node_modules/.vite/deps/lucide-react.js.map +0 -7
  111. package/packages/gui/node_modules/.vite/deps/package.json +0 -3
  112. package/packages/gui/node_modules/.vite/deps/react-dom.js +0 -6
  113. package/packages/gui/node_modules/.vite/deps/react-dom.js.map +0 -7
  114. package/packages/gui/node_modules/.vite/deps/react-dom_client.js +0 -20217
  115. package/packages/gui/node_modules/.vite/deps/react-dom_client.js.map +0 -7
  116. package/packages/gui/node_modules/.vite/deps/react.js +0 -5
  117. package/packages/gui/node_modules/.vite/deps/react.js.map +0 -7
  118. package/packages/gui/node_modules/.vite/deps/react_jsx-dev-runtime.js +0 -278
  119. package/packages/gui/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +0 -7
  120. package/packages/gui/node_modules/.vite/deps/react_jsx-runtime.js +0 -6
  121. package/packages/gui/node_modules/.vite/deps/react_jsx-runtime.js.map +0 -7
  122. package/packages/gui/node_modules/.vite/deps/tailwind-merge.js +0 -3263
  123. package/packages/gui/node_modules/.vite/deps/tailwind-merge.js.map +0 -7
  124. package/packages/gui/node_modules/.vite/deps/zustand.js +0 -56
  125. package/packages/gui/node_modules/.vite/deps/zustand.js.map +0 -7
@@ -1,3459 +0,0 @@
1
- // ../../node_modules/@marijn/find-cluster-break/src/index.js
2
- var rangeFrom = [];
3
- var rangeTo = [];
4
- (() => {
5
- let numbers = "lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((s) => s ? parseInt(s, 36) : 1);
6
- for (let i = 0, n = 0; i < numbers.length; i++)
7
- (i % 2 ? rangeTo : rangeFrom).push(n = n + numbers[i]);
8
- })();
9
- function isExtendingChar(code) {
10
- if (code < 768) return false;
11
- for (let from = 0, to = rangeFrom.length; ; ) {
12
- let mid = from + to >> 1;
13
- if (code < rangeFrom[mid]) to = mid;
14
- else if (code >= rangeTo[mid]) from = mid + 1;
15
- else return true;
16
- if (from == to) return false;
17
- }
18
- }
19
- function isRegionalIndicator(code) {
20
- return code >= 127462 && code <= 127487;
21
- }
22
- var ZWJ = 8205;
23
- function findClusterBreak(str, pos, forward = true, includeExtending = true) {
24
- return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending);
25
- }
26
- function nextClusterBreak(str, pos, includeExtending) {
27
- if (pos == str.length) return pos;
28
- if (pos && surrogateLow(str.charCodeAt(pos)) && surrogateHigh(str.charCodeAt(pos - 1))) pos--;
29
- let prev = codePointAt(str, pos);
30
- pos += codePointSize(prev);
31
- while (pos < str.length) {
32
- let next = codePointAt(str, pos);
33
- if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {
34
- pos += codePointSize(next);
35
- prev = next;
36
- } else if (isRegionalIndicator(next)) {
37
- let countBefore = 0, i = pos - 2;
38
- while (i >= 0 && isRegionalIndicator(codePointAt(str, i))) {
39
- countBefore++;
40
- i -= 2;
41
- }
42
- if (countBefore % 2 == 0) break;
43
- else pos += 2;
44
- } else {
45
- break;
46
- }
47
- }
48
- return pos;
49
- }
50
- function prevClusterBreak(str, pos, includeExtending) {
51
- while (pos > 0) {
52
- let found = nextClusterBreak(str, pos - 2, includeExtending);
53
- if (found < pos) return found;
54
- pos--;
55
- }
56
- return 0;
57
- }
58
- function codePointAt(str, pos) {
59
- let code0 = str.charCodeAt(pos);
60
- if (!surrogateHigh(code0) || pos + 1 == str.length) return code0;
61
- let code1 = str.charCodeAt(pos + 1);
62
- if (!surrogateLow(code1)) return code0;
63
- return (code0 - 55296 << 10) + (code1 - 56320) + 65536;
64
- }
65
- function surrogateLow(ch) {
66
- return ch >= 56320 && ch < 57344;
67
- }
68
- function surrogateHigh(ch) {
69
- return ch >= 55296 && ch < 56320;
70
- }
71
- function codePointSize(code) {
72
- return code < 65536 ? 1 : 2;
73
- }
74
-
75
- // ../../node_modules/@codemirror/state/dist/index.js
76
- var Text = class _Text {
77
- /**
78
- Get the line description around the given position.
79
- */
80
- lineAt(pos) {
81
- if (pos < 0 || pos > this.length)
82
- throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);
83
- return this.lineInner(pos, false, 1, 0);
84
- }
85
- /**
86
- Get the description for the given (1-based) line number.
87
- */
88
- line(n) {
89
- if (n < 1 || n > this.lines)
90
- throw new RangeError(`Invalid line number ${n} in ${this.lines}-line document`);
91
- return this.lineInner(n, true, 1, 0);
92
- }
93
- /**
94
- Replace a range of the text with the given content.
95
- */
96
- replace(from, to, text) {
97
- [from, to] = clip(this, from, to);
98
- let parts = [];
99
- this.decompose(
100
- 0,
101
- from,
102
- parts,
103
- 2
104
- /* Open.To */
105
- );
106
- if (text.length)
107
- text.decompose(
108
- 0,
109
- text.length,
110
- parts,
111
- 1 | 2
112
- /* Open.To */
113
- );
114
- this.decompose(
115
- to,
116
- this.length,
117
- parts,
118
- 1
119
- /* Open.From */
120
- );
121
- return TextNode.from(parts, this.length - (to - from) + text.length);
122
- }
123
- /**
124
- Append another document to this one.
125
- */
126
- append(other) {
127
- return this.replace(this.length, this.length, other);
128
- }
129
- /**
130
- Retrieve the text between the given points.
131
- */
132
- slice(from, to = this.length) {
133
- [from, to] = clip(this, from, to);
134
- let parts = [];
135
- this.decompose(from, to, parts, 0);
136
- return TextNode.from(parts, to - from);
137
- }
138
- /**
139
- Test whether this text is equal to another instance.
140
- */
141
- eq(other) {
142
- if (other == this)
143
- return true;
144
- if (other.length != this.length || other.lines != this.lines)
145
- return false;
146
- let start = this.scanIdentical(other, 1), end = this.length - this.scanIdentical(other, -1);
147
- let a = new RawTextCursor(this), b = new RawTextCursor(other);
148
- for (let skip = start, pos = start; ; ) {
149
- a.next(skip);
150
- b.next(skip);
151
- skip = 0;
152
- if (a.lineBreak != b.lineBreak || a.done != b.done || a.value != b.value)
153
- return false;
154
- pos += a.value.length;
155
- if (a.done || pos >= end)
156
- return true;
157
- }
158
- }
159
- /**
160
- Iterate over the text. When `dir` is `-1`, iteration happens
161
- from end to start. This will return lines and the breaks between
162
- them as separate strings.
163
- */
164
- iter(dir = 1) {
165
- return new RawTextCursor(this, dir);
166
- }
167
- /**
168
- Iterate over a range of the text. When `from` > `to`, the
169
- iterator will run in reverse.
170
- */
171
- iterRange(from, to = this.length) {
172
- return new PartialTextCursor(this, from, to);
173
- }
174
- /**
175
- Return a cursor that iterates over the given range of lines,
176
- _without_ returning the line breaks between, and yielding empty
177
- strings for empty lines.
178
-
179
- When `from` and `to` are given, they should be 1-based line numbers.
180
- */
181
- iterLines(from, to) {
182
- let inner;
183
- if (from == null) {
184
- inner = this.iter();
185
- } else {
186
- if (to == null)
187
- to = this.lines + 1;
188
- let start = this.line(from).from;
189
- inner = this.iterRange(start, Math.max(start, to == this.lines + 1 ? this.length : to <= 1 ? 0 : this.line(to - 1).to));
190
- }
191
- return new LineCursor(inner);
192
- }
193
- /**
194
- Return the document as a string, using newline characters to
195
- separate lines.
196
- */
197
- toString() {
198
- return this.sliceString(0);
199
- }
200
- /**
201
- Convert the document to an array of lines (which can be
202
- deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
203
- */
204
- toJSON() {
205
- let lines = [];
206
- this.flatten(lines);
207
- return lines;
208
- }
209
- /**
210
- @internal
211
- */
212
- constructor() {
213
- }
214
- /**
215
- Create a `Text` instance for the given array of lines.
216
- */
217
- static of(text) {
218
- if (text.length == 0)
219
- throw new RangeError("A document must have at least one line");
220
- if (text.length == 1 && !text[0])
221
- return _Text.empty;
222
- return text.length <= 32 ? new TextLeaf(text) : TextNode.from(TextLeaf.split(text, []));
223
- }
224
- };
225
- var TextLeaf = class _TextLeaf extends Text {
226
- constructor(text, length = textLength(text)) {
227
- super();
228
- this.text = text;
229
- this.length = length;
230
- }
231
- get lines() {
232
- return this.text.length;
233
- }
234
- get children() {
235
- return null;
236
- }
237
- lineInner(target, isLine, line, offset) {
238
- for (let i = 0; ; i++) {
239
- let string = this.text[i], end = offset + string.length;
240
- if ((isLine ? line : end) >= target)
241
- return new Line(offset, end, line, string);
242
- offset = end + 1;
243
- line++;
244
- }
245
- }
246
- decompose(from, to, target, open) {
247
- let text = from <= 0 && to >= this.length ? this : new _TextLeaf(sliceText(this.text, from, to), Math.min(to, this.length) - Math.max(0, from));
248
- if (open & 1) {
249
- let prev = target.pop();
250
- let joined = appendText(text.text, prev.text.slice(), 0, text.length);
251
- if (joined.length <= 32) {
252
- target.push(new _TextLeaf(joined, prev.length + text.length));
253
- } else {
254
- let mid = joined.length >> 1;
255
- target.push(new _TextLeaf(joined.slice(0, mid)), new _TextLeaf(joined.slice(mid)));
256
- }
257
- } else {
258
- target.push(text);
259
- }
260
- }
261
- replace(from, to, text) {
262
- if (!(text instanceof _TextLeaf))
263
- return super.replace(from, to, text);
264
- [from, to] = clip(this, from, to);
265
- let lines = appendText(this.text, appendText(text.text, sliceText(this.text, 0, from)), to);
266
- let newLen = this.length + text.length - (to - from);
267
- if (lines.length <= 32)
268
- return new _TextLeaf(lines, newLen);
269
- return TextNode.from(_TextLeaf.split(lines, []), newLen);
270
- }
271
- sliceString(from, to = this.length, lineSep = "\n") {
272
- [from, to] = clip(this, from, to);
273
- let result = "";
274
- for (let pos = 0, i = 0; pos <= to && i < this.text.length; i++) {
275
- let line = this.text[i], end = pos + line.length;
276
- if (pos > from && i)
277
- result += lineSep;
278
- if (from < end && to > pos)
279
- result += line.slice(Math.max(0, from - pos), to - pos);
280
- pos = end + 1;
281
- }
282
- return result;
283
- }
284
- flatten(target) {
285
- for (let line of this.text)
286
- target.push(line);
287
- }
288
- scanIdentical() {
289
- return 0;
290
- }
291
- static split(text, target) {
292
- let part = [], len = -1;
293
- for (let line of text) {
294
- part.push(line);
295
- len += line.length + 1;
296
- if (part.length == 32) {
297
- target.push(new _TextLeaf(part, len));
298
- part = [];
299
- len = -1;
300
- }
301
- }
302
- if (len > -1)
303
- target.push(new _TextLeaf(part, len));
304
- return target;
305
- }
306
- };
307
- var TextNode = class _TextNode extends Text {
308
- constructor(children, length) {
309
- super();
310
- this.children = children;
311
- this.length = length;
312
- this.lines = 0;
313
- for (let child of children)
314
- this.lines += child.lines;
315
- }
316
- lineInner(target, isLine, line, offset) {
317
- for (let i = 0; ; i++) {
318
- let child = this.children[i], end = offset + child.length, endLine = line + child.lines - 1;
319
- if ((isLine ? endLine : end) >= target)
320
- return child.lineInner(target, isLine, line, offset);
321
- offset = end + 1;
322
- line = endLine + 1;
323
- }
324
- }
325
- decompose(from, to, target, open) {
326
- for (let i = 0, pos = 0; pos <= to && i < this.children.length; i++) {
327
- let child = this.children[i], end = pos + child.length;
328
- if (from <= end && to >= pos) {
329
- let childOpen = open & ((pos <= from ? 1 : 0) | (end >= to ? 2 : 0));
330
- if (pos >= from && end <= to && !childOpen)
331
- target.push(child);
332
- else
333
- child.decompose(from - pos, to - pos, target, childOpen);
334
- }
335
- pos = end + 1;
336
- }
337
- }
338
- replace(from, to, text) {
339
- [from, to] = clip(this, from, to);
340
- if (text.lines < this.lines)
341
- for (let i = 0, pos = 0; i < this.children.length; i++) {
342
- let child = this.children[i], end = pos + child.length;
343
- if (from >= pos && to <= end) {
344
- let updated = child.replace(from - pos, to - pos, text);
345
- let totalLines = this.lines - child.lines + updated.lines;
346
- if (updated.lines < totalLines >> 5 - 1 && updated.lines > totalLines >> 5 + 1) {
347
- let copy = this.children.slice();
348
- copy[i] = updated;
349
- return new _TextNode(copy, this.length - (to - from) + text.length);
350
- }
351
- return super.replace(pos, end, updated);
352
- }
353
- pos = end + 1;
354
- }
355
- return super.replace(from, to, text);
356
- }
357
- sliceString(from, to = this.length, lineSep = "\n") {
358
- [from, to] = clip(this, from, to);
359
- let result = "";
360
- for (let i = 0, pos = 0; i < this.children.length && pos <= to; i++) {
361
- let child = this.children[i], end = pos + child.length;
362
- if (pos > from && i)
363
- result += lineSep;
364
- if (from < end && to > pos)
365
- result += child.sliceString(from - pos, to - pos, lineSep);
366
- pos = end + 1;
367
- }
368
- return result;
369
- }
370
- flatten(target) {
371
- for (let child of this.children)
372
- child.flatten(target);
373
- }
374
- scanIdentical(other, dir) {
375
- if (!(other instanceof _TextNode))
376
- return 0;
377
- let length = 0;
378
- let [iA, iB, eA, eB] = dir > 0 ? [0, 0, this.children.length, other.children.length] : [this.children.length - 1, other.children.length - 1, -1, -1];
379
- for (; ; iA += dir, iB += dir) {
380
- if (iA == eA || iB == eB)
381
- return length;
382
- let chA = this.children[iA], chB = other.children[iB];
383
- if (chA != chB)
384
- return length + chA.scanIdentical(chB, dir);
385
- length += chA.length + 1;
386
- }
387
- }
388
- static from(children, length = children.reduce((l, ch) => l + ch.length + 1, -1)) {
389
- let lines = 0;
390
- for (let ch of children)
391
- lines += ch.lines;
392
- if (lines < 32) {
393
- let flat = [];
394
- for (let ch of children)
395
- ch.flatten(flat);
396
- return new TextLeaf(flat, length);
397
- }
398
- let chunk = Math.max(
399
- 32,
400
- lines >> 5
401
- /* Tree.BranchShift */
402
- ), maxChunk = chunk << 1, minChunk = chunk >> 1;
403
- let chunked = [], currentLines = 0, currentLen = -1, currentChunk = [];
404
- function add(child) {
405
- let last;
406
- if (child.lines > maxChunk && child instanceof _TextNode) {
407
- for (let node of child.children)
408
- add(node);
409
- } else if (child.lines > minChunk && (currentLines > minChunk || !currentLines)) {
410
- flush();
411
- chunked.push(child);
412
- } else if (child instanceof TextLeaf && currentLines && (last = currentChunk[currentChunk.length - 1]) instanceof TextLeaf && child.lines + last.lines <= 32) {
413
- currentLines += child.lines;
414
- currentLen += child.length + 1;
415
- currentChunk[currentChunk.length - 1] = new TextLeaf(last.text.concat(child.text), last.length + 1 + child.length);
416
- } else {
417
- if (currentLines + child.lines > chunk)
418
- flush();
419
- currentLines += child.lines;
420
- currentLen += child.length + 1;
421
- currentChunk.push(child);
422
- }
423
- }
424
- function flush() {
425
- if (currentLines == 0)
426
- return;
427
- chunked.push(currentChunk.length == 1 ? currentChunk[0] : _TextNode.from(currentChunk, currentLen));
428
- currentLen = -1;
429
- currentLines = currentChunk.length = 0;
430
- }
431
- for (let child of children)
432
- add(child);
433
- flush();
434
- return chunked.length == 1 ? chunked[0] : new _TextNode(chunked, length);
435
- }
436
- };
437
- Text.empty = new TextLeaf([""], 0);
438
- function textLength(text) {
439
- let length = -1;
440
- for (let line of text)
441
- length += line.length + 1;
442
- return length;
443
- }
444
- function appendText(text, target, from = 0, to = 1e9) {
445
- for (let pos = 0, i = 0, first = true; i < text.length && pos <= to; i++) {
446
- let line = text[i], end = pos + line.length;
447
- if (end >= from) {
448
- if (end > to)
449
- line = line.slice(0, to - pos);
450
- if (pos < from)
451
- line = line.slice(from - pos);
452
- if (first) {
453
- target[target.length - 1] += line;
454
- first = false;
455
- } else
456
- target.push(line);
457
- }
458
- pos = end + 1;
459
- }
460
- return target;
461
- }
462
- function sliceText(text, from, to) {
463
- return appendText(text, [""], from, to);
464
- }
465
- var RawTextCursor = class {
466
- constructor(text, dir = 1) {
467
- this.dir = dir;
468
- this.done = false;
469
- this.lineBreak = false;
470
- this.value = "";
471
- this.nodes = [text];
472
- this.offsets = [dir > 0 ? 1 : (text instanceof TextLeaf ? text.text.length : text.children.length) << 1];
473
- }
474
- nextInner(skip, dir) {
475
- this.done = this.lineBreak = false;
476
- for (; ; ) {
477
- let last = this.nodes.length - 1;
478
- let top = this.nodes[last], offsetValue = this.offsets[last], offset = offsetValue >> 1;
479
- let size = top instanceof TextLeaf ? top.text.length : top.children.length;
480
- if (offset == (dir > 0 ? size : 0)) {
481
- if (last == 0) {
482
- this.done = true;
483
- this.value = "";
484
- return this;
485
- }
486
- if (dir > 0)
487
- this.offsets[last - 1]++;
488
- this.nodes.pop();
489
- this.offsets.pop();
490
- } else if ((offsetValue & 1) == (dir > 0 ? 0 : 1)) {
491
- this.offsets[last] += dir;
492
- if (skip == 0) {
493
- this.lineBreak = true;
494
- this.value = "\n";
495
- return this;
496
- }
497
- skip--;
498
- } else if (top instanceof TextLeaf) {
499
- let next = top.text[offset + (dir < 0 ? -1 : 0)];
500
- this.offsets[last] += dir;
501
- if (next.length > Math.max(0, skip)) {
502
- this.value = skip == 0 ? next : dir > 0 ? next.slice(skip) : next.slice(0, next.length - skip);
503
- return this;
504
- }
505
- skip -= next.length;
506
- } else {
507
- let next = top.children[offset + (dir < 0 ? -1 : 0)];
508
- if (skip > next.length) {
509
- skip -= next.length;
510
- this.offsets[last] += dir;
511
- } else {
512
- if (dir < 0)
513
- this.offsets[last]--;
514
- this.nodes.push(next);
515
- this.offsets.push(dir > 0 ? 1 : (next instanceof TextLeaf ? next.text.length : next.children.length) << 1);
516
- }
517
- }
518
- }
519
- }
520
- next(skip = 0) {
521
- if (skip < 0) {
522
- this.nextInner(-skip, -this.dir);
523
- skip = this.value.length;
524
- }
525
- return this.nextInner(skip, this.dir);
526
- }
527
- };
528
- var PartialTextCursor = class {
529
- constructor(text, start, end) {
530
- this.value = "";
531
- this.done = false;
532
- this.cursor = new RawTextCursor(text, start > end ? -1 : 1);
533
- this.pos = start > end ? text.length : 0;
534
- this.from = Math.min(start, end);
535
- this.to = Math.max(start, end);
536
- }
537
- nextInner(skip, dir) {
538
- if (dir < 0 ? this.pos <= this.from : this.pos >= this.to) {
539
- this.value = "";
540
- this.done = true;
541
- return this;
542
- }
543
- skip += Math.max(0, dir < 0 ? this.pos - this.to : this.from - this.pos);
544
- let limit = dir < 0 ? this.pos - this.from : this.to - this.pos;
545
- if (skip > limit)
546
- skip = limit;
547
- limit -= skip;
548
- let { value } = this.cursor.next(skip);
549
- this.pos += (value.length + skip) * dir;
550
- this.value = value.length <= limit ? value : dir < 0 ? value.slice(value.length - limit) : value.slice(0, limit);
551
- this.done = !this.value;
552
- return this;
553
- }
554
- next(skip = 0) {
555
- if (skip < 0)
556
- skip = Math.max(skip, this.from - this.pos);
557
- else if (skip > 0)
558
- skip = Math.min(skip, this.to - this.pos);
559
- return this.nextInner(skip, this.cursor.dir);
560
- }
561
- get lineBreak() {
562
- return this.cursor.lineBreak && this.value != "";
563
- }
564
- };
565
- var LineCursor = class {
566
- constructor(inner) {
567
- this.inner = inner;
568
- this.afterBreak = true;
569
- this.value = "";
570
- this.done = false;
571
- }
572
- next(skip = 0) {
573
- let { done, lineBreak, value } = this.inner.next(skip);
574
- if (done && this.afterBreak) {
575
- this.value = "";
576
- this.afterBreak = false;
577
- } else if (done) {
578
- this.done = true;
579
- this.value = "";
580
- } else if (lineBreak) {
581
- if (this.afterBreak) {
582
- this.value = "";
583
- } else {
584
- this.afterBreak = true;
585
- this.next();
586
- }
587
- } else {
588
- this.value = value;
589
- this.afterBreak = false;
590
- }
591
- return this;
592
- }
593
- get lineBreak() {
594
- return false;
595
- }
596
- };
597
- if (typeof Symbol != "undefined") {
598
- Text.prototype[Symbol.iterator] = function() {
599
- return this.iter();
600
- };
601
- RawTextCursor.prototype[Symbol.iterator] = PartialTextCursor.prototype[Symbol.iterator] = LineCursor.prototype[Symbol.iterator] = function() {
602
- return this;
603
- };
604
- }
605
- var Line = class {
606
- /**
607
- @internal
608
- */
609
- constructor(from, to, number, text) {
610
- this.from = from;
611
- this.to = to;
612
- this.number = number;
613
- this.text = text;
614
- }
615
- /**
616
- The length of the line (not including any line break after it).
617
- */
618
- get length() {
619
- return this.to - this.from;
620
- }
621
- };
622
- function clip(text, from, to) {
623
- from = Math.max(0, Math.min(text.length, from));
624
- return [from, Math.max(from, Math.min(text.length, to))];
625
- }
626
- function findClusterBreak2(str, pos, forward = true, includeExtending = true) {
627
- return findClusterBreak(str, pos, forward, includeExtending);
628
- }
629
- function surrogateLow2(ch) {
630
- return ch >= 56320 && ch < 57344;
631
- }
632
- function surrogateHigh2(ch) {
633
- return ch >= 55296 && ch < 56320;
634
- }
635
- function codePointAt2(str, pos) {
636
- let code0 = str.charCodeAt(pos);
637
- if (!surrogateHigh2(code0) || pos + 1 == str.length)
638
- return code0;
639
- let code1 = str.charCodeAt(pos + 1);
640
- if (!surrogateLow2(code1))
641
- return code0;
642
- return (code0 - 55296 << 10) + (code1 - 56320) + 65536;
643
- }
644
- function fromCodePoint(code) {
645
- if (code <= 65535)
646
- return String.fromCharCode(code);
647
- code -= 65536;
648
- return String.fromCharCode((code >> 10) + 55296, (code & 1023) + 56320);
649
- }
650
- function codePointSize2(code) {
651
- return code < 65536 ? 1 : 2;
652
- }
653
- var DefaultSplit = /\r\n?|\n/;
654
- var MapMode = (function(MapMode2) {
655
- MapMode2[MapMode2["Simple"] = 0] = "Simple";
656
- MapMode2[MapMode2["TrackDel"] = 1] = "TrackDel";
657
- MapMode2[MapMode2["TrackBefore"] = 2] = "TrackBefore";
658
- MapMode2[MapMode2["TrackAfter"] = 3] = "TrackAfter";
659
- return MapMode2;
660
- })(MapMode || (MapMode = {}));
661
- var ChangeDesc = class _ChangeDesc {
662
- // Sections are encoded as pairs of integers. The first is the
663
- // length in the current document, and the second is -1 for
664
- // unaffected sections, and the length of the replacement content
665
- // otherwise. So an insertion would be (0, n>0), a deletion (n>0,
666
- // 0), and a replacement two positive numbers.
667
- /**
668
- @internal
669
- */
670
- constructor(sections) {
671
- this.sections = sections;
672
- }
673
- /**
674
- The length of the document before the change.
675
- */
676
- get length() {
677
- let result = 0;
678
- for (let i = 0; i < this.sections.length; i += 2)
679
- result += this.sections[i];
680
- return result;
681
- }
682
- /**
683
- The length of the document after the change.
684
- */
685
- get newLength() {
686
- let result = 0;
687
- for (let i = 0; i < this.sections.length; i += 2) {
688
- let ins = this.sections[i + 1];
689
- result += ins < 0 ? this.sections[i] : ins;
690
- }
691
- return result;
692
- }
693
- /**
694
- False when there are actual changes in this set.
695
- */
696
- get empty() {
697
- return this.sections.length == 0 || this.sections.length == 2 && this.sections[1] < 0;
698
- }
699
- /**
700
- Iterate over the unchanged parts left by these changes. `posA`
701
- provides the position of the range in the old document, `posB`
702
- the new position in the changed document.
703
- */
704
- iterGaps(f) {
705
- for (let i = 0, posA = 0, posB = 0; i < this.sections.length; ) {
706
- let len = this.sections[i++], ins = this.sections[i++];
707
- if (ins < 0) {
708
- f(posA, posB, len);
709
- posB += len;
710
- } else {
711
- posB += ins;
712
- }
713
- posA += len;
714
- }
715
- }
716
- /**
717
- Iterate over the ranges changed by these changes. (See
718
- [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
719
- variant that also provides you with the inserted text.)
720
- `fromA`/`toA` provides the extent of the change in the starting
721
- document, `fromB`/`toB` the extent of the replacement in the
722
- changed document.
723
-
724
- When `individual` is true, adjacent changes (which are kept
725
- separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
726
- reported separately.
727
- */
728
- iterChangedRanges(f, individual = false) {
729
- iterChanges(this, f, individual);
730
- }
731
- /**
732
- Get a description of the inverted form of these changes.
733
- */
734
- get invertedDesc() {
735
- let sections = [];
736
- for (let i = 0; i < this.sections.length; ) {
737
- let len = this.sections[i++], ins = this.sections[i++];
738
- if (ins < 0)
739
- sections.push(len, ins);
740
- else
741
- sections.push(ins, len);
742
- }
743
- return new _ChangeDesc(sections);
744
- }
745
- /**
746
- Compute the combined effect of applying another set of changes
747
- after this one. The length of the document after this set should
748
- match the length before `other`.
749
- */
750
- composeDesc(other) {
751
- return this.empty ? other : other.empty ? this : composeSets(this, other);
752
- }
753
- /**
754
- Map this description, which should start with the same document
755
- as `other`, over another set of changes, so that it can be
756
- applied after it. When `before` is true, map as if the changes
757
- in `this` happened before the ones in `other`.
758
- */
759
- mapDesc(other, before = false) {
760
- return other.empty ? this : mapSet(this, other, before);
761
- }
762
- mapPos(pos, assoc = -1, mode = MapMode.Simple) {
763
- let posA = 0, posB = 0;
764
- for (let i = 0; i < this.sections.length; ) {
765
- let len = this.sections[i++], ins = this.sections[i++], endA = posA + len;
766
- if (ins < 0) {
767
- if (endA > pos)
768
- return posB + (pos - posA);
769
- posB += len;
770
- } else {
771
- if (mode != MapMode.Simple && endA >= pos && (mode == MapMode.TrackDel && posA < pos && endA > pos || mode == MapMode.TrackBefore && posA < pos || mode == MapMode.TrackAfter && endA > pos))
772
- return null;
773
- if (endA > pos || endA == pos && assoc < 0 && !len)
774
- return pos == posA || assoc < 0 ? posB : posB + ins;
775
- posB += ins;
776
- }
777
- posA = endA;
778
- }
779
- if (pos > posA)
780
- throw new RangeError(`Position ${pos} is out of range for changeset of length ${posA}`);
781
- return posB;
782
- }
783
- /**
784
- Check whether these changes touch a given range. When one of the
785
- changes entirely covers the range, the string `"cover"` is
786
- returned.
787
- */
788
- touchesRange(from, to = from) {
789
- for (let i = 0, pos = 0; i < this.sections.length && pos <= to; ) {
790
- let len = this.sections[i++], ins = this.sections[i++], end = pos + len;
791
- if (ins >= 0 && pos <= to && end >= from)
792
- return pos < from && end > to ? "cover" : true;
793
- pos = end;
794
- }
795
- return false;
796
- }
797
- /**
798
- @internal
799
- */
800
- toString() {
801
- let result = "";
802
- for (let i = 0; i < this.sections.length; ) {
803
- let len = this.sections[i++], ins = this.sections[i++];
804
- result += (result ? " " : "") + len + (ins >= 0 ? ":" + ins : "");
805
- }
806
- return result;
807
- }
808
- /**
809
- Serialize this change desc to a JSON-representable value.
810
- */
811
- toJSON() {
812
- return this.sections;
813
- }
814
- /**
815
- Create a change desc from its JSON representation (as produced
816
- by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
817
- */
818
- static fromJSON(json) {
819
- if (!Array.isArray(json) || json.length % 2 || json.some((a) => typeof a != "number"))
820
- throw new RangeError("Invalid JSON representation of ChangeDesc");
821
- return new _ChangeDesc(json);
822
- }
823
- /**
824
- @internal
825
- */
826
- static create(sections) {
827
- return new _ChangeDesc(sections);
828
- }
829
- };
830
- var ChangeSet = class _ChangeSet extends ChangeDesc {
831
- constructor(sections, inserted) {
832
- super(sections);
833
- this.inserted = inserted;
834
- }
835
- /**
836
- Apply the changes to a document, returning the modified
837
- document.
838
- */
839
- apply(doc) {
840
- if (this.length != doc.length)
841
- throw new RangeError("Applying change set to a document with the wrong length");
842
- iterChanges(this, (fromA, toA, fromB, _toB, text) => doc = doc.replace(fromB, fromB + (toA - fromA), text), false);
843
- return doc;
844
- }
845
- mapDesc(other, before = false) {
846
- return mapSet(this, other, before, true);
847
- }
848
- /**
849
- Given the document as it existed _before_ the changes, return a
850
- change set that represents the inverse of this set, which could
851
- be used to go from the document created by the changes back to
852
- the document as it existed before the changes.
853
- */
854
- invert(doc) {
855
- let sections = this.sections.slice(), inserted = [];
856
- for (let i = 0, pos = 0; i < sections.length; i += 2) {
857
- let len = sections[i], ins = sections[i + 1];
858
- if (ins >= 0) {
859
- sections[i] = ins;
860
- sections[i + 1] = len;
861
- let index = i >> 1;
862
- while (inserted.length < index)
863
- inserted.push(Text.empty);
864
- inserted.push(len ? doc.slice(pos, pos + len) : Text.empty);
865
- }
866
- pos += len;
867
- }
868
- return new _ChangeSet(sections, inserted);
869
- }
870
- /**
871
- Combine two subsequent change sets into a single set. `other`
872
- must start in the document produced by `this`. If `this` goes
873
- `docA` → `docB` and `other` represents `docB` → `docC`, the
874
- returned value will represent the change `docA` → `docC`.
875
- */
876
- compose(other) {
877
- return this.empty ? other : other.empty ? this : composeSets(this, other, true);
878
- }
879
- /**
880
- Given another change set starting in the same document, maps this
881
- change set over the other, producing a new change set that can be
882
- applied to the document produced by applying `other`. When
883
- `before` is `true`, order changes as if `this` comes before
884
- `other`, otherwise (the default) treat `other` as coming first.
885
-
886
- Given two changes `A` and `B`, `A.compose(B.map(A))` and
887
- `B.compose(A.map(B, true))` will produce the same document. This
888
- provides a basic form of [operational
889
- transformation](https://en.wikipedia.org/wiki/Operational_transformation),
890
- and can be used for collaborative editing.
891
- */
892
- map(other, before = false) {
893
- return other.empty ? this : mapSet(this, other, before, true);
894
- }
895
- /**
896
- Iterate over the changed ranges in the document, calling `f` for
897
- each, with the range in the original document (`fromA`-`toA`)
898
- and the range that replaces it in the new document
899
- (`fromB`-`toB`).
900
-
901
- When `individual` is true, adjacent changes are reported
902
- separately.
903
- */
904
- iterChanges(f, individual = false) {
905
- iterChanges(this, f, individual);
906
- }
907
- /**
908
- Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
909
- set.
910
- */
911
- get desc() {
912
- return ChangeDesc.create(this.sections);
913
- }
914
- /**
915
- @internal
916
- */
917
- filter(ranges) {
918
- let resultSections = [], resultInserted = [], filteredSections = [];
919
- let iter = new SectionIter(this);
920
- done: for (let i = 0, pos = 0; ; ) {
921
- let next = i == ranges.length ? 1e9 : ranges[i++];
922
- while (pos < next || pos == next && iter.len == 0) {
923
- if (iter.done)
924
- break done;
925
- let len = Math.min(iter.len, next - pos);
926
- addSection(filteredSections, len, -1);
927
- let ins = iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0;
928
- addSection(resultSections, len, ins);
929
- if (ins > 0)
930
- addInsert(resultInserted, resultSections, iter.text);
931
- iter.forward(len);
932
- pos += len;
933
- }
934
- let end = ranges[i++];
935
- while (pos < end) {
936
- if (iter.done)
937
- break done;
938
- let len = Math.min(iter.len, end - pos);
939
- addSection(resultSections, len, -1);
940
- addSection(filteredSections, len, iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0);
941
- iter.forward(len);
942
- pos += len;
943
- }
944
- }
945
- return {
946
- changes: new _ChangeSet(resultSections, resultInserted),
947
- filtered: ChangeDesc.create(filteredSections)
948
- };
949
- }
950
- /**
951
- Serialize this change set to a JSON-representable value.
952
- */
953
- toJSON() {
954
- let parts = [];
955
- for (let i = 0; i < this.sections.length; i += 2) {
956
- let len = this.sections[i], ins = this.sections[i + 1];
957
- if (ins < 0)
958
- parts.push(len);
959
- else if (ins == 0)
960
- parts.push([len]);
961
- else
962
- parts.push([len].concat(this.inserted[i >> 1].toJSON()));
963
- }
964
- return parts;
965
- }
966
- /**
967
- Create a change set for the given changes, for a document of the
968
- given length, using `lineSep` as line separator.
969
- */
970
- static of(changes, length, lineSep) {
971
- let sections = [], inserted = [], pos = 0;
972
- let total = null;
973
- function flush(force = false) {
974
- if (!force && !sections.length)
975
- return;
976
- if (pos < length)
977
- addSection(sections, length - pos, -1);
978
- let set = new _ChangeSet(sections, inserted);
979
- total = total ? total.compose(set.map(total)) : set;
980
- sections = [];
981
- inserted = [];
982
- pos = 0;
983
- }
984
- function process(spec) {
985
- if (Array.isArray(spec)) {
986
- for (let sub of spec)
987
- process(sub);
988
- } else if (spec instanceof _ChangeSet) {
989
- if (spec.length != length)
990
- throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${length})`);
991
- flush();
992
- total = total ? total.compose(spec.map(total)) : spec;
993
- } else {
994
- let { from, to = from, insert: insert2 } = spec;
995
- if (from > to || from < 0 || to > length)
996
- throw new RangeError(`Invalid change range ${from} to ${to} (in doc of length ${length})`);
997
- let insText = !insert2 ? Text.empty : typeof insert2 == "string" ? Text.of(insert2.split(lineSep || DefaultSplit)) : insert2;
998
- let insLen = insText.length;
999
- if (from == to && insLen == 0)
1000
- return;
1001
- if (from < pos)
1002
- flush();
1003
- if (from > pos)
1004
- addSection(sections, from - pos, -1);
1005
- addSection(sections, to - from, insLen);
1006
- addInsert(inserted, sections, insText);
1007
- pos = to;
1008
- }
1009
- }
1010
- process(changes);
1011
- flush(!total);
1012
- return total;
1013
- }
1014
- /**
1015
- Create an empty changeset of the given length.
1016
- */
1017
- static empty(length) {
1018
- return new _ChangeSet(length ? [length, -1] : [], []);
1019
- }
1020
- /**
1021
- Create a changeset from its JSON representation (as produced by
1022
- [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
1023
- */
1024
- static fromJSON(json) {
1025
- if (!Array.isArray(json))
1026
- throw new RangeError("Invalid JSON representation of ChangeSet");
1027
- let sections = [], inserted = [];
1028
- for (let i = 0; i < json.length; i++) {
1029
- let part = json[i];
1030
- if (typeof part == "number") {
1031
- sections.push(part, -1);
1032
- } else if (!Array.isArray(part) || typeof part[0] != "number" || part.some((e, i2) => i2 && typeof e != "string")) {
1033
- throw new RangeError("Invalid JSON representation of ChangeSet");
1034
- } else if (part.length == 1) {
1035
- sections.push(part[0], 0);
1036
- } else {
1037
- while (inserted.length < i)
1038
- inserted.push(Text.empty);
1039
- inserted[i] = Text.of(part.slice(1));
1040
- sections.push(part[0], inserted[i].length);
1041
- }
1042
- }
1043
- return new _ChangeSet(sections, inserted);
1044
- }
1045
- /**
1046
- @internal
1047
- */
1048
- static createSet(sections, inserted) {
1049
- return new _ChangeSet(sections, inserted);
1050
- }
1051
- };
1052
- function addSection(sections, len, ins, forceJoin = false) {
1053
- if (len == 0 && ins <= 0)
1054
- return;
1055
- let last = sections.length - 2;
1056
- if (last >= 0 && ins <= 0 && ins == sections[last + 1])
1057
- sections[last] += len;
1058
- else if (last >= 0 && len == 0 && sections[last] == 0)
1059
- sections[last + 1] += ins;
1060
- else if (forceJoin) {
1061
- sections[last] += len;
1062
- sections[last + 1] += ins;
1063
- } else
1064
- sections.push(len, ins);
1065
- }
1066
- function addInsert(values, sections, value) {
1067
- if (value.length == 0)
1068
- return;
1069
- let index = sections.length - 2 >> 1;
1070
- if (index < values.length) {
1071
- values[values.length - 1] = values[values.length - 1].append(value);
1072
- } else {
1073
- while (values.length < index)
1074
- values.push(Text.empty);
1075
- values.push(value);
1076
- }
1077
- }
1078
- function iterChanges(desc, f, individual) {
1079
- let inserted = desc.inserted;
1080
- for (let posA = 0, posB = 0, i = 0; i < desc.sections.length; ) {
1081
- let len = desc.sections[i++], ins = desc.sections[i++];
1082
- if (ins < 0) {
1083
- posA += len;
1084
- posB += len;
1085
- } else {
1086
- let endA = posA, endB = posB, text = Text.empty;
1087
- for (; ; ) {
1088
- endA += len;
1089
- endB += ins;
1090
- if (ins && inserted)
1091
- text = text.append(inserted[i - 2 >> 1]);
1092
- if (individual || i == desc.sections.length || desc.sections[i + 1] < 0)
1093
- break;
1094
- len = desc.sections[i++];
1095
- ins = desc.sections[i++];
1096
- }
1097
- f(posA, endA, posB, endB, text);
1098
- posA = endA;
1099
- posB = endB;
1100
- }
1101
- }
1102
- }
1103
- function mapSet(setA, setB, before, mkSet = false) {
1104
- let sections = [], insert2 = mkSet ? [] : null;
1105
- let a = new SectionIter(setA), b = new SectionIter(setB);
1106
- for (let inserted = -1; ; ) {
1107
- if (a.done && b.len || b.done && a.len) {
1108
- throw new Error("Mismatched change set lengths");
1109
- } else if (a.ins == -1 && b.ins == -1) {
1110
- let len = Math.min(a.len, b.len);
1111
- addSection(sections, len, -1);
1112
- a.forward(len);
1113
- b.forward(len);
1114
- } else if (b.ins >= 0 && (a.ins < 0 || inserted == a.i || a.off == 0 && (b.len < a.len || b.len == a.len && !before))) {
1115
- let len = b.len;
1116
- addSection(sections, b.ins, -1);
1117
- while (len) {
1118
- let piece = Math.min(a.len, len);
1119
- if (a.ins >= 0 && inserted < a.i && a.len <= piece) {
1120
- addSection(sections, 0, a.ins);
1121
- if (insert2)
1122
- addInsert(insert2, sections, a.text);
1123
- inserted = a.i;
1124
- }
1125
- a.forward(piece);
1126
- len -= piece;
1127
- }
1128
- b.next();
1129
- } else if (a.ins >= 0) {
1130
- let len = 0, left = a.len;
1131
- while (left) {
1132
- if (b.ins == -1) {
1133
- let piece = Math.min(left, b.len);
1134
- len += piece;
1135
- left -= piece;
1136
- b.forward(piece);
1137
- } else if (b.ins == 0 && b.len < left) {
1138
- left -= b.len;
1139
- b.next();
1140
- } else {
1141
- break;
1142
- }
1143
- }
1144
- addSection(sections, len, inserted < a.i ? a.ins : 0);
1145
- if (insert2 && inserted < a.i)
1146
- addInsert(insert2, sections, a.text);
1147
- inserted = a.i;
1148
- a.forward(a.len - left);
1149
- } else if (a.done && b.done) {
1150
- return insert2 ? ChangeSet.createSet(sections, insert2) : ChangeDesc.create(sections);
1151
- } else {
1152
- throw new Error("Mismatched change set lengths");
1153
- }
1154
- }
1155
- }
1156
- function composeSets(setA, setB, mkSet = false) {
1157
- let sections = [];
1158
- let insert2 = mkSet ? [] : null;
1159
- let a = new SectionIter(setA), b = new SectionIter(setB);
1160
- for (let open = false; ; ) {
1161
- if (a.done && b.done) {
1162
- return insert2 ? ChangeSet.createSet(sections, insert2) : ChangeDesc.create(sections);
1163
- } else if (a.ins == 0) {
1164
- addSection(sections, a.len, 0, open);
1165
- a.next();
1166
- } else if (b.len == 0 && !b.done) {
1167
- addSection(sections, 0, b.ins, open);
1168
- if (insert2)
1169
- addInsert(insert2, sections, b.text);
1170
- b.next();
1171
- } else if (a.done || b.done) {
1172
- throw new Error("Mismatched change set lengths");
1173
- } else {
1174
- let len = Math.min(a.len2, b.len), sectionLen = sections.length;
1175
- if (a.ins == -1) {
1176
- let insB = b.ins == -1 ? -1 : b.off ? 0 : b.ins;
1177
- addSection(sections, len, insB, open);
1178
- if (insert2 && insB)
1179
- addInsert(insert2, sections, b.text);
1180
- } else if (b.ins == -1) {
1181
- addSection(sections, a.off ? 0 : a.len, len, open);
1182
- if (insert2)
1183
- addInsert(insert2, sections, a.textBit(len));
1184
- } else {
1185
- addSection(sections, a.off ? 0 : a.len, b.off ? 0 : b.ins, open);
1186
- if (insert2 && !b.off)
1187
- addInsert(insert2, sections, b.text);
1188
- }
1189
- open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);
1190
- a.forward2(len);
1191
- b.forward(len);
1192
- }
1193
- }
1194
- }
1195
- var SectionIter = class {
1196
- constructor(set) {
1197
- this.set = set;
1198
- this.i = 0;
1199
- this.next();
1200
- }
1201
- next() {
1202
- let { sections } = this.set;
1203
- if (this.i < sections.length) {
1204
- this.len = sections[this.i++];
1205
- this.ins = sections[this.i++];
1206
- } else {
1207
- this.len = 0;
1208
- this.ins = -2;
1209
- }
1210
- this.off = 0;
1211
- }
1212
- get done() {
1213
- return this.ins == -2;
1214
- }
1215
- get len2() {
1216
- return this.ins < 0 ? this.len : this.ins;
1217
- }
1218
- get text() {
1219
- let { inserted } = this.set, index = this.i - 2 >> 1;
1220
- return index >= inserted.length ? Text.empty : inserted[index];
1221
- }
1222
- textBit(len) {
1223
- let { inserted } = this.set, index = this.i - 2 >> 1;
1224
- return index >= inserted.length && !len ? Text.empty : inserted[index].slice(this.off, len == null ? void 0 : this.off + len);
1225
- }
1226
- forward(len) {
1227
- if (len == this.len)
1228
- this.next();
1229
- else {
1230
- this.len -= len;
1231
- this.off += len;
1232
- }
1233
- }
1234
- forward2(len) {
1235
- if (this.ins == -1)
1236
- this.forward(len);
1237
- else if (len == this.ins)
1238
- this.next();
1239
- else {
1240
- this.ins -= len;
1241
- this.off += len;
1242
- }
1243
- }
1244
- };
1245
- var SelectionRange = class _SelectionRange {
1246
- constructor(from, to, flags) {
1247
- this.from = from;
1248
- this.to = to;
1249
- this.flags = flags;
1250
- }
1251
- /**
1252
- The anchor of the range—the side that doesn't move when you
1253
- extend it.
1254
- */
1255
- get anchor() {
1256
- return this.flags & 32 ? this.to : this.from;
1257
- }
1258
- /**
1259
- The head of the range, which is moved when the range is
1260
- [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
1261
- */
1262
- get head() {
1263
- return this.flags & 32 ? this.from : this.to;
1264
- }
1265
- /**
1266
- True when `anchor` and `head` are at the same position.
1267
- */
1268
- get empty() {
1269
- return this.from == this.to;
1270
- }
1271
- /**
1272
- If this is a cursor that is explicitly associated with the
1273
- character on one of its sides, this returns the side. -1 means
1274
- the character before its position, 1 the character after, and 0
1275
- means no association.
1276
- */
1277
- get assoc() {
1278
- return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0;
1279
- }
1280
- /**
1281
- The bidirectional text level associated with this cursor, if
1282
- any.
1283
- */
1284
- get bidiLevel() {
1285
- let level = this.flags & 7;
1286
- return level == 7 ? null : level;
1287
- }
1288
- /**
1289
- The goal column (stored vertical offset) associated with a
1290
- cursor. This is used to preserve the vertical position when
1291
- [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
1292
- lines of different length.
1293
- */
1294
- get goalColumn() {
1295
- let value = this.flags >> 6;
1296
- return value == 16777215 ? void 0 : value;
1297
- }
1298
- /**
1299
- Map this range through a change, producing a valid range in the
1300
- updated document.
1301
- */
1302
- map(change, assoc = -1) {
1303
- let from, to;
1304
- if (this.empty) {
1305
- from = to = change.mapPos(this.from, assoc);
1306
- } else {
1307
- from = change.mapPos(this.from, 1);
1308
- to = change.mapPos(this.to, -1);
1309
- }
1310
- return from == this.from && to == this.to ? this : new _SelectionRange(from, to, this.flags);
1311
- }
1312
- /**
1313
- Extend this range to cover at least `from` to `to`.
1314
- */
1315
- extend(from, to = from, assoc = 0) {
1316
- if (from <= this.anchor && to >= this.anchor)
1317
- return EditorSelection.range(from, to, void 0, void 0, assoc);
1318
- let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
1319
- return EditorSelection.range(this.anchor, head, void 0, void 0, assoc);
1320
- }
1321
- /**
1322
- Compare this range to another range.
1323
- */
1324
- eq(other, includeAssoc = false) {
1325
- return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn && (!includeAssoc || !this.empty || this.assoc == other.assoc);
1326
- }
1327
- /**
1328
- Return a JSON-serializable object representing the range.
1329
- */
1330
- toJSON() {
1331
- return { anchor: this.anchor, head: this.head };
1332
- }
1333
- /**
1334
- Convert a JSON representation of a range to a `SelectionRange`
1335
- instance.
1336
- */
1337
- static fromJSON(json) {
1338
- if (!json || typeof json.anchor != "number" || typeof json.head != "number")
1339
- throw new RangeError("Invalid JSON representation for SelectionRange");
1340
- return EditorSelection.range(json.anchor, json.head);
1341
- }
1342
- /**
1343
- @internal
1344
- */
1345
- static create(from, to, flags) {
1346
- return new _SelectionRange(from, to, flags);
1347
- }
1348
- };
1349
- var EditorSelection = class _EditorSelection {
1350
- constructor(ranges, mainIndex) {
1351
- this.ranges = ranges;
1352
- this.mainIndex = mainIndex;
1353
- }
1354
- /**
1355
- Map a selection through a change. Used to adjust the selection
1356
- position for changes.
1357
- */
1358
- map(change, assoc = -1) {
1359
- if (change.empty)
1360
- return this;
1361
- return _EditorSelection.create(this.ranges.map((r) => r.map(change, assoc)), this.mainIndex);
1362
- }
1363
- /**
1364
- Compare this selection to another selection. By default, ranges
1365
- are compared only by position. When `includeAssoc` is true,
1366
- cursor ranges must also have the same
1367
- [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
1368
- */
1369
- eq(other, includeAssoc = false) {
1370
- if (this.ranges.length != other.ranges.length || this.mainIndex != other.mainIndex)
1371
- return false;
1372
- for (let i = 0; i < this.ranges.length; i++)
1373
- if (!this.ranges[i].eq(other.ranges[i], includeAssoc))
1374
- return false;
1375
- return true;
1376
- }
1377
- /**
1378
- Get the primary selection range. Usually, you should make sure
1379
- your code applies to _all_ ranges, by using methods like
1380
- [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
1381
- */
1382
- get main() {
1383
- return this.ranges[this.mainIndex];
1384
- }
1385
- /**
1386
- Make sure the selection only has one range. Returns a selection
1387
- holding only the main range from this selection.
1388
- */
1389
- asSingle() {
1390
- return this.ranges.length == 1 ? this : new _EditorSelection([this.main], 0);
1391
- }
1392
- /**
1393
- Extend this selection with an extra range.
1394
- */
1395
- addRange(range, main = true) {
1396
- return _EditorSelection.create([range].concat(this.ranges), main ? 0 : this.mainIndex + 1);
1397
- }
1398
- /**
1399
- Replace a given range with another range, and then normalize the
1400
- selection to merge and sort ranges if necessary.
1401
- */
1402
- replaceRange(range, which = this.mainIndex) {
1403
- let ranges = this.ranges.slice();
1404
- ranges[which] = range;
1405
- return _EditorSelection.create(ranges, this.mainIndex);
1406
- }
1407
- /**
1408
- Convert this selection to an object that can be serialized to
1409
- JSON.
1410
- */
1411
- toJSON() {
1412
- return { ranges: this.ranges.map((r) => r.toJSON()), main: this.mainIndex };
1413
- }
1414
- /**
1415
- Create a selection from a JSON representation.
1416
- */
1417
- static fromJSON(json) {
1418
- if (!json || !Array.isArray(json.ranges) || typeof json.main != "number" || json.main >= json.ranges.length)
1419
- throw new RangeError("Invalid JSON representation for EditorSelection");
1420
- return new _EditorSelection(json.ranges.map((r) => SelectionRange.fromJSON(r)), json.main);
1421
- }
1422
- /**
1423
- Create a selection holding a single range.
1424
- */
1425
- static single(anchor, head = anchor) {
1426
- return new _EditorSelection([_EditorSelection.range(anchor, head)], 0);
1427
- }
1428
- /**
1429
- Sort and merge the given set of ranges, creating a valid
1430
- selection.
1431
- */
1432
- static create(ranges, mainIndex = 0) {
1433
- if (ranges.length == 0)
1434
- throw new RangeError("A selection needs at least one range");
1435
- for (let pos = 0, i = 0; i < ranges.length; i++) {
1436
- let range = ranges[i];
1437
- if (range.empty ? range.from <= pos : range.from < pos)
1438
- return _EditorSelection.normalized(ranges.slice(), mainIndex);
1439
- pos = range.to;
1440
- }
1441
- return new _EditorSelection(ranges, mainIndex);
1442
- }
1443
- /**
1444
- Create a cursor selection range at the given position. You can
1445
- safely ignore the optional arguments in most situations.
1446
- */
1447
- static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
1448
- return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 : 16) | (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) | (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6);
1449
- }
1450
- /**
1451
- Create a selection range.
1452
- */
1453
- static range(anchor, head, goalColumn, bidiLevel, assoc) {
1454
- let flags = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6 | (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1455
- if (!assoc && anchor != head)
1456
- assoc = head < anchor ? 1 : -1;
1457
- return head < anchor ? SelectionRange.create(head, anchor, 32 | 16 | flags) : SelectionRange.create(anchor, head, (!assoc ? 0 : assoc < 0 ? 8 : 16) | flags);
1458
- }
1459
- /**
1460
- @internal
1461
- */
1462
- static normalized(ranges, mainIndex = 0) {
1463
- let main = ranges[mainIndex];
1464
- ranges.sort((a, b) => a.from - b.from);
1465
- mainIndex = ranges.indexOf(main);
1466
- for (let i = 1; i < ranges.length; i++) {
1467
- let range = ranges[i], prev = ranges[i - 1];
1468
- if (range.empty ? range.from <= prev.to : range.from < prev.to) {
1469
- let from = prev.from, to = Math.max(range.to, prev.to);
1470
- if (i <= mainIndex)
1471
- mainIndex--;
1472
- ranges.splice(--i, 2, range.anchor > range.head ? _EditorSelection.range(to, from) : _EditorSelection.range(from, to));
1473
- }
1474
- }
1475
- return new _EditorSelection(ranges, mainIndex);
1476
- }
1477
- };
1478
- function checkSelection(selection, docLength) {
1479
- for (let range of selection.ranges)
1480
- if (range.to > docLength)
1481
- throw new RangeError("Selection points outside of document");
1482
- }
1483
- var nextID = 0;
1484
- var Facet = class _Facet {
1485
- constructor(combine, compareInput, compare2, isStatic, enables) {
1486
- this.combine = combine;
1487
- this.compareInput = compareInput;
1488
- this.compare = compare2;
1489
- this.isStatic = isStatic;
1490
- this.id = nextID++;
1491
- this.default = combine([]);
1492
- this.extensions = typeof enables == "function" ? enables(this) : enables;
1493
- }
1494
- /**
1495
- Returns a facet reader for this facet, which can be used to
1496
- [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
1497
- */
1498
- get reader() {
1499
- return this;
1500
- }
1501
- /**
1502
- Define a new facet.
1503
- */
1504
- static define(config = {}) {
1505
- return new _Facet(config.combine || ((a) => a), config.compareInput || ((a, b) => a === b), config.compare || (!config.combine ? sameArray : (a, b) => a === b), !!config.static, config.enables);
1506
- }
1507
- /**
1508
- Returns an extension that adds the given value to this facet.
1509
- */
1510
- of(value) {
1511
- return new FacetProvider([], this, 0, value);
1512
- }
1513
- /**
1514
- Create an extension that computes a value for the facet from a
1515
- state. You must take care to declare the parts of the state that
1516
- this value depends on, since your function is only called again
1517
- for a new state when one of those parts changed.
1518
-
1519
- In cases where your value depends only on a single field, you'll
1520
- want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
1521
- */
1522
- compute(deps, get) {
1523
- if (this.isStatic)
1524
- throw new Error("Can't compute a static facet");
1525
- return new FacetProvider(deps, this, 1, get);
1526
- }
1527
- /**
1528
- Create an extension that computes zero or more values for this
1529
- facet from a state.
1530
- */
1531
- computeN(deps, get) {
1532
- if (this.isStatic)
1533
- throw new Error("Can't compute a static facet");
1534
- return new FacetProvider(deps, this, 2, get);
1535
- }
1536
- from(field, get) {
1537
- if (!get)
1538
- get = (x) => x;
1539
- return this.compute([field], (state) => get(state.field(field)));
1540
- }
1541
- };
1542
- function sameArray(a, b) {
1543
- return a == b || a.length == b.length && a.every((e, i) => e === b[i]);
1544
- }
1545
- var FacetProvider = class {
1546
- constructor(dependencies, facet, type, value) {
1547
- this.dependencies = dependencies;
1548
- this.facet = facet;
1549
- this.type = type;
1550
- this.value = value;
1551
- this.id = nextID++;
1552
- }
1553
- dynamicSlot(addresses) {
1554
- var _a;
1555
- let getter = this.value;
1556
- let compare2 = this.facet.compareInput;
1557
- let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2;
1558
- let depDoc = false, depSel = false, depAddrs = [];
1559
- for (let dep of this.dependencies) {
1560
- if (dep == "doc")
1561
- depDoc = true;
1562
- else if (dep == "selection")
1563
- depSel = true;
1564
- else if ((((_a = addresses[dep.id]) !== null && _a !== void 0 ? _a : 1) & 1) == 0)
1565
- depAddrs.push(addresses[dep.id]);
1566
- }
1567
- return {
1568
- create(state) {
1569
- state.values[idx] = getter(state);
1570
- return 1;
1571
- },
1572
- update(state, tr) {
1573
- if (depDoc && tr.docChanged || depSel && (tr.docChanged || tr.selection) || ensureAll(state, depAddrs)) {
1574
- let newVal = getter(state);
1575
- if (multi ? !compareArray(newVal, state.values[idx], compare2) : !compare2(newVal, state.values[idx])) {
1576
- state.values[idx] = newVal;
1577
- return 1;
1578
- }
1579
- }
1580
- return 0;
1581
- },
1582
- reconfigure: (state, oldState) => {
1583
- let newVal, oldAddr = oldState.config.address[id];
1584
- if (oldAddr != null) {
1585
- let oldVal = getAddr(oldState, oldAddr);
1586
- if (this.dependencies.every((dep) => {
1587
- return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) : dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;
1588
- }) || (multi ? compareArray(newVal = getter(state), oldVal, compare2) : compare2(newVal = getter(state), oldVal))) {
1589
- state.values[idx] = oldVal;
1590
- return 0;
1591
- }
1592
- } else {
1593
- newVal = getter(state);
1594
- }
1595
- state.values[idx] = newVal;
1596
- return 1;
1597
- }
1598
- };
1599
- }
1600
- };
1601
- function compareArray(a, b, compare2) {
1602
- if (a.length != b.length)
1603
- return false;
1604
- for (let i = 0; i < a.length; i++)
1605
- if (!compare2(a[i], b[i]))
1606
- return false;
1607
- return true;
1608
- }
1609
- function ensureAll(state, addrs) {
1610
- let changed = false;
1611
- for (let addr of addrs)
1612
- if (ensureAddr(state, addr) & 1)
1613
- changed = true;
1614
- return changed;
1615
- }
1616
- function dynamicFacetSlot(addresses, facet, providers) {
1617
- let providerAddrs = providers.map((p) => addresses[p.id]);
1618
- let providerTypes = providers.map((p) => p.type);
1619
- let dynamic = providerAddrs.filter((p) => !(p & 1));
1620
- let idx = addresses[facet.id] >> 1;
1621
- function get(state) {
1622
- let values = [];
1623
- for (let i = 0; i < providerAddrs.length; i++) {
1624
- let value = getAddr(state, providerAddrs[i]);
1625
- if (providerTypes[i] == 2)
1626
- for (let val of value)
1627
- values.push(val);
1628
- else
1629
- values.push(value);
1630
- }
1631
- return facet.combine(values);
1632
- }
1633
- return {
1634
- create(state) {
1635
- for (let addr of providerAddrs)
1636
- ensureAddr(state, addr);
1637
- state.values[idx] = get(state);
1638
- return 1;
1639
- },
1640
- update(state, tr) {
1641
- if (!ensureAll(state, dynamic))
1642
- return 0;
1643
- let value = get(state);
1644
- if (facet.compare(value, state.values[idx]))
1645
- return 0;
1646
- state.values[idx] = value;
1647
- return 1;
1648
- },
1649
- reconfigure(state, oldState) {
1650
- let depChanged = ensureAll(state, providerAddrs);
1651
- let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
1652
- if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {
1653
- state.values[idx] = oldValue;
1654
- return 0;
1655
- }
1656
- let value = get(state);
1657
- if (facet.compare(value, oldValue)) {
1658
- state.values[idx] = oldValue;
1659
- return 0;
1660
- }
1661
- state.values[idx] = value;
1662
- return 1;
1663
- }
1664
- };
1665
- }
1666
- var initField = Facet.define({ static: true });
1667
- var StateField = class _StateField {
1668
- constructor(id, createF, updateF, compareF, spec) {
1669
- this.id = id;
1670
- this.createF = createF;
1671
- this.updateF = updateF;
1672
- this.compareF = compareF;
1673
- this.spec = spec;
1674
- this.provides = void 0;
1675
- }
1676
- /**
1677
- Define a state field.
1678
- */
1679
- static define(config) {
1680
- let field = new _StateField(nextID++, config.create, config.update, config.compare || ((a, b) => a === b), config);
1681
- if (config.provide)
1682
- field.provides = config.provide(field);
1683
- return field;
1684
- }
1685
- create(state) {
1686
- let init = state.facet(initField).find((i) => i.field == this);
1687
- return ((init === null || init === void 0 ? void 0 : init.create) || this.createF)(state);
1688
- }
1689
- /**
1690
- @internal
1691
- */
1692
- slot(addresses) {
1693
- let idx = addresses[this.id] >> 1;
1694
- return {
1695
- create: (state) => {
1696
- state.values[idx] = this.create(state);
1697
- return 1;
1698
- },
1699
- update: (state, tr) => {
1700
- let oldVal = state.values[idx];
1701
- let value = this.updateF(oldVal, tr);
1702
- if (this.compareF(oldVal, value))
1703
- return 0;
1704
- state.values[idx] = value;
1705
- return 1;
1706
- },
1707
- reconfigure: (state, oldState) => {
1708
- let init = state.facet(initField), oldInit = oldState.facet(initField), reInit;
1709
- if ((reInit = init.find((i) => i.field == this)) && reInit != oldInit.find((i) => i.field == this)) {
1710
- state.values[idx] = reInit.create(state);
1711
- return 1;
1712
- }
1713
- if (oldState.config.address[this.id] != null) {
1714
- state.values[idx] = oldState.field(this);
1715
- return 0;
1716
- }
1717
- state.values[idx] = this.create(state);
1718
- return 1;
1719
- }
1720
- };
1721
- }
1722
- /**
1723
- Returns an extension that enables this field and overrides the
1724
- way it is initialized. Can be useful when you need to provide a
1725
- non-default starting value for the field.
1726
- */
1727
- init(create) {
1728
- return [this, initField.of({ field: this, create })];
1729
- }
1730
- /**
1731
- State field instances can be used as
1732
- [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
1733
- given state.
1734
- */
1735
- get extension() {
1736
- return this;
1737
- }
1738
- };
1739
- var Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
1740
- function prec(value) {
1741
- return (ext) => new PrecExtension(ext, value);
1742
- }
1743
- var Prec = {
1744
- /**
1745
- The highest precedence level, for extensions that should end up
1746
- near the start of the precedence ordering.
1747
- */
1748
- highest: prec(Prec_.highest),
1749
- /**
1750
- A higher-than-default precedence, for extensions that should
1751
- come before those with default precedence.
1752
- */
1753
- high: prec(Prec_.high),
1754
- /**
1755
- The default precedence, which is also used for extensions
1756
- without an explicit precedence.
1757
- */
1758
- default: prec(Prec_.default),
1759
- /**
1760
- A lower-than-default precedence.
1761
- */
1762
- low: prec(Prec_.low),
1763
- /**
1764
- The lowest precedence level. Meant for things that should end up
1765
- near the end of the extension order.
1766
- */
1767
- lowest: prec(Prec_.lowest)
1768
- };
1769
- var PrecExtension = class {
1770
- constructor(inner, prec2) {
1771
- this.inner = inner;
1772
- this.prec = prec2;
1773
- }
1774
- };
1775
- var Compartment = class _Compartment {
1776
- /**
1777
- Create an instance of this compartment to add to your [state
1778
- configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
1779
- */
1780
- of(ext) {
1781
- return new CompartmentInstance(this, ext);
1782
- }
1783
- /**
1784
- Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
1785
- reconfigures this compartment.
1786
- */
1787
- reconfigure(content) {
1788
- return _Compartment.reconfigure.of({ compartment: this, extension: content });
1789
- }
1790
- /**
1791
- Get the current content of the compartment in the state, or
1792
- `undefined` if it isn't present.
1793
- */
1794
- get(state) {
1795
- return state.config.compartments.get(this);
1796
- }
1797
- };
1798
- var CompartmentInstance = class {
1799
- constructor(compartment, inner) {
1800
- this.compartment = compartment;
1801
- this.inner = inner;
1802
- }
1803
- };
1804
- var Configuration = class _Configuration {
1805
- constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
1806
- this.base = base;
1807
- this.compartments = compartments;
1808
- this.dynamicSlots = dynamicSlots;
1809
- this.address = address;
1810
- this.staticValues = staticValues;
1811
- this.facets = facets;
1812
- this.statusTemplate = [];
1813
- while (this.statusTemplate.length < dynamicSlots.length)
1814
- this.statusTemplate.push(
1815
- 0
1816
- /* SlotStatus.Unresolved */
1817
- );
1818
- }
1819
- staticFacet(facet) {
1820
- let addr = this.address[facet.id];
1821
- return addr == null ? facet.default : this.staticValues[addr >> 1];
1822
- }
1823
- static resolve(base, compartments, oldState) {
1824
- let fields = [];
1825
- let facets = /* @__PURE__ */ Object.create(null);
1826
- let newCompartments = /* @__PURE__ */ new Map();
1827
- for (let ext of flatten(base, compartments, newCompartments)) {
1828
- if (ext instanceof StateField)
1829
- fields.push(ext);
1830
- else
1831
- (facets[ext.facet.id] || (facets[ext.facet.id] = [])).push(ext);
1832
- }
1833
- let address = /* @__PURE__ */ Object.create(null);
1834
- let staticValues = [];
1835
- let dynamicSlots = [];
1836
- for (let field of fields) {
1837
- address[field.id] = dynamicSlots.length << 1;
1838
- dynamicSlots.push((a) => field.slot(a));
1839
- }
1840
- let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
1841
- for (let id in facets) {
1842
- let providers = facets[id], facet = providers[0].facet;
1843
- let oldProviders = oldFacets && oldFacets[id] || [];
1844
- if (providers.every(
1845
- (p) => p.type == 0
1846
- /* Provider.Static */
1847
- )) {
1848
- address[facet.id] = staticValues.length << 1 | 1;
1849
- if (sameArray(oldProviders, providers)) {
1850
- staticValues.push(oldState.facet(facet));
1851
- } else {
1852
- let value = facet.combine(providers.map((p) => p.value));
1853
- staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
1854
- }
1855
- } else {
1856
- for (let p of providers) {
1857
- if (p.type == 0) {
1858
- address[p.id] = staticValues.length << 1 | 1;
1859
- staticValues.push(p.value);
1860
- } else {
1861
- address[p.id] = dynamicSlots.length << 1;
1862
- dynamicSlots.push((a) => p.dynamicSlot(a));
1863
- }
1864
- }
1865
- address[facet.id] = dynamicSlots.length << 1;
1866
- dynamicSlots.push((a) => dynamicFacetSlot(a, facet, providers));
1867
- }
1868
- }
1869
- let dynamic = dynamicSlots.map((f) => f(address));
1870
- return new _Configuration(base, newCompartments, dynamic, address, staticValues, facets);
1871
- }
1872
- };
1873
- function flatten(extension, compartments, newCompartments) {
1874
- let result = [[], [], [], [], []];
1875
- let seen = /* @__PURE__ */ new Map();
1876
- function inner(ext, prec2) {
1877
- let known = seen.get(ext);
1878
- if (known != null) {
1879
- if (known <= prec2)
1880
- return;
1881
- let found = result[known].indexOf(ext);
1882
- if (found > -1)
1883
- result[known].splice(found, 1);
1884
- if (ext instanceof CompartmentInstance)
1885
- newCompartments.delete(ext.compartment);
1886
- }
1887
- seen.set(ext, prec2);
1888
- if (Array.isArray(ext)) {
1889
- for (let e of ext)
1890
- inner(e, prec2);
1891
- } else if (ext instanceof CompartmentInstance) {
1892
- if (newCompartments.has(ext.compartment))
1893
- throw new RangeError(`Duplicate use of compartment in extensions`);
1894
- let content = compartments.get(ext.compartment) || ext.inner;
1895
- newCompartments.set(ext.compartment, content);
1896
- inner(content, prec2);
1897
- } else if (ext instanceof PrecExtension) {
1898
- inner(ext.inner, ext.prec);
1899
- } else if (ext instanceof StateField) {
1900
- result[prec2].push(ext);
1901
- if (ext.provides)
1902
- inner(ext.provides, prec2);
1903
- } else if (ext instanceof FacetProvider) {
1904
- result[prec2].push(ext);
1905
- if (ext.facet.extensions)
1906
- inner(ext.facet.extensions, Prec_.default);
1907
- } else {
1908
- let content = ext.extension;
1909
- if (!content)
1910
- throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
1911
- inner(content, prec2);
1912
- }
1913
- }
1914
- inner(extension, Prec_.default);
1915
- return result.reduce((a, b) => a.concat(b));
1916
- }
1917
- function ensureAddr(state, addr) {
1918
- if (addr & 1)
1919
- return 2;
1920
- let idx = addr >> 1;
1921
- let status = state.status[idx];
1922
- if (status == 4)
1923
- throw new Error("Cyclic dependency between fields and/or facets");
1924
- if (status & 2)
1925
- return status;
1926
- state.status[idx] = 4;
1927
- let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
1928
- return state.status[idx] = 2 | changed;
1929
- }
1930
- function getAddr(state, addr) {
1931
- return addr & 1 ? state.config.staticValues[addr >> 1] : state.values[addr >> 1];
1932
- }
1933
- var languageData = Facet.define();
1934
- var allowMultipleSelections = Facet.define({
1935
- combine: (values) => values.some((v) => v),
1936
- static: true
1937
- });
1938
- var lineSeparator = Facet.define({
1939
- combine: (values) => values.length ? values[0] : void 0,
1940
- static: true
1941
- });
1942
- var changeFilter = Facet.define();
1943
- var transactionFilter = Facet.define();
1944
- var transactionExtender = Facet.define();
1945
- var readOnly = Facet.define({
1946
- combine: (values) => values.length ? values[0] : false
1947
- });
1948
- var Annotation = class {
1949
- /**
1950
- @internal
1951
- */
1952
- constructor(type, value) {
1953
- this.type = type;
1954
- this.value = value;
1955
- }
1956
- /**
1957
- Define a new type of annotation.
1958
- */
1959
- static define() {
1960
- return new AnnotationType();
1961
- }
1962
- };
1963
- var AnnotationType = class {
1964
- /**
1965
- Create an instance of this annotation.
1966
- */
1967
- of(value) {
1968
- return new Annotation(this, value);
1969
- }
1970
- };
1971
- var StateEffectType = class {
1972
- /**
1973
- @internal
1974
- */
1975
- constructor(map) {
1976
- this.map = map;
1977
- }
1978
- /**
1979
- Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
1980
- type.
1981
- */
1982
- of(value) {
1983
- return new StateEffect(this, value);
1984
- }
1985
- };
1986
- var StateEffect = class _StateEffect {
1987
- /**
1988
- @internal
1989
- */
1990
- constructor(type, value) {
1991
- this.type = type;
1992
- this.value = value;
1993
- }
1994
- /**
1995
- Map this effect through a position mapping. Will return
1996
- `undefined` when that ends up deleting the effect.
1997
- */
1998
- map(mapping) {
1999
- let mapped = this.type.map(this.value, mapping);
2000
- return mapped === void 0 ? void 0 : mapped == this.value ? this : new _StateEffect(this.type, mapped);
2001
- }
2002
- /**
2003
- Tells you whether this effect object is of a given
2004
- [type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
2005
- */
2006
- is(type) {
2007
- return this.type == type;
2008
- }
2009
- /**
2010
- Define a new effect type. The type parameter indicates the type
2011
- of values that his effect holds. It should be a type that
2012
- doesn't include `undefined`, since that is used in
2013
- [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
2014
- removed.
2015
- */
2016
- static define(spec = {}) {
2017
- return new StateEffectType(spec.map || ((v) => v));
2018
- }
2019
- /**
2020
- Map an array of effects through a change set.
2021
- */
2022
- static mapEffects(effects, mapping) {
2023
- if (!effects.length)
2024
- return effects;
2025
- let result = [];
2026
- for (let effect of effects) {
2027
- let mapped = effect.map(mapping);
2028
- if (mapped)
2029
- result.push(mapped);
2030
- }
2031
- return result;
2032
- }
2033
- };
2034
- StateEffect.reconfigure = StateEffect.define();
2035
- StateEffect.appendConfig = StateEffect.define();
2036
- var Transaction = class _Transaction {
2037
- constructor(startState, changes, selection, effects, annotations, scrollIntoView) {
2038
- this.startState = startState;
2039
- this.changes = changes;
2040
- this.selection = selection;
2041
- this.effects = effects;
2042
- this.annotations = annotations;
2043
- this.scrollIntoView = scrollIntoView;
2044
- this._doc = null;
2045
- this._state = null;
2046
- if (selection)
2047
- checkSelection(selection, changes.newLength);
2048
- if (!annotations.some((a) => a.type == _Transaction.time))
2049
- this.annotations = annotations.concat(_Transaction.time.of(Date.now()));
2050
- }
2051
- /**
2052
- @internal
2053
- */
2054
- static create(startState, changes, selection, effects, annotations, scrollIntoView) {
2055
- return new _Transaction(startState, changes, selection, effects, annotations, scrollIntoView);
2056
- }
2057
- /**
2058
- The new document produced by the transaction. Contrary to
2059
- [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
2060
- force the entire new state to be computed right away, so it is
2061
- recommended that [transaction
2062
- filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
2063
- when they need to look at the new document.
2064
- */
2065
- get newDoc() {
2066
- return this._doc || (this._doc = this.changes.apply(this.startState.doc));
2067
- }
2068
- /**
2069
- The new selection produced by the transaction. If
2070
- [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
2071
- this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
2072
- current selection through the changes made by the transaction.
2073
- */
2074
- get newSelection() {
2075
- return this.selection || this.startState.selection.map(this.changes);
2076
- }
2077
- /**
2078
- The new state created by the transaction. Computed on demand
2079
- (but retained for subsequent access), so it is recommended not to
2080
- access it in [transaction
2081
- filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
2082
- */
2083
- get state() {
2084
- if (!this._state)
2085
- this.startState.applyTransaction(this);
2086
- return this._state;
2087
- }
2088
- /**
2089
- Get the value of the given annotation type, if any.
2090
- */
2091
- annotation(type) {
2092
- for (let ann of this.annotations)
2093
- if (ann.type == type)
2094
- return ann.value;
2095
- return void 0;
2096
- }
2097
- /**
2098
- Indicates whether the transaction changed the document.
2099
- */
2100
- get docChanged() {
2101
- return !this.changes.empty;
2102
- }
2103
- /**
2104
- Indicates whether this transaction reconfigures the state
2105
- (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
2106
- with a top-level configuration
2107
- [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
2108
- */
2109
- get reconfigured() {
2110
- return this.startState.config != this.state.config;
2111
- }
2112
- /**
2113
- Returns true if the transaction has a [user
2114
- event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
2115
- or more specific than `event`. For example, if the transaction
2116
- has `"select.pointer"` as user event, `"select"` and
2117
- `"select.pointer"` will match it.
2118
- */
2119
- isUserEvent(event) {
2120
- let e = this.annotation(_Transaction.userEvent);
2121
- return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
2122
- }
2123
- };
2124
- Transaction.time = Annotation.define();
2125
- Transaction.userEvent = Annotation.define();
2126
- Transaction.addToHistory = Annotation.define();
2127
- Transaction.remote = Annotation.define();
2128
- function joinRanges(a, b) {
2129
- let result = [];
2130
- for (let iA = 0, iB = 0; ; ) {
2131
- let from, to;
2132
- if (iA < a.length && (iB == b.length || b[iB] >= a[iA])) {
2133
- from = a[iA++];
2134
- to = a[iA++];
2135
- } else if (iB < b.length) {
2136
- from = b[iB++];
2137
- to = b[iB++];
2138
- } else
2139
- return result;
2140
- if (!result.length || result[result.length - 1] < from)
2141
- result.push(from, to);
2142
- else if (result[result.length - 1] < to)
2143
- result[result.length - 1] = to;
2144
- }
2145
- }
2146
- function mergeTransaction(a, b, sequential) {
2147
- var _a;
2148
- let mapForA, mapForB, changes;
2149
- if (sequential) {
2150
- mapForA = b.changes;
2151
- mapForB = ChangeSet.empty(b.changes.length);
2152
- changes = a.changes.compose(b.changes);
2153
- } else {
2154
- mapForA = b.changes.map(a.changes);
2155
- mapForB = a.changes.mapDesc(b.changes, true);
2156
- changes = a.changes.compose(mapForA);
2157
- }
2158
- return {
2159
- changes,
2160
- selection: b.selection ? b.selection.map(mapForB) : (_a = a.selection) === null || _a === void 0 ? void 0 : _a.map(mapForA),
2161
- effects: StateEffect.mapEffects(a.effects, mapForA).concat(StateEffect.mapEffects(b.effects, mapForB)),
2162
- annotations: a.annotations.length ? a.annotations.concat(b.annotations) : b.annotations,
2163
- scrollIntoView: a.scrollIntoView || b.scrollIntoView
2164
- };
2165
- }
2166
- function resolveTransactionInner(state, spec, docSize) {
2167
- let sel = spec.selection, annotations = asArray(spec.annotations);
2168
- if (spec.userEvent)
2169
- annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));
2170
- return {
2171
- changes: spec.changes instanceof ChangeSet ? spec.changes : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),
2172
- selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),
2173
- effects: asArray(spec.effects),
2174
- annotations,
2175
- scrollIntoView: !!spec.scrollIntoView
2176
- };
2177
- }
2178
- function resolveTransaction(state, specs, filter) {
2179
- let s = resolveTransactionInner(state, specs.length ? specs[0] : {}, state.doc.length);
2180
- if (specs.length && specs[0].filter === false)
2181
- filter = false;
2182
- for (let i = 1; i < specs.length; i++) {
2183
- if (specs[i].filter === false)
2184
- filter = false;
2185
- let seq = !!specs[i].sequential;
2186
- s = mergeTransaction(s, resolveTransactionInner(state, specs[i], seq ? s.changes.newLength : state.doc.length), seq);
2187
- }
2188
- let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);
2189
- return extendTransaction(filter ? filterTransaction(tr) : tr);
2190
- }
2191
- function filterTransaction(tr) {
2192
- let state = tr.startState;
2193
- let result = true;
2194
- for (let filter of state.facet(changeFilter)) {
2195
- let value = filter(tr);
2196
- if (value === false) {
2197
- result = false;
2198
- break;
2199
- }
2200
- if (Array.isArray(value))
2201
- result = result === true ? value : joinRanges(result, value);
2202
- }
2203
- if (result !== true) {
2204
- let changes, back;
2205
- if (result === false) {
2206
- back = tr.changes.invertedDesc;
2207
- changes = ChangeSet.empty(state.doc.length);
2208
- } else {
2209
- let filtered = tr.changes.filter(result);
2210
- changes = filtered.changes;
2211
- back = filtered.filtered.mapDesc(filtered.changes).invertedDesc;
2212
- }
2213
- tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
2214
- }
2215
- let filters = state.facet(transactionFilter);
2216
- for (let i = filters.length - 1; i >= 0; i--) {
2217
- let filtered = filters[i](tr);
2218
- if (filtered instanceof Transaction)
2219
- tr = filtered;
2220
- else if (Array.isArray(filtered) && filtered.length == 1 && filtered[0] instanceof Transaction)
2221
- tr = filtered[0];
2222
- else
2223
- tr = resolveTransaction(state, asArray(filtered), false);
2224
- }
2225
- return tr;
2226
- }
2227
- function extendTransaction(tr) {
2228
- let state = tr.startState, extenders = state.facet(transactionExtender), spec = tr;
2229
- for (let i = extenders.length - 1; i >= 0; i--) {
2230
- let extension = extenders[i](tr);
2231
- if (extension && Object.keys(extension).length)
2232
- spec = mergeTransaction(spec, resolveTransactionInner(state, extension, tr.changes.newLength), true);
2233
- }
2234
- return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
2235
- }
2236
- var none = [];
2237
- function asArray(value) {
2238
- return value == null ? none : Array.isArray(value) ? value : [value];
2239
- }
2240
- var CharCategory = (function(CharCategory2) {
2241
- CharCategory2[CharCategory2["Word"] = 0] = "Word";
2242
- CharCategory2[CharCategory2["Space"] = 1] = "Space";
2243
- CharCategory2[CharCategory2["Other"] = 2] = "Other";
2244
- return CharCategory2;
2245
- })(CharCategory || (CharCategory = {}));
2246
- var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
2247
- var wordChar;
2248
- try {
2249
- wordChar = new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u");
2250
- } catch (_) {
2251
- }
2252
- function hasWordChar(str) {
2253
- if (wordChar)
2254
- return wordChar.test(str);
2255
- for (let i = 0; i < str.length; i++) {
2256
- let ch = str[i];
2257
- if (/\w/.test(ch) || ch > "€" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)))
2258
- return true;
2259
- }
2260
- return false;
2261
- }
2262
- function makeCategorizer(wordChars) {
2263
- return (char) => {
2264
- if (!/\S/.test(char))
2265
- return CharCategory.Space;
2266
- if (hasWordChar(char))
2267
- return CharCategory.Word;
2268
- for (let i = 0; i < wordChars.length; i++)
2269
- if (char.indexOf(wordChars[i]) > -1)
2270
- return CharCategory.Word;
2271
- return CharCategory.Other;
2272
- };
2273
- }
2274
- var EditorState = class _EditorState {
2275
- constructor(config, doc, selection, values, computeSlot, tr) {
2276
- this.config = config;
2277
- this.doc = doc;
2278
- this.selection = selection;
2279
- this.values = values;
2280
- this.status = config.statusTemplate.slice();
2281
- this.computeSlot = computeSlot;
2282
- if (tr)
2283
- tr._state = this;
2284
- for (let i = 0; i < this.config.dynamicSlots.length; i++)
2285
- ensureAddr(this, i << 1);
2286
- this.computeSlot = null;
2287
- }
2288
- field(field, require2 = true) {
2289
- let addr = this.config.address[field.id];
2290
- if (addr == null) {
2291
- if (require2)
2292
- throw new RangeError("Field is not present in this state");
2293
- return void 0;
2294
- }
2295
- ensureAddr(this, addr);
2296
- return getAddr(this, addr);
2297
- }
2298
- /**
2299
- Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
2300
- state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
2301
- can be passed. Unless
2302
- [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
2303
- [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
2304
- are assumed to start in the _current_ document (not the document
2305
- produced by previous specs), and its
2306
- [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
2307
- [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
2308
- to the document created by its _own_ changes. The resulting
2309
- transaction contains the combined effect of all the different
2310
- specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
2311
- specs take precedence over earlier ones.
2312
- */
2313
- update(...specs) {
2314
- return resolveTransaction(this, specs, true);
2315
- }
2316
- /**
2317
- @internal
2318
- */
2319
- applyTransaction(tr) {
2320
- let conf = this.config, { base, compartments } = conf;
2321
- for (let effect of tr.effects) {
2322
- if (effect.is(Compartment.reconfigure)) {
2323
- if (conf) {
2324
- compartments = /* @__PURE__ */ new Map();
2325
- conf.compartments.forEach((val, key) => compartments.set(key, val));
2326
- conf = null;
2327
- }
2328
- compartments.set(effect.value.compartment, effect.value.extension);
2329
- } else if (effect.is(StateEffect.reconfigure)) {
2330
- conf = null;
2331
- base = effect.value;
2332
- } else if (effect.is(StateEffect.appendConfig)) {
2333
- conf = null;
2334
- base = asArray(base).concat(effect.value);
2335
- }
2336
- }
2337
- let startValues;
2338
- if (!conf) {
2339
- conf = Configuration.resolve(base, compartments, this);
2340
- let intermediateState = new _EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);
2341
- startValues = intermediateState.values;
2342
- } else {
2343
- startValues = tr.startState.values.slice();
2344
- }
2345
- let selection = tr.startState.facet(allowMultipleSelections) ? tr.newSelection : tr.newSelection.asSingle();
2346
- new _EditorState(conf, tr.newDoc, selection, startValues, (state, slot) => slot.update(state, tr), tr);
2347
- }
2348
- /**
2349
- Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
2350
- replaces every selection range with the given content.
2351
- */
2352
- replaceSelection(text) {
2353
- if (typeof text == "string")
2354
- text = this.toText(text);
2355
- return this.changeByRange((range) => ({
2356
- changes: { from: range.from, to: range.to, insert: text },
2357
- range: EditorSelection.cursor(range.from + text.length)
2358
- }));
2359
- }
2360
- /**
2361
- Create a set of changes and a new selection by running the given
2362
- function for each range in the active selection. The function
2363
- can return an optional set of changes (in the coordinate space
2364
- of the start document), plus an updated range (in the coordinate
2365
- space of the document produced by the call's own changes). This
2366
- method will merge all the changes and ranges into a single
2367
- changeset and selection, and return it as a [transaction
2368
- spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
2369
- [`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
2370
- */
2371
- changeByRange(f) {
2372
- let sel = this.selection;
2373
- let result1 = f(sel.ranges[0]);
2374
- let changes = this.changes(result1.changes), ranges = [result1.range];
2375
- let effects = asArray(result1.effects);
2376
- for (let i = 1; i < sel.ranges.length; i++) {
2377
- let result = f(sel.ranges[i]);
2378
- let newChanges = this.changes(result.changes), newMapped = newChanges.map(changes);
2379
- for (let j = 0; j < i; j++)
2380
- ranges[j] = ranges[j].map(newMapped);
2381
- let mapBy = changes.mapDesc(newChanges, true);
2382
- ranges.push(result.range.map(mapBy));
2383
- changes = changes.compose(newMapped);
2384
- effects = StateEffect.mapEffects(effects, newMapped).concat(StateEffect.mapEffects(asArray(result.effects), mapBy));
2385
- }
2386
- return {
2387
- changes,
2388
- selection: EditorSelection.create(ranges, sel.mainIndex),
2389
- effects
2390
- };
2391
- }
2392
- /**
2393
- Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
2394
- description, taking the state's document length and line
2395
- separator into account.
2396
- */
2397
- changes(spec = []) {
2398
- if (spec instanceof ChangeSet)
2399
- return spec;
2400
- return ChangeSet.of(spec, this.doc.length, this.facet(_EditorState.lineSeparator));
2401
- }
2402
- /**
2403
- Using the state's [line
2404
- separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
2405
- [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
2406
- */
2407
- toText(string) {
2408
- return Text.of(string.split(this.facet(_EditorState.lineSeparator) || DefaultSplit));
2409
- }
2410
- /**
2411
- Return the given range of the document as a string.
2412
- */
2413
- sliceDoc(from = 0, to = this.doc.length) {
2414
- return this.doc.sliceString(from, to, this.lineBreak);
2415
- }
2416
- /**
2417
- Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
2418
- */
2419
- facet(facet) {
2420
- let addr = this.config.address[facet.id];
2421
- if (addr == null)
2422
- return facet.default;
2423
- ensureAddr(this, addr);
2424
- return getAddr(this, addr);
2425
- }
2426
- /**
2427
- Convert this state to a JSON-serializable object. When custom
2428
- fields should be serialized, you can pass them in as an object
2429
- mapping property names (in the resulting object, which should
2430
- not use `doc` or `selection`) to fields.
2431
- */
2432
- toJSON(fields) {
2433
- let result = {
2434
- doc: this.sliceDoc(),
2435
- selection: this.selection.toJSON()
2436
- };
2437
- if (fields)
2438
- for (let prop in fields) {
2439
- let value = fields[prop];
2440
- if (value instanceof StateField && this.config.address[value.id] != null)
2441
- result[prop] = value.spec.toJSON(this.field(fields[prop]), this);
2442
- }
2443
- return result;
2444
- }
2445
- /**
2446
- Deserialize a state from its JSON representation. When custom
2447
- fields should be deserialized, pass the same object you passed
2448
- to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
2449
- third argument.
2450
- */
2451
- static fromJSON(json, config = {}, fields) {
2452
- if (!json || typeof json.doc != "string")
2453
- throw new RangeError("Invalid JSON representation for EditorState");
2454
- let fieldInit = [];
2455
- if (fields)
2456
- for (let prop in fields) {
2457
- if (Object.prototype.hasOwnProperty.call(json, prop)) {
2458
- let field = fields[prop], value = json[prop];
2459
- fieldInit.push(field.init((state) => field.spec.fromJSON(value, state)));
2460
- }
2461
- }
2462
- return _EditorState.create({
2463
- doc: json.doc,
2464
- selection: EditorSelection.fromJSON(json.selection),
2465
- extensions: config.extensions ? fieldInit.concat([config.extensions]) : fieldInit
2466
- });
2467
- }
2468
- /**
2469
- Create a new state. You'll usually only need this when
2470
- initializing an editor—updated states are created by applying
2471
- transactions.
2472
- */
2473
- static create(config = {}) {
2474
- let configuration = Configuration.resolve(config.extensions || [], /* @__PURE__ */ new Map());
2475
- let doc = config.doc instanceof Text ? config.doc : Text.of((config.doc || "").split(configuration.staticFacet(_EditorState.lineSeparator) || DefaultSplit));
2476
- let selection = !config.selection ? EditorSelection.single(0) : config.selection instanceof EditorSelection ? config.selection : EditorSelection.single(config.selection.anchor, config.selection.head);
2477
- checkSelection(selection, doc.length);
2478
- if (!configuration.staticFacet(allowMultipleSelections))
2479
- selection = selection.asSingle();
2480
- return new _EditorState(configuration, doc, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
2481
- }
2482
- /**
2483
- The size (in columns) of a tab in the document, determined by
2484
- the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
2485
- */
2486
- get tabSize() {
2487
- return this.facet(_EditorState.tabSize);
2488
- }
2489
- /**
2490
- Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
2491
- string for this state.
2492
- */
2493
- get lineBreak() {
2494
- return this.facet(_EditorState.lineSeparator) || "\n";
2495
- }
2496
- /**
2497
- Returns true when the editor is
2498
- [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
2499
- */
2500
- get readOnly() {
2501
- return this.facet(readOnly);
2502
- }
2503
- /**
2504
- Look up a translation for the given phrase (via the
2505
- [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
2506
- original string if no translation is found.
2507
-
2508
- If additional arguments are passed, they will be inserted in
2509
- place of markers like `$1` (for the first value) and `$2`, etc.
2510
- A single `$` is equivalent to `$1`, and `$$` will produce a
2511
- literal dollar sign.
2512
- */
2513
- phrase(phrase, ...insert2) {
2514
- for (let map of this.facet(_EditorState.phrases))
2515
- if (Object.prototype.hasOwnProperty.call(map, phrase)) {
2516
- phrase = map[phrase];
2517
- break;
2518
- }
2519
- if (insert2.length)
2520
- phrase = phrase.replace(/\$(\$|\d*)/g, (m, i) => {
2521
- if (i == "$")
2522
- return "$";
2523
- let n = +(i || 1);
2524
- return !n || n > insert2.length ? m : insert2[n - 1];
2525
- });
2526
- return phrase;
2527
- }
2528
- /**
2529
- Find the values for a given language data field, provided by the
2530
- the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
2531
-
2532
- Examples of language data fields are...
2533
-
2534
- - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
2535
- comment syntax.
2536
- - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
2537
- for providing language-specific completion sources.
2538
- - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
2539
- characters that should be considered part of words in this
2540
- language.
2541
- - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
2542
- bracket closing behavior.
2543
- */
2544
- languageDataAt(name, pos, side = -1) {
2545
- let values = [];
2546
- for (let provider of this.facet(languageData)) {
2547
- for (let result of provider(this, pos, side)) {
2548
- if (Object.prototype.hasOwnProperty.call(result, name))
2549
- values.push(result[name]);
2550
- }
2551
- }
2552
- return values;
2553
- }
2554
- /**
2555
- Return a function that can categorize strings (expected to
2556
- represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
2557
- into one of:
2558
-
2559
- - Word (contains an alphanumeric character or a character
2560
- explicitly listed in the local language's `"wordChars"`
2561
- language data, which should be a string)
2562
- - Space (contains only whitespace)
2563
- - Other (anything else)
2564
- */
2565
- charCategorizer(at) {
2566
- let chars = this.languageDataAt("wordChars", at);
2567
- return makeCategorizer(chars.length ? chars[0] : "");
2568
- }
2569
- /**
2570
- Find the word at the given position, meaning the range
2571
- containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
2572
- around it. If no word characters are adjacent to the position,
2573
- this returns null.
2574
- */
2575
- wordAt(pos) {
2576
- let { text, from, length } = this.doc.lineAt(pos);
2577
- let cat = this.charCategorizer(pos);
2578
- let start = pos - from, end = pos - from;
2579
- while (start > 0) {
2580
- let prev = findClusterBreak2(text, start, false);
2581
- if (cat(text.slice(prev, start)) != CharCategory.Word)
2582
- break;
2583
- start = prev;
2584
- }
2585
- while (end < length) {
2586
- let next = findClusterBreak2(text, end);
2587
- if (cat(text.slice(end, next)) != CharCategory.Word)
2588
- break;
2589
- end = next;
2590
- }
2591
- return start == end ? null : EditorSelection.range(start + from, end + from);
2592
- }
2593
- };
2594
- EditorState.allowMultipleSelections = allowMultipleSelections;
2595
- EditorState.tabSize = Facet.define({
2596
- combine: (values) => values.length ? values[0] : 4
2597
- });
2598
- EditorState.lineSeparator = lineSeparator;
2599
- EditorState.readOnly = readOnly;
2600
- EditorState.phrases = Facet.define({
2601
- compare(a, b) {
2602
- let kA = Object.keys(a), kB = Object.keys(b);
2603
- return kA.length == kB.length && kA.every((k) => a[k] == b[k]);
2604
- }
2605
- });
2606
- EditorState.languageData = languageData;
2607
- EditorState.changeFilter = changeFilter;
2608
- EditorState.transactionFilter = transactionFilter;
2609
- EditorState.transactionExtender = transactionExtender;
2610
- Compartment.reconfigure = StateEffect.define();
2611
- function combineConfig(configs, defaults, combine = {}) {
2612
- let result = {};
2613
- for (let config of configs)
2614
- for (let key of Object.keys(config)) {
2615
- let value = config[key], current = result[key];
2616
- if (current === void 0)
2617
- result[key] = value;
2618
- else if (current === value || value === void 0) ;
2619
- else if (Object.hasOwnProperty.call(combine, key))
2620
- result[key] = combine[key](current, value);
2621
- else
2622
- throw new Error("Config merge conflict for field " + key);
2623
- }
2624
- for (let key in defaults)
2625
- if (result[key] === void 0)
2626
- result[key] = defaults[key];
2627
- return result;
2628
- }
2629
- var RangeValue = class {
2630
- /**
2631
- Compare this value with another value. Used when comparing
2632
- rangesets. The default implementation compares by identity.
2633
- Unless you are only creating a fixed number of unique instances
2634
- of your value type, it is a good idea to implement this
2635
- properly.
2636
- */
2637
- eq(other) {
2638
- return this == other;
2639
- }
2640
- /**
2641
- Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
2642
- */
2643
- range(from, to = from) {
2644
- return Range.create(from, to, this);
2645
- }
2646
- };
2647
- RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
2648
- RangeValue.prototype.point = false;
2649
- RangeValue.prototype.mapMode = MapMode.TrackDel;
2650
- function cmpVal(a, b) {
2651
- return a == b || a.constructor == b.constructor && a.eq(b);
2652
- }
2653
- var Range = class _Range {
2654
- constructor(from, to, value) {
2655
- this.from = from;
2656
- this.to = to;
2657
- this.value = value;
2658
- }
2659
- /**
2660
- @internal
2661
- */
2662
- static create(from, to, value) {
2663
- return new _Range(from, to, value);
2664
- }
2665
- };
2666
- function cmpRange(a, b) {
2667
- return a.from - b.from || a.value.startSide - b.value.startSide;
2668
- }
2669
- var Chunk = class _Chunk {
2670
- constructor(from, to, value, maxPoint) {
2671
- this.from = from;
2672
- this.to = to;
2673
- this.value = value;
2674
- this.maxPoint = maxPoint;
2675
- }
2676
- get length() {
2677
- return this.to[this.to.length - 1];
2678
- }
2679
- // Find the index of the given position and side. Use the ranges'
2680
- // `from` pos when `end == false`, `to` when `end == true`.
2681
- findIndex(pos, side, end, startAt = 0) {
2682
- let arr = end ? this.to : this.from;
2683
- for (let lo = startAt, hi = arr.length; ; ) {
2684
- if (lo == hi)
2685
- return lo;
2686
- let mid = lo + hi >> 1;
2687
- let diff = arr[mid] - pos || (end ? this.value[mid].endSide : this.value[mid].startSide) - side;
2688
- if (mid == lo)
2689
- return diff >= 0 ? lo : hi;
2690
- if (diff >= 0)
2691
- hi = mid;
2692
- else
2693
- lo = mid + 1;
2694
- }
2695
- }
2696
- between(offset, from, to, f) {
2697
- for (let i = this.findIndex(from, -1e9, true), e = this.findIndex(to, 1e9, false, i); i < e; i++)
2698
- if (f(this.from[i] + offset, this.to[i] + offset, this.value[i]) === false)
2699
- return false;
2700
- }
2701
- map(offset, changes) {
2702
- let value = [], from = [], to = [], newPos = -1, maxPoint = -1;
2703
- for (let i = 0; i < this.value.length; i++) {
2704
- let val = this.value[i], curFrom = this.from[i] + offset, curTo = this.to[i] + offset, newFrom, newTo;
2705
- if (curFrom == curTo) {
2706
- let mapped = changes.mapPos(curFrom, val.startSide, val.mapMode);
2707
- if (mapped == null)
2708
- continue;
2709
- newFrom = newTo = mapped;
2710
- if (val.startSide != val.endSide) {
2711
- newTo = changes.mapPos(curFrom, val.endSide);
2712
- if (newTo < newFrom)
2713
- continue;
2714
- }
2715
- } else {
2716
- newFrom = changes.mapPos(curFrom, val.startSide);
2717
- newTo = changes.mapPos(curTo, val.endSide);
2718
- if (newFrom > newTo || newFrom == newTo && val.startSide > 0 && val.endSide <= 0)
2719
- continue;
2720
- }
2721
- if ((newTo - newFrom || val.endSide - val.startSide) < 0)
2722
- continue;
2723
- if (newPos < 0)
2724
- newPos = newFrom;
2725
- if (val.point)
2726
- maxPoint = Math.max(maxPoint, newTo - newFrom);
2727
- value.push(val);
2728
- from.push(newFrom - newPos);
2729
- to.push(newTo - newPos);
2730
- }
2731
- return { mapped: value.length ? new _Chunk(from, to, value, maxPoint) : null, pos: newPos };
2732
- }
2733
- };
2734
- var RangeSet = class _RangeSet {
2735
- constructor(chunkPos, chunk, nextLayer, maxPoint) {
2736
- this.chunkPos = chunkPos;
2737
- this.chunk = chunk;
2738
- this.nextLayer = nextLayer;
2739
- this.maxPoint = maxPoint;
2740
- }
2741
- /**
2742
- @internal
2743
- */
2744
- static create(chunkPos, chunk, nextLayer, maxPoint) {
2745
- return new _RangeSet(chunkPos, chunk, nextLayer, maxPoint);
2746
- }
2747
- /**
2748
- @internal
2749
- */
2750
- get length() {
2751
- let last = this.chunk.length - 1;
2752
- return last < 0 ? 0 : Math.max(this.chunkEnd(last), this.nextLayer.length);
2753
- }
2754
- /**
2755
- The number of ranges in the set.
2756
- */
2757
- get size() {
2758
- if (this.isEmpty)
2759
- return 0;
2760
- let size = this.nextLayer.size;
2761
- for (let chunk of this.chunk)
2762
- size += chunk.value.length;
2763
- return size;
2764
- }
2765
- /**
2766
- @internal
2767
- */
2768
- chunkEnd(index) {
2769
- return this.chunkPos[index] + this.chunk[index].length;
2770
- }
2771
- /**
2772
- Update the range set, optionally adding new ranges or filtering
2773
- out existing ones.
2774
-
2775
- (Note: The type parameter is just there as a kludge to work
2776
- around TypeScript variance issues that prevented `RangeSet<X>`
2777
- from being a subtype of `RangeSet<Y>` when `X` is a subtype of
2778
- `Y`.)
2779
- */
2780
- update(updateSpec) {
2781
- let { add = [], sort = false, filterFrom = 0, filterTo = this.length } = updateSpec;
2782
- let filter = updateSpec.filter;
2783
- if (add.length == 0 && !filter)
2784
- return this;
2785
- if (sort)
2786
- add = add.slice().sort(cmpRange);
2787
- if (this.isEmpty)
2788
- return add.length ? _RangeSet.of(add) : this;
2789
- let cur = new LayerCursor(this, null, -1).goto(0), i = 0, spill = [];
2790
- let builder = new RangeSetBuilder();
2791
- while (cur.value || i < add.length) {
2792
- if (i < add.length && (cur.from - add[i].from || cur.startSide - add[i].value.startSide) >= 0) {
2793
- let range = add[i++];
2794
- if (!builder.addInner(range.from, range.to, range.value))
2795
- spill.push(range);
2796
- } else if (cur.rangeIndex == 1 && cur.chunkIndex < this.chunk.length && (i == add.length || this.chunkEnd(cur.chunkIndex) < add[i].from) && (!filter || filterFrom > this.chunkEnd(cur.chunkIndex) || filterTo < this.chunkPos[cur.chunkIndex]) && builder.addChunk(this.chunkPos[cur.chunkIndex], this.chunk[cur.chunkIndex])) {
2797
- cur.nextChunk();
2798
- } else {
2799
- if (!filter || filterFrom > cur.to || filterTo < cur.from || filter(cur.from, cur.to, cur.value)) {
2800
- if (!builder.addInner(cur.from, cur.to, cur.value))
2801
- spill.push(Range.create(cur.from, cur.to, cur.value));
2802
- }
2803
- cur.next();
2804
- }
2805
- }
2806
- return builder.finishInner(this.nextLayer.isEmpty && !spill.length ? _RangeSet.empty : this.nextLayer.update({ add: spill, filter, filterFrom, filterTo }));
2807
- }
2808
- /**
2809
- Map this range set through a set of changes, return the new set.
2810
- */
2811
- map(changes) {
2812
- if (changes.empty || this.isEmpty)
2813
- return this;
2814
- let chunks = [], chunkPos = [], maxPoint = -1;
2815
- for (let i = 0; i < this.chunk.length; i++) {
2816
- let start = this.chunkPos[i], chunk = this.chunk[i];
2817
- let touch = changes.touchesRange(start, start + chunk.length);
2818
- if (touch === false) {
2819
- maxPoint = Math.max(maxPoint, chunk.maxPoint);
2820
- chunks.push(chunk);
2821
- chunkPos.push(changes.mapPos(start));
2822
- } else if (touch === true) {
2823
- let { mapped, pos } = chunk.map(start, changes);
2824
- if (mapped) {
2825
- maxPoint = Math.max(maxPoint, mapped.maxPoint);
2826
- chunks.push(mapped);
2827
- chunkPos.push(pos);
2828
- }
2829
- }
2830
- }
2831
- let next = this.nextLayer.map(changes);
2832
- return chunks.length == 0 ? next : new _RangeSet(chunkPos, chunks, next || _RangeSet.empty, maxPoint);
2833
- }
2834
- /**
2835
- Iterate over the ranges that touch the region `from` to `to`,
2836
- calling `f` for each. There is no guarantee that the ranges will
2837
- be reported in any specific order. When the callback returns
2838
- `false`, iteration stops.
2839
- */
2840
- between(from, to, f) {
2841
- if (this.isEmpty)
2842
- return;
2843
- for (let i = 0; i < this.chunk.length; i++) {
2844
- let start = this.chunkPos[i], chunk = this.chunk[i];
2845
- if (to >= start && from <= start + chunk.length && chunk.between(start, from - start, to - start, f) === false)
2846
- return;
2847
- }
2848
- this.nextLayer.between(from, to, f);
2849
- }
2850
- /**
2851
- Iterate over the ranges in this set, in order, including all
2852
- ranges that end at or after `from`.
2853
- */
2854
- iter(from = 0) {
2855
- return HeapCursor.from([this]).goto(from);
2856
- }
2857
- /**
2858
- @internal
2859
- */
2860
- get isEmpty() {
2861
- return this.nextLayer == this;
2862
- }
2863
- /**
2864
- Iterate over the ranges in a collection of sets, in order,
2865
- starting from `from`.
2866
- */
2867
- static iter(sets, from = 0) {
2868
- return HeapCursor.from(sets).goto(from);
2869
- }
2870
- /**
2871
- Iterate over two groups of sets, calling methods on `comparator`
2872
- to notify it of possible differences.
2873
- */
2874
- static compare(oldSets, newSets, textDiff, comparator, minPointSize = -1) {
2875
- let a = oldSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
2876
- let b = newSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
2877
- let sharedChunks = findSharedChunks(a, b, textDiff);
2878
- let sideA = new SpanCursor(a, sharedChunks, minPointSize);
2879
- let sideB = new SpanCursor(b, sharedChunks, minPointSize);
2880
- textDiff.iterGaps((fromA, fromB, length) => compare(sideA, fromA, sideB, fromB, length, comparator));
2881
- if (textDiff.empty && textDiff.length == 0)
2882
- compare(sideA, 0, sideB, 0, 0, comparator);
2883
- }
2884
- /**
2885
- Compare the contents of two groups of range sets, returning true
2886
- if they are equivalent in the given range.
2887
- */
2888
- static eq(oldSets, newSets, from = 0, to) {
2889
- if (to == null)
2890
- to = 1e9 - 1;
2891
- let a = oldSets.filter((set) => !set.isEmpty && newSets.indexOf(set) < 0);
2892
- let b = newSets.filter((set) => !set.isEmpty && oldSets.indexOf(set) < 0);
2893
- if (a.length != b.length)
2894
- return false;
2895
- if (!a.length)
2896
- return true;
2897
- let sharedChunks = findSharedChunks(a, b);
2898
- let sideA = new SpanCursor(a, sharedChunks, 0).goto(from), sideB = new SpanCursor(b, sharedChunks, 0).goto(from);
2899
- for (; ; ) {
2900
- if (sideA.to != sideB.to || !sameValues(sideA.active, sideB.active) || sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point)))
2901
- return false;
2902
- if (sideA.to > to)
2903
- return true;
2904
- sideA.next();
2905
- sideB.next();
2906
- }
2907
- }
2908
- /**
2909
- Iterate over a group of range sets at the same time, notifying
2910
- the iterator about the ranges covering every given piece of
2911
- content. Returns the open count (see
2912
- [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
2913
- of the iteration.
2914
- */
2915
- static spans(sets, from, to, iterator, minPointSize = -1) {
2916
- let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;
2917
- let openRanges = cursor.openStart;
2918
- for (; ; ) {
2919
- let curTo = Math.min(cursor.to, to);
2920
- if (cursor.point) {
2921
- let active = cursor.activeForPoint(cursor.to);
2922
- let openCount = cursor.pointFrom < from ? active.length + 1 : cursor.point.startSide < 0 ? active.length : Math.min(active.length, openRanges);
2923
- iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
2924
- openRanges = Math.min(cursor.openEnd(curTo), active.length);
2925
- } else if (curTo > pos) {
2926
- iterator.span(pos, curTo, cursor.active, openRanges);
2927
- openRanges = cursor.openEnd(curTo);
2928
- }
2929
- if (cursor.to > to)
2930
- return openRanges + (cursor.point && cursor.to > to ? 1 : 0);
2931
- pos = cursor.to;
2932
- cursor.next();
2933
- }
2934
- }
2935
- /**
2936
- Create a range set for the given range or array of ranges. By
2937
- default, this expects the ranges to be _sorted_ (by start
2938
- position and, if two start at the same position,
2939
- `value.startSide`). You can pass `true` as second argument to
2940
- cause the method to sort them.
2941
- */
2942
- static of(ranges, sort = false) {
2943
- let build = new RangeSetBuilder();
2944
- for (let range of ranges instanceof Range ? [ranges] : sort ? lazySort(ranges) : ranges)
2945
- build.add(range.from, range.to, range.value);
2946
- return build.finish();
2947
- }
2948
- /**
2949
- Join an array of range sets into a single set.
2950
- */
2951
- static join(sets) {
2952
- if (!sets.length)
2953
- return _RangeSet.empty;
2954
- let result = sets[sets.length - 1];
2955
- for (let i = sets.length - 2; i >= 0; i--) {
2956
- for (let layer = sets[i]; layer != _RangeSet.empty; layer = layer.nextLayer)
2957
- result = new _RangeSet(layer.chunkPos, layer.chunk, result, Math.max(layer.maxPoint, result.maxPoint));
2958
- }
2959
- return result;
2960
- }
2961
- };
2962
- RangeSet.empty = new RangeSet([], [], null, -1);
2963
- function lazySort(ranges) {
2964
- if (ranges.length > 1)
2965
- for (let prev = ranges[0], i = 1; i < ranges.length; i++) {
2966
- let cur = ranges[i];
2967
- if (cmpRange(prev, cur) > 0)
2968
- return ranges.slice().sort(cmpRange);
2969
- prev = cur;
2970
- }
2971
- return ranges;
2972
- }
2973
- RangeSet.empty.nextLayer = RangeSet.empty;
2974
- var RangeSetBuilder = class _RangeSetBuilder {
2975
- finishChunk(newArrays) {
2976
- this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
2977
- this.chunkPos.push(this.chunkStart);
2978
- this.chunkStart = -1;
2979
- this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
2980
- this.maxPoint = -1;
2981
- if (newArrays) {
2982
- this.from = [];
2983
- this.to = [];
2984
- this.value = [];
2985
- }
2986
- }
2987
- /**
2988
- Create an empty builder.
2989
- */
2990
- constructor() {
2991
- this.chunks = [];
2992
- this.chunkPos = [];
2993
- this.chunkStart = -1;
2994
- this.last = null;
2995
- this.lastFrom = -1e9;
2996
- this.lastTo = -1e9;
2997
- this.from = [];
2998
- this.to = [];
2999
- this.value = [];
3000
- this.maxPoint = -1;
3001
- this.setMaxPoint = -1;
3002
- this.nextLayer = null;
3003
- }
3004
- /**
3005
- Add a range. Ranges should be added in sorted (by `from` and
3006
- `value.startSide`) order.
3007
- */
3008
- add(from, to, value) {
3009
- if (!this.addInner(from, to, value))
3010
- (this.nextLayer || (this.nextLayer = new _RangeSetBuilder())).add(from, to, value);
3011
- }
3012
- /**
3013
- @internal
3014
- */
3015
- addInner(from, to, value) {
3016
- let diff = from - this.lastTo || value.startSide - this.last.endSide;
3017
- if (diff <= 0 && (from - this.lastFrom || value.startSide - this.last.startSide) < 0)
3018
- throw new Error("Ranges must be added sorted by `from` position and `startSide`");
3019
- if (diff < 0)
3020
- return false;
3021
- if (this.from.length == 250)
3022
- this.finishChunk(true);
3023
- if (this.chunkStart < 0)
3024
- this.chunkStart = from;
3025
- this.from.push(from - this.chunkStart);
3026
- this.to.push(to - this.chunkStart);
3027
- this.last = value;
3028
- this.lastFrom = from;
3029
- this.lastTo = to;
3030
- this.value.push(value);
3031
- if (value.point)
3032
- this.maxPoint = Math.max(this.maxPoint, to - from);
3033
- return true;
3034
- }
3035
- /**
3036
- @internal
3037
- */
3038
- addChunk(from, chunk) {
3039
- if ((from - this.lastTo || chunk.value[0].startSide - this.last.endSide) < 0)
3040
- return false;
3041
- if (this.from.length)
3042
- this.finishChunk(true);
3043
- this.setMaxPoint = Math.max(this.setMaxPoint, chunk.maxPoint);
3044
- this.chunks.push(chunk);
3045
- this.chunkPos.push(from);
3046
- let last = chunk.value.length - 1;
3047
- this.last = chunk.value[last];
3048
- this.lastFrom = chunk.from[last] + from;
3049
- this.lastTo = chunk.to[last] + from;
3050
- return true;
3051
- }
3052
- /**
3053
- Finish the range set. Returns the new set. The builder can't be
3054
- used anymore after this has been called.
3055
- */
3056
- finish() {
3057
- return this.finishInner(RangeSet.empty);
3058
- }
3059
- /**
3060
- @internal
3061
- */
3062
- finishInner(next) {
3063
- if (this.from.length)
3064
- this.finishChunk(false);
3065
- if (this.chunks.length == 0)
3066
- return next;
3067
- let result = RangeSet.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(next) : next, this.setMaxPoint);
3068
- this.from = null;
3069
- return result;
3070
- }
3071
- };
3072
- function findSharedChunks(a, b, textDiff) {
3073
- let inA = /* @__PURE__ */ new Map();
3074
- for (let set of a)
3075
- for (let i = 0; i < set.chunk.length; i++)
3076
- if (set.chunk[i].maxPoint <= 0)
3077
- inA.set(set.chunk[i], set.chunkPos[i]);
3078
- let shared = /* @__PURE__ */ new Set();
3079
- for (let set of b)
3080
- for (let i = 0; i < set.chunk.length; i++) {
3081
- let known = inA.get(set.chunk[i]);
3082
- if (known != null && (textDiff ? textDiff.mapPos(known) : known) == set.chunkPos[i] && !(textDiff === null || textDiff === void 0 ? void 0 : textDiff.touchesRange(known, known + set.chunk[i].length)))
3083
- shared.add(set.chunk[i]);
3084
- }
3085
- return shared;
3086
- }
3087
- var LayerCursor = class {
3088
- constructor(layer, skip, minPoint, rank = 0) {
3089
- this.layer = layer;
3090
- this.skip = skip;
3091
- this.minPoint = minPoint;
3092
- this.rank = rank;
3093
- }
3094
- get startSide() {
3095
- return this.value ? this.value.startSide : 0;
3096
- }
3097
- get endSide() {
3098
- return this.value ? this.value.endSide : 0;
3099
- }
3100
- goto(pos, side = -1e9) {
3101
- this.chunkIndex = this.rangeIndex = 0;
3102
- this.gotoInner(pos, side, false);
3103
- return this;
3104
- }
3105
- gotoInner(pos, side, forward) {
3106
- while (this.chunkIndex < this.layer.chunk.length) {
3107
- let next = this.layer.chunk[this.chunkIndex];
3108
- if (!(this.skip && this.skip.has(next) || this.layer.chunkEnd(this.chunkIndex) < pos || next.maxPoint < this.minPoint))
3109
- break;
3110
- this.chunkIndex++;
3111
- forward = false;
3112
- }
3113
- if (this.chunkIndex < this.layer.chunk.length) {
3114
- let rangeIndex = this.layer.chunk[this.chunkIndex].findIndex(pos - this.layer.chunkPos[this.chunkIndex], side, true);
3115
- if (!forward || this.rangeIndex < rangeIndex)
3116
- this.setRangeIndex(rangeIndex);
3117
- }
3118
- this.next();
3119
- }
3120
- forward(pos, side) {
3121
- if ((this.to - pos || this.endSide - side) < 0)
3122
- this.gotoInner(pos, side, true);
3123
- }
3124
- next() {
3125
- for (; ; ) {
3126
- if (this.chunkIndex == this.layer.chunk.length) {
3127
- this.from = this.to = 1e9;
3128
- this.value = null;
3129
- break;
3130
- } else {
3131
- let chunkPos = this.layer.chunkPos[this.chunkIndex], chunk = this.layer.chunk[this.chunkIndex];
3132
- let from = chunkPos + chunk.from[this.rangeIndex];
3133
- this.from = from;
3134
- this.to = chunkPos + chunk.to[this.rangeIndex];
3135
- this.value = chunk.value[this.rangeIndex];
3136
- this.setRangeIndex(this.rangeIndex + 1);
3137
- if (this.minPoint < 0 || this.value.point && this.to - this.from >= this.minPoint)
3138
- break;
3139
- }
3140
- }
3141
- }
3142
- setRangeIndex(index) {
3143
- if (index == this.layer.chunk[this.chunkIndex].value.length) {
3144
- this.chunkIndex++;
3145
- if (this.skip) {
3146
- while (this.chunkIndex < this.layer.chunk.length && this.skip.has(this.layer.chunk[this.chunkIndex]))
3147
- this.chunkIndex++;
3148
- }
3149
- this.rangeIndex = 0;
3150
- } else {
3151
- this.rangeIndex = index;
3152
- }
3153
- }
3154
- nextChunk() {
3155
- this.chunkIndex++;
3156
- this.rangeIndex = 0;
3157
- this.next();
3158
- }
3159
- compare(other) {
3160
- return this.from - other.from || this.startSide - other.startSide || this.rank - other.rank || this.to - other.to || this.endSide - other.endSide;
3161
- }
3162
- };
3163
- var HeapCursor = class _HeapCursor {
3164
- constructor(heap) {
3165
- this.heap = heap;
3166
- }
3167
- static from(sets, skip = null, minPoint = -1) {
3168
- let heap = [];
3169
- for (let i = 0; i < sets.length; i++) {
3170
- for (let cur = sets[i]; !cur.isEmpty; cur = cur.nextLayer) {
3171
- if (cur.maxPoint >= minPoint)
3172
- heap.push(new LayerCursor(cur, skip, minPoint, i));
3173
- }
3174
- }
3175
- return heap.length == 1 ? heap[0] : new _HeapCursor(heap);
3176
- }
3177
- get startSide() {
3178
- return this.value ? this.value.startSide : 0;
3179
- }
3180
- goto(pos, side = -1e9) {
3181
- for (let cur of this.heap)
3182
- cur.goto(pos, side);
3183
- for (let i = this.heap.length >> 1; i >= 0; i--)
3184
- heapBubble(this.heap, i);
3185
- this.next();
3186
- return this;
3187
- }
3188
- forward(pos, side) {
3189
- for (let cur of this.heap)
3190
- cur.forward(pos, side);
3191
- for (let i = this.heap.length >> 1; i >= 0; i--)
3192
- heapBubble(this.heap, i);
3193
- if ((this.to - pos || this.value.endSide - side) < 0)
3194
- this.next();
3195
- }
3196
- next() {
3197
- if (this.heap.length == 0) {
3198
- this.from = this.to = 1e9;
3199
- this.value = null;
3200
- this.rank = -1;
3201
- } else {
3202
- let top = this.heap[0];
3203
- this.from = top.from;
3204
- this.to = top.to;
3205
- this.value = top.value;
3206
- this.rank = top.rank;
3207
- if (top.value)
3208
- top.next();
3209
- heapBubble(this.heap, 0);
3210
- }
3211
- }
3212
- };
3213
- function heapBubble(heap, index) {
3214
- for (let cur = heap[index]; ; ) {
3215
- let childIndex = (index << 1) + 1;
3216
- if (childIndex >= heap.length)
3217
- break;
3218
- let child = heap[childIndex];
3219
- if (childIndex + 1 < heap.length && child.compare(heap[childIndex + 1]) >= 0) {
3220
- child = heap[childIndex + 1];
3221
- childIndex++;
3222
- }
3223
- if (cur.compare(child) < 0)
3224
- break;
3225
- heap[childIndex] = cur;
3226
- heap[index] = child;
3227
- index = childIndex;
3228
- }
3229
- }
3230
- var SpanCursor = class {
3231
- constructor(sets, skip, minPoint) {
3232
- this.minPoint = minPoint;
3233
- this.active = [];
3234
- this.activeTo = [];
3235
- this.activeRank = [];
3236
- this.minActive = -1;
3237
- this.point = null;
3238
- this.pointFrom = 0;
3239
- this.pointRank = 0;
3240
- this.to = -1e9;
3241
- this.endSide = 0;
3242
- this.openStart = -1;
3243
- this.cursor = HeapCursor.from(sets, skip, minPoint);
3244
- }
3245
- goto(pos, side = -1e9) {
3246
- this.cursor.goto(pos, side);
3247
- this.active.length = this.activeTo.length = this.activeRank.length = 0;
3248
- this.minActive = -1;
3249
- this.to = pos;
3250
- this.endSide = side;
3251
- this.openStart = -1;
3252
- this.next();
3253
- return this;
3254
- }
3255
- forward(pos, side) {
3256
- while (this.minActive > -1 && (this.activeTo[this.minActive] - pos || this.active[this.minActive].endSide - side) < 0)
3257
- this.removeActive(this.minActive);
3258
- this.cursor.forward(pos, side);
3259
- }
3260
- removeActive(index) {
3261
- remove(this.active, index);
3262
- remove(this.activeTo, index);
3263
- remove(this.activeRank, index);
3264
- this.minActive = findMinIndex(this.active, this.activeTo);
3265
- }
3266
- addActive(trackOpen) {
3267
- let i = 0, { value, to, rank } = this.cursor;
3268
- while (i < this.activeRank.length && (rank - this.activeRank[i] || to - this.activeTo[i]) > 0)
3269
- i++;
3270
- insert(this.active, i, value);
3271
- insert(this.activeTo, i, to);
3272
- insert(this.activeRank, i, rank);
3273
- if (trackOpen)
3274
- insert(trackOpen, i, this.cursor.from);
3275
- this.minActive = findMinIndex(this.active, this.activeTo);
3276
- }
3277
- // After calling this, if `this.point` != null, the next range is a
3278
- // point. Otherwise, it's a regular range, covered by `this.active`.
3279
- next() {
3280
- let from = this.to, wasPoint = this.point;
3281
- this.point = null;
3282
- let trackOpen = this.openStart < 0 ? [] : null;
3283
- for (; ; ) {
3284
- let a = this.minActive;
3285
- if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {
3286
- if (this.activeTo[a] > from) {
3287
- this.to = this.activeTo[a];
3288
- this.endSide = this.active[a].endSide;
3289
- break;
3290
- }
3291
- this.removeActive(a);
3292
- if (trackOpen)
3293
- remove(trackOpen, a);
3294
- } else if (!this.cursor.value) {
3295
- this.to = this.endSide = 1e9;
3296
- break;
3297
- } else if (this.cursor.from > from) {
3298
- this.to = this.cursor.from;
3299
- this.endSide = this.cursor.startSide;
3300
- break;
3301
- } else {
3302
- let nextVal = this.cursor.value;
3303
- if (!nextVal.point) {
3304
- this.addActive(trackOpen);
3305
- this.cursor.next();
3306
- } else if (wasPoint && this.cursor.to == this.to && this.cursor.from < this.cursor.to) {
3307
- this.cursor.next();
3308
- } else {
3309
- this.point = nextVal;
3310
- this.pointFrom = this.cursor.from;
3311
- this.pointRank = this.cursor.rank;
3312
- this.to = this.cursor.to;
3313
- this.endSide = nextVal.endSide;
3314
- this.cursor.next();
3315
- this.forward(this.to, this.endSide);
3316
- break;
3317
- }
3318
- }
3319
- }
3320
- if (trackOpen) {
3321
- this.openStart = 0;
3322
- for (let i = trackOpen.length - 1; i >= 0 && trackOpen[i] < from; i--)
3323
- this.openStart++;
3324
- }
3325
- }
3326
- activeForPoint(to) {
3327
- if (!this.active.length)
3328
- return this.active;
3329
- let active = [];
3330
- for (let i = this.active.length - 1; i >= 0; i--) {
3331
- if (this.activeRank[i] < this.pointRank)
3332
- break;
3333
- if (this.activeTo[i] > to || this.activeTo[i] == to && this.active[i].endSide >= this.point.endSide)
3334
- active.push(this.active[i]);
3335
- }
3336
- return active.reverse();
3337
- }
3338
- openEnd(to) {
3339
- let open = 0;
3340
- for (let i = this.activeTo.length - 1; i >= 0 && this.activeTo[i] > to; i--)
3341
- open++;
3342
- return open;
3343
- }
3344
- };
3345
- function compare(a, startA, b, startB, length, comparator) {
3346
- a.goto(startA);
3347
- b.goto(startB);
3348
- let endB = startB + length;
3349
- let pos = startB, dPos = startB - startA;
3350
- let bounds = !!comparator.boundChange;
3351
- for (let boundChange = false; ; ) {
3352
- let dEnd = a.to + dPos - b.to, diff = dEnd || a.endSide - b.endSide;
3353
- let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
3354
- let point = a.point || b.point;
3355
- if (point) {
3356
- if (!(a.point && b.point && cmpVal(a.point, b.point) && sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
3357
- comparator.comparePoint(pos, clipEnd, a.point, b.point);
3358
- boundChange = false;
3359
- } else {
3360
- if (boundChange)
3361
- comparator.boundChange(pos);
3362
- if (clipEnd > pos && !sameValues(a.active, b.active))
3363
- comparator.compareRange(pos, clipEnd, a.active, b.active);
3364
- if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end)))
3365
- boundChange = true;
3366
- }
3367
- if (end > endB)
3368
- break;
3369
- pos = end;
3370
- if (diff <= 0)
3371
- a.next();
3372
- if (diff >= 0)
3373
- b.next();
3374
- }
3375
- }
3376
- function sameValues(a, b) {
3377
- if (a.length != b.length)
3378
- return false;
3379
- for (let i = 0; i < a.length; i++)
3380
- if (a[i] != b[i] && !cmpVal(a[i], b[i]))
3381
- return false;
3382
- return true;
3383
- }
3384
- function remove(array, index) {
3385
- for (let i = index, e = array.length - 1; i < e; i++)
3386
- array[i] = array[i + 1];
3387
- array.pop();
3388
- }
3389
- function insert(array, index, value) {
3390
- for (let i = array.length - 1; i >= index; i--)
3391
- array[i + 1] = array[i];
3392
- array[index] = value;
3393
- }
3394
- function findMinIndex(value, array) {
3395
- let found = -1, foundPos = 1e9;
3396
- for (let i = 0; i < array.length; i++)
3397
- if ((array[i] - foundPos || value[i].endSide - value[found].endSide) < 0) {
3398
- found = i;
3399
- foundPos = array[i];
3400
- }
3401
- return found;
3402
- }
3403
- function countColumn(string, tabSize, to = string.length) {
3404
- let n = 0;
3405
- for (let i = 0; i < to && i < string.length; ) {
3406
- if (string.charCodeAt(i) == 9) {
3407
- n += tabSize - n % tabSize;
3408
- i++;
3409
- } else {
3410
- n++;
3411
- i = findClusterBreak2(string, i);
3412
- }
3413
- }
3414
- return n;
3415
- }
3416
- function findColumn(string, col, tabSize, strict) {
3417
- for (let i = 0, n = 0; ; ) {
3418
- if (n >= col)
3419
- return i;
3420
- if (i == string.length)
3421
- break;
3422
- n += string.charCodeAt(i) == 9 ? tabSize - n % tabSize : 1;
3423
- i = findClusterBreak2(string, i);
3424
- }
3425
- return strict === true ? -1 : string.length;
3426
- }
3427
-
3428
- export {
3429
- Text,
3430
- Line,
3431
- findClusterBreak2 as findClusterBreak,
3432
- codePointAt2 as codePointAt,
3433
- fromCodePoint,
3434
- codePointSize2 as codePointSize,
3435
- MapMode,
3436
- ChangeDesc,
3437
- ChangeSet,
3438
- SelectionRange,
3439
- EditorSelection,
3440
- Facet,
3441
- StateField,
3442
- Prec,
3443
- Compartment,
3444
- Annotation,
3445
- AnnotationType,
3446
- StateEffectType,
3447
- StateEffect,
3448
- Transaction,
3449
- CharCategory,
3450
- EditorState,
3451
- combineConfig,
3452
- RangeValue,
3453
- Range,
3454
- RangeSet,
3455
- RangeSetBuilder,
3456
- countColumn,
3457
- findColumn
3458
- };
3459
- //# sourceMappingURL=chunk-YYJMNVCJ.js.map